From c83d92e84688dd861a8f0cf60b6fe7c6a8056dc2 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 10 Aug 2015 11:30:37 -0600 Subject: [PATCH 001/858] RAMTRON: Update driver to include support for newer RAMTRON parts. --- ChangeLog | 3 +++ drivers/mtd/ramtron.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7e92de8a31..03e6dd4558 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10801,3 +10801,6 @@ * fs/vfs/epoll.c and include/sys/epoll.h: Add a very simple epoll layer just around poll calls. To satisfy build app requirements. From Anton D. Kachalov. + * drivers/mtd/ramtron.c: Update to include supportf for newer + RAMTRON parts. From David Sidrane. + diff --git a/drivers/mtd/ramtron.c b/drivers/mtd/ramtron.c index 215c13f7b2..b800d0f27c 100644 --- a/drivers/mtd/ramtron.c +++ b/drivers/mtd/ramtron.c @@ -176,6 +176,14 @@ static const struct ramtron_parts_s g_ramtron_parts[] = 2, /* addr_len */ RAMTRON_INIT_CLK_MAX /* speed */ }, + { + "FM25V01A", /* name */ + 0x21, /* id1 */ + 0x08, /* id2 */ + 16L*1024L, /* size */ + 2, /* addr_len */ + RAMTRON_INIT_CLK_MAX /* speed */ + }, { "FM25V02", /* name */ 0x22, /* id1 */ @@ -184,6 +192,14 @@ static const struct ramtron_parts_s g_ramtron_parts[] = 2, /* addr_len */ RAMTRON_INIT_CLK_MAX /* speed */ }, + { + "FM25V02A", /* name */ + 0x22, /* id1 */ + 0x08, /* id2 */ + 32L*1024L, /* size */ + 2, /* addr_len */ + RAMTRON_INIT_CLK_MAX /* speed */ + }, { "FM25VN02", /* name */ 0x22, /* id1 */ @@ -224,6 +240,22 @@ static const struct ramtron_parts_s g_ramtron_parts[] = 3, /* addr_len */ RAMTRON_INIT_CLK_MAX /* speed */ }, + { + "FM25V20A", /* name */ + 0x25, /* id1 */ + 0x08, /* id2 */ + 256L*1024L, /* size */ + 3, /* addr_len */ + RAMTRON_INIT_CLK_MAX /* speed */ + }, + { + "CY15B104Q", /* name */ + 0x26, /* id1 */ + 0x08, /* id2 */ + 512L*1024L, /* size */ + 3, /* addr_len */ + RAMTRON_INIT_CLK_MAX /* speed */ + }, { "MB85RS1MT", /* name */ 0x27, /* id1 */ -- GitLab From 1d0e25af309f9ab1985e78126c8c7e621c324224 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 10 Aug 2015 10:14:44 -0400 Subject: [PATCH 002/858] Convert the AS5048B to use the quadrature encoder interface. --- drivers/sensors/as5048b.c | 305 +++++++++++++++----------------- include/nuttx/sensors/as5048b.h | 33 ++-- 2 files changed, 162 insertions(+), 176 deletions(-) diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index ffa96a47f2..c93cc31d25 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -49,7 +49,7 @@ #include #include -#if defined(CONFIG_I2C) && defined(CONFIG_AS5048B) +#if defined(CONFIG_I2C) && defined(CONFIG_QENCODER) && defined(CONFIG_AS5048B) /**************************************************************************** * Private Types @@ -57,8 +57,9 @@ struct as5048b_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ + struct qe_lowerhalf_s lower; /* AS5048B quadrature encoder lower half */ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ }; /**************************************************************************** @@ -66,13 +67,13 @@ struct as5048b_dev_s ****************************************************************************/ /* I2C Helpers */ -static int as5048b_readb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, +static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval); -static int as5048b_readb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, +static int as5048b_readu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, uint8_t regaddrlo, FAR uint16_t *regval); -static int as5048b_writeb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, +static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, uint8_t regval); -static int as5048b_writeb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, +static int as5048b_writeu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, uint8_t regaddrlo, uint16_t regval); static int as5048b_readzero(FAR struct as5048b_dev_s *priv, FAR uint16_t *zero); @@ -85,33 +86,24 @@ static int as5048b_readang(FAR struct as5048b_dev_s *priv, FAR uint16_t *ang); /* Character Driver Methods */ -static int as5048b_open(FAR struct file *filep); -static int as5048b_close(FAR struct file *filep); -static ssize_t as5048b_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); -static ssize_t as5048b_write(FAR struct file *filep, FAR const char *buffer, - size_t buflen); -static int as5048b_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); +static int as5048b_setup(FAR struct qe_lowerhalf_s *lower); +static int as5048b_shutdown(FAR struct qe_lowerhalf_s *lower); +static int as5048b_position(FAR struct qe_lowerhalf_s *lower, int32_t *pos); +static int as5048b_reset(FAR struct qe_lowerhalf_s *lower); +static int as5048b_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, + unsigned long arg); /**************************************************************************** * Private Data ****************************************************************************/ -static const struct file_operations g_as5048bfops = +static const struct qe_ops_s g_qeops = { - as5048b_open, - as5048b_close, - as5048b_read, - as5048b_write, - NULL, + as5048b_setup, + as5048b_shutdown, + as5048b_position, + as5048b_reset, as5048b_ioctl -#ifndef CONFIG_DISABLE_POLL - , NULL -#endif -#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS - , NULL -#endif }; /**************************************************************************** @@ -119,17 +111,16 @@ static const struct file_operations g_as5048bfops = ****************************************************************************/ /**************************************************************************** - * Name: as5048b_readb8 + * Name: as5048b_readu8 * * Description: * Read from an 8-bit register * ****************************************************************************/ -static int as5048b_readb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, +static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval) { - uint8_t buffer; int ret; /* Write the register address */ @@ -144,27 +135,26 @@ static int as5048b_readb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, /* Restart and read 8 bits from the register */ - ret = I2C_READ(priv->i2c, &buffer, sizeof(buffer)); + ret = I2C_READ(priv->i2c, regval, sizeof(*regval)); if (ret < 0) { sndbg("I2C_READ failed: %d\n", ret); return ret; } - *regval = buffer; sndbg("addr: %02x value: %02x ret: %d\n", regaddr, *regval, ret); return ret; } /**************************************************************************** - * Name: as5048b_readb16 + * Name: as5048b_readu16 * * Description: * Read from two 8-bit registers * ****************************************************************************/ -static int as5048b_readb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, +static int as5048b_readu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, uint8_t regaddrlo, FAR uint16_t *regval) { uint8_t hi, lo; @@ -172,19 +162,19 @@ static int as5048b_readb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, /* Read the high 8 bits of the 13-bit value */ - ret = as5048b_readb8(priv, regaddrhi, &hi); + ret = as5048b_readu8(priv, regaddrhi, &hi); if (ret < 0) { - sndbg("as5048b_readb8 failed: %d\n", ret); + sndbg("as5048b_readu8 failed: %d\n", ret); return ret; } /* Read the low 5 bits of the 13-bit value */ - ret = as5048b_readb8(priv, regaddrlo, &lo); + ret = as5048b_readu8(priv, regaddrlo, &lo); if (ret < 0) { - sndbg("as5048b_readb8 failed: %d\n", ret); + sndbg("as5048b_readu8 failed: %d\n", ret); return ret; } @@ -195,14 +185,14 @@ static int as5048b_readb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, } /**************************************************************************** - * Name: as5048b_writeb8 + * Name: as5048b_writeu8 * * Description: * Write from an 8-bit register * ****************************************************************************/ -static int as5048b_writeb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, +static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, uint8_t regval) { uint8_t buffer[2]; @@ -228,14 +218,14 @@ static int as5048b_writeb8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, } /**************************************************************************** - * Name: as5048b_writeb16 + * Name: as5048b_writeu16 * * Description: * Write to two 8-bit registers * ****************************************************************************/ -static int as5048b_writeb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, +static int as5048b_writeu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, uint8_t regaddrlo, uint16_t regval) { int ret; @@ -245,19 +235,19 @@ static int as5048b_writeb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, /* Write the high 8 bits of the 13-bit value */ - ret = as5048b_writeb8(priv, regaddrhi, (uint8_t)(regval >> 6)); + ret = as5048b_writeu8(priv, regaddrhi, (uint8_t)(regval >> 6)); if (ret < 0) { - sndbg("as5048b_writeb8 failed: %d\n", ret); + sndbg("as5048b_writeu8 failed: %d\n", ret); return ret; } /* Write the low 5 bits of the 13-bit value */ - ret = as5048b_writeb8(priv, regaddrhi, (uint8_t)regval); + ret = as5048b_writeu8(priv, regaddrhi, (uint8_t)regval); if (ret < 0) { - sndbg("as5048b_writeb8 failed: %d\n", ret); + sndbg("as5048b_writeu8 failed: %d\n", ret); } return ret; @@ -274,18 +264,15 @@ static int as5048b_writeb16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, static int as5048b_readzero(FAR struct as5048b_dev_s *priv, FAR uint16_t *zero) { - uint16_t buffer; int ret; - ret = as5048b_readb16(priv, AS5048B_ZEROHI_REG, AS5048B_ZEROLO_REG, - &buffer); + ret = as5048b_readu16(priv, AS5048B_ZEROHI_REG, AS5048B_ZEROLO_REG, zero); if (ret < 0) { - sndbg("as5048b_readb16 failed: %d\n", ret); + sndbg("as5048b_readu16 failed: %d\n", ret); return ret; } - *zero = buffer; sndbg("zero: %04x ret: %d\n", *zero, ret); return ret; } @@ -304,10 +291,10 @@ static int as5048b_writezero(FAR struct as5048b_dev_s *priv, uint16_t zero) sndbg("zero: %04x\n", zero); - ret = as5048b_writeb16(priv, AS5048B_ZEROHI_REG, AS5048B_ZEROLO_REG, zero); + ret = as5048b_writeu16(priv, AS5048B_ZEROHI_REG, AS5048B_ZEROLO_REG, zero); if (ret < 0) { - sndbg("as5048b_writeb16 failed: %d\n", ret); + sndbg("as5048b_writeu16 failed: %d\n", ret); } return ret; @@ -323,17 +310,15 @@ static int as5048b_writezero(FAR struct as5048b_dev_s *priv, uint16_t zero) static int as5048b_readagc(FAR struct as5048b_dev_s *priv, FAR uint8_t *agc) { - uint8_t buffer; int ret; - ret = as5048b_readb8(priv, AS5048B_AGC_REG, &buffer); + ret = as5048b_readu8(priv, AS5048B_AGC_REG, agc); if (ret < 0) { - sndbg("as5048b_readb8 failed: %d\n", ret); + sndbg("as5048b_readu8 failed: %d\n", ret); return ret; } - *agc = buffer; sndbg("agc: %02x ret: %d\n", *agc, ret); return ret; } @@ -348,17 +333,15 @@ static int as5048b_readagc(FAR struct as5048b_dev_s *priv, FAR uint8_t *agc) static int as5048b_readdiag(FAR struct as5048b_dev_s *priv, FAR uint8_t *diag) { - uint8_t buffer; int ret; - ret = as5048b_readb8(priv, AS5048B_DIAG_REG, &buffer); + ret = as5048b_readu8(priv, AS5048B_DIAG_REG, diag); if (ret < 0) { - sndbg("as5048b_readb8 failed: %d\n", ret); + sndbg("as5048b_readu8 failed: %d\n", ret); return ret; } - *diag = buffer; sndbg("diag: %02x ret: %d\n", *diag, ret); return ret; } @@ -373,17 +356,15 @@ static int as5048b_readdiag(FAR struct as5048b_dev_s *priv, FAR uint8_t *diag) static int as5048b_readmag(FAR struct as5048b_dev_s *priv, FAR uint16_t *mag) { - uint16_t buffer; int ret; - ret = as5048b_readb16(priv, AS5048B_MAGHI_REG, AS5048B_MAGLO_REG, &buffer); + ret = as5048b_readu16(priv, AS5048B_MAGHI_REG, AS5048B_MAGLO_REG, mag); if (ret < 0) { - sndbg("as5048b_readb16 failed: %d\n", ret); + sndbg("as5048b_readu16 failed: %d\n", ret); return ret; } - *mag = buffer; sndbg("mag: %04x ret: %d\n", *mag, ret); return ret; } @@ -398,135 +379,141 @@ static int as5048b_readmag(FAR struct as5048b_dev_s *priv, FAR uint16_t *mag) static int as5048b_readang(FAR struct as5048b_dev_s *priv, FAR uint16_t *ang) { - uint16_t buffer; int ret; - ret = as5048b_readb16(priv, AS5048B_ANGHI_REG, AS5048B_ANGLO_REG, &buffer); + ret = as5048b_readu16(priv, AS5048B_ANGHI_REG, AS5048B_ANGLO_REG, ang); if (ret < 0) { - sndbg("as5048b_readb16 failed: %d\n", ret); + sndbg("as5048b_readu16 failed: %d\n", ret); return ret; } - *ang = buffer; sndbg("ang: %04x ret: %d\n", *ang, ret); return ret; } /**************************************************************************** - * Name: as5048b_open + * Name: as5048b_setup * * Description: - * This function is called whenever the device is opened + * This method is called when the driver is opened * ****************************************************************************/ -static int as5048b_open(FAR struct file *filep) +static int as5048b_setup(FAR struct qe_lowerhalf_s *lower) { return OK; } /**************************************************************************** - * Name: as5048b_close + * Name: as5048b_shutdown * * Description: - * This function is called whenever the device is closed + * This method is called when the driver is closed * ****************************************************************************/ -static int as5048b_close(FAR struct file *filep) +static int as5048b_shutdown(FAR struct qe_lowerhalf_s *lower) { return OK; } /**************************************************************************** - * Name: as5048b_read + * Name: as5048b_position + * + * Description: + * Return the current position measurement + * ****************************************************************************/ -static ssize_t as5048b_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) +static int as5048b_position(FAR struct qe_lowerhalf_s *lower, int32_t *pos) { - FAR struct inode *inode = filep->f_inode; - FAR struct as5048b_dev_s *priv = inode->i_private; - FAR uint16_t *ptr; - ssize_t nsamples; - ssize_t i; - int ret; - - /* How many samples were requested? */ - - ptr = (FAR uint16_t *)buffer; - nsamples = buflen / sizeof(*ptr); - - sndbg("buflen: %u nsamples: %d\n", buflen, nsamples); - - /* Get the requested number of samples */ + FAR struct as5048b_dev_s *priv = (FAR struct as5048b_dev_s *)lower; + uint16_t ang; + int ret; - for (i = 0; i < nsamples; i++) + ret = as5048b_readang(priv, &ang); + if (ret < 0) { - uint16_t ang = 0; - - /* Read the next uint16_t angle value */ - - ret = as5048b_readang(priv, &ang); - if (ret < 0) - { - sndbg("as5048b_readang failed: %d\n", ret); - return (ssize_t)ret; - } - - /* Save the angle value in the user buffer */ - - *ptr++ = ang; + sndbg("as5048b_readang failed: %d\n", ret); + return ret; } - return nsamples * sizeof(*ptr); + *pos = (int32_t)ang; + return ret; } /**************************************************************************** - * Name: as5048b_write + * Name: as5048b_reset + * + * Description: + * Reset the position measurement to zero + * ****************************************************************************/ -static ssize_t as5048b_write(FAR struct file *filep, FAR const char *buffer, - size_t buflen) +static int as5048b_reset(FAR struct qe_lowerhalf_s *lower) { - return -ENOSYS; + FAR struct as5048b_dev_s *priv = (FAR struct as5048b_dev_s *)lower; + uint16_t ang; + int ret; + + ret = as5048b_writezero(priv, 0); + if (ret < 0) + { + sndbg("as5048b_writezero failed: %d\n", ret); + return ret; + } + + ret = as5048b_readang(priv, &ang); + if (ret < 0) + { + sndbg("as5048b_readang failed: %d\n", ret); + return ret; + } + + ret = as5048b_writezero(priv, ang); + if (ret < 0) + { + sndbg("as5048b_writezero failed: %d\n", ret); + } + + return ret; } /**************************************************************************** * Name: as5048b_ioctl ****************************************************************************/ -static int as5048b_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +static int as5048b_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, + unsigned long arg) { - FAR struct inode *inode = filep->f_inode; - FAR struct as5048b_dev_s *priv = inode->i_private; - int ret = OK; + FAR struct as5048b_dev_s *priv = (FAR struct as5048b_dev_s *)lower; + int ret = OK; switch (cmd) { - /* Read from the zero position registers. Arg: uint16_t* pointer. */ + /* Read from the zero position registers. Arg: int32_t* pointer. */ - case SNIOC_READZERO: + case QEIOC_ZEROPOSITION: { - FAR uint16_t *ptr = (FAR uint16_t *)((uintptr_t)arg); - ret = as5048b_readzero(priv, ptr); + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + uint16_t zero; + DEBUGASSERT(ptr != NULL); + ret = as5048b_readzero(priv, &zero); + if (ret == OK) + { + *ptr = (int32_t)zero; + } sndbg("zero: %04x ret: %d\n", *ptr, ret); } break; - /* Write to the zero position registers. Arg: uint16_t value. */ - - case SNIOC_WRITEZERO: - ret = as5048b_writezero(priv, (uint16_t)arg); - sndbg("zero: %04x ret: %d\n", *(uint16_t *)arg, ret); - break; - /* Read from the automatic gain control register. Arg: uint8_t* pointer. */ - case SNIOC_READAGC: + case QEIOC_AUTOGAINCTL: { FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = as5048b_readagc(priv, ptr); sndbg("agc: %02x ret: %d\n", *ptr, ret); } @@ -534,26 +521,33 @@ static int as5048b_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Read from the diagnostics register. Arg: uint8_t* pointer. */ - case SNIOC_READDIAG: + case QEIOC_DIAGNOSTICS: { FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = as5048b_readdiag(priv, ptr); sndbg("diag: %02x ret: %d\n", *ptr, ret); } break; - /* Read from the magnitude registers. Arg: uint16_t* pointer. */ + /* Read from the magnitude registers. Arg: int32_t* pointer. */ - case SNIOC_READMAG: + case QEIOC_MAGNITUDE: { - FAR uint16_t *ptr = (FAR uint16_t *)((uintptr_t)arg); - ret = as5048b_readmag(priv, ptr); + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + uint16_t mag; + DEBUGASSERT(ptr != NULL); + ret = as5048b_readmag(priv, &mag); + if (ret == OK) + { + *ptr = (int32_t)mag; + } sndbg("mag: %04x ret: %d\n", *ptr, ret); } break; default: - sndbg("Unrecognized cmd: %d\n", cmd); + sndbg("Unrecognized cmd: %d arg: %ld\n", cmd, arg); ret = -ENOTTY; break; } @@ -566,28 +560,27 @@ static int as5048b_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ****************************************************************************/ /**************************************************************************** - * Name: as5048b_register + * Name: as5048b_initialize * * Description: - * Register the AS5048B character device as 'devpath'. + * Initialize the AS5048B device. * * Input Parameters: - * devpath - The full path to the driver to register, - * for example "/dev/angle0". - * i2c - An instance of the I2C interface to use to communicate - * with the AS5048B. - * addr - The I2C address of the AS5048B. + * i2c - An I2C driver instance. + * addr - The I2C address of the AS5048B. * * Returned Value: - * Zero (OK) on success; a negated errno value on failure. + * A new lower half quadrature encoder interface for the AS5048B on success; + * NULL on failure. * ****************************************************************************/ -int as5048b_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, - uint8_t addr) +FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_dev_s *i2c, + uint8_t addr) { FAR struct as5048b_dev_s *priv; - int ret; + + DEBUGASSERT(i2c != NULL); /* Initialize the device's structure */ @@ -595,22 +588,14 @@ int as5048b_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, if (priv == NULL) { sndbg("Failed to allocate instance\n"); - return -ENOMEM; + return NULL; } - priv->i2c = i2c; - priv->addr = addr; + priv->lower.ops = &g_qeops; + priv->i2c = i2c; + priv->addr = addr; - /* Register the character driver */ - - ret = register_driver(devpath, &g_as5048bfops, 0666, priv); - if (ret < 0) - { - sndbg("Failed to register driver: %d\n", ret); - kmm_free(priv); - } - - return ret; + return &priv->lower; } -#endif /* CONFIG_I2C && CONFIG_AS5048B */ +#endif /* CONFIG_I2C && CONFIG_QENCODER && CONFIG_AS5048B */ diff --git a/include/nuttx/sensors/as5048b.h b/include/nuttx/sensors/as5048b.h index 6e8c0c3aae..7e11ae1a97 100644 --- a/include/nuttx/sensors/as5048b.h +++ b/include/nuttx/sensors/as5048b.h @@ -41,8 +41,11 @@ ****************************************************************************/ #include -#include #include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_QENCODER) && defined(CONFIG_AS5048B) /**************************************************************************** * Pre-processor Definitions @@ -58,11 +61,10 @@ /* IOCTL Commands ***********************************************************/ -#define SNIOC_READZERO _SNIOC(0x0001) /* Arg: uint16_t* pointer */ -#define SNIOC_WRITEZERO _SNIOC(0x0002) /* Arg: uint16_t value */ -#define SNIOC_READAGC _SNIOC(0x0004) /* Arg: uint8_t* pointer */ -#define SNIOC_READDIAG _SNIOC(0x0005) /* Arg: uint8_t* pointer */ -#define SNIOC_READMAG _SNIOC(0x0006) /* Arg: uint16_t* pointer */ +#define QEIOC_ZEROPOSITION _QEIOC(QEIOC_USER+0) /* Arg: int32_t* pointer */ +#define QEIOC_AUTOGAINCTL _QEIOC(QEIOC_USER+1) /* Arg: uint8_t* pointer */ +#define QEIOC_DIAGNOSTICS _QEIOC(QEIOC_USER+2) /* Arg: uint8_t* pointer */ +#define QEIOC_MAGNITUDE _QEIOC(QEIOC_USER+3) /* Arg: int32_t* pointer */ /* Resolution ***************************************************************/ @@ -108,29 +110,28 @@ extern "C" #endif /**************************************************************************** - * Name: as5048b_register + * Name: as5048b_initialize * * Description: - * Register the AS5048B character device as 'devpath'. + * Initialize the AS5048B device. * * Input Parameters: - * devpath - The full path to the driver to register, - * for example "/dev/angle0". - * i2c - An instance of the I2C interface to use to communicate - * with the AS5048B. - * addr - The I2C address of the AS5048B. + * i2c - An I2C driver instance. + * addr - The I2C address of the AS5048B. * * Returned Value: - * Zero (OK) on success; a negated errno value on failure. + * A new lower half quadrature encoder interface for the AS5048B on success; + * NULL on failure. * ****************************************************************************/ -int as5048b_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, - uint8_t addr); +FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_dev_s *i2c, + uint8_t addr); #undef EXTERN #ifdef __cplusplus } #endif +#endif /* CONFIG_I2C && CONFIG_QENCODER && CONFIG_AS5048B */ #endif /* __INCLUDE_NUTTX_SENSORS_AS5048B */ -- GitLab From 877d5f3b09fa17d8c65244fdf191975b795c6e6b Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 10 Aug 2015 14:03:18 -0400 Subject: [PATCH 003/858] Changed copyright notices to my boss's preference. --- drivers/sensors/as5048b.c | 4 ++-- drivers/sensors/lm92.c | 6 +++--- include/nuttx/sensors/as5048b.h | 4 ++-- include/nuttx/sensors/lm92.h | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index c93cc31d25..1df9768460 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -2,8 +2,8 @@ * drivers/sensors/as5048b.c * Character driver for the AMS AS5048B Magnetic Rotary Encoder * - * Copyright (C) 2015 Alexandru Duru. All rights reserved. - * Author: Alexandru Duru + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 8d75e01771..618b3d3290 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -3,9 +3,9 @@ * Character driver for the TI LM92 Temperature Sensor * * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. - * Copyright (C) 2015 Alexandru Duru. All rights reserved. - * Author: Gregory Nutt - * Alexandru Duru + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Authors: Gregory Nutt + * Paul Alexander Patience * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/nuttx/sensors/as5048b.h b/include/nuttx/sensors/as5048b.h index 7e11ae1a97..b28c86ae7c 100644 --- a/include/nuttx/sensors/as5048b.h +++ b/include/nuttx/sensors/as5048b.h @@ -1,8 +1,8 @@ /**************************************************************************** * include/nuttx/sensors/as5048b.h * - * Copyright (C) 2015 Alexandru Duru. All rights reserved. - * Author: Alexandru Duru + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/include/nuttx/sensors/lm92.h b/include/nuttx/sensors/lm92.h index 7db294dfdf..d0fcea8fec 100644 --- a/include/nuttx/sensors/lm92.h +++ b/include/nuttx/sensors/lm92.h @@ -2,9 +2,9 @@ * include/nuttx/sensors/lm92.h * * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. - * Copyright (C) 2015 Alexandru Duru. All rights reserved. - * Author: Gregory Nutt - * Alexandru Duru + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Authors: Gregory Nutt + * Paul Alexander Patience * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions -- GitLab From dc773a06d874fe15d15964ac028f69788d469cfc Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 10 Aug 2015 14:15:20 -0400 Subject: [PATCH 004/858] Updated ChangeLog to use my full name. --- ChangeLog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37a4b8cd75..8044da6e69 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10787,11 +10787,11 @@ * arch/arm/src/samv7: Add an MCAN driver for the SAMV7 platform (2015-08-06). * drivers/sensors/lm92.c and include/nuttx/sensors/lm92.h: Add a driver - for the LM92 temperature sensor. Contributed by Paul Patience + for the LM92 temperature sensor. Contributed by Paul Alexander Patience (2015-08-06). * drivers/sensors/as5048b.c and include/nuttx/sensors/as5048b.h: Add - support for an AS5048B rotary magnetic sensor. From Paul Patience - (2015-08-06). + support for an AS5048B rotary magnetic sensor. From Paul Alexander + Patience (2015-08-07). * include/nuttx/spi/slave.h: Add a definition of an SPI slave interface (2015-08-08). * arch/arm/src/samv7: Add the framework for an SPI slave drvier. This -- GitLab From c0964a17b4298c4946e7b80163ed91f4df7db9f6 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 10 Aug 2015 14:40:36 -0400 Subject: [PATCH 005/858] Fixed a forgotten FAR, a typo, and an incorrect bit-field definition. --- drivers/sensors/as5048b.c | 6 ++++-- drivers/sensors/lm75.c | 2 +- include/nuttx/audio/audio.h | 2 +- include/nuttx/sensors/lm75.h | 2 +- include/nuttx/sensors/qencoder.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index 1df9768460..f0e8d4f907 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -88,7 +88,8 @@ static int as5048b_readang(FAR struct as5048b_dev_s *priv, FAR uint16_t *ang); static int as5048b_setup(FAR struct qe_lowerhalf_s *lower); static int as5048b_shutdown(FAR struct qe_lowerhalf_s *lower); -static int as5048b_position(FAR struct qe_lowerhalf_s *lower, int32_t *pos); +static int as5048b_position(FAR struct qe_lowerhalf_s *lower, + FAR int32_t *pos); static int as5048b_reset(FAR struct qe_lowerhalf_s *lower); static int as5048b_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, unsigned long arg); @@ -426,7 +427,8 @@ static int as5048b_shutdown(FAR struct qe_lowerhalf_s *lower) * ****************************************************************************/ -static int as5048b_position(FAR struct qe_lowerhalf_s *lower, int32_t *pos) +static int as5048b_position(FAR struct qe_lowerhalf_s *lower, + FAR int32_t *pos) { FAR struct as5048b_dev_s *priv = (FAR struct as5048b_dev_s *)lower; uint16_t ang; diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 5277fada40..e11e3f725f 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -462,7 +462,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Write TOS (Over-temp Shutdown Threshold) Register. Arg: b16_t value */ - case SNIOC_WRITRETOS: + case SNIOC_WRITETOS: ret = lm75_writeb16(priv, LM75_TOS_REG, (b16_t)arg); sndbg("TOS: %08x ret: %d\n", (b16_t)arg, ret); break; diff --git a/include/nuttx/audio/audio.h b/include/nuttx/audio/audio.h index 9799e004e5..323c4dd696 100644 --- a/include/nuttx/audio/audio.h +++ b/include/nuttx/audio/audio.h @@ -130,7 +130,7 @@ */ #define AUDIO_TYPE_QUERY 0x00 -#define AUDIO_TYPE_INPUT 0x02 +#define AUDIO_TYPE_INPUT 0x01 #define AUDIO_TYPE_OUTPUT 0x02 #define AUDIO_TYPE_MIXER 0x04 #define AUDIO_TYPE_SELECTOR 0x08 diff --git a/include/nuttx/sensors/lm75.h b/include/nuttx/sensors/lm75.h index bd01e51b53..75f8d95f02 100644 --- a/include/nuttx/sensors/lm75.h +++ b/include/nuttx/sensors/lm75.h @@ -64,7 +64,7 @@ #define SNIOC_READTHYS _SNIOC(0x0007) /* Arg: b16_t* pointer */ #define SNIOC_WRITETHYS _SNIOC(0x0008) /* Arg: b16_t value */ #define SNIOC_READTOS _SNIOC(0x0009) /* Arg: b16_t* pointer */ -#define SNIOC_WRITRETOS _SNIOC(0x000a) /* Arg: b16_t value */ +#define SNIOC_WRITETOS _SNIOC(0x000a) /* Arg: b16_t value */ /* LM-75 Register Definitions ***********************************************/ /* LM-75 Registers addresses */ diff --git a/include/nuttx/sensors/qencoder.h b/include/nuttx/sensors/qencoder.h index 62ab322278..f765ee1956 100644 --- a/include/nuttx/sensors/qencoder.h +++ b/include/nuttx/sensors/qencoder.h @@ -102,7 +102,7 @@ struct qe_ops_s /* Return the current position measurement. */ - CODE int (*position)(FAR struct qe_lowerhalf_s *lower, int32_t *pos); + CODE int (*position)(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos); /* Reset the position measurement to zero. */ -- GitLab From 65792c5dbc1301a25f45aeea4d051c97e9f65e6e Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 10 Aug 2015 14:59:11 -0400 Subject: [PATCH 006/858] Added forward declarations of structures to fix header inclusion order bugs. Removed an unused variable. Added debug asserts to check for invalid I2C addresses. --- drivers/sensors/Kconfig | 2 ++ drivers/sensors/adxl345_i2c.c | 1 + drivers/sensors/adxl345_spi.c | 1 + drivers/sensors/lis331dl.c | 5 +++++ drivers/sensors/lm75.c | 17 ++++++++++++++--- drivers/sensors/lm92.c | 18 +++++++++++++++--- drivers/sensors/mpl115a.c | 2 -- include/nuttx/sensors/adxl345.h | 7 +++---- include/nuttx/sensors/as5048b.h | 8 ++++++-- include/nuttx/sensors/bmp180.h | 12 ++++++++++-- include/nuttx/sensors/lis331dl.h | 7 ++++++- include/nuttx/sensors/lm75.h | 17 +++++++++++++---- include/nuttx/sensors/lm92.h | 9 +++++---- include/nuttx/sensors/mpl115a.h | 12 ++++++++++-- 14 files changed, 91 insertions(+), 27 deletions(-) diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 19bdedae26..fbb7118b85 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -7,6 +7,7 @@ config AS5048B bool "AMS AS5048B Magnetic Rotary Encoder support" default n select I2C + select QENCODER ---help--- Enable driver support for the AMS AS5048B magnetic rotary encoder. @@ -21,6 +22,7 @@ config LIS331DL bool "ST LIS331DL device support" default n select I2C + select I2C_TRANSFER config MPL115A bool "Freescale MPL115A Barometer Sensor support" diff --git a/drivers/sensors/adxl345_i2c.c b/drivers/sensors/adxl345_i2c.c index fb2c786135..9b905b7b97 100644 --- a/drivers/sensors/adxl345_i2c.c +++ b/drivers/sensors/adxl345_i2c.c @@ -46,6 +46,7 @@ #include #include +#include #include #include "adxl345.h" diff --git a/drivers/sensors/adxl345_spi.c b/drivers/sensors/adxl345_spi.c index 2f3b4894fb..a87765e819 100644 --- a/drivers/sensors/adxl345_spi.c +++ b/drivers/sensors/adxl345_spi.c @@ -46,6 +46,7 @@ #include #include +#include #include #include "adxl345.h" diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index ec44a72868..10cf8d360a 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -46,8 +46,11 @@ #include #include +#include #include +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -373,3 +376,5 @@ lis331dl_getreadings(FAR struct lis331dl_dev_s * dev) return NULL; } + +#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */ diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index e11e3f725f..7c47f86710 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -103,10 +103,10 @@ static const struct file_operations g_lm75fops = lm75_close, lm75_read, lm75_write, - 0, + NULL, lm75_ioctl #ifndef CONFIG_DISABLE_POLL - , 0 + , NULL #endif }; @@ -377,6 +377,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READCONF: { FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm75_readconf(priv, ptr); sndbg("conf: %02x ret: %d\n", *ptr, ret); } @@ -438,6 +439,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTHYS: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm75_readb16(priv, LM75_THYS_REG, ptr); sndbg("THYS: %08x ret: %d\n", *ptr, ret); } @@ -455,6 +457,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTOS: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm75_readb16(priv, LM75_TOS_REG, ptr); sndbg("TOS: %08x ret: %d\n", *ptr, ret); } @@ -503,10 +506,18 @@ int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t ad FAR struct lm75_dev_s *priv; int ret; + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + DEBUGASSERT(addr == CONFIG_LM75_ADDR0 || addr == CONFIG_LM75_ADDR1 || + addr == CONFIG_LM75_ADDR2 || addr == CONFIG_LM75_ADDR3 || + addr == CONFIG_LM75_ADDR4 || addr == CONFIG_LM75_ADDR5 || + addr == CONFIG_LM75_ADDR6 || addr == CONFIG_LM75_ADDR7); + /* Initialize the LM-75 device structure */ priv = (FAR struct lm75_dev_s *)kmm_malloc(sizeof(struct lm75_dev_s)); - if (!priv) + if (priv == NULL) { sndbg("Failed to allocate instance\n"); return -ENOMEM; diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 618b3d3290..f2fa27f65b 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -107,10 +107,10 @@ static const struct file_operations g_lm92fops = lm92_close, lm92_read, lm92_write, - 0, + NULL, lm92_ioctl #ifndef CONFIG_DISABLE_POLL - , 0 + , NULL #endif }; @@ -423,6 +423,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READCONF: { FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readconf(priv, ptr); sndbg("conf: %02x ret: %d\n", *ptr, ret); } @@ -484,6 +485,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTHYS: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readb16(priv, LM92_THYS_REG, ptr); sndbg("THYS: %08x ret: %d\n", *ptr, ret); } @@ -501,6 +503,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTCRIT: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readb16(priv, LM92_TCRIT_REG, ptr); sndbg("TCRIT: %08x ret: %d\n", *ptr, ret); } @@ -518,6 +521,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTLOW: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readb16(priv, LM92_TLOW_REG, ptr); sndbg("TLOW: %08x ret: %d\n", *ptr, ret); } @@ -535,6 +539,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READTHIGH: { FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readb16(priv, LM92_THIGH_REG, ptr); sndbg("THIGH: %08x ret: %d\n", *ptr, ret); } @@ -552,6 +557,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_READID: { FAR uint16_t *ptr = (FAR uint16_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); ret = lm92_readid(priv, ptr); sndbg("id: %04x ret: %d\n", *ptr, ret); } @@ -595,10 +601,16 @@ int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, FAR struct lm92_dev_s *priv; int ret; + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + DEBUGASSERT(addr == CONFIG_LM92_ADDR0 || addr == CONFIG_LM92_ADDR1 || + addr == CONFIG_LM92_ADDR2 || addr == CONFIG_LM92_ADDR3); + /* Initialize the LM92 device structure */ priv = (FAR struct lm92_dev_s *)kmm_malloc(sizeof(struct lm92_dev_s)); - if (!priv) + if (priv == NULL) { sndbg("Failed to allocate instance\n"); return -ENOMEM; diff --git a/drivers/sensors/mpl115a.c b/drivers/sensors/mpl115a.c index a5b940ab7b..f3d1bff907 100644 --- a/drivers/sensors/mpl115a.c +++ b/drivers/sensors/mpl115a.c @@ -212,8 +212,6 @@ static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv) static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv) { - uint16_t pressure; - /* Start a new conversion */ mpl115a_getreg8(priv, (MPL115A_CONVERT << 1)); diff --git a/include/nuttx/sensors/adxl345.h b/include/nuttx/sensors/adxl345.h index 4e806d5ea0..9655e84f69 100644 --- a/include/nuttx/sensors/adxl345.h +++ b/include/nuttx/sensors/adxl345.h @@ -41,10 +41,6 @@ ********************************************************************************************/ #include - -#include -#include - #include #if defined(CONFIG_SENSORS_ADXL345) @@ -329,6 +325,9 @@ struct adxl345_config_s typedef FAR void *ADXL345_HANDLE; +struct i2c_dev_s; +struct spi_dev_s; + /******************************************************************************************** * Public Function Prototypes ********************************************************************************************/ diff --git a/include/nuttx/sensors/as5048b.h b/include/nuttx/sensors/as5048b.h index b28c86ae7c..6a6de4eef0 100644 --- a/include/nuttx/sensors/as5048b.h +++ b/include/nuttx/sensors/as5048b.h @@ -41,8 +41,6 @@ ****************************************************************************/ #include -#include -#include #include #if defined(CONFIG_I2C) && defined(CONFIG_QENCODER) && defined(CONFIG_AS5048B) @@ -97,6 +95,12 @@ #define AS5048B_DIAG_COMPLOW (1 << 2) /* High Magnetic Field */ #define AS5048B_DIAG_COMPHIGH (1 << 3) /* Low Magnetic Field */ +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_dev_s; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/include/nuttx/sensors/bmp180.h b/include/nuttx/sensors/bmp180.h index 668ce62815..505aa72488 100644 --- a/include/nuttx/sensors/bmp180.h +++ b/include/nuttx/sensors/bmp180.h @@ -36,7 +36,9 @@ #ifndef __DRIVERS_SENSORS_BMP180_H #define __DRIVERS_SENSORS_BMP180_H -#if defined(CONFIG_BMP180) +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_BMP180) /******************************************************************************************** * Pre-processor Definitions @@ -53,6 +55,12 @@ * Enable very low register-level debug output. Requires CONFIG_DEBUG. */ +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_dev_s; + /******************************************************************************************** * Public Function Prototypes ********************************************************************************************/ @@ -88,5 +96,5 @@ int bmp180_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c); } #endif -#endif /* CONFIG_BMP180 */ +#endif /* CONFIG_I2C && CONFIG_BMP180 */ #endif /* __DRIVERS_BMP180_H */ diff --git a/include/nuttx/sensors/lis331dl.h b/include/nuttx/sensors/lis331dl.h index 2025e82952..6006288463 100644 --- a/include/nuttx/sensors/lis331dl.h +++ b/include/nuttx/sensors/lis331dl.h @@ -38,9 +38,11 @@ #ifndef __INCLUDE_NUTTX_SENSORS_LIS331DL_H #define __INCLUDE_NUTTX_SENSORS_LIS331DL_H -#include +#include #include +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL) + /************************************************************************************ * Pre-Processor Declarations ************************************************************************************/ @@ -69,6 +71,8 @@ struct lis331dl_vector_s int8_t z; }; +struct i2c_dev_s; + /************************************************************************************ * Public Function Prototypes ************************************************************************************/ @@ -204,4 +208,5 @@ FAR const struct lis331dl_vector_s * #endif #endif /* __ASSEMBLY__ */ +#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */ #endif /* __INCLUDE_NUTTX_SENSORS_LIS331DL_H */ diff --git a/include/nuttx/sensors/lm75.h b/include/nuttx/sensors/lm75.h index 75f8d95f02..a343a54874 100644 --- a/include/nuttx/sensors/lm75.h +++ b/include/nuttx/sensors/lm75.h @@ -43,6 +43,8 @@ #include #include +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -52,6 +54,14 @@ */ #define CONFIG_LM75_BASEADDR 0x48 +#define CONFIG_LM75_ADDR0 (CONFIG_LM75_BASEADDR + 0) +#define CONFIG_LM75_ADDR1 (CONFIG_LM75_BASEADDR + 1) +#define CONFIG_LM75_ADDR2 (CONFIG_LM75_BASEADDR + 2) +#define CONFIG_LM75_ADDR3 (CONFIG_LM75_BASEADDR + 3) +#define CONFIG_LM75_ADDR4 (CONFIG_LM75_BASEADDR + 4) +#define CONFIG_LM75_ADDR5 (CONFIG_LM75_BASEADDR + 5) +#define CONFIG_LM75_ADDR6 (CONFIG_LM75_BASEADDR + 6) +#define CONFIG_LM75_ADDR7 (CONFIG_LM75_BASEADDR + 7) /* IOCTL Commands ***********************************************************/ @@ -86,12 +96,10 @@ */ /**************************************************************************** - * Public Data + * Public Types ****************************************************************************/ -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +struct i2c_dev_s; /**************************************************************************** * Public Function Prototypes @@ -131,4 +139,5 @@ int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, } #endif +#endif /* CONFIG_I2C && CONFIG_I2C_LM75 */ #endif /* __INCLUDE_NUTTX_SENSORS_LM75_H */ diff --git a/include/nuttx/sensors/lm92.h b/include/nuttx/sensors/lm92.h index d0fcea8fec..16266568a8 100644 --- a/include/nuttx/sensors/lm92.h +++ b/include/nuttx/sensors/lm92.h @@ -45,6 +45,8 @@ #include #include +#if defined(CONFIG_I2C) && defined(CONFIG_LM92) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -101,12 +103,10 @@ */ /**************************************************************************** - * Public Data + * Public Types ****************************************************************************/ -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +struct i2c_dev_s; /**************************************************************************** * Public Function Prototypes @@ -147,4 +147,5 @@ int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, } #endif +#endif /* CONFIG_I2C && CONFIG_LM92 */ #endif /* __INCLUDE_NUTTX_SENSORS_LM92_H */ diff --git a/include/nuttx/sensors/mpl115a.h b/include/nuttx/sensors/mpl115a.h index 9aa6049573..c958c8025d 100644 --- a/include/nuttx/sensors/mpl115a.h +++ b/include/nuttx/sensors/mpl115a.h @@ -36,7 +36,9 @@ #ifndef __DRIVERS_SENSORS_MPL115A_H #define __DRIVERS_SENSORS_MPL115A_H -#if defined(CONFIG_MPL115A) +#include + +#if defined(CONFIG_SPI) && defined(CONFIG_MPL115A) /******************************************************************************************** * Pre-processor Definitions @@ -83,6 +85,12 @@ /* 0x0c - 0x11 are reserved */ #define MPL115A_CONVERT 0x12 /* Start Pressure and Temperature Conversion */ +/******************************************************************************************** + * Public Types + ********************************************************************************************/ + +struct spi_dev_s; + /******************************************************************************************** * Public Function Prototypes ********************************************************************************************/ @@ -118,5 +126,5 @@ int mpl115a_register(FAR const char *devpath, FAR struct spi_dev_s *spi); } #endif -#endif /* CONFIG_SENSORS_MPL115A */ +#endif /* CONFIG_SPI && CONFIG_MPL115A */ #endif /* __DRIVERS_SENSORS_MPL115A_H */ -- GitLab From e0238df359dc4a540d8ae37c55bf1b535775e4cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Aug 2015 12:23:53 -0600 Subject: [PATCH 007/858] SPI Slave: Summarize DMA issues in SPI slave header file --- include/nuttx/spi/slave.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/include/nuttx/spi/slave.h b/include/nuttx/spi/slave.h index 2fb7dd3762..ac551e79f6 100644 --- a/include/nuttx/spi/slave.h +++ b/include/nuttx/spi/slave.h @@ -387,7 +387,42 @@ * upon it. * * A typical DMA data transfer processes as follows: - * To be provided + * To be provided -- I do not have a design in mind to support DMA on the + * Slave side. The design might be very complex because: + * + * 1) You need DMA buffers of fixed size, but you cannot know the size of a + * transfer in advance, it could be much larger than your buffer or much + * smaller. The DMA would fail in either case. + * + * 2) You cannot setup the DMA before the transfer. In most SPI protocols, + * the first word send is a command to read or write something following + * by a sequence of transfers to implement the write. So you have very, + * very limited time window to setup the correct DMA to respond to the + * command. DMA setup time can be longer. And I am not sure it I can + * make it reliable. + * + * 3) I mentioned that you do not know the size of the transfer in advance. + * If you set up the DMA to terminate to soon, then you lose the last part + * of the transfer. If you set the DMA up to be too large, then you will + * get no indication when the transfer completes. + * + * The chip select going high would be one possibility to detect the end + * of a transfer. You could cancel a DMA in progress if the CS changes, + * but I do not know if that would work. If there is only one device on + * the SPI bus, then most board designs will save a pin and simply tie CS + * to ground. So the CS is not always a reliable indicator of when the + * transfer completes. + * + * 4) The option is to use a timer but that would really slow down the + * transfers if each DMA has to end with a timeout. It would be faster + * non-DMA transfers. + * + * If the device as a very restricted protocol, like just register reads + * and writes, then it might possible to implement DMA. However, that + * solution would not be general and probably not an appropriate part of + * a general OS. But if the interface is unpredictable, such as reading/ + * variable amounts of data from FLASH, there is more risk. A general + * solution might not be possible. */ enum spi_smode_e -- GitLab From 7d041044852d6df1c8fc59b1941d91e3f7f9a0d3 Mon Sep 17 00:00:00 2001 From: Max Neklyudov Date: Tue, 11 Aug 2015 07:55:40 -0600 Subject: [PATCH 008/858] Networking: Allow receipt of empty UDP packets. From Max Neklyudov --- ChangeLog | 9 +++--- net/iob/iob_copyout.c | 6 ++++ net/socket/recvfrom.c | 30 ++++++++++++------- net/udp/udp_callback.c | 66 +++++++++++++++++++++--------------------- 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 229e496b8a..eed77b2bee 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10797,10 +10797,11 @@ * arch/arm/src/samv7: Add the framework for an SPI slave drvier. This driver has a lot of missing logic on initial commit (2015-08-09). * arch/arm/src/samv7: Basic, no-DMA SPI slave driver is in place - (2015-080=-10). + (2015-08-10). * fs/vfs/epoll.c and include/sys/epoll.h: Add a very simple epoll layer just around poll calls. To satisfy build app requirements. From Anton - D. Kachalov. + D. Kachalov (2015-08-10). * drivers/mtd/ramtron.c: Update to include supportf for newer - RAMTRON parts. From David Sidrane. - + RAMTRON parts. From David Sidrane (2015-08-10). + * Networking: Allow receipt of empty UDP packets. From Max Neklyudov + (2015-08-11). diff --git a/net/iob/iob_copyout.c b/net/iob/iob_copyout.c index 300b63df81..e7b682651c 100644 --- a/net/iob/iob_copyout.c +++ b/net/iob/iob_copyout.c @@ -101,6 +101,12 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob, { offset -= iob->io_len; iob = iob->io_flink; + if (iob == NULL) + { + /* We have no requested data in iob chain */ + + return 0; + } } /* Then loop until all of the I/O data is copied to the user buffer */ diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index cf26072ac9..32b2067ffc 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -101,7 +101,7 @@ struct recvfrom_s uint8_t *rf_buffer; /* Pointer to receive buffer */ FAR struct sockaddr *rf_from; /* Address of sender */ FAR socklen_t *rf_fromlen; /* Number of bytes allocated for address of sender */ - size_t rf_recvlen; /* The received length */ + ssize_t rf_recvlen; /* The received length */ int rf_result; /* Success:OK, failure:negated errno */ }; #endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ @@ -404,8 +404,9 @@ static inline void recvfrom_udpreadahead(struct recvfrom_s *pstate) * buffer. */ - if ((iob = iob_peek_queue(&conn->readahead)) != NULL && - pstate->rf_buflen > 0) + pstate->rf_recvlen = -1; + + if ((iob = iob_peek_queue(&conn->readahead)) != NULL) { FAR struct iob_s *tmp; uint8_t src_addr_size; @@ -445,16 +446,23 @@ static inline void recvfrom_udpreadahead(struct recvfrom_s *pstate) } } - recvlen = iob_copyout(pstate->rf_buffer, iob, pstate->rf_buflen, - src_addr_size + sizeof(uint8_t)); + if (pstate->rf_buflen > 0) + { + recvlen = iob_copyout(pstate->rf_buffer, iob, pstate->rf_buflen, + src_addr_size + sizeof(uint8_t)); - nllvdbg("Received %d bytes (of %d)\n", recvlen, iob->io_pktlen); + nllvdbg("Received %d bytes (of %d)\n", recvlen, iob->io_pktlen); - /* Update the accumulated size of the data read */ + /* Update the accumulated size of the data read */ - pstate->rf_recvlen += recvlen; - pstate->rf_buffer += recvlen; - pstate->rf_buflen -= recvlen; + pstate->rf_recvlen = recvlen; + pstate->rf_buffer += recvlen; + pstate->rf_buflen -= recvlen; + } + else + { + pstate->rf_recvlen = 0; + } out: /* Remove the I/O buffer chain from the head of the read-ahead @@ -1482,7 +1490,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, * something was received (already in 'ret'); EAGAIN if not. */ - if (ret <= 0) + if (ret < 0) { /* Nothing was received */ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index f99aa2eac1..1f09ede313 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -200,19 +200,23 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con return 0; } - /* Copy the new appdata into the I/O buffer chain */ - - ret = iob_trycopyin(iob, buffer, buflen, src_addr_size + sizeof(uint8_t), - true); - if (ret < 0) + if (buflen > 0) { - /* On a failure, iob_trycopyin return a negated error value but does - * not free any I/O buffers. - */ + /* Copy the new appdata into the I/O buffer chain */ - nlldbg("ERROR: Failed to add data to the I/O buffer chain: %d\n", ret); - (void)iob_free_chain(iob); - return 0; + ret = iob_trycopyin(iob, buffer, buflen, + src_addr_size + sizeof(uint8_t), true); + if (ret < 0) + { + /* On a failure, iob_trycopyin return a negated error value but + * does not free any I/O buffers. + */ + + nlldbg("ERROR: Failed to add data to the I/O buffer chain: %d\n", + ret); + (void)iob_free_chain(iob); + return 0; + } } /* Add the new I/O buffer chain to the tail of the read-ahead queue */ @@ -243,6 +247,11 @@ net_dataevent(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, uint16_t flags) { uint16_t ret; +#ifdef CONFIG_NET_UDP_READAHEAD + uint8_t *buffer = dev->d_appdata; + int buflen = dev->d_len; + uint16_t recvlen; +#endif ret = (flags & ~UDP_NEWDATA); @@ -250,35 +259,26 @@ net_dataevent(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, * can have zero-length with UDP_NEWDATA set just to cause an ACK). */ - if (dev->d_len > 0) - { -#ifdef CONFIG_NET_UDP_READAHEAD - uint8_t *buffer = dev->d_appdata; - int buflen = dev->d_len; - uint16_t recvlen; -#endif - - nllvdbg("No receive on connection\n"); + nllvdbg("No receive on connection\n"); #ifdef CONFIG_NET_UDP_READAHEAD - /* Save as the packet data as in the read-ahead buffer. NOTE that - * partial packets will not be buffered. - */ + /* Save as the packet data as in the read-ahead buffer. NOTE that + * partial packets will not be buffered. + */ - recvlen = udp_datahandler(dev, conn, buffer, buflen); - if (recvlen < buflen) + recvlen = udp_datahandler(dev, conn, buffer, buflen); + if (recvlen < buflen) #endif - { - /* There is no handler to receive new data and there are no free - * read-ahead buffers to retain the data -- drop the packet. - */ + { + /* There is no handler to receive new data and there are no free + * read-ahead buffers to retain the data -- drop the packet. + */ - nllvdbg("Dropped %d bytes\n", dev->d_len); + nllvdbg("Dropped %d bytes\n", dev->d_len); - #ifdef CONFIG_NET_STATISTICS - g_netstats.udp.drop++; +#ifdef CONFIG_NET_STATISTICS + g_netstats.udp.drop++; #endif - } } /* In any event, the new data has now been handled */ -- GitLab From 7791b2a62ea85105ae4cf1e6aaacbc5727d11743 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 07:56:26 -0600 Subject: [PATCH 009/858] Refresh submodules + Update comments in SPI slave header file --- arch | 2 +- configs | 2 +- include/nuttx/spi/slave.h | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 6190d66466..da550063e6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6190d664666b19580969c4e620646ef4e54f0182 +Subproject commit da550063e6081057d2324b76c8ac065ed6fe1d6f diff --git a/configs b/configs index ac4035687c..c779f69eb4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ac4035687c824bb4a573e06feb017cb4f3ce7626 +Subproject commit c779f69eb4070272ef136a27124223bddafec5a1 diff --git a/include/nuttx/spi/slave.h b/include/nuttx/spi/slave.h index ac551e79f6..eb557252e6 100644 --- a/include/nuttx/spi/slave.h +++ b/include/nuttx/spi/slave.h @@ -398,8 +398,10 @@ * the first word send is a command to read or write something following * by a sequence of transfers to implement the write. So you have very, * very limited time window to setup the correct DMA to respond to the - * command. DMA setup time can be longer. And I am not sure it I can - * make it reliable. + * command. I am not certain that it can be done reliably. + * + * Inserting dummy words into the protocol between the first command word + * and the remaining data transfer could allow time to set up the DMA. * * 3) I mentioned that you do not know the size of the transfer in advance. * If you set up the DMA to terminate to soon, then you lose the last part -- GitLab From 9c9fc419e805594d6080b0013ccfbe75ae6c150a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 08:33:14 -0600 Subject: [PATCH 010/858] Fix error in handling CONFIG_APPS_DIR in configure.sh. From Krishna Kumar --- tools/configure.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/configure.sh b/tools/configure.sh index 2de790506e..3ee734d6e9 100755 --- a/tools/configure.sh +++ b/tools/configure.sh @@ -144,7 +144,7 @@ winnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2` defappdir=y if [ -z "${appdir}" ]; then quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2` - if [ ! -z "${appdir}" ]; then + if [ ! -z "${quoted}" ]; then appdir=`echo ${quoted} | sed -e "s/\"//g"` defappdir=n fi @@ -165,7 +165,6 @@ if [ -z "${appdir}" ]; then if [ -d "${TOPDIR}/../apps" ]; then appdir="../apps" - else # Check for a versioned apps/ directory -- GitLab From a634ad55286073ebe6214d5ddc8803ec0d2262b5 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 11 Aug 2015 10:03:10 -0400 Subject: [PATCH 011/858] Added MB7040 sonar. --- drivers/sensors/Kconfig | 7 + drivers/sensors/Make.defs | 4 + drivers/sensors/mb7040.c | 373 +++++++++++++++++++++++++++++++++ include/nuttx/sensors/mb7040.h | 120 +++++++++++ 4 files changed, 504 insertions(+) create mode 100644 drivers/sensors/mb7040.c create mode 100644 include/nuttx/sensors/mb7040.h diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index fbb7118b85..71df93e31d 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -24,6 +24,13 @@ config LIS331DL select I2C select I2C_TRANSFER +config MB7040 + bool "MaxBotix MB7040 Sonar support" + default n + select I2C + ---help--- + Enable driver support for the MaxBotix MB7040 sonar. + config MPL115A bool "Freescale MPL115A Barometer Sensor support" default n diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 0d86e8e9f7..7b1e1952db 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -69,6 +69,10 @@ ifeq ($(CONFIG_LM92),y) CSRCS += lm92.c endif +ifeq ($(CONFIG_MB7040),y) + CSRCS += mb7040.c +endif + endif # CONFIG_I2C # These drivers depend on SPI support diff --git a/drivers/sensors/mb7040.c b/drivers/sensors/mb7040.c new file mode 100644 index 0000000000..16c853421a --- /dev/null +++ b/drivers/sensors/mb7040.c @@ -0,0 +1,373 @@ +/**************************************************************************** + * drivers/sensors/mb7040.c + * Character driver for the MaxBotix MB7040 Sonar + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MB7040) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct mb7040_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* I2C Helpers */ + +static int mb7040_measurerange(FAR struct mb7040_dev_s *priv); +static int mb7040_readrange(FAR struct mb7040_dev_s *priv, + FAR uint16_t *range); +static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr); + +/* Character Driver Methods */ + +static int mb7040_open(FAR struct file *filep); +static int mb7040_close(FAR struct file *filep); +static ssize_t mb7040_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t mb7040_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int mb7040_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_fops = +{ + mb7040_open, + mb7040_close, + mb7040_read, + mb7040_write, + NULL, + mb7040_ioctl +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mb7040_measurerange + * + * Description: + * Command the device to measure the range. + * + ****************************************************************************/ + +static int mb7040_measurerange(FAR struct mb7040_dev_s *priv) +{ + uint8_t regaddr; + int ret; + + regaddr = MB7040_RANGE_REG; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: mb7040_readrange + * + * Description: + * Read the range last measured by the device. The units are centimeters. + * + ****************************************************************************/ + +static int mb7040_readrange(FAR struct mb7040_dev_s *priv, + FAR uint16_t *range) +{ + uint8_t buffer[2]; + int ret; + + /* Read two bytes */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + *range = (uint16_t)buffer[0] << 8 | (uint16_t)buffer[1]; + sndbg("range: %04x ret: %d\n", *range, ret); + return ret; +} + +/**************************************************************************** + * Name: mb7040_changeaddr + * + * Description: + * Change the device's I2C address. + * + ****************************************************************************/ + +static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr) +{ + uint8_t buffer[3]; + int ret; + + sndbg("new addr: %02x\n", addr); + + /* Sanity check */ + + DEBUGASSERT((addr & 1) == 0); + DEBUGASSERT(addr != 0x00 && addr != 0x50 && addr != 0xa4 && addr != 0xaa); + + /* Set up a 3-byte message to send */ + + buffer[0] = MB7040_ADDRUNLOCK1_REG; + buffer[1] = MB7040_ADDRUNLOCK2_REG; + buffer[2] = addr; + + /* Write the register address followed by the data (no RESTART) */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + priv->addr = addr; + return ret; +} + +/**************************************************************************** + * Name: mb7040_open + * + * Description: + * This method is called when the device is opened. + * + ****************************************************************************/ + +static int mb7040_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: mb7040_close + * + * Description: + * This method is called when the device is closed. + * + ****************************************************************************/ + +static int mb7040_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: mb7040_read + * + * Description: + * A dummy read method. + * + ****************************************************************************/ + +static ssize_t mb7040_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + return 0; +} + +/**************************************************************************** + * Name: mb7040_write + * + * Description: + * A dummy write method. + * + ****************************************************************************/ + +static ssize_t mb7040_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: mb7040_ioctl + * + * Description: + * The standard ioctl method. + * + ****************************************************************************/ + +static int mb7040_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct mb7040_dev_s *priv = inode->i_private; + int ret = OK; + + /* Handle ioctl commands */ + + switch (cmd) + { + /* Command the device to measure the range. Arg: None. */ + + case SNIOC_MEASURE: + DEBUGASSERT(arg == 0); + ret = mb7040_measurerange(priv); + break; + + /* Read the range last measured by the device. Arg: int32_t* pointer. */ + + case SNIOC_RANGE: + { + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + uint16_t range = 0; + DEBUGASSERT(ptr != NULL); + ret = mb7040_readrange(priv, &range); + if (ret == OK) + { + *ptr = (int32_t)range; + } + sndbg("range: %04x ret: %d\n", *ptr, ret); + } + break; + + /* Change the device's I2C address. Arg: uint8_t value. */ + + case SNIOC_CHANGEADDR: + ret = mb7040_changeaddr(priv, (uint8_t)arg); + sndbg("new addr: %02x ret: %d\n", *(uint8_t *)arg, ret); + break; + + /* Unrecognized commands */ + + default: + sndbg("Unrecognized cmd: %d arg: %ld\n", cmd, arg); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mb7040_register + * + * Description: + * Register the MB7040 character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/sonar0". + * i2c - An I2C driver instance. + * addr - The I2C address of the MB7040. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int mb7040_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr) +{ + FAR struct mb7040_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + + /* Initialize the device's structure */ + + priv = (FAR struct mb7040_dev_s *)kmm_malloc(sizeof(*priv)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + + /* Register the character driver */ + + ret = register_driver(devpath, &g_fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + return ret; +} + +#endif /* CONFIG_I2C && CONFIG_MB7040 */ diff --git a/include/nuttx/sensors/mb7040.h b/include/nuttx/sensors/mb7040.h new file mode 100644 index 0000000000..f3359ea1f3 --- /dev/null +++ b/include/nuttx/sensors/mb7040.h @@ -0,0 +1,120 @@ +/**************************************************************************** + * include/nuttx/sensors/mb7040.h + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_MB7040 +#define __INCLUDE_NUTTX_SENSORS_MB7040 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MB7040) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************ + * Prerequisites: + * + * CONFIG_I2C + * Enables support for I2C drivers + * CONFIG_MB7040 + * Enables support for the MB7040 driver + */ + +/* IOCTL Commands ***********************************************************/ + +#define SNIOC_MEASURE _SNIOC(0x0001) /* Arg: None */ +#define SNIOC_RANGE _SNIOC(0x0002) /* Arg: int32_t* pointer */ +#define SNIOC_CHANGEADDR _SNIOC(0x0003) /* Arg: uint8_t value */ + +/* I2C Addresses ************************************************************/ + +#define MB7040_DEFAULTADDR 0x70 /* Default I2C Address */ + +/* Register Definitions *****************************************************/ +/* Register Addresses */ + +#define MB7040_RANGE_REG 0x51 +#define MB7040_ADDRUNLOCK1_REG 0xaa +#define MB7040_ADDRUNLOCK2_REG 0xa5 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: mb7040_register + * + * Description: + * Register the MB7040 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/sonar0". + * i2c - An I2C driver instance. + * addr - The I2C address of the MB7040. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int mb7040_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_MB7040 */ +#endif /* __INCLUDE_NUTTX_SENSORS_MB7040 */ -- GitLab From b2a2176123b3c0eacaaf9c4f448700c3c59381c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 09:31:12 -0600 Subject: [PATCH 012/858] Refresh submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index da550063e6..56596fd000 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit da550063e6081057d2324b76c8ac065ed6fe1d6f +Subproject commit 56596fd0001c1906600d7806e67e92040ed99183 diff --git a/configs b/configs index c779f69eb4..d22ff0b3ff 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c779f69eb4070272ef136a27124223bddafec5a1 +Subproject commit d22ff0b3ff36cd5e324538b74b8064edaa3b63d8 -- GitLab From 29a0d5d23cb26adcfa50a6a3b1ce1633cc0b6fd6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 12:29:49 -0600 Subject: [PATCH 013/858] Update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index eed77b2bee..209b040945 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10805,3 +10805,5 @@ RAMTRON parts. From David Sidrane (2015-08-10). * Networking: Allow receipt of empty UDP packets. From Max Neklyudov (2015-08-11). + * drivers/sensors/mb7040.c and include/nuttx/sensors/mb7040.h: Add + support Added MB7040 sonar. From Paul Alexander Patience (2015-08-07). -- GitLab From 597a7b2f529e40b0aa5be2fde342f0ac850746be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 16:13:05 -0600 Subject: [PATCH 014/858] Update TODO list --- TODO | 20 ++++++++++++++++++-- arch | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index b63ea6f646..8812ad5fad 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 6, 2015) +NuttX TODO List (Last updated August 11, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -16,7 +16,7 @@ nuttx/ (0) Message Queues (sched/mqueue) (4) C++ Support (6) Binary loaders (binfmt/) - (12) Network (net/, drivers/net) + (13) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (12) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) @@ -990,6 +990,22 @@ o Network (net/, drivers/net) Priority: Low. I don't know of any issues now, but I am sure that someone will encounter this in the future. + Title: USING send() WITH UDP CONNECTIONS. + Description: Currently send is not implemented unless TCP is enabled. If + TCP is enabled and send() is called with a UDP socket, send() + will fail with EDESTADDRREQ. According to OpenGroup.org: + + "The send() function shall initiate transmission of a message + from the specified socket to its peer. The send() function + shall send a message only when the socket is connected + (including when the peer of a connectionless socket has been + set via connect()). + + This means that, internally, send() should detect the "connected" + UDP socket and automatically call sendto(). + Status: Open + Priority: Low, there is always the work-around of just calling sendto(). + o USB (drivers/usbdev, drivers/usbhost) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/arch b/arch index 56596fd000..5d220dfb29 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 56596fd0001c1906600d7806e67e92040ed99183 +Subproject commit 5d220dfb291e8184b71fd13590e820a6026b7770 -- GitLab From 97ce03737b24c2cb1a8b683ea9fef00a67bf4f46 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 17:35:00 -0600 Subject: [PATCH 015/858] Top-level Makefiles: Add an application pre-configuration target --- Makefile.unix | 18 ++++++++++++------ Makefile.win | 14 ++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Makefile.unix b/Makefile.unix index 3e6442bb56..7d02fed717 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -1,7 +1,7 @@ ############################################################################ # Makefile.unix # -# Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2012, 2014-2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -473,19 +473,19 @@ pass2dep: context tools/mkdeps$(HOSTEXEEXT) # location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See # README.txt file in the NuttX tools GIT repository for additional information. -config: +config: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf Kconfig -oldconfig: +oldconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --oldconfig Kconfig -menuconfig: +menuconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-mconf Kconfig -qconfig: +qconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-qconf Kconfig -gconfig: +gconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-gconf Kconfig # export @@ -556,11 +556,17 @@ endif # as a convenience, the following targets are included to support housekeeping # functions in the user application directory from the NuttX build directory. # +# apps_preconfig: Prepare applications to be configured # apps_clean: Perform the clean operation only in the user application # directory # apps_distclean: Perform the distclean operation only in the user application # directory. +apps_preconfig: +ifneq ($(APPDIR),) + $(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" preconfig +endif + apps_clean: ifneq ($(APPDIR),) $(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" clean diff --git a/Makefile.win b/Makefile.win index 1ff9ceefc1..4db50470a9 100644 --- a/Makefile.win +++ b/Makefile.win @@ -1,7 +1,7 @@ ############################################################################ # Makefile.win # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -476,13 +476,13 @@ pass2dep: context tools\mkdeps$(HOSTEXEEXT) # location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See # misc\tools\README.txt for additional information. -config: +config: apps_preconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf Kconfig -oldconfig: +oldconfig: apps_preconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --oldconfig Kconfig -menuconfig: configenv +menuconfig: configenv apps_preconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-mconf Kconfig # export @@ -545,11 +545,17 @@ endif # as a convenience, the following targets are included to support housekeeping # functions in the user application directory from the NuttX build directory. # +# apps_preconfig: Prepare applications to be configured # apps_clean: Perform the clean operation only in the user application # directory # apps_distclean: Perform the distclean operation only in the user application # directory. +apps_preconfig: +ifneq ($(APPDIR),) + $(Q) $(MAKE) -C "$(APPDIR)" TOPDIR="$(TOPDIR)" preconfig +endif + apps_clean: ifneq ($(APPDIR),) $(Q) $(MAKE) -C "$(APPDIR)" TOPDIR="$(TOPDIR)" clean -- GitLab From 530d2293610463579babbc5e16b36fcb5008ad40 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 19:17:55 -0600 Subject: [PATCH 016/858] net/udp: Add support for send() with connected UDP sockets --- ChangeLog | 5 +- TODO | 18 +-- net/socket/Make.defs | 16 +-- net/socket/connect.c | 8 ++ net/socket/send.c | 29 ++++- net/socket/sendto.c | 3 - net/udp/Make.defs | 2 +- net/udp/udp.h | 11 ++ net/udp/udp_psock_send.c | 130 +++++++++++++++++++ net/udp/{udp_sendto.c => udp_psock_sendto.c} | 2 +- 10 files changed, 189 insertions(+), 35 deletions(-) create mode 100644 net/udp/udp_psock_send.c rename net/udp/{udp_sendto.c => udp_psock_sendto.c} (99%) diff --git a/ChangeLog b/ChangeLog index 209b040945..5708819a94 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10806,4 +10806,7 @@ * Networking: Allow receipt of empty UDP packets. From Max Neklyudov (2015-08-11). * drivers/sensors/mb7040.c and include/nuttx/sensors/mb7040.h: Add - support Added MB7040 sonar. From Paul Alexander Patience (2015-08-07). + support Added MB7040 sonar. From Paul Alexander Patience (2015-08-11). + * net/udp: Add support for send() for connected UDP sockets + (2015-08-11). + diff --git a/TODO b/TODO index 8812ad5fad..b717d54c74 100644 --- a/TODO +++ b/TODO @@ -16,7 +16,7 @@ nuttx/ (0) Message Queues (sched/mqueue) (4) C++ Support (6) Binary loaders (binfmt/) - (13) Network (net/, drivers/net) + (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (12) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) @@ -990,22 +990,6 @@ o Network (net/, drivers/net) Priority: Low. I don't know of any issues now, but I am sure that someone will encounter this in the future. - Title: USING send() WITH UDP CONNECTIONS. - Description: Currently send is not implemented unless TCP is enabled. If - TCP is enabled and send() is called with a UDP socket, send() - will fail with EDESTADDRREQ. According to OpenGroup.org: - - "The send() function shall initiate transmission of a message - from the specified socket to its peer. The send() function - shall send a message only when the socket is connected - (including when the peer of a connectionless socket has been - set via connect()). - - This means that, internally, send() should detect the "connected" - UDP socket and automatically call sendto(). - Status: Open - Priority: Low, there is always the work-around of just calling sendto(). - o USB (drivers/usbdev, drivers/usbhost) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/net/socket/Make.defs b/net/socket/Make.defs index ca4dab4d77..cfb6233bd1 100644 --- a/net/socket/Make.defs +++ b/net/socket/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # net/socket/Make.defs # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,21 +35,19 @@ # Include socket source files -SOCK_CSRCS += bind.c connect.c getsockname.c recv.c recvfrom.c socket.c -SOCK_CSRCS += sendto.c net_sockets.c net_close.c net_dupsd.c net_dupsd2.c -SOCK_CSRCS += net_clone.c net_poll.c net_vfcntl.c +SOCK_CSRCS += bind.c connect.c getsockname.c recv.c recvfrom.c send.c +SOCK_CSRCS += sendto.c socket.c net_sockets.c net_close.c net_dupsd.c +SOCK_CSRCS += net_dupsd2.c net_clone.c net_poll.c net_vfcntl.c # TCP/IP support ifeq ($(CONFIG_NET_TCP),y) -SOCK_CSRCS += send.c listen.c accept.c net_monitor.c -else +SOCK_CSRCS += listen.c accept.c net_monitor.c # Local Unix domain support -ifeq ($(CONFIG_NET_LOCAL_STREAM),y) -SOCK_CSRCS += send.c listen.c accept.c -endif +else ifeq ($(CONFIG_NET_LOCAL_STREAM),y) +SOCK_CSRCS += listen.c accept.c endif # Socket options diff --git a/net/socket/connect.c b/net/socket/connect.c index 7360d611c6..77443a775e 100644 --- a/net/socket/connect.c +++ b/net/socket/connect.c @@ -621,6 +621,14 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, #endif { ret = udp_connect(psock->s_conn, addr); + if (ret < 0 || addr == NULL) + { + psock->s_flags &= ~_SF_CONNECTED; + } + else + { + psock->s_flags |= _SF_CONNECTED; + } } #endif /* CONFIG_NET_UDP */ diff --git a/net/socket/send.c b/net/socket/send.c index 771f4e9806..562152031c 100644 --- a/net/socket/send.c +++ b/net/socket/send.c @@ -38,13 +38,13 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL_STREAM) #include #include #include #include "tcp/tcp.h" +#include "udp/udp.h" #include "pkt/pkt.h" #include "local/local.h" #include "socket/socket.h" @@ -168,6 +168,31 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, break; #endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL_STREAM */ +#ifdef CONFIG_NET_UDP + case SOCK_DGRAM: + { +#ifdef CONFIG_NET_LOCAL_DGRAM +#ifdef CONFIG_NET_UDP + if (psock->s_domain == PF_LOCAL) +#endif + { +#warning Missing logic + ret = -ENOSYS; + } +#endif /* CONFIG_NET_LOCAL_DGRAM */ + +#ifdef CONFIG_NET_UDP +#ifdef CONFIG_NET_LOCAL_DGRAM + else +#endif + { + ret = psock_udp_send(psock, buf, len); + } +#endif /* CONFIG_NET_UDP */ + } + break; +#endif /* CONFIG_NET_UDP */ + default: { /* EDESTADDRREQ. Signifies that the socket is not connection-mode @@ -250,5 +275,3 @@ ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags) { return psock_send(sockfd_socket(sockfd), buf, len, flags); } - -#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL_STREAM */ diff --git a/net/socket/sendto.c b/net/socket/sendto.c index 3332f57916..193e3ae4fe 100644 --- a/net/socket/sendto.c +++ b/net/socket/sendto.c @@ -38,7 +38,6 @@ ****************************************************************************/ #include -#ifdef CONFIG_NET #include #include @@ -319,5 +318,3 @@ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags, return psock_sendto(psock, buf, len, flags, to, tolen); } - -#endif /* CONFIG_NET */ diff --git a/net/udp/Make.defs b/net/udp/Make.defs index 3b4d1062af..76c72b33ab 100644 --- a/net/udp/Make.defs +++ b/net/udp/Make.defs @@ -39,7 +39,7 @@ ifeq ($(CONFIG_NET_UDP),y) # Socket layer -NET_CSRCS += udp_sendto.c +NET_CSRCS += udp_psock_send.c udp_psock_sendto.c ifneq ($(CONFIG_DISABLE_POLL),y) ifeq ($(CONFIG_NET_UDP_READAHEAD),y) diff --git a/net/udp/udp.h b/net/udp/udp.h index 66612eef81..91447d2596 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -425,6 +425,17 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn); uint16_t udp_callback(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, uint16_t flags); +/**************************************************************************** + * Function: psock_udp_send + * + * Description: + * Implements send() for connected UDP sockets + * + ****************************************************************************/ + +ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf, + size_t len); + /**************************************************************************** * Function: psock_udp_sendto * diff --git a/net/udp/udp_psock_send.c b/net/udp/udp_psock_send.c new file mode 100644 index 0000000000..c53fa088e9 --- /dev/null +++ b/net/udp/udp_psock_send.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * net/udp/udp_send.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "socket/socket.h" +#include "udp/udp.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: psock_udp_send + * + * Description: + * Implements send() for connected UDP sockets + * + ****************************************************************************/ + +ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf, + size_t len) +{ + FAR struct udp_conn_s *conn; + union + { + struct sockaddr addr; +#ifdef CONFIG_NET_IPv4 + struct sockaddr_in addr4; +#endif +#ifdef CONFIG_NET_IPv6 + struct sockaddr_in6 addr6; +#endif + } to; + socklen_t tolen; + + DEBUGASSERT(psock != NULL && psock->s_crefs > 0); + DEBUGASSERT(psock->s_type != SOCK_DGRAM); + + conn = (FAR struct udp_conn_s *)psock->s_conn; + DEBUGASSERT(conn); + + /* Was the UDP socket connected via connect()? */ + + if (!_SS_ISCONNECTED(psock->s_flags)) + { + /* Now, then it is not legal to call send */ + + return -ENOTCONN; + } + + /* Yes, then let psock_sendto to the work */ + +#ifdef CONFIG_NET_IPv4 +#ifdef CONFIG_NET_IPv6 + if (conn->domain == PF_INET) +#endif + { + tolen = sizeof(struct sockaddr_in); + to.addr4.sin_family = AF_INET; + to.addr4.sin_port = conn->rport; + net_ipv4addr_copy(to.addr4.sin_addr.s_addr, conn->u.ipv4.raddr); + } +#endif /* CONFIG_NET_IPv4 */ + +#ifdef CONFIG_NET_IPv6 +#ifdef CONFIG_NET_IPv4 + else +#endif + { + tolen = sizeof(struct sockaddr_in6); + to.addr6.sin6_family = AF_INET6; + to.addr6.sin6_port = conn->rport; + net_ipv6addr_copy(to.addr6.sin6_addr.s6_addr, conn->u.ipv6.raddr); + } +#endif /* CONFIG_NET_IPv6 */ + + return psock_udp_sendto(psock, buf, len, 0, &to.addr, tolen); +} diff --git a/net/udp/udp_sendto.c b/net/udp/udp_psock_sendto.c similarity index 99% rename from net/udp/udp_sendto.c rename to net/udp/udp_psock_sendto.c index e1463f7fee..36ba573f25 100644 --- a/net/udp/udp_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/udp/udp_sendto.c + * net/udp/udp_psock_sendto.c * * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt -- GitLab From 850225223dbc346539fe8da5ef5ad178fb7b5ace Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 19:21:15 -0600 Subject: [PATCH 017/858] Costmetic fix to a comment --- net/udp/udp_psock_send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/udp/udp_psock_send.c b/net/udp/udp_psock_send.c index c53fa088e9..f54d9dd07c 100644 --- a/net/udp/udp_psock_send.c +++ b/net/udp/udp_psock_send.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/udp/udp_send.c + * net/udp/udp_psock_send.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt -- GitLab From 4c4868c69fda768b67373b0ea020b6a6a200b3db Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 19:23:51 -0600 Subject: [PATCH 018/858] More cosmetic changes: Fix some errors in comments and some indentation problems --- net/udp/udp_psock_send.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/net/udp/udp_psock_send.c b/net/udp/udp_psock_send.c index f54d9dd07c..b042d9c485 100644 --- a/net/udp/udp_psock_send.c +++ b/net/udp/udp_psock_send.c @@ -95,7 +95,7 @@ ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf, if (!_SS_ISCONNECTED(psock->s_flags)) { - /* Now, then it is not legal to call send */ + /* No, then it is not legal to call send() with this socket. */ return -ENOTCONN; } @@ -104,26 +104,26 @@ ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf, #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET) + if (conn->domain == PF_INET) #endif - { - tolen = sizeof(struct sockaddr_in); - to.addr4.sin_family = AF_INET; - to.addr4.sin_port = conn->rport; - net_ipv4addr_copy(to.addr4.sin_addr.s_addr, conn->u.ipv4.raddr); - } + { + tolen = sizeof(struct sockaddr_in); + to.addr4.sin_family = AF_INET; + to.addr4.sin_port = conn->rport; + net_ipv4addr_copy(to.addr4.sin_addr.s_addr, conn->u.ipv4.raddr); + } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else + else #endif - { - tolen = sizeof(struct sockaddr_in6); - to.addr6.sin6_family = AF_INET6; - to.addr6.sin6_port = conn->rport; - net_ipv6addr_copy(to.addr6.sin6_addr.s6_addr, conn->u.ipv6.raddr); - } + { + tolen = sizeof(struct sockaddr_in6); + to.addr6.sin6_family = AF_INET6; + to.addr6.sin6_port = conn->rport; + net_ipv6addr_copy(to.addr6.sin6_addr.s6_addr, conn->u.ipv6.raddr); + } #endif /* CONFIG_NET_IPv6 */ return psock_udp_sendto(psock, buf, len, 0, &to.addr, tolen); -- GitLab From c4b888b41d9e94612be878925249f9da8569964c Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 11 Aug 2015 15:05:56 -0400 Subject: [PATCH 019/858] Added MS5805 altimeter. --- drivers/sensors/Kconfig | 7 + drivers/sensors/Make.defs | 4 + drivers/sensors/ms5805.c | 715 +++++++++++++++++++++++++++++++++ include/nuttx/sensors/ms5805.h | 111 +++++ 4 files changed, 837 insertions(+) create mode 100644 drivers/sensors/ms5805.c create mode 100644 include/nuttx/sensors/ms5805.h diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 71df93e31d..adbedd6ae8 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -31,6 +31,13 @@ config MB7040 ---help--- Enable driver support for the MaxBotix MB7040 sonar. +config MS5805 + bool "MEAS MS5805 Altimeter support" + default n + select I2C + ---help--- + Enable driver support for the MEAS MS5805 altimeter. + config MPL115A bool "Freescale MPL115A Barometer Sensor support" default n diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 7b1e1952db..20931edb3b 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -73,6 +73,10 @@ ifeq ($(CONFIG_MB7040),y) CSRCS += mb7040.c endif +ifeq ($(CONFIG_MS5805),y) + CSRCS += ms5805.c +endif + endif # CONFIG_I2C # These drivers depend on SPI support diff --git a/drivers/sensors/ms5805.c b/drivers/sensors/ms5805.c new file mode 100644 index 0000000000..8882d42940 --- /dev/null +++ b/drivers/sensors/ms5805.c @@ -0,0 +1,715 @@ +/**************************************************************************** + * drivers/sensors/ms5805.c + * Character driver for the MEAS MS5805 Altimeter + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MS5805) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* I2C Address **************************************************************/ + +#define MS5805_ADDR 0x76 + +/* Register Definitions *****************************************************/ +/* Register Addresses */ + +#define MS5805_RESET_REG 0x1e /* Reset Register */ +#define MS5805_PRESS_REG 0x40 /* Pressure Register */ +#define MS5805_TEMP_REG 0x50 /* Temperature Register */ +#define MS5805_ADC_REG 0x00 /* ADC Register */ +#define MS5805_PROM_REG 0xa0 /* PROM Register */ + +/* PROM Definitions *********************************************************/ + +#define MS5805_PROM_LEN 8 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ms5805_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + int32_t temp; /* Uncompensated temperature (degrees Centigrade) */ + int32_t press; /* Uncompensated pressure (millibar) */ + uint8_t osr; /* Oversampling ratio bits */ + useconds_t delay; /* Oversampling ratio delay */ + + /* Calibration coefficients */ + + uint16_t c1; + uint16_t c2; + uint16_t c3; + uint16_t c4; + uint16_t c5; + uint16_t c6; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* CRC Calculation */ + +static uint8_t ms5805_crc(FAR const uint8_t *src, size_t len); + +/* I2C Helpers */ + +static int ms5805_readu16(FAR struct ms5805_dev_s *priv, uint8_t regaddr, + FAR uint16_t *regval); +static int ms5805_readadc(FAR struct ms5805_dev_s *priv, FAR uint32_t *adc); +static int ms5805_setosr(FAR struct ms5805_dev_s *priv, uint16_t osr); +static int ms5805_reset(FAR struct ms5805_dev_s *priv); +static int ms5805_readprom(FAR struct ms5805_dev_s *priv); +static int ms5805_convert(FAR struct ms5805_dev_s *priv, uint8_t regaddr, + FAR uint32_t *regval); +static int ms5805_measure(FAR struct ms5805_dev_s *priv); + +/* Character Driver Methods */ + +static int ms5805_open(FAR struct file *filep); +static int ms5805_close(FAR struct file *filep); +static ssize_t ms5805_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t ms5805_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int ms5805_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_fops = +{ + ms5805_open, + ms5805_close, + ms5805_read, + ms5805_write, + NULL, + ms5805_ioctl +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ms5805_crc + * + * Description: + * Calculate the CRC. + * + ****************************************************************************/ + +static uint8_t ms5805_crc(FAR const uint8_t *src, size_t len) +{ + uint16_t crc = 0; + size_t i; + int j; + + for (i = 0; i < len; i++) + { + crc ^= src[i]; + + for (j = 0; j < 8; j++) + { + bool xor = (crc & 0x8000) != 0; + + crc <<= 1; + if (xor) + { + crc ^= 0x3000; + } + } + } + + return (uint8_t)(crc >> 12); +} + +/**************************************************************************** + * Name: ms5805_readu16 + * + * Description: + * Read from a 16-bit register. + * + ****************************************************************************/ + +static int ms5805_readu16(FAR struct ms5805_dev_s *priv, uint8_t regaddr, + FAR uint16_t *regval) +{ + uint8_t buffer[2]; + int ret; + + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 16 bits from the register */ + + ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + *regval = (uint16_t)buffer[0] << 8 | (uint16_t)buffer[1]; + sndbg("value: %04x ret: %d\n", *regval, ret); + return ret; +} + +/**************************************************************************** + * Name: ms5805_readadc + * + * Description: + * Read from the ADC register. + * + ****************************************************************************/ + +static int ms5805_readadc(FAR struct ms5805_dev_s *priv, FAR uint32_t *adc) +{ + uint8_t regaddr; + uint8_t buffer[3]; + int ret; + + regaddr = MS5805_ADC_REG; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 24 bits from the register */ + + ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + *adc = (uint32_t)buffer[0] << 16 | + (uint32_t)buffer[1] << 8 | + (uint32_t)buffer[2]; + sndbg("adc: %06x ret: %d\n", *adc, ret); + return ret; +} + +/**************************************************************************** + * Name: ms5805_setosr + * + * Description: + * Set the oversampling ratio. + * + ****************************************************************************/ + +static int ms5805_setosr(FAR struct ms5805_dev_s *priv, uint16_t osr) +{ + int ret = OK; + + sndbg("osr: %04x\n", osr); + + switch (osr) + { + case 256: + priv->delay = 540; + break; + + case 512: + priv->delay = 1060; + break; + + case 1024: + priv->delay = 2080; + break; + + case 2048: + priv->delay = 4130; + break; + + case 4096: + priv->delay = 8220; + break; + + case 8192: + priv->delay = 16440; + break; + + default: + ret = -EINVAL; + break; + } + + if (ret == OK) + { + priv->osr = (osr / 256 - 1) * 2; + } + + return ret; +} + +/**************************************************************************** + * Name: ms5805_readprom + * + * Description: + * Read from the PROM. + * + ****************************************************************************/ + +static int ms5805_readprom(FAR struct ms5805_dev_s *priv) +{ + uint16_t prom[MS5805_PROM_LEN]; + uint8_t regaddr; + uint8_t crc; + int ret; + int i; + + regaddr = MS5805_PROM_REG; + for (i = 0; i < MS5805_PROM_LEN-1; i++) + { + ret = ms5805_readu16(priv, regaddr, prom+i); + if (ret < 0) + { + sndbg("ms5805_readu16 failed: %d\n", ret); + return ret; + } + + regaddr += 2; + } + + crc = (uint8_t)(prom[0] >> 12); + + prom[0] = 0; + prom[MS5805_PROM_LEN-1] = 0; + + if (crc != ms5805_crc((uint8_t *)prom, sizeof(prom))) + { + sndbg("crc mismatch\n"); + return -ENODEV; + } + + priv->c1 = prom[1]; + priv->c2 = prom[2]; + priv->c3 = prom[3]; + priv->c4 = prom[4]; + priv->c5 = prom[5]; + priv->c6 = prom[6]; + + return ret; +} + +/**************************************************************************** + * Name: ms5805_reset + * + * Description: + * Reset the device. + * + ****************************************************************************/ + +static int ms5805_reset(FAR struct ms5805_dev_s *priv) +{ + uint8_t regaddr; + int ret; + + regaddr = MS5805_RESET_REG; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Check the CRC and read the calibration coefficients */ + + ret = ms5805_readprom(priv); + if (ret < 0) + { + sndbg("ms5805_readprom failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: ms5805_convert + * + * Description: + * Measure the uncompensated temperature or the uncompensated pressure. + * + ****************************************************************************/ + +static int ms5805_convert(FAR struct ms5805_dev_s *priv, uint8_t regaddr, + FAR uint32_t *regval) +{ + int ret; + + regaddr |= priv->osr; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + } + + /* Wait for the conversion to end */ + + up_udelay(priv->delay); + + /* Read the value from the ADC */ + + ret = ms5805_readadc(priv, regval); + if (ret < 0) + { + sndbg("ms5805_readadc failed: %d\n", ret); + return ret; + } + + return ret; +} + +/**************************************************************************** + * Name: ms5805_measure + * + * Description: + * Measure the compensated temperature and the compensated pressure. + * + ****************************************************************************/ + +static int ms5805_measure(FAR struct ms5805_dev_s *priv) +{ + uint32_t rawpress; + uint32_t rawtemp; + int32_t diff; + int32_t temp; + int64_t off; + int64_t sens; + int32_t press; + int ret; + + ret = ms5805_convert(priv, MS5805_PRESS_REG, &rawpress); + if (ret < 0) + { + sndbg("ms5805_convert failed: %d\n", ret); + return ret; + } + + ret = ms5805_convert(priv, MS5805_TEMP_REG, &rawtemp); + if (ret < 0) + { + sndbg("ms5805_convert failed: %d\n", ret); + return ret; + } + + diff = (int32_t)rawtemp - (int32_t)priv->c5 / ((int32_t)1 << 8); + temp = (int32_t)((int64_t)20 + + (int64_t)diff * (int64_t)priv->c6 / ((int64_t)1 << 23)); + + off = (int64_t)priv->c2 * ((int64_t)1 << 17) + + (int64_t)priv->c4 * (int64_t)diff / ((int64_t)1 << 8); + sens = (int64_t)priv->c1 * ((int64_t)1 << 16) + + (int64_t)priv->c3 * (int64_t)diff / ((int64_t)1 << 7); + + if (temp < 2000) + { + int32_t ti; + int64_t offi; + int64_t sensi; + + ti = (int32_t)((int64_t)11 * (int64_t)diff * + (int64_t)diff / ((int64_t)1 << 35)); + offi = (int64_t)31 * ((int64_t)temp - (int64_t)2000) * + ((int64_t)temp - (int64_t)2000) / ((int64_t)1 << 3); + sensi = (int64_t)63 * ((int64_t)temp - (int64_t)2000) * + ((int64_t)temp - (int64_t)2000) / ((int64_t)1 << 5); + + temp -= ti; + off -= offi; + sens -= sensi; + } + + press = (int32_t)(((int64_t)rawpress * sens / ((int64_t)1 << 21) - off) / + ((int64_t)1 << 15)); + + priv->temp = temp / (int32_t)100; + priv->press = press / (int32_t)100; + return ret; +} + +/**************************************************************************** + * Name: ms5805_open + * + * Description: + * This method is called when the device is opened. + * + ****************************************************************************/ + +static int ms5805_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: ms5805_close + * + * Description: + * This method is called when the device is closed. + * + ****************************************************************************/ + +static int ms5805_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: ms5805_read + * + * Description: + * A dummy read method. + * + ****************************************************************************/ + +static ssize_t ms5805_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + return 0; +} + +/**************************************************************************** + * Name: ms5805_write + * + * Description: + * A dummy write method. + * + ****************************************************************************/ + +static ssize_t ms5805_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: ms5805_ioctl + * + * Description: + * The standard ioctl method. + * + ****************************************************************************/ + +static int ms5805_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ms5805_dev_s *priv = inode->i_private; + int ret = OK; + + /* Handle ioctl commands */ + + switch (cmd) + { + /* Measure the temperature and the pressure. Arg: None. */ + + case SNIOC_MEASURE: + DEBUGASSERT(arg == 0); + ret = ms5805_measure(priv); + break; + + /* Return the temperature last measured. Arg: int32_t* pointer. */ + + case SNIOC_TEMPERATURE: + { + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); + *ptr = priv->temp; + sndbg("temp: %08x\n", *ptr); + } + break; + + /* Return the pressure last measured. Arg: int32_t* pointer. */ + + case SNIOC_PRESSURE: + { + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); + *ptr = priv->press; + sndbg("press: %08x\n", *ptr); + } + break; + + /* Reset the device. Arg: None. */ + + case SNIOC_RESET: + DEBUGASSERT(arg == 0); + ret = ms5805_reset(priv); + break; + + /* Change the oversampling ratio. Arg: uint16_t value. */ + + case SNIOC_OVERSAMPLING: + ret = ms5805_setosr(priv, (uint16_t)arg); + sndbg("osr: %04x ret: %d\n", *(uint16_t *)arg, ret); + break; + + /* Unrecognized commands */ + + default: + sndbg("Unrecognized cmd: %d arg: %ld\n", cmd, arg); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ms5805_register + * + * Description: + * Register the MS5805 character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/press0". + * i2c - An I2C driver instance. + * osr - The oversampling ratio. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ms5805_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint16_t osr) +{ + FAR struct ms5805_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + + /* Initialize the device's structure */ + + priv = (FAR struct ms5805_dev_s *)kmm_malloc(sizeof(*priv)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->temp = 0; + priv->press = 0; + + ret = ms5805_setosr(priv, osr); + if (ret < 0) + { + sndbg("ms5805_setosr failed: %d\n", ret); + goto err; + } + + ret = ms5805_reset(priv); + if (ret < 0) + { + sndbg("ms5805_reset failed: %d\n", ret); + goto err; + } + + /* Register the character driver */ + + ret = register_driver(devpath, &g_fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + goto err; + } + + return ret; + +err: + kmm_free(priv); + return ret; +} + +#endif /* CONFIG_I2C && CONFIG_MS5805 */ diff --git a/include/nuttx/sensors/ms5805.h b/include/nuttx/sensors/ms5805.h new file mode 100644 index 0000000000..728889325f --- /dev/null +++ b/include/nuttx/sensors/ms5805.h @@ -0,0 +1,111 @@ +/**************************************************************************** + * include/nuttx/sensors/ms5805.h + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_MS5805 +#define __INCLUDE_NUTTX_SENSORS_MS5805 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MS5805) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************ + * Prerequisites: + * + * CONFIG_I2C + * Enables support for I2C drivers + * CONFIG_MS5805 + * Enables support for the MS5805 driver + */ + +/* IOCTL Commands ***********************************************************/ + +#define SNIOC_MEASURE _SNIOC(0x0001) /* Arg: None */ +#define SNIOC_TEMPERATURE _SNIOC(0x0002) /* Arg: int32_t* pointer */ +#define SNIOC_PRESSURE _SNIOC(0x0003) /* Arg: int32_t* pointer */ +#define SNIOC_RESET _SNIOC(0x0004) /* Arg: None */ +#define SNIOC_OVERSAMPLING _SNIOC(0x0005) /* Arg: uint16_t value */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: ms5805_register + * + * Description: + * Register the MS5805 character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/press0". + * i2c - An I2C driver instance. + * osr - The oversampling ratio. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ms5805_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint16_t osr); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_MS5805 */ +#endif /* __INCLUDE_NUTTX_SENSORS_MS5805 */ -- GitLab From a543dfbcec02f79bcae2edeb7bb169858fd1ed1a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 21:12:15 -0600 Subject: [PATCH 020/858] Update ChangeLog; Convert a few tabs to spaces --- ChangeLog | 4 +++- drivers/sensors/ms5805.c | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5708819a94..6d17da4292 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10809,4 +10809,6 @@ support Added MB7040 sonar. From Paul Alexander Patience (2015-08-11). * net/udp: Add support for send() for connected UDP sockets (2015-08-11). - + * drivers/sensors/ms5805.c and include/nuttx/sensors/ms5805.h: Add + support for an MS5805 altimeter. From Paul Alexander Patience + (2015-08-07). diff --git a/drivers/sensors/ms5805.c b/drivers/sensors/ms5805.c index 8882d42940..073268184f 100644 --- a/drivers/sensors/ms5805.c +++ b/drivers/sensors/ms5805.c @@ -274,7 +274,7 @@ static int ms5805_readadc(FAR struct ms5805_dev_s *priv, FAR uint32_t *adc) static int ms5805_setosr(FAR struct ms5805_dev_s *priv, uint16_t osr) { - int ret = OK; + int ret = OK; sndbg("osr: %04x\n", osr); @@ -378,7 +378,7 @@ static int ms5805_readprom(FAR struct ms5805_dev_s *priv) static int ms5805_reset(FAR struct ms5805_dev_s *priv) { uint8_t regaddr; - int ret; + int ret; regaddr = MS5805_RESET_REG; sndbg("addr: %02x\n", regaddr); @@ -415,7 +415,7 @@ static int ms5805_reset(FAR struct ms5805_dev_s *priv) static int ms5805_convert(FAR struct ms5805_dev_s *priv, uint8_t regaddr, FAR uint32_t *regval) { - int ret; + int ret; regaddr |= priv->osr; sndbg("addr: %02x\n", regaddr); @@ -462,7 +462,7 @@ static int ms5805_measure(FAR struct ms5805_dev_s *priv) int64_t off; int64_t sens; int32_t press; - int ret; + int ret; ret = ms5805_convert(priv, MS5805_PRESS_REG, &rawpress); if (ret < 0) -- GitLab From 5323597c3f806bf1cce390064d583fa9d76918c6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Aug 2015 11:51:53 -0600 Subject: [PATCH 021/858] Prep for 7.11 release --- ChangeLog | 16 ++- Documentation | 2 +- ReleaseNotes | 379 ++++++++++++++++++++++++++++++++++++++++++++++++++ arch | 2 +- 4 files changed, 390 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d17da4292..ea6fea163c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10559,7 +10559,7 @@ * arch/arm/src/sama5/sam_can.c: Fix SAMA5 CAN frame construction. From Max Holtzberg (2015-06-07). -7.11 2015-xx-xx Gregory Nutt +7.11 2015-08-13 Gregory Nutt * arch/arm/src/efm32/efm32_spi.c: Correct write to incorrect register in EFM32 SPI driver. From Pierre-noel Bouteville (2015-06-09). @@ -10600,7 +10600,7 @@ * arch/arm/include/samdl and arch/arm/src/samdl: Add architecture support for the SAMD21 family (2015-06-19). * configs/samd21-xplained: Board configuration for the SAMD21 Xplained - bord (2015-06-21). + board (2015-06-21). * arch/arm/src/sam34/sam_lowputc.c: Back out an error introduced with commit 02c33f66c5a8be774034cd40e4125e9323c7b4d8. Causes an infinite loop in up_lowputc(). From Max Neklyudov (2015-06-22). @@ -10618,8 +10618,8 @@ * SAM3/4: Add a TWI driver for the SAM4CM. From Max Neklyudov (2015-06-22). * SAMV7 Xplained: In clock configuration, divider was set to 25 to get - 25*12MHz=300MHz CPU clock. The correct multiplier is 24 becaue the - calculatin if (24+1)*12MHz. So the board was running at 312MHz. + 25*12MHz=300MHz CPU clock. The correct multiplier is 24 because the + calculation if (24+1)*12MHz. So the board was running at 312MHz. From Efim Monjak (2015-06-26). * NFS client: Fix prototype of unbind method. The function prototype was not updated for NFS after a recent change to the file system @@ -10729,7 +10729,7 @@ for the STMicro STM32 F7 (2015-07-15). * drivers/can.c: Fix an issue in the CAN driver where the rx_sem count can grow beyond bounds (2015-07-15). - * configs/stm32f762g-disco/: Add initialize support for the STMicor + * configs/stm32f762g-disco/: Add initialize support for the STMicro STM32 F7 Discovery board. This is a work in progress and will be a while before it is fully functional (2015-07-16). * arch/../up_etherstub.c, arch/../up_initialize, and other files: Add @@ -10794,7 +10794,7 @@ Patience (2015-08-07). * include/nuttx/spi/slave.h: Add a definition of an SPI slave interface (2015-08-08). - * arch/arm/src/samv7: Add the framework for an SPI slave drvier. This + * arch/arm/src/samv7: Add the framework for an SPI slave driver. This driver has a lot of missing logic on initial commit (2015-08-09). * arch/arm/src/samv7: Basic, no-DMA SPI slave driver is in place (2015-08-10). @@ -10806,9 +10806,11 @@ * Networking: Allow receipt of empty UDP packets. From Max Neklyudov (2015-08-11). * drivers/sensors/mb7040.c and include/nuttx/sensors/mb7040.h: Add - support Added MB7040 sonar. From Paul Alexander Patience (2015-08-11). + support for a MB7040 sonar driver. From Paul Alexander Patience (2015-08-11). * net/udp: Add support for send() for connected UDP sockets (2015-08-11). * drivers/sensors/ms5805.c and include/nuttx/sensors/ms5805.h: Add support for an MS5805 altimeter. From Paul Alexander Patience (2015-08-07). + +7.12 2015-xx-xx Gregory Nutt diff --git a/Documentation b/Documentation index 429e6427da..8cc114a79f 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 429e6427da4453da9342f52f57cf87bddafdb6e5 +Subproject commit 8cc114a79fd2b9b61aa4dd6185feafd9b4acf805 diff --git a/ReleaseNotes b/ReleaseNotes index 711b03e677..c00d931228 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -9239,3 +9239,382 @@ detailed bugfix information): returned value which will always be -1. - apps/examples: Correct use of the BOARDIOC_GRAPHICS_SETUP boardctl() call. + +NuttX-7.11 Release Notes +------------------------ + +The 111th release of NuttX, Version 7.11, was made on June 9, 2015, +and is available for download from the Bitbucket.org website. Note +that release consists of two tarballs: nuttx-7.11.tar.gz and +apps-7.11.tar.gz. Both may be needed (see the top-level nuttx/README.txt +file for build information). + +Additional new features and extended functionality: + + * Core OS: + + - clock_gettime(): Use up_timer_gettime for CLOCK_MONOTONIC in + tickless mode. From Max Neklyudov. + - waitpid(): Implement WNOHANG for waitpid() only and for the case of + CONFIG_SCHED_HAVE_PARENT not selected. From Max Neklyudov. + - SCHED_SPORADIC: Add a sporadic scheduler to NuttX. + - Extend the processor-specific interface to include information to + support the Sporadic Scheduler. + - sem_tickwait(): Added this function for internal use within the OS. + It is a non-standard but more efficient version of sem_timedwait() + for use in higher performance device drivers. + + * Binary Loader: + + * Graphics/Graphic Drivers: + + - Graphics: Implement anti-aliasing in order to clean the drawing of + all edges. Anti-aliasing is supported in the horizontal, raster + direction only. + - SSD1306 LCD Driver: Modify the SSD1306 LCD driver to support either + the SPI or I2C interface. From Alan Carvalho de Assis. + + * File Systems/Block Drivers/MTD: + + - mount: Add the ability to mount a file system on top of en existing + node in the psuedo-file system. + - epoll(): Add a very simple epoll layer just around poll calls. To + satisfy build app requirements. From Anton D. Kachalov. + + * Common Device Drivers: + + - IOCTL: Add relay IOCTL definitions. From Max Neklyudov. + - I/O Expander Framework: Add an I/O expander driver framework. From + Sebastien Lorquet + - NXP PCA9555 I/O Explander. Add PCA9555 driver.From Sebastien + Lorquet + - BMP180 Barameter: Add support to Bosch BMP180 barometer. From + Alan Carvalho de Assis. + - CAN IOCTLs: Add CAN IOCTL command definitions to manage CAN message + filtering + - CAN Driver: Add configuration to support DLC to byte conversions + needed for CAN FD mode. + - SPI Slave Interface: Add a definition of an SPI slave interface. + - LM92 Temperature Sensor: Add a driver for the LM92 temperature + sensor. Contributed by Paul Alexander Patience. + - AS5048B Rotary Magnetic Sensor: Add support for an AS5048B rotary + magnetic sensor. From Paul Alexander Patience. + - Ramtron Driver: Update to include supportf for newer RAMTRON parts. + From David Sidrane. + - MB7040 Sonar Driver: Add support for a MB7040 sonar driver. From + Paul Alexander Patience. + - ms5805 Altimeter Driver: Add support for an MS5805 altimeter. From + Paul Alexander Patience. + + * Networking: + + - DNS Client: Implement the low-level network DNS packet protocol to + request and receive IPv6 address mappings. + - NetDB: Add support for a DNS host name resolution cache. This can + save a lot of DNS name server lookups (but might also have the + negative consequence of using stale IP address mappings. + - NetDB: Name resolution logic now supports lookups from a file like + /etc/hosts. + - Network Initialization: Add CONFIG_NETDEV_LATEINIT that can be + used to suppress calls to up_netinitialize() from early in + initialization. + - FTMAC100 Ethernet MAC Driver. Add support for Faraday FTMCA100 + Ethernet MAC/ From Anton D. Kachalov. + - UDP Networking: Add support for send() for connected UDP sockets. + + * Crypto: + + - Add CFB and MAC AES modes. From Max Neklyudov. + + * Simulation Platform: + + - Simulation: Implement board_power_off() for the simulation platform. + This allows for a graceful exit from the simulation. + + * MoxaRT: + + - MoxaRT SoC: Add support for MoxaRT SoC found in the most Moxa serial + converters such as NP51x0, NP66xx, UC72xx. From Anton D. Kachalov. + + * MoxaRT Boards: + + - Moxa NP51x0: Moxa NP51x0 series of 2-port advanced RS-232/422/485 + serial device servers. From Anton D. Kachalov. + + * ARMv6-M: + + - ARMv6-M Assertions: Port some per-process stack dumping logic from + ARMv7-M to ARMv6-M. From Alan Carvalho de Assis. + + * Atmel SAMD/L Boards: + + - SAML21: DMA: Add SAML21 DMA support. + - SAMD21: Add architecture support for the SAMD21 family. + - SAMD21-Xplained: Board configuration for the SAMD21 Xplained board. + + * Atmel SAM3/4 Drivers: + + - SAM4E: Add default loop optimization if EEFC_FMR is available in the + configuration (i.e., for SAM4S and 4E). From Marco Aurélio da Cruz. + - crypto/ and SAM4CM: Add CFB and MAC AES modes. From Max Neklyudov. + - SAM3/4: Add a TWI driver for the SAM4CM. From Max Neklyudov. + + * Freescale (NXP) Kinetis: + + - Kinetis: Add support for MK20DN--VLH5 and MK20DX---VLH5. Needed + for backward compatible support for Teensy-3.0. + + * Freescale (NXP) Kinetis Boards: + + - Teensy 3.x: Add board support for the PJRC Teensy-3.0 and + Teensy-3.1 boards. + + * Atmel SAMV7 Drivers: + + - SAMV7: Add an MCAN driver for the SAMV7 platform. + - SAMV7 SPI Slave Driver: Add the an SPI slave driver. + + * STMicro STM32: + + - STMicro STM32 F7: Add architecture support for the STMicro STM32 + F7. + - STM32 F446: Add support for the STMicro STM32 F446. From David + Sidrane. + + * STMicro STM32 Drivers: + + - STM32 F7: Add an STM32 F7 Ethernet driver. + - STM32 F7: Port the STM32 F4 DMA driver. + - STM32 F4 ADC: Add DMA support to the ADC driver for STM32 F4. From + Max Kriegler. + + * STMicro STM32 Boards: + + - STM32F762G-Disco: Add support for the STMicro STM32 F7 Discovery + board. + - STM32F4-Disco: Add support to BMP180 driver on the STM32F4 Discovery. + From Alan Carvalho de Assis. + + * C Library/Header Files: + + - Add asctime(), asctime_r(), ctime(), and ctime_r(). + - sethostname(): Add support for sethostname(). + - gethostbyname() and gethostbyaddr(): Add support for + gethostbyname() and gethostbyaddr(). Also support included for the + non-standard gethostbyname_r() and gethostbyaddr_r(). This moves + the DNS client logic from apps/ into the NuttX libc implementation. + + * Tools: + + - testbuild.sh: Add a script that can be used to perform building + testing for several board configurations. + + * Build/Configuration System: + + - apps/ Build System: No longer depends on hardcoded lists of + directories. Instead, it does a wildcard search to find all + appropriate directories. This means that to install a new + application, you simply have to copy the directory (or link it) into + the apps/ directory. If the new directory includes a Makefile and + Make.defs file, then it will automatically be included in the build. + - mkkonfig.sh: Add the tool mkkconfig.sh that dynamically builds the + apps/Kconfig file at configuration time. The hardcoded + configuration file has been removed and now the top-level Makefile + executes tools/mkkconfig.sh to auto-generate the top-level Kconfig + file. A new apps/ make target call preconfig: was added to support + this operation. Now you do not have to modify the top-level Kconfig + file to add a new directory into the configuration; the top-level + subdirectory simply needs to include a Kconfig file and it will + automatically be included in the configuration. The native Windows + build is temporarily broken until a new apps/tools/mkconfig.bat + script is generated. + - mkkconfig.bat: Add the Windows script corresponding to + apps/tools/mkkconfig.sh. Needed for a Windows native build. + + * Applications: apps/nshlib: + + - NSH shutdown command: NSH will now support an (optional) shutdown + command if the board provides the option CONFIG_BOARDCTL_POWEROFF. + The command can also be used to reset the system if + CONFIG_BOARDCTL_RESET=y. + - NSH uname command: Add support for a uname command. + - NSH nslookup command: Add an nslookup command. + + * Applications: apps/system: + + - NetDB: Add a system command to access the network database. + - readline(): Add support for Unix-style tab complete to readline. + Contributed by Nghia Ho. + - readline(): Extended the tab-completion support to also expand NSH + command names. + - readline(): Add support for an in-memory command line history that + can be retrieved using the up and down arrows. Contributed by Nghia + Ho. + + * Applications: apps/netutils: + + - DNS client: Moved the DNS client logic into the NuttX C library. + It is a necessary part for the full implementation of the netdb logic + and provides more flexibility in that location. + - Replace calls to the non-standard dns_gethotip() with calls to + standard gethostbyname(). + - NetLib: Create netlib wrapper functions around dns_getserver() and + dns_setserver() to isolate application code from changes to those + interfaces. + + * Applications: apps/examples: + + - OS test: Extend the OS test to include a test of + pthread_mutex_trylock() for recursive mutexes. From Juha Niskanen. + - OS test: Add a test for the sporadic scheduler. + +Bugfixes. Only the most critical bugfixes are listed here (see the +ChangeLog for the complete list of bugfixes and for additional, more +detailed bugfix information): + + * Core OS: + + - pthreads: Use -1 instead of 0 as PID for unclaimed mutexes. From + Juha Niskanen. + - pthreads: Implement pthread_mutex_trylock() for recursive mutexes. + From Juha Niskanen. + - pthread_create(): Group binding needs to be cleared before + sched_releasetcb(), as otherwise group_leave() will be called and + group->tg_nmembers decremented or group being released. group_leave() + should be called only after group_join() is called, not after + group_bind(). From Jussi Kivilinna. + - Protected Mode User Memory Allocator: Redesigned how the user space + heap is accessed from the kernel code in protected mode. It used to + call memory management functions in user space via function pointers + in the userspace interface. That is inefficient because the first + thing that those memory management functions do is to trap back into + the kernel to get the current PID. Worse, that operation can be + fatal is certain fragile situations such as when a task is exiting. + The solution is to remove all of the memory management function + calls from the interface. Instead, the interface exports the users + pace heap structure and then kernel size implementations of those + memory management functions will operate on the userspace heap + structure. This avoids the unnecessary system calls and, more + importantly, failures do to freeing memory when a test exits. + - pthread_create(): Fix an (unlikely) error in fallback value in the + event of a failure (which should never occur). + + * Common Drivers: + + - STMPE811 Driver: In stmpe811_instanciate() when + CONFIG_STMPE811_MULTIPLE is enabled, and the call to + stmpe811_checkid() fails, then the linked device list is not + restored to its previous state. From Sebastien Lorquet. + - CAN driver: Fix an issue in the CAN driver where the rx_sem count + can grow beyond bounds. + + * File System/Block Drivers: + + - NFS client: Fix prototype of unbind method. The function prototype + was not updated for NFS after a recent change to the file system + interface. From Manuel St??. + + * Networking/Network Drivers: + + - netconfig.h: Fix some backward compilation that was emitting #error + in the wrong condition when SLIP was enabled. + - SLIP Driver: Fix a missed name change when many of network + interface names changed sometime back but were apparently never + updated for SLIP. + - Networking: Allow receipt of empty UDP packets. From Max Neklyudov. + + * ARMv6-M: + + - ARMv6-M: Fix Cortex-M0 assembly error when the interrupt stack is + enabled. From Alan Carvalho de Assis. + + * Atmel SAMD/L Drivers: + + - SAMD20, D21, L21: In the SAML21, SERCOM5 uses a different SLOW clock + channel (and, hence, also a different SLOW GCLK generator). This + means that the channel selection cannot be a global definition but + must be a per SERCOM configuration setting. + - SAMD/L: Several fixes to register definitions and types. From + Janne Rosberg. + + * Atmel SAM3/4 Drivers: + + - SAM3/4 UART: Back out an error introduced with commit + 02c33f66c5a8be774034cd40e4125e9323c7b4d8. Causes an infinite loop in + up_lowputc(). From Max Neklyudov. + - SAM4CM: Fix SUPC register definitions. From Max Neklyudov. + - SAM3/4 WDT: Correct some problems with SAM3/4 watchdog driver. + Includes some small improvements. From Max Neklyudov. + + * Atmel SAMV7 Drivers: + + - SAMV7 UART: Also back the bad cloned change o sam_lowputc.c for + SAMV7 platform. + + * NXP LPC43xx Drivers: + + - LPC4350: Correct some LPC4350 GPIO pin configurations. From + Alessandro Temil. + + * SiLabs EMF32 Drivers: + + - EFM32 SPI: Correct write to incorrect register in EFM32 SPI driver. + From Pierre-noel Bouteville. + + * STMicro STM32 Drivers: + + - STM32 F15x: STM322 F15x stm32_stdclockconfig() was calling + stm32_pw_setvos() which accessed PWR_CR via an inactive APB From + Juha Niskaneni. + - STM32 Ethernet: Extend STM32 Ethernet operating frequency to 180MHz. + From Sebastien Lorquet. + + * STMicro STM32 Boards: + + - SAMV7 Xplained: In clock configuration, divider was set to 25 to get + 25*12MHz=300MHz CPU clock. The correct multiplier is 24 because the + calculation if (24+1)*12MHz. So the board was running at 312MHz. + From Efim Monjak. + + * ARMv7-A: + + - Cortex-A5 vfork(): Fix a Cortex-A compilation error when system + calls are enabled in modes other than CONFIG_BUILD_KERNEL. + + * Atmel SAMA5 Drivers: + + - SAMA5Dx EHCI: Fix some bad conditional compilation that left a + function undefined if CONFIG_USBHOST_ASYNCH is not selected. + + * C Library/Header Files: + + - getopt(): Uninitialized variable can cause hardfault from getopt() + if required argument is missing. From George McWilliams. + + * Applications: apps/nshlib: + + - NSH/THHPD: Change decoding to handle the increased size of the + scheduling policy field in the TCB. + + * Applications: apps/netutils: + + - THTTPD: Fix compilation problems when + CONFIG_THTTPD_GENERATE_INDICES is defined. + - THTTPD: Missing gci-src as a dependency path when building with + BINFS enabled. + + * Applications: apps/examples: + + - poll() example: Fix a few bit-rot compilation errors. + - Nx Lines example: If CONFIG_NX_ANTIALIASING=y, then the nxlines + example now erases a line that is 2 pixels longer and 2 pixels wider + than the line it drew. That eliminates edges effects due to + applying the anti-aliasing algorithm twice. A better solution + would be to make anti-aliasing an option for each graphics call so + you would rend the line with anti-aliasing ON and clear it with + anti-aliasing OFF. but I don't have the wherewithal for that change + today. + - OS test: Improve synchronization in round robin tests. On very fast + processors, there are race conditions that make the test failure. + Need better interlocking to assure that the threads actually do start + at the same time. diff --git a/arch b/arch index 5d220dfb29..bf8d859e37 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5d220dfb291e8184b71fd13590e820a6026b7770 +Subproject commit bf8d859e37ed9556cb915895ec84db3b1bd59a13 -- GitLab From 7d0f9436d2cb3ec5423efa85362e3e178c4f9da9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Aug 2015 11:59:06 -0600 Subject: [PATCH 022/858] Refresh submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index bf8d859e37..6ab2a611d0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bf8d859e37ed9556cb915895ec84db3b1bd59a13 +Subproject commit 6ab2a611d0ebd7520b6702b6da669387aa91c654 -- GitLab From 3f8a084d01efe1699eb6f719b9a0658883356b3d Mon Sep 17 00:00:00 2001 From: - Max Neklyudov Date: Thu, 13 Aug 2015 14:28:31 -0600 Subject: [PATCH 023/858] fs/vfs/fs_poll.c: use sem_tickwait instead of sem_timedwait --- fs/vfs/fs_poll.c | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index f5873f3a78..0937afc3cf 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/vfs/fs_poll.c * - * Copyright (C) 2008-2009, 2012-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,16 +39,16 @@ #include -#include #include #include -#include +#include +#include #include -#include +#include -#include #include #include +#include #include @@ -341,36 +341,15 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) } else if (timeout > 0) { - time_t sec; - uint32_t nsec; - /* Either wait for either a poll event(s), for a signal to occur, * or for the specified timeout to elapse with no event. * * NOTE: If a poll event is pending (i.e., the semaphore has already - * been incremented), sem_timedwait() will not wait, but will return + * been incremented), sem_tickwait() will not wait, but will return * immediately. */ - sec = timeout / MSEC_PER_SEC; - nsec = (timeout - MSEC_PER_SEC * sec) * NSEC_PER_MSEC; - - /* Make sure that the following are atomic by disabling interrupts. - * Interrupts will be re-enabled while we are waiting. - */ - - flags = irqsave(); - (void)clock_gettime(CLOCK_REALTIME, &abstime); - - abstime.tv_sec += sec; - abstime.tv_nsec += nsec; - if (abstime.tv_nsec >= NSEC_PER_SEC) - { - abstime.tv_sec++; - abstime.tv_nsec -= NSEC_PER_SEC; - } - - ret = sem_timedwait(&sem, &abstime); + ret = sem_tickwait(&sem, clock_systimer(), MSEC2TICK(timeout)); if (ret < 0) { int err = get_errno(); @@ -388,8 +367,6 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) ret = -err; } } - - irqrestore(flags); } else { -- GitLab From 48107bf073aa9635df8a609bb306c89a6728655e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Aug 2015 14:58:52 -0600 Subject: [PATCH 024/858] poll() now returns POLLERR for any file descriptor that returns a failure during the poll setup --- ChangeLog | 11 +++++++++-- fs/vfs/fs_poll.c | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea6fea163c..94806d147a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10806,11 +10806,18 @@ * Networking: Allow receipt of empty UDP packets. From Max Neklyudov (2015-08-11). * drivers/sensors/mb7040.c and include/nuttx/sensors/mb7040.h: Add - support for a MB7040 sonar driver. From Paul Alexander Patience (2015-08-11). + support for a MB7040 sonar driver. From Paul Alexander Patience + (2015-08-11). * net/udp: Add support for send() for connected UDP sockets (2015-08-11). * drivers/sensors/ms5805.c and include/nuttx/sensors/ms5805.h: Add support for an MS5805 altimeter. From Paul Alexander Patience - (2015-08-07). + (2015-08-12). 7.12 2015-xx-xx Gregory Nutt + + * fs/vfs/fs_poll.c: Use sem_tickwait() insteadk of sem_timedwait() + From Macs Neklyudov (2015-08-13). + * fs/vfs/fs_poll.c: If we fail to setup the poll for any file + descriptor, for any reason, set the POLLERR bit (2015-08-13). + diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 0937afc3cf..d7b8da4e94 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -176,6 +176,9 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) (void)poll_fdsetup(fds[j].fd, &fds[j], false); } + /* Indicate an error on the file discriptor */ + + fds[i].revents |= POLLERR; return ret; } } -- GitLab From dd7ffa481c683d7f80f1c5f7b4f9428159550e91 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 08:22:03 -0600 Subject: [PATCH 025/858] Fix a spelling error in a comment --- fs/vfs/fs_poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index d7b8da4e94..10852e7d91 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -176,7 +176,7 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) (void)poll_fdsetup(fds[j].fd, &fds[j], false); } - /* Indicate an error on the file discriptor */ + /* Indicate an error on the file descriptor */ fds[i].revents |= POLLERR; return ret; -- GitLab From 301f2156388018e59403d4c4c7bcdd1cad73080b Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Fri, 14 Aug 2015 08:35:01 -0600 Subject: [PATCH 026/858] Add support for div() to the C library. From OrbitalFox --- Documentation | 2 +- include/stdlib.h | 20 +++++++++-- libc/stdlib/Make.defs | 4 +-- libc/stdlib/lib_div.c | 80 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 libc/stdlib/lib_div.c diff --git a/Documentation b/Documentation index 8cc114a79f..ce750c0899 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8cc114a79fd2b9b61aa4dd6185feafd9b4acf805 +Subproject commit ce750c0899c2138b37b52a48d020a3eceb92fd04 diff --git a/include/stdlib.h b/include/stdlib.h index 70e9f707e7..cd24222723 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/stdlib.h * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -95,6 +95,16 @@ struct mallinfo * by free (not in use) chunks.*/ }; +/* Structure type returned by the div() function. */ + +struct div_s +{ + int quot; /* Quotient */ + int rem; /* Remainder */ +}; + +typedef struct div_s div_t; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -170,13 +180,19 @@ FAR void *memalign(size_t, size_t); FAR void *zalloc(size_t); FAR void *calloc(size_t, size_t); -/* Misc */ +/* Arithmetic */ int abs(int j); +#ifdef CONFIG_CAN_PASS_STRUCTS +div_t div(int numer, int denom); +#endif long int labs(long int j); #ifdef CONFIG_HAVE_LONG_LONG long long int llabs(long long int j); #endif + +/* Temporary files */ + int mktemp(FAR char *path_template); int mkstemp(FAR char *path_template); diff --git a/libc/stdlib/Make.defs b/libc/stdlib/Make.defs index 6a0d8ad7d8..deffb5f62d 100644 --- a/libc/stdlib/Make.defs +++ b/libc/stdlib/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libc/stdlib/Make.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,7 +35,7 @@ # Add the stdlib C files to the build -CSRCS += lib_abs.c lib_abort.c lib_imaxabs.c lib_itoa.c lib_labs.c +CSRCS += lib_abs.c lib_abort.c lib_div.c lib_imaxabs.c lib_itoa.c lib_labs.c CSRCS += lib_llabs.c lib_rand.c lib_qsort.c CSRCS += lib_strtol.c lib_strtoll.c lib_strtoul.c lib_strtoull.c CSRCS += lib_strtod.c lib_checkbase.c diff --git a/libc/stdlib/lib_div.c b/libc/stdlib/lib_div.c new file mode 100644 index 0000000000..03274a1da4 --- /dev/null +++ b/libc/stdlib/lib_div.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libc/stdlib/lib_div.c + * + * Copyright (C) 2015 Stavros Polymenis. All rights reserved. + * Author: Stavros Polymenis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#ifdef CONFIG_CAN_PASS_STRUCTS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: div + * + * Description: + * The div() function computes the quotient and remainder of the division + * of the numerator 'numer' by the denominator 'denom". If the division is + * inexact, the resulting quotient is the integer of lesser magnitude that + * is the nearest to the algebraic quotient. If the result cannot be + * represented, the behavior is undefined; otherwise, quot * denom + rem + * will equal 'numer'. + * + * Input Parameters: + * numer - Numerator of the Division + * denom - Denominator of the division + * + * Returned Value: + * The result of the devision represent as values of type div_t + * + ****************************************************************************/ + +div_t div(int numer, int denom) +{ + div_t f; + + f.quot = numer / denom; + f.rem = numer % denom; + return f; +} + +#endif /* CONFIG_CAN_PASS_STRUCTS */ \ No newline at end of file -- GitLab From 6df94096caff21d5a626ec0a31b54c11383a75e7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 08:45:59 -0600 Subject: [PATCH 027/858] Add ldiv() and lldiv() too --- ChangeLog | 6 +++++- include/stdlib.h | 24 ++++++++++++++++++++++++ libc/stdlib/Make.defs | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94806d147a..f8832b8a83 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10820,4 +10820,8 @@ From Macs Neklyudov (2015-08-13). * fs/vfs/fs_poll.c: If we fail to setup the poll for any file descriptor, for any reason, set the POLLERR bit (2015-08-13). - + * libc/stdlib: Add support for div() to the C library. From + OrbitalFox (2015-08-14). + * libc/stdlib: Might as well add ldiv() and lldiv() to since + these are equivalent to div() with long and long long types, + respectively, instead of int (2015-08-14). diff --git a/include/stdlib.h b/include/stdlib.h index cd24222723..433b11dc9a 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -105,6 +105,26 @@ struct div_s typedef struct div_s div_t; +/* Structure type returned by the ldiv() function. */ + +struct ldiv_s +{ + long quot; /* Quotient */ + long rem; /* Remainder */ +}; + +typedef struct ldiv_s ldiv_t; + +/* Structure type returned by the lldiv() function. */ + +struct lldiv_s +{ + long quot; /* Quotient */ + long rem; /* Remainder */ +}; + +typedef struct lldiv_s lldiv_t; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -185,6 +205,10 @@ FAR void *calloc(size_t, size_t); int abs(int j); #ifdef CONFIG_CAN_PASS_STRUCTS div_t div(int numer, int denom); +ldiv_t ldiv(long numer, long denom); +#ifdef CONFIG_HAVE_LONG_LONG +lldiv_t lldiv(long long numer, long long denom); +#endif #endif long int labs(long int j); #ifdef CONFIG_HAVE_LONG_LONG diff --git a/libc/stdlib/Make.defs b/libc/stdlib/Make.defs index deffb5f62d..5f1b7a06a0 100644 --- a/libc/stdlib/Make.defs +++ b/libc/stdlib/Make.defs @@ -35,8 +35,9 @@ # Add the stdlib C files to the build -CSRCS += lib_abs.c lib_abort.c lib_div.c lib_imaxabs.c lib_itoa.c lib_labs.c -CSRCS += lib_llabs.c lib_rand.c lib_qsort.c +CSRCS += lib_abs.c lib_abort.c lib_div.c lib_ldiv.c lib_lldiv.c +CSRCS += lib_imaxabs.c lib_itoa.c lib_labs.c lib_llabs.c +CSRCS += lib_rand.c lib_qsort.c CSRCS += lib_strtol.c lib_strtoll.c lib_strtoul.c lib_strtoull.c CSRCS += lib_strtod.c lib_checkbase.c -- GitLab From 768d89218856af238a22b8b36e4098d22dae4d50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 10:10:32 -0600 Subject: [PATCH 028/858] Add si_errno to siginfo_t --- include/signal.h | 1 + sched/pthread/pthread_condtimedwait.c | 3 ++- sched/pthread/pthread_kill.c | 1 + sched/sched/sched_waitid.c | 3 ++- sched/signal/sig_kill.c | 3 ++- sched/signal/sig_mqnotempty.c | 3 ++- sched/signal/sig_queue.c | 1 + sched/signal/sig_timedwait.c | 1 + sched/task/task_exithook.c | 4 +++- sched/timer/timer_settime.c | 1 + 10 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/signal.h b/include/signal.h index 30f97ef687..18ab6b85c1 100644 --- a/include/signal.h +++ b/include/signal.h @@ -216,6 +216,7 @@ struct siginfo { uint8_t si_signo; /* Identifies signal */ uint8_t si_code; /* Source: SI_USER, SI_QUEUE, SI_TIMER, SI_ASYNCIO, or SI_MESGQ */ + uint8_t si_errno; /* Zero or errno value associated with signal */ union sigval si_value; /* Data passed with signal */ #ifdef CONFIG_SCHED_HAVE_PARENT pid_t si_pid; /* Sending task ID */ diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index b9d266a763..3a3e6f21f7 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_condtimedwait.c * - * Copyright (C) 2007-2009, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -119,6 +119,7 @@ static void pthread_condtimedout(int argc, uint32_t pid, uint32_t signo) info.si_signo = signo; info.si_code = SI_QUEUE; + info.si_errno = ETIMEDOUT; info.si_value.sival_ptr = NULL; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = (pid_t)pid; diff --git a/sched/pthread/pthread_kill.c b/sched/pthread/pthread_kill.c index 7c9609a4d6..78da939d08 100644 --- a/sched/pthread/pthread_kill.c +++ b/sched/pthread/pthread_kill.c @@ -116,6 +116,7 @@ int pthread_kill(pthread_t thread, int signo) info.si_signo = signo; info.si_code = SI_USER; + info.si_errno = EINTR; info.si_value.sival_ptr = NULL; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 31a393861d..ca9054ba88 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -68,11 +68,12 @@ static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *chil FAR siginfo_t *info) { /* The child has exited. Return the saved exit status (and some fudged - * information. + * information). */ info->si_signo = SIGCHLD; info->si_code = CLD_EXITED; + info->si_errno = OK; info->si_value.sival_ptr = NULL; info->si_pid = child->ch_pid; info->si_status = child->ch_status; diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 956029a693..2183598602 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/signal/sig_kill.c * - * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -114,6 +114,7 @@ int kill(pid_t pid, int signo) info.si_signo = signo; info.si_code = SI_USER; + info.si_errno = EINTR; info.si_value.sival_ptr = NULL; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; diff --git a/sched/signal/sig_mqnotempty.c b/sched/signal/sig_mqnotempty.c index ee936f02fc..4fa0196a17 100644 --- a/sched/signal/sig_mqnotempty.c +++ b/sched/signal/sig_mqnotempty.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_mqnotempty.c * - * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -112,6 +112,7 @@ int sig_mqnotempty(int pid, int signo, void *sival_ptr) info.si_signo = signo; info.si_code = SI_MESGQ; + info.si_errno = OK; #ifdef CONFIG_CAN_PASS_STRUCTS info.si_value = value; #else diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index 6e9b1b2ce9..bc0aa01012 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -135,6 +135,7 @@ int sigqueue(int pid, int signo, void *sival_ptr) info.si_signo = signo; info.si_code = SI_QUEUE; + info.si_errno = OK; #ifdef CONFIG_CAN_PASS_STRUCTS info.si_value = value; #else diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index a0abc47d93..18ab5075c4 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -115,6 +115,7 @@ static void sig_timeout(int argc, wdparm_t itcb) { u.wtcb->sigunbinfo.si_signo = SIG_WAIT_TIMEOUT; u.wtcb->sigunbinfo.si_code = SI_TIMER; + u.wtcb->sigunbinfo.si_errno = ETIMEDOUT; u.wtcb->sigunbinfo.si_value.sival_int = 0; #ifdef CONFIG_SCHED_HAVE_PARENT u.wtcb->sigunbinfo.si_pid = 0; /* Not applicable */ diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index 585b897d49..e471e64578 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_exithook.c * - * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -343,6 +343,7 @@ static inline void task_sigchild(gid_t pgid, FAR struct tcb_s *ctcb, int status) info.si_signo = SIGCHLD; info.si_code = CLD_EXITED; + info.si_errno = OK; info.si_value.sival_ptr = NULL; #ifndef CONFIG_DISABLE_PTHREAD info.si_pid = chgrp->tg_task; @@ -394,6 +395,7 @@ static inline void task_sigchild(FAR struct tcb_s *ptcb, info.si_signo = SIGCHLD; info.si_code = CLD_EXITED; + info.si_errno = OK; info.si_value.sival_ptr = NULL; #ifndef CONFIG_DISABLE_PTHREAD info.si_pid = ctcb->group->tg_task; diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 432b6d2068..1145ff7783 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -100,6 +100,7 @@ static inline void timer_sigqueue(FAR struct posix_timer_s *timer) info.si_signo = timer->pt_signo; info.si_code = SI_TIMER; + info.si_errno = OK; #ifdef CONFIG_CAN_PASS_STRUCTS info.si_value = timer->pt_value; #else -- GitLab From eb19e0c0e25db6939e1a1d779751a2c3ea654b7c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 10:12:04 -0600 Subject: [PATCH 029/858] Add two files that I forgot in a previous commit --- ChangeLog | 3 ++ libc/stdlib/lib_ldiv.c | 85 +++++++++++++++++++++++++++++++++++++++++ libc/stdlib/lib_lldiv.c | 85 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 libc/stdlib/lib_ldiv.c create mode 100644 libc/stdlib/lib_lldiv.c diff --git a/ChangeLog b/ChangeLog index f8832b8a83..bc43ca719b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10825,3 +10825,6 @@ * libc/stdlib: Might as well add ldiv() and lldiv() to since these are equivalent to div() with long and long long types, respectively, instead of int (2015-08-14). + * include/signal.h and files that include it: Add si_errno to + siginfo_t (2015-08-14). + diff --git a/libc/stdlib/lib_ldiv.c b/libc/stdlib/lib_ldiv.c new file mode 100644 index 0000000000..84a4343fd5 --- /dev/null +++ b/libc/stdlib/lib_ldiv.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * libc/stdlib/lib_ldiv.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * A direct leverage of the div() inplement by: + * + * Copyright (C) 2015 Stavros Polymenis. All rights reserved. + * Author: Stavros Polymenis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#ifdef CONFIG_CAN_PASS_STRUCTS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ldiv + * + * Description: + * The ldiv() function computes the quotient and remainder of the division + * of the numerator 'numer' by the denominator 'denom". If the division is + * inexact, the resulting quotient is the integer of lesser magnitude that + * is the nearest to the algebraic quotient. If the result cannot be + * represented, the behavior is undefined; otherwise, quot * denom + rem + * will equal 'numer'. + * + * Input Parameters: + * numer - Numerator of the Division + * denom - Denominator of the division + * + * Returned Value: + * The result of the devision represent as values of type ldiv_t + * + ****************************************************************************/ + +ldiv_t ldiv(long numer, long denom) +{ + ldiv_t f; + + f.quot = numer / denom; + f.rem = numer % denom; + return f; +} + +#endif /* CONFIG_CAN_PASS_STRUCTS */ \ No newline at end of file diff --git a/libc/stdlib/lib_lldiv.c b/libc/stdlib/lib_lldiv.c new file mode 100644 index 0000000000..0c4e4da192 --- /dev/null +++ b/libc/stdlib/lib_lldiv.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * libc/stdlib/lib_lldiv.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * A direct leverage of the div() inplement by: + * + * Copyright (C) 2015 Stavros Polymenis. All rights reserved. + * Author: Stavros Polymenis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#if defined(CONFIG_CAN_PASS_STRUCTS) && defined(CONFIG_HAVE_LONG_LONG) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lldiv + * + * Description: + * The lldiv() function computes the quotient and remainder of the division + * of the numerator 'numer' by the denominator 'denom". If the division is + * inexact, the resulting quotient is the integer of lesser magnitude that + * is the nearest to the algebraic quotient. If the result cannot be + * represented, the behavior is undefined; otherwise, quot * denom + rem + * will equal 'numer'. + * + * Input Parameters: + * numer - Numerator of the Division + * denom - Denominator of the division + * + * Returned Value: + * The result of the devision represent as values of type lldiv_t + * + ****************************************************************************/ + +lldiv_t lldiv(long long numer, long long denom) +{ + lldiv_t f; + + f.quot = numer / denom; + f.rem = numer % denom; + return f; +} + +#endif /* CONFIG_CAN_PASS_STRUCTS && CONFIG_HAVE_LONG_LONG */ \ No newline at end of file -- GitLab From 8f7453b5ecc6d5ca7641c756f285495e4d02b468 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 12:04:57 -0600 Subject: [PATCH 030/858] Addings to stdlib.h must be added to cstdlib too --- include/cxx/cstdlib | 18 ++++++++++++++++-- include/stdlib.h | 9 +++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/cxx/cstdlib b/include/cxx/cstdlib index 790996a8ea..419291c789 100644 --- a/include/cxx/cstdlib +++ b/include/cxx/cstdlib @@ -1,7 +1,7 @@ //*************************************************************************** // include/cxx/cstdlib // -// Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. +// Copyright (C) 2009, 2012, 2015 Gregory Nutt. All rights reserved. // Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without @@ -100,15 +100,29 @@ namespace std using ::calloc; using ::mallinfo; - // Misc. + // Arithmetic using ::abs; using ::labs; #ifdef CONFIG_HAVE_LONG_LONG using ::llabs; #endif + +#ifdef CONFIG_CAN_PASS_STRUCTS + using ::div; + using ::ldiv; +#ifdef CONFIG_HAVE_LONG_LONG + using ::lldiv; +#endif +#endif + + // Temporary files + using ::mktemp; using ::mkstemp; + + // Sorting + using ::qsort; } diff --git a/include/stdlib.h b/include/stdlib.h index 433b11dc9a..12a1b951a9 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -203,6 +203,11 @@ FAR void *calloc(size_t, size_t); /* Arithmetic */ int abs(int j); +long int labs(long int j); +#ifdef CONFIG_HAVE_LONG_LONG +long long int llabs(long long int j); +#endif + #ifdef CONFIG_CAN_PASS_STRUCTS div_t div(int numer, int denom); ldiv_t ldiv(long numer, long denom); @@ -210,10 +215,6 @@ ldiv_t ldiv(long numer, long denom); lldiv_t lldiv(long long numer, long long denom); #endif #endif -long int labs(long int j); -#ifdef CONFIG_HAVE_LONG_LONG -long long int llabs(long long int j); -#endif /* Temporary files */ -- GitLab From 3303ef8c8590d85805afb720dd093dcb3557fbec Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Fri, 14 Aug 2015 13:47:18 -0400 Subject: [PATCH 031/858] Added support for other MS58XX altimeters. --- drivers/sensors/Kconfig | 10 +- drivers/sensors/Make.defs | 4 +- drivers/sensors/ms5805.c | 715 ------------ drivers/sensors/ms58xx.c | 1042 ++++++++++++++++++ include/nuttx/sensors/{ms5805.h => ms58xx.h} | 44 +- 5 files changed, 1083 insertions(+), 732 deletions(-) delete mode 100644 drivers/sensors/ms5805.c create mode 100644 drivers/sensors/ms58xx.c rename include/nuttx/sensors/{ms5805.h => ms58xx.h} (78%) diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index adbedd6ae8..4afdae7c85 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -31,12 +31,16 @@ config MB7040 ---help--- Enable driver support for the MaxBotix MB7040 sonar. -config MS5805 - bool "MEAS MS5805 Altimeter support" +config MS58XX + bool "MEAS MS58XX Altimeter support" default n select I2C ---help--- - Enable driver support for the MEAS MS5805 altimeter. + Enable driver support for MEAS MS58XX altimeters. + +config MS58XX_VDD + int "MEAS MS58XX VDD" + default 30 config MPL115A bool "Freescale MPL115A Barometer Sensor support" diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 20931edb3b..3625e10e62 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -73,8 +73,8 @@ ifeq ($(CONFIG_MB7040),y) CSRCS += mb7040.c endif -ifeq ($(CONFIG_MS5805),y) - CSRCS += ms5805.c +ifeq ($(CONFIG_MS58XX),y) + CSRCS += ms58xx.c endif endif # CONFIG_I2C diff --git a/drivers/sensors/ms5805.c b/drivers/sensors/ms5805.c deleted file mode 100644 index 073268184f..0000000000 --- a/drivers/sensors/ms5805.c +++ /dev/null @@ -1,715 +0,0 @@ -/**************************************************************************** - * drivers/sensors/ms5805.c - * Character driver for the MEAS MS5805 Altimeter - * - * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. - * Author: Paul Alexander Patience - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#if defined(CONFIG_I2C) && defined(CONFIG_MS5805) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* I2C Address **************************************************************/ - -#define MS5805_ADDR 0x76 - -/* Register Definitions *****************************************************/ -/* Register Addresses */ - -#define MS5805_RESET_REG 0x1e /* Reset Register */ -#define MS5805_PRESS_REG 0x40 /* Pressure Register */ -#define MS5805_TEMP_REG 0x50 /* Temperature Register */ -#define MS5805_ADC_REG 0x00 /* ADC Register */ -#define MS5805_PROM_REG 0xa0 /* PROM Register */ - -/* PROM Definitions *********************************************************/ - -#define MS5805_PROM_LEN 8 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct ms5805_dev_s -{ - FAR struct i2c_dev_s *i2c; /* I2C interface */ - int32_t temp; /* Uncompensated temperature (degrees Centigrade) */ - int32_t press; /* Uncompensated pressure (millibar) */ - uint8_t osr; /* Oversampling ratio bits */ - useconds_t delay; /* Oversampling ratio delay */ - - /* Calibration coefficients */ - - uint16_t c1; - uint16_t c2; - uint16_t c3; - uint16_t c4; - uint16_t c5; - uint16_t c6; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ -/* CRC Calculation */ - -static uint8_t ms5805_crc(FAR const uint8_t *src, size_t len); - -/* I2C Helpers */ - -static int ms5805_readu16(FAR struct ms5805_dev_s *priv, uint8_t regaddr, - FAR uint16_t *regval); -static int ms5805_readadc(FAR struct ms5805_dev_s *priv, FAR uint32_t *adc); -static int ms5805_setosr(FAR struct ms5805_dev_s *priv, uint16_t osr); -static int ms5805_reset(FAR struct ms5805_dev_s *priv); -static int ms5805_readprom(FAR struct ms5805_dev_s *priv); -static int ms5805_convert(FAR struct ms5805_dev_s *priv, uint8_t regaddr, - FAR uint32_t *regval); -static int ms5805_measure(FAR struct ms5805_dev_s *priv); - -/* Character Driver Methods */ - -static int ms5805_open(FAR struct file *filep); -static int ms5805_close(FAR struct file *filep); -static ssize_t ms5805_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); -static ssize_t ms5805_write(FAR struct file *filep, FAR const char *buffer, - size_t buflen); -static int ms5805_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct file_operations g_fops = -{ - ms5805_open, - ms5805_close, - ms5805_read, - ms5805_write, - NULL, - ms5805_ioctl -#ifndef CONFIG_DISABLE_POLL - , NULL -#endif -#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS - , NULL -#endif -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ms5805_crc - * - * Description: - * Calculate the CRC. - * - ****************************************************************************/ - -static uint8_t ms5805_crc(FAR const uint8_t *src, size_t len) -{ - uint16_t crc = 0; - size_t i; - int j; - - for (i = 0; i < len; i++) - { - crc ^= src[i]; - - for (j = 0; j < 8; j++) - { - bool xor = (crc & 0x8000) != 0; - - crc <<= 1; - if (xor) - { - crc ^= 0x3000; - } - } - } - - return (uint8_t)(crc >> 12); -} - -/**************************************************************************** - * Name: ms5805_readu16 - * - * Description: - * Read from a 16-bit register. - * - ****************************************************************************/ - -static int ms5805_readu16(FAR struct ms5805_dev_s *priv, uint8_t regaddr, - FAR uint16_t *regval) -{ - uint8_t buffer[2]; - int ret; - - sndbg("addr: %02x\n", regaddr); - - /* Write the register address */ - - I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); - if (ret < 0) - { - sndbg("I2C_WRITE failed: %d\n", ret); - return ret; - } - - /* Restart and read 16 bits from the register */ - - ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); - if (ret < 0) - { - sndbg("I2C_READ failed: %d\n", ret); - return ret; - } - - *regval = (uint16_t)buffer[0] << 8 | (uint16_t)buffer[1]; - sndbg("value: %04x ret: %d\n", *regval, ret); - return ret; -} - -/**************************************************************************** - * Name: ms5805_readadc - * - * Description: - * Read from the ADC register. - * - ****************************************************************************/ - -static int ms5805_readadc(FAR struct ms5805_dev_s *priv, FAR uint32_t *adc) -{ - uint8_t regaddr; - uint8_t buffer[3]; - int ret; - - regaddr = MS5805_ADC_REG; - sndbg("addr: %02x\n", regaddr); - - /* Write the register address */ - - I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); - if (ret < 0) - { - sndbg("I2C_WRITE failed: %d\n", ret); - return ret; - } - - /* Restart and read 24 bits from the register */ - - ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); - if (ret < 0) - { - sndbg("I2C_READ failed: %d\n", ret); - return ret; - } - - *adc = (uint32_t)buffer[0] << 16 | - (uint32_t)buffer[1] << 8 | - (uint32_t)buffer[2]; - sndbg("adc: %06x ret: %d\n", *adc, ret); - return ret; -} - -/**************************************************************************** - * Name: ms5805_setosr - * - * Description: - * Set the oversampling ratio. - * - ****************************************************************************/ - -static int ms5805_setosr(FAR struct ms5805_dev_s *priv, uint16_t osr) -{ - int ret = OK; - - sndbg("osr: %04x\n", osr); - - switch (osr) - { - case 256: - priv->delay = 540; - break; - - case 512: - priv->delay = 1060; - break; - - case 1024: - priv->delay = 2080; - break; - - case 2048: - priv->delay = 4130; - break; - - case 4096: - priv->delay = 8220; - break; - - case 8192: - priv->delay = 16440; - break; - - default: - ret = -EINVAL; - break; - } - - if (ret == OK) - { - priv->osr = (osr / 256 - 1) * 2; - } - - return ret; -} - -/**************************************************************************** - * Name: ms5805_readprom - * - * Description: - * Read from the PROM. - * - ****************************************************************************/ - -static int ms5805_readprom(FAR struct ms5805_dev_s *priv) -{ - uint16_t prom[MS5805_PROM_LEN]; - uint8_t regaddr; - uint8_t crc; - int ret; - int i; - - regaddr = MS5805_PROM_REG; - for (i = 0; i < MS5805_PROM_LEN-1; i++) - { - ret = ms5805_readu16(priv, regaddr, prom+i); - if (ret < 0) - { - sndbg("ms5805_readu16 failed: %d\n", ret); - return ret; - } - - regaddr += 2; - } - - crc = (uint8_t)(prom[0] >> 12); - - prom[0] = 0; - prom[MS5805_PROM_LEN-1] = 0; - - if (crc != ms5805_crc((uint8_t *)prom, sizeof(prom))) - { - sndbg("crc mismatch\n"); - return -ENODEV; - } - - priv->c1 = prom[1]; - priv->c2 = prom[2]; - priv->c3 = prom[3]; - priv->c4 = prom[4]; - priv->c5 = prom[5]; - priv->c6 = prom[6]; - - return ret; -} - -/**************************************************************************** - * Name: ms5805_reset - * - * Description: - * Reset the device. - * - ****************************************************************************/ - -static int ms5805_reset(FAR struct ms5805_dev_s *priv) -{ - uint8_t regaddr; - int ret; - - regaddr = MS5805_RESET_REG; - sndbg("addr: %02x\n", regaddr); - - /* Write the register address */ - - I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); - if (ret < 0) - { - sndbg("I2C_WRITE failed: %d\n", ret); - return ret; - } - - /* Check the CRC and read the calibration coefficients */ - - ret = ms5805_readprom(priv); - if (ret < 0) - { - sndbg("ms5805_readprom failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: ms5805_convert - * - * Description: - * Measure the uncompensated temperature or the uncompensated pressure. - * - ****************************************************************************/ - -static int ms5805_convert(FAR struct ms5805_dev_s *priv, uint8_t regaddr, - FAR uint32_t *regval) -{ - int ret; - - regaddr |= priv->osr; - sndbg("addr: %02x\n", regaddr); - - /* Write the register address */ - - I2C_SETADDRESS(priv->i2c, MS5805_ADDR, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); - if (ret < 0) - { - sndbg("I2C_WRITE failed: %d\n", ret); - } - - /* Wait for the conversion to end */ - - up_udelay(priv->delay); - - /* Read the value from the ADC */ - - ret = ms5805_readadc(priv, regval); - if (ret < 0) - { - sndbg("ms5805_readadc failed: %d\n", ret); - return ret; - } - - return ret; -} - -/**************************************************************************** - * Name: ms5805_measure - * - * Description: - * Measure the compensated temperature and the compensated pressure. - * - ****************************************************************************/ - -static int ms5805_measure(FAR struct ms5805_dev_s *priv) -{ - uint32_t rawpress; - uint32_t rawtemp; - int32_t diff; - int32_t temp; - int64_t off; - int64_t sens; - int32_t press; - int ret; - - ret = ms5805_convert(priv, MS5805_PRESS_REG, &rawpress); - if (ret < 0) - { - sndbg("ms5805_convert failed: %d\n", ret); - return ret; - } - - ret = ms5805_convert(priv, MS5805_TEMP_REG, &rawtemp); - if (ret < 0) - { - sndbg("ms5805_convert failed: %d\n", ret); - return ret; - } - - diff = (int32_t)rawtemp - (int32_t)priv->c5 / ((int32_t)1 << 8); - temp = (int32_t)((int64_t)20 + - (int64_t)diff * (int64_t)priv->c6 / ((int64_t)1 << 23)); - - off = (int64_t)priv->c2 * ((int64_t)1 << 17) + - (int64_t)priv->c4 * (int64_t)diff / ((int64_t)1 << 8); - sens = (int64_t)priv->c1 * ((int64_t)1 << 16) + - (int64_t)priv->c3 * (int64_t)diff / ((int64_t)1 << 7); - - if (temp < 2000) - { - int32_t ti; - int64_t offi; - int64_t sensi; - - ti = (int32_t)((int64_t)11 * (int64_t)diff * - (int64_t)diff / ((int64_t)1 << 35)); - offi = (int64_t)31 * ((int64_t)temp - (int64_t)2000) * - ((int64_t)temp - (int64_t)2000) / ((int64_t)1 << 3); - sensi = (int64_t)63 * ((int64_t)temp - (int64_t)2000) * - ((int64_t)temp - (int64_t)2000) / ((int64_t)1 << 5); - - temp -= ti; - off -= offi; - sens -= sensi; - } - - press = (int32_t)(((int64_t)rawpress * sens / ((int64_t)1 << 21) - off) / - ((int64_t)1 << 15)); - - priv->temp = temp / (int32_t)100; - priv->press = press / (int32_t)100; - return ret; -} - -/**************************************************************************** - * Name: ms5805_open - * - * Description: - * This method is called when the device is opened. - * - ****************************************************************************/ - -static int ms5805_open(FAR struct file *filep) -{ - return OK; -} - -/**************************************************************************** - * Name: ms5805_close - * - * Description: - * This method is called when the device is closed. - * - ****************************************************************************/ - -static int ms5805_close(FAR struct file *filep) -{ - return OK; -} - -/**************************************************************************** - * Name: ms5805_read - * - * Description: - * A dummy read method. - * - ****************************************************************************/ - -static ssize_t ms5805_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) -{ - return 0; -} - -/**************************************************************************** - * Name: ms5805_write - * - * Description: - * A dummy write method. - * - ****************************************************************************/ - -static ssize_t ms5805_write(FAR struct file *filep, FAR const char *buffer, - size_t buflen) -{ - return -ENOSYS; -} - -/**************************************************************************** - * Name: ms5805_ioctl - * - * Description: - * The standard ioctl method. - * - ****************************************************************************/ - -static int ms5805_ioctl(FAR struct file *filep, int cmd, unsigned long arg) -{ - FAR struct inode *inode = filep->f_inode; - FAR struct ms5805_dev_s *priv = inode->i_private; - int ret = OK; - - /* Handle ioctl commands */ - - switch (cmd) - { - /* Measure the temperature and the pressure. Arg: None. */ - - case SNIOC_MEASURE: - DEBUGASSERT(arg == 0); - ret = ms5805_measure(priv); - break; - - /* Return the temperature last measured. Arg: int32_t* pointer. */ - - case SNIOC_TEMPERATURE: - { - FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); - DEBUGASSERT(ptr != NULL); - *ptr = priv->temp; - sndbg("temp: %08x\n", *ptr); - } - break; - - /* Return the pressure last measured. Arg: int32_t* pointer. */ - - case SNIOC_PRESSURE: - { - FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); - DEBUGASSERT(ptr != NULL); - *ptr = priv->press; - sndbg("press: %08x\n", *ptr); - } - break; - - /* Reset the device. Arg: None. */ - - case SNIOC_RESET: - DEBUGASSERT(arg == 0); - ret = ms5805_reset(priv); - break; - - /* Change the oversampling ratio. Arg: uint16_t value. */ - - case SNIOC_OVERSAMPLING: - ret = ms5805_setosr(priv, (uint16_t)arg); - sndbg("osr: %04x ret: %d\n", *(uint16_t *)arg, ret); - break; - - /* Unrecognized commands */ - - default: - sndbg("Unrecognized cmd: %d arg: %ld\n", cmd, arg); - ret = -ENOTTY; - break; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ms5805_register - * - * Description: - * Register the MS5805 character device as 'devpath'. - * - * Input Parameters: - * devpath - The full path to the driver to register, e.g., "/dev/press0". - * i2c - An I2C driver instance. - * osr - The oversampling ratio. - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -int ms5805_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, - uint16_t osr) -{ - FAR struct ms5805_dev_s *priv; - int ret; - - /* Sanity check */ - - DEBUGASSERT(i2c != NULL); - - /* Initialize the device's structure */ - - priv = (FAR struct ms5805_dev_s *)kmm_malloc(sizeof(*priv)); - if (priv == NULL) - { - sndbg("Failed to allocate instance\n"); - return -ENOMEM; - } - - priv->i2c = i2c; - priv->temp = 0; - priv->press = 0; - - ret = ms5805_setosr(priv, osr); - if (ret < 0) - { - sndbg("ms5805_setosr failed: %d\n", ret); - goto err; - } - - ret = ms5805_reset(priv); - if (ret < 0) - { - sndbg("ms5805_reset failed: %d\n", ret); - goto err; - } - - /* Register the character driver */ - - ret = register_driver(devpath, &g_fops, 0666, priv); - if (ret < 0) - { - sndbg("Failed to register driver: %d\n", ret); - goto err; - } - - return ret; - -err: - kmm_free(priv); - return ret; -} - -#endif /* CONFIG_I2C && CONFIG_MS5805 */ diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c new file mode 100644 index 0000000000..e539b1eaa8 --- /dev/null +++ b/drivers/sensors/ms58xx.c @@ -0,0 +1,1042 @@ +/**************************************************************************** + * drivers/sensors/ms58xx.c + * Character driver for MEAS MS58XX Altimeters + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MS58XX) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Register Definitions *****************************************************/ +/* Register Addresses */ + +#define MS58XX_RESET_REG 0x1e /* Reset Register */ +#define MS58XX_PRESS_REG 0x40 /* Pressure Register */ +#define MS58XX_TEMP_REG 0x50 /* Temperature Register */ +#define MS58XX_ADC_REG 0x00 /* ADC Register */ +#define MS58XX_PROM_REG 0xa0 /* PROM Register */ + +/* PROM Definitions *********************************************************/ + +#define MS58XX_PROM_LEN 8 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ms58xx_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + + enum ms58xx_model_e model; + uint8_t crcindex; + uint8_t crcshift; + + int32_t temp; /* Uncompensated temperature (degrees Centigrade) */ + int32_t press; /* Uncompensated pressure (millibar) */ + + uint8_t osr; /* Oversampling ratio bits */ + useconds_t delay; /* Oversampling ratio delay */ + + /* Calibration coefficients */ + + uint16_t c1; + uint16_t c2; + uint16_t c3; + uint16_t c4; + uint16_t c5; + uint16_t c6; + uint8_t c7; + uint8_t c8; + + /* Constants used when calculating the temperature and the pressure */ + + uint8_t c1s; + uint8_t c2s; + uint8_t c3s; + uint8_t c4s; + + uint8_t diffmull; + uint8_t diffdivls; + uint8_t offmull; + uint8_t offdivls; + uint8_t sensmull; + uint8_t sensdivls; + + uint8_t offmulvl; + uint8_t sensmulvl; + + uint8_t diffmulh; + uint8_t diffdivhs; + uint8_t offmulh; + uint8_t offdivhs; + uint8_t sensmulh; + uint8_t sensdivhs; + + uint8_t pressdivs; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* CRC Calculation */ + +static uint8_t ms58xx_crc(FAR const uint8_t *src, size_t len); + +/* I2C Helpers */ + +static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, + FAR uint16_t *regval); +static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc); +static int ms58xx_setosr(FAR struct ms58xx_dev_s *priv, uint16_t osr); +static int ms58xx_reset(FAR struct ms58xx_dev_s *priv); +static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv); +static int ms58xx_convert(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, + FAR uint32_t *regval); +static int ms58xx_measure(FAR struct ms58xx_dev_s *priv); + +/* Character Driver Methods */ + +static int ms58xx_open(FAR struct file *filep); +static int ms58xx_close(FAR struct file *filep); +static ssize_t ms58xx_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t ms58xx_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int ms58xx_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_fops = +{ + ms58xx_open, + ms58xx_close, + ms58xx_read, + ms58xx_write, + NULL, + ms58xx_ioctl +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ms58xx_crc + * + * Description: + * Calculate the CRC. + * + ****************************************************************************/ + +static uint8_t ms58xx_crc(FAR const uint8_t *src, size_t len) +{ + uint16_t crc = 0; + size_t i; + int j; + + for (i = 0; i < len; i++) + { + crc ^= src[i]; + + for (j = 0; j < 8; j++) + { + bool xor = (crc & 0x8000) != 0; + + crc <<= 1; + if (xor) + { + crc ^= 0x3000; + } + } + } + + return (uint8_t)(crc >> 12); +} + +/**************************************************************************** + * Name: ms58xx_readu16 + * + * Description: + * Read from a 16-bit register. + * + ****************************************************************************/ + +static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, + FAR uint16_t *regval) +{ + uint8_t buffer[2]; + int ret; + + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 16 bits from the register */ + + ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + *regval = (uint16_t)buffer[0] << 8 | (uint16_t)buffer[1]; + sndbg("value: %04x ret: %d\n", *regval, ret); + return ret; +} + +/**************************************************************************** + * Name: ms58xx_readadc + * + * Description: + * Read from the ADC register. + * + ****************************************************************************/ + +static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc) +{ + uint8_t regaddr; + uint8_t buffer[3]; + int ret; + + regaddr = MS58XX_ADC_REG; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 24 bits from the register */ + + ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + *adc = (uint32_t)buffer[0] << 16 | + (uint32_t)buffer[1] << 8 | + (uint32_t)buffer[2]; + sndbg("adc: %06x ret: %d\n", *adc, ret); + return ret; +} + +/**************************************************************************** + * Name: ms58xx_setosr + * + * Description: + * Set the oversampling ratio. + * + ****************************************************************************/ + +static int ms58xx_setosr(FAR struct ms58xx_dev_s *priv, uint16_t osr) +{ + int ret = OK; + + sndbg("osr: %04x\n", osr); + + switch (osr) + { + case 256: + priv->delay = 600; + break; + + case 512: + priv->delay = 1170; + break; + + case 1024: + priv->delay = 2280; + break; + + case 2048: + priv->delay = 4540; + break; + + case 4096: + priv->delay = 9040; + break; + + case 8192: + switch (priv->model) + { + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5837_30: + priv->delay = 18080; + break; + + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_07: + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5806_02: + default: + ret = -EINVAL; + break; + } + break; + + default: + ret = -EINVAL; + break; + } + + if (ret == OK) + { + priv->osr = (osr / 256 - 1) * 2; + } + + return ret; +} + +/**************************************************************************** + * Name: ms58xx_readprom + * + * Description: + * Read from the PROM. + * + ****************************************************************************/ + +static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv) +{ + uint16_t prom[MS58XX_PROM_LEN]; + uint8_t crc; + uint8_t crcindex; + uint8_t crcshift; + uint16_t crcmask; + int ret; + int i; + int len = MS58XX_PROM_LEN; + + switch (priv->model) + { + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5837_30: + prom[MS58XX_PROM_LEN-1] = 0; + len--; + crcindex = 0; + crcshift = 12; + break; + + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_07: + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5806_02: + default: + crcindex = 7; + crcshift = 0; + break; + } + + for (i = 0; i < len; i++) + { + ret = ms58xx_readu16(priv, MS58XX_PROM_REG+i*2, prom+i); + if (ret < 0) + { + sndbg("ms58xx_readu16 failed: %d\n", ret); + return ret; + } + } + + crcmask = (uint16_t)0xf << crcshift; + crc = (uint8_t)((prom[crcindex] & crcmask) >> crcshift); + prom[crcindex] &= ~crcmask; + + if (crc != ms58xx_crc((uint8_t *)prom, sizeof(prom))) + { + sndbg("crc mismatch\n"); + return -ENODEV; + } + + priv->c1 = prom[1]; + priv->c2 = prom[2]; + priv->c3 = prom[3]; + priv->c4 = prom[4]; + priv->c5 = prom[5]; + priv->c6 = prom[6]; + + switch (priv->model) + { + case MS58XX_MODEL_MS5803_07: + priv->c7 = (uint8_t)((prom[7] & 0x03f0) >> 4); + priv->c8 = (uint8_t)((prom[7] & 0xf700) >> 10); + break; + + case MS58XX_MODEL_MS5806_02: + priv->c7 = (uint8_t)((prom[7] & 0x0ff0) >> 4); + priv->c8 = 0; + break; + + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5837_30: + default: + priv->c7 = 0; + priv->c8 = 0; + break; + } + + return ret; +} + +/**************************************************************************** + * Name: ms58xx_reset + * + * Description: + * Reset the device. + * + ****************************************************************************/ + +static int ms58xx_reset(FAR struct ms58xx_dev_s *priv) +{ + uint8_t regaddr; + int ret; + + regaddr = MS58XX_RESET_REG; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Check the CRC and read the calibration coefficients */ + + ret = ms58xx_readprom(priv); + if (ret < 0) + { + sndbg("ms58xx_readprom failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: ms58xx_convert + * + * Description: + * Measure the uncompensated temperature or the uncompensated pressure. + * + ****************************************************************************/ + +static int ms58xx_convert(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, + FAR uint32_t *regval) +{ + int ret; + + regaddr |= priv->osr; + sndbg("addr: %02x\n", regaddr); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + } + + /* Wait for the conversion to end */ + + up_udelay(priv->delay); + + /* Read the value from the ADC */ + + ret = ms58xx_readadc(priv, regval); + if (ret < 0) + { + sndbg("ms58xx_readadc failed: %d\n", ret); + return ret; + } + + return ret; +} + +/**************************************************************************** + * Name: ms58xx_measure + * + * Description: + * Measure the compensated temperature and the compensated pressure. + * + ****************************************************************************/ + +static int ms58xx_measure(FAR struct ms58xx_dev_s *priv) +{ + uint32_t rawpress; + uint32_t rawtemp; + int32_t diff; + int32_t temp; + int64_t off; + int64_t sens; + int32_t press; + int64_t diffmul; + int64_t diffdiv; + int64_t offmula; + int64_t offdiva; + int64_t sensmula; + int64_t sensdiva; + int64_t offmulb; + int64_t sensmulb; + int64_t tm; + int64_t tp; + int ret; + + ret = ms58xx_convert(priv, MS58XX_PRESS_REG, &rawpress); + if (ret < 0) + { + sndbg("ms58xx_convert failed: %d\n", ret); + return ret; + } + + ret = ms58xx_convert(priv, MS58XX_TEMP_REG, &rawtemp); + if (ret < 0) + { + sndbg("ms58xx_convert failed: %d\n", ret); + return ret; + } + + diff = (int32_t)rawtemp - (int32_t)priv->c5 / ((int32_t)1 << 8); + temp = (int32_t)((int64_t)2000 + + (int64_t)diff * (int64_t)priv->c6 / ((int64_t)1 << 23)); + + off = (int64_t)priv->c2 * ((int64_t)1 << priv->c2s) + + (int64_t)priv->c4 * (int64_t)diff / ((int64_t)1 << priv->c4s); + sens = (int64_t)priv->c1 * ((int64_t)1 << priv->c1s) + + (int64_t)priv->c3 * (int64_t)diff / ((int64_t)1 << priv->c3s); + + if (temp < 2000) + { + diffmul = (int64_t)priv->diffmull; + diffdiv = (int64_t)1 << priv->diffdivls; + offmula = (int64_t)priv->offmull; + offdiva = (int64_t)1 << priv->offdivls; + sensmula = (int64_t)priv->sensmull; + sensdiva = (int64_t)1 << priv->sensdivls; + + if (temp < -1500) + { + offmulb = (int64_t)priv->offmulvl; + sensmulb = (int64_t)priv->sensmulvl; + } + else + { + offmulb = 0; + sensmulb = 0; + } + } + else + { + diffmul = (int64_t)priv->diffmulh; + diffdiv = (int64_t)1 << priv->diffdivhs; + offmula = (int64_t)priv->offmulh; + offdiva = (int64_t)1 << priv->offdivhs; + sensmula = (int64_t)priv->sensmulh; + sensdiva = (int64_t)1 << priv->sensdivhs; + + offmulb = 0; + sensmulb = 0; + } + + tm = (int64_t)temp - (int64_t)2000; + tm *= tm; + + tp = (int64_t)temp + (int64_t)1500; + tp *= tp; + + off -= offmula * tm / offdiva + offmulb * tp; + sens -= sensmula * tm / sensdiva + sensmulb * tp; + temp -= (int32_t)(diffmul * (int64_t)diff * (int64_t)diff / diffdiv); + + press = (int32_t)(((int64_t)rawpress * sens / ((int64_t)1 << 21) - off) / + ((int64_t)1 << priv->pressdivs)); + + switch (priv->model) + { + case MS58XX_MODEL_MS5803_07: + if (press > 110000) + { + press += (int32_t)((((int64_t)priv->c7 - ((int64_t)1 << 5)) * + (int64_t)100 * ((int64_t)1 << 2) - + ((int64_t)priv->c8 - ((int64_t)1 << 5)) * + ((int64_t)temp - (int64_t)2000) / + ((int64_t)1 << 4)) * + ((int64_t)press - (int64_t)110000) / + (int64_t)49000000); + } + break; + + case MS58XX_MODEL_MS5806_02: +#if CONFIG_MS58XX_VDD >= 22 && CONFIG_MS58XX_VDD <= 30 + press += (int32_t)(((int64_t)30 - (int64_t)CONFIG_MS58XX_VDD) * + (int64_t)priv->c7 / + (((int64_t)1 << 6) * (int64_t)10)); +#endif + break; + + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5837_30: + break; + } + + priv->temp = temp; + priv->press = press; + return ret; +} + +/**************************************************************************** + * Name: ms58xx_open + * + * Description: + * This method is called when the device is opened. + * + ****************************************************************************/ + +static int ms58xx_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: ms58xx_close + * + * Description: + * This method is called when the device is closed. + * + ****************************************************************************/ + +static int ms58xx_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: ms58xx_read + * + * Description: + * A dummy read method. + * + ****************************************************************************/ + +static ssize_t ms58xx_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + return 0; +} + +/**************************************************************************** + * Name: ms58xx_write + * + * Description: + * A dummy write method. + * + ****************************************************************************/ + +static ssize_t ms58xx_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: ms58xx_ioctl + * + * Description: + * The standard ioctl method. + * + ****************************************************************************/ + +static int ms58xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ms58xx_dev_s *priv = inode->i_private; + int ret = OK; + + /* Handle ioctl commands */ + + switch (cmd) + { + /* Measure the temperature and the pressure. Arg: None. */ + + case SNIOC_MEASURE: + DEBUGASSERT(arg == 0); + ret = ms58xx_measure(priv); + break; + + /* Return the temperature last measured. Arg: int32_t* pointer. */ + + case SNIOC_TEMPERATURE: + { + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); + *ptr = priv->temp; + sndbg("temp: %08x\n", *ptr); + } + break; + + /* Return the pressure last measured. Arg: int32_t* pointer. */ + + case SNIOC_PRESSURE: + { + FAR int32_t *ptr = (FAR int32_t *)((uintptr_t)arg); + DEBUGASSERT(ptr != NULL); + *ptr = priv->press; + sndbg("press: %08x\n", *ptr); + } + break; + + /* Reset the device. Arg: None. */ + + case SNIOC_RESET: + DEBUGASSERT(arg == 0); + ret = ms58xx_reset(priv); + break; + + /* Change the oversampling ratio. Arg: uint16_t value. */ + + case SNIOC_OVERSAMPLING: + ret = ms58xx_setosr(priv, (uint16_t)arg); + sndbg("osr: %04x ret: %d\n", *(uint16_t *)arg, ret); + break; + + /* Unrecognized commands */ + + default: + sndbg("Unrecognized cmd: %d arg: %ld\n", cmd, arg); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ms58xx_register + * + * Description: + * Register the MS58XX character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/press0". + * i2c - An I2C driver instance. + * addr - The I2C address of the MS58XX. + * osr - The oversampling ratio. + * model - The MS58XX model. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ms58xx_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr, uint16_t osr, enum ms58xx_model_e model) +{ + FAR struct ms58xx_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + DEBUGASSERT((model == MS58XX_MODEL_MS5803_02 || + model == MS58XX_MODEL_MS5803_05 || + model == MS58XX_MODEL_MS5803_07 || + model == MS58XX_MODEL_MS5803_14 || + model == MS58XX_MODEL_MS5803_30 || + model == MS58XX_MODEL_MS5806_02) && + (addr == MS58XX_ADDR0 || addr == MS58XX_ADDR1) || + (model == MS58XX_MODEL_MS5805_02 || + model == MS58XX_MODEL_MS5837_30) && + addr == MS58XX_ADDR0); + + /* Initialize the device's structure */ + + priv = (FAR struct ms58xx_dev_s *)kmm_malloc(sizeof(*priv)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + priv->model = model; + priv->temp = 0; + priv->press = 0; + + switch (priv->model) + { + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5806_02: + default: + priv->c1s = 16; + priv->c2s = 17; + priv->c3s = 7; + priv->c4s = 6; + break; + + case MS58XX_MODEL_MS5803_05: + priv->c1s = 17; + priv->c2s = 18; + priv->c3s = 7; + priv->c4s = 5; + break; + + case MS58XX_MODEL_MS5803_07: + priv->c1s = 17; + priv->c2s = 18; + priv->c3s = 6; + priv->c4s = 5; + break; + + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5837_30: + priv->c1s = 15; + priv->c2s = 16; + priv->c3s = 8; + priv->c4s = 7; + break; + } + + switch (priv->model) + { + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5806_02: + priv->diffmull = 1; + priv->diffdivls = 31; + priv->offmull = 61; + priv->offdivls = 4; + priv->sensmull = 2; + priv->sensdivls = 0; + + priv->offmulvl = 20; + priv->sensmulvl = 12; + + priv->diffmulh = 0; + priv->diffdivhs = 0; + priv->offmulh = 0; + priv->offdivhs = 0; + priv->sensmulh = 0; + priv->sensdivhs = 0; + break; + + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_07: + priv->diffmull = 3; + priv->diffdivls = 33; + priv->offmull = 3; + priv->offdivls = 3; + priv->sensmull = 7; + priv->sensdivls = 3; + + priv->offmulvl = 0; + priv->sensmulvl = 3; + + priv->diffmulh = 0; + priv->diffdivhs = 0; + priv->offmulh = 0; + priv->offdivhs = 0; + priv->sensmulh = 0; + priv->sensdivhs = 0; + break; + + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5803_30: + priv->diffmull = 3; + priv->diffdivls = 33; + priv->offmull = 3; + priv->offdivls = 1; + priv->sensmull = 5; + priv->sensdivls = 3; + + priv->offmulvl = 7; + priv->sensmulvl = 4; + + priv->diffmulh = 7; + priv->diffdivhs = 37; + priv->offmulh = 1; + priv->offdivhs = 4; + priv->sensmulh = 0; + priv->sensdivhs = 0; + break; + + case MS58XX_MODEL_MS5805_02: + priv->diffmull = 11; + priv->diffdivls = 35; + priv->offmull = 31; + priv->offdivls = 3; + priv->sensmull = 63; + priv->sensdivls = 5; + + priv->offmulvl = 0; + priv->sensmulvl = 0; + + priv->diffmulh = 0; + priv->diffdivhs = 0; + priv->offmulh = 0; + priv->offdivhs = 0; + priv->sensmulh = 0; + priv->sensdivhs = 0; + break; + + case MS58XX_MODEL_MS5837_30: + priv->diffmull = 3; + priv->diffdivls = 33; + priv->offmull = 3; + priv->offdivls = 1; + priv->sensmull = 5; + priv->sensdivls = 3; + + priv->offmulvl = 7; + priv->sensmulvl = 4; + + priv->diffmulh = 2; + priv->diffdivhs = 37; + priv->offmulh = 1; + priv->offdivhs = 4; + priv->sensmulh = 0; + priv->sensdivhs = 0; + break; + } + + switch (priv->model) + { + case MS58XX_MODEL_MS5803_02: + case MS58XX_MODEL_MS5803_05: + case MS58XX_MODEL_MS5803_14: + case MS58XX_MODEL_MS5805_02: + case MS58XX_MODEL_MS5806_02: + default: + priv->pressdivs = 15; + break; + + case MS58XX_MODEL_MS5803_30: + case MS58XX_MODEL_MS5837_30: + priv->pressdivs = 13; + break; + } + + ret = ms58xx_setosr(priv, osr); + if (ret < 0) + { + sndbg("ms58xx_setosr failed: %d\n", ret); + goto err; + } + + ret = ms58xx_reset(priv); + if (ret < 0) + { + sndbg("ms58xx_reset failed: %d\n", ret); + goto err; + } + + /* Register the character driver */ + + ret = register_driver(devpath, &g_fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + goto err; + } + + return ret; + +err: + kmm_free(priv); + return ret; +} + +#endif /* CONFIG_I2C && CONFIG_MS58XX */ diff --git a/include/nuttx/sensors/ms5805.h b/include/nuttx/sensors/ms58xx.h similarity index 78% rename from include/nuttx/sensors/ms5805.h rename to include/nuttx/sensors/ms58xx.h index 728889325f..3ad6bd3107 100644 --- a/include/nuttx/sensors/ms5805.h +++ b/include/nuttx/sensors/ms58xx.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/sensors/ms5805.h + * include/nuttx/sensors/ms58xx.h * * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_SENSORS_MS5805 -#define __INCLUDE_NUTTX_SENSORS_MS5805 +#ifndef __INCLUDE_NUTTX_SENSORS_MS58XX +#define __INCLUDE_NUTTX_SENSORS_MS58XX /**************************************************************************** * Included Files @@ -43,7 +43,7 @@ #include #include -#if defined(CONFIG_I2C) && defined(CONFIG_MS5805) +#if defined(CONFIG_I2C) && defined(CONFIG_MS58XX) /**************************************************************************** * Pre-processor Definitions @@ -53,8 +53,9 @@ * * CONFIG_I2C * Enables support for I2C drivers - * CONFIG_MS5805 - * Enables support for the MS5805 driver + * CONFIG_MS58XX + * Enables support for the MS58XX driver + * CONFIG_MS58XX_VDD */ /* IOCTL Commands ***********************************************************/ @@ -65,10 +66,27 @@ #define SNIOC_RESET _SNIOC(0x0004) /* Arg: None */ #define SNIOC_OVERSAMPLING _SNIOC(0x0005) /* Arg: uint16_t value */ +/* I2C Address **************************************************************/ + +#define MS58XX_ADDR0 0x76 +#define MS58XX_ADDR1 0x77 + /**************************************************************************** * Public Types ****************************************************************************/ +enum ms58xx_model_e +{ + MS58XX_MODEL_MS5803_02 = 0, + MS58XX_MODEL_MS5803_05 = 1, + MS58XX_MODEL_MS5803_07 = 2, + MS58XX_MODEL_MS5803_14 = 3, + MS58XX_MODEL_MS5803_30 = 4, + MS58XX_MODEL_MS5805_02 = 5, + MS58XX_MODEL_MS5806_02 = 6, + MS58XX_MODEL_MS5837_30 = 7 +}; + struct i2c_dev_s; /**************************************************************************** @@ -84,28 +102,30 @@ extern "C" #endif /**************************************************************************** - * Name: ms5805_register + * Name: ms58xx_register * * Description: - * Register the MS5805 character device as 'devpath'. + * Register the MS58XX character device as 'devpath'. * * Input Parameters: * devpath - The full path to the driver to register, e.g., "/dev/press0". * i2c - An I2C driver instance. + * addr - The I2C address of the MS58XX. * osr - The oversampling ratio. + * model - The MS58XX model. * * Returned Value: * Zero (OK) on success; a negated errno value on failure. * ****************************************************************************/ -int ms5805_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, - uint16_t osr); +int ms58xx_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr, uint16_t osr, enum ms58xx_model_e model); #undef EXTERN #ifdef __cplusplus } #endif -#endif /* CONFIG_I2C && CONFIG_MS5805 */ -#endif /* __INCLUDE_NUTTX_SENSORS_MS5805 */ +#endif /* CONFIG_I2C && CONFIG_MS58XX */ +#endif /* __INCLUDE_NUTTX_SENSORS_MS58XX */ -- GitLab From a33bcc42fd4ad3aa0e4fa71bca3741931df8a61a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 18:13:57 -0600 Subject: [PATCH 032/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bc43ca719b..a364185ded 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10827,4 +10827,8 @@ respectively, instead of int (2015-08-14). * include/signal.h and files that include it: Add si_errno to siginfo_t (2015-08-14). + * drivers/sensors/mx58xx.c and include/nuttx/sensors/ms58xx.h: + General the MS5805 altimeter driver to support other family + members and rename to ms58xx. From Paul Alexander Patience + (2015-08-14). diff --git a/arch b/arch index 6ab2a611d0..13d69bdf6f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6ab2a611d0ebd7520b6702b6da669387aa91c654 +Subproject commit 13d69bdf6f30f3893cc910301050a667931c6535 -- GitLab From 2478d27dd805737abeccdfbd9fe2678589e3413b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Aug 2015 13:03:31 -0600 Subject: [PATCH 033/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 13d69bdf6f..b1ae87d1e9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 13d69bdf6f30f3893cc910301050a667931c6535 +Subproject commit b1ae87d1e95d2c3593d87e2e6d292979bfdd68aa -- GitLab From 77f5c34af0e4e2c114476759e3971decfdf27f01 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 16 Aug 2015 11:00:30 -0600 Subject: [PATCH 034/858] Fix some common typos --- ChangeLog | 4 ++-- arch | 2 +- configs | 2 +- drivers/net/e1000.c | 4 ++-- drivers/usbdev/usbmsc_scsi.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a364185ded..1812628b4d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5333,7 +5333,7 @@ * arch/arm/src/sama5/sam_memories.c and .h: Centralize logic for conversions between physical and virtual addresses (2013-8-9). * arch/arm/src/sama5/sam_hsmci.c and sam34/sam_hsmci.c: Correct a - race condition in the SAMA5 HSCMI driver: The tranfer done + race condition in the SAMA5 HSCMI driver: The transfer done interrupt was firing before the wait was started. Fix this and also backported the changes to SAM3/4 (untested). Now HSCMI is functional on the SAMA5 with DMA! (2013-8-10). @@ -10383,7 +10383,7 @@ corrected implementation of pthread_kill() will direct the signal specifically to the specific pthread and no other (2015-05-13). * arch/arm/include/samdl, arch/arm/src/samdl, configs/samd20-xplained: - Rename the samd/ directories and configuratino varialbes to samdl to + Rename the samd/ directories and configuration varialbes to samdl to all the same directory structure to support the SAML21 (2015-05-14). * arch/arm/include/samdl and arch/arm/src/samdl: And chip definitions, configuration framework, and placeholder memory map and pin diff --git a/arch b/arch index b1ae87d1e9..97e57f60e9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b1ae87d1e95d2c3593d87e2e6d292979bfdd68aa +Subproject commit 97e57f60e929eb6e7be76edcfad4f67e8714ef25 diff --git a/configs b/configs index d22ff0b3ff..24588fc10a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d22ff0b3ff36cd5e324538b74b8064edaa3b63d8 +Subproject commit 24588fc10ae08f68c7dead477a7ad625b028679e diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index b122b75d98..38b0f15ee2 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -1128,8 +1128,8 @@ static int e1000_probe(uint16_t addr, pci_id_t id) * access performance. The page size alloc will restrict * this bad effect only within the memory we alloc here. * - * NEED FIX: the memalign may alloc memory continous in - * virtual address but dis-continous in physical address + * NEED FIX: the memalign may alloc memory continuous in + * virtual address but dis-continuous in physical address * due to RGMP memory setup. */ diff --git a/drivers/usbdev/usbmsc_scsi.c b/drivers/usbdev/usbmsc_scsi.c index fd8a5340ae..97b489b523 100644 --- a/drivers/usbdev/usbmsc_scsi.c +++ b/drivers/usbdev/usbmsc_scsi.c @@ -2281,7 +2281,7 @@ static int usbmsc_cmdwritestate(FAR struct usbmsc_dev_s *priv) xfrd = req->xfrd; priv->nreqbytes = xfrd; - /* Now loop until all of the data in the read request has been tranferred + /* Now loop until all of the data in the read request has been transferred * to the block driver OR all of the request data has been transferred. */ -- GitLab From 51f386d08a87172ec7f83ab08b23c61c692f0058 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 16 Aug 2015 11:07:23 -0600 Subject: [PATCH 035/858] Fix more common typos --- ChangeLog | 4 ++-- arch | 2 +- drivers/usbdev/usbdev_strings.c | 6 +++--- include/nuttx/binfmt/elf.h | 2 +- include/nuttx/binfmt/nxflat.h | 2 +- libc/stdio/lib_fopen.c | 2 +- sched/Kconfig | 2 +- sched/group/group_setupstreams.c | 2 +- sched/task/task_spawnparms.c | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1812628b4d..3acfa4f652 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1233,7 +1233,7 @@ macros definitions (patch submitted by Tiago Maluta). * Documents/NuttxPortingGuide.html, configs/README.txt, etc. - Replaced CONFIG_EXAMPLE with CONFIG_APP_DIR (see documents for - desciption). This allows NuttX application code to be built + description). This allows NuttX application code to be built outside of the examples/ directory. For people who have their own configurations and/or Makefiles, @@ -1325,7 +1325,7 @@ * configs/avr32dev1/nsh: Added a configuration to support the NuttShell (NSH). As of this writing, here is a problem receiving serial data (this is, very likely, my hardware setup). - * lib/lib_open.c: Fix an error in fdopen when a valid file desciptor does + * lib/lib_open.c: Fix an error in fdopen when a valid file descriptor does not refer to an open file. * configs/olimex-lpc1766stk: Add support for the Olimex LPC1766-STK development board. The OS test and NSH configurations (only) have been diff --git a/arch b/arch index 97e57f60e9..a7a7a7c6dd 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 97e57f60e929eb6e7be76edcfad4f67e8714ef25 +Subproject commit a7a7a7c6dd4f36f690139bc457064e6b24d009eb diff --git a/drivers/usbdev/usbdev_strings.c b/drivers/usbdev/usbdev_strings.c index 94771369b9..9dc9afdc40 100644 --- a/drivers/usbdev/usbdev_strings.c +++ b/drivers/usbdev/usbdev_strings.c @@ -49,7 +49,7 @@ * Public Data ****************************************************************************/ -/* Class API call strings that may be enabled for more desciptive USB trace +/* Class API call strings that may be enabled for more descriptive USB trace * output. */ @@ -72,7 +72,7 @@ const struct trace_msg_t g_usb_trace_strings_clsapi[] = TRACE_STR_END }; -/* Class state strings that may be enabled for more desciptive USB trace +/* Class state strings that may be enabled for more descriptive USB trace * output. */ @@ -97,7 +97,7 @@ const struct trace_msg_t g_usb_trace_strings_clsstate[] = TRACE_STR_END }; -/* Class error strings that may be enabled for more desciptive USB trace +/* Class error strings that may be enabled for more descriptive USB trace * output. */ diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h index ed42499356..982fc4462d 100644 --- a/include/nuttx/binfmt/elf.h +++ b/include/nuttx/binfmt/elf.h @@ -86,7 +86,7 @@ * Public Types ****************************************************************************/ -/* This struct provides a desciption of the currently loaded instantiation +/* This struct provides a description of the currently loaded instantiation * of an ELF binary. */ diff --git a/include/nuttx/binfmt/nxflat.h b/include/nuttx/binfmt/nxflat.h index 8e661115b0..eb039f40a1 100644 --- a/include/nuttx/binfmt/nxflat.h +++ b/include/nuttx/binfmt/nxflat.h @@ -56,7 +56,7 @@ * Public Types ****************************************************************************/ -/* This struct provides a desciption of the currently loaded instantiation +/* This struct provides a description of the currently loaded instantiation * of an nxflat binary. */ diff --git a/libc/stdio/lib_fopen.c b/libc/stdio/lib_fopen.c index 62cada68a6..a29140ebae 100644 --- a/libc/stdio/lib_fopen.c +++ b/libc/stdio/lib_fopen.c @@ -294,7 +294,7 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode) fd = open(path, oflags, 0666); /* If the open was successful, then fdopen() the fil using the file - * desciptor returned by open. If open failed, then just return the + * descriptor returned by open. If open failed, then just return the * NULL stream -- open() has already set the errno. */ diff --git a/sched/Kconfig b/sched/Kconfig index be15080ea4..941026ffa1 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -606,7 +606,7 @@ config SDCLONE_DISABLE default n ---help--- Disable cloning of all socket - desciptors by task_create() when a new task is started. If + descriptors by task_create() when a new task is started. If set, all sockets will appear to be closed in the new task. config NFILE_DESCRIPTORS diff --git a/sched/group/group_setupstreams.c b/sched/group/group_setupstreams.c index 72fc12dd6e..292f0a6fe4 100644 --- a/sched/group/group_setupstreams.c +++ b/sched/group/group_setupstreams.c @@ -68,7 +68,7 @@ * * Description: * Setup streams data structures that may be used for standard C buffered - * I/O with underlying socket or file desciptors + * I/O with underlying socket or file descriptors * ****************************************************************************/ diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index 8e1b0318fb..df0946c2fb 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -127,7 +127,7 @@ static inline int spawn_open(FAR struct spawn_open_file_action_s *action) } /* Does the return file descriptor happen to match the required file - * desciptor number? + * descriptor number? */ else if (fd != action->fd) -- GitLab From 425146255ad1dc568a800c251454ef626827561f Mon Sep 17 00:00:00 2001 From: Max Neklyudov Date: Mon, 17 Aug 2015 09:04:58 -0600 Subject: [PATCH 036/858] Network drivers: Fix bug in tun interface driver. From Max Neklyudov --- ChangeLog | 3 ++- ReleaseNotes | 11 ++++++++--- drivers/net/tun.c | 20 +++++++++++--------- include/nuttx/net/tun.h | 4 +++- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3acfa4f652..cf068fc4b6 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10831,4 +10831,5 @@ General the MS5805 altimeter driver to support other family members and rename to ms58xx. From Paul Alexander Patience (2015-08-14). - + * Network drivers. Fix bug in tun interface driver. From Max + Neklyudov (2015-08-17). diff --git a/ReleaseNotes b/ReleaseNotes index c00d931228..d4b8dd72d9 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -9243,11 +9243,16 @@ detailed bugfix information): NuttX-7.11 Release Notes ------------------------ -The 111th release of NuttX, Version 7.11, was made on June 9, 2015, +The 111th release of NuttX, Version 7.11, was made on August 13 2015, and is available for download from the Bitbucket.org website. Note that release consists of two tarballs: nuttx-7.11.tar.gz and -apps-7.11.tar.gz. Both may be needed (see the top-level nuttx/README.txt -file for build information). +apps-7.11.tar.gz. These are available from: + + https://bitbucket.org/patacongo/nuttx/downloads + https://bitbucket.org/nuttx/apps/downloads + +Both may be needed (see the top-level nuttx/README.txt file for build +information). Additional new features and extended functionality: diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 63470dfad0..507678c7c1 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -378,6 +378,7 @@ static int tun_txpoll(struct net_driver_s *dev) { /* Send the packet */ + priv->read_d_len = priv->dev.d_len; tun_transmit(priv); return 1; @@ -511,7 +512,6 @@ static void tun_txdone(FAR struct tun_device_s *priv) priv->dev.d_buf = priv->read_buf; (void)devif_poll(&priv->dev, tun_txpoll); - priv->read_d_len = priv->dev.d_len; } /**************************************************************************** @@ -537,14 +537,13 @@ static void tun_poll_process(FAR struct tun_device_s *priv) * the TX poll if he are unable to accept another packet for transmission. */ - /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. - * might be bug here. Does this mean if there is a transmit in progress, - * we will missing TCP time state updates? - */ + if (priv->read_d_len == 0) + { + /* If so, poll uIP for new XMIT data. */ - priv->dev.d_buf = priv->read_buf; - (void)devif_timer(&priv->dev, tun_txpoll, TUN_POLLHSEC); - priv->read_d_len = priv->dev.d_len; + priv->dev.d_buf = priv->read_buf; + (void)devif_timer(&priv->dev, tun_txpoll, TUN_POLLHSEC); + } /* Setup the watchdog poll timer again */ @@ -576,9 +575,13 @@ static void tun_poll_work(FAR void *arg) /* Perform the poll */ + tun_lock(priv); state = net_lock(); + tun_poll_process(priv); + net_unlock(state); + tun_unlock(priv); } #endif @@ -757,7 +760,6 @@ static int tun_txavail(struct net_driver_s *dev) priv->dev.d_buf = priv->read_buf; (void)devif_poll(&priv->dev, tun_txpoll); - priv->read_d_len = priv->dev.d_len; } net_unlock(state); diff --git a/include/nuttx/net/tun.h b/include/nuttx/net/tun.h index 0ed8f3940e..3db395f170 100644 --- a/include/nuttx/net/tun.h +++ b/include/nuttx/net/tun.h @@ -56,7 +56,9 @@ /* TUNSETIFF ifr flags */ -#define IFF_TUN 0x0001 +#define IFF_TUN 0x01 +#define IFF_TAP 0x02 +#define IFF_NO_PI 0x80 /**************************************************************************** * Public Type Definitions -- GitLab From 95634a3b3433f669e510b32c37d2ae8d818a39c7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Aug 2015 10:53:49 -0600 Subject: [PATCH 037/858] CAN IOCTLs: Should support standard CAN filtering in extended ID mode --- arch | 2 +- include/nuttx/can.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index a7a7a7c6dd..b86c14f379 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a7a7a7c6dd4f36f690139bc457064e6b24d009eb +Subproject commit b86c14f379e704186664ddfaff5fd26c7fe89711 diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 3235b9de54..68945c5e1e 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -378,7 +378,8 @@ struct canioc_extfilter_s uint8_t xf_type; /* See CAN_FILTER_* definitions */ uint8_t xf_prio; /* See CAN_MSGPRIO_* definitions */ }; -#else +#endif + struct canioc_stdfilter_s { uint16_t sf_id1; /* 11-bit ID. For dual match or for the @@ -388,7 +389,6 @@ struct canioc_stdfilter_s uint8_t sf_type; /* See CAN_FILTER_* definitions */ uint8_t sf_prio; /* See CAN_MSGPRIO_* definitions */ }; -#endif /************************************************************************************ * Public Data -- GitLab From 42fc5a9198629267169cc9660acd41dee9fabda9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Aug 2015 11:49:40 -0600 Subject: [PATCH 038/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index b86c14f379..73a9e0dba2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b86c14f379e704186664ddfaff5fd26c7fe89711 +Subproject commit 73a9e0dba2656ef8976c80910df503424d764fe8 -- GitLab From a987379e6465259a542f644e6e69139d206e67b9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 07:27:00 -0600 Subject: [PATCH 039/858] Add an error bit to the CAN message report --- ChangeLog | 7 +++++++ arch | 2 +- configs | 2 +- include/nuttx/can.h | 47 +++++++++++++++++++++++++++++---------------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf068fc4b6..26df765f87 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10833,3 +10833,10 @@ (2015-08-14). * Network drivers. Fix bug in tun interface driver. From Max Neklyudov (2015-08-17). + * STM32: Added definitions for STM32F303K6, STM32F303K8, STM32F303C6, + STM32F303C8, STM32F303RD, and STM32F303RE devices. From Paul + Alexander Patience (2015-08-17). + * include/nuttx/can.h and all CAN drivers: Add an error indication + bit to the CAN message report. This indication must then be cleared + in all existing drivers. More to come (2015-08-18). + diff --git a/arch b/arch index 73a9e0dba2..ec44a171ff 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 73a9e0dba2656ef8976c80910df503424d764fe8 +Subproject commit ec44a171ffae60b88acd5457461c9d86ff9c4500 diff --git a/configs b/configs index 24588fc10a..e140ddc5f4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 24588fc10ae08f68c7dead477a7ad625b028679e +Subproject commit e140ddc5f4568a55f2f2410bf0c5e61e9abe897e diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 68945c5e1e..c077485ac6 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -196,24 +196,34 @@ * One based CAN-message is represented with a maximum of 10 bytes. A message is * composed of at least the first 2 bytes (when there are no data bytes present). * - * Bytes 0-1: Hold a 16-bit value in host byte order - * Bits 0-3: Data Length Code (DLC) - * Bit 4: Remote Transmission Request (RTR) - * Bits 5-15: The 11-bit CAN identifier - * - * Bytes 2-9: CAN data + * Bytes 0-1: Bits 0-3: Data Length Code (DLC) + * Bit 4: Remote Transmission Request (RTR) + * Bit 5: 1=Message ID is a bit-encoded error report (See NOTE) + * Bits 6-7: Unused + * Bytes 1-2: Bits 0-10: The 11-bit CAN identifier This message ID is a bit + * encoded error set if ch_error is set (See NOTE). + * Bits 11-15: Unused + * Bytes 3-10: CAN data * * CAN-message Format (with Extended ID support) * * One CAN-message consists of a maximum of 13 bytes. A message is composed of at * least the first 5 bytes (when there are no data bytes). * - * Bytes 0-3: Hold 11- or 29-bit CAN ID in host byte order - * Byte 4: Bits 0-3: Data Length Code (DLC) - * Bit 4: Remote Transmission Request (RTR) - * Bit 5: Extended ID indication - * Bits 6-7: Unused - * Bytes 5-12: CAN data + * Bytes 0-3: Bits 0-28: Hold 11- or 29-bit CAN ID in host byte order. This + * message ID is a bit encoded error set if ch_error + * is set (See NOTE). + * Bits 29-31: Unused + * Byte 4: Bits 0-3: Data Length Code (DLC) + * Bit 4: Remote Transmission Request (RTR) + * Bit 5: 1=Message ID is a bit-encoded error report (See NOTE) + * Bit 6: Extended ID indication + * Bit 7: Unused + * Bytes 5-12: CAN data Size determined by DLC + * + * NOTE: The error indication if valid only on message reports received from the + * CAN driver; it is ignored on transmission. When the error bit is set, the + * message ID is an encoded set of error indications (see CAN_ERROR_* definitions). * * The struct can_msg_s holds this information in a user-friendly, unpacked form. * This is the form that is used at the read() and write() driver interfaces. The @@ -224,18 +234,21 @@ #ifdef CONFIG_CAN_EXTID struct can_hdr_s { - uint32_t ch_id; /* 11- or 29-bit ID (3-bits unused) */ + uint32_t ch_id; /* 11- or 29-bit ID (20- or 3-bits unused) */ uint8_t ch_dlc : 4; /* 4-bit DLC */ uint8_t ch_rtr : 1; /* RTR indication */ + uint8_t ch_error : 1; /* 1=ch_id is an error report */ uint8_t ch_extid : 1; /* Extended ID indication */ - uint8_t ch_unused : 2; /* Unused */ + uint8_t ch_unused : 1; /* Unused */ } packed_struct; #else struct can_hdr_s { - uint16_t ch_dlc : 4; /* 4-bit DLC. May be encoded in CAN_FD mode. */ - uint16_t ch_rtr : 1; /* RTR indication */ - uint16_t ch_id : 11; /* 11-bit standard ID */ + uint16_t ch_id; /* 11-bit standard ID (5-bits unused) */ + uint8_t ch_dlc : 4; /* 4-bit DLC. May be encoded in CAN_FD mode. */ + uint8_t ch_rtr : 1; /* RTR indication */ + uint8_t ch_error : 1; /* 1=ch_id is an error report */ + uint8_t ch_unused : 2; /* Unused */ } packed_struct; #endif -- GitLab From 505d5f810310e6f24fd68b9a3997a3ed055c9dad Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 08:48:39 -0600 Subject: [PATCH 040/858] CAN: Add error bit values --- arch | 2 +- include/nuttx/can.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch b/arch index ec44a171ff..c4e2c4ec83 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ec44a171ffae60b88acd5457461c9d86ff9c4500 +Subproject commit c4e2c4ec83f421469a3ef3f355fd56317e0ac595 diff --git a/include/nuttx/can.h b/include/nuttx/can.h index c077485ac6..c997a82748 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -173,6 +173,22 @@ #define CAN_MSGLEN(nbytes) (sizeof(struct can_msg_s) - CAN_MAXDATALEN + (nbytes)) +/* CAN Error Indications ************************************************************/ + +#define CAN_ERROR_SYSTEM (1 << 0) /* Bit 0: Driver internal error */ +#define CAN_ERROR_RXLOST (1 << 1) /* Bit 1: RX Message Lost */ +#define CAN_ERROR_TXLOST (1 << 2) /* Bit 2: TX Message Lost */ +#define CAN_ERROR_ACCESS (1 << 3) /* Bit 3: RAM Access Failure */ +#define CAN_ERROR_TIMEOUT (1 << 4) /* Bit 4: Timeout Occurred */ +#define CAN_ERROR_PASSIVE (1 << 5) /* Bit 5: Error Passive */ +#define CAN_ERROR_CRC (1 << 6) /* Bit 6: RX CRC Error */ +#define CAN_ERROR_BIT (1 << 7) /* Bit 7: Bit Error */ +#define CAN_ERROR_ACK (1 << 8) /* Bit 8: Acknowledge Error */ +#define CAN_ERROR_FORMAT (1 << 9) /* Bit 9: Format Error */ +#define CAN_ERROR_STUFF (1 << 10) /* Bit 10: Stuff Error */ + +#define CAN_ERROR_ALL (0x07ff) + /* CAN filter support ***************************************************************/ /* Some CAN hardware supports a notion of prioritizing messages that match filters. * Only two priority levels are currently supported and are encoded as defined -- GitLab From 28853e59326b4621abc703282a71ea298da1f24b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 11:21:01 -0600 Subject: [PATCH 041/858] CAN: Define IOCTL commands to get and set the bit timing values --- arch | 2 +- include/nuttx/can.h | 61 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/arch b/arch index c4e2c4ec83..fba93b8a0f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c4e2c4ec83f421469a3ef3f355fd56317e0ac595 +Subproject commit fba93b8a0fa0176c2df08835677e6f85adf75f4f diff --git a/include/nuttx/can.h b/include/nuttx/can.h index c997a82748..18c06e8416 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -106,7 +106,7 @@ * Returned Value: A non-negative filter ID is returned on success. * Otherwise -1 (ERROR) is returned with the errno * variable set to indicate the nature of the error. - * Dependencies: Requires CONFIG_CAN_EXID *not* defined + * Dependencies: None * * CANIOC_ADD_EXTFILTER: * Description: Add an address filter for a extended 29 bit address. @@ -114,7 +114,7 @@ * Returned Value: A non-negative filter ID is returned on success. * Otherwise -1 (ERROR) is returned with the errno * variable set to indicate the nature of the error. - * Dependencies: Requires CONFIG_CAN_EXID=y + * Dependencies: Requires CONFIG_CAN_EXTID=y * * CANIOC_DEL_STDFILTER: * Description: Remove an address filter for a standard 11 bit address. @@ -123,7 +123,7 @@ * Returned Value: Zero (OK) is returned on success. Otherwise -1 (ERROR) * is returned with the errno variable set to indicate the * nature of the error. - * Dependencies: Requires CONFIG_CAN_EXID *not* defined + * Dependencies: None * * CANIOC_DEL_EXTFILTER: * Description: Remove an address filter for a standard 29 bit address. @@ -132,20 +132,42 @@ * Returned Value: Zero (OK) is returned on success. Otherwise -1 (ERROR) * is returned with the errno variable set to indicate the * nature of the error. - * Dependencies: Requires CONFIG_CAN_EXID=y + * Dependencies: Requires CONFIG_CAN_EXTID=y + * + * CANIOC_GET_BITTIMING: + * Description: Return the current bit timing settings + * Argument: A pointer to a write-able instance of struct + * canioc_bittiming_s in which current bit timing values + * will be returned. + * Returned Value: Zero (OK) is returned on success. Otherwise -1 (ERROR) + * is returned with the errno variable set to indicate the + * nature of the error. + * Dependencies: None + * + * CANIOC_SET_BITTIMING: + * Description: Set new current bit timing values + * Argument: A pointer to a read-able instance of struct + * canioc_bittiming_s in which the new bit timing values + * are provided. + * Returned Value: Zero (OK) is returned on success. Otherwise -1 (ERROR) + * is returned with the errno variable set to indicate the + * nature of the error. + * Dependencies: None */ #define CANIOC_RTR _CANIOC(1) -#define CANIOC_ADD_STDFILTER _CANIOC(2) -#define CANIOC_ADD_EXTFILTER _CANIOC(3) -#define CANIOC_DEL_STDFILTER _CANIOC(4) -#define CANIOC_DEL_EXTFILTER _CANIOC(5) +#define CANIOC_GET_BITTIMING _CANIOC(2) +#define CANIOC_SET_BITTIMING _CANIOC(3) +#define CANIOC_ADD_STDFILTER _CANIOC(4) +#define CANIOC_ADD_EXTFILTER _CANIOC(5) +#define CANIOC_DEL_STDFILTER _CANIOC(6) +#define CANIOC_DEL_EXTFILTER _CANIOC(7) /* CANIOC_USER: Device specific ioctl calls can be supported with cmds greater * than this value */ -#define CANIOC_USER _CANIOC(6) +#define CANIOC_USER _CANIOC(8) /* Convenience macros ***************************************************************/ @@ -390,6 +412,7 @@ struct can_dev_s }; /* Structures used with ioctl calls */ +/* CANIOC_RTR: */ struct canioc_rtr_s { @@ -397,7 +420,25 @@ struct canioc_rtr_s FAR struct can_msg_s *ci_msg; /* The location to return the RTR response */ }; +/* CANIOC_GET_BITTIMING/CANIOC_SET_BITTIMING: */ +/* Bit time = Tquanta * (Sync_Seg + Prop_Seq + Phase_Seg1 + Phase_Seg2) + * = Tquanta * (TSEG1 + TSEG2 + 1) + * Where + * TSEG1 = Prop_Seq + Phase_Seg1 + * TSEG2 = Phase_Seg2 + */ + +struct canioc_bittiming_s +{ + uint32_t bt_baud; /* Bit rate = 1 / bit time */ + uint8_t bt_tseg1; /* TSEG1 in time quanta */ + uint8_t bt_tseg2; /* TSEG2 in time quanta */ + uint8_t bt_sjw; /* Synchronization Jump Width in time quanta */ +}; + #ifdef CONFIG_CAN_EXTID +/* CANIOC_ADD_EXTFILTER: */ + struct canioc_extfilter_s { uint32_t xf_id1; /* 29-bit ID. For dual match or for the @@ -409,6 +450,8 @@ struct canioc_extfilter_s }; #endif +/* CANIOC_ADD_STDFILTER: */ + struct canioc_stdfilter_s { uint16_t sf_id1; /* 11-bit ID. For dual match or for the -- GitLab From 02306044b276f1680e7efa2a295abc62ce5d0d3b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 13:23:34 -0600 Subject: [PATCH 042/858] boardctl.h: Extended boardctl() commands with BOARDIOC_CAN_INITIALIZE --- arch | 2 +- configs | 2 +- include/nuttx/board.h | 35 +++++++++++++++++++++++++++-------- include/sys/boardctl.h | 11 +++++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/arch b/arch index fba93b8a0f..e81d1ea960 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fba93b8a0fa0176c2df08835677e6f85adf75f4f +Subproject commit e81d1ea960b2da0d93dfb672bfd4d217fe688f52 diff --git a/configs b/configs index e140ddc5f4..ba676894cf 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e140ddc5f4568a55f2f2410bf0c5e61e9abe897e +Subproject commit ba676894cfcff35cd578cd02ca93b60e6ae9a945 diff --git a/include/nuttx/board.h b/include/nuttx/board.h index f29b68cf10..d482591584 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -205,8 +205,8 @@ int board_reset(int status); * application-level touchscreen testing logic (perhaps by * apps/examples/touchscreen). If CONFIG_LIB_BOARDCTL=y and * CONFIG_BOARDCTL_TSCTEST=y, then this functions will be invoked via the - * (non-standard) boardctl() interface using the commands - * BOARDIOC_TSCTEST_SETUP command. + * (non-standard) boardctl() interface using the BOARDIOC_TSCTEST_SETUP + * command. * * Input Parameters: * minor - The input device minor number @@ -231,8 +231,8 @@ int board_tsc_setup(int minor); * application-level touchscreen testing logic (perhaps by * apps/examples/touchscreen). If CONFIG_LIB_BOARDCTL=y and * CONFIG_BOARDCTL_TSCTEST=y, then this functions will be invoked via the - * (non-standard) boardctl() interface using the commands - * BOARDIOC_TSCTEST_TEARDOWN command. + * (non-standard) boardctl() interface using the BOARDIOC_TSCTEST_TEARDOWN + * command. * * Input Parameters: * None @@ -254,8 +254,8 @@ void board_tsc_teardown(void); * This is an internal OS interface but may be invoked indirectly from * application-level graphics logic. If CONFIG_LIB_BOARDCTL=y and * CONFIG_BOARDCTL_ADCTEST=y, then this functions will be invoked via the - * (non-standard) boardctl() interface using the commands - * BOARDIOC_ADCTEST_SETUP command. + * (non-standard) boardctl() interface using the BOARDIOC_ADCTEST_SETUP + * command. * ****************************************************************************/ @@ -288,8 +288,8 @@ int board_pwm_setup(void); * This is an internal OS interface but may be invoked indirectly from * application-level graphics logic. If CONFIG_LIB_BOARDCTL=y and * CONFIG_BOARDCTL_GRAPHICS=y, then this functions will be invoked via the - * (non-standard) boardctl() interface using the commands - * BOARDIOC_GRAPHICS_SETUP command. + * (non-standard) boardctl() interface using the BOARDIOC_GRAPHICS_SETUP + * command. * ****************************************************************************/ @@ -301,6 +301,25 @@ struct fb_vtable_s; FAR struct fb_vtable_s *board_graphics_setup(unsigned int devno); #endif +/***************************************************************************** + * Name: board_can_initialize + * + * Description: + * Perform one-time CAN initialization. This is currently only needed for + * apps/examples/can. + * + * This is an internal OS interface but may be invoked indirectly from + * application-level graphics logic. If CONFIG_LIB_BOARDCTL=y and + * CONFIG_BOARDCTL_CANINIT=y, then this functions will be invoked via the + * (non-standard) boardctl() interface using the BOARDIOC_CAN_INITIALIZE + * command. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARDCTL_CANINIT +int board_can_initialize(void); +#endif + /**************************************************************************** * Name: board_ioctl * diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index 5e8adaf6d8..172f0b69f5 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -94,6 +94,12 @@ * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_PWMTEST * DEPENDENCIES: Board logic must provide board_pwm_setup() * + * CMD: BOARDIOC_CAN_INITIALIZE + * DESCRIPTION: CAN device initialization + * ARG: None + * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_CANINIT + * DEPENDENCIES: Board logic must provide board_can_initialize() + * * CMD: BOARDIOC_GRAPHICS_SETUP * DESCRIPTION: Configure graphics that require special initialization * procedures @@ -109,7 +115,8 @@ #define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0005) #define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0006) #define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0007) -#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x0008) +#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x0008) +#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x0009) /* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support. * In this case, all commands not recognized by boardctl() will be forwarded @@ -118,7 +125,7 @@ * User defined board commands may begin with this value: */ -#define BOARDIOC_USER _BOARDIOC(0x0009) +#define BOARDIOC_USER _BOARDIOC(0x000a) /**************************************************************************** * Public Type Definitions -- GitLab From 470a95aa4fbccae0d24eac04c7219f90f49d2cd4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 13:24:47 -0600 Subject: [PATCH 043/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index ba676894cf..bdd28db165 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ba676894cfcff35cd578cd02ca93b60e6ae9a945 +Subproject commit bdd28db16569fb05df637bf61a7b0e30aeffa6cc -- GitLab From 2a81a76c3379773c554184ff59e76c06e4cbe9a4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 20 Aug 2015 07:56:20 -0600 Subject: [PATCH 044/858] Update ChangeLog --- ChangeLog | 6 ++++-- arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26df765f87..7f93650473 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10816,7 +10816,7 @@ 7.12 2015-xx-xx Gregory Nutt - * fs/vfs/fs_poll.c: Use sem_tickwait() insteadk of sem_timedwait() + * fs/vfs/fs_poll.c: Use sem_tickwait() instead of sem_timedwait() From Macs Neklyudov (2015-08-13). * fs/vfs/fs_poll.c: If we fail to setup the poll for any file descriptor, for any reason, set the POLLERR bit (2015-08-13). @@ -10839,4 +10839,6 @@ * include/nuttx/can.h and all CAN drivers: Add an error indication bit to the CAN message report. This indication must then be cleared in all existing drivers. More to come (2015-08-18). - + * arch/arm/src/lpc17/lpc17_irq.c: Set NVIC vector address so that + code can execute with a bootloader or can execute from RAM. From + Pavel Pisa (2015-08-20). diff --git a/arch b/arch index e81d1ea960..29f7043bc6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e81d1ea960b2da0d93dfb672bfd4d217fe688f52 +Subproject commit 29f7043bc649460e709f191fca47a0a026a50adb diff --git a/configs b/configs index bdd28db165..e3f37812a9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bdd28db16569fb05df637bf61a7b0e30aeffa6cc +Subproject commit e3f37812a9a7595a7ddab1a625ebe857d104beb2 -- GitLab From 622c5c9aa631f85f747d2d3efc5fd9072f7af87d Mon Sep 17 00:00:00 2001 From: Max Neklyudov Date: Fri, 21 Aug 2015 07:39:57 -0600 Subject: [PATCH 045/858] Another TUN driver fix from Max Neklyudov --- arch | 2 +- drivers/net/tun.c | 7 +++---- include/nuttx/net/tun.h | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 29f7043bc6..76efd5e60a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 29f7043bc649460e709f191fca47a0a026a50adb +Subproject commit 76efd5e60a14c9e3b312b6f11c7c67de972a8299 diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 507678c7c1..d804eea2cb 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1178,8 +1178,8 @@ errout: static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { - FAR struct inode *inode = filep->f_inode; - FAR struct tun_driver_s *tun = inode->i_private; + FAR struct inode *inode = filep->f_inode; + FAR struct tun_driver_s *tun = inode->i_private; FAR struct tun_device_s *priv = filep->f_priv; int ret = OK; @@ -1189,7 +1189,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) int intf; FAR struct ifreq *ifr = (FAR struct ifreq*)arg; - if (!ifr || ifr->ifr_flags != IFF_TUN) + if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN) { return -EINVAL; } @@ -1220,7 +1220,6 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv = filep->f_priv; strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ); - lldbg("--- %s\n", priv->dev.d_ifname); tundev_unlock(tun); diff --git a/include/nuttx/net/tun.h b/include/nuttx/net/tun.h index 3db395f170..c61c3c84f4 100644 --- a/include/nuttx/net/tun.h +++ b/include/nuttx/net/tun.h @@ -58,6 +58,7 @@ #define IFF_TUN 0x01 #define IFF_TAP 0x02 +#define IFF_MASK 0x7f #define IFF_NO_PI 0x80 /**************************************************************************** -- GitLab From 12b1c0450832b63e1df3de263497e371cd05c3c4 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 21 Aug 2015 09:15:06 -0600 Subject: [PATCH 046/858] recvfrom(): Correct wait for new data when NET_UDP_READAHEAD is enabled. Fix size accounting when recvfrom_udpreadahead() sets state.rf_recvlen == -1. I have not checked if data are accumulated to the right position in the buffer however. Signed-off-by: Pavel Pisa --- ChangeLog | 12 +++++++++++ arch | 2 +- net/socket/recvfrom.c | 49 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f93650473..cad1af1cb5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10842,3 +10842,15 @@ * arch/arm/src/lpc17/lpc17_irq.c: Set NVIC vector address so that code can execute with a bootloader or can execute from RAM. From Pavel Pisa (2015-08-20). + * All ARMV7-M IRQ setup: Always set the NVIC vector table address + unconditionally. This is needed in cases where the code is running + with a bootload and when the code is running from RAM. It is also + needed by the logic of up_ramvec_initialize() which gets the vector + base address from the NVIC. Suggested by Pavel Pisa (2015-08-21). + * SAMV7 USBHS DCD: The device controller driver is (finally) functional + (2015-08-21). + * recvfrom(): Correct wait for new data when NET_UDP_READAHEAD is + enabled. Fix size accounting when recvfrom_udpreadahead() sets + state.rf_recvlen == -1. I have not checked if data are accumulated + to the right position in the buffer however. From Pavel Pisa + (2015-08-15). diff --git a/arch b/arch index 76efd5e60a..94705f285e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 76efd5e60a14c9e3b312b6f11c7c67de972a8299 +Subproject commit 94705f285e98a1ec5ca66027be01eff2e1189e27 diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 32b2067ffc..09bf4626e1 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -110,6 +110,39 @@ struct recvfrom_s * Private Functions ****************************************************************************/ +/**************************************************************************** + * Function: recvfrom_add_recvlen + * + * Description: + * Update information about space available for new data and update size + * of data in buffer, This logic accounts for the case where + * recvfrom_udpreadahead() sets state.rf_recvlen == -1 . + * + * Parameters: + * pstate recvfrom state structure + * recvlen size of new data appended to buffer + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) || defined(CONFIG_NET_PKT) + +static inline void recvfrom_add_recvlen(FAR struct recvfrom_s *pstate, + size_t recvlen) +{ + if (pstate->rf_recvlen < 0) + { + pstate->rf_recvlen = 0; + } + + pstate->rf_recvlen += recvlen; + pstate->rf_buffer += recvlen; + pstate->rf_buflen -= recvlen; +} +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP || CONFIG_NET_PKT */ + /**************************************************************************** * Function: recvfrom_newdata * @@ -152,9 +185,7 @@ static size_t recvfrom_newdata(FAR struct net_driver_s *dev, /* Update the accumulated size of the data read */ - pstate->rf_recvlen += recvlen; - pstate->rf_buffer += recvlen; - pstate->rf_buflen -= recvlen; + recvfrom_add_recvlen(pstate, recvlen); return recvlen; } @@ -200,9 +231,7 @@ static void recvfrom_newpktdata(FAR struct net_driver_s *dev, /* Update the accumulated size of the data read */ - pstate->rf_recvlen += recvlen; - pstate->rf_buffer += recvlen; - pstate->rf_buffer -= recvlen; + recvfrom_add_recvlen(pstate, recvlen); } #endif /* CONFIG_NET_PKT */ @@ -353,9 +382,7 @@ static inline void recvfrom_tcpreadahead(struct recvfrom_s *pstate) /* Update the accumulated size of the data read */ - pstate->rf_recvlen += recvlen; - pstate->rf_buffer += recvlen; - pstate->rf_buflen -= recvlen; + recvfrom_add_recvlen(pstate, recvlen); /* If we took all of the ata from the I/O buffer chain is empty, then * release it. If there is still data available in the I/O buffer @@ -1501,9 +1528,11 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, /* It is okay to block if we need to. If there is space to receive anything * more, then we will wait to receive the data. Otherwise return the number * of bytes read from the read-ahead buffer (already in 'ret'). + * + * NOTE: that recvfrom_udpreadahead() may set state.rf_recvlen == -1. */ - else if (state.rf_recvlen == 0) + else if (state.rf_recvlen <= 0) #endif { /* Get the device that will handle the packet transfers. This may be -- GitLab From 89b5ef8d35918eb26ca0a19b4739163287520d56 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Aug 2015 11:30:22 -0600 Subject: [PATCH 047/858] wdogs: Fix counting of free, pre-allocated wdog timers. The could could get decremented below zero in some situations --- ChangeLog | 4 ++++ net/socket/recvfrom.c | 4 ++-- sched/wdog/wd_create.c | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index cad1af1cb5..577712b511 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10854,3 +10854,7 @@ state.rf_recvlen == -1. I have not checked if data are accumulated to the right position in the buffer however. From Pavel Pisa (2015-08-15). + * sched/wdog/wd_create.c: Correct a counting error in the number + of available watchdog timers. When the number of free timers is + low, the counter could be incremented below zero (2015-08-15). + diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 09bf4626e1..f6519de186 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -916,11 +916,11 @@ static uint16_t recvfrom_tcpinterrupt(FAR struct net_driver_s *dev, /* Report an error only if no data has been received. (If * CONFIG_NET_TCP_RECVDELAY then rf_recvlen should always be - * zero). + * less than or equal to zero). */ #if CONFIG_NET_TCP_RECVDELAY > 0 - if (pstate->rf_recvlen == 0) + if (pstate->rf_recvlen <= 0) #endif { /* Report the timeout error */ diff --git a/sched/wdog/wd_create.c b/sched/wdog/wd_create.c index 2c04724a40..f4b3962b72 100644 --- a/sched/wdog/wd_create.c +++ b/sched/wdog/wd_create.c @@ -109,24 +109,34 @@ WDOG_ID wd_create (void) if (g_wdnfree > CONFIG_WDOG_INTRESERVE || up_interrupt_context()) { - /* Remove the watchdog timer from the free list and decrement the - * count of free timers all with interrupts disabled. - */ + /* Remove the watchdog timer from the free list */ wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdfreelist); - DEBUGASSERT(g_wdnfree > 0); - g_wdnfree--; - irqrestore(state); /* Did we get one? */ if (wdog) { - /* Yes.. Clear the forward link and all flags */ + /* Yes.. decrement the count of free, pre-allocated timers (all + * with interrupts disabled). + */ + + DEBUGASSERT(g_wdnfree > 0 && wdog != NULL); + g_wdnfree--; + + /* Clear the forward link and all flags */ wdog->next = NULL; wdog->flags = 0; } + else + { + /* We didn't get one... The count should then be exactly zero */ + + DEBUGASSERT(g_wdnfree == 0); + } + + irqrestore(state); } /* We are in a normal tasking context AND there are not enough unreserved, -- GitLab From 0b2fbd7a2ca801f5c3f8a6f587b44fe032f71591 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Aug 2015 12:33:14 -0600 Subject: [PATCH 048/858] Fix a DEBUGASSERTion --- arch | 2 +- configs | 2 +- sched/wdog/wd_create.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 94705f285e..b2709988e6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 94705f285e98a1ec5ca66027be01eff2e1189e27 +Subproject commit b2709988e66303b69358f7b7a910905a6a7ff888 diff --git a/configs b/configs index e3f37812a9..fda2b22665 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e3f37812a9a7595a7ddab1a625ebe857d104beb2 +Subproject commit fda2b2266521c5cf312aa37ed3c2cd03a4a5c1db diff --git a/sched/wdog/wd_create.c b/sched/wdog/wd_create.c index f4b3962b72..db303d1627 100644 --- a/sched/wdog/wd_create.c +++ b/sched/wdog/wd_create.c @@ -115,18 +115,18 @@ WDOG_ID wd_create (void) /* Did we get one? */ - if (wdog) + if (wdog != NULL) { /* Yes.. decrement the count of free, pre-allocated timers (all * with interrupts disabled). */ - DEBUGASSERT(g_wdnfree > 0 && wdog != NULL); + DEBUGASSERT(g_wdnfree > 0); g_wdnfree--; /* Clear the forward link and all flags */ - wdog->next = NULL; + wdog->next = NULL; wdog->flags = 0; } else -- GitLab From 23035ca68dfc1d6554a1954269201e80cf68dae4 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 21 Aug 2015 18:33:03 -0600 Subject: [PATCH 049/858] [PATCH] gethostbyname(): correct returned address format when DNS is used. The hostent.h_addr_list should point to raw in_addr or in6_addr as defined in the standard. Original implementation used that for numeric addresses but for DNS lookup returned pointer to whole sockaddr_in or sockaddr_in6. getaddrinfo() should be preferred in a long term perspective. Return of complete addresses from the lookup would be better in such case but it requires significant changes anyway - multiple addresses support and most probably dynamic memory allocation which is bad for many RT applications. So gethostbyname() is sufficient for most applications now. Signed-off-by: Pavel Pisa --- ChangeLog | 3 +++ arch | 2 +- libc/netdb/lib_gethostbynamer.c | 10 ++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 577712b511..c6d94c3215 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10857,4 +10857,7 @@ * sched/wdog/wd_create.c: Correct a counting error in the number of available watchdog timers. When the number of free timers is low, the counter could be incremented below zero (2015-08-15). + * arch/arm/src/stm32: Add OTG support for STM32F44x. From David + Sidrane (2015-08-15). + diff --git a/arch b/arch index b2709988e6..e725e3d458 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b2709988e66303b69358f7b7a910905a6a7ff888 +Subproject commit e725e3d458e77bb268ca3a02909c71c2e5751f24 diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index f9bd4af9f0..ff90bcbf76 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -236,6 +236,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, { FAR struct hostent_info_s *info; FAR char *ptr; + FAR void *addrdata; socklen_t addrlen; int addrtype; int namelen; @@ -280,6 +281,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); addrtype = AF_INET; + addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; } #endif @@ -291,12 +293,13 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; } #endif /* Yes.. Return the address that we obtained from the DNS cache. */ - info->hi_addrlist[0] = ptr; + info->hi_addrlist[0] = addrdata; host->h_addr_list = info->hi_addrlist; host->h_addrtype = addrtype; host->h_length = addrlen; @@ -377,6 +380,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, { FAR struct hostent_info_s *info; FAR char *ptr; + FAR void *addrdata; socklen_t addrlen; int addrtype; int namelen; @@ -419,6 +423,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); addrtype = AF_INET; + addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; } #endif @@ -430,12 +435,13 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; } #endif /* Yes.. Return the address that we obtained from the DNS name server. */ - info->hi_addrlist[0] = ptr; + info->hi_addrlist[0] = addrdata; host->h_addr_list = info->hi_addrlist; host->h_addrtype = addrtype; host->h_length = addrlen; -- GitLab From 7f3a36fb784f283cc40a0fdf7e23f3979ad7c74e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Aug 2015 18:36:12 -0600 Subject: [PATCH 050/858] Update ChangeLog --- ChangeLog | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6d94c3215..4a3e93db1b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10853,11 +10853,16 @@ enabled. Fix size accounting when recvfrom_udpreadahead() sets state.rf_recvlen == -1. I have not checked if data are accumulated to the right position in the buffer however. From Pavel Pisa - (2015-08-15). + (2015-08-21). * sched/wdog/wd_create.c: Correct a counting error in the number of available watchdog timers. When the number of free timers is - low, the counter could be incremented below zero (2015-08-15). + low, the counter could be incremented below zero (2015-08-21). * arch/arm/src/stm32: Add OTG support for STM32F44x. From David - Sidrane (2015-08-15). - - + Sidrane (2015-08-21). + * arch/arm/src/lpc17: Actually implement options to use external + SDRAM and or SRAM for the heap. From Pavel Pisa (2015-08-21). + * gethostbyname(): correct returned address format when DNS is used. + The hostent.h_addr_list should point to raw in_addr or in6_addr + as defined in the standard. Original implementation used that + for numeric addresses but for DNS lookup returned pointer to + whole sockaddr_in or sockaddr_in6. From Pavel Pisa (2015-08-21). -- GitLab From 64cff5489477a3f6ce8bbe59be79b361f0d9e292 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 22 Aug 2015 10:16:51 -0600 Subject: [PATCH 051/858] Upate submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index e725e3d458..386bfb2232 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e725e3d458e77bb268ca3a02909c71c2e5751f24 +Subproject commit 386bfb2232c31cdab2abc2cad120a419295f1d75 diff --git a/configs b/configs index fda2b22665..ba78f31764 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit fda2b2266521c5cf312aa37ed3c2cd03a4a5c1db +Subproject commit ba78f31764727583a33edf26a591daefeefda9b9 -- GitLab From ad5448d9b4c32f839691f089a884bd36bc18cbcd Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 23 Aug 2015 08:17:30 -0600 Subject: [PATCH 052/858] mksymtab: declare g_symtab array as conts to occupy RO section (Flash). --- tools/mksymtab.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/mksymtab.c b/tools/mksymtab.c index e9591febbc..ddac7fda07 100644 --- a/tools/mksymtab.c +++ b/tools/mksymtab.c @@ -1,7 +1,7 @@ /**************************************************************************** * tools/mksymtab.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -234,7 +234,7 @@ int main(int argc, char **argv, char **envp) /* Now the symbol table itself */ - fprintf(outstream, "\nstruct symtab_s %s[] =\n", SYMTAB_NAME); + fprintf(outstream, "\nconst struct symtab_s %s[] =\n", SYMTAB_NAME); fprintf(outstream, "{\n"); /* Parse each line in the CVS file */ -- GitLab From 81a257eeb04d61c29c1b944bfa5853f866efba43 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 23 Aug 2015 08:38:58 -0600 Subject: [PATCH 053/858] Optional canned symtab inclusion to the build. When option CONFIG_LIBC_SYMTAB is selected and symbol table file libc/symtab/canned_symtab.inc is prepared then application can use system provided complete symbol table. The option has substantial effect on system image size. Mainly code/text. If loading of applications at runtime is not planned do not select this. From Pavel Pisa. --- ChangeLog | 9 +++ README.txt | 2 + include/nuttx/binfmt/canned_symtab.h | 102 +++++++++++++++++++++++++++ libc/Kconfig | 2 + libc/Makefile | 1 + libc/symtab/Kconfig | 14 ++++ libc/symtab/Make.defs | 45 ++++++++++++ libc/symtab/README.txt | 19 +++++ libc/symtab/lib_symbtab.c | 61 ++++++++++++++++ 9 files changed, 255 insertions(+) create mode 100644 include/nuttx/binfmt/canned_symtab.h create mode 100644 libc/symtab/Kconfig create mode 100644 libc/symtab/Make.defs create mode 100644 libc/symtab/README.txt create mode 100644 libc/symtab/lib_symbtab.c diff --git a/ChangeLog b/ChangeLog index 4a3e93db1b..c0ba51ab8b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10866,3 +10866,12 @@ as defined in the standard. Original implementation used that for numeric addresses but for DNS lookup returned pointer to whole sockaddr_in or sockaddr_in6. From Pavel Pisa (2015-08-21). + * tools/mksymtab: declare g_symtab array as conts to occupy RO + section (Flash). From Pavel Pisa (2015-08-23). + * libc/symtab: Optional canned symtab inclusion to the build. When + option CONFIG_LIBC_SYMTAB is selected and symbol table file + libc/symtab/canned_symtab.inc is prepared then application can + use system provided complete symbol table. The option has + substantial effect on system image size. Mainly code/text. If + loading of applications at runtime is not planned do not select + this. From Pavel Pisa (2015-08-23). diff --git a/README.txt b/README.txt index 4f8b364353..035159dea8 100644 --- a/README.txt +++ b/README.txt @@ -1513,6 +1513,8 @@ nuttx/ |- lib/ | `- README.txt |- libc/ + | |- symtab/ + | | `- README.txt | `- README.txt |- libnx/ | `- README.txt diff --git a/include/nuttx/binfmt/canned_symtab.h b/include/nuttx/binfmt/canned_symtab.h new file mode 100644 index 0000000000..ba3419dec3 --- /dev/null +++ b/include/nuttx/binfmt/canned_symtab.h @@ -0,0 +1,102 @@ +/**************************************************************************** + * include/nuttx/binfmt/canned_symtab.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H +#define __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* struct symbtab_s describes one entry in the symbol table. A symbol table + * is a fixed size array of struct symtab_s. The information is intentionally + * minimal and supports only: + * + * 1. Function pointers as sym_values. Of other kinds of values need to be + * supported, then typing information would also need to be included in + * the structure. + * + * 2. Fixed size arrays. There is no explicit provisional for dynamically + * adding or removing entries from the symbol table (realloc might be + * used for that purpose if needed). The intention is to support only + * fixed size arrays completely defined at compilation or link time. + */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: canned_symtab_initialize + * + * Description: + * Setup system provided canned symbol table. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void canned_symtab_initialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H */ + diff --git a/libc/Kconfig b/libc/Kconfig index e51915d1c2..1be0aedcd0 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -195,6 +195,8 @@ config EXECFUNCS_NSYMBOLS symbols in that table. This selection provides the number of symbols in the symbol table. +source libc/symtab/Kconfig + endif # EXECFUNCS_HAVE_SYMTAB endif # LIBC_EXECFUNCS diff --git a/libc/Makefile b/libc/Makefile index 76d3e473aa..6509aa61d7 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -84,6 +84,7 @@ include queue/Make.defs include wqueue/Make.defs include misc/Make.defs include audio/Make.defs +include symtab/Make.defs # REVISIT: Backslash causes problems in $(COBJS) target DELIM := $(strip /) diff --git a/libc/symtab/Kconfig b/libc/symtab/Kconfig new file mode 100644 index 0000000000..317abaff47 --- /dev/null +++ b/libc/symtab/Kconfig @@ -0,0 +1,14 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIBC_SYMTAB + bool "Include canned symtab for applications and shell" + default n + depends on EXECFUNCS_HAVE_SYMTAB + ---help--- + Build and include default symbol table in the NuttX library. + The symbol table is selected by call canned_symtab_initialize(). + The table libc/symtab/canned_symtab.inc has to be generated + by mksymtab manually before this option is selected. diff --git a/libc/symtab/Make.defs b/libc/symtab/Make.defs new file mode 100644 index 0000000000..98954a0e0d --- /dev/null +++ b/libc/symtab/Make.defs @@ -0,0 +1,45 @@ +############################################################################ +# libc/symtab/Make.defs +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_LIBC_SYMTAB),y) + +# Include canned symtab to the build + +CSRCS += lib_symtab.c + +DEPPATH += --dep-path symtab +VPATH += :symtab + +endif diff --git a/libc/symtab/README.txt b/libc/symtab/README.txt new file mode 100644 index 0000000000..21bb1759da --- /dev/null +++ b/libc/symtab/README.txt @@ -0,0 +1,19 @@ +symtab +====== + +This directory provide support for canned symbol table which provides +all/most of system and libc services/functions to the application and NSH. + +The support is selected by CONFIG_LIBC_SYMTAB option and table has to be +prepared in advance manually. + +It can be prepared from NuttX top level directory by next commands + + cat syscall/syscall.csv libc/libc.csv | sort >libc/symtab/canned_symtab.csv + tools/mksymtab libc/symtab/canned_symtab.csv libc/symtab/canned_symtab.inc + +Next code selectes canned symtab from application: + + #include + ... + canned_symtab_initialize(); diff --git a/libc/symtab/lib_symbtab.c b/libc/symtab/lib_symbtab.c new file mode 100644 index 0000000000..bdf9d32413 --- /dev/null +++ b/libc/symtab/lib_symbtab.c @@ -0,0 +1,61 @@ +/**************************************************************************** + * libc/symtab/lib_symtab.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Canned symtab implemented by Pavel Pisa + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include + +#ifdef CONFIG_LIBC_SYMTAB + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "canned_symtab.inc" + +/************************************************************************ + * Public Functions + ************************************************************************/ + +void canned_symtab_initialize(void) +{ + exec_setsymtab(g_symtab, NSYMBOLS); +} + +#endif /* CONFIG_LIBC_SYMTAB */ -- GitLab From 9ab3f03153d32b6558380a3168422c709a25cc32 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 23 Aug 2015 09:05:40 -0600 Subject: [PATCH 054/858] Define some symbol export conditions, correct errno and add sleep and usleep. From Pavel Pisa --- ChangeLog | 3 +++ libc/libc.csv | 16 +++++++++------- libc/symtab/README.txt | 9 +++++++++ syscall/syscall.csv | 7 ++++--- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0ba51ab8b..09ee7e1802 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10875,3 +10875,6 @@ substantial effect on system image size. Mainly code/text. If loading of applications at runtime is not planned do not select this. From Pavel Pisa (2015-08-23). + * libc/libc.csv and syscalls/syscalls.csv: Define some symbol + export conditions, correct errno and add sleep and usleep. From + Pavel Pisa (2015-08-23). diff --git a/libc/libc.csv b/libc/libc.csv index 65dc81da82..977a111fbe 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -6,12 +6,12 @@ "aio_suspend","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR const struct timespec *" "asprintf","stdio.h","","int","FAR char **","const char *","..." "avsprintf","stdio.h","","int","FAR char **","const char *","va_list" -"b16atan2","fixedmath.h","","b16_t","b16_t","b16_t" +"b16atan2","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" "b16cos","fixedmath.h","","b16_t","b16_t" -"b16divb16","fixedmath.h","","b16_t","b16_t","b16_t" -"b16mulb16","fixedmath.h","","b16_t","b16_t","b16_t" +"b16divb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" +"b16mulb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" "b16sin","fixedmath.h","","b16_t","b16_t" -"b16sqr","fixedmath.h","","b16_t","b16_t" +"b16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t" "basename","libgen.h","","FAR char","FAR char *" "cfgetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *" "cfsetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t" @@ -117,6 +117,7 @@ "sigemptyset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" "sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" "sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int" +"sleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","unsigned int","unsigned int" "snprintf","stdio.h","","int","FAR char *","size_t","const char *","..." "sprintf","stdio.h","","int","FAR char *","const char *","..." "sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *" @@ -162,10 +163,11 @@ "tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" "telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *" "time","time.h","","time_t","time_t *" -"ub16divub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" -"ub16mulub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" -"ub16sqr","fixedmath.h","","ub16_t","ub16_t" +"ub16divub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t" +"ub16mulub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t" +"ub16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t" "ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *" +"usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","int","int","FAR FILE *" "vdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE)","int","const char *","..." "vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","const char *","va_list" "vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list" diff --git a/libc/symtab/README.txt b/libc/symtab/README.txt index 21bb1759da..d7dc6abcca 100644 --- a/libc/symtab/README.txt +++ b/libc/symtab/README.txt @@ -17,3 +17,12 @@ Next code selectes canned symtab from application: #include ... canned_symtab_initialize(); + +The option can have substantial effect on system image size, mainly +code/text. That is because the instructions to generate canned_symtab.inc +above will cause EVERY interface in the NuttX RTOS and the C library to be +included into build. Add to that the size of a huge symbol table. + +In order to reduce the code/text size, you may want to manually prune the +auto-generated canned_symtab.inc file to remove all interfaces that you do +not wish to include into the base FLASH image. diff --git a/syscall/syscall.csv b/syscall/syscall.csv index c97d16ccf4..f9ea9285a6 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -11,7 +11,7 @@ "clock_getres","time.h","","int","clockid_t","struct timespec*" "clock_gettime","time.h","","int","clockid_t","struct timespec*" "clock_settime","time.h","","int","clockid_t","const struct timespec*" -"clock_systimer","nuttx/clock.h","","uint32_t" +"clock_systimer","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS)","uint32_t" "close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int" "closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*" "connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t" @@ -23,7 +23,8 @@ "fs_fdopen","nuttx/fs/fs.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR struct file_struct*","int","int","FAR struct tcb_s*" "fs_ioctl","nuttx/fs/fs.h","defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "fsync","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","int" -"get_errno","errno.h","","int" +"get_errno","errno.h","!defined(__DIRECT_ERRNO_ACCESS)","int" +"get_errno_ptr","errno.h","defined(__DIRECT_ERRNO_ACCESS)","FAR int*" "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char*","FAR const char*" "getpid","unistd.h","","pid_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" @@ -119,7 +120,7 @@ "send","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","ssize_t","int","FAR const void*","size_t","int" "sendfile","sys/sendfile.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_NET_SENDFILE)","ssize_t","int","int","FAR off_t*","size_t" "sendto","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","ssize_t","int","FAR const void*","size_t","int","FAR const struct sockaddr*","socklen_t" -"set_errno","errno.h","","void","int" +"set_errno","errno.h","!defined(__DIRECT_ERRNO_ACCESS)","void","int" "setenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char*","FAR const char*","int" "sethostname","unistd.h","defined(CONFIG_LIBC_NETDB)","int","FAR const char*","size_t" "setsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR const void*","socklen_t" -- GitLab From f12692b78f2eb7db9611729c9366511fa35c7f45 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 10:44:04 -0600 Subject: [PATCH 055/858] Extend canned symbol table logic to work in protected build mode --- configs | 2 +- include/nuttx/binfmt/canned_symtab.h | 45 +++++++++++++++- include/sys/boardctl.h | 22 +++++--- libc/symtab/Kconfig | 3 +- libc/symtab/README.txt | 35 +++++++++++-- libc/symtab/lib_symbtab.c | 78 +++++++++++++++++++++++++++- 6 files changed, 168 insertions(+), 17 deletions(-) diff --git a/configs b/configs index ba78f31764..de62dbc734 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ba78f31764727583a33edf26a591daefeefda9b9 +Subproject commit de62dbc734217b4c18c11b87e4d1e75789193cdb diff --git a/include/nuttx/binfmt/canned_symtab.h b/include/nuttx/binfmt/canned_symtab.h index ba3419dec3..f40018081c 100644 --- a/include/nuttx/binfmt/canned_symtab.h +++ b/include/nuttx/binfmt/canned_symtab.h @@ -64,6 +64,18 @@ * fixed size arrays completely defined at compilation or link time. */ +/* In order to full describe a symbol table, a vector containing the address + * of the symbol table and the number of elements in the symbol table is + * required. + */ + +struct symtab_s; /* Forward reference */ +struct symtab_desc_s +{ + FAR struct symtab_s *symtab; + int nsymbols; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -81,7 +93,9 @@ extern "C" * Name: canned_symtab_initialize * * Description: - * Setup system provided canned symbol table. + * Setup system provided canned symbol table. NOTE that this a user-space + * interface only. It is not generally available to to kernel mode code + * in protected or kernel builds. * * Input Parameters: * None @@ -91,7 +105,36 @@ extern "C" * ****************************************************************************/ +#if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__) void canned_symtab_initialize(void); +#endif + +/**************************************************************************** + * Name: canned_symtab_select + * + * Description: + * Setup system provided canned symbol table. This function only exists + * the kernel portion of a protected or kernel build. It is called only + * by boardctl(). I this case: + * + * - canned_symbtab_initialize() and g_symtab() lie in the user space. + * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in + * kernel space. + * + * Access to boardctl() is provided in user space through a call gate. + * + * Input Parameters: + * symtab - The symbol table to be used + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ + defined(__KERNEL__) +int canned_symtab_select(FAR const struct symtab_desc_s *symdesc); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index 172f0b69f5..0cbc937971 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -70,6 +70,13 @@ * CONFIGURATION: CONFIG_BOARDCTL_RESET * DEPENDENCIES: Board logic must provide board_reset * + * CMD: BOARDIOC_SYMTAB + * DESCRIPTION: Select a symbol table + * ARG: A pointer to an instance of struct symtab_desc_s + * (See include/nuttx/binfmt/canned_symtab.h). + * CONFIGURATION: CONFIG_LIBC_SYMTAB + * DEPENDENCIES: None + * * CMD: BOARDIOC_TSCTEST_SETUP * DESCRIPTION: Touchscreen controller test configuration * ARG: Touch controller device minor number @@ -111,12 +118,13 @@ #define BOARDIOC_INIT _BOARDIOC(0x0001) #define BOARDIOC_POWEROFF _BOARDIOC(0x0002) #define BOARDIOC_RESET _BOARDIOC(0x0003) -#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0004) -#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0005) -#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0006) -#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0007) -#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x0008) -#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x0009) +#define BOARDIOC_SYMTAB _BOARDIOC(0x0004) +#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0005) +#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0006) +#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0007) +#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0008) +#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x0009) +#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000a) /* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support. * In this case, all commands not recognized by boardctl() will be forwarded @@ -125,7 +133,7 @@ * User defined board commands may begin with this value: */ -#define BOARDIOC_USER _BOARDIOC(0x000a) +#define BOARDIOC_USER _BOARDIOC(0x000b) /**************************************************************************** * Public Type Definitions diff --git a/libc/symtab/Kconfig b/libc/symtab/Kconfig index 317abaff47..4cdef0d9c7 100644 --- a/libc/symtab/Kconfig +++ b/libc/symtab/Kconfig @@ -6,7 +6,8 @@ config LIBC_SYMTAB bool "Include canned symtab for applications and shell" default n - depends on EXECFUNCS_HAVE_SYMTAB + depends on EXECFUNCS_HAVE_SYMTAB && !BUILD_KERNEL + select LIB_BOARDCTL if !BUILD_FLAT ---help--- Build and include default symbol table in the NuttX library. The symbol table is selected by call canned_symtab_initialize(). diff --git a/libc/symtab/README.txt b/libc/symtab/README.txt index d7dc6abcca..7cb544aefb 100644 --- a/libc/symtab/README.txt +++ b/libc/symtab/README.txt @@ -1,23 +1,48 @@ symtab ====== -This directory provide support for canned symbol table which provides +Symbol Tables and Build Modes +----------------------------- +This directory provide support for a canned symbol table which provides all/most of system and libc services/functions to the application and NSH. -The support is selected by CONFIG_LIBC_SYMTAB option and table has to be -prepared in advance manually. +Symbol tables have differing usefulness in different NuttX build modes: + + 1. In the FLAT build (CONFIG_BUILD_FLAT), symbol tables are used to bind + addresses in loaded ELF or NxFLAT modules to base code that usually + resides in FLASH memory. Both OS interfaces and user/application + libraries are made available to the loaded module via symbol tables. + + 2. Symbol tables may be of value in a protected build + (CONFIG_BUILD_PROTECTED) where the newly started user task must + share resources with other user code (but should use system calls to + interact with the OS). -It can be prepared from NuttX top level directory by next commands + 3. But in the kernel build mode (CONFIG_BUILD_KERNEL), only fully linked + executables loadable via execl(), execv(), or posix_spawan() can used. + There is no use for a symbol table with the kernel build since all + memory resources are separate; nothing is share-able with the newly + started process. + +Creating the Canned Symbol Table +-------------------------------- +The support is selected by CONFIG_LIBC_SYMTAB option and table has to be +prepared in advance manually. It can be prepared from NuttX top level +directory by using the following commands: cat syscall/syscall.csv libc/libc.csv | sort >libc/symtab/canned_symtab.csv tools/mksymtab libc/symtab/canned_symtab.csv libc/symtab/canned_symtab.inc -Next code selectes canned symtab from application: +Your board-level start up code code then needs to select the canned symbol +table by calling the OS internal function canned_symtab_initialize() in the +board-specfic board_apps_initialize() logic: #include ... canned_symtab_initialize(); +Code/Text Size Implications +--------------------------- The option can have substantial effect on system image size, mainly code/text. That is because the instructions to generate canned_symtab.inc above will cause EVERY interface in the NuttX RTOS and the C library to be diff --git a/libc/symtab/lib_symbtab.c b/libc/symtab/lib_symbtab.c index bdf9d32413..4905d0bc91 100644 --- a/libc/symtab/lib_symbtab.c +++ b/libc/symtab/lib_symbtab.c @@ -49,13 +49,87 @@ #include "canned_symtab.inc" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ +/**************************************************************************** + * Name: canned_symtab_initialize + * + * Description: + * Setup system provided canned symbol table. NOTE that this a user-space + * interface only. It is not generally available to to kernel mode code + * in protected or kernel builds. That is because exec_setsymtab() and + * g_symtab lie in different address spaces. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__) void canned_symtab_initialize(void) { +#ifdef CONFIG_BUILD_FLAT + /* In the FLAT build, exec_symtab() can be called directly from any logic. + * Both the symbol table and the function exec_setsymtabe reside in the same + * namespace and address space. + */ + exec_setsymtab(g_symtab, NSYMBOLS); + +#else + /* In the user mode portion of a protected or kernel build, we must set + * the symbol table indirectly through the boardctl() call gate that will + * proxy the call to canned_symtab_select(). In this case + * + * - canned_symbtab_initialize() and g_symtab() lie in the user space. + * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in + * kernel space. + * + * Access to boardctl() is provided in user space throug a call gate. + */ + + struct symtab_desc_s symdesc; + + symdesc.symtab = g_symtab; + symdesc.nsymbols = NSYMBOLS; + (void)boardctl(BOARDIOC_SYMTAB, (uinptr_t)&symdesc); +#endif +} +#endif + +/**************************************************************************** + * Name: canned_symtab_select + * + * Description: + * Setup system provided canned symbol table. This function only exists + * the kernel portion of a protected or kernel build. It is called only + * by boardctl(). I this case: + * + * - canned_symbtab_initialize() and g_symtab() lie in the user space. + * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in + * kernel space. + * + * Access to boardctl() is provided in user space through a call gate. + * + * Input Parameters: + * symtab - The symbol table to be used + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ + defined(__KERNEL__) +int canned_symtab_select(FAR const struct symtab_desc_s *symdesc) +{ + exec_setsymtab(symdesc->symtab, symdesc->nsymbols); } +#endif #endif /* CONFIG_LIBC_SYMTAB */ -- GitLab From 4723ff55630993f43225ceade6aff273b8ea1b6c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 10:46:11 -0600 Subject: [PATCH 056/858] Update README --- libc/symtab/README.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libc/symtab/README.txt b/libc/symtab/README.txt index 7cb544aefb..8102c5dc5d 100644 --- a/libc/symtab/README.txt +++ b/libc/symtab/README.txt @@ -33,6 +33,10 @@ directory by using the following commands: cat syscall/syscall.csv libc/libc.csv | sort >libc/symtab/canned_symtab.csv tools/mksymtab libc/symtab/canned_symtab.csv libc/symtab/canned_symtab.inc +You may want omit syscall/syscall.csv in the above command in the protected +mode. It is optional since the system calls are provided through system +call traps. + Your board-level start up code code then needs to select the canned symbol table by calling the OS internal function canned_symtab_initialize() in the board-specfic board_apps_initialize() logic: -- GitLab From 9b036311c0bf9ad76b4c8c6c08361ba3a4a21780 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 23 Aug 2015 11:06:32 -0600 Subject: [PATCH 057/858] Missing comma in spi.h header file --- include/nuttx/spi/spi.h | 2 +- libc/symtab/{lib_symbtab.c => lib_symtab.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libc/symtab/{lib_symbtab.c => lib_symtab.c} (100%) diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 2a6e25ed03..4f77e0cb79 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -392,7 +392,7 @@ struct spi_ops_s CODE void (*setbits)(FAR struct spi_dev_s *dev, int nbits); CODE uint8_t (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); #ifdef CONFIG_SPI_CMDDATA - CODE int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid + CODE int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); #endif CODE uint16_t (*send)(FAR struct spi_dev_s *dev, uint16_t wd); diff --git a/libc/symtab/lib_symbtab.c b/libc/symtab/lib_symtab.c similarity index 100% rename from libc/symtab/lib_symbtab.c rename to libc/symtab/lib_symtab.c -- GitLab From 6fc449f689f59c68107640acd27ee8204bb120cb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 11:33:29 -0600 Subject: [PATCH 058/858] Moving canned_symtab from nuttx/libc to apps/system --- ChangeLog | 7 -- README.txt | 4 +- include/nuttx/binfmt/canned_symtab.h | 145 --------------------------- include/sys/boardctl.h | 17 +++- libc/Kconfig | 2 - libc/Makefile | 1 - libc/symtab/Kconfig | 15 --- libc/symtab/Make.defs | 45 --------- libc/symtab/README.txt | 57 ----------- libc/symtab/lib_symtab.c | 135 ------------------------- 10 files changed, 16 insertions(+), 412 deletions(-) delete mode 100644 include/nuttx/binfmt/canned_symtab.h delete mode 100644 libc/symtab/Kconfig delete mode 100644 libc/symtab/Make.defs delete mode 100644 libc/symtab/README.txt delete mode 100644 libc/symtab/lib_symtab.c diff --git a/ChangeLog b/ChangeLog index 09ee7e1802..61f179f326 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10868,13 +10868,6 @@ whole sockaddr_in or sockaddr_in6. From Pavel Pisa (2015-08-21). * tools/mksymtab: declare g_symtab array as conts to occupy RO section (Flash). From Pavel Pisa (2015-08-23). - * libc/symtab: Optional canned symtab inclusion to the build. When - option CONFIG_LIBC_SYMTAB is selected and symbol table file - libc/symtab/canned_symtab.inc is prepared then application can - use system provided complete symbol table. The option has - substantial effect on system image size. Mainly code/text. If - loading of applications at runtime is not planned do not select - this. From Pavel Pisa (2015-08-23). * libc/libc.csv and syscalls/syscalls.csv: Define some symbol export conditions, correct errno and add sleep and usleep. From Pavel Pisa (2015-08-23). diff --git a/README.txt b/README.txt index 035159dea8..53c6873725 100644 --- a/README.txt +++ b/README.txt @@ -1513,8 +1513,6 @@ nuttx/ |- lib/ | `- README.txt |- libc/ - | |- symtab/ - | | `- README.txt | `- README.txt |- libnx/ | `- README.txt @@ -1575,6 +1573,8 @@ apps/ | | `- README.txt | |- nxplayer | | `- README.txt + | |- symtab/ + | | `- README.txt | |- usbmsc | | `- README.txt | |- zmodem diff --git a/include/nuttx/binfmt/canned_symtab.h b/include/nuttx/binfmt/canned_symtab.h deleted file mode 100644 index f40018081c..0000000000 --- a/include/nuttx/binfmt/canned_symtab.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * include/nuttx/binfmt/canned_symtab.h - * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H -#define __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* struct symbtab_s describes one entry in the symbol table. A symbol table - * is a fixed size array of struct symtab_s. The information is intentionally - * minimal and supports only: - * - * 1. Function pointers as sym_values. Of other kinds of values need to be - * supported, then typing information would also need to be included in - * the structure. - * - * 2. Fixed size arrays. There is no explicit provisional for dynamically - * adding or removing entries from the symbol table (realloc might be - * used for that purpose if needed). The intention is to support only - * fixed size arrays completely defined at compilation or link time. - */ - -/* In order to full describe a symbol table, a vector containing the address - * of the symbol table and the number of elements in the symbol table is - * required. - */ - -struct symtab_s; /* Forward reference */ -struct symtab_desc_s -{ - FAR struct symtab_s *symtab; - int nsymbols; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: canned_symtab_initialize - * - * Description: - * Setup system provided canned symbol table. NOTE that this a user-space - * interface only. It is not generally available to to kernel mode code - * in protected or kernel builds. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__) -void canned_symtab_initialize(void); -#endif - -/**************************************************************************** - * Name: canned_symtab_select - * - * Description: - * Setup system provided canned symbol table. This function only exists - * the kernel portion of a protected or kernel build. It is called only - * by boardctl(). I this case: - * - * - canned_symbtab_initialize() and g_symtab() lie in the user space. - * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in - * kernel space. - * - * Access to boardctl() is provided in user space through a call gate. - * - * Input Parameters: - * symtab - The symbol table to be used - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ - defined(__KERNEL__) -int canned_symtab_select(FAR const struct symtab_desc_s *symdesc); -#endif - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_BINFMT_CANNED_SYMTAB_H */ - diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index 0cbc937971..28d08d81e4 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -72,9 +72,8 @@ * * CMD: BOARDIOC_SYMTAB * DESCRIPTION: Select a symbol table - * ARG: A pointer to an instance of struct symtab_desc_s - * (See include/nuttx/binfmt/canned_symtab.h). - * CONFIGURATION: CONFIG_LIBC_SYMTAB + * ARG: A pointer to an instance of struct boardioc_symtab_s + * CONFIGURATION: CONFIG_BOARDCTL_SYMTAB * DEPENDENCIES: None * * CMD: BOARDIOC_TSCTEST_SETUP @@ -159,6 +158,18 @@ struct boardioc_graphics_s #endif }; +/* In order to full describe a symbol table, a vector containing the address + * of the symbol table and the number of elements in the symbol table is + * required. + */ + +struct symtab_s; /* Forward reference */ +struct boardioc_symtab_s +{ + FAR struct symtab_s *symtab; + int nsymbols; +}; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/libc/Kconfig b/libc/Kconfig index 1be0aedcd0..e51915d1c2 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -195,8 +195,6 @@ config EXECFUNCS_NSYMBOLS symbols in that table. This selection provides the number of symbols in the symbol table. -source libc/symtab/Kconfig - endif # EXECFUNCS_HAVE_SYMTAB endif # LIBC_EXECFUNCS diff --git a/libc/Makefile b/libc/Makefile index 6509aa61d7..76d3e473aa 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -84,7 +84,6 @@ include queue/Make.defs include wqueue/Make.defs include misc/Make.defs include audio/Make.defs -include symtab/Make.defs # REVISIT: Backslash causes problems in $(COBJS) target DELIM := $(strip /) diff --git a/libc/symtab/Kconfig b/libc/symtab/Kconfig deleted file mode 100644 index 4cdef0d9c7..0000000000 --- a/libc/symtab/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config LIBC_SYMTAB - bool "Include canned symtab for applications and shell" - default n - depends on EXECFUNCS_HAVE_SYMTAB && !BUILD_KERNEL - select LIB_BOARDCTL if !BUILD_FLAT - ---help--- - Build and include default symbol table in the NuttX library. - The symbol table is selected by call canned_symtab_initialize(). - The table libc/symtab/canned_symtab.inc has to be generated - by mksymtab manually before this option is selected. diff --git a/libc/symtab/Make.defs b/libc/symtab/Make.defs deleted file mode 100644 index 98954a0e0d..0000000000 --- a/libc/symtab/Make.defs +++ /dev/null @@ -1,45 +0,0 @@ -############################################################################ -# libc/symtab/Make.defs -# -# Copyright (C) 2015 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_LIBC_SYMTAB),y) - -# Include canned symtab to the build - -CSRCS += lib_symtab.c - -DEPPATH += --dep-path symtab -VPATH += :symtab - -endif diff --git a/libc/symtab/README.txt b/libc/symtab/README.txt deleted file mode 100644 index 8102c5dc5d..0000000000 --- a/libc/symtab/README.txt +++ /dev/null @@ -1,57 +0,0 @@ -symtab -====== - -Symbol Tables and Build Modes ------------------------------ -This directory provide support for a canned symbol table which provides -all/most of system and libc services/functions to the application and NSH. - -Symbol tables have differing usefulness in different NuttX build modes: - - 1. In the FLAT build (CONFIG_BUILD_FLAT), symbol tables are used to bind - addresses in loaded ELF or NxFLAT modules to base code that usually - resides in FLASH memory. Both OS interfaces and user/application - libraries are made available to the loaded module via symbol tables. - - 2. Symbol tables may be of value in a protected build - (CONFIG_BUILD_PROTECTED) where the newly started user task must - share resources with other user code (but should use system calls to - interact with the OS). - - 3. But in the kernel build mode (CONFIG_BUILD_KERNEL), only fully linked - executables loadable via execl(), execv(), or posix_spawan() can used. - There is no use for a symbol table with the kernel build since all - memory resources are separate; nothing is share-able with the newly - started process. - -Creating the Canned Symbol Table --------------------------------- -The support is selected by CONFIG_LIBC_SYMTAB option and table has to be -prepared in advance manually. It can be prepared from NuttX top level -directory by using the following commands: - - cat syscall/syscall.csv libc/libc.csv | sort >libc/symtab/canned_symtab.csv - tools/mksymtab libc/symtab/canned_symtab.csv libc/symtab/canned_symtab.inc - -You may want omit syscall/syscall.csv in the above command in the protected -mode. It is optional since the system calls are provided through system -call traps. - -Your board-level start up code code then needs to select the canned symbol -table by calling the OS internal function canned_symtab_initialize() in the -board-specfic board_apps_initialize() logic: - - #include - ... - canned_symtab_initialize(); - -Code/Text Size Implications ---------------------------- -The option can have substantial effect on system image size, mainly -code/text. That is because the instructions to generate canned_symtab.inc -above will cause EVERY interface in the NuttX RTOS and the C library to be -included into build. Add to that the size of a huge symbol table. - -In order to reduce the code/text size, you may want to manually prune the -auto-generated canned_symtab.inc file to remove all interfaces that you do -not wish to include into the base FLASH image. diff --git a/libc/symtab/lib_symtab.c b/libc/symtab/lib_symtab.c deleted file mode 100644 index 4905d0bc91..0000000000 --- a/libc/symtab/lib_symtab.c +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** - * libc/symtab/lib_symtab.c - * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Canned symtab implemented by Pavel Pisa - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#include - -#ifdef CONFIG_LIBC_SYMTAB - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include "canned_symtab.inc" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: canned_symtab_initialize - * - * Description: - * Setup system provided canned symbol table. NOTE that this a user-space - * interface only. It is not generally available to to kernel mode code - * in protected or kernel builds. That is because exec_setsymtab() and - * g_symtab lie in different address spaces. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__) -void canned_symtab_initialize(void) -{ -#ifdef CONFIG_BUILD_FLAT - /* In the FLAT build, exec_symtab() can be called directly from any logic. - * Both the symbol table and the function exec_setsymtabe reside in the same - * namespace and address space. - */ - - exec_setsymtab(g_symtab, NSYMBOLS); - -#else - /* In the user mode portion of a protected or kernel build, we must set - * the symbol table indirectly through the boardctl() call gate that will - * proxy the call to canned_symtab_select(). In this case - * - * - canned_symbtab_initialize() and g_symtab() lie in the user space. - * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in - * kernel space. - * - * Access to boardctl() is provided in user space throug a call gate. - */ - - struct symtab_desc_s symdesc; - - symdesc.symtab = g_symtab; - symdesc.nsymbols = NSYMBOLS; - (void)boardctl(BOARDIOC_SYMTAB, (uinptr_t)&symdesc); -#endif -} -#endif - -/**************************************************************************** - * Name: canned_symtab_select - * - * Description: - * Setup system provided canned symbol table. This function only exists - * the kernel portion of a protected or kernel build. It is called only - * by boardctl(). I this case: - * - * - canned_symbtab_initialize() and g_symtab() lie in the user space. - * - boardctl(), canned_symtabl_select(), and exec_setsymtab() reside in - * kernel space. - * - * Access to boardctl() is provided in user space through a call gate. - * - * Input Parameters: - * symtab - The symbol table to be used - * - * Returned Value: - * Zero (OK) on success; a negated errno value on failure. - * - ****************************************************************************/ - -#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ - defined(__KERNEL__) -int canned_symtab_select(FAR const struct symtab_desc_s *symdesc) -{ - exec_setsymtab(symdesc->symtab, symdesc->nsymbols); -} -#endif - -#endif /* CONFIG_LIBC_SYMTAB */ -- GitLab From 2e9b81ee83f4b643b292ea702846abb7cd57a6b1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 12:17:31 -0600 Subject: [PATCH 059/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index de62dbc734..a4716900fa 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit de62dbc734217b4c18c11b87e4d1e75789193cdb +Subproject commit a4716900fafd56978018ec9e70047ec2b5080078 -- GitLab From 47bab42498665eb27bd241b0ead5d06206b41545 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 17:21:34 -0600 Subject: [PATCH 060/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 386bfb2232..c50e6b0277 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 386bfb2232c31cdab2abc2cad120a419295f1d75 +Subproject commit c50e6b0277974daf54f97105c5ad99057b0ad1aa diff --git a/configs b/configs index a4716900fa..71ee5a6c64 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a4716900fafd56978018ec9e70047ec2b5080078 +Subproject commit 71ee5a6c640704517a24c3cbbb100caeba5a78ca -- GitLab From 3743d3d84acd07b7097df2bbf10a920bfd708c18 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 08:00:39 -0600 Subject: [PATCH 061/858] Add configuration options for forthcoming st25fl1 devices --- Documentation | 2 +- drivers/mtd/Kconfig | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Documentation b/Documentation index ce750c0899..cae6e67e05 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit ce750c0899c2138b37b52a48d020a3eceb92fd04 +Subproject commit cae6e67e0534485cd42119346a2e0121d6652965 diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index cf912b3ca5..5989a526ba 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -387,6 +387,27 @@ config M25P_SUBSECTOR_ERASE endif +config MTD_ST25FL1 + bool "QuadSPI-based ST25FL1 FLASH" + default n + select SPI + +if MTD_ST25FL1 + +config ST25FL1_SPIMODE + int "ST25FL1 SPI Mode" + default 0 + +config ST25FL1_SPIFREQUENCY + int "ST25FL1 SPI Frequency" + default 20000000 + +config ST25FL1_SECTOR512 + bool "Simulate 512 byte Erase Blocks" + default n + +endif + config MTD_SMART bool "Sector Mapped Allocation for Really Tiny (SMART) Flash support" default n -- GitLab From ea2fafb024d8486596a03caabf84c1525c628ae3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 08:25:08 -0600 Subject: [PATCH 062/858] Add definitions to support a local loopback link layer --- Documentation | 2 +- drivers/net/Kconfig | 13 +++++++++++-- include/nuttx/net/net.h | 1 + include/nuttx/net/netconfig.h | 13 ++++++++++--- net/netdev/netdev_register.c | 14 +++++++++++++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Documentation b/Documentation index ce750c0899..cae6e67e05 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit ce750c0899c2138b37b52a48d020a3eceb92fd04 +Subproject commit cae6e67e0534485cd42119346a2e0121d6652965 diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 32c87c7e0c..370b35cc5d 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -5,12 +5,21 @@ comment "General Ethernet MAC Driver Options" +config NETDEV_LOOPBACK + bool "Local loopback support" + default n + ---help--- + Add support for the local network loopback device, lo. + config NETDEV_MULTINIC bool "Multiple network interface support" - default n + default n if !NETDEV_LOOPBACK + default y if NETDEV_LOOPBACK ---help--- Select this option if you board and/or MCU are capable of supporting - multiple Ethernet MAC drivers. + multiple link layer drivers. NOTE that the local loopback device + is considered to be a a link layer driver so if local loopback + support is used you probably need to select this option. config NETDEV_LATEINIT bool "Late driver initialization" diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 77c7fd807a..b10787f171 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -76,6 +76,7 @@ enum net_lltype_e { NET_LL_ETHERNET = 0, /* Ethernet */ + NET_LL_LOOPBACK, /* Local loopback */ NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ NET_LL_PPP, /* Point-to-Point Protocol (PPP) */ NET_LL_TUN, /* TUN Virtual Network Device */ diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index aeea16b4e1..8825c50981 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -157,7 +157,7 @@ # define MAX_NET_DEV_MTU CONFIG_NET_ETH_MTU #else - /* Perhaps only Unix domain sockets */ + /* Perhaps only Unix domain sockets of the loopback device */ # define NET_LL_HDRLEN(d) 0 # define NET_DEV_MTU(d) 0 @@ -166,6 +166,10 @@ #endif /* MULTILINK or SLIP or ETHERNET */ +/* For the loopback device, we will use the largest representable MTU */ + +#define NET_LO_MTU UINT16_MAX + /* Layer 3/4 Configuration Options ******************************************/ /* IP configuration options */ @@ -346,6 +350,7 @@ */ #define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - TCP_HDRLEN - (h)) +#define LO_TCP_MSS(h) (NET_LO_MTU - (h)) /* If Ethernet is supported, then it will have the smaller MSS */ @@ -402,15 +407,17 @@ * See the note above regarding the TCP MSS and CONFIG_NET_MULTILINK. */ +#define NET_LO_TCP_RECVWNDO LO_TCP_MSS(0) + #ifdef CONFIG_NET_SLIP # ifndef CONFIG_NET_SLIP_TCP_RECVWNDO -# define CONFIG_NET_SLIP_TCP_RECVWNDO SLIP_TCP_MSS +# define CONFIG_NET_SLIP_TCP_RECVWNDO SLIP_TCP_MSS(0) # endif #endif #ifdef CONFIG_NET_ETHERNET # ifndef CONFIG_NET_ETH_TCP_RECVWNDO -# define CONFIG_NET_ETH_TCP_RECVWNDO ETH_TCP_MSS +# define CONFIG_NET_ETH_TCP_RECVWNDO ETH_TCP_MSS(0) # endif #endif diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 524f6cb2d4..e46ce2afc9 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -61,8 +61,9 @@ * Pre-processor Definitions ****************************************************************************/ -#define NETDEV_SLIP_FORMAT "sl%d" #define NETDEV_ETH_FORMAT "eth%d" +#define NETDEV_LO_FORMAT "lo" +#define NETDEV_SLIP_FORMAT "sl%d" #define NETDEV_TUN_FORMAT "tun%d" #if defined(CONFIG_NET_SLIP) @@ -190,6 +191,17 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) switch (lltype) { +#ifdef CONFIG_NETDEV_LOOPBACK + case NET_LL_LOOPBACK: /* Local loopback */ + dev->d_llhdrlen = 0; + dev->d_mtu = NET_LO_MTU; +#ifdef CONFIG_NET_TCP + dev->d_recvwndo = NET_LO_TCP_RECVWNDO; +#endif + devfmt = NETDEV_LO_FORMAT; + break; +#endif + #ifdef CONFIG_NET_ETHERNET case NET_LL_ETHERNET: /* Ethernet */ dev->d_llhdrlen = ETH_HDRLEN; -- GitLab From 569ff602ea9e4228572d1fcc715d8b4fc7ff1f8a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 08:29:07 -0600 Subject: [PATCH 063/858] Networking: Remove bogus references to PPP as a link layer protocol --- ChangeLog | 3 +++ include/nuttx/net/net.h | 3 +-- net/netdev/netdev_register.c | 13 +------------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61f179f326..d6a532f42c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10871,3 +10871,6 @@ * libc/libc.csv and syscalls/syscalls.csv: Define some symbol export conditions, correct errno and add sleep and usleep. From Pavel Pisa (2015-08-23). + * net/ ande include/nuttx/net: Remove references to PPP as a + link layer protocol (2015-08-24). + diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 77c7fd807a..9519407c8f 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -77,7 +77,6 @@ enum net_lltype_e { NET_LL_ETHERNET = 0, /* Ethernet */ NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ - NET_LL_PPP, /* Point-to-Point Protocol (PPP) */ NET_LL_TUN, /* TUN Virtual Network Device */ }; @@ -1078,7 +1077,7 @@ int net_vfcntl(int sockfd, int cmd, va_list ap); * * Parameters: * dev - The device driver structure to be registered. - * lltype - Link level protocol used by the driver (Ethernet, SLIP, PPP, ... + * lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, ... * * Returned Value: * 0:Success; negated errno on failure diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 524f6cb2d4..38f77d516d 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -159,7 +159,7 @@ static int find_devnum(FAR const char *devfmt) * * Parameters: * dev - The device driver structure to be registered. - * lltype - Link level protocol used by the driver (Ethernet, SLIP, PPP, ... + * lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, ... * ... * * Returned Value: @@ -223,17 +223,6 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) break; #endif -#if 0 /* REVISIT: Not yet supported */ - case NET_LL_PPP: /* Point-to-Point Protocol (PPP) */ - dev->d_llhdrlen = 0; - dev->d_mtu = CONFIG_NET_PPP_MTU; -#ifdef CONFIG_NET_TCP - dev->d_recvwndo = CONFIG_NET_PPP_TCP_RECVWNDO; -#endif - devfmt = NETDEV_PPP_FORMAT; - break; -#endif - default: nlldbg("ERROR: Unrecognized link type: %d\n", lltype); return -EINVAL; -- GitLab From 07bdff9ef78ff5eff87bc1e3c7826eb1c19201d0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 10:08:26 -0600 Subject: [PATCH 064/858] Networking: Add NetDB support for the local loopback device --- ChangeLog | 5 +- include/nuttx/net/loopback.h | 98 ++++++++++++ libc/netdb/lib_gethostbyaddrr.c | 264 +++++++++++++++++++++++++++++--- libc/netdb/lib_gethostbynamer.c | 104 ++++++++++++- net/Kconfig | 1 + net/Makefile | 1 + net/README.txt | 1 + net/loopback/Kconfig | 4 + net/loopback/Make.defs | 48 ++++++ net/loopback/lo_globals.c | 70 +++++++++ net/loopback/loopback.h | 72 +++++++++ 11 files changed, 646 insertions(+), 22 deletions(-) create mode 100644 include/nuttx/net/loopback.h create mode 100644 net/loopback/Kconfig create mode 100644 net/loopback/Make.defs create mode 100644 net/loopback/lo_globals.c create mode 100644 net/loopback/loopback.h diff --git a/ChangeLog b/ChangeLog index d6a532f42c..32a4086f3b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10873,4 +10873,7 @@ Pavel Pisa (2015-08-23). * net/ ande include/nuttx/net: Remove references to PPP as a link layer protocol (2015-08-24). - + * net/, drivers/net, and include/net: Add definitions to support + a local loopback device and link layer (2015-08-24). + * libc/netdb, net/loopback, include/nuttx/net: Add NetDB support + for the local loopback device (2015-08-24). diff --git a/include/nuttx/net/loopback.h b/include/nuttx/net/loopback.h new file mode 100644 index 0000000000..084a8d61be --- /dev/null +++ b/include/nuttx/net/loopback.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * include/nuttx/net/loopback.h + * Definitions for use with local loopback device + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory nutt + * + * Includes some definitions that a compatible with the LGPL GNU C Library + * header file of the same name. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_LOOPBACK_H +#define __INCLUDE_NUTTX_NET_LOOPBACK_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_NETDEV_LOOPBACK + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#ifdef CONFIG_LIBC_NETDB +/* Local loopback hostname */ + +EXTERN const char g_lo_hostname[]; +#endif + +/* Local loopback addresses */ + +EXTERN const in_addr_t g_lo_ipv4addr; +EXTERN const in_addr_t g_lo_ipv4mask; +EXTERN const net_ipv6addr_t g_lo_ipv6addr; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NETDEV_LOOPBACK */ +#endif /* __INCLUDE_NUTTX_NET_LOOPBACK_H */ diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index d88527570c..153e749602 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -53,21 +53,81 @@ #ifdef CONFIG_NETDB_HOSTFILE /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: gethostbyaddr_r + * Name: lib_lo_ipv4match * * Description: - * The gethostbyaddr_r() function returns a structure of type hostent for - * the given host address addr of length len and address type type. Valid - * address types are AF_INET and AF_INET6. The host address argument is a - * pointer to a struct of a type depending on the address type, for example - * a struct in_addr * for address type AF_INET. - * - * gethostbyaddr_r() is *not* POSIX but is similar to a Glibc extension and is - * used internally by NuttX to implement the POSIX gethostbyaddr(). + * Check if the address is the reserved IPv4 address for the local + * loopback device. + * + * Input Parameters: + * addr - The address of the host to find. + * len - The length of the address + * type - The type of the address + * + * Returned Value: + * True if the address is the IPv4 local loopback address. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_LOOPBACK +static bool lib_lo_ipv4match(FAR const void *addr, socklen_t len, int type) +{ + FAR struct in_addr *ipv4addr; + + if (type == AF_INET && len >= sizeof(struct in_addr)) + { + ipv4addr = (FAR struct in_addr *)addr; + return net_ipv4addr_maskcmp(ipv4addr->sin_addr.s_addr, + g_lo_ipv4addr->s_addr, + g_lo_ipv4addr->s_addr); + } + + return false; +} +#endif + +/**************************************************************************** + * Name: lib_lo_ipv6match + * + * Description: + * Check if the address is the reserved IPv6 address for the local + * loopback device. + * + * Input Parameters: + * addr - The address of the host to find. + * len - The length of the address + * type - The type of the address + * + * Returned Value: + * True if the address is the IPv4 local loopback address. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_LOOPBACK +static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type) +{ + FAR struct in_addr6 *ipv6addr; + + if (type == AF_INE6T && len >= sizeof(struct in_addr6)) + { + ipv6addr = (FAR struct in_addr6 *)addr; + return net_ipv6addr_cmp(ipv6addr->sin6_addr.s6_addr16, g_lo_ipv6addr); + } + + return false; +} +#endif + +/**************************************************************************** + * Name: lib_localhost + * + * Description: + * Check if the address is the reserved address for the local loopback + * device. * * Input Parameters: * addr - The address of the host to find. @@ -85,24 +145,123 @@ * ****************************************************************************/ -int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, - FAR struct hostent *host, FAR char *buf, - size_t buflen, int *h_errnop) +#ifdef CONFIG_NETDEV_LOOPBACK +static int lib_localhost(FAR const void *addr, socklen_t len, int type, + FAR struct hostent *host, FAR char *buf, + size_t buflen, int *h_errnop) { - FAR FILE *stream; + FAR struct hostent_info_s *info; + socklen_t addrlen; + FAR const uint8_t *src; + FAR uint8_t *dest; + bool match; int herrnocode; - int nread; + int namelen; + int ret; - DEBUGASSERT(addr != NULL && host != NULL && buf != NULL); - DEBUGASSERT(type == AF_INET || type == AF_INET6); + if (lib_lo_ipv4match(addr, len, type)) + { + /* Setup to transfer the IPv4 address */ - /* Make sure that the h_errno has a non-error code */ + addrlen = sizeof(struct in_addr); + src = (FAR uint8_t *)&g_lo_ipv4addr; + host->h_addrtype = AF_INET; + } + else if (lib_lo_ipv4match(addr, len, type)) + { + /* Setup to transfer the IPv6 address */ + addrlen = sizeof(struct in6_addr); + src = (FAR uint8_t *)&g_lo_ipv6addr; + host->h_addrtype = AF_INET6; + } + else + { + /* Return 1 meaning that we have no errors but no match either */ + + return 1; + } + + /* Make sure that space remains to hold the hostent structure and + * the IP address. + */ + + if (buflen <= (sizeof(struct hostent_info_s) + addrlen)) + { + return -ERANGE; + } + + + info = (FAR struct hostent_info_s *)buf; + dest = (FAR uint8_t *)info->hi_data; + buflen -= (sizeof(struct hostent_info_s) - 1); + + memset(host, 0, sizeof(struct hostent)); + memset(info, 0, sizeof(struct hostent_info_s)); + memcpy(dest, src, addrlen); + + info->hi_addrlist[0] = dest; + host->h_addr_list = info->hi_addrlist; + host->h_length = addrlen; + + ptr += addrlen; + buflen -= addrlen; + + /* And copy localhost host name */ + + namelen = strlen(g_lo_hostname); + if (addrlen + namelen + 1 > buflen) + { + herrnocode = ERANGE; + goto errorout_with_herrnocode; + } + + strncpy(ptr, g_lo_hostname, buflen); + return 0; + } + + return 1; + +errorout_with_herrnocode: if (h_errnop) { - *h_errnop = 0; + *h_errnop = herrnocode; } + return ERROR; +} +#endif + +/**************************************************************************** + * Name: lib_hostfile_lookup + * + * Description: + * Try to look-up the host name from the network host file + * + * Input Parameters: + * addr - The address of the host to find. + * len - The length of the address + * type - The type of the address + * host - Caller provided location to return the host data. + * buf - Caller provided buffer to hold string data associated with the + * host data. + * buflen - The size of the caller-provided buffer + * h_errnop - There h_errno value returned in the event of a failure. + * + * Returned Value: + * Zero (OK) is returned on success, -1 (ERROR) is returned on a failure + * with the returned h_errno value provided the reason for the failure. + * + ****************************************************************************/ + +int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type, + FAR struct hostent *host, FAR char *buf, + size_t buflen, int *h_errnop) +{ + FAR FILE *stream; + int herrnocode; + int nread; + /* Search the hosts file for a match */ stream = fopen(CONFIG_NETDB_HOSTCONF_PATH, "r"); @@ -185,4 +344,71 @@ errorout_with_herrnocode: return ERROR; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gethostbyaddr_r + * + * Description: + * The gethostbyaddr_r() function returns a structure of type hostent for + * the given host address addr of length len and address type type. Valid + * address types are AF_INET and AF_INET6. The host address argument is a + * pointer to a struct of a type depending on the address type, for example + * a struct in_addr * for address type AF_INET. + * + * gethostbyaddr_r() is *not* POSIX but is similar to a Glibc extension and is + * used internally by NuttX to implement the POSIX gethostbyaddr(). + * + * Input Parameters: + * addr - The address of the host to find. + * len - The length of the address + * type - The type of the address + * host - Caller provided location to return the host data. + * buf - Caller provided buffer to hold string data associated with the + * host data. + * buflen - The size of the caller-provided buffer + * h_errnop - There h_errno value returned in the event of a failure. + * + * Returned Value: + * Zero (OK) is returned on success, -1 (ERROR) is returned on a failure + * with the returned h_errno value provided the reason for the failure. + * + ****************************************************************************/ + +int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, + FAR struct hostent *host, FAR char *buf, + size_t buflen, int *h_errnop) +{ + FAR FILE *stream; + int herrnocode; + int nread; + + DEBUGASSERT(addr != NULL && host != NULL && buf != NULL); + DEBUGASSERT(type == AF_INET || type == AF_INET6); + + /* Make sure that the h_errno has a non-error code */ + + if (h_errnop) + { + *h_errnop = 0; + } + +#ifdef CONFIG_NETDEV_LOOPBACK + /* Check for the local loopback address */ + + if (lib_localhost(addr, len, type, host, but, buflen, h_errnop) == 0) + { + /* Yes.. we are done */ + + return OK; + } +#endif + + /* Search the hosts file for a match */ + + return lib_hostfile_lookup(addr, len, type, host, but, buflen, h_errnop); +} + #endif /* CONFIG_NETDB_HOSTFILE */ diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index ff90bcbf76..aa18807783 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -85,7 +85,7 @@ struct hostent_info_s * name into the h_name field and its struct in_addr equivalent into the * h_addr_list[0] field of the returned hostent structure. * - * Input paramters: + * Input Parameters: * stream - File stream of the opened hosts file with the file pointer * positioned at the beginning of the next host entry. * host - Caller provided location to return the host data. @@ -211,6 +211,95 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, return 0; } +/**************************************************************************** + * Name: lib_localhost + * + * Description: + * Check if the name is the reserved name for the local loopback device. + * + * Input Parameters: + * stream - File stream of the opened hosts file with the file pointer + * positioned at the beginning of the next host entry. + * host - Caller provided location to return the host data. + * buf - Caller provided buffer to hold string data associated with the + * host data. + * buflen - The size of the caller-provided buffer + * + * Returned Value: + * Zero (0) is returned if the name is an numeric IP address. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_LOOPBACK +static int lib_localhost(FAR const char *name, FAR struct hostent *host, + FAR char *buf, size_t buflen) +{ + FAR struct hostent_info_s *info; + socklen_t addrlen; + FAR const uint8_t *src; + FAR uint8_t *dest; + int namelen; + int ret; + + if (strcmp(name, "localhost") == 0) + { + /* Yes.. it is the localhost */ + +#ifdef CONFIG_NET_IPv4 + /* Setup to transfer the IPv4 address */ + + addrlen = sizeof(struct in_addr); + src = (FAR uint8_t *)&g_lo_ipv4addr; + host->h_addrtype = AF_INET; + +#else /* CONFIG_NET_IPv6 */ + /* Setup to transfer the IPv6 address */ + + addrlen = sizeof(struct in6_addr); + src = (FAR uint8_t *)&g_lo_ipv6addr; + host->h_addrtype = AF_INET6; +#endif + + /* Make sure that space remains to hold the hostent structure and + * the IP address. + */ + + if (buflen <= (sizeof(struct hostent_info_s) + addrlen)) + { + return -ERANGE; + } + + info = (FAR struct hostent_info_s *)buf; + dest = (FAR uint8_t *)info->hi_data; + buflen -= (sizeof(struct hostent_info_s) - 1); + + memset(host, 0, sizeof(struct hostent)); + memset(info, 0, sizeof(struct hostent_info_s)); + memcpy(dest, src, addrlen); + + info->hi_addrlist[0] = dest; + host->h_addr_list = info->hi_addrlist; + host->h_length = addrlen; + + ptr += addrlen; + buflen -= addrlen; + + /* And copy name */ + + namelen = strlen(name); + if (addrlen + namelen + 1 > buflen) + { + return -ERANGE; + } + + strncpy(ptr, name, buflen); + return 0; + } + + return 1; +} +#endif + /**************************************************************************** * Name: lib_find_answer * @@ -471,7 +560,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, * Description: * Try to look-up the host name from the network host file * - * Input paramters: + * Input Parameters: * name - The name of the host to find. * host - Caller provided location to return the host data. * buf - Caller provided buffer to hold string data associated with the @@ -651,6 +740,17 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host, return OK; } +#ifdef CONFIG_NETDEV_LOOPBACK + /* Check for the local loopback host name */ + + if (lib_localhost(name, host, buf, buflen) == 0) + { + /* Yes.. we are done */ + + return OK; + } +#endif + /* Try to find the name in the HOSTALIASES environment variable */ /* REVISIT: Not implemented */ diff --git a/net/Kconfig b/net/Kconfig index 3c91e020d0..a6597e064d 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -245,6 +245,7 @@ source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" source "net/igmp/Kconfig" source "net/arp/Kconfig" +source "net/loopback/Kconfig" source "net/iob/Kconfig" source "net/utils/Kconfig" diff --git a/net/Makefile b/net/Makefile index ce3faf0f3a..0b3aea0a29 100644 --- a/net/Makefile +++ b/net/Makefile @@ -68,6 +68,7 @@ include local/Make.defs include tcp/Make.defs include udp/Make.defs include devif/Make.defs +include loopback/Make.defs include route/Make.defs include utils/Make.defs endif diff --git a/net/README.txt b/net/README.txt index db0a59452a..0f93c07581 100644 --- a/net/README.txt +++ b/net/README.txt @@ -14,6 +14,7 @@ Directory Structure +- icmpv6 - Internet Control Message Protocol (IPv6) +- iob - I/O buffering logic +- local - Unix domain (local) sockets + +- loopback - Local loopback +- neighbor - Neighbor Discovery Protocol (IPv6) +- netdev - Socket network device interface +- pkt - "Raw" packet socket support diff --git a/net/loopback/Kconfig b/net/loopback/Kconfig new file mode 100644 index 0000000000..f72f3c094c --- /dev/null +++ b/net/loopback/Kconfig @@ -0,0 +1,4 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# diff --git a/net/loopback/Make.defs b/net/loopback/Make.defs new file mode 100644 index 0000000000..5cbdc8bf75 --- /dev/null +++ b/net/loopback/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# net/route/Make.defs +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_NET_ROUTE),y) + +# Routing table support + +SOCK_CSRCS += net_addroute.c net_allocroute.c net_delroute.c +SOCK_CSRCS += net_foreachroute.c net_router.c netdev_router.c + +# Include routing table build support + +DEPPATH += --dep-path route +VPATH += :route + +endif diff --git a/net/loopback/lo_globals.c b/net/loopback/lo_globals.c new file mode 100644 index 0000000000..55d273c566 --- /dev/null +++ b/net/loopback/lo_globals.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * net/loopback/lo_globals.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "loopback/loopback.h" + +#ifdef CONFIG_NETDEV_LOOPBACK + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Local loopback hostname */ + +const char g_lo_hostname[] = "localhost"; + +/* Local loopback addresses */ + +const in_addr_t g_lo_ipv4addr = HTONL(0x7f000001); +const in_addr_t g_lo_ipv4mask = HTONL(0xff000000); +const net_ipv6addr_t g_lo_ipv6addr = +{ + HTONS(0), HTONS(0), HTONS(0), HTONS(0), + HTONS(0), HTONS(0), HTONS(0), HTONS(1) +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_NETDEV_LOOPBACK */ diff --git a/net/loopback/loopback.h b/net/loopback/loopback.h new file mode 100644 index 0000000000..082e6ccb68 --- /dev/null +++ b/net/loopback/loopback.h @@ -0,0 +1,72 @@ +/**************************************************************************** + * net/route/route.h + * + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NET_LOOPBACK_LOOBACK_H +#define __NET_LOOPBACK_LOOBACK_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_NETDEV_LOOPBACK + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + + /**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* CONFIG_NETDEV_LOOPBACK */ +#endif /* __NET_LOOPBACK_LOOBACK_H */ -- GitLab From ccb24e1766f27ad7895f7dc31453c6b9e21623a1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 11:03:36 -0600 Subject: [PATCH 065/858] drivers/net: Add a basic prototype for a local loopback device --- ChangeLog | 2 + drivers/net/Kconfig | 5 +- drivers/net/Make.defs | 6 +- drivers/net/loopback.c | 648 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 659 insertions(+), 2 deletions(-) create mode 100644 drivers/net/loopback.c diff --git a/ChangeLog b/ChangeLog index 32a4086f3b..4a1244b08a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10877,3 +10877,5 @@ a local loopback device and link layer (2015-08-24). * libc/netdb, net/loopback, include/nuttx/net: Add NetDB support for the local loopback device (2015-08-24). + * drivers/net/loopback.c: Add basic prototype of a local loopback + device (2015-08-24). diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 370b35cc5d..9806298da3 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -8,8 +8,11 @@ comment "General Ethernet MAC Driver Options" config NETDEV_LOOPBACK bool "Local loopback support" default n + select NET_NOINTS ---help--- - Add support for the local network loopback device, lo. + Add support for the local network loopback device, lo. Any additional + networking devices that are enabled must be compatible with + CONFIG_NET_NOINTS. config NETDEV_MULTINIC bool "Multiple network interface support" diff --git a/drivers/net/Make.defs b/drivers/net/Make.defs index 1af4356565..e09162c00c 100644 --- a/drivers/net/Make.defs +++ b/drivers/net/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # drivers/net/Make.defs # -# Copyright (C) 2007, 2010-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2010-2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -39,6 +39,10 @@ ifeq ($(CONFIG_NET),y) # Include network interface drivers +ifeq ($(CONFIG_NETDEV_LOOPBACK),y) + CSRCS += loopback.c +endif + ifeq ($(CONFIG_NET_DM90x0),y) CSRCS += dm90x0.c endif diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c new file mode 100644 index 0000000000..a3d0779043 --- /dev/null +++ b/drivers/net/loopback.c @@ -0,0 +1,648 @@ +/**************************************************************************** + * drivers/net/loopback.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#if defined(CONFIG_NET) && defined(CONFIG_NETDEV_LOOBACK) + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_NET_PKT +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_NET_NOINTS +# error CONFIG_NET_NOINTS must be selected +#endif + +#ifndef CONFIG_SCHED_HPWORK +# error High priority work queue support is required (CONFIG_SCHED_HPWORK) +#endif + +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ + +#define LO_WDDELAY (1*CLK_TCK) +#define LO_POLLHSEC (1*2) + +/* This is a helper pointer for accessing the contents of the Ethernet header */ + +#define BUF ((struct eth_hdr_s *)priv->lo_dev.d_buf) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The lo_driver_s encapsulates all state information for a single hardware + * interface + */ + +struct lo_driver_s +{ + bool lo_bifup; /* true:ifup false:ifdown */ + WDOG_ID lo_polldog; /* TX poll timer */ + struct work_s lo_work; /* For deferring work to the work queue */ + + /* This holds the information visible to uIP/NuttX */ + + struct net_driver_s lo_dev; /* Interface understood by uIP */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct lo_driver_s g_loopback; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Loop back logic */ + +static void lo_loopback(FAR struct lo_driver_s *priv); + +/* Polling logic */ + +static int lo_txpoll(FAR struct net_driver_s *dev); +static inline void lo_poll(FAR struct lo_driver_s *priv); +static void lo_poll_work(FAR void *arg); +static void lo_poll_expiry(int argc, uint32_t arg, ...); + +/* NuttX callback functions */ + +static int lo_ifup(FAR struct net_driver_s *dev); +static int lo_ifdown(FAR struct net_driver_s *dev); +static inline void lo_txavail_process(FAR struct lo_driver_s *priv); +static void lo_txavail_work(FAR void *arg); +static int lo_txavail(FAR struct net_driver_s *dev); +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#ifdef CONFIG_NET_IGMP +static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: lo_loopback + * + * Description: + * An interrupt was received indicating the availability of a new RX packet + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by interrupt handling logic. + * + ****************************************************************************/ + +static void lo_loopback(FAR struct lo_driver_s *priv) +{ +#ifdef CONFIG_NET_PKT + /* When packet sockets are enabled, feed the frame into the packet tap */ + + pkt_input(&priv->lo_dev); +#endif + + /* We only accept IP packets of the configured type and ARP packets */ + +#ifdef CONFIG_NET_IPv4 + if (BUF->type == HTONS(ETHTYPE_IP)) + { + nllvdbg("IPv4 frame\n"); + ipv4_input(&priv->lo_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (priv->lo_dev.d_len > 0) + { + /* Loop the packet back to the network. + * REVISIST: The must be a limit to the depth of recursion. + */ + + lo_loopback(priv); + } + } + else +#endif +#ifdef CONFIG_NET_IPv6 + if (BUF->type == HTONS(ETHTYPE_IP6)) + { + nllvdbg("Iv6 frame\n"); + ipv6_input(&priv->lo_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (priv->lo_dev.d_len > 0) + { + /* Loop the packet back to the netork + * REVISIST: The must be a limit to the depth of recursion. + */ + + lo_loopback(priv); + } + } + else +#endif + { + ndbg("WARNING: Unrecognized packet type dropped: %04x\n", BUF->type); + } +#endif +} + +/**************************************************************************** + * Function: lo_txpoll + * + * Description: + * Check if the network has any outgoing packets ready to send. This is + * a callback from devif_poll(). devif_poll() will be called only during + * normal TX polling. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * global interrupts are disabled, either explicitly or indirectly through + * interrupt handling logic. + * + ****************************************************************************/ + +static int lo_txpoll(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + + /* Check if the polling resulted in data that should be sent, i.e., tht + * the field d_len is set to a value > 0. + */ + + if (priv->lo_dev.d_len > 0) + { + /* Loop the packet back to the host */ + + lo_loopback(priv); + } + + return 0; +} + +/**************************************************************************** + * Function: lo_poll + * + * Description: + * Perform the periodic poll. This may be called either from watchdog + * timer logic or from the worker thread, depending upon the configuration. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static inline void lo_poll(FAR struct lo_driver_s *priv) +{ + /* Perform the poll */ + + (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); +} + +/**************************************************************************** + * Function: lo_poll_work + * + * Description: + * Perform periodic polling from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * Ethernet interrupts are disabled + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void lo_poll_work(FAR void *arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + net_lock_t state; + + /* Perform the poll */ + + state = net_lock(); + lo_poll(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: lo_poll_expiry + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void lo_poll_expiry(int argc, uint32_t arg, ...) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions. + */ + + if (work_available(&priv->lo_work)) + { + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(HPWORK, &priv->lo_work, lo_poll_work, priv, 0); + } + else + { + /* No.. Just re-start the watchdog poll timer, missing one polling + * cycle. + */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, arg); + } +} + +/**************************************************************************** + * Function: lo_ifup + * + * Description: + * NuttX Callback: Bring up the Ethernet interface when an IP address is + * provided + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int lo_ifup(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + +#ifdef CONFIG_NET_IPv4 + ndbg("Bringing up: %d.%d.%d.%d\n", + dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); +#endif +#ifdef CONFIG_NET_IPv6 + ndbg("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], + dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], + dev->d_ipv6addr[6], dev->d_ipv6addr[7]); +#endif + + /* Set and activate a timer process */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, (uint32_t)priv); + + priv->lo_bifup = true; + return OK; +} + +/**************************************************************************** + * Function: lo_ifdown + * + * Description: + * NuttX Callback: Stop the interface. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int lo_ifdown(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + + /* Cancel the TX poll timer and TX timeout timers */ + + wd_cancel(priv->lo_polldog); + + /* Mark the device "down" */ + + priv->lo_bifup = false; + return OK; +} + +/**************************************************************************** + * Function: lo_txavail_process + * + * Description: + * Perform an out-of-cycle poll. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static inline void lo_txavail_process(FAR struct lo_driver_s *priv) +{ + /* Ignore the notification if the interface is not yet up */ + + if (priv->lo_bifup) + { + /* If so, then poll the network for new XMIT data */ + + (void)devif_poll(&priv->lo_dev, lo_txpoll); + } +} + +/**************************************************************************** + * Function: lo_txavail_work + * + * Description: + * Perform an out-of-cycle poll on the worker thread. + * + * Parameters: + * arg - Reference to the NuttX driver state structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * Called on the higher priority worker thread. + * + ****************************************************************************/ + +static void lo_txavail_work(FAR void *arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + net_lock_t state; + + /* Perform the poll */ + + state = net_lock(); + lo_txavail_process(priv); + net_unlock(state); +} + +/**************************************************************************** + * Function: lo_txavail + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static int lo_txavail(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&priv->lo_work)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(HPWORK, &priv->lo_work, lo_txavail_work, priv, 0); + } + + return OK; +} + +/**************************************************************************** + * Function: lo_addmac + * + * Description: + * NuttX Callback: Add the specified MAC address to the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be added + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + /* There is no multicast support in the loopback driver */ + + return OK; +} +#endif + +/**************************************************************************** + * Function: lo_rmmac + * + * Description: + * NuttX Callback: Remove the specified MAC address from the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be removed + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IGMP +static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + /* There is no multicast support in the loopback driver */ + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: localhost_initialize + * + * Description: + * Initialize the Ethernet controller and driver + * + * Parameters: + * intf - In the case where there are multiple EMACs, this value + * identifies which EMAC is to be initialized. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +int localhost_initialize(void) +{ + FAR struct lo_driver_s *priv; + + /* Get the interface structure associated with this interface number. */ + + priv = &g_loopback; + + /* Initialize the driver structure */ + + memset(priv, 0, sizeof(struct lo_driver_s)); + priv->lo_dev.d_ifup = lo_ifup; /* I/F up (new IP address) callback */ + priv->lo_dev.d_ifdown = lo_ifdown; /* I/F down callback */ + priv->lo_dev.d_txavail = lo_txavail; /* New TX data callback */ +#ifdef CONFIG_NET_IGMP + priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */ + priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */ +#endif + priv->lo_dev.d_private = (void*)g_loopback; /* Used to recover private state from dev */ + + /* Create a watchdog for timing polling for and timing of transmissions */ + + priv->lo_polldog = wd_create(); /* Create periodic poll timer */ + + /* Register the loopabck device with the OS so that socket IOCTLs can b + * performed. + */ + + (void)netdev_register(&priv->lo_dev, NET_LL_LOOPBACK); + + /* Set the local loopback IP address */ + +#ifdef CONFIG_NET_IPv4 + net_ipv4addr_copy(dev->d_ipaddr, g_lo_ipv4addr); + net_ipv4addr_copy(dev->d_draddr, g_lo_ipv4addr); + net_ipv4addr_copy(dev->d_netmask, g_lo_ipv4mask); +#endif +#ifdef CONFIG_NET_IPv6 + net_ipv6addr_hdrcopy(dev->d_ipv6addr, g_lo_ipv6addr) + net_ipv6addr_hdrcopy(dev->d_ipv6draddr, g_lo_ipv6addr) + net_ipv6addr_hdrcopy(dev->d_ipv6netmask, g_ipv6_allzeroaddr) +#endif + /* Put the network in the UP state */ + + return lo_ifup(&priv->lo_dev); +} + +#endif /* CONFIG_NET && CONFIG_NETDEV_LOOBACK */ -- GitLab From 0b012c7978ead2af94b4aedc171cb2407666291e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 11:29:54 -0600 Subject: [PATCH 066/858] Fix some initial loop back device compilation errors; mark configuration as EXPERIMENTAL --- drivers/net/Kconfig | 1 + drivers/net/loopback.c | 1 - drivers/net/skeleton.c | 28 ++++++++++++++++------------ include/nuttx/net/loopback.h | 1 + libc/netdb/lib_gethostbyaddrr.c | 10 +++++----- libc/netdb/lib_gethostbynamer.c | 16 ++++++++-------- net/loopback/Make.defs | 15 +++++++-------- 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 9806298da3..ec2a65aa5c 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -9,6 +9,7 @@ config NETDEV_LOOPBACK bool "Local loopback support" default n select NET_NOINTS + depends on EXPERIMENTAL ---help--- Add support for the local network loopback device, lo. Any additional networking devices that are enabled must be compatible with diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index a3d0779043..22ede3df9c 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -213,7 +213,6 @@ static void lo_loopback(FAR struct lo_driver_s *priv) { ndbg("WARNING: Unrecognized packet type dropped: %04x\n", BUF->type); } -#endif } /**************************************************************************** diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index e0bef1ee44..9b8ed1e16c 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -113,9 +113,9 @@ struct skel_driver_s struct work_s sk_work; /* For deferring work to the work queue */ #endif - /* This holds the information visible to uIP/NuttX */ + /* This holds the information visible to the NuttX network */ - struct net_driver_s sk_dev; /* Interface understood by uIP */ + struct net_driver_s sk_dev; /* Interface understood by the network */ }; /**************************************************************************** @@ -215,7 +215,8 @@ static int skel_transmit(FAR struct skel_driver_s *priv) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT, skel_txtimeout_expiry, 1, (uint32_t)priv); + (void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT, + skel_txtimeout_expiry, 1, (uint32_t)priv); return OK; } @@ -223,8 +224,9 @@ static int skel_transmit(FAR struct skel_driver_s *priv) * Function: skel_txpoll * * Description: - * The transmitter is available, check if uIP has any outgoing packets ready - * to send. This is a callback from devif_poll(). devif_poll() may be called: + * The transmitter is available, check if the network has any outgoing + * packets ready to send. This is a callback from devif_poll(). + * devif_poll() may be called: * * 1. When the preceding TX packet send is complete, * 2. When the preceding TX packet send timesout and the interface is reset @@ -314,7 +316,9 @@ static void skel_receive(FAR struct skel_driver_s *priv) { /* Check for errors and update statistics */ - /* Check if the packet is a valid size for the uIP buffer configuration */ + /* Check if the packet is a valid size for the network buffer + * configuration. + */ /* Copy the data data from the hardware to priv->sk_dev.d_buf. Set * amount of data in priv->sk_dev.d_len @@ -451,7 +455,7 @@ static void skel_txdone(FAR struct skel_driver_s *priv) wd_cancel(priv->sk_txtimeout); - /* Then poll uIP for new XMIT data */ + /* Then poll the network for new XMIT data */ (void)devif_poll(&priv->sk_dev, skel_txpoll); } @@ -607,7 +611,7 @@ static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv) /* Then reset the hardware */ - /* Then poll uIP for new XMIT data */ + /* Then poll the network for new XMIT data */ (void)devif_poll(&priv->sk_dev, skel_txpoll); } @@ -713,9 +717,9 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) * the TX poll if he are unable to accept another packet for transmission. */ - /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. - * might be bug here. Does this mean if there is a transmit in progress, - * we will missing TCP time state updates? + /* If so, update TCP timing states and poll the network for new XMIT data. + * Hmmm.. might be bug here. Does this mean if there is a transmit in + * progress, we will missing TCP time state updates? */ (void)devif_timer(&priv->sk_dev, skel_txpoll, skeleton_POLLHSEC); @@ -927,7 +931,7 @@ static inline void skel_txavail_process(FAR struct skel_driver_s *priv) { /* Check if there is room in the hardware to hold another outgoing packet. */ - /* If so, then poll uIP for new XMIT data */ + /* If so, then poll the network for new XMIT data */ (void)devif_poll(&priv->sk_dev, skel_txpoll); } diff --git a/include/nuttx/net/loopback.h b/include/nuttx/net/loopback.h index 084a8d61be..e4d2f8f9f7 100644 --- a/include/nuttx/net/loopback.h +++ b/include/nuttx/net/loopback.h @@ -47,6 +47,7 @@ #include #include +#include #ifdef CONFIG_NETDEV_LOOPBACK diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index 153e749602..5f3b18e534 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -46,6 +46,7 @@ #include #include +#include #include "lib_internal.h" #include "netdb/lib_netdb.h" @@ -153,11 +154,10 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, FAR struct hostent_info_s *info; socklen_t addrlen; FAR const uint8_t *src; - FAR uint8_t *dest; + FAR char *dest; bool match; int herrnocode; int namelen; - int ret; if (lib_lo_ipv4match(addr, len, type)) { @@ -193,7 +193,7 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, info = (FAR struct hostent_info_s *)buf; - dest = (FAR uint8_t *)info->hi_data; + dest = info->hi_data; buflen -= (sizeof(struct hostent_info_s) - 1); memset(host, 0, sizeof(struct hostent)); @@ -204,7 +204,7 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, host->h_addr_list = info->hi_addrlist; host->h_length = addrlen; - ptr += addrlen; + dest += addrlen; buflen -= addrlen; /* And copy localhost host name */ @@ -216,7 +216,7 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, goto errorout_with_herrnocode; } - strncpy(ptr, g_lo_hostname, buflen); + strncpy(dest, g_lo_hostname, buflen); return 0; } diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index aa18807783..800c9b3ec1 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -51,6 +51,7 @@ #include #include +#include #include "lib_internal.h" #include "netdb/lib_dns.h" @@ -236,10 +237,9 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, { FAR struct hostent_info_s *info; socklen_t addrlen; - FAR const uint8_t *src; - FAR uint8_t *dest; + FAR const char *src; + FAR char *dest; int namelen; - int ret; if (strcmp(name, "localhost") == 0) { @@ -249,14 +249,14 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, /* Setup to transfer the IPv4 address */ addrlen = sizeof(struct in_addr); - src = (FAR uint8_t *)&g_lo_ipv4addr; + src = (FAR const char *)&g_lo_ipv4addr; host->h_addrtype = AF_INET; #else /* CONFIG_NET_IPv6 */ /* Setup to transfer the IPv6 address */ addrlen = sizeof(struct in6_addr); - src = (FAR uint8_t *)&g_lo_ipv6addr; + src = (FAR const char *)&g_lo_ipv6addr; host->h_addrtype = AF_INET6; #endif @@ -270,7 +270,7 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, } info = (FAR struct hostent_info_s *)buf; - dest = (FAR uint8_t *)info->hi_data; + dest = info->hi_data; buflen -= (sizeof(struct hostent_info_s) - 1); memset(host, 0, sizeof(struct hostent)); @@ -281,7 +281,7 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, host->h_addr_list = info->hi_addrlist; host->h_length = addrlen; - ptr += addrlen; + dest += addrlen; buflen -= addrlen; /* And copy name */ @@ -292,7 +292,7 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, return -ERANGE; } - strncpy(ptr, name, buflen); + strncpy(dest, name, buflen); return 0; } diff --git a/net/loopback/Make.defs b/net/loopback/Make.defs index 5cbdc8bf75..e7970df99b 100644 --- a/net/loopback/Make.defs +++ b/net/loopback/Make.defs @@ -1,7 +1,7 @@ ############################################################################ -# net/route/Make.defs +# net/loopback/Make.defs # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -33,16 +33,15 @@ # ############################################################################ -ifeq ($(CONFIG_NET_ROUTE),y) +ifeq ($(CONFIG_NETDEV_LOOPBACK),y) -# Routing table support +# Local loopback support -SOCK_CSRCS += net_addroute.c net_allocroute.c net_delroute.c -SOCK_CSRCS += net_foreachroute.c net_router.c netdev_router.c +NETDEV_CSRCS += lo_globals.c # Include routing table build support -DEPPATH += --dep-path route -VPATH += :route +DEPPATH += --dep-path loopback +VPATH += :loopback endif -- GitLab From 933d74e5c1ed9cfa8829d5882c9c0d6c978a266e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 13:49:12 -0600 Subject: [PATCH 067/858] Networking: With these changes, I can ping the local loopback device from the simulator --- arch | 2 +- configs | 2 +- drivers/net/Kconfig | 22 +++---------------- drivers/net/loopback.c | 33 ++++++++++++++-------------- drivers/net/skeleton.c | 16 ++++++++------ include/nuttx/net/ip.h | 6 +++++ include/nuttx/net/loopback.h | 25 +++++++++++++++++++-- include/nuttx/net/netconfig.h | 39 +++++++++++++++++++++++++++------ libc/netdb/lib_gethostbyaddrr.c | 8 +++---- libc/netdb/lib_gethostbynamer.c | 4 ++-- net/Kconfig | 34 +++++++++++++++++++++++----- net/loopback/Make.defs | 2 +- net/loopback/lo_globals.c | 4 ++-- net/loopback/loopback.h | 4 ++-- net/netdev/netdev_register.c | 6 +++-- 15 files changed, 135 insertions(+), 72 deletions(-) diff --git a/arch b/arch index c50e6b0277..1ffc0ecc02 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c50e6b0277974daf54f97105c5ad99057b0ad1aa +Subproject commit 1ffc0ecc02112a9d813dc9f95f2a8ecac4d8c6d8 diff --git a/configs b/configs index 71ee5a6c64..e1e1873700 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 71ee5a6c640704517a24c3cbbb100caeba5a78ca +Subproject commit e1e1873700ffda7aeb632e2b1234333d88ce3457 diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index ec2a65aa5c..6a3ceaffaf 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -6,8 +6,9 @@ comment "General Ethernet MAC Driver Options" config NETDEV_LOOPBACK - bool "Local loopback support" - default n + bool + default n if !NET_LOOPBACK + default y if NET_LOOPBACK select NET_NOINTS depends on EXPERIMENTAL ---help--- @@ -315,23 +316,6 @@ config NET_SLIP_DEFPRIO ---help--- Provides the priority for SLIP RX and TX threads. -config NET_SLIP_MTU - int "Packet size (MTU)" - default 296 - ---help--- - Provides the size of the SLIP packet buffers. - - The Linux slip module hard-codes its MTU size to 296 (40 bytes for - the IP+TPC headers plus 256 bytes of data). So you might as well - set CONFIG_NET_SLIP_MTU to 296 as well. - - There may be an issue with this setting, however. I see that Linux - uses a MTU of 296 and window of 256, but actually only sends 168 - bytes of data: 40 + 128. I believe that is to allow for the 2x - worst cast packet expansion. Ideally we would like to advertise the - 256 MSS, but restrict transfers to 128 bytes (possibly by modifying - the tcp_mss() macro). - config NET_SLIP_NINTERFACES int "Number of SLIP interfaces" default 1 diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 22ede3df9c..12fd3a01bb 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET) && defined(CONFIG_NETDEV_LOOBACK) +#if defined(CONFIG_NET) && defined(CONFIG_NETDEV_LOOPBACK) #include #include @@ -81,7 +81,8 @@ /* This is a helper pointer for accessing the contents of the Ethernet header */ -#define BUF ((struct eth_hdr_s *)priv->lo_dev.d_buf) +#define IPv4BUF ((FAR struct ipv4_hdr_s *)priv->lo_dev.d_buf) +#define IPv6BUF ((FAR struct ipv6_hdr_s *)priv->lo_dev.d_buf) /**************************************************************************** * Private Types @@ -121,7 +122,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv); static int lo_txpoll(FAR struct net_driver_s *dev); static inline void lo_poll(FAR struct lo_driver_s *priv); static void lo_poll_work(FAR void *arg); -static void lo_poll_expiry(int argc, uint32_t arg, ...); +static void lo_poll_expiry(int argc, wdparm_t arg, ...); /* NuttX callback functions */ @@ -169,7 +170,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv) /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 - if (BUF->type == HTONS(ETHTYPE_IP)) + if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) { nllvdbg("IPv4 frame\n"); ipv4_input(&priv->lo_dev); @@ -190,7 +191,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv) else #endif #ifdef CONFIG_NET_IPv6 - if (BUF->type == HTONS(ETHTYPE_IP6)) + if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv46VERSION) { nllvdbg("Iv6 frame\n"); ipv6_input(&priv->lo_dev); @@ -211,7 +212,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv) else #endif { - ndbg("WARNING: Unrecognized packet type dropped: %04x\n", BUF->type); + ndbg("WARNING: Unrecognized packet type dropped: %04x\n", IPv4BUF->type); } } @@ -331,7 +332,7 @@ static void lo_poll_work(FAR void *arg) * ****************************************************************************/ -static void lo_poll_expiry(int argc, uint32_t arg, ...) +static void lo_poll_expiry(int argc, wdparm_t arg, ...) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; @@ -390,7 +391,7 @@ static int lo_ifup(FAR struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, (uint32_t)priv); + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, (wdparm_t)priv); priv->lo_bifup = true; return OK; @@ -615,7 +616,7 @@ int localhost_initialize(void) priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */ priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */ #endif - priv->lo_dev.d_private = (void*)g_loopback; /* Used to recover private state from dev */ + priv->lo_dev.d_private = (void*)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmissions */ @@ -630,18 +631,18 @@ int localhost_initialize(void) /* Set the local loopback IP address */ #ifdef CONFIG_NET_IPv4 - net_ipv4addr_copy(dev->d_ipaddr, g_lo_ipv4addr); - net_ipv4addr_copy(dev->d_draddr, g_lo_ipv4addr); - net_ipv4addr_copy(dev->d_netmask, g_lo_ipv4mask); + net_ipv4addr_copy(priv->lo_dev.d_ipaddr, g_lo_ipv4addr); + net_ipv4addr_copy(priv->lo_dev.d_draddr, g_lo_ipv4addr); + net_ipv4addr_copy(priv->lo_dev.d_netmask, g_lo_ipv4mask); #endif #ifdef CONFIG_NET_IPv6 - net_ipv6addr_hdrcopy(dev->d_ipv6addr, g_lo_ipv6addr) - net_ipv6addr_hdrcopy(dev->d_ipv6draddr, g_lo_ipv6addr) - net_ipv6addr_hdrcopy(dev->d_ipv6netmask, g_ipv6_allzeroaddr) + net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr) + net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr) + net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_allzeroaddr) #endif /* Put the network in the UP state */ return lo_ifup(&priv->lo_dev); } -#endif /* CONFIG_NET && CONFIG_NETDEV_LOOBACK */ +#endif /* CONFIG_NET && CONFIG_NETDEV_LOOPBACK */ diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 9b8ed1e16c..8822073c61 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -149,13 +149,13 @@ static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv); #ifdef CONFIG_NET_NOINTS static void skel_txtimeout_work(FAR void *arg); #endif -static void skel_txtimeout_expiry(int argc, uint32_t arg, ...); +static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...); static inline void skel_poll_process(FAR struct skel_driver_s *priv); #ifdef CONFIG_NET_NOINTS static void skel_poll_work(FAR void *arg); #endif -static void skel_poll_expiry(int argc, uint32_t arg, ...); +static void skel_poll_expiry(int argc, wdparm_t arg, ...); /* NuttX callback functions */ @@ -216,7 +216,7 @@ static int skel_transmit(FAR struct skel_driver_s *priv) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ (void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT, - skel_txtimeout_expiry, 1, (uint32_t)priv); + skel_txtimeout_expiry, 1, (wdparm_t)priv); return OK; } @@ -666,7 +666,7 @@ static void skel_txtimeout_work(FAR void *arg) * ****************************************************************************/ -static void skel_txtimeout_expiry(int argc, uint32_t arg, ...) +static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...) { FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; @@ -726,7 +726,8 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) /* Setup the watchdog poll timer again */ - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, priv); + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); } /**************************************************************************** @@ -778,7 +779,7 @@ static void skel_poll_work(FAR void *arg) * ****************************************************************************/ -static void skel_poll_expiry(int argc, uint32_t arg, ...) +static void skel_poll_expiry(int argc, wdparm_t arg, ...) { FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; @@ -854,7 +855,8 @@ static int skel_ifup(FAR struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, (uint32_t)priv); + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); /* Enable the Ethernet interrupt */ diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index 59088d9059..c707b91bda 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -62,6 +62,12 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* IP Version Mask (bits 0-3 of first byte) */ + +#define IP_VERSION_MASK 0x70 +#define IPv4_VERSION 0x40 +#define IPv6_VERSION 0x60 + /* Values for the IP protocol field */ #define IP_PROTO_ICMP 1 diff --git a/include/nuttx/net/loopback.h b/include/nuttx/net/loopback.h index e4d2f8f9f7..76e8312c39 100644 --- a/include/nuttx/net/loopback.h +++ b/include/nuttx/net/loopback.h @@ -49,7 +49,7 @@ #include #include -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK /**************************************************************************** * Public Type Definitions @@ -90,10 +90,31 @@ EXTERN const net_ipv6addr_t g_lo_ipv6addr; * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Function: localhost_initialize + * + * Description: + * Initialize the Ethernet controller and driver + * + * Parameters: + * intf - In the case where there are multiple EMACs, this value + * identifies which EMAC is to be initialized. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_LOOPBACK +int localhost_initialize(void); +#endif /* CONFIG_NETDEV_LOOPBACK */ + #undef EXTERN #ifdef __cplusplus } #endif -#endif /* CONFIG_NETDEV_LOOPBACK */ +#endif /* CONFIG_NET_LOOPBACK */ #endif /* __INCLUDE_NUTTX_NET_LOOPBACK_H */ diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 8825c50981..8b182b0b82 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -136,6 +136,10 @@ # define MIN_NET_DEV_MTU _MIN_SLIP_MTU # define MAX_NET_DEV_MTU _MAX_SLIP_MTU +/* For the loopback device, we will use the largest representable MTU */ + +# define NET_LO_MTU UINT16_MAX + #elif defined(CONFIG_NET_SLIP) /* There is no link layer header with SLIP */ @@ -156,6 +160,20 @@ # define MIN_NET_DEV_MTU CONFIG_NET_ETH_MTU # define MAX_NET_DEV_MTU CONFIG_NET_ETH_MTU +#elif defined(CONFIG_NET_LOOPBACK) + /* Force the loopback MTU to some reasonable size. We could do something smarter, but + * The case where the local loopback device is the only device is very unusal. + */ + +# define NET_LO_MTU 1518 + + /* Assume standard Ethernet link layer header */ + +# define NET_LL_HDRLEN(d) 0 +# define NET_DEV_MTU(d) NET_LO_MTU +# define MIN_NET_DEV_MTU NET_LO_MTU +# define MAX_NET_DEV_MTU NET_LO_MTU + #else /* Perhaps only Unix domain sockets of the loopback device */ @@ -166,10 +184,6 @@ #endif /* MULTILINK or SLIP or ETHERNET */ -/* For the loopback device, we will use the largest representable MTU */ - -#define NET_LO_MTU UINT16_MAX - /* Layer 3/4 Configuration Options ******************************************/ /* IP configuration options */ @@ -230,9 +244,12 @@ /* If Ethernet is supported, then it will have the smaller MSS */ -#ifdef CONFIG_NET_SLIP +#if defined(CONFIG_NET_SLIP) # define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) # define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h) +#elif defined(CONFIG_NET_LOOPBACK) +# define LO_UDP_MSS(h) (NET_LO_MTU - (h)) +# define __MIN_UDP_MSS(h) LO_UDP_MSS(h) #endif #ifdef CONFIG_NET_ETHERNET @@ -354,9 +371,12 @@ /* If Ethernet is supported, then it will have the smaller MSS */ -#ifdef CONFIG_NET_SLIP +#if defined(CONFIG_NET_SLIP) # define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) # define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h) +#elif defined(CONFIG_NET_LOOPBACK) +# define LO_TCP_MSS(h) (NET_LO_MTU - (h)) +# define __MIN_TCP_MSS(h) LO_TCP_MSS(h) #endif #ifdef CONFIG_NET_ETHERNET @@ -433,11 +453,16 @@ # define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO -#else /* if defined(CONFIG_NET_ETHERNET) */ +#elif defined(CONFIG_NET_ETHERNET) /* Only Ethernet.. use the configured SLIP receive window size */ # define NET_DEV_RCVWNDO(d) CONFIG_NET_ETH_TCP_RECVWNDO +#else /* if defined(CONFIG_NET_LOOPBACK) */ + /* Only loal loopback.. use the fixed loopback receive window size */ + +# define NET_DEV_RCVWNDO(d) NET_LO_TCP_RECVWNDO + #endif /* MULTILINK or SLIP or ETHERNET */ /* How long a connection should stay in the TIME_WAIT state. diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index 5f3b18e534..defc4d2162 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -74,7 +74,7 @@ * ****************************************************************************/ -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK static bool lib_lo_ipv4match(FAR const void *addr, socklen_t len, int type) { FAR struct in_addr *ipv4addr; @@ -108,7 +108,7 @@ static bool lib_lo_ipv4match(FAR const void *addr, socklen_t len, int type) * ****************************************************************************/ -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type) { FAR struct in_addr6 *ipv6addr; @@ -146,7 +146,7 @@ static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type) * ****************************************************************************/ -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK static int lib_localhost(FAR const void *addr, socklen_t len, int type, FAR struct hostent *host, FAR char *buf, size_t buflen, int *h_errnop) @@ -395,7 +395,7 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, *h_errnop = 0; } -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback address */ if (lib_localhost(addr, len, type, host, but, buflen, h_errnop) == 0) diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 800c9b3ec1..6ae638ead2 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -231,7 +231,7 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, * ****************************************************************************/ -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK static int lib_localhost(FAR const char *name, FAR struct hostent *host, FAR char *buf, size_t buflen) { @@ -740,7 +740,7 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host, return OK; } -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback host name */ if (lib_localhost(name, host, buf, buflen) == 0) diff --git a/net/Kconfig b/net/Kconfig index a6597e064d..42aa5c27a8 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -85,12 +85,25 @@ config NET_SLIP_MTU depends on NET_SLIP range 296 1518 ---help--- - Packet buffer size. This size includes the TCP/UDP payload plus the - size of TCP/UDP header and the IP header. This value is normally - referred to as the MTU (Maximum Transmission Unit); the payload - payload is the MSS (Maximum Segment Size). SLIP is required to - support at lest 256+20+20 = 296. Values other than 296 are not - recommended. + Provides the size of the SLIP packet buffers. This size includes + the TCP/UDP payload plus the size of TCP/UDP header and the IP header. + This value is normally referred to as the MTU (Maximum Transmission Unit); + the payload payload is the MSS (Maximum Segment Size). + + SLIP is required to support at lest 256+20+20 = 296. Values other than + 296 are not recommended. + + The Linux slip module hard-codes its MTU size to 296 (40 bytes for + the IP+TPC headers plus 256 bytes of data). So you might as well + set CONFIG_NET_SLIP_MTU to 296 as well. + + There may be an issue with this setting, however. I see that Linux + uses a MTU of 296 and window of 256, but actually only sends 168 + bytes of data: 40 + 128. I believe that is to allow for the 2x + worst cast packet expansion. Ideally we would like to advertise the + 256 MSS, but restrict transfers to 128 bytes (possibly by modifying + the tcp_mss() macro). + config NET_SLIP_TCP_RECVWNDO int "SLIP TCP receive window size" @@ -150,6 +163,15 @@ config NET_ETHERNET no need to define anything special in the configuration file to use Ethernet -- it is the default). +config NET_LOOPBACK + bool "Local loopback" + default n + depends on EXPERIMENTAL + ---help--- + Add support for the local network loopback device, lo. Any additional + networking devices that are enabled must be compatible with + CONFIG_NET_NOINTS. + config NET_SLIP bool "SLIP support" default n diff --git a/net/loopback/Make.defs b/net/loopback/Make.defs index e7970df99b..097be782f9 100644 --- a/net/loopback/Make.defs +++ b/net/loopback/Make.defs @@ -33,7 +33,7 @@ # ############################################################################ -ifeq ($(CONFIG_NETDEV_LOOPBACK),y) +ifeq ($(CONFIG_NET_LOOPBACK),y) # Local loopback support diff --git a/net/loopback/lo_globals.c b/net/loopback/lo_globals.c index 55d273c566..270fdb0b91 100644 --- a/net/loopback/lo_globals.c +++ b/net/loopback/lo_globals.c @@ -43,7 +43,7 @@ #include "loopback/loopback.h" -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK /**************************************************************************** * Public Data @@ -67,4 +67,4 @@ const net_ipv6addr_t g_lo_ipv6addr = * Public Functions ****************************************************************************/ -#endif /* CONFIG_NETDEV_LOOPBACK */ +#endif /* CONFIG_NET_LOOPBACK */ diff --git a/net/loopback/loopback.h b/net/loopback/loopback.h index 082e6ccb68..8529fdbd1c 100644 --- a/net/loopback/loopback.h +++ b/net/loopback/loopback.h @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK /**************************************************************************** * Pre-processor Definitions @@ -68,5 +68,5 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -#endif /* CONFIG_NETDEV_LOOPBACK */ +#endif /* CONFIG_NET_LOOPBACK */ #endif /* __NET_LOOPBACK_LOOBACK_H */ diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 0b09bac0d7..362e5a44a2 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -68,8 +68,10 @@ #if defined(CONFIG_NET_SLIP) # define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT -#else /* if defined(CONFIG_NET_ETHERNET) */ +#elif defined(CONFIG_NET_ETHERNET) # define NETDEV_DEFAULT_FORMAT NETDEV_ETH_FORMAT +#else /* if defined(CONFIG_NET_LOOPBACK) */ +# define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT #endif /**************************************************************************** @@ -191,7 +193,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) switch (lltype) { -#ifdef CONFIG_NETDEV_LOOPBACK +#ifdef CONFIG_NET_LOOPBACK case NET_LL_LOOPBACK: /* Local loopback */ dev->d_llhdrlen = 0; dev->d_mtu = NET_LO_MTU; -- GitLab From 3c5f8175136d6c2938e8500649dd280f76316e13 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 13:58:57 -0600 Subject: [PATCH 068/858] Networking: Local loopback is basically functional and is no longer EXPERIMENTAL --- drivers/net/Kconfig | 1 - net/Kconfig | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 6a3ceaffaf..c28f600521 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -10,7 +10,6 @@ config NETDEV_LOOPBACK default n if !NET_LOOPBACK default y if NET_LOOPBACK select NET_NOINTS - depends on EXPERIMENTAL ---help--- Add support for the local network loopback device, lo. Any additional networking devices that are enabled must be compatible with diff --git a/net/Kconfig b/net/Kconfig index 42aa5c27a8..235eb9a579 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -166,7 +166,6 @@ config NET_ETHERNET config NET_LOOPBACK bool "Local loopback" default n - depends on EXPERIMENTAL ---help--- Add support for the local network loopback device, lo. Any additional networking devices that are enabled must be compatible with -- GitLab From d99e217906d961ebfde3a3a2e95a1e7d63c754a6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 14:26:12 -0600 Subject: [PATCH 069/858] Urefresh submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 1ffc0ecc02..575acae66e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1ffc0ecc02112a9d813dc9f95f2a8ecac4d8c6d8 +Subproject commit 575acae66e3ada04a55da640ba61b3ea482babdb -- GitLab From 4d040d572a4bb3c564d53c2be2f0b8bab72894b6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 15:16:03 -0600 Subject: [PATCH 070/858] Networking: Eliminate recursion from the local loopback driver --- arch | 2 +- drivers/net/loopback.c | 42 ++++++++++++------------------------------ 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/arch b/arch index 575acae66e..5336c64638 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 575acae66e3ada04a55da640ba61b3ea482babdb +Subproject commit 5336c646386607424e3426fb488d73241abb5f08 diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 12fd3a01bb..6d4dbe5762 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -161,53 +161,35 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static void lo_loopback(FAR struct lo_driver_s *priv) { + /* Loop while there is data "sent", i.e., while d_len > 0. That should be + * the case upon entry here and while the processing of the IPv4/6 packet + * generates a new packet to be sent. Sending, of course, just means + * relaying back through the network for this driver. + */ + + while (priv->lo_dev.d_len > 0) + { #ifdef CONFIG_NET_PKT - /* When packet sockets are enabled, feed the frame into the packet tap */ + /* When packet sockets are enabled, feed the frame into the packet tap */ - pkt_input(&priv->lo_dev); + pkt_input(&priv->lo_dev); #endif - /* We only accept IP packets of the configured type and ARP packets */ + /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) { nllvdbg("IPv4 frame\n"); ipv4_input(&priv->lo_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (priv->lo_dev.d_len > 0) - { - /* Loop the packet back to the network. - * REVISIST: The must be a limit to the depth of recursion. - */ - - lo_loopback(priv); - } } else #endif #ifdef CONFIG_NET_IPv6 - if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv46VERSION) + if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION) { nllvdbg("Iv6 frame\n"); ipv6_input(&priv->lo_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (priv->lo_dev.d_len > 0) - { - /* Loop the packet back to the netork - * REVISIST: The must be a limit to the depth of recursion. - */ - - lo_loopback(priv); - } } else #endif -- GitLab From eea69cf6e3da6c6f31caa6917f621f3f39291158 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 15:23:09 -0600 Subject: [PATCH 071/858] Networking: Local loopback, fix a error in last commit + fix a bad functional partitioning --- drivers/net/loopback.c | 67 +++++++++++++----------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 6d4dbe5762..8f54c2f593 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -120,7 +120,6 @@ static void lo_loopback(FAR struct lo_driver_s *priv); /* Polling logic */ static int lo_txpoll(FAR struct net_driver_s *dev); -static inline void lo_poll(FAR struct lo_driver_s *priv); static void lo_poll_work(FAR void *arg); static void lo_poll_expiry(int argc, wdparm_t arg, ...); @@ -178,23 +177,25 @@ static void lo_loopback(FAR struct lo_driver_s *priv) /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 - if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) - { - nllvdbg("IPv4 frame\n"); - ipv4_input(&priv->lo_dev); - } - else + if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) + { + nllvdbg("IPv4 frame\n"); + ipv4_input(&priv->lo_dev); + } + else #endif #ifdef CONFIG_NET_IPv6 - if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION) - { - nllvdbg("Iv6 frame\n"); - ipv6_input(&priv->lo_dev); - } - else + if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION) + { + nllvdbg("Iv6 frame\n"); + ipv6_input(&priv->lo_dev); + } + else #endif - { - ndbg("WARNING: Unrecognized packet type dropped: %04x\n", IPv4BUF->type); + { + ndbg("WARNING: Unrecognized packet type dropped: %04x\n", IPv4BUF->type); + priv->lo_dev.d_len = 0; + } } } @@ -237,34 +238,6 @@ static int lo_txpoll(FAR struct net_driver_s *dev) return 0; } -/**************************************************************************** - * Function: lo_poll - * - * Description: - * Perform the periodic poll. This may be called either from watchdog - * timer logic or from the worker thread, depending upon the configuration. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static inline void lo_poll(FAR struct lo_driver_s *priv) -{ - /* Perform the poll */ - - (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); - - /* Setup the watchdog poll timer again */ - - (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); -} - /**************************************************************************** * Function: lo_poll_work * @@ -282,7 +255,6 @@ static inline void lo_poll(FAR struct lo_driver_s *priv) * ****************************************************************************/ -#ifdef CONFIG_NET_NOINTS static void lo_poll_work(FAR void *arg) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; @@ -291,10 +263,13 @@ static void lo_poll_work(FAR void *arg) /* Perform the poll */ state = net_lock(); - lo_poll(priv); + (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); net_unlock(state); } -#endif /**************************************************************************** * Function: lo_poll_expiry -- GitLab From 6158086dd4dd47d20402b3f87e67a09be373995c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 15:41:45 -0600 Subject: [PATCH 072/858] Update some comments --- Documentation | 2 +- libc/netdb/lib_gethostbyaddrr.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation b/Documentation index cae6e67e05..8a30728ae9 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit cae6e67e0534485cd42119346a2e0121d6652965 +Subproject commit 8a30728ae9a64496f0c9a0ff5dd62bd3b022c145 diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index defc4d2162..06f5833cf4 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -406,6 +406,15 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, } #endif + /* TODO: + * + * 1. Look in the DNS cache to see if we have the address mapping already + * in place. If not, + * 2. Perform a reverse DNS lookup. And if that fails as well, then + * finally + * 3. Search the hosts file for a match. + */ + /* Search the hosts file for a match */ return lib_hostfile_lookup(addr, len, type, host, but, buflen, h_errnop); -- GitLab From 9d5a86753eeadb33176a256ad200637125227189 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 15:52:14 -0600 Subject: [PATCH 073/858] Update TODO list --- TODO | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index b717d54c74..55324a46f8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 11, 2015) +NuttX TODO List (Last updated August 24, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -9,7 +9,7 @@ issues reated to each board port. nuttx/ - (12) Task/Scheduler (sched/) + (13) Task/Scheduler (sched/) (1) Memory Management (mm/) (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) @@ -213,6 +213,31 @@ o Task/Scheduler (sched/) Status: Open Priority: Medium-ish + Title: SCALABILITY + Description: Task control information is retained in simple lists. This + is completely appropriate for small embedded systems where + the number of tasks, N, is relatively small. Most list + operations are O(N). This could become as issue if N gets + very large. + + In that case, these simple lists should be replaced with + something more performant such as a balanced tree in the + case of ordered lists. Fortunately, most internal lists are + hidden behind simple accessor functions and so the internal + data structures can be changed if need with very little impact. + + The only area are the list structure is not well contained is + in the sequence of code that finds the current running task: + + FAR struct tcb_s *rtcb = (FAT struc tcb_s *)g_readytorun.head; + + That needs to be hidden behind a macro (it would also be a problem + for any SMP implementation). + + Status: Open + Priority: Low. Things are just the way that we want them for the way + that NuttX is used today. + o Memory Managment (mm/) ^^^^^^^^^^^^^^^^^^^^^^ -- GitLab From 3018dc31e56facf6244adb5a46ee60890b091366 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 16:08:17 -0600 Subject: [PATCH 074/858] Network local loopback: Another structural simplication --- drivers/net/loopback.c | 102 +++++++++-------------------------------- drivers/net/skeleton.c | 18 ++++---- 2 files changed, 29 insertions(+), 91 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 8f54c2f593..186e6a906a 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -113,10 +113,6 @@ static struct lo_driver_s g_loopback; * Private Function Prototypes ****************************************************************************/ -/* Loop back logic */ - -static void lo_loopback(FAR struct lo_driver_s *priv); - /* Polling logic */ static int lo_txpoll(FAR struct net_driver_s *dev); @@ -127,7 +123,6 @@ static void lo_poll_expiry(int argc, wdparm_t arg, ...); static int lo_ifup(FAR struct net_driver_s *dev); static int lo_ifdown(FAR struct net_driver_s *dev); -static inline void lo_txavail_process(FAR struct lo_driver_s *priv); static void lo_txavail_work(FAR void *arg); static int lo_txavail(FAR struct net_driver_s *dev); #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) @@ -142,24 +137,29 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); ****************************************************************************/ /**************************************************************************** - * Function: lo_loopback + * Function: lo_txpoll * * Description: - * An interrupt was received indicating the availability of a new RX packet + * Check if the network has any outgoing packets ready to send. This is + * a callback from devif_poll(). devif_poll() will be called only during + * normal TX polling. * * Parameters: - * priv - Reference to the driver state structure + * dev - Reference to the NuttX driver state structure * * Returned Value: - * None + * OK on success; a negated errno on failure * * Assumptions: - * Global interrupts are disabled by interrupt handling logic. + * May or may not be called from an interrupt handler. In either case, + * the network is locked. * ****************************************************************************/ -static void lo_loopback(FAR struct lo_driver_s *priv) +static int lo_txpoll(FAR struct net_driver_s *dev) { + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + /* Loop while there is data "sent", i.e., while d_len > 0. That should be * the case upon entry here and while the processing of the IPv4/6 packet * generates a new packet to be sent. Sending, of course, just means @@ -197,43 +197,6 @@ static void lo_loopback(FAR struct lo_driver_s *priv) priv->lo_dev.d_len = 0; } } -} - -/**************************************************************************** - * Function: lo_txpoll - * - * Description: - * Check if the network has any outgoing packets ready to send. This is - * a callback from devif_poll(). devif_poll() will be called only during - * normal TX polling. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * OK on success; a negated errno on failure - * - * Assumptions: - * May or may not be called from an interrupt handler. In either case, - * global interrupts are disabled, either explicitly or indirectly through - * interrupt handling logic. - * - ****************************************************************************/ - -static int lo_txpoll(FAR struct net_driver_s *dev) -{ - FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; - - /* Check if the polling resulted in data that should be sent, i.e., tht - * the field d_len is set to a value > 0. - */ - - if (priv->lo_dev.d_len > 0) - { - /* Loop the packet back to the host */ - - lo_loopback(priv); - } return 0; } @@ -251,7 +214,7 @@ static int lo_txpoll(FAR struct net_driver_s *dev) * OK on success * * Assumptions: - * Ethernet interrupts are disabled + * The network is locked * ****************************************************************************/ @@ -285,7 +248,7 @@ static void lo_poll_work(FAR void *arg) * None * * Assumptions: - * Global interrupts are disabled by the watchdog logic. + * The network is locked. * ****************************************************************************/ @@ -384,35 +347,6 @@ static int lo_ifdown(FAR struct net_driver_s *dev) return OK; } -/**************************************************************************** - * Function: lo_txavail_process - * - * Description: - * Perform an out-of-cycle poll. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * Called in normal user mode - * - ****************************************************************************/ - -static inline void lo_txavail_process(FAR struct lo_driver_s *priv) -{ - /* Ignore the notification if the interface is not yet up */ - - if (priv->lo_bifup) - { - /* If so, then poll the network for new XMIT data */ - - (void)devif_poll(&priv->lo_dev, lo_txpoll); - } -} - /**************************************************************************** * Function: lo_txavail_work * @@ -435,10 +369,16 @@ static void lo_txavail_work(FAR void *arg) FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; net_lock_t state; - /* Perform the poll */ + /* Ignore the notification if the interface is not yet up */ state = net_lock(); - lo_txavail_process(priv); + if (priv->lo_bifup) + { + /* If so, then poll the network for new XMIT data */ + + (void)devif_poll(&priv->lo_dev, lo_txpoll); + } + net_unlock(state); } diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 8822073c61..949ace1938 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -195,8 +195,7 @@ static void skel_ipv6multicast(FAR struct skel_driver_s *priv); * * Assumptions: * May or may not be called from an interrupt handler. In either case, - * global interrupts are disabled, either explicitly or indirectly through - * interrupt handling logic. + * the network is locked. * ****************************************************************************/ @@ -240,8 +239,7 @@ static int skel_transmit(FAR struct skel_driver_s *priv) * * Assumptions: * May or may not be called from an interrupt handler. In either case, - * global interrupts are disabled, either explicitly or indirectly through - * interrupt handling logic. + * the network is locked. * ****************************************************************************/ @@ -306,7 +304,7 @@ static int skel_txpoll(FAR struct net_driver_s *dev) * None * * Assumptions: - * Global interrupts are disabled by interrupt handling logic. + * The network is locked. * ****************************************************************************/ @@ -441,7 +439,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) * None * * Assumptions: - * Global interrupts are disabled by the watchdog logic. + * The network is locked. * ****************************************************************************/ @@ -474,7 +472,7 @@ static void skel_txdone(FAR struct skel_driver_s *priv) * None * * Assumptions: - * Ethernet interrupts are disabled + * The network is locked. * ****************************************************************************/ @@ -509,7 +507,7 @@ static inline void skel_interrupt_process(FAR struct skel_driver_s *priv) * OK on success * * Assumptions: - * Ethernet interrupts are disabled + * The network is locked. * ****************************************************************************/ @@ -629,7 +627,7 @@ static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv) * OK on success * * Assumptions: - * Ethernet interrupts are disabled + * The network is locked. * ****************************************************************************/ @@ -743,7 +741,7 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) * OK on success * * Assumptions: - * Ethernet interrupts are disabled + * The network is locked. * ****************************************************************************/ -- GitLab From a2c00680113be8e2e1f98a292ebbbd71f685d18b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 17:27:38 -0600 Subject: [PATCH 075/858] Fix some IPv6 loopback device problems --- drivers/net/loopback.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 186e6a906a..fb208ad259 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -533,9 +533,9 @@ int localhost_initialize(void) net_ipv4addr_copy(priv->lo_dev.d_netmask, g_lo_ipv4mask); #endif #ifdef CONFIG_NET_IPv6 - net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr) - net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr) - net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_allzeroaddr) + net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr); + net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr); + net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_alloneaddr); #endif /* Put the network in the UP state */ -- GitLab From 79aa3d40b037a3b3a1f06105b2ba66a667f9753a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Aug 2015 06:51:15 -0600 Subject: [PATCH 076/858] Kconfig: CONFIG_NET_MULTILINK and CONFIG_NET_MULTINIC must be support if the loopback device and any real network device are selected --- drivers/net/loopback.c | 2 +- net/Kconfig | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index fb208ad259..5e2a12d1e3 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -193,7 +193,7 @@ static int lo_txpoll(FAR struct net_driver_s *dev) else #endif { - ndbg("WARNING: Unrecognized packet type dropped: %04x\n", IPv4BUF->type); + ndbg("WARNING: Unrecognized packet type dropped: %02x\n", IPv4BUF->vhl); priv->lo_dev.d_len = 0; } } diff --git a/net/Kconfig b/net/Kconfig index 235eb9a579..f7e5f67cfa 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -156,8 +156,8 @@ config NET_ETHERNET bool "Ethernet support" default y if !NET_SLIP default n if NET_SLIP - select NETDEV_MULTINIC if NET_SLIP - select NET_MULTILINK if NET_SLIP + select NETDEV_MULTINIC if NET_LOOPBACK || NET_SLIP || NET_TUN + select NET_MULTILINK if NET_LOOPBACK || NET_SLIP || NET_TUN ---help--- If NET_SLIP is not selected, then Ethernet will be used (there is no need to define anything special in the configuration file to use @@ -166,6 +166,8 @@ config NET_ETHERNET config NET_LOOPBACK bool "Local loopback" default n + select NETDEV_MULTINIC if NET_ETHERNET || NET_SLIP || NET_TUN + select NET_MULTILINK if NET_ETHERNET || NET_SLIP || NET_TUN ---help--- Add support for the local network loopback device, lo. Any additional networking devices that are enabled must be compatible with @@ -174,8 +176,8 @@ config NET_LOOPBACK config NET_SLIP bool "SLIP support" default n - select NETDEV_MULTINIC if NET_ETHERNET - select NET_MULTILINK if NET_ETHERNET + select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_TUN + select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_TUN ---help--- Enables building of the SLIP driver. SLIP requires at least one IP protocol selected and the following additional @@ -222,6 +224,8 @@ endif # NET_SLIP config NET_TUN bool "TUN Virtual Network Device support" default n + select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_SLIP + select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_SLIP if NET_TUN -- GitLab From e983e547e142b670d79273ca5ff27e6d3c8fa2e3 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Tue, 25 Aug 2015 07:15:21 -0600 Subject: [PATCH 077/858] Networking: Correct return value from psock_tcp_accept(). From SaeHie Park --- ChangeLog | 3 +++ net/tcp/tcp_accept.c | 19 +++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a1244b08a..377f2b110a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10879,3 +10879,6 @@ for the local loopback device (2015-08-24). * drivers/net/loopback.c: Add basic prototype of a local loopback device (2015-08-24). + * networking: Correct return value from psock_tcp_accept(). From + SaeHie Park (2015-08-25). + diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 9597b6b36b..0a92e3327e 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -238,7 +238,6 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, { FAR struct tcp_conn_s *conn; struct accept_s state; - int err = OK; int ret; DEBUGASSERT(psock && newconn); @@ -267,8 +266,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, else if (_SS_ISNONBLOCK(psock->s_flags)) { - err = EAGAIN; - goto errout; + return -EAGAIN; } else #endif @@ -314,7 +312,8 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, * altered by intervening operations. */ - err = get_errno(); + ret = -get_errno(); + DEBUGASSERT(ret < 0); } /* Make sure that no further interrupts are processed */ @@ -334,27 +333,23 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, if (state.acpt_result != 0) { - err = state.acpt_result; - goto errout; + DEBUGASSERT(state.acpt_result > 0); + return -state.acpt_result; } /* If net_lockedwait failed, then we were probably reawakened by a - * signal. In this case, logic above will have set 'err' to the + * signal. In this case, logic above will have set 'ret' to the * errno value returned by net_lockedwait(). */ if (ret < 0) { - goto errout; + return ret; } } *newconn = (FAR void *)state.acpt_newconn; return OK; - -errout: - set_errno(err); - return ERROR; } #endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS && CONFIG_NET_TCP */ -- GitLab From 94ecf7ebada051474897e7fe4aa6b6164caf17a8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Aug 2015 09:10:12 -0600 Subject: [PATCH 078/858] drivers/mtd/st25fl1.c: Add a driver for ST25FL1*K QuadSPI FLASH parts --- ChangeLog | 2 + drivers/mtd/Make.defs | 4 + drivers/mtd/st25fl1.c | 935 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 941 insertions(+) create mode 100644 drivers/mtd/st25fl1.c diff --git a/ChangeLog b/ChangeLog index 377f2b110a..d67d91d1b4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10881,4 +10881,6 @@ device (2015-08-24). * networking: Correct return value from psock_tcp_accept(). From SaeHie Park (2015-08-25). + * drivers/mtd/st25fl1.c: Add a driver for ST25L1*K QuadSPI parts + (2015-08-15). diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs index ff1b899d99..afbe4bd0e0 100644 --- a/drivers/mtd/Make.defs +++ b/drivers/mtd/Make.defs @@ -92,6 +92,10 @@ ifeq ($(CONFIG_MTD_AT25),y) CSRCS += at25.c endif +ifeq ($(CONFIG_MTD_ST25FL1),y) +CSRCS += st25fl1.c +endif + ifeq ($(CONFIG_MTD_SMART),y) ifeq ($(CONFIG_FS_SMARTFS),y) CSRCS += smart.c diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c new file mode 100644 index 0000000000..d61026fe52 --- /dev/null +++ b/drivers/mtd/st25fl1.c @@ -0,0 +1,935 @@ +/************************************************************************************ + * drivers/mtd/st25fl1.c + * Driver for QuadSPI-based S25FL116K, S25FL132K, and S25L164K + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ +/* QuadSPI Mode */ + +#ifndef CONFIG_ST25FL1_SPIMODE +# define CONFIG_ST25FL1_SPIMODE SPIDEV_MODE0 +#endif + +/* QuadSPI Frequency. May be up to 25MHz. */ + +#ifndef CONFIG_ST25FL1_SPIFREQUENCY +# define CONFIG_ST25FL1_SPIFREQUENCY 20000000 +#endif + +/* ST25FL1 Commands *****************************************************************/ +/* Configuration, Status, Erase, Program Commands ***********************************/ +/* Command Value Description: */ +/* Data sequence */ +#define ST25FL1_READ_STATUS1 0x05 /* Read status register 1: * + * 0x05 | SR1 */ +#define ST25FL1_READ_STATUS2 0x35 /* Read status register 2: * + * 0x35 | SR2 */ +#define ST25FL1_READ_STATUS3 0x33 /* Read status register 3: * + * 0x33 | SR3 */ +#define ST25FL1_WRITE_ENABLE 0x06 /* Write enable: * + * 0x06 */ +#define ST25FL1_VWRITE_ENABLE 0x50 /* Write enable for volatile status: * + * 0x50 */ +#define ST25FL1_WRITE_DISABLE 0x04 /* Write disable command code: * + * 0x04 */ +#define ST25FL1_WRITE_STATUS 0x01 /* Write status register: * + * 0x01 | SR1 | SR2 | SR3 */ +#define ST25FL1_WRAP_ENABLE 0x77 /* Set Burst with Wrap: * + * 0x77 | xx | xx | xx | SR3 */ +#define ST25FL1_UNPROTECT_SECTOR 0x39 /* Set Block / Pointer Protection: * + * 0x39 | ADDR(MS) | ADDR(MID) | xx */ +#define ST25FL1_PAGE_PROGRAM 0x02 /* Page Program: * + * 0x02 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | data */ +#define ST25FL1_SECTOR_ERASE 0x20 /* Sector Erase (4 kB) * + * 0x02 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) */ +#define ST25FL1_BLOCK_ERASE 0xd8 /* Block Erase (64 kB): * + * 0x02 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) */ +#define ST25FL1_CHIP_ERASE_1 0x60 /* Chip Erase 1: * + * 0x60 */ +#define ST25FL1_CHIP_ERASE_2 0xc7 /* Chip Erase 2: * + * 0xc7 */ +#define ST25FL1_ERASE_PROG_SUSPEND 0x75 /* Erase / Program Suspend: * + * 0x75 */ +#define ST25FL1_ERASE_PROG_RESUME 0x7a /* Erase / Program Resume: * + * 0x7a */ + +/* Read Commands ********************************************************************/ +/* Command Value Description: */ +/* Data sequence */ +#define ST25FL1_READ_DATA 0x03 /* Read Data: * + * 0x03 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | data... */ +#define ST25FL1_FAST_READ 0x0b /* Fast Read: * + * 0x0b | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | dummy | data... */ +#define ST25FL1_FAST_READ_DUAL 0x3b /* Fast Read Dual Output: * + * 0x3b | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | dummy | data... */ +#define ST25FL1_FAST_READ_QUAD 0x6b /* Fast Read Dual Output: * + * 0x6b | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | dummy | data... */ +#define ST25FL1_FAST_READ_DUALIO 0xbb /* Fast Read Dual I/O: * + * 0xbb | ADDR(MS) | ADDR(LS) | data... */ +#define ST25FL1_FAST_READ_QUADIO 0xeb /* Fast Read Quad I/O: * + * 0xeb | ADDR | data... */ +#define ST25FL1_CONT_READ_RESET 0xff /* Continuous Read Mode Reset: * + * 0xff | 0xff */ + +/* Reset Commands *******************************************************************/ +/* Command Value Description: */ +/* Data sequence */ +#define ST25FL1_SOFT_RESET_ENABLE 0x66 /* Software Reset Enable: * + * 0x66 */ +#define ST25FL1_SOFT_RESET 0x99 /* Software Reset: * + * 0x99 */ + /* Continuous Read Mode Reset: * + * 0xff | 0xff */ + +/* ID/Security Commands *************************&***********************************/ +/* Command Value Description: */ +/* Data sequence */ +#define ST25FL1_DEEP_PWRDOWN 0xb9 /* Deep Power-down: * + * 0xb9 */ +#define ST25FL1_RELEASE_PWRDOWN 0xab /* Release Power down / Device ID: * + * 0xab | dummy | dummy | dummy | * + * DeviceID */ +#define ST25FL1_MANUFACTURER 0x90 /* Manufacturer / Device ID: * + * 0x90 | dummy | dummy | 0x00 | * + * Manufacturer | DeviceID */ +#define ST25FL1_JEDEC_ID 0x9f /* JEDEC ID: * + * 0x9f | Manufacturer | MemoryType | * + * Capacity */ +#define ST25FL1_READ_SFDP 0x5a /* Read SFDP Register / Read Unique ID * + * Number: * + * 0x5a | 0x00 | 0x00 | ADDR | dummy | * + * data... */ +#define ST25FL1_READ_SECURITY 0x48 /* Read Security Registers: * + * 0x48 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | dummy | data... */ +#define ST25FL1_ERASE_SECURITY 0x44 /* Erase Security Registers: * + * 0x48 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) */ +#define ST25FL1_PROgRAM_SECURITY 0x42 /* Program Security Registers: * + * 0x42 | ADDR(MS) | ADDR(MID) | * + * ADDR(LS) | data... */ + +/* Flash Manufacturer JEDEC IDs */ + +#define ST25FL1_JEDEC_ID_ATMEL 0x1f +#define ST25FL1_JEDEC_ID_ST 0x20 +#define ST25FL1_JEDEC_ID_SST 0xbf +#define ST25FL1_JEDEC_ID_MACRONIX 0xc2 +#define ST25FL1_JEDEC_ID_WINBOND 0xef + +/* ST25FL1 Registers ****************************************************************/ +/* Status register bit definitions */ + +#define STATUS1_BUSY_MASK (1 << 0) /* Bit 0: Device ready/busy status */ +# define STATUS1_READY (0 << 0) /* 0 = Not Busy */ +# define STATUS1_BUSY (1 << 0) /* 1 = Busy */ +#define STATUS1_WEL_MASK (1 << 1) /* Bit 1: Write enable latch status */ +# define STATUS1_WEL_DISABLED (0 << 1) /* 0 = Not Write Enabled */ +# define STATUS1_WEL_ENABLED (1 << 1) /* 1 = Write Enabled */ +#define STATUS1_BP_SHIFT (2) /* Bits 2-4: Block protect bits */ +#define STATUS1_BP_MASK (7 << STATUS1_BP_SHIFT) +# define STATUS1_BP_NONE (0 << STATUS1_BP_SHIFT) +# define STATUS1_BP_ALL (7 << STATUS1_BP_SHIFT) +#define STATUS1_TB_MASK (1 << 5) /* Bit 5: Top / Bottom Protect */ +# define STATUS1_TB_TOP (0 << 5) /* 0 = BP2-BP0 protect Top down */ +# define STATUS1_TB_BOTTOM (1 << 5) /* 1 = BP2-BP0 protect Bottom up */ +#define STATUS1_SEC_MASK (1 << 6) /* Bit 6: Sector / Block Protect */ +# define STATUS1_SEC_BLOCK (0 << 6) /* 0 = BP2-BP0 protect 64-kB blocks */ +# define STATUS1_SEC_BLOCK (1 << 6) /* 1 = BP2-BP0 protect 4-kB sectors */ +#define STATUS1_SRP0_MASK (1 << 7) /* Bit 7: Status register protect 0 */ +# define STATUS1_SRP0_UNLOCKED (0 << 7) /* 0 = WP# no effect / PS Lock Down */ +# define STATUS1_SRP0_LOCKED (1 << 7) /* 1 = WP# protect / OTP Lock Down */ + +#define STATUS2_SRP1_MASK (1 << 0) /* Bit 0: Status register protect 1 */ +# define STATUS2_SRP1_UNLOCKED (0 << 0) /* 0 = WP# no effect / PS Lock Down */ +# define STATUS2_SRP1_LOCKED (1 << 0) /* 1 = WP# protect / OTP Lock Down */ +#define STATUS2_QUAD_ENABLE_MASK (1 << 1) /* Bit 1: Quad Enable */ +# define STATUS2_QUAD_DISABLE (0 << 1) /* 0 = Quad Mode Not Enabled */ +# define STATUS2_QUAD_ENABLE (1 << 1) /* 1 = Quad Mode Enabled */ +#define STATUS2_LB_SHIFT (2) /* Bits 2-5: Security Register Lock */ +#define STATUS2_LB_MASK (15 << STATUS2_LB_SHIFT) +# define STATUS2_LB_NONE (0 << STATUS2_LB_SHIFT) +# define STATUS2_LB_ALL (15 << STATUS2_LB_SHIFT) +#define STATUS2_CMP_MASK (1 << 6) /* Bit 6: Complement Protect */ +# define STATUS2_CMP_NORMAL (0 << 6) /* 0 = Normal Protection Map */ +# define STATUS2_CMP_INVERTED (1 << 6) /* 1 = Inverted Protection Map */ +#define STATUS2_SUS_MASK (1 << 7) /* Bit 7: Suspend Status */ +# define STATUS2_SUS_NONE (0 << 7) /* 0 = Erase / Program not suspended */ +# define STATUS2_SUS_SUSPENDED (1 << 7) /* 1 = Erase / Program suspended */ + +#define STATUS3_LC_SHIFT (0) /* Bits 0-3: Latency control */ +#define STATUS3_LC_MASK (15 << STATUS3_LC_SHIFT) +#define STATUS3_W4_MASK (1 << 4) /* Bit 4: Burst Wrap Enable */ +# define STATUS3_W4_DISABLED (0 << 4) /* 0 = Wrap Enabled */ +# define STATUS3_W4_ENABLED (1 << 4) /* 1 = Wrap Disabled */ +#define STATUS3_W56_SHIFT (5) /* Bits 5-6: Burst Wrap Length */ +#define STATUS3_W56_MASK (3 << STATUS3_W56_SHIFT) +# define STATUS3_W56_8BYTE (0 << STATUS3_W56_SHIFT) +# define STATUS3_W56_16BYTE (1 << STATUS3_W56_SHIFT) +# define STATUS3_W56_32BYTE (2 << STATUS3_W56_SHIFT) +# define STATUS3_W56_63BYTE (3 << STATUS3_W56_SHIFT) + /* Bit 7: Reserved */ + + +/* Chip Geometries ******************************************************************/ +/* All members of the family support uniform 4K-byte sectors */ + +#define S25FL116K_SECTOR_SIZE (4*1024) +#define S25FL116K_SECTOR_COUNT (512) + +#define S25FL132K_SECTOR_SIZE (4*1024) +#define S25FL132K_SECTOR_COUNT (1024) + +#define S25FL164K_SECTOR_SIZE (4*1024) +#define S25FL164K_SECTOR_COUNT (2048) + +/* Cache flags **********************************************************************/ + +#define ST25FL1_CACHE_VALID (1 << 0) /* 1=Cache has valid data */ +#define ST25FL1_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */ +#define ST25FL1_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */ + +#define IS_VALID(p) ((((p)->flags) & ST25FL1_CACHE_VALID) != 0) +#define IS_DIRTY(p) ((((p)->flags) & ST25FL1_CACHE_DIRTY) != 0) +#define IS_ERASED(p) ((((p)->flags) & ST25FL1_CACHE_DIRTY) != 0) + +#define SET_VALID(p) do { (p)->flags |= ST25FL1_CACHE_VALID; } while (0) +#define SET_DIRTY(p) do { (p)->flags |= ST25FL1_CACHE_DIRTY; } while (0) +#define SET_ERASED(p) do { (p)->flags |= ST25FL1_CACHE_DIRTY; } while (0) + +#define CLR_VALID(p) do { (p)->flags &= ~ST25FL1_CACHE_VALID; } while (0) +#define CLR_DIRTY(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) +#define CLR_ERASED(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/* This type represents the state of the MTD device. The struct mtd_dev_s must + * appear at the beginning of the definition so that you can freely cast between + * pointers to struct mtd_dev_s and struct st25fl1_dev_s. + */ + +struct st25fl1_dev_s +{ + struct mtd_dev_s mtd; /* MTD interface */ + FAR struct spi_dev_s *spi; /* Saved QuadSPI interface instance */ + uint16_t nsectors; /* Number of erase sectors */ + +#ifdef CONFIG_ST25FL1_SECTOR512 + uint8_t flags; /* Buffered sector flags */ + uint16_t esectno; /* Erase sector number in the cache*/ + FAR uint8_t *sector; /* Allocated sector data */ +#endif +}; + +/************************************************************************************ + * Private Function Prototypes + ************************************************************************************/ + +/* Helpers */ + +static void st25fl1_lock(FAR struct spi_dev_s *spi); +static inline void st25fl1_unlock(FAR struct spi_dev_s *spi); +static inline int st25fl1_readid(FAR struct st25fl1_dev_s *priv); +static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); +static uint8_t st25fl1_waitwritecomplete(FAR struct st25fl1_dev_s *priv); +static inline void st25fl1_wren(FAR struct st25fl1_dev_s *priv); +static inline void st25fl1_wrdi(FAR struct st25fl1_dev_s *priv); +static void st25fl1_sectorerase(FAR struct st25fl1_dev_s *priv, off_t offset); +static inline int st25fl1_chiperase(FAR struct st25fl1_dev_s *priv); +static void st25fl1_byteread(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t nbytes); +static void st25fl1_pagewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t nbytes); +#ifdef CONFIG_ST25FL1_SECTOR512 +static void st25fl1_cacheflush(struct st25fl1_dev_s *priv); +static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector); +static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector); +static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t sector, size_t nsectors); +#endif + +/* MTD driver methods */ + +static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); +static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); +static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR uint8_t *buffer); +static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: st25fl1_lock + ************************************************************************************/ + +static void st25fl1_lock(FAR struct spi_dev_s *spi) +{ + /* On QuadSPI busses where there are multiple devices, it will be necessary to + * lock QuadSPI to have exclusive access to the busses for a sequence of + * transfers. The bus should be locked before the chip is selected. + * + * This is a blocking call and will not return until we have exclusiv access to + * the QuadSPI buss. We will retain that exclusive access until the bus is unlocked. + */ + + (void)SPI_LOCK(spi, true); + + /* After locking the QuadSPI bus, the we also need call the setfrequency, setbits, and + * setmode methods to make sure that the QuadSPI is properly configured for the device. + * If the QuadSPI buss is being shared, then it may have been left in an incompatible + * state. + */ + + SPI_SETMODE(spi, CONFIG_ST25FL1_SPIMODE); + SPI_SETBITS(spi, 8); + (void)SPI_SETFREQUENCY(spi, CONFIG_ST25FL1_SPIFREQUENCY); +} + +/************************************************************************************ + * Name: st25fl1_unlock + ************************************************************************************/ + +static inline void st25fl1_unlock(FAR struct spi_dev_s *spi) +{ + (void)SPI_LOCK(spi, false); +} + +/************************************************************************************ + * Name: st25fl1_readid + ************************************************************************************/ + +static inline int st25fl1_readid(struct st25fl1_dev_s *priv) +{ + uint16_t manufacturer; + uint16_t memory; + uint16_t capacity; + + fvdbg("priv: %p\n", priv); + + /* Lock the QuadSPI bus, configure the bus, and select this FLASH part. */ + + st25fl1_lock(priv->spi); + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + +#warning Missing Logic + + /* Deselect the FLASH and unlock the bus */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + st25fl1_unlock(priv->spi); + + fvdbg("manufacturer: %02x memory: %02x capacity: %02x\n", + manufacturer, memory, capacity); + + /* Check for a valid manufacturer and memory type */ +#warning Missing Logic + + /* We don't understand the manufacturer or the memory type */ + + return -ENODEV; +} + +/************************************************************************************ + * Name: st25fl1_unprotect + ************************************************************************************/ + +static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv) +{ +#warning Missing Logic +} + +/************************************************************************************ + * Name: st25fl1_waitwritecomplete + ************************************************************************************/ + +static uint8_t st25fl1_waitwritecomplete(struct st25fl1_dev_s *priv) +{ + uint8_t status; + + /* Are we the only device on the bus? */ + +#ifdef CONFIG_SPI_OWNBUS + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); +#warning Missing Logic + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + +#else + + /* Loop as long as the memory is busy with a write cycle */ + + do + { + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); +#warning Missing Logic + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + } + while ((status & ST25FL1_SR_BUSY) != 0); +#endif + + return status; +} + +/************************************************************************************ + * Name: st25fl1_wren + ************************************************************************************/ + +static inline void st25fl1_wren(struct st25fl1_dev_s *priv) +{ + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); +#warning Missing Logic + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: st25fl1_wrdi + ************************************************************************************/ + +static inline void st25fl1_wrdi(struct st25fl1_dev_s *priv) +{ + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); +#warning Missing Logic + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: st25fl1_sectorerase + ************************************************************************************/ + +static void st25fl1_sectorerase(struct st25fl1_dev_s *priv, off_t sector) +{ + fvdbg("sector: %08lx\n", (long)sector); +#warning Missing Logic +} + +/************************************************************************************ + * Name: st25fl1_chiperase + ************************************************************************************/ + +static inline int st25fl1_chiperase(struct st25fl1_dev_s *priv) +{ + fvdbg("priv: %p\n", priv); +#warning Missing Logic +} + +/************************************************************************************ + * Name: st25fl1_byteread + ************************************************************************************/ + +static void st25fl1_byteread(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t nbytes) +{ + fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)nbytes); +#warning Missing Logic +} + +/************************************************************************************ + * Name: st25fl1_pagewrite + ************************************************************************************/ + +static void st25fl1_pagewrite(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t nbytes) +{ + fvdbg("address: %08lx nwords: %d\n", (long)address, (int)nbytes); +#warning Missing Logic +} + +/************************************************************************************ + * Name: st25fl1_cacheflush + ************************************************************************************/ + +#ifdef CONFIG_ST25FL1_SECTOR512 +static void st25fl1_cacheflush(struct st25fl1_dev_s *priv) +{ + /* If the cached is dirty (meaning that it no longer matches the old FLASH contents) + * or was erased (with the cache containing the correct FLASH contents), then write + * the cached erase block to FLASH. + */ + + if (IS_DIRTY(priv) || IS_ERASED(priv)) + { + /* Write entire erase block to FLASH */ +#warning Missing Logic + + /* The case is no long dirty and the FLASH is no longer erased */ + + CLR_DIRTY(priv); + CLR_ERASED(priv); + } +} +#endif + +/************************************************************************************ + * Name: st25fl1_cacheread + ************************************************************************************/ + +#ifdef CONFIG_ST25FL1_SECTOR512 +static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector) +{ + off_t esectno; + int shift; + int index; + + /* Convert from the 512 byte sector to the erase sector size of the device. For + * exmample, if the actual erase sector size if 4Kb (1 << 12), then we first + * shift to the right by 3 to get the sector number in 4096 increments. + */ + + shift = ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT; + esectno = sector >> shift; + fvdbg("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift); + + /* Check if the requested erase block is already in the cache */ + + if (!IS_VALID(priv) || esectno != priv->esectno) + { + /* No.. Flush any dirty erase block currently in the cache */ + + st25fl1_cacheflush(priv); + + /* Read the erase block into the cache */ + + st25fl1_byteread(priv, priv->sector, (esectno << ST25FL1_SECTOR_SHIFT), ST25FL1_SECTOR_SIZE); + + /* Mark the sector as cached */ + + priv->esectno = esectno; + + SET_VALID(priv); /* The data in the cache is valid */ + CLR_DIRTY(priv); /* It should match the FLASH contents */ + CLR_ERASED(priv); /* The underlying FLASH has not been erased */ + } + + /* Get the index to the 512 sector in the erase block that holds the argument */ + + index = sector & ((1 << shift) - 1); + + /* Return the address in the cache that holds this sector */ + + return &priv->sector[index << ST25FL1_SECTOR512_SHIFT]; +} +#endif + +/************************************************************************************ + * Name: st25fl1_cacheerase + ************************************************************************************/ + +#ifdef CONFIG_ST25FL1_SECTOR512 +static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector) +{ + FAR uint8_t *dest; + + /* First, make sure that the erase block containing the 512 byte sector is in + * the cache. + */ + + dest = st25fl1_cacheread(priv, sector); + + /* Erase the block containing this sector if it is not already erased. + * The erased indicated will be cleared when the data from the erase sector + * is read into the cache and set here when we erase the block. + */ + + if (!IS_ERASED(priv)) + { + off_t esectno = sector >> (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); + fvdbg("sector: %ld esectno: %d\n", sector, esectno); + + st25fl1_sectorerase(priv, esectno); + SET_ERASED(priv); + } + + /* Put the cached sector data into the erase state and mart the cache as dirty + * (but don't update the FLASH yet. The caller will do that at a more optimal + * time). + */ + + memset(dest, ST25FL1_ERASED_STATE, ST25FL1_SECTOR512_SIZE); + SET_DIRTY(priv); +} +#endif + +/************************************************************************************ + * Name: st25fl1_cachewrite + ************************************************************************************/ + +#ifdef CONFIG_ST25FL1_SECTOR512 +static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t sector, size_t nsectors) +{ + FAR uint8_t *dest; + + for (; nsectors > 0; nsectors--) + { + /* First, make sure that the erase block containing 512 byte sector is in + * memory. + */ + + dest = st25fl1_cacheread(priv, sector); + + /* Erase the block containing this sector if it is not already erased. + * The erased indicated will be cleared when the data from the erase sector + * is read into the cache and set here when we erase the sector. + */ + + if (!IS_ERASED(priv)) + { + off_t esectno = sector >> (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); + fvdbg("sector: %ld esectno: %d\n", sector, esectno); + + st25fl1_sectorerase(priv, esectno); + SET_ERASED(priv); + } + + /* Copy the new sector data into cached erase block */ + + memcpy(dest, buffer, ST25FL1_SECTOR512_SIZE); + SET_DIRTY(priv); + + /* Set up for the next 512 byte sector */ + + buffer += ST25FL1_SECTOR512_SIZE; + sector++; + } + + /* Flush the last erase block left in the cache */ + + st25fl1_cacheflush(priv); +} +#endif + +/************************************************************************************ + * Name: st25fl1_erase + ************************************************************************************/ + +static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +{ + FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); +#warning Missing Logic + +} + +/************************************************************************************ + * Name: st25fl1_bread + ************************************************************************************/ + +static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR uint8_t *buffer) +{ + ssize_t nbytes; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* On this device, we can handle the block read just like the byte-oriented read */ + +#ifdef CONFIG_ST25FL1_SECTOR512 + nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR512_SHIFT, nblocks << ST25FL1_SECTOR512_SHIFT, buffer); + if (nbytes > 0) + { + nbytes >>= ST25FL1_SECTOR512_SHIFT; + } +#else + nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR_SHIFT, nblocks << ST25FL1_SECTOR_SHIFT, buffer); + if (nbytes > 0) + { + nbytes >>= ST25FL1_SECTOR_SHIFT; + } +#endif + + return nbytes; +} + +/************************************************************************************ + * Name: st25fl1_bwrite + ************************************************************************************/ + +static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR const uint8_t *buffer) +{ + FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* Lock the QuadSPI bus and write all of the pages to FLASH */ + + st25fl1_lock(priv->spi); + +#if defined(CONFIG_ST25FL1_SECTOR512) + st25fl1_cachewrite(priv, buffer, startblock, nblocks); +#else + st25fl1_pagewrite(priv, buffer, startblock << ST25FL1_SECTOR_SHIFT, + nblocks << ST25FL1_SECTOR_SHIFT); +#endif + st25fl1_unlock(priv->spi); + + return nblocks; +} + +/************************************************************************************ + * Name: st25fl1_read + ************************************************************************************/ + +static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR uint8_t *buffer) +{ + FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + + fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes); + + /* Lock the QuadSPI bus and select this FLASH part */ + + st25fl1_lock(priv->spi); + st25fl1_byteread(priv, buffer, offset, nbytes); + st25fl1_unlock(priv->spi); + + fvdbg("return nbytes: %d\n", (int)nbytes); + return nbytes; +} + +/************************************************************************************ + * Name: st25fl1_ioctl + ************************************************************************************/ + +static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + int ret = -EINVAL; /* Assume good command with bad parameters */ + + fvdbg("cmd: %d \n", cmd); + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) + { + /* Populate the geometry structure with information need to know + * the capacity and how to access the device. + * + * NOTE: that the device is treated as though it where just an array + * of fixed size blocks. That is most likely not true, but the client + * will expect the device logic to do whatever is necessary to make it + * appear so. + */ + +#ifdef CONFIG_ST25FL1_SECTOR512 + geo->blocksize = (1 << ST25FL1_SECTOR512_SHIFT); + geo->erasesize = (1 << ST25FL1_SECTOR512_SHIFT); + geo->neraseblocks = priv->nsectors << (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); +#else + geo->blocksize = ST25FL1_SECTOR_SIZE; + geo->erasesize = ST25FL1_SECTOR_SIZE; + geo->neraseblocks = priv->nsectors; +#endif + ret = OK; + + fvdbg("blocksize: %d erasesize: %d neraseblocks: %d\n", + geo->blocksize, geo->erasesize, geo->neraseblocks); + } + } + break; + + case MTDIOC_BULKERASE: + { + /* Erase the entire device */ + + st25fl1_lock(priv->spi); + ret = st25fl1_chiperase(priv); + st25fl1_unlock(priv->spi); + } + break; + + case MTDIOC_XIPBASE: + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + fvdbg("return %d\n", ret); + return ret; +} + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: st25fl1_initialize + * + * Description: + * Create an initialize MTD device instance. MTD devices are not registered + * in the file system, but are created as instances that can be bound to + * other functions (such as a block or character driver front end). + * + ************************************************************************************/ + +FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *spi) +{ + FAR struct st25fl1_dev_s *priv; + int ret; + + fvdbg("spi: %p\n", spi); + + /* Allocate a state structure (we allocate the structure instead of using + * a fixed, static allocation so that we can handle multiple FLASH devices. + * The current implementation would handle only one FLASH part per QuadSPI + * device (only because of the SPIDEV_FLASH definition) and so would have + * to be extended to handle multiple FLASH parts on the same QuadSPI bus. + */ + + priv = (FAR struct st25fl1_dev_s *)kmm_zalloc(sizeof(struct st25fl1_dev_s)); + if (priv) + { + /* Initialize the allocated structure (unsupported methods were + * nullified by kmm_zalloc). + */ + + priv->mtd.erase = st25fl1_erase; + priv->mtd.bread = st25fl1_bread; + priv->mtd.bwrite = st25fl1_bwrite; + priv->mtd.read = st25fl1_read; + priv->mtd.ioctl = st25fl1_ioctl; + priv->spi = spi; + + /* Deselect the FLASH */ + + SPI_SELECT(spi, SPIDEV_FLASH, false); + + /* Identify the FLASH chip and get its capacity */ + + ret = st25fl1_readid(priv); + if (ret != OK) + { + /* Unrecognized! Discard all of that work we just did and return NULL */ + + fdbg("Unrecognized\n"); + kmm_free(priv); + priv = NULL; + } + else + { + /* Make sure that the FLASH is unprotected so that we can write into it */ + + st25fl1_unprotect(priv); + +#ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ + /* Allocate a buffer for the erase block cache */ + + priv->sector = (FAR uint8_t *)kmm_malloc(ST25FL1_SECTOR_SIZE); + if (!priv->sector) + { + /* Allocation failed! Discard all of that work we just did and return NULL */ + + fdbg("Allocation failed\n"); + kmm_free(priv); + priv = NULL; + } +#endif + } + } + + /* Register the MTD with the procfs system if enabled */ + +#ifdef CONFIG_MTD_REGISTRATION + mtd_register(&priv->mtd, "st25fl1"); +#endif + + /* Return the implementation-specific state structure as the MTD device */ + + fvdbg("Return %p\n", priv); + return (FAR struct mtd_dev_s *)priv; +} -- GitLab From 8d57be2b6fead7d99f1789e8398736f2bb46515e Mon Sep 17 00:00:00 2001 From: "Anton D. Kachalov" Date: Wed, 26 Aug 2015 00:14:50 +0300 Subject: [PATCH 079/858] Eliminate compilation warnings Signed-off-by: Anton D. Kachalov --- fs/vfs/fs_poll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 10852e7d91..f13148288c 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -326,8 +327,6 @@ int file_poll(int fd, FAR struct pollfd *fds, bool setup) int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) { - struct timespec abstime; - irqstate_t flags; sem_t sem; int count = 0; int ret; -- GitLab From b125c36849c24aeca50003f7e48aaf927f1c47f1 Mon Sep 17 00:00:00 2001 From: "Anton D. Kachalov" Date: Wed, 26 Aug 2015 00:16:52 +0300 Subject: [PATCH 080/858] Field `d_sndlen' is unsigned. It is always >= 0. Signed-off-by: Anton D. Kachalov --- net/tcp/tcp_appsend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index 4f110f848a..ab799d975a 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -172,7 +172,7 @@ void tcp_appsend(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, else { #ifdef CONFIG_NET_TCP_WRITE_BUFFERS - DEBUGASSERT(dev->d_sndlen >= 0 && dev->d_sndlen <= conn->mss); + DEBUGASSERT(dev->d_sndlen <= conn->mss); #else /* If d_sndlen > 0, the application has data to be sent. */ -- GitLab From 6dadfcbf6bb8418ac66414913a92ca9f32ae334e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Aug 2015 15:26:16 -0600 Subject: [PATCH 081/858] Add QSPI interface definition --- ChangeLog | 4 + arch | 2 +- include/nuttx/spi/qspi.h | 257 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 include/nuttx/spi/qspi.h diff --git a/ChangeLog b/ChangeLog index d67d91d1b4..71e236906a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10883,4 +10883,8 @@ SaeHie Park (2015-08-25). * drivers/mtd/st25fl1.c: Add a driver for ST25L1*K QuadSPI parts (2015-08-15). + * include/nuttx/spi/qspi.h: Develop a new interface for QSPI, at + least the way that QSPI is implemented on the SAMV71. Originally + planned to use the SPI interface, but it is just now compatible + with the SAMV71 QSPI hardware (2015-08-15). diff --git a/arch b/arch index 5336c64638..463d5c9af8 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5336c646386607424e3426fb488d73241abb5f08 +Subproject commit 463d5c9af87cb0e749f7400ae1a1dfe0d56517fc diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h new file mode 100644 index 0000000000..127b8c8306 --- /dev/null +++ b/include/nuttx/spi/qspi.h @@ -0,0 +1,257 @@ +/**************************************************************************** + * include/nuttx/qspi/qspi.h + * + * Copyright(C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_QSPI_QSPI_H +#define __INCLUDE_NUTTX_QSPI_QSPI_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Access macros ************************************************************/ + +/**************************************************************************** + * Name: QSPI_LOCK + * + * Description: + * On QSPI busses where there are multiple devices, it will be necessary to + * lock QSPI to have exclusive access to the busses for a sequence of + * transfers. The bus should be locked before the chip is selected. After + * locking the QSPI bus, the caller should then also call the setfrequency, + * setbits, and setmode methods to make sure that the QSPI is properly + * configured for the device. If the QSPI buss is being shared, then it + * may have been left in an incompatible state. + * + * Input Parameters: + * dev - Device-specific state data + * lock - true: Lock qspi bus, false: unlock QSPI bus + * + * Returned Value: + * None + * + ****************************************************************************/ + +#define QSPI_LOCK(d,l) (d)->ops->lock(d,l) + +/**************************************************************************** + * Name: QSPI_SETFREQUENCY + * + * Description: + * Set the QSPI frequency. Required. + * + * Input Parameters: + * dev - Device-specific state data + * frequency - The QSPI frequency requested + * + * Returned Value: + * Returns the actual frequency selected + * + ****************************************************************************/ + +#define QSPI_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) + +/**************************************************************************** + * Name: QSPI_SETMODE + * + * Description: + * Set the QSPI mode. Optional. See enum qspi_mode_e for mode definitions. + * + * Input Parameters: + * dev - Device-specific state data + * mode - The QSPI mode requested + * + * Returned Value: + * none + * + ****************************************************************************/ + +#define QSPI_SETMODE(d,m) (d)->ops->setmode(d,m) + +/**************************************************************************** + * Name: QSPI_SETBITS + * + * Description: + * Set the number if bits per word. + * + * Input Parameters: + * dev - Device-specific state data + * nbits - The number of bits requests. + * If value is greater > 0 then it implies MSB first + * If value is below < 0, then it implies LSB first with -nbits + * + * Returned Value: + * none + * + ****************************************************************************/ + +#define QSPI_SETBITS(d,b) (d)->ops->setbits(d,b) + +/**************************************************************************** + * Name: QSPI_COMMAND + * + * Description: + * Send a command to the QSPI device + * + * Input Parameters: + * dev - Device-specific state data + * cmd - The command to send. the size of the data is determined by the + * number of bits selected for the QSPI interface. + * + * Returned Value: + * Zero (OK) on SUCCESS, a negated errno on value of failure + * + ****************************************************************************/ + +#define QSPI_COMMAND(d,c) ((d)->ops->command(d,(uint16_t)c)) + +/**************************************************************************** + * Name: QSPI_COMMAND_WRITE + * + * Description: + * Send a command then send a block of data. + * + * Input Parameters: + * dev - Device-specific state data + * cmd - The command to send. the size of the data is determined by + * the number of bits selected for the QSPI interface. + * buffer - A pointer to the buffer of data to be sent + * buflen - the length of data to send from the buffer in number of words. + * The wordsize is determined by the number of bits-per-word + * selected for the QSPI interface. If nbits <= 8, the data is + * packed into uint8_t's; if nbits >8, the data is packed into + * uint16_t's + * + * Returned Value: + * Zero (OK) on SUCCESS, a negated errno on value of failure + * + ****************************************************************************/ + +#define QSPI_COMMAND_WRITE(d,c,b,l) ((d)->ops->command_write(d,c,b,l)) + +/**************************************************************************** + * Name: QSPI_COMMAND_READ + * + * Description: + * Receive a block of data from QSPI. Required. + * + * Input Parameters: + * dev - Device-specific state data + * cmd - The command to send. the size of the data is determined by + * the number of bits selected for the QSPI interface. + * buffer - A pointer to the buffer in which to receive data + * buflen - the length of data that can be received in the buffer in number + * of words. The wordsize is determined by the number of bits- + * per-word selected for the QSPI interface. If nbits <= 8, the + * data is packed into uint8_t's; if nbits >8, the data is packed + * into uint16_t's + * + * Returned Value: + * Zero (OK) on SUCCESS, a negated errno on value of failure + * + ****************************************************************************/ + +#define QSPI_COMMAND_READ(d,c,b,l) ((d)->ops->command_read(d,c,b,l)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Certain QSPI devices may required different clocking modes */ + +enum qspi_mode_e +{ + QSPIDEV_MODE0 = 0, /* CPOL=0 CHPHA=0 */ + QSPIDEV_MODE1, /* CPOL=0 CHPHA=1 */ + QSPIDEV_MODE2, /* CPOL=1 CHPHA=0 */ + QSPIDEV_MODE3 /* CPOL=1 CHPHA=1 */ +}; + +/* The QSPI vtable */ + +struct qspi_dev_s; +struct qspi_ops_s +{ + CODE int (*lock)(FAR struct qspi_dev_s *dev, bool lock); + CODE uint32_t (*setfrequency)(FAR struct qspi_dev_s *dev, uint32_t frequency); + CODE void (*setmode)(FAR struct qspi_dev_s *dev, enum qspi_mode_e mode); + CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits); + CODE int (*command)(FAR struct qspi_dev_s *dev, uint16_t command); + CODE int (*command_write)(FAR struct qspi_dev_s *dev, uint16_t cmd, + FAR const void *buffer, size_t buflen); + CODE int (*command_read)(FAR struct qspi_dev_s *dev, uint16_t cmd, + FAR void *buffer, size_t buflen); +}; + +/* QSPI private data. This structure only defines the initial fields of the + * structure visible to the QSPI client. The specific implementation may + * add additional, device specific fields + */ + +struct qspi_dev_s +{ + FAR const struct qspi_ops_s *ops; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __INCLUDE_NUTTX_QSPI_QSPI_H */ -- GitLab From 8fe0121e1ac15e22fae18640a4aa293e2605e3a1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Aug 2015 17:20:54 -0600 Subject: [PATCH 082/858] Convert fragmentation ST24FL1 driver to use QSPI interface --- drivers/mtd/Kconfig | 9 ++-- drivers/mtd/st25fl1.c | 98 +++++++++++++------------------------------ 2 files changed, 33 insertions(+), 74 deletions(-) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 5989a526ba..717d4b199e 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -390,16 +390,15 @@ endif config MTD_ST25FL1 bool "QuadSPI-based ST25FL1 FLASH" default n - select SPI if MTD_ST25FL1 -config ST25FL1_SPIMODE - int "ST25FL1 SPI Mode" +config ST25FL1_QSPIMODE + int "ST25FL1 QuadSPI Mode" default 0 -config ST25FL1_SPIFREQUENCY - int "ST25FL1 SPI Frequency" +config ST25FL1_QSPIFREQUENCY + int "ST25FL1 QuadSPI Frequency" default 20000000 config ST25FL1_SECTOR512 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index d61026fe52..44f57c71a5 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include /************************************************************************************ @@ -62,14 +62,14 @@ /* Configuration ********************************************************************/ /* QuadSPI Mode */ -#ifndef CONFIG_ST25FL1_SPIMODE -# define CONFIG_ST25FL1_SPIMODE SPIDEV_MODE0 +#ifndef CONFIG_ST25FL1_QSPIMODE +# define CONFIG_ST25FL1_QSPIMODE QSPIDEV_MODE0 #endif /* QuadSPI Frequency. May be up to 25MHz. */ -#ifndef CONFIG_ST25FL1_SPIFREQUENCY -# define CONFIG_ST25FL1_SPIFREQUENCY 20000000 +#ifndef CONFIG_ST25FL1_QSPIFREQUENCY +# define CONFIG_ST25FL1_QSPIFREQUENCY 20000000 #endif /* ST25FL1 Commands *****************************************************************/ @@ -276,7 +276,7 @@ struct st25fl1_dev_s { struct mtd_dev_s mtd; /* MTD interface */ - FAR struct spi_dev_s *spi; /* Saved QuadSPI interface instance */ + FAR struct spi_dev_s *qspi; /* Saved QuadSPI interface instance */ uint16_t nsectors; /* Number of erase sectors */ #ifdef CONFIG_ST25FL1_SECTOR512 @@ -292,8 +292,8 @@ struct st25fl1_dev_s /* Helpers */ -static void st25fl1_lock(FAR struct spi_dev_s *spi); -static inline void st25fl1_unlock(FAR struct spi_dev_s *spi); +static void st25fl1_lock(FAR struct spi_dev_s *qspi); +static inline void st25fl1_unlock(FAR struct spi_dev_s *qspi); static inline int st25fl1_readid(FAR struct st25fl1_dev_s *priv); static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); static uint8_t st25fl1_waitwritecomplete(FAR struct st25fl1_dev_s *priv); @@ -336,7 +336,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); * Name: st25fl1_lock ************************************************************************************/ -static void st25fl1_lock(FAR struct spi_dev_s *spi) +static void st25fl1_lock(FAR struct spi_dev_s *qspi) { /* On QuadSPI busses where there are multiple devices, it will be necessary to * lock QuadSPI to have exclusive access to the busses for a sequence of @@ -346,7 +346,7 @@ static void st25fl1_lock(FAR struct spi_dev_s *spi) * the QuadSPI buss. We will retain that exclusive access until the bus is unlocked. */ - (void)SPI_LOCK(spi, true); + (void)QSPI_LOCK(qspi, true); /* After locking the QuadSPI bus, the we also need call the setfrequency, setbits, and * setmode methods to make sure that the QuadSPI is properly configured for the device. @@ -354,18 +354,18 @@ static void st25fl1_lock(FAR struct spi_dev_s *spi) * state. */ - SPI_SETMODE(spi, CONFIG_ST25FL1_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_SETFREQUENCY(spi, CONFIG_ST25FL1_SPIFREQUENCY); + QSPI_SETMODE(qspi, CONFIG_ST25FL1_QSPIMODE); + QSPI_SETBITS(qspi, 8); + (void)QSPI_SETFREQUENCY(qspi, CONFIG_ST25FL1_QSPIFREQUENCY); } /************************************************************************************ * Name: st25fl1_unlock ************************************************************************************/ -static inline void st25fl1_unlock(FAR struct spi_dev_s *spi) +static inline void st25fl1_unlock(FAR struct spi_dev_s *qspi) { - (void)SPI_LOCK(spi, false); + (void)QSPI_LOCK(qspi, false); } /************************************************************************************ @@ -380,17 +380,15 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) fvdbg("priv: %p\n", priv); - /* Lock the QuadSPI bus, configure the bus, and select this FLASH part. */ + /* Lock the QuadSPI bus and configure the bus. */ - st25fl1_lock(priv->spi); - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + st25fl1_lock(priv->qspi); #warning Missing Logic - /* Deselect the FLASH and unlock the bus */ + /* Unlock the bus */ - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); - st25fl1_unlock(priv->spi); + st25fl1_unlock(priv->qspi); fvdbg("manufacturer: %02x memory: %02x capacity: %02x\n", manufacturer, memory, capacity); @@ -420,35 +418,13 @@ static uint8_t st25fl1_waitwritecomplete(struct st25fl1_dev_s *priv) { uint8_t status; - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); -#warning Missing Logic - - /* Deselect the FLASH */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); - -#else - /* Loop as long as the memory is busy with a write cycle */ do { - /* Select this FLASH part */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); #warning Missing Logic - /* Deselect the FLASH */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); } while ((status & ST25FL1_SR_BUSY) != 0); -#endif return status; } @@ -459,13 +435,7 @@ static uint8_t st25fl1_waitwritecomplete(struct st25fl1_dev_s *priv) static inline void st25fl1_wren(struct st25fl1_dev_s *priv) { - /* Select this FLASH part */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); #warning Missing Logic - /* Deselect the FLASH */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); } /************************************************************************************ @@ -474,13 +444,7 @@ static inline void st25fl1_wren(struct st25fl1_dev_s *priv) static inline void st25fl1_wrdi(struct st25fl1_dev_s *priv) { - /* Select this FLASH part */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); #warning Missing Logic - /* Deselect the FLASH */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); } /************************************************************************************ @@ -745,7 +709,7 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_ /* Lock the QuadSPI bus and write all of the pages to FLASH */ - st25fl1_lock(priv->spi); + st25fl1_lock(priv->qspi); #if defined(CONFIG_ST25FL1_SECTOR512) st25fl1_cachewrite(priv, buffer, startblock, nblocks); @@ -753,7 +717,7 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_ st25fl1_pagewrite(priv, buffer, startblock << ST25FL1_SECTOR_SHIFT, nblocks << ST25FL1_SECTOR_SHIFT); #endif - st25fl1_unlock(priv->spi); + st25fl1_unlock(priv->qspi); return nblocks; } @@ -771,9 +735,9 @@ static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbyt /* Lock the QuadSPI bus and select this FLASH part */ - st25fl1_lock(priv->spi); + st25fl1_lock(priv->qspi); st25fl1_byteread(priv, buffer, offset, nbytes); - st25fl1_unlock(priv->spi); + st25fl1_unlock(priv->qspi); fvdbg("return nbytes: %d\n", (int)nbytes); return nbytes; @@ -827,9 +791,9 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { /* Erase the entire device */ - st25fl1_lock(priv->spi); + st25fl1_lock(priv->qspi); ret = st25fl1_chiperase(priv); - st25fl1_unlock(priv->spi); + st25fl1_unlock(priv->qspi); } break; @@ -857,17 +821,17 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ************************************************************************************/ -FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *spi) +FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *qspi) { FAR struct st25fl1_dev_s *priv; int ret; - fvdbg("spi: %p\n", spi); + fvdbg("qspi: %p\n", qspi); /* Allocate a state structure (we allocate the structure instead of using * a fixed, static allocation so that we can handle multiple FLASH devices. * The current implementation would handle only one FLASH part per QuadSPI - * device (only because of the SPIDEV_FLASH definition) and so would have + * device (only because of the QSPIDEV_FLASH definition) and so would have * to be extended to handle multiple FLASH parts on the same QuadSPI bus. */ @@ -883,11 +847,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *spi) priv->mtd.bwrite = st25fl1_bwrite; priv->mtd.read = st25fl1_read; priv->mtd.ioctl = st25fl1_ioctl; - priv->spi = spi; - - /* Deselect the FLASH */ - - SPI_SELECT(spi, SPIDEV_FLASH, false); + priv->qspi = qspi; /* Identify the FLASH chip and get its capacity */ -- GitLab From e6dbd3d9032c0166144476e65d6444d8d84356c7 Mon Sep 17 00:00:00 2001 From: Saehie ParK Date: Tue, 25 Aug 2015 19:59:45 -0600 Subject: [PATCH 083/858] Networking: Fix network device name assignment logic for the case of the local loopback device. There is only one local loopback network device and it is unnumbered --- net/netdev/netdev_register.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 362e5a44a2..de5fa6c8f4 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -257,16 +257,35 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) dev->d_conncb = NULL; dev->d_devcb = NULL; - /* Get the next available device number and sssign a device name to + /* Get the next available device number and assign a device name to * the interface */ save = net_lock(); + #ifdef CONFIG_NET_MULTILINK - devnum = find_devnum(devfmt); +# ifdef CONFIG_NET_LOOPBACK + /* The local loopback device is a special case: There can be only one + * local loopback device so it is unnumbered. + */ + + if (lltype == NET_LL_LOOPBACK) + { + devnum = 0; + } + else +# endif + { + devnum = find_devnum(devfmt); + } #else + /* There is only a single link type. Finding the next network device + * number is simple. + */ + devnum = g_next_devnum++; #endif + #ifdef CONFIG_NET_USER_DEVFMT if (*dev->d_ifname) { -- GitLab From 32de036490515f3d2ced152033a24a67fb563c5f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Aug 2015 20:09:12 -0600 Subject: [PATCH 084/858] Local loopback: Set the IFF_UP flags during initialization because the local loopback device is always up --- Documentation | 2 +- configs | 2 +- drivers/net/loopback.c | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index 8a30728ae9..ce750c0899 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8a30728ae9a64496f0c9a0ff5dd62bd3b022c145 +Subproject commit ce750c0899c2138b37b52a48d020a3eceb92fd04 diff --git a/configs b/configs index e1e1873700..e3f37812a9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e1e1873700ffda7aeb632e2b1234333d88ce3457 +Subproject commit e3f37812a9a7595a7ddab1a625ebe857d104beb2 diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 5e2a12d1e3..83aa983657 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -532,13 +533,16 @@ int localhost_initialize(void) net_ipv4addr_copy(priv->lo_dev.d_draddr, g_lo_ipv4addr); net_ipv4addr_copy(priv->lo_dev.d_netmask, g_lo_ipv4mask); #endif + #ifdef CONFIG_NET_IPv6 net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr); net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr); net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_alloneaddr); #endif + /* Put the network in the UP state */ + priv->lo_dev.d_flags = IFF_UP; return lo_ifup(&priv->lo_dev); } -- GitLab From 1cf57ae2bd6e41c10828062026c5665d8113c61c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 07:16:07 -0600 Subject: [PATCH 085/858] Cosmetic --- drivers/mtd/st25fl1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 44f57c71a5..18a67eef24 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -882,9 +882,9 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *qspi) } } +#ifdef CONFIG_MTD_REGISTRATION /* Register the MTD with the procfs system if enabled */ -#ifdef CONFIG_MTD_REGISTRATION mtd_register(&priv->mtd, "st25fl1"); #endif -- GitLab From 70620d3dd6df6e6b0a095b9ebff7551e450e719e Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Wed, 26 Aug 2015 07:18:50 -0600 Subject: [PATCH 086/858] rivers/rwbuffer: Fix some logic errors --- ChangeLog | 2 ++ Documentation | 2 +- configs | 2 +- drivers/rwbuffer.c | 10 +++++----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 377f2b110a..2bda7e474b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10881,4 +10881,6 @@ device (2015-08-24). * networking: Correct return value from psock_tcp_accept(). From SaeHie Park (2015-08-25). + * drivers/rwbuffer.c: Fix some logic errors. From Dmitry Nikolaev + via Juha Niskanen (2015-08-26). diff --git a/Documentation b/Documentation index ce750c0899..8a30728ae9 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit ce750c0899c2138b37b52a48d020a3eceb92fd04 +Subproject commit 8a30728ae9a64496f0c9a0ff5dd62bd3b022c145 diff --git a/configs b/configs index e3f37812a9..e1e1873700 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e3f37812a9a7595a7ddab1a625ebe857d104beb2 +Subproject commit e1e1873700ffda7aeb632e2b1234333d88ce3457 diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index fd2f73c77a..9c443df7b5 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -96,7 +96,7 @@ static void rwb_semtake(sem_t *sem) while (sem_wait(sem) != 0) { - /* The only case that an error should occr here is if + /* The only case that an error should occur here is if * the wait was awakened by a signal. */ @@ -117,8 +117,8 @@ static void rwb_semtake(sem_t *sem) static inline bool rwb_overlap(off_t blockstart1, size_t nblocks1, off_t blockstart2, size_t nblocks2) { - off_t blockend1 = blockstart1 + nblocks1; - off_t blockend2 = blockstart2 + nblocks2; + off_t blockend1 = blockstart1 + nblocks1 - 1; + off_t blockend2 = blockstart2 + nblocks2 - 1; /* If the buffer 1 is wholly outside of buffer 2, return false */ @@ -257,7 +257,7 @@ static ssize_t rwb_writebuffer(FAR struct rwbuffer_s *rwb, /* Flush the write buffer */ - ret = rwb->wrflush(rwb, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnblocks); + ret = rwb->wrflush(rwb->dev, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnblocks); if (ret < 0) { fdbg("ERROR: Error writing multiple from cache: %d\n", -ret); @@ -842,7 +842,7 @@ int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32_t nblocks, * the user buffer. */ - ret = rwb->rhreload(rwb->dev, startblock, nblocks, rdbuffer); + ret = rwb->rhreload(rwb->dev, rdbuffer, startblock, nblocks); } #endif -- GitLab From 7a168a791ffd8d8d57f93d88c89f859f50030476 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 10:33:44 -0600 Subject: [PATCH 087/858] Networking: Fix loopback device MTU --- drivers/net/loopback.c | 21 ++++++++++++++------- include/nuttx/net/netconfig.h | 28 ++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 83aa983657..ddaa8a5a1c 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -110,6 +110,10 @@ struct lo_driver_s static struct lo_driver_s g_loopback; +#ifdef CONFIG_NET_MULTIBUFFER +static uint8_t g_iobuffer[[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -507,18 +511,21 @@ int localhost_initialize(void) /* Initialize the driver structure */ memset(priv, 0, sizeof(struct lo_driver_s)); - priv->lo_dev.d_ifup = lo_ifup; /* I/F up (new IP address) callback */ - priv->lo_dev.d_ifdown = lo_ifdown; /* I/F down callback */ - priv->lo_dev.d_txavail = lo_txavail; /* New TX data callback */ + priv->lo_dev.d_ifup = lo_ifup; /* I/F up (new IP address) callback */ + priv->lo_dev.d_ifdown = lo_ifdown; /* I/F down callback */ + priv->lo_dev.d_txavail = lo_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */ - priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */ + priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */ + priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */ +#endif +#ifdef CONFIG_NET_MULTIBUFFER + priv->lo_dev.d_buf = g_iobuffer; /* Attach the IO buffer */ #endif - priv->lo_dev.d_private = (void*)priv; /* Used to recover private state from dev */ + priv->lo_dev.d_private = (void*)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmissions */ - priv->lo_polldog = wd_create(); /* Create periodic poll timer */ + priv->lo_polldog = wd_create(); /* Create periodic poll timer */ /* Register the loopabck device with the OS so that socket IOCTLs can b * performed. diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 8b182b0b82..f65b1c478d 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -62,6 +62,14 @@ * Public Type Definitions ****************************************************************************/ +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + /* Layer 2 Configuration Options ********************************************/ /* The default data link layer for uIP is Ethernet. If CONFIG_NET_SLIP is @@ -125,20 +133,28 @@ # define _MAX_ETH_MTU 0 # endif +# ifdef CONFIG_NET_LOOPBACK +# define _MIN_LO_MTU MIN(_MIN_ETH_MTU,1518) +# define _MAX_LO_MTU MAX(_MAX_ETH_MTU,574) +# else +# define _MIN_LO_MTU _MIN_ETH_MTU +# define _MAX_LO_MTU _MAX_ETH_MTU +# endif + # ifdef CONFIG_NET_SLIP -# define _MIN_SLIP_MTU MIN(_MIN_ETH_MTU,CONFIG_NET_SLIP_MTU) -# define _MAX_SLIP_MTU MAX(_MAX_ETH_MTU,CONFIG_NET_SLIP_MTU) +# define _MIN_SLIP_MTU MIN(_MIN_LO_MTU,CONFIG_NET_SLIP_MTU) +# define _MAX_SLIP_MTU MAX(_MAX_LO_MTU,CONFIG_NET_SLIP_MTU) # else -# define _MIN_SLIP_MTU _MIN_ETH_MTU -# define _MAX_SLIP_MTU _MAX_ETH_MTU +# define _MIN_SLIP_MTU _MIN_LO_MTU +# define _MAX_SLIP_MTU _MAX_LO_MTU # endif # define MIN_NET_DEV_MTU _MIN_SLIP_MTU # define MAX_NET_DEV_MTU _MAX_SLIP_MTU -/* For the loopback device, we will use the largest representable MTU */ +/* For the loopback device, we will use the largest MTU */ -# define NET_LO_MTU UINT16_MAX +# define NET_LO_MTU MAX_NET_DEV_MTU #elif defined(CONFIG_NET_SLIP) /* There is no link layer header with SLIP */ -- GitLab From 7936819fccc5bca455ba0fcc45cde3fcb36fe1ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 14:16:45 -0600 Subject: [PATCH 088/858] ST25FL1: Flesh out more initialization logic --- arch | 2 +- drivers/mtd/st25fl1.c | 494 ++++++++++++++++++++++++++++++++---------- 2 files changed, 376 insertions(+), 120 deletions(-) diff --git a/arch b/arch index 5336c64638..5f3f8a53bb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5336c646386607424e3426fb488d73241abb5f08 +Subproject commit 5f3f8a53bbcc0fd201bed99de4f69a6fa97597eb diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 18a67eef24..4694320d08 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -174,12 +174,20 @@ /* Flash Manufacturer JEDEC IDs */ +#define ST25FL1_JEDEC_ID_SPANSION 0x01 #define ST25FL1_JEDEC_ID_ATMEL 0x1f #define ST25FL1_JEDEC_ID_ST 0x20 #define ST25FL1_JEDEC_ID_SST 0xbf #define ST25FL1_JEDEC_ID_MACRONIX 0xc2 #define ST25FL1_JEDEC_ID_WINBOND 0xef +/* ST25FL1 JEDIC IDs */ + +#define ST25FL1_JEDEC_DEVICE_TYPE 0x40 /* ST25FL1 memory devuce type */ +#define S25FL116K_JEDEC_CAPACITY 0x15 /* S25FL116K memory capacity */ +#define S25FL132K_JEDEC_CAPACITY 0x16 /* S25FL132K memory capacity */ +#define S25FL164K_JEDEC_CAPACITY 0x17 /* S25FL164K memory capacity */ + /* ST25FL1 Registers ****************************************************************/ /* Status register bit definitions */ @@ -198,7 +206,7 @@ # define STATUS1_TB_BOTTOM (1 << 5) /* 1 = BP2-BP0 protect Bottom up */ #define STATUS1_SEC_MASK (1 << 6) /* Bit 6: Sector / Block Protect */ # define STATUS1_SEC_BLOCK (0 << 6) /* 0 = BP2-BP0 protect 64-kB blocks */ -# define STATUS1_SEC_BLOCK (1 << 6) /* 1 = BP2-BP0 protect 4-kB sectors */ +# define STATUS1_SEC_SECTOR (1 << 6) /* 1 = BP2-BP0 protect 4-kB sectors */ #define STATUS1_SRP0_MASK (1 << 7) /* Bit 7: Status register protect 0 */ # define STATUS1_SRP0_UNLOCKED (0 << 7) /* 0 = WP# no effect / PS Lock Down */ # define STATUS1_SRP0_LOCKED (1 << 7) /* 1 = WP# protect / OTP Lock Down */ @@ -238,12 +246,15 @@ /* All members of the family support uniform 4K-byte sectors */ #define S25FL116K_SECTOR_SIZE (4*1024) +#define S25FL116K_SECTOR_SHIFT (12) #define S25FL116K_SECTOR_COUNT (512) #define S25FL132K_SECTOR_SIZE (4*1024) +#define S25FL163K_SECTOR_SHIFT (12) #define S25FL132K_SECTOR_COUNT (1024) #define S25FL164K_SECTOR_SIZE (4*1024) +#define S25FL164K_SECTOR_SHIFT (12) #define S25FL164K_SECTOR_COUNT (2048) /* Cache flags **********************************************************************/ @@ -276,8 +287,9 @@ struct st25fl1_dev_s { struct mtd_dev_s mtd; /* MTD interface */ - FAR struct spi_dev_s *qspi; /* Saved QuadSPI interface instance */ + FAR struct qspi_dev_s *qspi; /* Saved QuadSPI interface instance */ uint16_t nsectors; /* Number of erase sectors */ + uint8_t sectorshift; /* Log2 of sector size */ #ifdef CONFIG_ST25FL1_SECTOR512 uint8_t flags; /* Buffered sector flags */ @@ -290,39 +302,54 @@ struct st25fl1_dev_s * Private Function Prototypes ************************************************************************************/ -/* Helpers */ +/* Locking */ + +static void st25fl1_lock(FAR struct qspi_dev_s *qspi); +static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi); -static void st25fl1_lock(FAR struct spi_dev_s *qspi); -static inline void st25fl1_unlock(FAR struct spi_dev_s *qspi); -static inline int st25fl1_readid(FAR struct st25fl1_dev_s *priv); +/* Low-level message helpers */ + +static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd); +static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, + off_t address); +static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR void *buffer, size_t buflen); +static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR const void *buffer, size_t buflen); +static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi); +static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi); +static uint8_t sf25fl1_read_status3(FAR struct qspi_dev_s *qspi); +static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi); +static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi); + +static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); static uint8_t st25fl1_waitwritecomplete(FAR struct st25fl1_dev_s *priv); -static inline void st25fl1_wren(FAR struct st25fl1_dev_s *priv); -static inline void st25fl1_wrdi(FAR struct st25fl1_dev_s *priv); -static void st25fl1_sectorerase(FAR struct st25fl1_dev_s *priv, off_t offset); -static inline int st25fl1_chiperase(FAR struct st25fl1_dev_s *priv); -static void st25fl1_byteread(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, - off_t address, size_t nbytes); -static void st25fl1_pagewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, - off_t address, size_t nbytes); +static int st25fl1_erase_sector(FAR struct st25fl1_dev_s *priv, off_t offset); +static int st25fl1_erase_chip(FAR struct st25fl1_dev_s *priv); +static void st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t nbytes); +static void st25fl1_write_page(FAR struct st25fl1_dev_s *priv, + FAR const uint8_t *buffer, off_t address, size_t nbytes); #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_cacheflush(struct st25fl1_dev_s *priv); -static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector); -static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector); -static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, - off_t sector, size_t nsectors); +static void st25fl1_flush_cache(struct st25fl1_dev_s *priv); +static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector); +static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector); +static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, + FAR const uint8_t *buffer, off_t sector, size_t nsectors); #endif /* MTD driver methods */ -static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); +static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks); static ssize_t st25fl1_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 st25fl1_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 st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer); -static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); + FAR uint8_t *buffer); +static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); /************************************************************************************ * Private Data @@ -336,7 +363,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); * Name: st25fl1_lock ************************************************************************************/ -static void st25fl1_lock(FAR struct spi_dev_s *qspi) +static void st25fl1_lock(FAR struct qspi_dev_s *qspi) { /* On QuadSPI busses where there are multiple devices, it will be necessary to * lock QuadSPI to have exclusive access to the busses for a sequence of @@ -363,42 +390,189 @@ static void st25fl1_lock(FAR struct spi_dev_s *qspi) * Name: st25fl1_unlock ************************************************************************************/ -static inline void st25fl1_unlock(FAR struct spi_dev_s *qspi) +static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi) { (void)QSPI_LOCK(qspi, false); } +/************************************************************************************ + * Name: st25fl1_command + ************************************************************************************/ + +static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) +{ + /* This function just allows us to insert debug output */ + + fvdbg("CMD: %02x\n", cmd); + return QSPI_COMMAND(qspi, (uint16_t)cmd); +} + +/************************************************************************************ + * Name: st25fl1_command_read + ************************************************************************************/ + +static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR void *buffer, size_t buflen) +{ + /* This function just allows us to insert debug output */ + + fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); + return QSPI_COMMAND_READ(qspi, (uint16_t)cmd, buffer, buflen); +} + +/************************************************************************************ + * Name: st25fl1_command_write + ************************************************************************************/ + +static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR const void *buffer, size_t buflen) +{ + /* This function just allows us to insert debug output */ + + fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); + return QSPI_COMMAND_WRITE(qspi, (uint16_t)cmd, buffer, buflen); +} + +/************************************************************************************ + * Name: sf25fl1_read_status1 + ************************************************************************************/ + +static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi) +{ + uint8_t status; + + DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS1, + (FAR void *)&status, 1)); + return status; +} + +/************************************************************************************ + * Name: sf25fl1_read_status2 + ************************************************************************************/ + +static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi) +{ + uint8_t status; + + DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS2, + (FAR void *)&status, 1)); + return status; +} + +/************************************************************************************ + * Name: sf25fl1_read_status3 + ************************************************************************************/ + +static uint8_t sf25fl1_read_status3(FAR struct qspi_dev_s *qspi) +{ + uint8_t status; + + DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS3, + (FAR void *)&status, 1)); + return status; +} + +/************************************************************************************ + * Name: st25fl1_write_enable + ************************************************************************************/ + +static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi) +{ + uint8_t status; + + do + { + st25fl1_command(qspi, ST25FL1_WRITE_ENABLE); + status = sf25fl1_read_status1(qspi); + } + while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_ENABLED); +} + +/************************************************************************************ + * Name: st25fl1_write_disable + ************************************************************************************/ + +static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi) +{ + uint8_t status; + + do + { + st25fl1_command(qspi, ST25FL1_WRITE_DISABLE); + status = sf25fl1_read_status1(qspi); + } + while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_DISABLED); +} + +/************************************************************************************ + * Name: st25fl1_write_status + ************************************************************************************/ + +static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[3]) +{ + st25fl1_write_enable(qspi); + st25fl1_command_write(qspi, ST25FL1_WRITE_STATUS, (FAR const void *)status, 3); + st25fl1_write_disable(qspi); +} + /************************************************************************************ * Name: st25fl1_readid ************************************************************************************/ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) { - uint16_t manufacturer; - uint16_t memory; - uint16_t capacity; - - fvdbg("priv: %p\n", priv); + uint8_t jedecid[3]; /* Lock the QuadSPI bus and configure the bus. */ st25fl1_lock(priv->qspi); -#warning Missing Logic + /* Read the JEDEC ID */ + + st25fl1_command_read(priv->qspi, ST25FL1_JEDEC_ID, jedecid, 3); /* Unlock the bus */ st25fl1_unlock(priv->qspi); - fvdbg("manufacturer: %02x memory: %02x capacity: %02x\n", - manufacturer, memory, capacity); + fvdbg("Manufacturer: %02x Device Type %02x, Capacity: %02x", + jedecid[0], jedecid[1], jedecid[2]); - /* Check for a valid manufacturer and memory type */ -#warning Missing Logic + /* Check for a recognized memory device type */ + + if (jedecid[1] != ST25FL1_JEDEC_DEVICE_TYPE) + { + fdbg("ERROR: Unrecognized device type: %02x\n", jedecid[1]); + return -ENODEV; + } - /* We don't understand the manufacturer or the memory type */ + /* Check for a supported capacity */ + + switch (jedecid[2]) + { + case S25FL116K_JEDEC_CAPACITY: + priv->sectorshift = S25FL116K_SECTOR_SHIFT; + priv->nsectors = S25FL116K_SECTOR_COUNT; + break; + + case S25FL132K_JEDEC_CAPACITY: + priv->sectorshift = S25FL163K_SECTOR_SHIFT; + priv->nsectors = S25FL132K_SECTOR_COUNT; + break; - return -ENODEV; + case S25FL164K_JEDEC_CAPACITY: + priv->sectorshift = S25FL164K_SECTOR_SHIFT; + priv->nsectors = S25FL164K_SECTOR_COUNT; + break; + + /* Support for this part is not implemented yet */ + + default: + fdbg("ERROR: Unsupported memory capacity: %02x\n", jedecid[2]); + return -ENODEV; + } + + return OK; } /************************************************************************************ @@ -424,54 +598,93 @@ static uint8_t st25fl1_waitwritecomplete(struct st25fl1_dev_s *priv) { #warning Missing Logic } - while ((status & ST25FL1_SR_BUSY) != 0); + while ((status & STATUS1_BUSY_MASK) == STATUS1_BUSY); return status; } /************************************************************************************ - * Name: st25fl1_wren + * Name: st25fl1_erase_sector ************************************************************************************/ -static inline void st25fl1_wren(struct st25fl1_dev_s *priv) +static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) { -#warning Missing Logic -} +#ifdef CONFIG_DEBUG + uint8_t status; +#endif -/************************************************************************************ - * Name: st25fl1_wrdi - ************************************************************************************/ + fvdbg("sector: %08lx\n", (unsigned long)sector); -static inline void st25fl1_wrdi(struct st25fl1_dev_s *priv) -{ -#warning Missing Logic -} +#ifdef CONFIG_DEBUG + /* Check that the flash is ready and unprotected */ -/************************************************************************************ - * Name: st25fl1_sectorerase - ************************************************************************************/ + status = sf25fl1_read_status1(priv->qspi); + if ((status & STATUS1_BUSY_MASK) != STATUS1_READY) + { + fdbg("ERROR: Flash busy: %02x", status); + return -EBUSY; + } -static void st25fl1_sectorerase(struct st25fl1_dev_s *priv, off_t sector) -{ - fvdbg("sector: %08lx\n", (long)sector); -#warning Missing Logic + if ((status & STATUS1_BP_MASK) != 0) + { + fdbg("ERROR: Flash protected: %02x", status); + /* REVISIT: Should check if this particular sector is protected */ + //return -EACCES; + } +#endif + + /* Send the sector erase command */ + + st25fl1_write_enable(priv->qspi); + st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, sector); + + /* Wait for erasure to finish */ + + while ((sf25fl1_read_status1(priv->qspi) & STATUS1_BUSY_MASK) != 0); + return OK; } /************************************************************************************ - * Name: st25fl1_chiperase + * Name: st25fl1_erase_chip ************************************************************************************/ -static inline int st25fl1_chiperase(struct st25fl1_dev_s *priv) +static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) { - fvdbg("priv: %p\n", priv); -#warning Missing Logic + uint8_t status; + +#ifdef CONFIG_DEBUG + /* Check if the FLASH is protected */ + + status = sf25fl1_read_status1(priv->qspi); + if ((status & STATUS1_BP_MASK) != 0) + { + fdbg("ERROR: FLASH is Protected: %02x", status); + return -EACCES; + } +#endif + + /* Erase the whole chip */ + + st25fl1_write_enable(priv->qspi); + st25fl1_command(priv->qspi, ST25FL1_CHIP_ERASE_2); + + /* Wait for the erasure to complete */ + + status = sf25fl1_read_status1(priv->qspi); + while ((status & STATUS1_BUSY_MASK) != 0) + { + usleep(200*1000); + status = sf25fl1_read_status1(priv->qspi); + } + + return OK; } /************************************************************************************ - * Name: st25fl1_byteread + * Name: st25fl1_read_byte ************************************************************************************/ -static void st25fl1_byteread(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, +static void st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, off_t address, size_t nbytes) { fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)nbytes); @@ -479,10 +692,10 @@ static void st25fl1_byteread(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer } /************************************************************************************ - * Name: st25fl1_pagewrite + * Name: st25fl1_write_page ************************************************************************************/ -static void st25fl1_pagewrite(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, +static void st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t address, size_t nbytes) { fvdbg("address: %08lx nwords: %d\n", (long)address, (int)nbytes); @@ -490,11 +703,11 @@ static void st25fl1_pagewrite(struct st25fl1_dev_s *priv, FAR const uint8_t *buf } /************************************************************************************ - * Name: st25fl1_cacheflush + * Name: st25fl1_flush_cache ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_cacheflush(struct st25fl1_dev_s *priv) +static void st25fl1_flush_cache(struct st25fl1_dev_s *priv) { /* If the cached is dirty (meaning that it no longer matches the old FLASH contents) * or was erased (with the cache containing the correct FLASH contents), then write @@ -515,11 +728,11 @@ static void st25fl1_cacheflush(struct st25fl1_dev_s *priv) #endif /************************************************************************************ - * Name: st25fl1_cacheread + * Name: st25fl1_read_cache ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector) +static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) { off_t esectno; int shift; @@ -530,7 +743,7 @@ static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector) * shift to the right by 3 to get the sector number in 4096 increments. */ - shift = ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT; + shift = priv->sectorshift - ST25FL1_SECTOR512_SHIFT; esectno = sector >> shift; fvdbg("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift); @@ -540,11 +753,12 @@ static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector) { /* No.. Flush any dirty erase block currently in the cache */ - st25fl1_cacheflush(priv); + st25fl1_flush_cache(priv); /* Read the erase block into the cache */ - st25fl1_byteread(priv, priv->sector, (esectno << ST25FL1_SECTOR_SHIFT), ST25FL1_SECTOR_SIZE); + st25fl1_read_byte(priv, priv->sector, (esectno << priv->sectorshift) + (1 << priv->sectorshift)); /* Mark the sector as cached */ @@ -566,11 +780,11 @@ static FAR uint8_t *st25fl1_cacheread(struct st25fl1_dev_s *priv, off_t sector) #endif /************************************************************************************ - * Name: st25fl1_cacheerase + * Name: st25fl1_erase_cache ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector) +static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) { FAR uint8_t *dest; @@ -578,7 +792,7 @@ static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector) * the cache. */ - dest = st25fl1_cacheread(priv, sector); + dest = st25fl1_read_cache(priv, sector); /* Erase the block containing this sector if it is not already erased. * The erased indicated will be cleared when the data from the erase sector @@ -587,10 +801,10 @@ static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector) if (!IS_ERASED(priv)) { - off_t esectno = sector >> (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); + off_t esectno = sector >> (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); fvdbg("sector: %ld esectno: %d\n", sector, esectno); - st25fl1_sectorerase(priv, esectno); + DEBUGVERIFY(st25fl1_erase_sector(priv, esectno)); SET_ERASED(priv); } @@ -605,11 +819,11 @@ static void st25fl1_cacheerase(struct st25fl1_dev_s *priv, off_t sector) #endif /************************************************************************************ - * Name: st25fl1_cachewrite + * Name: st25fl1_write_cache ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, +static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t sector, size_t nsectors) { FAR uint8_t *dest; @@ -620,7 +834,7 @@ static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t * memory. */ - dest = st25fl1_cacheread(priv, sector); + dest = st25fl1_read_cache(priv, sector); /* Erase the block containing this sector if it is not already erased. * The erased indicated will be cleared when the data from the erase sector @@ -629,10 +843,10 @@ static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t if (!IS_ERASED(priv)) { - off_t esectno = sector >> (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); + off_t esectno = sector >> (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); fvdbg("sector: %ld esectno: %d\n", sector, esectno); - st25fl1_sectorerase(priv, esectno); + DEBUGVERIFY(st25fl1_erase_sector(priv, esectno)); SET_ERASED(priv); } @@ -649,7 +863,7 @@ static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t /* Flush the last erase block left in the cache */ - st25fl1_cacheflush(priv); + st25fl1_flush_cache(priv); } #endif @@ -660,19 +874,44 @@ static void st25fl1_cachewrite(FAR struct st25fl1_dev_s *priv, FAR const uint8_t static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) { FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + size_t blocksleft = nblocks; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); -#warning Missing Logic + /* Lock access to the SPI bus until we complete the erase */ + + st25fl1_lock(priv->qspi); + + while (blocksleft-- > 0) + { + /* Erase each sector */ + +#ifdef CONFIG_S25FL1_SECTOR512 + st25fl1_erase_cache(priv, startblock); +#else + st25fl1_erase_sector(priv, startblock); +#endif + startblock++; + } + +#ifdef CONFIG_S25FL1_SECTOR512 + /* Flush the last erase block left in the cache */ + + st25fl1_flush_cache(priv); +#endif + + st25fl1_unlock(priv->qspi); + return (int)nblocks; } /************************************************************************************ * Name: st25fl1_bread ************************************************************************************/ -static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buffer) +static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buffer) { + FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; ssize_t nbytes; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); @@ -680,16 +919,18 @@ static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t /* On this device, we can handle the block read just like the byte-oriented read */ #ifdef CONFIG_ST25FL1_SECTOR512 - nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR512_SHIFT, nblocks << ST25FL1_SECTOR512_SHIFT, buffer); + nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR512_SHIFT, + nblocks << ST25FL1_SECTOR512_SHIFT, buffer); if (nbytes > 0) { nbytes >>= ST25FL1_SECTOR512_SHIFT; } #else - nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR_SHIFT, nblocks << ST25FL1_SECTOR_SHIFT, buffer); + nbytes = st25fl1_read(dev, startblock << priv->sectorshift, + nblocks << priv->sectorshift, buffer); if (nbytes > 0) { - nbytes >>= ST25FL1_SECTOR_SHIFT; + nbytes >>= priv->sectorshift; } #endif @@ -700,8 +941,8 @@ static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t * Name: st25fl1_bwrite ************************************************************************************/ -static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR const uint8_t *buffer) +static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buffer) { FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; @@ -712,10 +953,10 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_ st25fl1_lock(priv->qspi); #if defined(CONFIG_ST25FL1_SECTOR512) - st25fl1_cachewrite(priv, buffer, startblock, nblocks); + st25fl1_write_cache(priv, buffer, startblock, nblocks); #else - st25fl1_pagewrite(priv, buffer, startblock << ST25FL1_SECTOR_SHIFT, - nblocks << ST25FL1_SECTOR_SHIFT); + st25fl1_write_page(priv, buffer, startblock << priv->sectorshift, + nblocks << priv->sectorshift); #endif st25fl1_unlock(priv->qspi); @@ -736,7 +977,7 @@ static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbyt /* Lock the QuadSPI bus and select this FLASH part */ st25fl1_lock(priv->qspi); - st25fl1_byteread(priv, buffer, offset, nbytes); + st25fl1_read_byte(priv, buffer, offset, nbytes); st25fl1_unlock(priv->qspi); fvdbg("return nbytes: %d\n", (int)nbytes); @@ -758,7 +999,9 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { case MTDIOC_GEOMETRY: { - FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + FAR struct mtd_geometry_s *geo = + (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) { /* Populate the geometry structure with information need to know @@ -773,10 +1016,10 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) #ifdef CONFIG_ST25FL1_SECTOR512 geo->blocksize = (1 << ST25FL1_SECTOR512_SHIFT); geo->erasesize = (1 << ST25FL1_SECTOR512_SHIFT); - geo->neraseblocks = priv->nsectors << (ST25FL1_SECTOR_SHIFT - ST25FL1_SECTOR512_SHIFT); + geo->neraseblocks = priv->nsectors << (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); #else - geo->blocksize = ST25FL1_SECTOR_SIZE; - geo->erasesize = ST25FL1_SECTOR_SIZE; + geo->blocksize = (1 << priv->sectorshift); + geo->erasesize = (1 << priv->sectorshift); geo->neraseblocks = priv->nsectors; #endif ret = OK; @@ -789,11 +1032,11 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) case MTDIOC_BULKERASE: { - /* Erase the entire device */ + /* Erase the entire device */ - st25fl1_lock(priv->qspi); - ret = st25fl1_chiperase(priv); - st25fl1_unlock(priv->qspi); + st25fl1_lock(priv->qspi); + ret = st25fl1_erase_chip(priv); + st25fl1_unlock(priv->qspi); } break; @@ -821,9 +1064,10 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ************************************************************************************/ -FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *qspi) +FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) { FAR struct st25fl1_dev_s *priv; + uint8_t status[3]; int ret; fvdbg("qspi: %p\n", qspi); @@ -856,30 +1100,42 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct spi_dev_s *qspi) { /* Unrecognized! Discard all of that work we just did and return NULL */ - fdbg("Unrecognized\n"); + fdbg("ERROR Unrecognized QSPI device\n"); kmm_free(priv); - priv = NULL; + return NULL; } - else + + /* Enable quad mode */ + + status[0] = sf25fl1_read_status1(priv->qspi); + status[1] = sf25fl1_read_status2(priv->qspi); + status[2] = sf25fl1_read_status3(priv->qspi); + + while ((status[1] & STATUS2_QUAD_ENABLE_MASK) == 0) { - /* Make sure that the FLASH is unprotected so that we can write into it */ + status[1] |= STATUS2_QUAD_ENABLE; + st25fl1_write_status(priv->qspi, status); + status[1] = sf25fl1_read_status2(priv->qspi); + usleep(50*1000); + } - st25fl1_unprotect(priv); + /* Make sure that the FLASH is unprotected so that we can write into it */ + + st25fl1_unprotect(priv); #ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ - /* Allocate a buffer for the erase block cache */ + /* Allocate a buffer for the erase block cache */ - priv->sector = (FAR uint8_t *)kmm_malloc(ST25FL1_SECTOR_SIZE); - if (!priv->sector) - { - /* Allocation failed! Discard all of that work we just did and return NULL */ + priv->sector = (FAR uint8_t *)kmm_malloc((1 << priv->sectorshift)); + if (!priv->sector) + { + /* Allocation failed! Discard all of that work we just did and return NULL */ - fdbg("Allocation failed\n"); - kmm_free(priv); - priv = NULL; - } -#endif + fdbg("ERROR: Allocation failed\n"); + kmm_free(priv); + return NULL; } +#endif } #ifdef CONFIG_MTD_REGISTRATION -- GitLab From a268e0aeb9ff9a15ea1bcd05ecf0ff299f85cbbc Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Wed, 26 Aug 2015 18:12:58 -0600 Subject: [PATCH 089/858] Fix a typo from an earlier commit --- configs | 2 +- drivers/net/loopback.c | 2 +- net/netdev/netdev_rxnotify.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configs b/configs index e1e1873700..0198c46e0b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e1e1873700ffda7aeb632e2b1234333d88ce3457 +Subproject commit 0198c46e0bd38d2a7fada9e4a1ea445218284c61 diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index ddaa8a5a1c..0ba2caae44 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -111,7 +111,7 @@ struct lo_driver_s static struct lo_driver_s g_loopback; #ifdef CONFIG_NET_MULTIBUFFER -static uint8_t g_iobuffer[[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; +static uint8_t g_iobuffer[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; #endif /**************************************************************************** diff --git a/net/netdev/netdev_rxnotify.c b/net/netdev/netdev_rxnotify.c index 824c78f89c..afef07e545 100644 --- a/net/netdev/netdev_rxnotify.c +++ b/net/netdev/netdev_rxnotify.c @@ -79,7 +79,7 @@ * * Description: * Notify the device driver that forwards the IPv4 address that the - * application waits for RX data. + * application waits for RX data. * * Parameters: * lipaddr - The local board IPv6 address of the socket -- GitLab From 007aabc46f63a528155d9fdad56e813ed4ed33e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 19:18:04 -0600 Subject: [PATCH 090/858] Fix a badly formatted comment --- net/tcp/tcp_conn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index fd411cf8dc..32ea2d6901 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -1238,8 +1238,9 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) goto errout_with_lock; } - /* Set up the local address (laddr) and the remote address (raddr) that describes the TCP connection. - */ + /* Set up the local address (laddr) and the remote address (raddr) that + * describes the TCP connection. + */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 -- GitLab From 3bcdb218ff2429bae3023f515d7b030948d54e06 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 08:39:17 -0600 Subject: [PATCH 091/858] Networking: Get rid of the tcp_mss macro. It is confusing and only obfuscates what is really going on --- arch | 2 +- net/Kconfig | 2 +- net/devif/devif.h | 4 ++-- net/socket/net_sendfile.c | 4 ++-- net/tcp/tcp.h | 6 ------ net/tcp/tcp_send_buffered.c | 4 ++-- net/tcp/tcp_send_unbuffered.c | 12 ++++++------ 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/arch b/arch index 5336c64638..3077bd096b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5336c646386607424e3426fb488d73241abb5f08 +Subproject commit 3077bd096b77a5a49ff80cc460dc024fe69cb078 diff --git a/net/Kconfig b/net/Kconfig index f7e5f67cfa..b13a38351c 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -102,7 +102,7 @@ config NET_SLIP_MTU bytes of data: 40 + 128. I believe that is to allow for the 2x worst cast packet expansion. Ideally we would like to advertise the 256 MSS, but restrict transfers to 128 bytes (possibly by modifying - the tcp_mss() macro). + the MSS value in the TCP connection structure). config NET_SLIP_TCP_RECVWNDO diff --git a/net/devif/devif.h b/net/devif/devif.h index d4ecdd023f..a7c26d3437 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -423,8 +423,8 @@ uint16_t devif_dev_event(FAR struct net_driver_s *dev, void *pvconn, * The amount of data that actually is sent out after a call to this * function is determined by the maximum amount of data TCP allows. uIP * will automatically crop the data so that only the appropriate - * amount of data is sent. The function tcp_mss() can be used to query - * uIP for the amount of data that actually will be sent. + * amount of data is sent. The mss field of the TCP connection structure + * can be used to determine the amount of data that actually will be sent. * * Note: This function does not guarantee that the sent data will * arrive at the destination. If the data is lost in the network, the diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 2f6c3c9bb5..443a66357d 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -354,9 +354,9 @@ static uint16_t sendfile_interrupt(FAR struct net_driver_s *dev, FAR void *pvcon uint32_t sndlen = pstate->snd_flen - pstate->snd_sent; - if (sndlen > tcp_mss(conn)) + if (sndlen > conn->mss) { - sndlen = tcp_mss(conn); + sndlen = conn->mss; } /* Check if we have "space" in the window */ diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 7e958b6006..759b50deb8 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -101,12 +101,6 @@ devif_conn_callback_free(g_netdevices, cb, NULL) #endif -/* Get the current maximum segment size that can be sent on the current - * TCP connection. - */ - -#define tcp_mss(conn) ((conn)->mss) - #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* TCP write buffer access macros */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index d8ea4a66b7..3044b5f030 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -697,9 +697,9 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, */ sndlen = WRB_PKTLEN(wrb) - WRB_SENT(wrb); - if (sndlen > tcp_mss(conn)) + if (sndlen > conn->mss) { - sndlen = tcp_mss(conn); + sndlen = conn->mss; } if (sndlen > conn->winsize) diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 9526332424..b8052a1ec7 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -442,12 +442,12 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, if (sndlen >= CONFIG_NET_TCP_SPLIT_SIZE) { /* sndlen is the number of bytes remaining to be sent. - * tcp_mss(conn) will return the number of bytes that can sent + * conn->mss will provide the number of bytes that can sent * in one packet. The difference, then, is the number of bytes * that would be sent in the next packet after this one. */ - int32_t next_sndlen = sndlen - tcp_mss(conn); + int32_t next_sndlen = sndlen - conn->mss; /* Is this the even packet in the packet pair transaction? */ @@ -474,13 +474,13 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, { /* Will there be another (even) packet afer this one? * (next_sndlen > 0) Will the split condition occur on that - * next, even packet? ((next_sndlen - tcp_mss(conn)) < 0) If + * next, even packet? ((next_sndlen - conn->mss) < 0) If * so, then perform the split now to avoid the case where the * byte count is less than CONFIG_NET_TCP_SPLIT_SIZE on the * next pair. */ - if (next_sndlen > 0 && (next_sndlen - tcp_mss(conn)) < 0) + if (next_sndlen > 0 && (next_sndlen - conn->mss) < 0) { /* Here, we know that sndlen must be MSS < sndlen <= 2*MSS * and so (sndlen / 2) is <= MSS. @@ -497,9 +497,9 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, #endif /* CONFIG_NET_TCP_SPLIT */ - if (sndlen > tcp_mss(conn)) + if (sndlen > conn->mss) { - sndlen = tcp_mss(conn); + sndlen = conn->mss; } /* Check if we have "space" in the window */ -- GitLab From b1e09d4847693daa480d16a12ee69cfa48febc9a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 09:06:46 -0600 Subject: [PATCH 092/858] net/socket and net/tcp: Fix a problem in whent there are multiple network devices. Polls were being sent to all TCP sockets before. This is not good because it means that packets may sometimes be sent out on the wrong device. That is inefficient because it will cause retransmissions and bad performance. But, worse, when one of the devices is not Ethernet, it will have a different MSS and, as a result, incorrect data transfers can cause crashes. The fix is to lock into a single device once the MSS is locked locked down. --- ChangeLog | 9 +++++++++ net/socket/connect.c | 26 ++++++++++++++++++-------- net/socket/net_sendfile.c | 12 ++++++++++++ net/tcp/tcp_conn.c | 14 ++++++++++++++ net/tcp/tcp_send_buffered.c | 12 ++++++++++++ net/tcp/tcp_send_unbuffered.c | 12 ++++++++++++ 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2bda7e474b..cc6e9cd57a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10883,4 +10883,13 @@ SaeHie Park (2015-08-25). * drivers/rwbuffer.c: Fix some logic errors. From Dmitry Nikolaev via Juha Niskanen (2015-08-26). + * net/socket and net/tcp: Fix a problem in whent there are multiple + network devices. Polls were being sent to all TCP sockets before. + This is not good because it means that packets may sometimes be + sent out on the wrong device. That is inefficient because it + will cause retransmissions and bad performance. But, worse, when + one of the devices is not Ethernet, it will have a different MSS + and, as a result, incorrect data transfers can cause crashes. + The fix is to lock into a single device once the MSS is locked + locked down (2015-08-27). diff --git a/net/socket/connect.c b/net/socket/connect.c index 77443a775e..00e2db1e05 100644 --- a/net/socket/connect.c +++ b/net/socket/connect.c @@ -278,22 +278,32 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (pstate->tc_conn->domain == PF_INET) + if (pstate->tc_conn->domain == PF_INET) #endif - { - pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev); - } + { + pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev); + } #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else + else #endif - { - pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev); - } + { + pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev); + } #endif /* CONFIG_NET_IPv6 */ +#ifdef CONFIG_NETDEV_MULTINIC + /* We now have to filter all outgoing transfers so that they use only + * the MSS of this device. + */ + + DEBUGASSERT(pstate->tc_conn->dev == NULL || + pstate->tc_conn->dev == dev); + pstate->tc_conn->dev = dev; + +#endif /* CONFIG_NETDEV_MULTINIC */ #endif /* CONFIG_NET_MULTILINK */ /* Wake up the waiting thread */ diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 443a66357d..9bb413cefd 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -324,6 +324,18 @@ static uint16_t sendfile_interrupt(FAR struct net_driver_s *dev, FAR void *pvcon FAR struct sendfile_s *pstate = (FAR struct sendfile_s *)pvpriv; int ret; +#ifdef CONFIG_NETDEV_MULTINIC + /* The TCP socket is connected and, hence, should be bound to a device. + * Make sure that the polling device is the own that we are bound to. + */ + + DEBUGASSERT(conn->dev != NULL); + if (dev != conn->dev) + { + return flags; + } +#endif + nllvdbg("flags: %04x acked: %d sent: %d\n", flags, pstate->snd_acked, pstate->snd_sent); diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 32ea2d6901..f6e33e6ac0 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -1003,6 +1003,13 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, net_ipv6addr_copy(conn->u.ipv6.raddr, ip->srcipaddr); #ifdef CONFIG_NETDEV_MULTINIC net_ipv6addr_copy(conn->u.ipv6.laddr, ip->destipaddr); + + /* We now have to filter all outgoing transfers so that they use + * only the MSS of this device. + */ + + DEBUGASSERT(conn->dev == NULL || conn->dev == dev); + conn->dev = dev; #endif /* Find the device that can receive packets on the network @@ -1028,6 +1035,13 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, #ifdef CONFIG_NETDEV_MULTINIC net_ipv4addr_copy(conn->u.ipv4.laddr, net_ip4addr_conv32(ip->destipaddr)); + + /* We now have to filter all outgoing transfers so that they use + * only the MSS of this device. + */ + + DEBUGASSERT(conn->dev == NULL || conn->dev == dev); + conn->dev = dev; #endif /* Find the device that can receive packets on the network diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 3044b5f030..34e9100ad0 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -338,6 +338,18 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct socket *psock = (FAR struct socket *)pvpriv; +#ifdef CONFIG_NETDEV_MULTINIC + /* The TCP socket is connected and, hence, should be bound to a device. + * Make sure that the polling device is the own that we are bound to. + */ + + DEBUGASSERT(conn->dev != NULL); + if (dev != conn->dev) + { + return flags; + } +#endif + nllvdbg("flags: %04x\n", flags); /* If this packet contains an acknowledgement, then update the count of diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index b8052a1ec7..efffe4793f 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -290,6 +290,18 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct send_s *pstate = (FAR struct send_s *)pvpriv; +#ifdef CONFIG_NETDEV_MULTINIC + /* The TCP socket is connected and, hence, should be bound to a device. + * Make sure that the polling device is the own that we are bound to. + */ + + DEBUGASSERT(conn->dev != NULL); + if (dev != conn->dev) + { + return flags; + } +#endif + nllvdbg("flags: %04x acked: %d sent: %d\n", flags, pstate->snd_acked, pstate->snd_sent); -- GitLab From 63071a563a1f7646dab9a6bd718d8b4b550471c4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 10:38:43 -0600 Subject: [PATCH 093/858] Costmetic changes --- net/socket/net_monitor.c | 18 ++++++++++++++++ net/socket/recvfrom.c | 45 +++++++++++++++++++++++++++------------- net/tcp/tcp_listen.c | 2 +- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/net/socket/net_monitor.c b/net/socket/net_monitor.c index a57308cbcc..ed2f0acc53 100644 --- a/net/socket/net_monitor.c +++ b/net/socket/net_monitor.c @@ -163,6 +163,24 @@ static uint16_t connection_event(FAR struct net_driver_s *dev, else if ((flags & TCP_CONNECTED) != 0) { +#if 0 /* REVISIT: Assertion fires. Why? */ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)psock->s_conn; + + /* Make sure that this is the device bound to the connection */ + + DEBUGASSERT(conn->dev == NULL || conn->dev == dev); + conn->dev = dev; +#endif +#endif + + /* If there is no local address assigned to the socket (perhaps + * because it was INADDR_ANY), then assign it the address of the + * connecting device. + * + * TODO: Implement this. + */ + /* Indicate that the socket is now connected */ psock->s_flags |= _SF_CONNECTED; diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index f6519de186..d7094d21e0 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -157,7 +157,7 @@ static inline void recvfrom_add_recvlen(FAR struct recvfrom_s *pstate, * The number of bytes taken from the packet. * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -205,7 +205,7 @@ static size_t recvfrom_newdata(FAR struct net_driver_s *dev, * None. * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -249,7 +249,7 @@ static void recvfrom_newpktdata(FAR struct net_driver_s *dev, * None. * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -321,7 +321,7 @@ static inline void recvfrom_newtcpdata(FAR struct net_driver_s *dev, * None. * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -353,7 +353,7 @@ static inline void recvfrom_newudpdata(FAR struct net_driver_s *dev, * None * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -520,7 +520,7 @@ out: * TRUE:timeout FALSE:no timeout * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -616,7 +616,7 @@ static inline void recvfrom_pktsender(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_PKT static uint16_t recvfrom_pktinterrupt(FAR struct net_driver_s *dev, - FAR void *conn, FAR void *pvpriv, + FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { struct recvfrom_s *pstate = (struct recvfrom_s *)pvpriv; @@ -744,24 +744,40 @@ static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev, * * Parameters: * dev The structure of the network driver that caused the interrupt - * conn The connection structure associated with the socket + * pvconn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * * Returned Value: * None * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ #ifdef CONFIG_NET_TCP static uint16_t recvfrom_tcpinterrupt(FAR struct net_driver_s *dev, - FAR void *conn, FAR void *pvpriv, + FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { FAR struct recvfrom_s *pstate = (struct recvfrom_s *)pvpriv; +#if 0 /* REVISIT: The assertion fires. Why? */ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; + + /* The TCP socket is connected and, hence, should be bound to a device. + * Make sure that the polling device is the own that we are bound to. + */ + + DEBUGASSERT(conn->dev == NULL || conn->dev == dev); + if (conn->dev != NULL && conn->dev != dev) + { + return flags; + } +#endif +#endif + nllvdbg("flags: %04x\n", flags); /* 'priv' might be null in some race conditions (?) */ @@ -956,7 +972,7 @@ static uint16_t recvfrom_tcpinterrupt(FAR struct net_driver_s *dev, * None * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ @@ -1049,7 +1065,8 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ * Terminate the UDP transfer. * * Parameters: - * conn The connection structure associated with the socket + * pstate - The recvfrom state structure + * result - The result of the operation * * Returned Value: * None @@ -1086,14 +1103,14 @@ static void recvfrom_udp_terminate(FAR struct recvfrom_s *pstate, int result) * * Parameters: * dev The structure of the network driver that caused the interrupt - * conn The connection structure associated with the socket + * pvconn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * * Returned Value: * None * * Assumptions: - * Running at the interrupt level + * The network is locked. * ****************************************************************************/ diff --git a/net/tcp/tcp_listen.c b/net/tcp/tcp_listen.c index dbe56b9f2a..b4990ba166 100644 --- a/net/tcp/tcp_listen.c +++ b/net/tcp/tcp_listen.c @@ -243,7 +243,7 @@ bool tcp_islistener(uint16_t portno) * Accept the new connection for the specified listening port. * * Assumptions: - * Called at interrupt level + * Called with the network locked. * ****************************************************************************/ -- GitLab From 8811681d7f6f1493e6726d9db25c0268eb827875 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 11:05:53 -0600 Subject: [PATCH 094/858] networking: Big performance improvement for local loopback driver --- drivers/net/loopback.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 0ba2caae44..aa50d035af 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -96,6 +96,7 @@ struct lo_driver_s { bool lo_bifup; /* true:ifup false:ifdown */ + bool lo_txdone; /* One RX packet was looped back */ WDOG_ID lo_polldog; /* TX poll timer */ struct work_s lo_work; /* For deferring work to the work queue */ @@ -146,8 +147,8 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); * * Description: * Check if the network has any outgoing packets ready to send. This is - * a callback from devif_poll(). devif_poll() will be called only during - * normal TX polling. + * a callback from devif_poll() or devif_timer(). devif_poll() will be + * called only during normal TX polling. * * Parameters: * dev - Reference to the NuttX driver state structure @@ -201,6 +202,8 @@ static int lo_txpoll(FAR struct net_driver_s *dev) ndbg("WARNING: Unrecognized packet type dropped: %02x\n", IPv4BUF->vhl); priv->lo_dev.d_len = 0; } + + priv->lo_txdone = true; } return 0; @@ -231,8 +234,19 @@ static void lo_poll_work(FAR void *arg) /* Perform the poll */ state = net_lock(); + priv->lo_txdone = false; (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); + /* Was something received and looped back? */ + + while (priv->lo_txdone) + { + /* Yes, poll again for more TX data */ + + priv->lo_txdone = false; + (void)devif_poll(&priv->lo_dev, lo_txpoll); + } + /* Setup the watchdog poll timer again */ (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); @@ -379,9 +393,14 @@ static void lo_txavail_work(FAR void *arg) state = net_lock(); if (priv->lo_bifup) { - /* If so, then poll the network for new XMIT data */ + do + { + /* If so, then poll the network for new XMIT data */ - (void)devif_poll(&priv->lo_dev, lo_txpoll); + priv->lo_txdone = false; + (void)devif_poll(&priv->lo_dev, lo_txpoll); + } + while (priv->lo_txdone); } net_unlock(state); -- GitLab From 361e35a7be5b60a6f8f5d69465bbf0eb52587b00 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 14:16:51 -0600 Subject: [PATCH 095/858] QSPI: Make changes to interface to better work with the SAMV71 --- arch | 2 +- drivers/mtd/st25fl1.c | 84 ++++++++++++++++++++++++++-------------- include/nuttx/spi/qspi.h | 81 +++++++++++++------------------------- 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/arch b/arch index 131d15e819..3a926c8edd 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 131d15e81914f13308331ebe10a8737bade31601 +Subproject commit 3a926c8edd68eac7b60d4430ef9d4284215e3372 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 4694320d08..61667ff184 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -311,7 +311,7 @@ static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi); static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd); static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, - off_t address); + off_t addr, uint8_t addrlen); static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR void *buffer, size_t buflen); static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, @@ -324,7 +324,6 @@ static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi); static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); -static uint8_t st25fl1_waitwritecomplete(FAR struct st25fl1_dev_s *priv); static int st25fl1_erase_sector(FAR struct st25fl1_dev_s *priv, off_t offset); static int st25fl1_erase_chip(FAR struct st25fl1_dev_s *priv); static void st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, @@ -401,10 +400,39 @@ static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi) static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) { - /* This function just allows us to insert debug output */ + struct qspi_xfrinfo_s xfrinfo; fvdbg("CMD: %02x\n", cmd); - return QSPI_COMMAND(qspi, (uint16_t)cmd); + + xfrinfo.flags = 0; + xfrinfo.addrlen = 0; + xfrinfo.cmd = cmd; + xfrinfo.buflen = 0; + xfrinfo.addr = 0; + xfrinfo.buffer = NULL; + + return QSPI_COMMAND(qspi, &xfrinfo); +} + +/************************************************************************************ + * Name: st25fl1_command_address + ************************************************************************************/ + +static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, + off_t addr, uint8_t addrlen) +{ + struct qspi_xfrinfo_s xfrinfo; + + fvdbg("CMD: %02x Address: %04lx addrlen=%d\n", cmd, (unsigned long)addr, addrlen); + + xfrinfo.flags = QSPIXFR_ADDRESS; + xfrinfo.addrlen = addrlen; + xfrinfo.cmd = cmd; + xfrinfo.buflen = 0; + xfrinfo.addr = addr; + xfrinfo.buffer = NULL; + + return QSPI_COMMAND(qspi, &xfrinfo); } /************************************************************************************ @@ -414,10 +442,18 @@ static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR void *buffer, size_t buflen) { - /* This function just allows us to insert debug output */ + struct qspi_xfrinfo_s xfrinfo; fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); - return QSPI_COMMAND_READ(qspi, (uint16_t)cmd, buffer, buflen); + + xfrinfo.flags = QSPIXFR_READDATA; + xfrinfo.addrlen = 0; + xfrinfo.cmd = cmd; + xfrinfo.buflen = buflen; + xfrinfo.addr = 0; + xfrinfo.buffer = buffer; + + return QSPI_COMMAND(qspi, &xfrinfo); } /************************************************************************************ @@ -427,10 +463,18 @@ static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR const void *buffer, size_t buflen) { - /* This function just allows us to insert debug output */ + struct qspi_xfrinfo_s xfrinfo; fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); - return QSPI_COMMAND_WRITE(qspi, (uint16_t)cmd, buffer, buflen); + + xfrinfo.flags = QSPIXFR_WRITEDATA; + xfrinfo.addrlen = 0; + xfrinfo.cmd = cmd; + xfrinfo.buflen = buflen; + xfrinfo.addr = 0; + xfrinfo.buffer = (FAR void *)buffer; + + return QSPI_COMMAND(qspi, &xfrinfo); } /************************************************************************************ @@ -584,31 +628,13 @@ static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv) #warning Missing Logic } -/************************************************************************************ - * Name: st25fl1_waitwritecomplete - ************************************************************************************/ - -static uint8_t st25fl1_waitwritecomplete(struct st25fl1_dev_s *priv) -{ - uint8_t status; - - /* Loop as long as the memory is busy with a write cycle */ - - do - { -#warning Missing Logic - } - while ((status & STATUS1_BUSY_MASK) == STATUS1_BUSY); - - return status; -} - /************************************************************************************ * Name: st25fl1_erase_sector ************************************************************************************/ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) { + off_t address; #ifdef CONFIG_DEBUG uint8_t status; #endif @@ -635,8 +661,10 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) /* Send the sector erase command */ + address = (off_t)sector << priv->sectorshift; + st25fl1_write_enable(priv->qspi); - st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, sector); + st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, address, 3); /* Wait for erasure to finish */ diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h index 127b8c8306..c306faac42 100644 --- a/include/nuttx/spi/qspi.h +++ b/include/nuttx/spi/qspi.h @@ -131,67 +131,29 @@ * Name: QSPI_COMMAND * * Description: - * Send a command to the QSPI device + * Perform one QSPI command transfer * * Input Parameters: - * dev - Device-specific state data - * cmd - The command to send. the size of the data is determined by the - * number of bits selected for the QSPI interface. + * dev - Device-specific state data + * xfrinfo - Describes the command transfer to be performed. * * Returned Value: * Zero (OK) on SUCCESS, a negated errno on value of failure * ****************************************************************************/ -#define QSPI_COMMAND(d,c) ((d)->ops->command(d,(uint16_t)c)) +#define QSPI_COMMAND(d,x) (d)->ops->command(d,x) -/**************************************************************************** - * Name: QSPI_COMMAND_WRITE - * - * Description: - * Send a command then send a block of data. - * - * Input Parameters: - * dev - Device-specific state data - * cmd - The command to send. the size of the data is determined by - * the number of bits selected for the QSPI interface. - * buffer - A pointer to the buffer of data to be sent - * buflen - the length of data to send from the buffer in number of words. - * The wordsize is determined by the number of bits-per-word - * selected for the QSPI interface. If nbits <= 8, the data is - * packed into uint8_t's; if nbits >8, the data is packed into - * uint16_t's - * - * Returned Value: - * Zero (OK) on SUCCESS, a negated errno on value of failure - * - ****************************************************************************/ +/* QSPI Transfer Flags */ -#define QSPI_COMMAND_WRITE(d,c,b,l) ((d)->ops->command_write(d,c,b,l)) +#define QSPIXFR_ADDRESS (1 << 0) /* Enable address transfer */ +#define QSPIXFR_READDATA (1 << 1) /* Enable read data transfer */ +#define QSPIXFR_WRITEDATA (1 << 2) /* Enable write data transfer */ -/**************************************************************************** - * Name: QSPI_COMMAND_READ - * - * Description: - * Receive a block of data from QSPI. Required. - * - * Input Parameters: - * dev - Device-specific state data - * cmd - The command to send. the size of the data is determined by - * the number of bits selected for the QSPI interface. - * buffer - A pointer to the buffer in which to receive data - * buflen - the length of data that can be received in the buffer in number - * of words. The wordsize is determined by the number of bits- - * per-word selected for the QSPI interface. If nbits <= 8, the - * data is packed into uint8_t's; if nbits >8, the data is packed - * into uint16_t's - * - * Returned Value: - * Zero (OK) on SUCCESS, a negated errno on value of failure - * - ****************************************************************************/ - -#define QSPI_COMMAND_READ(d,c,b,l) ((d)->ops->command_read(d,c,b,l)) +#define QSPIXFR_ISADDRESS(f) (((f) & QSPIXFR_ADDRESS) != 0) +#define QSPIXFR_ISDATA(f) (((f) & (QSPIXFR_READDATA | QSPIXFR_WRITEDATA)) != 0) +#define QSPIXFR_ISREAD(f) (((f) & QSPIXFR_READDATA) != 0) +#define QSPIXFR_ISWRITE(f) (((f) & QSPIXFR_WRITEDATA) != 0) /**************************************************************************** * Public Types @@ -207,6 +169,18 @@ enum qspi_mode_e QSPIDEV_MODE3 /* CPOL=1 CHPHA=1 */ }; +/* This structure describes one transfer */ + +struct qspi_xfrinfo_s +{ + uint8_t flags; /* See QSPIXFR_* definitions */ + uint8_t addrlen; /* Address length in bytes (if QSPIXFR_ADDRESS) */ + uint16_t cmd; /* Command */ + uint16_t buflen; /* Data buffer length in bytes (if QSPIXFR_DATA) */ + uint32_t addr; /* Address (if QSPIXFR_ADDRESS) */ + FAR void *buffer; /* Data buffer (if QSPIXFR_DATA) */ +}; + /* The QSPI vtable */ struct qspi_dev_s; @@ -216,11 +190,8 @@ struct qspi_ops_s CODE uint32_t (*setfrequency)(FAR struct qspi_dev_s *dev, uint32_t frequency); CODE void (*setmode)(FAR struct qspi_dev_s *dev, enum qspi_mode_e mode); CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits); - CODE int (*command)(FAR struct qspi_dev_s *dev, uint16_t command); - CODE int (*command_write)(FAR struct qspi_dev_s *dev, uint16_t cmd, - FAR const void *buffer, size_t buflen); - CODE int (*command_read)(FAR struct qspi_dev_s *dev, uint16_t cmd, - FAR void *buffer, size_t buflen); + CODE int (*command)(FAR struct qspi_dev_s *dev, + FAR struct qspi_xfrinfo_s *xfrinfo); }; /* QSPI private data. This structure only defines the initial fields of the -- GitLab From 70bdf682afd34364a232fc2a7144c3ea93331fa2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Aug 2015 10:15:08 -0600 Subject: [PATCH 096/858] QSPI: Add support for data vs command transfer --- arch | 2 +- include/nuttx/spi/qspi.h | 84 +++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/arch b/arch index 3a926c8edd..1a54ffc673 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3a926c8edd68eac7b60d4430ef9d4284215e3372 +Subproject commit 1a54ffc673e7fafc388b43677b2a947171437645 diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h index c306faac42..a14b622d9c 100644 --- a/include/nuttx/spi/qspi.h +++ b/include/nuttx/spi/qspi.h @@ -135,25 +135,56 @@ * * Input Parameters: * dev - Device-specific state data - * xfrinfo - Describes the command transfer to be performed. + * cmdinfo - Describes the command transfer to be performed. * * Returned Value: * Zero (OK) on SUCCESS, a negated errno on value of failure * ****************************************************************************/ -#define QSPI_COMMAND(d,x) (d)->ops->command(d,x) +#define QSPI_COMMAND(d,c) (d)->ops->command(d,c) -/* QSPI Transfer Flags */ +/* QSPI Command Transfer Flags */ -#define QSPIXFR_ADDRESS (1 << 0) /* Enable address transfer */ -#define QSPIXFR_READDATA (1 << 1) /* Enable read data transfer */ -#define QSPIXFR_WRITEDATA (1 << 2) /* Enable write data transfer */ +#define QSPICMD_ADDRESS (1 << 0) /* Bit 0: Enable address transfer */ +#define QSPICMD_READDATA (1 << 1) /* Bit 1: Enable read data transfer */ +#define QSPICMD_WRITEDATA (1 << 2) /* Bit 2: Enable write data transfer */ -#define QSPIXFR_ISADDRESS(f) (((f) & QSPIXFR_ADDRESS) != 0) -#define QSPIXFR_ISDATA(f) (((f) & (QSPIXFR_READDATA | QSPIXFR_WRITEDATA)) != 0) -#define QSPIXFR_ISREAD(f) (((f) & QSPIXFR_READDATA) != 0) -#define QSPIXFR_ISWRITE(f) (((f) & QSPIXFR_WRITEDATA) != 0) +#define QSPICMD_ISADDRESS(f) (((f) & QSPICMD_ADDRESS) != 0) +#define QSPICMD_ISDATA(f) (((f) & (QSPICMD_READDATA | QSPICMD_WRITEDATA)) != 0) +#define QSPICMD_ISREAD(f) (((f) & QSPICMD_READDATA) != 0) +#define QSPICMD_ISWRITE(f) (((f) & QSPICMD_WRITEDATA) != 0) + +/**************************************************************************** + * Name: QSPI_MEMORY + * + * Description: + * Perform one QSPI memory transfer + * + * Input Parameters: + * dev - Device-specific state data + * meminfo - Describes the memory transfer to be performed. + * + * Returned Value: + * Zero (OK) on SUCCESS, a negated errno on value of failure + * + ****************************************************************************/ + +#define QSPI_MEMORY(d,m) (d)->ops->memory(d,m) + +/* QSPI Memory Transfer Flags */ + +#define QSPIMEM_WRITE (1 << 2) /* Bit 2: Memory write data transfer */ +#define QSPIMEM_SCRAMBLE (1 << 3) /* Bit 3: Memory write data transfer */ +#define QSPIMEM_RANDOM (1 << 3) /* Bit 4: Use random key in scrambler */ + +#define QSPIMEM_ISREAD(f) (((f) & QSPIMEM_WRITE) == 0) +#define QSPIMEM_ISWRITE(f) (((f) & QSPIMEM_WRITE) != 0) +#define QSPIMEM_ISSCRAMBLE(f) (((f) & QSPIMEM_SCRAMBLE) != 0) + +#define QSPIMEM_ISRANDOM(f) \ + (((f) & (QSPIMEM_SCRAMBLE|QSPIMEM_RANDOM)) == \ + (QSPIMEM_SCRAMBLE|QSPIMEM_RANDOM)) /**************************************************************************** * Public Types @@ -169,16 +200,29 @@ enum qspi_mode_e QSPIDEV_MODE3 /* CPOL=1 CHPHA=1 */ }; -/* This structure describes one transfer */ +/* This structure describes one command transfer */ + +struct qspi_cmdinfo_s +{ + uint8_t flags; /* See QSPICMD_* definitions */ + uint8_t addrlen; /* Address length in bytes (if QSPICMD_ADDRESS) */ + uint16_t cmd; /* Command */ + uint16_t buflen; /* Data buffer length in bytes (if QSPICMD_DATA) */ + uint32_t addr; /* Address (if QSPICMD_ADDRESS) */ + FAR void *buffer; /* Data buffer (if QSPICMD_DATA) */ +}; + +/* This structure describes one memory transfer */ -struct qspi_xfrinfo_s +struct qspi_meminfo_s { - uint8_t flags; /* See QSPIXFR_* definitions */ - uint8_t addrlen; /* Address length in bytes (if QSPIXFR_ADDRESS) */ - uint16_t cmd; /* Command */ - uint16_t buflen; /* Data buffer length in bytes (if QSPIXFR_DATA) */ - uint32_t addr; /* Address (if QSPIXFR_ADDRESS) */ - FAR void *buffer; /* Data buffer (if QSPIXFR_DATA) */ + uint8_t flags; /* See QSPMEM_* definitions */ + uint8_t addrlen; /* Address length in bytes */ + uint16_t buflen; /* Data buffer length in bytes */ + uint16_t cmd; /* Memory access command */ + uint32_t addr; /* Memory Address */ + uint32_t key; /* Scrambler key */ + FAR void *buffer; /* Data buffer */ }; /* The QSPI vtable */ @@ -191,7 +235,9 @@ struct qspi_ops_s CODE void (*setmode)(FAR struct qspi_dev_s *dev, enum qspi_mode_e mode); CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits); CODE int (*command)(FAR struct qspi_dev_s *dev, - FAR struct qspi_xfrinfo_s *xfrinfo); + FAR struct qspi_cmdinfo_s *cmdinfo); + CODE int (*memory)(FAR struct qspi_dev_s *dev, + FAR struct qspi_meminfo_s *meminfo); }; /* QSPI private data. This structure only defines the initial fields of the -- GitLab From d2653ef7a858444d405af3ffc9e28546ff08c728 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Aug 2015 10:15:39 -0600 Subject: [PATCH 097/858] ST25FL1: Update for changes to QSPI interface definitions --- drivers/mtd/st25fl1.c | 78 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 61667ff184..fd571acf5b 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -248,14 +248,20 @@ #define S25FL116K_SECTOR_SIZE (4*1024) #define S25FL116K_SECTOR_SHIFT (12) #define S25FL116K_SECTOR_COUNT (512) +#define S25FL116K_PAGE_SIZE (256) +#define S25FL116K_PAGE_SHIFT (8) #define S25FL132K_SECTOR_SIZE (4*1024) -#define S25FL163K_SECTOR_SHIFT (12) +#define S25FL132K_SECTOR_SHIFT (12) #define S25FL132K_SECTOR_COUNT (1024) +#define S25FL132K_PAGE_SIZE (256) +#define S25FL132K_PAGE_SHIFT (8) #define S25FL164K_SECTOR_SIZE (4*1024) #define S25FL164K_SECTOR_SHIFT (12) #define S25FL164K_SECTOR_COUNT (2048) +#define S25FL164K_PAGE_SIZE (256) +#define S25FL164K_PAGE_SHIFT (8) /* Cache flags **********************************************************************/ @@ -290,6 +296,7 @@ struct st25fl1_dev_s FAR struct qspi_dev_s *qspi; /* Saved QuadSPI interface instance */ uint16_t nsectors; /* Number of erase sectors */ uint8_t sectorshift; /* Log2 of sector size */ + uint8_t pageshift; /* Log2 of page size */ #ifdef CONFIG_ST25FL1_SECTOR512 uint8_t flags; /* Buffered sector flags */ @@ -400,18 +407,18 @@ static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi) static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) { - struct qspi_xfrinfo_s xfrinfo; + struct qspi_cmdinfo_s cmdinfo; fvdbg("CMD: %02x\n", cmd); - xfrinfo.flags = 0; - xfrinfo.addrlen = 0; - xfrinfo.cmd = cmd; - xfrinfo.buflen = 0; - xfrinfo.addr = 0; - xfrinfo.buffer = NULL; + cmdinfo.flags = 0; + cmdinfo.addrlen = 0; + cmdinfo.cmd = cmd; + cmdinfo.buflen = 0; + cmdinfo.addr = 0; + cmdinfo.buffer = NULL; - return QSPI_COMMAND(qspi, &xfrinfo); + return QSPI_COMMAND(qspi, &cmdinfo); } /************************************************************************************ @@ -421,18 +428,18 @@ static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, off_t addr, uint8_t addrlen) { - struct qspi_xfrinfo_s xfrinfo; + struct qspi_cmdinfo_s cmdinfo; fvdbg("CMD: %02x Address: %04lx addrlen=%d\n", cmd, (unsigned long)addr, addrlen); - xfrinfo.flags = QSPIXFR_ADDRESS; - xfrinfo.addrlen = addrlen; - xfrinfo.cmd = cmd; - xfrinfo.buflen = 0; - xfrinfo.addr = addr; - xfrinfo.buffer = NULL; + cmdinfo.flags = QSPICMD_ADDRESS; + cmdinfo.addrlen = addrlen; + cmdinfo.cmd = cmd; + cmdinfo.buflen = 0; + cmdinfo.addr = addr; + cmdinfo.buffer = NULL; - return QSPI_COMMAND(qspi, &xfrinfo); + return QSPI_COMMAND(qspi, &cmdinfo); } /************************************************************************************ @@ -442,18 +449,18 @@ static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR void *buffer, size_t buflen) { - struct qspi_xfrinfo_s xfrinfo; + struct qspi_cmdinfo_s cmdinfo; fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); - xfrinfo.flags = QSPIXFR_READDATA; - xfrinfo.addrlen = 0; - xfrinfo.cmd = cmd; - xfrinfo.buflen = buflen; - xfrinfo.addr = 0; - xfrinfo.buffer = buffer; + cmdinfo.flags = QSPICMD_READDATA; + cmdinfo.addrlen = 0; + cmdinfo.cmd = cmd; + cmdinfo.buflen = buflen; + cmdinfo.addr = 0; + cmdinfo.buffer = buffer; - return QSPI_COMMAND(qspi, &xfrinfo); + return QSPI_COMMAND(qspi, &cmdinfo); } /************************************************************************************ @@ -463,18 +470,18 @@ static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR const void *buffer, size_t buflen) { - struct qspi_xfrinfo_s xfrinfo; + struct qspi_cmdinfo_s cmdinfo; fvdbg("CMD: %02x buflen: %lu\n", cmd, (unsigned long)buflen); - xfrinfo.flags = QSPIXFR_WRITEDATA; - xfrinfo.addrlen = 0; - xfrinfo.cmd = cmd; - xfrinfo.buflen = buflen; - xfrinfo.addr = 0; - xfrinfo.buffer = (FAR void *)buffer; + cmdinfo.flags = QSPICMD_WRITEDATA; + cmdinfo.addrlen = 0; + cmdinfo.cmd = cmd; + cmdinfo.buflen = buflen; + cmdinfo.addr = 0; + cmdinfo.buffer = (FAR void *)buffer; - return QSPI_COMMAND(qspi, &xfrinfo); + return QSPI_COMMAND(qspi, &cmdinfo); } /************************************************************************************ @@ -596,16 +603,19 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) { case S25FL116K_JEDEC_CAPACITY: priv->sectorshift = S25FL116K_SECTOR_SHIFT; + priv->pageshift = S25FL116K_PAGE_SHIFT; priv->nsectors = S25FL116K_SECTOR_COUNT; break; case S25FL132K_JEDEC_CAPACITY: - priv->sectorshift = S25FL163K_SECTOR_SHIFT; + priv->sectorshift = S25FL132K_SECTOR_SHIFT; + priv->pageshift = S25FL116K_PAGE_SHIFT; priv->nsectors = S25FL132K_SECTOR_COUNT; break; case S25FL164K_JEDEC_CAPACITY: priv->sectorshift = S25FL164K_SECTOR_SHIFT; + priv->pageshift = S25FL116K_PAGE_SHIFT; priv->nsectors = S25FL164K_SECTOR_COUNT; break; -- GitLab From e392471dc2b3bf864cbfd3cc01e9a90d2e599b8c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Aug 2015 12:00:06 -0600 Subject: [PATCH 098/858] QSPI interface: Add support for dual and quad read transfers; Add support for dummy read cycles. --- arch | 2 +- include/nuttx/spi/qspi.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 1a54ffc673..e6fdf9eb6a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1a54ffc673e7fafc388b43677b2a947171437645 +Subproject commit e6fdf9eb6a1e288e90a12eb3ee70a393ea30bec3 diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h index a14b622d9c..628b5bf629 100644 --- a/include/nuttx/spi/qspi.h +++ b/include/nuttx/spi/qspi.h @@ -174,12 +174,17 @@ /* QSPI Memory Transfer Flags */ -#define QSPIMEM_WRITE (1 << 2) /* Bit 2: Memory write data transfer */ -#define QSPIMEM_SCRAMBLE (1 << 3) /* Bit 3: Memory write data transfer */ -#define QSPIMEM_RANDOM (1 << 3) /* Bit 4: Use random key in scrambler */ +#define QSPIMEM_READ (0) /* Bit 2: 0=Memory read data transfer */ +#define QSPIMEM_WRITE (1 << 2) /* Bit 2: 1=Memory write data transfer */ +#define QSPIMEM_DUALIO (1 << 3) /* Bit 3: Use Dual I/O (READ only) */ +#define QSPIMEM_QUADIO (1 << 4) /* Bit 4: Use Quad I/O (READ only) */ +#define QSPIMEM_SCRAMBLE (1 << 5) /* Bit 5: Scramble data */ +#define QSPIMEM_RANDOM (1 << 6) /* Bit 6: Use random key in scrambler */ #define QSPIMEM_ISREAD(f) (((f) & QSPIMEM_WRITE) == 0) #define QSPIMEM_ISWRITE(f) (((f) & QSPIMEM_WRITE) != 0) +#define QSPIMEM_ISDUALIO(f) (((f) & QSPIMEM_DUALIO) != 0) +#define QSPIMEM_ISQUADIO(f) (((f) & QSPIMEM_QUADIO) != 0) #define QSPIMEM_ISSCRAMBLE(f) (((f) & QSPIMEM_SCRAMBLE) != 0) #define QSPIMEM_ISRANDOM(f) \ @@ -218,6 +223,7 @@ struct qspi_meminfo_s { uint8_t flags; /* See QSPMEM_* definitions */ uint8_t addrlen; /* Address length in bytes */ + uint8_t dummies; /* Number of dummy read cycles (READ only) */ uint16_t buflen; /* Data buffer length in bytes */ uint16_t cmd; /* Memory access command */ uint32_t addr; /* Memory Address */ -- GitLab From 4a1951b1921440a51806dcf85dd144f96c3d3bcd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Aug 2015 12:01:08 -0600 Subject: [PATCH 099/858] ST25FL1: Flesh out FLASH write logic --- drivers/mtd/Kconfig | 11 +++ drivers/mtd/st25fl1.c | 172 +++++++++++++++++++++++++++++++++++------- 2 files changed, 157 insertions(+), 26 deletions(-) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 717d4b199e..ea0ab7bf87 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -405,6 +405,17 @@ config ST25FL1_SECTOR512 bool "Simulate 512 byte Erase Blocks" default n +config ST25FL1_SCRAMBLE + bool "Scramble data" + default n + ---help--- + Requires drviver support for data scrambling/descrambling. + +config ST25FL1_SCRAMBLE_KEY + hex "Scramble key" + default 0x0baddead + depends on ST25FL1_SCRAMBLE + endif config MTD_SMART diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index fd571acf5b..ee25e74b22 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -333,15 +333,15 @@ static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); static int st25fl1_erase_sector(FAR struct st25fl1_dev_s *priv, off_t offset); static int st25fl1_erase_chip(FAR struct st25fl1_dev_s *priv); -static void st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, +static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, off_t address, size_t nbytes); -static void st25fl1_write_page(FAR struct st25fl1_dev_s *priv, +static int st25fl1_write_page(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t address, size_t nbytes); #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_flush_cache(struct st25fl1_dev_s *priv); +static int st25fl1_flush_cache(struct st25fl1_dev_s *priv); static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector); static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector); -static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, +static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t sector, size_t nsectors); #endif @@ -722,22 +722,98 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) * Name: st25fl1_read_byte ************************************************************************************/ -static void st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, - off_t address, size_t nbytes) +static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t buflen) { + struct qspi_meminfo_s meminfo; + fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)nbytes); -#warning Missing Logic + +#ifdef CONFIG_ST25FL1_SCRAMBLE + meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO | QSPIMEM_SCRAMBLE; +#else + meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO; +#endif + meminfo.addrlen = 3; + meminfo.dummies = 6; + meminfo.buflen = buflen; + meminfo.cmd = ST25FL1_FAST_READ_QUADIO; + meminfo.addr = address; +#ifdef CONFIG_ST25FL1_SCRAMBLE + meminfo.key = CONFIG_ST25FL1_SCRAMBLE_KEY; +#endif + meminfo.buffer = buffer; + + return QSPI_MEMORY(priv->qspi, &meminfo); } /************************************************************************************ * Name: st25fl1_write_page ************************************************************************************/ -static void st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, - off_t address, size_t nbytes) +static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t buflen) { - fvdbg("address: %08lx nwords: %d\n", (long)address, (int)nbytes); -#warning Missing Logic + struct qspi_meminfo_s meminfo; + unsigned int pagesize; + unsigned int npages; + int ret; + int i; + + fvdbg("address: %08lx buflen: %u\n", (unsigned long)address, (unsigned)buflen); + + npages = (buflen >> priv->pageshift); + pagesize = (1 << priv->pageshift); + + /* Set up non-varying parts of transfer description */ + +#ifdef CONFIG_ST25FL1_SCRAMBLE + meminfo.flags = QSPIMEM_WRITE | QSPIMEM_SCRAMBLE; +#else + meminfo.flags = QSPIMEM_WRITE; +#endif + meminfo.cmd = ST25FL1_PAGE_PROGRAM; + meminfo.addrlen = 3; + meminfo.buflen = pagesize; +#ifdef CONFIG_ST25FL1_SCRAMBLE + meminfo.key = CONFIG_ST25FL1_SCRAMBLE_KEY; +#endif + meminfo.dummies = 0; + + /* Then write each page */ + + for (i = 0; i < npages; i++) + { + /* Set up varying parts of the transfer description */ + + meminfo.addr = address; + meminfo.buffer = (void *)buffer; + + /* Write one page */ + + st25fl1_write_enable(priv->qspi); + ret = QSPI_MEMORY(priv->qspi, &meminfo); + if (ret < 0) + { + fdbg("ERROR: QSPI_MEMORY failed writing address=%06x\n", + address) + return ret; + } + + /* Update for the next time through the loop */ + + buffer += pagesize; + address += pagesize; + buflen -= pagesize; + } + + /* The transfer should always be an even number of sectors and hence also + * pages. There should be no remainder. + */ + + DEBUGASSERT(buflen == 0); + st25fl1_write_disable(priv->qspi); + return OK; } /************************************************************************************ @@ -745,7 +821,7 @@ static void st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *bu ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_flush_cache(struct st25fl1_dev_s *priv) +static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) { /* If the cached is dirty (meaning that it no longer matches the old FLASH contents) * or was erased (with the cache containing the correct FLASH contents), then write @@ -762,6 +838,8 @@ static void st25fl1_flush_cache(struct st25fl1_dev_s *priv) CLR_DIRTY(priv); CLR_ERASED(priv); } + + return OK; } #endif @@ -775,6 +853,7 @@ static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) off_t esectno; int shift; int index; + int ret; /* Convert from the 512 byte sector to the erase sector size of the device. For * exmample, if the actual erase sector size if 4Kb (1 << 12), then we first @@ -791,12 +870,23 @@ static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) { /* No.. Flush any dirty erase block currently in the cache */ - st25fl1_flush_cache(priv); + ret = st25fl1_flush_cache(priv); + if (ret < 0) + { + fdbg("ERROR: st25fl1_flush_cache failed: %d\n", ret); + return NULL; + } /* Read the erase block into the cache */ - st25fl1_read_byte(priv, priv->sector, (esectno << priv->sectorshift) - (1 << priv->sectorshift)); + ret = st25fl1_read_byte(priv, priv->sector, + (esectno << priv->sectorshift) + (1 << priv->sectorshift)); + if (ret < 0) + { + fdbg("ERROR: st25fl1_read_byte failed: %d\n", ret); + return NULL; + } /* Mark the sector as cached */ @@ -861,10 +951,12 @@ static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) ************************************************************************************/ #ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, - off_t sector, size_t nsectors) +static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, + FAR const uint8_t *buffer, off_t sector, + size_t nsectors) { FAR uint8_t *dest; + int ret; for (; nsectors > 0; nsectors--) { @@ -884,7 +976,13 @@ static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, FAR const uint8_ off_t esectno = sector >> (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); fvdbg("sector: %ld esectno: %d\n", sector, esectno); - DEBUGVERIFY(st25fl1_erase_sector(priv, esectno)); + ret = st25fl1_erase_sector(priv, esectno); + if (ret < 0) + { + fdbg("ERROR: st25fl1_erase_sector failed: %d\n", ret); + return ret; + } + SET_ERASED(priv); } @@ -901,7 +999,7 @@ static void st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, FAR const uint8_ /* Flush the last erase block left in the cache */ - st25fl1_flush_cache(priv); + return st25fl1_flush_cache(priv); } #endif @@ -935,7 +1033,11 @@ static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl #ifdef CONFIG_S25FL1_SECTOR512 /* Flush the last erase block left in the cache */ - st25fl1_flush_cache(priv); + ret = st25fl1_flush_cache(priv); + if (ret < 0) + { + nblocks = ret; + } #endif st25fl1_unlock(priv->qspi); @@ -983,6 +1085,7 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR const uint8_t *buffer) { FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + int ret = (int)nblocks; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); @@ -991,14 +1094,24 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, st25fl1_lock(priv->qspi); #if defined(CONFIG_ST25FL1_SECTOR512) - st25fl1_write_cache(priv, buffer, startblock, nblocks); + ret = st25fl1_write_cache(priv, buffer, startblock, nblocks); + if (ret < 0) + { + fdbg("ERROR: st25fl1_write_cache failed: %d\n", ret); + } + #else - st25fl1_write_page(priv, buffer, startblock << priv->sectorshift, - nblocks << priv->sectorshift); + ret = st25fl1_write_page(priv, buffer, startblock << priv->sectorshift, + nblocks << priv->sectorshift); + if (ret < 0) + { + fdbg("ERROR: st25fl1_write_page failed: %d\n", ret); + } #endif + st25fl1_unlock(priv->qspi); - return nblocks; + return ret; } /************************************************************************************ @@ -1009,17 +1122,24 @@ static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbyt FAR uint8_t *buffer) { FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + int ret; fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes); /* Lock the QuadSPI bus and select this FLASH part */ st25fl1_lock(priv->qspi); - st25fl1_read_byte(priv, buffer, offset, nbytes); + ret = st25fl1_read_byte(priv, buffer, offset, nbytes); st25fl1_unlock(priv->qspi); + if (ret < 0) + { + fdbg("ERROR: st25fl1_read_byte returned: %d\n", ret); + return (ssize_t)ret; + } + fvdbg("return nbytes: %d\n", (int)nbytes); - return nbytes; + return (ssize_t)nbytes; } /************************************************************************************ -- GitLab From 01b68e90d0ef9c39297f2c81876ed67d130c9a78 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 24 Aug 2015 13:12:52 -0400 Subject: [PATCH 100/858] Add SSD1351 OLED controller support --- drivers/lcd/Kconfig | 171 +++++ drivers/lcd/Make.defs | 4 + drivers/lcd/ssd1351.c | 1256 +++++++++++++++++++++++++++++++++++ include/nuttx/lcd/ssd1351.h | 139 ++++ 4 files changed, 1570 insertions(+) create mode 100644 drivers/lcd/ssd1351.c create mode 100644 include/nuttx/lcd/ssd1351.h diff --git a/drivers/lcd/Kconfig b/drivers/lcd/Kconfig index ceceaad84d..d996b67a74 100644 --- a/drivers/lcd/Kconfig +++ b/drivers/lcd/Kconfig @@ -366,6 +366,177 @@ config SSD1306_I2CFREQ endif # LCD_SSD1306_I2C +config LCD_SSD1351 + bool "SSD1351 OLED Display Module" + default n + ---help--- + OLED Display Module, SSD1351, Solomon Systech. + +if LCD_SSD1351 + +choice + prompt "Interface" + default SSD1351_SPI4WIRE + +config SSD1351_SPI3WIRE + bool "3-wire SPI Interface" + select SPI + ---help--- + Enables support for the 3-wire SPI interface. + +config SSD1351_SPI4WIRE + bool "4-wire SPI Interface" + select SPI + select SPI_CMDDATA + ---help--- + Enables support for the 4-wire SPI interface. + +endchoice + +config SSD1351_SPIMODE + int "SPI Mode" + default 0 + range 0 3 + ---help--- + Specifies the SPI mode. + +config SSD1351_SPIFREQ + int "SPI Frequency" + default 1000000 + ---help--- + Specifies the SPI frequency. + +config SSD1351_NINTERFACES + int "Number of SSD1351 Devices" + default 1 + range 1 1 + ---help--- + Specifies the number of physical SSD1351 devices that will + be supported. + +config SSD1351_XRES + int "X Resolution" + default 128 + range 1 128 + ---help--- + Specifies the X resolution of the display. + +config SSD1351_YRES + int "Y Resolution" + default 128 + range 1 128 + ---help--- + Specifies the Y resolution of the display. + +config SSD1351_MIRRORX + bool "Mirror X" + default n + ---help--- + Mirrors the display along the X axis. + +config SSD1351_MIRRORY + bool "Mirror Y" + default n + ---help--- + Mirrors the display along the Y axis. + +config SSD1351_INVERT + bool "Invert Display" + default n + ---help--- + Inverts the display. + +config SSD1351_VDDEXT + bool "External VDD" + default n + ---help--- + Specifies that VDD is external. + +config SSD1351_TRST + int "Reset Period" + default 5 + range 5 31 + ---help--- + Specifies the reset period in DCLKs. + +config SSD1351_TPRECHG1 + int "First Pre-charge Period" + default 8 + range 3 15 + ---help--- + Specifies the first pre-charge period in DCLKs. + +config SSD1351_PERFENHANCE + bool "Enhance Display Performance" + default n + ---help--- + Enhances the display performance. + +config SSD1351_CLKDIV + int "Clock Divider" + default 0 + range 0 10 + ---help--- + Specifies the clock divider. + +config SSD1351_OSCFREQ + int "Oscillator Frequency" + default 15 + range 0 15 + ---help--- + Specifies the oscillator frequency. + +config SSD1351_TPRECHG2 + int "Second Pre-charge Period" + default 8 + range 1 15 + ---help--- + Specifies the second pre-charge period in DCLKs. + +config SSD1351_VPRECHG + int "Voltage Pre-charge Level" + default 50 + range 20 60 + ---help--- + Specifies the pre-charge voltage level as a percentage of VCC. + +config SSD1351_VCOMH + int "COM Deselect Voltage Level" + default 82 + range 72 86 + ---help--- + Specifies the COM deselect voltage level as a percentage of VCC. + +config SSD1351_CONTRASTA + int "Color A Contrast" + default 138 + range 0 255 + ---help--- + Specifies the contrast of color A. + +config SSD1351_CONTRASTB + int "Color B Contrast" + default 81 + range 0 255 + ---help--- + Specifies the contrast of color B. + +config SSD1351_CONTRASTC + int "Color C Contrast" + default 138 + range 0 255 + ---help--- + Specifies the contrast of color C. + +config SSD1351_MSTRCONTRAST + int "Master Contrast Ratio" + default 16 + range 1 16 + ---help--- + Specifies the master contrast ratio in sixteenths. + +endif + config LCD_ST7565 bool "ST7565 LCD Display Module" default n diff --git a/drivers/lcd/Make.defs b/drivers/lcd/Make.defs index 6c46771f09..1becc0fa97 100644 --- a/drivers/lcd/Make.defs +++ b/drivers/lcd/Make.defs @@ -71,6 +71,10 @@ ifeq ($(CONFIG_LCD_SSD1289),y) CSRCS += ssd1289.c endif +ifeq ($(CONFIG_LCD_SSD1351),y) + CSRCS += ssd1351.c +endif + ifeq ($(CONFIG_LCD_MIO283QT2),y) CSRCS += mio283qt2.c endif diff --git a/drivers/lcd/ssd1351.c b/drivers/lcd/ssd1351.c new file mode 100644 index 0000000000..e11e6b1fb1 --- /dev/null +++ b/drivers/lcd/ssd1351.c @@ -0,0 +1,1256 @@ +/**************************************************************************** + * drivers/lcd/ssd1351.c + * LCD driver for the Solomon Systech SSD1351 LCD controller + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef CONFIG_LCD_SSD1351 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* SSD1351 configuration settings: + * CONFIG_SSD1351_SPI3WIRE - 3-wire SPI interface + * CONFIG_SSD1351_SPI4WIRE - 4-wire SPI interface + * CONFIG_SSD1351_SPIMODE - SPI mode + * CONFIG_SSD1351_SPIFREQ - SPI frequency + * CONFIG_SSD1351_NINTERFACES - number of physical devices supported + * CONFIG_SSD1351_XRES - X resolution + * CONFIG_SSD1351_YRES - Y resolution + * CONFIG_SSD1351_MIRRORX - mirror along the X axis + * CONFIG_SSD1351_MIRRORY - mirror along the Y axis + * CONFIG_SSD1351_INVERT - invert the display + * CONFIG_SSD1351_VDDEXT - external VDD + * CONFIG_SSD1351_TRST - reset period + * CONFIG_SSD1351_TPRECHG1 - first pre-charge period + * CONFIG_SSD1351_PERFENHANCE - enhace display performance + * CONFIG_SSD1351_CLKDIV - clock divider + * CONFIG_SSD1351_OSCFREQ - oscillator frequency + * CONFIG_SSD1351_TPRECHG2 - second pre-charge period + * CONFIG_SSD1351_VPRECHG - pre-charge voltage level + * CONFIG_SSD1351_VCOMH - COM deselect voltage level + * CONFIG_SSD1351_CONTRASTA - color A contrast + * CONFIG_SSD1351_CONTRASTB - color B contrast + * CONFIG_SSD1351_CONTRASTC - color C contrast + * CONFIG_SSD1351_MSTRCONTRAST - master contrast ratio + * + * Required LCD driver settings: + * CONFIG_LCD_SSD1351 - enables SSD1351 support + * CONFIG_LCD_MAXPOWER - maximum power, must be 1 + * + * Additional LCD driver settings: + * CONFIG_LCD_LANDSCAPE - landscape + * CONFIG_LCD_RLANDSCAPE - reverse landscape + * CONFIG_LCD_PORTRAIT - portrait + * CONFIG_LCD_RPORTRAIT - reverse portrait + * + * Required SPI driver settings: + * CONFIG_SPI - enables support for SPI + * CONFIG_SPI_CMDDATA - enables support for cmd/data selection + * (if using 4-wire SPI) + * + * NX settings that must be undefined: + * CONFIG_NX_DISABLE_16BPP - disables 16 bpp support + */ + +/* Verify that all configuration requirements have been met */ + +/* Interface to use */ + +#if !defined(CONFIG_SSD1351_SPI3WIRE) && !defined(CONFIG_SSD1351_SPI4WIRE) +# error "Choose an interface to use" +#endif + +#if defined(CONFIG_SSD1351_SPI3WIRE) && defined(CONFIG_SSD1351_SPI4WIRE) +# error "Cannot choose more than one interface" +#endif + +/* SPI */ + +#ifndef CONFIG_SPI +# error "Requires support for SPI" +#endif + +/* Cmd/data selection */ + +#if defined(CONFIG_SSD1351_SPI4WIRE) && !defined(CONFIG_SPI_CMDDATA) +# error "4-wire SPI interface requires support for SPI_CMDDATA" +#endif + +/* Number of bits per pixel */ + +#ifdef CONFIG_NX_DISABLE_16BPP +# error "Requires support for 16 bits per pixel" +#endif + +/* Max power */ + +#ifndef CONFIG_LCD_MAXPOWER +# define CONFIG_LCD_MAXPOWER 1 +#endif + +#if CONFIG_LCD_MAXPOWER != 1 +# error "CONFIG_LCD_MAXPOWER should be 1" +#endif + +/* SPI mode */ + +#ifndef CONFIG_SSD1351_SPIMODE +# define CONFIG_SSD1351_SPIMODE SPIDEV_MODE0 +#endif + +/* SPI frequency */ + +#ifndef CONFIG_SSD1351_SPIFREQ +# define CONFIG_SSD1351_SPIFREQ 1000000 +#endif + +/* The number of physical interfaces that will be supported */ + +#ifndef CONFIG_SSD1351_NINTERFACES +# define CONFIG_SSD1351_NINTERFACES 1 +#endif + +#if CONFIG_SSD1351_NINTERFACES != 1 +# error "This implementation supports only a single LCD device" +#endif + +/* X resolution */ + +#ifndef CONFIG_SSD1351_XRES +# define CONFIG_SSD1351_XRES 128 +#endif + +#if CONFIG_SSD1351_XRES < 0 || CONFIG_SSD1351_XRES > 128 +# error "Invalid X resolution" +#endif + +/* Y resolution */ + +#ifndef CONFIG_SSD1351_YRES +# define CONFIG_SSD1351_YRES 128 +#endif + +#if CONFIG_SSD1351_YRES < 0 || CONFIG_SSD1351_YRES > 128 +# error "Invalid Y resolution" +#endif + +/* Reset period */ + +#ifndef CONFIG_SSD1351_TRST +# define CONFIG_SSD1351_TRST 5 +#endif + +/* First pre-charge period */ + +#ifndef CONFIG_SSD1351_TPRECHG1 +# define CONFIG_SSD1351_TPRECHG1 8 +#endif + +/* Clock divider */ + +#ifndef CONFIG_SSD1351_CLKDIV +# define CONFIG_SSD1351_CLKDIV 0 +#endif + +/* Oscillator frequency */ + +#ifndef CONFIG_SSD1351_OSCFREQ +# define CONFIG_SSD1351_OSCFREQ 15 +#endif + +/* Second pre-charge period */ + +#ifndef CONFIG_SSD1351_TPRECHG2 +# define CONFIG_SSD1351_TPRECHG2 8 +#endif + +/* Pre-charge voltage level */ + +#ifndef CONFIG_SSD1351_VPRECHG +# define CONFIG_SSD1351_VPRECHG 50 +#endif + +/* COM deselect voltage level */ + +#ifndef CONFIG_SSD1351_VCOMH +# define CONFIG_SSD1351_VCOMH 82 +#endif + +/* Color A contrast */ + +#ifndef CONFIG_SSD1351_CONTRASTA +# define CONFIG_SSD1351_CONTRASTA 138 +#endif + +/* Color B contrast */ + +#ifndef CONFIG_SSD1351_CONTRASTB +# define CONFIG_SSD1351_CONTRASTB 81 +#endif + +/* Color C contrast */ + +#ifndef CONFIG_SSD1351_CONTRASTC +# define CONFIG_SSD1351_CONTRASTC 138 +#endif + +/* Master contrast ratio */ + +#ifndef CONFIG_SSD1351_MSTRCONTRAST +# define CONFIG_SSD1351_MSTRCONTRAST 16 +#endif + +/* 9-bit SPI */ + +#ifdef CONFIG_SSD1351_SPI3WIRE +# define SSD1351_SPICMD 0 +# define SSD1351_SPIDATA (1 << 8) +#endif + +/* Macro Helpers ************************************************************/ + +#define SSD1351_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define SSD1351_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define SSD1351_CLAMP(n, a, b) SSD1351_MIN(SSD1351_MAX(n, a), b) + +/* Fundamental Commands *****************************************************/ + +/* Set column address. Two data bytes. + * Data 1: start address (0-127) + * Data 2: end address (0-127) + */ + +#define SSD1351_CMD_COLADDR 0x15 + +/* Set row address. Two data bytes. + * Data 1: start address (0-127) + * Data 2: end address (0-127) + */ + +#define SSD1351_CMD_ROWADDR 0x75 + +/* Write data bytes to RAM. */ + +#define SSD1351_CMD_RAMWRITE 0x5c + +/* Read data bytes from RAM. */ + +#define SSD1351_CMD_RAMREAD 0x5d + +/* Set address increment, column address mapping, color sequence, + * scan direction, COM split, and color depth. + * One data byte. + */ + +#define SSD1351_CMD_ORIENTATION 0xa0 +#define SSD1351_ADDRINCHORIZ 0x00 /* Horizontal address increment */ +#define SSD1351_ADDRINCVERT 0x01 /* Vertical address increment */ +#define SSD1351_REMAPCOL0 0x00 /* Column address 0 mapped to SEG0 */ +#define SSD1351_REMAPCOL127 0x02 /* Column address 127 mapped to SEG0 */ +#define SSD1351_COLORABC 0x00 /* Color sequence ABC */ +#define SSD1351_COLORCBA 0x04 /* Color sequence CBA */ +#define SSD1351_SCANFROMCOM0 0x00 /* Scan from COM0 */ +#define SSD1351_SCANTOCOM0 0x10 /* Scan to COM0 */ +#define SSD1351_SPLITDIS 0x00 /* Disable COM split odd even */ +#define SSD1351_SPLITEN 0x20 /* Enable COM split odd even */ +#define SSD1351_DEPTH65K 0x00 /* 65k color depth */ +#define SSD1351_DEPTH262K1 0x80 /* 262k color depth format 1 */ +#define SSD1351_DEPTH262K2 0xc0 /* 262k color depth format 2 */ + +/* Set vertical scroll by RAM (0-128). One data byte. */ + +#define SSD1351_CMD_STARTLINE 0xa1 +#define SSD1351_STARTLINE(n) SSD1351_CLAMP(n, 0, 128) + +/* Set vertical scroll by row (0-128). One data byte. */ + +#define SSD1351_CMD_OFFSET 0xa2 +#define SSD1351_OFFSET(n) SSD1351_CLAMP(n, 0, 128) + +/* Set all pixels off. No data bytes. */ + +#define SSD1351_CMD_ALLOFF 0xa4 + +/* Set all pixels on. No data bytes. */ + +#define SSD1351_CMD_ALLON 0xa5 + +/* Set normal display. No data bytes. */ + +#define SSD1351_CMD_NORMAL 0xa6 + +/* Set inverse display. No data bytes. */ + +#define SSD1351_CMD_INVERSE 0xa7 + +/* Set VDD and interface. One data byte. */ + +#define SSD1351_CMD_VDDIFACE 0xab +#define SSD1351_VDDEXT 0x00 /* external VDD */ +#define SSD1351_VDDINT 0x01 /* internal VDD */ +#define SSD1351_IFACE8BIT 0x00 /* 8-bit parallel */ +#define SSD1351_IFACE16BIT 0x40 /* 16-bit parallel */ +#define SSD1351_IFACE18BIT 0xc0 /* 18-bit parallel */ + +/* Set display off (sleep mode on). No data bytes. */ + +#define SSD1351_CMD_DISPOFF 0xae + +/* Set display on (sleep mode off). No data bytes. */ + +#define SSD1351_CMD_DISPON 0xaf + +/* Set reset period in DCLKs (5-31) and first pre-charge period + * in DCLKs (3-15). One data byte. + */ + +#define SSD1351_CMD_TRSTTPRECHG1 0xb1 +#define SSD1351_TRST(n) (SSD1351_CLAMP(n, 5, 31) / 2) +#define SSD1351_TPRECHG1(n) (SSD1351_CLAMP(n, 3, 15) << 4) + +/* Set display performance. Three data bytes. */ + +#define SSD1351_CMD_PERF 0xb2 +#define SSD1351_PERFNORMAL 0x00 /* Data 1: normal performance */ +#define SSD1351_PERFENHANCED 0xa4 /* Data 1: enhanced performance */ +#define SSD1351_PERFDATA2 0x00 +#define SSD1351_PERFDATA3 0x00 + +/* Set clock divider (0-10) and oscillator frequency (0-15). + * One data byte. + */ + +#define SSD1351_CMD_DIVFREQ 0xb3 +#define SSD1351_CLKDIV(r) (SSD1351_CLAMP(r, 0, 10) << 0) +#define SSD1351_OSCFREQ(r) (SSD1351_CLAMP(r, 0, 15) << 4) + +/* Set segment low voltage. Three data bytes. */ + +#define SSD1351_CMD_VSL 0xb4 +#define SSD1351_VSLEXT 0xa0 /* Data 1: external VSL */ +#define SSD1351_VSLDATA2 0xb5 +#define SSD1351_VSLDATA3 0x55 + +/* Set GPIO pins. One data byte. */ + +#define SSD1351_CMD_GPIO 0xb5 +#define SSD1351_GPIODIS 0x00 /* High impedance, disabled */ +#define SSD1351_GPIOEN 0x01 /* High impedance, enabled */ +#define SSD1351_GPIOLOW 0x02 /* Output low */ +#define SSD1351_GPIOHIGH 0x03 /* Output high */ +#define SSD1351_GPIO0(n) (((n) & 3) << 0) +#define SSD1351_GPIO1(n) (((n) & 3) << 2) + +/* Set second pre-charge period in DCLKs (1-15). One data byte. */ + +#define SSD1351_CMD_TPRECHG2 0xb6 +#define SSD1351_TPRECHG2(n) SSD1351_CLAMP(n, 1, 15) + +/* Set lookup table for grayscale pulse width. 63 data bytes. */ + +#define SSD1351_CMD_LUT 0xb8 + +/* Use built-in linear lookup table. No data bytes. */ + +#define SSD1351_CMD_LINEARLUT 0xb9 + +/* Set pre-charge voltage level as a percentage of VCC (20-60). + * One data byte. + */ + +#define SSD1351_CMD_VPRECHG 0xbb +#define SSD1351_VPRECHG(n) (100 * (SSD1351_CLAMP(n, 20, 60) - 20) / \ + (100 * (60 - 20) / 31)) + +/* Set COM deselect voltage level as a percentage of VCC (72-86). + * One data byte. + */ + +#define SSD1351_CMD_VCOMH 0xbe +#define SSD1351_VCOMH(n) ((SSD1351_CLAMP(n, 72, 86) - 72) / 2) + +/* Set contrast for colors A (0-255), B (0-255), and C (0-255). + * Three data bytes. + * Data 1: color A + * Data 2: color B + * Data 3: color C + */ + +#define SSD1351_CMD_CONTRAST 0xc1 +#define SSD1351_CONTRAST(n) SSD1351_CLAMP(n, 0, 255) + +/* Set master contrast ratio in sixteenths (1-16). One data byte. */ + +#define SSD1351_CMD_MSTRCONTRAST 0xc7 +#define SSD1351_MSTRCONTRAST(n) (SSD1351_CLAMP(n, 1, 16) - 1) + +/* Set multiplex ratio (16-128). One data byte. */ + +#define SSD1351_CMD_MUXRATIO 0xca +#define SSD1351_MUXRATIO(n) (SSD1351_CLAMP(n, 16, 128) - 1) + +/* Set command lock. One data byte. */ + +#define SSD1351_CMD_LOCK 0xfd +#define SSD1351_UNLOCK 0x12 /* Unlock commands */ +#define SSD1351_LOCK 0x16 /* Lock commands */ +#define SSD1351_INACCESSIBLE 0xb0 /* Make some commands inaccessible */ +#define SSD1351_ACCESSIBLE 0xb1 /* Make some commands accessible */ + +/* Graphic Acceleration Commands ********************************************/ + +/* Set horizontal scroll. Five data bytes. + * Data 1: 0x00: no scrolling + * 0x01-0x3f: scroll towards SEG127 with 1 column offset + * 0x40-0xff: scroll towards SEG0 with 1 column offset + * Data 2: start row address + * Data 3: number of rows to scroll + */ + +#define SSD1351_CMD_HSCROLL 0x96 +#define SSD1351_HSCROLLDATA4 0x00 /* Data 4 */ +#define SSD1351_HSCROLLTEST 0x00 /* Data 5: test mode */ +#define SSD1351_HSCROLLNORMAL 0x01 /* Data 5: normal */ +#define SSD1351_HSCROLLSLOW 0x02 /* Data 5: slow */ +#define SSD1351_HSCROLLSLOWEST 0x03 /* Data 5: slowest */ + +/* Start horizontal scroll. No data bytes. */ + +#define SSD1351_CMD_STARTHSCROLL 0x9e + +/* Stop horizontal scroll. No data bytes. */ + +#define SSD1351_CMD_STOPHSCROLL 0x9f + +/* Color Properties *********************************************************/ + +/* Display resolution */ + +#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE) +#define SSD1351_XRES CONFIG_SSD1351_XRES +#define SSD1351_YRES CONFIG_SSD1351_YRES +#else +#define SSD1351_XRES CONFIG_SSD1351_YRES +#define SSD1351_YRES CONFIG_SSD1351_XRES +#endif + +/* Color depth and format */ + +#define SSD1351_BPP 16 +#define SSD1351_COLORFMT FB_FMT_RGB16_565 +#define SSD1351_STRIDE (2 * SSD1351_XRES) +#define SSD1351_PIX2BYTES(p) (2 * (p)) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure describes the state of this driver */ + +struct ssd1351_dev_s +{ + /* Publically visible device structure */ + + struct lcd_dev_s dev; + + /* Private LCD-specific information follows */ + + FAR struct spi_dev_s *spi; /* Contained SPI driver instance */ + uint8_t power; /* Current power (backlight) setting */ + + /* This is working memory allocated by the LCD driver for each LCD device + * and for each color plane. This memory will hold one raster line of + * data. The size of the allocated run buffer must therefore be at least + * (bpp * xres / 8). Actual alignment of the buffer must conform to the + * bitwidth of the underlying pixel type. + * + * If there are multiple planes, they may share the same working buffer + * because different planes will not be operate on concurrently. However, + * if there are multiple LCD devices, they must each have unique run + * buffers. + */ + + uint16_t runbuffer[SSD1351_XRES]; + + /* This is another buffer, but used internally by the LCD driver in order + * to expand the pixel data into 9-bit data needed by the LCD. There are + * some customizations that would eliminate the need for this extra buffer + * and for the extra expansion/copy, but those customizations would require + * a special, non-standard SPI driver that could expand 8- to 9-bit data on + * the fly. + */ + +#ifdef CONFIG_SSD1351_SPI3WIRE + uint16_t rowbuffer[SSD1351_STRIDE+1]; +#endif +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* SPI Helpers */ + +static inline void ssd1351_configspi(FAR struct spi_dev_s *spi); +#ifdef CONFIG_SPI_OWNBUS +static inline void ssd1351_select(FAR struct spi_dev_s *spi); +static inline void ssd1351_deselect(FAR struct spi_dev_s *spi); +#else +static void ssd1351_select(FAR struct spi_dev_s *spi); +static void ssd1351_deselect(FAR struct spi_dev_s *spi); +#endif +static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen); + +/* LCD Data Transfer Methods */ + +static int ssd1351_putrun(fb_coord_t row, fb_coord_t col, + FAR const uint8_t *buffer, size_t npixels); +static int ssd1351_getrun(fb_coord_t row, fb_coord_t col, + FAR uint8_t *buffer, size_t npixels); + +/* LCD Configuration */ + +static int ssd1351_getvideoinfo(FAR struct lcd_dev_s *dev, + FAR struct fb_videoinfo_s *vinfo); +static int ssd1351_getplaneinfo(FAR struct lcd_dev_s *dev, + unsigned int planeno, + FAR struct lcd_planeinfo_s *pinfo); + +/* LCD RGB Mapping */ + +#ifdef CONFIG_FB_CMAP +# error "RGB color mapping not supported by this driver" +#endif + +/* Cursor Controls */ + +#ifdef CONFIG_FB_HWCURSOR +# error "Cursor control not supported by this driver" +#endif + +/* LCD Specific Controls */ + +static int ssd1351_getpower(struct lcd_dev_s *dev); +static int ssd1351_setpower(struct lcd_dev_s *dev, int power); +static int ssd1351_getcontrast(struct lcd_dev_s *dev); +static int ssd1351_setcontrast(struct lcd_dev_s *dev, unsigned int contrast); + +/* Initialization */ + +static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This is the standard, NuttX LCD driver object */ + +static struct ssd1351_dev_s g_lcddev; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ssd1351_configspi + * + * Description: + * Configure the SPI. + * + ****************************************************************************/ + +static inline void ssd1351_configspi(FAR struct spi_dev_s *spi) +{ + SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); +#ifdef CONFIG_SSD1351_SPI3WIRE + SPI_SETBITS(spi, 9); +#else + SPI_SETBITS(spi, 8); +#endif + SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); +} + +/**************************************************************************** + * Name: ssd1351_select + * + * Description: + * Select the SPI, locking and re-configuring if necessary. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_OWNBUS +static inline void ssd1351_select(FAR struct spi_dev_s *spi) +{ + /* We own the SPI bus, so just select the chip */ + + gdbg("SELECTED\n"); + SPI_SELECT(spi, SPIDEV_DISPLAY, true); +} +#else +static void ssd1351_select(FAR struct spi_dev_s *spi) +{ + /* Select the chip, locking the SPI bus in case there are multiple devices + * competing for the SPI bus + */ + + gdbg("SELECTED\n"); + SPI_LOCK(spi, true); + SPI_SELECT(spi, SPIDEV_DISPLAY, true); + + /* Now make sure that the SPI bus is configured for this device (it might + * have gotten configured for a different device while unlocked) + */ + + ssd1351_configspi(spi); +} +#endif + +/**************************************************************************** + * Name: ssd1351_deselect + * + * Description: + * De-select the SPI. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_OWNBUS +static inline void ssd1351_deselect(FAR struct spi_dev_s *spi) +{ + /* We own the SPI bus, so just de-select the chip */ + + gdbg("DE-SELECTED\n"); + SPI_SELECT(spi, SPIDEV_DISPLAY, false); +} +#else +static void ssd1351_deselect(FAR struct spi_dev_s *spi) +{ + /* De-select the chip and relinquish the SPI bus */ + + gdbg("DE-SELECTED\n"); + SPI_SELECT(spi, SPIDEV_DISPLAY, false); + SPI_LOCK(spi, false); +} +#endif + +/**************************************************************************** + * Name: ssd1351_cmddata + * + * Description: + * Send a 1-byte command followed by datlen data bytes. + * + ****************************************************************************/ + +#ifdef CONFIG_SSD1351_SPI3WIRE +static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen) +{ + size_t i; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); + DEBUGASSERT(datlen <= SSD1351_STRIDE); + + /* Copy the command into the line buffer */ + + priv->rowbuffer[0] = (uint16_t)cmd | SSD1351_SPICMD; + + /* Copy any data after the command into the line buffer */ + + for (i = 0; i < datlen; i++) + { + priv->rowbuffer[i+1] = (uint16_t)data[i] | SSD1351_SPIDATA; + } + + /* Send the line buffer */ + + (void)SPI_SNDBLOCK(priv->spi, priv->rowbuffer, datlen+1); +} +#else +static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); + + /* Select command transfer */ + + (void)SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, true); + + /* Send the command */ + + (void)SPI_SEND(priv->spi, cmd); + + /* Do we have any data to send? */ + + if (datlen > 0) + { + /* Yes, select data transfer */ + + (void)SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, false); + + /* Transfer all of the data */ + + (void)SPI_SNDBLOCK(priv->spi, data, datlen); + } +} +#endif + +/**************************************************************************** + * Name: ssd1351_setcursor + * + * Description: + * Set the cursor position. + * + ****************************************************************************/ + +static void ssd1351_setcursor(FAR struct ssd1351_dev_s *priv, uint8_t col, + uint8_t row) +{ + uint8_t buf[2]; + +#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE) + /* Set the column address to the column */ + + buf[0] = col; + buf[1] = SSD1351_XRES - 1; + ssd1351_cmddata(priv, SSD1351_CMD_COLADDR, buf, 2); + + /* Set the row address to the row */ + + buf[0] = row; + buf[1] = SSD1351_YRES - 1; + ssd1351_cmddata(priv, SSD1351_CMD_ROWADDR, buf, 2); +#else + /* Set the column address to the row */ + + buf[0] = row; + buf[1] = SSD1351_YRES - 1; + ssd1351_cmddata(priv, SSD1351_CMD_COLADDR, buf, 2); + + /* Set the row address to the column */ + + buf[0] = col; + buf[1] = SSD1351_XRES - 1; + ssd1351_cmddata(priv, SSD1351_CMD_ROWADDR, buf, 2); +#endif +} + +/**************************************************************************** + * Name: ssd1351_putrun + * + * Description: + * This method can be used to write a partial raster line to the LCD: + * + * Input Parameters: + * row - Starting row to write to (range: 0 <= row < yres) + * col - Starting column to write to (range: 0 <= col <= xres-npixels + * buffer - The buffer containing the run to be written to the LCD + * npixels - The number of pixels to write to the LCD + * (range: 0 < npixels <= xres-col) + * + ****************************************************************************/ + +static int ssd1351_putrun(fb_coord_t row, fb_coord_t col, + FAR const uint8_t *buffer, size_t npixels) +{ + FAR struct ssd1351_dev_s *priv = &g_lcddev; + + /* Sanity check */ + + DEBUGASSERT(buffer != NULL && ((uintptr_t)buffer & 1) == 0 && + col >= 0 && col+npixels <= SSD1351_XRES && + row >= 0 && row < SSD1351_YRES); + + /* Select and lock the device */ + + ssd1351_select(priv->spi); + + /* Set the starting position for the run */ + + ssd1351_setcursor(priv, col, row); + + /* Transfer all of the data */ + + ssd1351_cmddata(priv, SSD1351_CMD_RAMWRITE, buffer, + SSD1351_PIX2BYTES(npixels)); + + /* Unlock and de-select the device */ + + ssd1351_deselect(priv->spi); + + return OK; +} + +/**************************************************************************** + * Name: ssd1351_getrun + * + * Description: + * This method can be used to read a partial raster line from the LCD. + * + * Input Parameters: + * row - Starting row to read from (range: 0 <= row < yres) + * col - Starting column to read from (range: 0 <= col <= xres-npixels) + * buffer - The buffer in which to return the run read from the LCD + * npixels - The number of pixels to read from the LCD + * (range: 0 < npixels <= xres-col) + * + ****************************************************************************/ + +static int ssd1351_getrun(fb_coord_t row, fb_coord_t col, + FAR uint8_t *buffer, size_t npixels) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: ssd1351_getvideoinfo + * + * Description: + * Get information about the LCD video controller configuration. + * + ****************************************************************************/ + +static int ssd1351_getvideoinfo(FAR struct lcd_dev_s *dev, + FAR struct fb_videoinfo_s *vinfo) +{ + DEBUGASSERT(dev != NULL && vinfo != NULL); + + vinfo->fmt = SSD1351_COLORFMT; + vinfo->xres = SSD1351_XRES; + vinfo->yres = SSD1351_YRES; + vinfo->nplanes = 1; + + gvdbg("fmt: %u xres: %u yres: %u nplanes: %u\n", + vinfo->fmt, vinfo->xres, vinfo->yres, vinfo->nplanes); + return OK; +} + +/**************************************************************************** + * Name: ssd1351_getplaneinfo + * + * Description: + * Get information about the configuration of each LCD color plane. + * + ****************************************************************************/ + +static int ssd1351_getplaneinfo(FAR struct lcd_dev_s *dev, + unsigned int planeno, + FAR struct lcd_planeinfo_s *pinfo) +{ + FAR struct ssd1351_dev_s *priv = (FAR struct ssd1351_dev_s *)dev; + + DEBUGASSERT(dev != NULL && pinfo != NULL && planeno == 0); + + pinfo->putrun = ssd1351_putrun; + pinfo->getrun = ssd1351_getrun; + pinfo->buffer = (uint8_t *)priv->runbuffer; + pinfo->bpp = SSD1351_BPP; + + gvdbg("planeno: %u bpp: %u\n", planeno, pinfo->bpp); + return OK; +} + +/**************************************************************************** + * Name: ssd1351_getpower + * + * Description: + * Get the LCD panel power status + * (0: full off - CONFIG_LCD_MAXPOWER: full on). + * On backlit LCDs, this setting may correspond to the backlight setting. + * + ****************************************************************************/ + +static int ssd1351_getpower(FAR struct lcd_dev_s *dev) +{ + FAR struct ssd1351_dev_s *priv = (FAR struct ssd1351_dev_s *)dev; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + gvdbg("power: %d\n", priv->power); + + return priv->power; +} + +/**************************************************************************** + * Name: ssd1351_setpower + * + * Description: + * Enable/disable LCD panel power + * (0: full off - CONFIG_LCD_MAXPOWER: full on). + * On backlit LCDs, this setting may correspond to the backlight setting. + * + ****************************************************************************/ + +static int ssd1351_setpower(FAR struct lcd_dev_s *dev, int power) +{ + FAR struct ssd1351_dev_s *priv = (FAR struct ssd1351_dev_s *)dev; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL && (unsigned int)power <= CONFIG_LCD_MAXPOWER); + gvdbg("power: %d\n", power); + + /* Select and lock the device */ + + ssd1351_select(priv->spi); + + if (power > 0) + { + /* Turn the display on */ + + ssd1351_cmddata(priv, SSD1351_CMD_DISPON, NULL, 0); + priv->power = CONFIG_LCD_MAXPOWER; + } + else + { + /* Turn the display off */ + + ssd1351_cmddata(priv, SSD1351_CMD_DISPOFF, NULL, 0); + priv->power = 0; + } + + /* Unlock and de-select the device */ + + ssd1351_deselect(priv->spi); + + return OK; +} + +/**************************************************************************** + * Name: ssd1351_getcontrast + * + * Description: + * Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST). + * + ****************************************************************************/ + +static int ssd1351_getcontrast(FAR struct lcd_dev_s *dev) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: ssd1351_setcontrast + * + * Description: + * Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST). + * + ****************************************************************************/ + +static int ssd1351_setcontrast(FAR struct lcd_dev_s *dev, + unsigned int contrast) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: ssd1351_hwinitialize + * + * Description: + * Initialize the video hardware. + * + ****************************************************************************/ + +static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) +{ + size_t i; + uint8_t buf[3]; + + /* Select and lock the device */ + + ssd1351_select(priv->spi); + + /* Unlock most commands */ + + buf[0] = SSD1351_UNLOCK; + ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + + /* Unlock the rest of the commands */ + + buf[0] = SSD1351_ACCESSIBLE; + ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + + /* Turn the display off */ + + ssd1351_cmddata(priv, SSD1351_CMD_DISPOFF, NULL, 0); + + /* Set the address increment, the column address mapping, the color + * sequence, the scan direction, the COM split, and the color depth + */ + + buf[0] = SSD1351_COLORABC | SSD1351_SPLITEN | SSD1351_DEPTH65K; +#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE) + buf[0] |= SSD1351_ADDRINCHORIZ; +#else + buf[0] |= SSD1351_ADDRINCVERT; +#endif +#if (defined(CONFIG_LCD_LANDSCAPE) && !defined(CONFIG_SSD1351_MIRRORX)) || \ + (defined(CONFIG_LCD_RLANDSCAPE) && defined(CONFIG_SSD1351_MIRRORX)) || \ + (defined(CONFIG_LCD_PORTRAIT) && !defined(CONFIG_SSD1351_MIRRORY)) || \ + (defined(CONFIG_LCD_RPORTRAIT) && defined(CONFIG_SSD1351_MIRRORY)) + buf[0] |= SSD1351_REMAPCOL0; +#else + buf[0] |= SSD1351_REMAPCOL127; +#endif +#if (defined(CONFIG_LCD_LANDSCAPE) && !defined(CONFIG_SSD1351_MIRRORY)) || \ + (defined(CONFIG_LCD_RLANDSCAPE) && defined(CONFIG_SSD1351_MIRRORY)) || \ + (defined(CONFIG_LCD_PORTRAIT) && defined(CONFIG_SSD1351_MIRRORX)) || \ + (defined(CONFIG_LCD_RPORTRAIT) && !defined(CONFIG_SSD1351_MIRRORX)) + buf[0] |= SSD1351_SCANTOCOM0; +#else + buf[0] |= SSD1351_SCANFROMCOM0; +#endif + ssd1351_cmddata(priv, SSD1351_CMD_ORIENTATION, buf, 1); + + /* Set the vertical scroll by RAM */ + +#if (defined(CONFIG_LCD_LANDSCAPE) && !defined(CONFIG_SSD1351_MIRRORY)) || \ + (defined(CONFIG_LCD_RLANDSCAPE) && defined(CONFIG_SSD1351_MIRRORY)) || \ + (defined(CONFIG_LCD_PORTRAIT) && defined(CONFIG_SSD1351_MIRRORX)) || \ + (defined(CONFIG_LCD_RPORTRAIT) && !defined(CONFIG_SSD1351_MIRRORX)) + buf[0] = SSD1351_STARTLINE(CONFIG_SSD1351_YRES); +#else + buf[0] = SSD1351_STARTLINE(0); +#endif + ssd1351_cmddata(priv, SSD1351_CMD_STARTLINE, buf, 1); + + /* Set the vertical scroll by row */ + + buf[0] = SSD1351_OFFSET(0); + ssd1351_cmddata(priv, SSD1351_CMD_OFFSET, buf, 1); + + /* Set the display to normal or inverse */ + +#ifdef CONFIG_SSD1351_INVERT + ssd1351_cmddata(priv, SSD1351_CMD_INVERSE, NULL, 0); +#else + ssd1351_cmddata(priv, SSD1351_CMD_NORMAL, NULL, 0); +#endif + + /* Set the VDD and the interface */ + +#ifdef CONFIG_SSD1351_VDDEXT + buf[0] = SSD1351_VDDEXT; +#else + buf[0] = SSD1351_VDDINT; +#endif + buf[0] |= SSD1351_IFACE8BIT; + ssd1351_cmddata(priv, SSD1351_CMD_VDDIFACE, buf, 1); + + /* Set the reset period and the first pre-charge period */ + + buf[0] = SSD1351_TRST(CONFIG_SSD1351_TRST) | + SSD1351_TPRECHG1(CONFIG_SSD1351_TPRECHG1); + ssd1351_cmddata(priv, SSD1351_CMD_TRSTTPRECHG1, buf, 1); + + /* Set the display performance */ + +#ifdef CONFIG_SSD1351_PERFENHANCE + buf[0] = SSD1351_PERFENHANCE; +#else + buf[0] = SSD1351_PERFNORMAL; +#endif + buf[1] = SSD1351_PERFDATA2; + buf[2] = SSD1351_PERFDATA3; + ssd1351_cmddata(priv, SSD1351_CMD_PERF, buf, 3); + + /* Set the clock divider and the oscillator frequency */ + + buf[0] = SSD1351_CLKDIV(CONFIG_SSD1351_CLKDIV) | + SSD1351_OSCFREQ(CONFIG_SSD1351_OSCFREQ); + ssd1351_cmddata(priv, SSD1351_CMD_DIVFREQ, buf, 1); + + /* Set the segment low voltage */ + + buf[0] = SSD1351_VSLEXT; + buf[1] = SSD1351_VSLDATA2; + buf[2] = SSD1351_VSLDATA3; + ssd1351_cmddata(priv, SSD1351_CMD_VSL, buf, 3); + + /* Set the GPIO pins */ + + buf[0] = SSD1351_GPIO0(SSD1351_GPIOLOW) | SSD1351_GPIO1(SSD1351_GPIOLOW); + ssd1351_cmddata(priv, SSD1351_CMD_GPIO, buf, 1); + + /* Set the second pre-charge period */ + + buf[0] = SSD1351_TPRECHG2(CONFIG_SSD1351_TPRECHG2); + ssd1351_cmddata(priv, SSD1351_CMD_TPRECHG2, buf, 1); + + /* Use the built-in linear lookup table */ + + ssd1351_cmddata(priv, SSD1351_CMD_LINEARLUT, NULL, 0); + + /* Set the pre-charge voltage level */ + + buf[0] = SSD1351_VPRECHG(CONFIG_SSD1351_VPRECHG); + ssd1351_cmddata(priv, SSD1351_CMD_VPRECHG, buf, 1); + + /* Set the COM deselect voltage level */ + + buf[0] = SSD1351_VCOMH(CONFIG_SSD1351_VCOMH); + ssd1351_cmddata(priv, SSD1351_CMD_VCOMH, buf, 1); + + /* Set the contrast */ + + buf[0] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTA); + buf[1] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTB); + buf[2] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTC); + ssd1351_cmddata(priv, SSD1351_CMD_CONTRAST, buf, 3); + + /* Set the master contrast ratio */ + + buf[0] = SSD1351_MSTRCONTRAST(CONFIG_SSD1351_MSTRCONTRAST); + ssd1351_cmddata(priv, SSD1351_CMD_MSTRCONTRAST, buf, 1); + + /* Set the multiplex ratio */ + + buf[0] = SSD1351_MUXRATIO(128); + ssd1351_cmddata(priv, SSD1351_CMD_MUXRATIO, buf, 1); + + /* Lock some of the commands */ + + buf[0] = SSD1351_INACCESSIBLE; + ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + + /* Set the cursor position */ + + ssd1351_setcursor(priv, 0, 0); + + /* Clear the display memory */ + + buf[0] = 0; + buf[1] = 0; + for (i = 0; i < SSD1351_XRES * SSD1351_YRES; i++) + { + ssd1351_cmddata(priv, SSD1351_CMD_RAMWRITE, buf, 2); + } + + /* Unlock and de-select the device */ + + ssd1351_deselect(priv->spi); +} + +/**************************************************************************** + * Name: ssd1351_initialize + * + * Description: + * Initialize the video hardware. The initial state of the device + * is fully initialized, display memory cleared, and ready to use, + * but with the power setting at 0 (full off == sleep mode). + * + * Input Parameters: + * spi - A reference to the SPI driver instance. + * devno - A value in the range of 0 through CONFIG_SSD1351_NINTERFACES-1. + * This allows support for multiple devices. + * + * Returned Value: + * On success, this function returns a reference to the LCD object for the + * specified device. NULL is returned on failure. + * + ****************************************************************************/ + +FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, + unsigned int devno) +{ + FAR struct ssd1351_dev_s *priv = &g_lcddev; + size_t i; + uint16_t buf[SSD1351_XRES/2]; + + /* Sanity check */ + + DEBUGASSERT(spi != NULL && devno == 0); + + /* Initialize the driver data structure */ + + priv->dev.getvideoinfo = ssd1351_getvideoinfo; + priv->dev.getplaneinfo = ssd1351_getplaneinfo; + priv->dev.getpower = ssd1351_getpower; + priv->dev.setpower = ssd1351_setpower; + priv->dev.getcontrast = ssd1351_getcontrast; + priv->dev.setcontrast = ssd1351_setcontrast; + priv->spi = spi; + priv->power = 0; + + /* Configure the SPI bus if we own it. Otherwise, don't bother because + * it might change. + */ + +#ifdef CONFIG_SPI_OWNBUS + ssd1351_configspi(spi); +#endif + + /* Configure the device */ + + ssd1351_hwinitialize(priv); + + ssd1351_setpower(&priv->dev, 1); + + memset(buf, 0xff, sizeof(buf)); + for (i = 0; i < SSD1351_YRES / 4; i++) + { + ssd1351_putrun(i, 0, (const uint8_t *)buf, SSD1351_XRES/2); + } + + return &priv->dev; +} + +#endif /* CONFIG_LCD_SSD1351 */ diff --git a/include/nuttx/lcd/ssd1351.h b/include/nuttx/lcd/ssd1351.h new file mode 100644 index 0000000000..37b0483a92 --- /dev/null +++ b/include/nuttx/lcd/ssd1351.h @@ -0,0 +1,139 @@ +/**************************************************************************** + * include/nuttx/lcd/ssd1351.h + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_LCD_SSD1351_H +#define __INCLUDE_NUTTX_LCD_SSD1351_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_LCD_SSD1351 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* SSD1351 configuration settings: + * CONFIG_SSD1351_SPI3WIRE - 3-wire SPI interface + * CONFIG_SSD1351_SPI4WIRE - 4-wire SPI interface + * CONFIG_SSD1351_SPIMODE - SPI mode + * CONFIG_SSD1351_SPIFREQ - SPI frequency + * CONFIG_SSD1351_NINTERFACES - number of physical devices supported + * CONFIG_SSD1351_XRES - X resolution + * CONFIG_SSD1351_YRES - Y resolution + * CONFIG_SSD1351_MIRRORX - mirror along the X axis + * CONFIG_SSD1351_MIRRORY - mirror along the Y axis + * CONFIG_SSD1351_INVERT - invert the display + * CONFIG_SSD1351_VDDEXT - external VDD + * CONFIG_SSD1351_TRST - reset period + * CONFIG_SSD1351_TPRECHG1 - first pre-charge period + * CONFIG_SSD1351_PERFENHANCE - enhace display performance + * CONFIG_SSD1351_CLKDIV - clock divider + * CONFIG_SSD1351_OSCFREQ - oscillator frequency + * CONFIG_SSD1351_TPRECHG2 - second pre-charge period + * CONFIG_SSD1351_VPRECHG - pre-charge voltage level + * CONFIG_SSD1351_VCOMH - COM deselect voltage level + * CONFIG_SSD1351_CONTRASTA - color A contrast + * CONFIG_SSD1351_CONTRASTB - color B contrast + * CONFIG_SSD1351_CONTRASTC - color C contrast + * CONFIG_SSD1351_MSTRCONTRAST - master contrast ratio + * + * Required LCD driver settings: + * CONFIG_LCD_SSD1351 - enables SSD1351 support + * CONFIG_LCD_MAXPOWER - maximum power, must be 1 + * + * Additional LCD driver settings: + * CONFIG_LCD_LANDSCAPE - landscape + * CONFIG_LCD_RLANDSCAPE - reverse landscape + * CONFIG_LCD_PORTRAIT - portrait + * CONFIG_LCD_RPORTRAIT - reverse portrait + * + * Required SPI driver settings: + * CONFIG_SPI - enables support for SPI + * CONFIG_SPI_CMDDATA - enables support for cmd/data selection + * (if using 4-wire SPI) + * + * NX settings that must be undefined: + * CONFIG_NX_DISABLE_16BPP - disables 16 bpp support + */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct spi_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/**************************************************************************** + * Name: ssd1351_initialize + * + * Description: + * Initialize the video hardware. The initial state of the device + * is fully initialized, display memory cleared, and ready to use, + * but with the power setting at 0 (full off == sleep mode). + * + * Input Parameters: + * spi - A reference to the SPI driver instance. + * devno - A value in the range of 0 through CONFIG_SSD1351_NINTERFACES-1. + * This allows support for multiple devices. + * + * Returned Value: + * On success, this function returns a reference to the LCD object for the + * specified device. NULL is returned on failure. + * + ****************************************************************************/ + +FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, + unsigned int devno); + +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_LCD_SSD1351 */ +#endif /* __INCLUDE_NUTTX_LCD_SSD1351_H */ -- GitLab From 726adbeb3f6703eae28dbdad2f91dfc7a3854632 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Aug 2015 17:05:02 -0600 Subject: [PATCH 101/858] Update ChangeLog --- ChangeLog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cc6e9cd57a..d848da89b0 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10892,4 +10892,6 @@ and, as a result, incorrect data transfers can cause crashes. The fix is to lock into a single device once the MSS is locked locked down (2015-08-27). - + * drivers/lcd and include/nuttx/lcd: Add SSD1351 OLED controller + support. Contributed by Paul Alexander Patience (2015-08-28). + \ No newline at end of file -- GitLab From bfc3c98e12ef4cab983dbe41bd560a81adcc5880 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Aug 2015 10:54:38 -0600 Subject: [PATCH 102/858] Move MTD ioctls commands from include/nuttx/fs/fs.h to include/nuttx/mtd/mtd.h. Add commands to protect and unprotect memory --- arch | 2 +- include/nuttx/fs/ioctl.h | 19 ------------------- include/nuttx/mtd/mtd.h | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/arch b/arch index e6fdf9eb6a..a26ed33fa4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e6fdf9eb6a1e288e90a12eb3ee70a393ea30bec3 +Subproject commit a26ed33fa4c164564b45b4f0905887fcf553f425 diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index f047d38906..827f62e4c5 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -217,25 +217,6 @@ #define _MTDIOCVALID(c) (_IOC_TYPE(c)==_MTDIOCBASE) #define _MTDIOC(nr) _IOC(_MTDIOCBASE,nr) -#define MTDIOC_GEOMETRY _MTDIOC(0x0001) /* IN: Pointer to write-able struct - * mtd_geometry_s in which to receive - * receive geometry data (see mtd.h) - * OUT: Geometry structure is populated - * with data for the MTD */ -#define MTDIOC_XIPBASE _MTDIOC(0x0002) /* IN: Pointer to pointer to void in - * which to received the XIP base. - * OUT: If media is directly accessible, - * return (void*) base address - * of device memory */ -#define MTDIOC_BULKERASE _MTDIOC(0x0003) /* IN: None - * OUT: None */ -#define MTDIOC_SETSPEED _MTDIOC(0x0004) /* IN: New bus speed in Hz - * OUT: None */ -#define MTDIOC_EXTENDED _MTDIOC(0x0005) /* IN: unsigned long - * 0=Use normal memory region - * 1=Use alternate/extended memory - * OUT: None */ - /* NuttX ARP driver ioctl definitions (see netinet/arp.h) *******************/ #define _ARPIOCVALID(c) (_IOC_TYPE(c)==_ARPIOCBASE) diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 4162cde6f9..e9e4060ae6 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -49,6 +49,34 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Ioctl commands */ + +#define MTDIOC_GEOMETRY _MTDIOC(0x0001) /* IN: Pointer to write-able struct + * mtd_geometry_s in which to receive + * receive geometry data (see mtd.h) + * OUT: Geometry structure is populated + * with data for the MTD */ +#define MTDIOC_XIPBASE _MTDIOC(0x0002) /* IN: Pointer to pointer to void in + * which to received the XIP base. + * OUT: If media is directly accessible, + * return (void*) base address + * of device memory */ +#define MTDIOC_BULKERASE _MTDIOC(0x0003) /* IN: None + * OUT: None */ +#define MTDIOC_PROTECT _MTDIOC(0x0004) /* IN: Pointer to read-able struct + * mtd_protects_s that provides + * the region to protect. + * OUT: None */ +#define MTDIOC_UNPROTECT _MTDIOC(0x0005) /* IN: Pointer to read-able struct + * mtd_protects_s that provides + * the region to un-protect. + * OUT: None */ +#define MTDIOC_SETSPEED _MTDIOC(0x0006) /* IN: New bus speed in Hz + * OUT: None */ +#define MTDIOC_EXTENDED _MTDIOC(0x0007) /* IN: unsigned long + * 0=Use normal memory region + * 1=Use alternate/extended memory + * OUT: None */ /* Macros to hide implementation */ @@ -90,6 +118,16 @@ struct mtd_geometry_s uint32_t neraseblocks; /* Number of erase blocks */ }; +/* This structure describes a range of sectors to be protected or + * unprotected. + */ + +struct mtd_protect_s +{ + off_t startblock; /* First block to be [un-]protected */ + size_t nblocks; /* Number of blocks to [un-]protect */ +}; + /* The following defines the information for writing bytes to a sector * that are not a full page write (bytewrite). */ -- GitLab From d6b0a8fe7241cf6e3ee3dba9e02a530e477e3108 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Aug 2015 15:58:54 -0600 Subject: [PATCH 103/858] ST25FL1 driver is code complete --- ChangeLog | 4 +- arch | 2 +- drivers/mtd/st25fl1.c | 225 ++++++++++++++++++++++++++++++++++++---- include/nuttx/mtd/mtd.h | 2 + 4 files changed, 209 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6793e74c54..fc2b2decd2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10900,4 +10900,6 @@ locked down (2015-08-27). * drivers/lcd and include/nuttx/lcd: Add SSD1351 OLED controller support. Contributed by Paul Alexander Patience (2015-08-28). - \ No newline at end of file + * include/nuttx/mtd/mtd.h: Move MTD ioctl command definitions from + include/nuttx/fs/fs.h to include/nuttx/mtd.h. Add ioctl commands + to protect and unprotect memory (2015-08-29). diff --git a/arch b/arch index a26ed33fa4..7678d3b41e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a26ed33fa4c164564b45b4f0905887fcf553f425 +Subproject commit 7678d3b41e8c697ac6d59154ed48135f12a14208 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index ee25e74b22..5038cd2103 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -330,7 +330,12 @@ static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi); static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi); static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); -static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv); +static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, + off_t startblock, size_t nblocks); +static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, + off_t startblock, size_t nblocks); +static bool st25fl1_isprotected(FAR struct st25fl1_dev_s *priv, + uint8_t status, off_t address); static int st25fl1_erase_sector(FAR struct st25fl1_dev_s *priv, off_t offset); static int st25fl1_erase_chip(FAR struct st25fl1_dev_s *priv); static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, @@ -629,13 +634,171 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) return OK; } +/************************************************************************************ + * Name: st25fl1_protect + ************************************************************************************/ + +static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, + off_t startblock, size_t nblocks) +{ + unsigned char status[3]; + + /* Get the status register value to check the current protection */ + + status[0] = sf25fl1_read_status1(priv->qspi); + status[1] = sf25fl1_read_status2(priv->qspi); + status[2] = sf25fl1_read_status3(priv->qspi); + + if ((status[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) + { + /* Protection already disabled */ + + return 0; + } + + /* Check if sector protection registers are locked */ + + if ((status[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) + { + /* Yes.. unprotect section protection registers */ + + status[0] &= ~STATUS1_SRP0_MASK; + st25fl1_write_status(priv->qspi, status); + } + + /* Set the protection mask to zero. + * REVISIT: This logic should really just set the BP bits as + * necessary to protect the range of sectors. + */ + + status[0] |= STATUS1_BP_MASK; + st25fl1_write_status(priv->qspi, status); + + /* Check the new status */ + + status[0] = sf25fl1_read_status1(priv->qspi); + if ((status[0] & STATUS1_BP_MASK) != STATUS1_BP_MASK) + { + return -EACCES; + } + + return OK; +} + /************************************************************************************ * Name: st25fl1_unprotect ************************************************************************************/ -static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv) +static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, + off_t startblock, size_t nblocks) +{ + unsigned char status[3]; + + /* Get the status register value to check the current protection */ + + status[0] = sf25fl1_read_status1(priv->qspi); + status[1] = sf25fl1_read_status2(priv->qspi); + status[2] = sf25fl1_read_status3(priv->qspi); + + if ((status[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) + { + /* Protection already disabled */ + + return 0; + } + + /* Check if sector protection registers are locked */ + + if ((status[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) + { + /* Yes.. unprotect section protection registers */ + + status[0] &= ~STATUS1_SRP0_MASK; + st25fl1_write_status(priv->qspi, status); + } + + /* Set the protection mask to zero. + * REVISIT: This logic should really just re-write the BP bits as + * necessary to unprotect the range of sectors. + */ + + status[0] &= ~STATUS1_BP_MASK; + st25fl1_write_status(priv->qspi, status); + + /* Check the new status */ + + status[0] = sf25fl1_read_status1(priv->qspi); + if ((status[0] & (STATUS1_SRP0_MASK | STATUS1_BP_MASK)) != 0) + { + return -EACCES; + } + + return OK; +} + +/************************************************************************************ + * Name: st25fl1_isprotected + ************************************************************************************/ + +static bool st25fl1_isprotected(FAR struct st25fl1_dev_s *priv, uint8_t status, + off_t address) { -#warning Missing Logic + off_t protstart; + off_t protend; + off_t protsize; + unsigned int bp; + + /* What is protected? 64 Kb blocks? Or 4Kb sectors? */ + + if ((status & STATUS1_SEC_MASK) == STATUS1_SEC_BLOCK) + { + /* 64 Kb block */ + + protsize = 0x00010000; + } + else + { + /* 4 Kb sector */ + + protsize = 0x00001000; + } + + /* The BP field is the essentially a multiplier on this protection size */ + + bp = (status & STATUS1_BP_MASK) >> STATUS1_BP_SHIFT; + switch (bp) + { + case 0: + return false; + + case 1: + break; + + case 6: + case 7: + return true; + + default: + protsize <<= (protsize << (bp - 1)); + break; + } + + /* The final protection range then depends on if the protection region is + * configured top-down or bottom up (assuming CMP=0). + */ + + if ((status & STATUS1_TB_MASK) != 0) + { + protstart = 0x00000000; + protend = protstart + protsize; + } + else + { + protend = 0x00200000; + protstart = protend - protsize; + } + + return (address >= protstart && address < protend); } /************************************************************************************ @@ -645,13 +808,10 @@ static void st25fl1_unprotect(FAR struct st25fl1_dev_s *priv) static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) { off_t address; -#ifdef CONFIG_DEBUG uint8_t status; -#endif fvdbg("sector: %08lx\n", (unsigned long)sector); -#ifdef CONFIG_DEBUG /* Check that the flash is ready and unprotected */ status = sf25fl1_read_status1(priv->qspi); @@ -661,18 +821,19 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) return -EBUSY; } - if ((status & STATUS1_BP_MASK) != 0) + /* Get the address associated with the sector */ + + address = (off_t)sector << priv->sectorshift; + + if ((status & STATUS1_BP_MASK) != 0 && + st25fl1_isprotected(priv, status, address)) { fdbg("ERROR: Flash protected: %02x", status); - /* REVISIT: Should check if this particular sector is protected */ - //return -EACCES; + return -EACCES; } -#endif /* Send the sector erase command */ - address = (off_t)sector << priv->sectorshift; - st25fl1_write_enable(priv->qspi); st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, address, 3); @@ -690,7 +851,6 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) { uint8_t status; -#ifdef CONFIG_DEBUG /* Check if the FLASH is protected */ status = sf25fl1_read_status1(priv->qspi); @@ -699,7 +859,6 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) fdbg("ERROR: FLASH is Protected: %02x", status); return -EACCES; } -#endif /* Erase the whole chip */ @@ -823,6 +982,8 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf #ifdef CONFIG_ST25FL1_SECTOR512 static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) { + int ret = OK; + /* If the cached is dirty (meaning that it no longer matches the old FLASH contents) * or was erased (with the cache containing the correct FLASH contents), then write * the cached erase block to FLASH. @@ -831,7 +992,12 @@ static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) if (IS_DIRTY(priv) || IS_ERASED(priv)) { /* Write entire erase block to FLASH */ -#warning Missing Logic + + ret = st25fl1_write_page(priv, priv->sector, 1 << priv->sectorshift); + if (ret < 0) + { + fdbg("ERROR: st25fl1_write_page failed: %d\n", ret); + } /* The case is no long dirty and the FLASH is no longer erased */ @@ -839,7 +1005,7 @@ static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) CLR_ERASED(priv); } - return OK; + return ret; } #endif @@ -1198,9 +1364,28 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) } break; - case MTDIOC_XIPBASE: + case MTDIOC_PROTECT: + { + FAR const struct mtd_protect_s *prot = + (FAR const struct mtd_protect_s *)((uintptr_t)arg); + + DEBUGASSERT(prot); + ret = st25fl1_protect(priv, prot->startblock, prot->nblocks); + } + break; + + case MTDIOC_UNPROTECT: + { + FAR const struct mtd_protect_s *prot = + (FAR const struct mtd_protect_s *)((uintptr_t)arg); + + DEBUGASSERT(prot); + ret = st25fl1_unprotect(priv, prot->startblock, prot->nblocks); + } + break; + default: - ret = -ENOTTY; /* Bad command */ + ret = -ENOTTY; /* Bad/unsupported command */ break; } @@ -1277,10 +1462,6 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) usleep(50*1000); } - /* Make sure that the FLASH is unprotected so that we can write into it */ - - st25fl1_unprotect(priv); - #ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ /* Allocate a buffer for the erase block cache */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index e9e4060ae6..b25f5585c0 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -46,6 +46,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -- GitLab From ed750f3600763874c5db6d96033e9ae2701c565c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Aug 2015 18:54:20 -0600 Subject: [PATCH 104/858] ST25FL1: Changes after review of ST24FL1 clocking --- arch | 2 +- drivers/mtd/Kconfig | 25 +++++++++++++++++++++++-- drivers/mtd/st25fl1.c | 32 +++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/arch b/arch index 7678d3b41e..9068b5bf82 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7678d3b41e8c697ac6d59154ed48135f12a14208 +Subproject commit 9068b5bf82084407894c61ed835a5c56d81e1cf6 diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index ea0ab7bf87..97ce9effca 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -397,9 +397,30 @@ config ST25FL1_QSPIMODE int "ST25FL1 QuadSPI Mode" default 0 -config ST25FL1_QSPIFREQUENCY +config ST25FL1_QSPI_FREQUENCY int "ST25FL1 QuadSPI Frequency" - default 20000000 + default 108000000 + ---help--- + Per data sheet: + – Normal Read (Serial): + – 50 MHz clock rate (-40°C to +85°C/105°C) + – 45 MHz clock rate (-40°C to +125°C) + – Fast Read (Serial): + – 108 MHz clock rate (-40°C to +85°C/105°C) + – 97 MHz clock rate (-40°C to +125°C) + – Dual Read: + – 108 MHz clock rate (-40°C to +85°C/105°C) + – 97 MHz clock rate (-40°C to +125°C) + – Quad Read: + – 108 MHz clock rate (-40°C to +85°C/105°C) + – 97 MHz clock rate for S25FL164K (-40°C to +125°C) + + - Clock frequency for all SPI commands except for Read Data + command (0x03) and Fast Read command (0x0b): 108 MHz + - Clock frequency for Read Data command (0x03): 50 MHz + - Clock frequency for all Fast Read commands SIO and MIO: 108 MHz + + In this implementation, only "Quad" reads are performed. config ST25FL1_SECTOR512 bool "Simulate 512 byte Erase Blocks" diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 5038cd2103..1342235111 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -60,16 +60,38 @@ * Pre-processor Definitions ************************************************************************************/ /* Configuration ********************************************************************/ -/* QuadSPI Mode */ +/* QuadSPI Mode. Per data sheet, either Mode 0 or Mode 3 may be used. */ #ifndef CONFIG_ST25FL1_QSPIMODE # define CONFIG_ST25FL1_QSPIMODE QSPIDEV_MODE0 #endif -/* QuadSPI Frequency. May be up to 25MHz. */ +/* QuadSPI Frequency per data sheet:: + * + * – Normal Read (Serial): + * 50 MHz clock rate (-40°C to +85°C/105°C) + * 45 MHz clock rate (-40°C to +125°C) + * – Fast Read (Serial): + * 108 MHz clock rate (-40°C to +85°C/105°C) + * 97 MHz clock rate (-40°C to +125°C) + * – Dual Read: + * 108 MHz clock rate (-40°C to +85°C/105°C) + * 97 MHz clock rate (-40°C to +125°C) + * – Quad Read: + * 108 MHz clock rate (-40°C to +85°C/105°C) + * 97 MHz clock rate for S25FL164K (-40°C to +125°C) + * + * Table 5.8: + * - Clock frequency for all SPI commands except for Read Data + * command (0x03) and Fast Read command (0x0b): 108 MHz + * - Clock frequency for Read Data command (0x03): 50 MHz + * - Clock frequency for all Fast Read commands SIO and MIO: 108 MHz + * + * In this implementation, only "Quad" reads are performed. + */ -#ifndef CONFIG_ST25FL1_QSPIFREQUENCY -# define CONFIG_ST25FL1_QSPIFREQUENCY 20000000 +#ifndef CONFIG_ST25FL1_QSPI_FREQUENCY +# define CONFIG_ST25FL1_QSPI_FREQUENCY 108000000 #endif /* ST25FL1 Commands *****************************************************************/ @@ -394,7 +416,7 @@ static void st25fl1_lock(FAR struct qspi_dev_s *qspi) QSPI_SETMODE(qspi, CONFIG_ST25FL1_QSPIMODE); QSPI_SETBITS(qspi, 8); - (void)QSPI_SETFREQUENCY(qspi, CONFIG_ST25FL1_QSPIFREQUENCY); + (void)QSPI_SETFREQUENCY(qspi, CONFIG_ST25FL1_QSPI_FREQUENCY); } /************************************************************************************ -- GitLab From 3fd07e32e9a6a9d9cea26ef2362caa80ec109d0e Mon Sep 17 00:00:00 2001 From: Bruno Herrera Date: Sun, 30 Aug 2015 07:14:45 -0600 Subject: [PATCH 105/858] binfmt/builtin.c: Fix a memory leak: File was not being closed. --- ChangeLog | 3 +++ binfmt/builtin.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index fc2b2decd2..6f6479b67b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10903,3 +10903,6 @@ * include/nuttx/mtd/mtd.h: Move MTD ioctl command definitions from include/nuttx/fs/fs.h to include/nuttx/mtd.h. Add ioctl commands to protect and unprotect memory (2015-08-29). + * binfmt/builtin.c: Fix a memory leak: File was not being closed. + From Bruno Herrera (2015-08-30). + diff --git a/binfmt/builtin.c b/binfmt/builtin.c index 4e6b18c9c4..537556136b 100644 --- a/binfmt/builtin.c +++ b/binfmt/builtin.c @@ -116,6 +116,7 @@ static int builtin_loadbinary(struct binary_s *binp) { int errval = get_errno(); bdbg("ERROR: FIOC_FILENAME ioctl failed: %d\n", errval); + close(fd); return -errval; } @@ -128,6 +129,7 @@ static int builtin_loadbinary(struct binary_s *binp) { int errval = get_errno(); bdbg("ERROR: %s is not a builtin application\n", filename); + close(fd); return -errval; } @@ -140,6 +142,7 @@ static int builtin_loadbinary(struct binary_s *binp) binp->entrypt = b->main; binp->stacksize = b->stacksize; binp->priority = b->priority; + close(fd); return OK; } -- GitLab From 915792cca14e1dd54a00af6796d5d0d3ff6736b9 Mon Sep 17 00:00:00 2001 From: Bruno Herrera Date: Sun, 30 Aug 2015 18:31:58 -0600 Subject: [PATCH 106/858] fs/romfs: One allocation was not being freed if there was a subsequent failure to allocation I/O buffers resulting in a memory leak on certain error conditions. From Bruno Herrera. --- ChangeLog | 4 +++- fs/romfs/fs_romfs.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6f6479b67b..16ea59458f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10905,4 +10905,6 @@ to protect and unprotect memory (2015-08-29). * binfmt/builtin.c: Fix a memory leak: File was not being closed. From Bruno Herrera (2015-08-30). - + * fs/romfs: One allocation was not being freed if there was a + subsequent failure to allocation I/O buffers resulting in a memory + leak on certain error conditions. From Bruno Herrera (2015-08-30). diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 3a65adfc2b..14c68ef7e8 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -656,6 +656,7 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp) ret = romfs_fileconfigure(rm, newrf); if (ret < 0) { + kmm_free(newrf); fdbg("Failed configure buffering: %d\n", ret); goto errout_with_semaphore; } -- GitLab From 409262a8ef5458cec33c0169da3ac54987f52757 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 31 Aug 2015 08:41:17 -0600 Subject: [PATCH 107/858] Update ChangeLog/sub-module version --- ChangeLog | 6 ++++++ arch | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 16ea59458f..f48482e5a6 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10908,3 +10908,9 @@ * fs/romfs: One allocation was not being freed if there was a subsequent failure to allocation I/O buffers resulting in a memory leak on certain error conditions. From Bruno Herrera (2015-08-30). + * arch/arm/src/up_iternal.h and several ARM Make.defs files: In the + original implementation, !defined(CONFIG_ARMV7M_CMNVECTOR) was a + sufficient test to determine if lazy floating point register saving + was being used. But recents changes added common lazy register as + well so now that test must be (!defined(CONFIG_ARMV7M_CMNVECTOR) || + defined(CONFIG_ARMV7M_LAZYFPU)) (2015-08-31). diff --git a/arch b/arch index 9068b5bf82..e076ee09c2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9068b5bf82084407894c61ed835a5c56d81e1cf6 +Subproject commit e076ee09c276733d56014afa87c19c077b8f9385 -- GitLab From 2d842705523b63a0c4ea6b22c5a18a9bab0a8c7f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 31 Aug 2015 09:25:14 -0600 Subject: [PATCH 108/858] ST25FL1: Correct some compile problems when file system debug is enabled --- arch | 2 +- configs | 2 +- drivers/mtd/st25fl1.c | 13 ++++++++----- include/nuttx/mtd/mtd.h | 12 ++++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/arch b/arch index e076ee09c2..eaba40bd73 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e076ee09c276733d56014afa87c19c077b8f9385 +Subproject commit eaba40bd7303c737a812e307e2b687cd473d90da diff --git a/configs b/configs index 0198c46e0b..08a06b5db2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0198c46e0bd38d2a7fada9e4a1ea445218284c61 +Subproject commit 08a06b5db223a973e8f25b092f787e27ccc7b400 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 1342235111..85cc495ae7 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -908,7 +908,7 @@ static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer { struct qspi_meminfo_s meminfo; - fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)nbytes); + fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)buflen); #ifdef CONFIG_ST25FL1_SCRAMBLE meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO | QSPIMEM_SCRAMBLE; @@ -977,7 +977,7 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf if (ret < 0) { fdbg("ERROR: QSPI_MEMORY failed writing address=%06x\n", - address) + address); return ret; } @@ -1423,9 +1423,12 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * Name: st25fl1_initialize * * Description: - * Create an initialize MTD device instance. MTD devices are not registered - * in the file system, but are created as instances that can be bound to - * other functions (such as a block or character driver front end). + * Create an initialize MTD device instance for the QuadSPI-based ST24FL1 + * FLASH part. + * + * MTD devices are not registered in the file system, but are created as instances + * that can be bound to other functions (such as a block or character driver front + * end). * ************************************************************************************/ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index b25f5585c0..976b47a367 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -474,6 +474,18 @@ FAR struct mtd_dev_s *sst39vf_initialize(void); FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); +/**************************************************************************** + * Name: st25fl1_initialize + * + * Description: + * Create an initialize MTD device instance for the QuadSPI-based ST24FL1 + * FLASH part. + * + ****************************************************************************/ + +struct qspi_dev_s; /* Forward reference */ +FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi); + /**************************************************************************** * Name: up_flashinitialize * -- GitLab From ebd97dcf89abb0fbc75aa9b78442fd12cec6ba90 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 31 Aug 2015 10:18:50 -0600 Subject: [PATCH 109/858] ST25FL1: Make buffers all even multiple of 32-bit values --- arch | 2 +- drivers/mtd/st25fl1.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch b/arch index eaba40bd73..f33bbe8b35 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit eaba40bd7303c737a812e307e2b687cd473d90da +Subproject commit f33bbe8b35c3c18c0f740a7f3c2e08557d996c63 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 85cc495ae7..d889d77bac 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -586,7 +586,7 @@ static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi) * Name: st25fl1_write_status ************************************************************************************/ -static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[3]) +static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[4]) { st25fl1_write_enable(qspi); st25fl1_command_write(qspi, ST25FL1_WRITE_STATUS, (FAR const void *)status, 3); @@ -599,7 +599,7 @@ static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[3]) static inline int st25fl1_readid(struct st25fl1_dev_s *priv) { - uint8_t jedecid[3]; + uint8_t jedecid[4]; /* Lock the QuadSPI bus and configure the bus. */ @@ -663,7 +663,7 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[3]; + unsigned char status[4]; /* Get the status register value to check the current protection */ @@ -714,7 +714,7 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[3]; + unsigned char status[4]; /* Get the status register value to check the current protection */ @@ -1435,7 +1435,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) { FAR struct st25fl1_dev_s *priv; - uint8_t status[3]; + uint8_t status[4]; int ret; fvdbg("qspi: %p\n", qspi); -- GitLab From bb385c242faf74ed919f39a4b875bfb0b76eb64d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 31 Aug 2015 15:23:01 -0600 Subject: [PATCH 110/858] Update changelog/submodule --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index f48482e5a6..2413f5ba66 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10914,3 +10914,7 @@ was being used. But recents changes added common lazy register as well so now that test must be (!defined(CONFIG_ARMV7M_CMNVECTOR) || defined(CONFIG_ARMV7M_LAZYFPU)) (2015-08-31). + * arch/arm/include/sama5 and src/sama5: Add basic chip description, + configuration support and interrupt definitions for the SAMA5D2 + (2015-08-31). + -- GitLab From 5ac6de118ed9a4e7fde5c04cff081b50afe2af5d Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Tue, 1 Sep 2015 08:45:14 -0600 Subject: [PATCH 111/858] libc/math/lib_asin.c: The function did not convert for some input values. Asin did not convert for values which do not belong to the domain of the function. But aside of that the function also did not convert for sine allowed values. I achieved a conversion of the function by reducing the DBL_EPSION and by checking if the input value is in the domain of the function. This is a fix for the problem but the function should always terminate after a given number of iterations. From Stefan Kolb. --- ChangeLog | 13 ++++++++++++- TODO | 6 +++++- libc/math/lib_asin.c | 20 ++++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2413f5ba66..b52c0672ad 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10917,4 +10917,15 @@ * arch/arm/include/sama5 and src/sama5: Add basic chip description, configuration support and interrupt definitions for the SAMA5D2 (2015-08-31). - + * LPC43xx: Fix NVIC_SYSH_PRIORITY_STEP define. From Ilya Averyanov + (2015-09-01). + * LPC43xx: Fix missing #define in eeprom. From Ilya Averyanov + (2015-09-01). + * libc/math/lib_asin.c: The function did not convert for some input + values. Asin did not convert for values which do not belong to the + domain of the function. But aside of that the function also did not + convert for sine allowed values. I achieved a conversion of the + function by reducing the DBL_EPSION and by checking if the input + value is in the domain of the function. This is a fix for the + problem but the function should always terminate after a given + number of iterations. From Stefan Kolb (2015-09-01). diff --git a/TODO b/TODO index 55324a46f8..c6c07c00f3 100644 --- a/TODO +++ b/TODO @@ -1318,12 +1318,16 @@ o Libraries (libc/) it does not return at all as the loop in it does not converge, hanging your app. - "There are likely many other issues like these as the Rhombs + "There are likely many other issues like these as the Rhombus OS code has not been tested or used that much. Sorry for not providing patches, but we found it easier just to switch the math library." Ref: https://groups.yahoo.com/neo/groups/nuttx/conversations/messages/7805 + + UPDATE: 2015-09-01: A fix for the noted problems with asin() + has been applied. + Status: Open Priority: Low for casual users but clearly high if you need care about these incorrect corner case behaviors in the math libraries. diff --git a/libc/math/lib_asin.c b/libc/math/lib_asin.c index 9518fb69c7..5940ce8215 100644 --- a/libc/math/lib_asin.c +++ b/libc/math/lib_asin.c @@ -3,7 +3,7 @@ * * This file is a part of NuttX: * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. * Ported by: Darcy Gong * * It derives from the Rhombs OS math library by Nick Johnson which has @@ -35,6 +35,13 @@ #include #include +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ + +#undef DBL_EPSILON +#define DBL_EPSILON 1e-12 + /************************************************************************ * Public Functions ************************************************************************/ @@ -42,7 +49,16 @@ #ifdef CONFIG_HAVE_DOUBLE double asin(double x) { - long double y, y_sin, y_cos; + long double y; + long double y_sin; + long double y_cos; + + /* Verify that the input value is in the domain of the function */ + + if (x < -1.0 || x > 1.0) + { + return NAN; + } y = 0; -- GitLab From 3b89eabd50155f603aaf4fa3bad6bfdb6b847c41 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 1 Sep 2015 09:04:09 -0400 Subject: [PATCH 112/858] Correct #if to #ifdef when the macro can be undefined. Fix bug in AT24XX driver: it should compare AT24XX_ADDRSIZE to 2. --- crypto/crypto.c | 2 +- drivers/mtd/at24xx.c | 2 +- drivers/net/dm90x0.c | 10 ++--- drivers/pipes/pipe_common.c | 2 +- drivers/serial/serial.c | 2 +- drivers/usbdev/cdcacm.c | 12 +++--- drivers/usbdev/pl2303.c | 12 +++--- drivers/usbdev/usbmsc.c | 2 +- drivers/video/ov2640.c | 4 +- graphics/nxbe/nxbe_colormap.c | 2 +- graphics/nxmu/nxmu_server.c | 2 +- graphics/nxsu/nx_open.c | 2 +- include/cxx/cmath | 4 +- include/nuttx/float.h | 18 ++++----- include/nuttx/math.h | 62 ++++++++++++++--------------- include/nuttx/timers/rtc.h | 2 +- libc/stdio/lib_fgetpos.c | 2 +- libc/stdio/lib_fsetpos.c | 2 +- libxx/libxx_cxa_atexit.cxx | 4 +- net/neighbor/neighbor.h | 2 +- net/socket/net_sockets.c | 2 +- sched/group/group_killchildren.c | 2 +- sched/sched/sched_timerexpiration.c | 2 +- sched/task/task_restart.c | 2 +- 24 files changed, 79 insertions(+), 79 deletions(-) diff --git a/crypto/crypto.c b/crypto/crypto.c index 9b4391b5bb..401417d874 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -77,7 +77,7 @@ int up_cryptoinitialize(void) } #endif -#if CONFIG_CRYPTO_ALGTEST +#ifdef CONFIG_CRYPTO_ALGTEST res = crypto_test(); if (res) { diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index fbb56b7108..32ea3c618e 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -356,7 +356,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t while (blocksleft-- > 0) { -#if AT24XX_ADDRSIZE +#if AT24XX_ADDRSIZE == 2 uint16_t offset = startblock * priv->pagesize; buf[1] = offset & 0xff; buf[0] = (offset >> 8) & 0xff; diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index 03e1e44f8d..d9f3644a43 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -1411,19 +1411,19 @@ static inline void dm9x_phymode(struct dm9x_driver_s *dm9x) uint16_t phyreg0; uint16_t phyreg4; -#if CONFIG_DM9X_MODE_AUTO +#ifdef CONFIG_DM9X_MODE_AUTO phyreg0 = 0x1200; /* Auto-negotiation & Restart Auto-negotiation */ phyreg4 = 0x01e1; /* Default flow control disable*/ -#elif CONFIG_DM9X_MODE_10MHD +#elif defined(CONFIG_DM9X_MODE_10MHD) phyreg4 = 0x21; phyreg0 = 0x1000; -#elif CONFIG_DM9X_MODE_10MFD +#elif defined(CONFIG_DM9X_MODE_10MFD) phyreg4 = 0x41; phyreg0 = 0x1100; -#elif CONFIG_DM9X_MODE_100MHD +#elif defined(CONFIG_DM9X_MODE_100MHD) phyreg4 = 0x81; phyreg0 = 0x3000; -#elif CONFIG_DM9X_MODE_100MFD +#elif defined(CONFIG_DM9X_MODE_100MFD) phyreg4 = 0x101; phyreg0 = 0x3100; #else diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index e2f33aceec..c077ea537f 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -55,7 +55,7 @@ #include #include -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG # include #endif diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index ff4fe55d47..b07f655466 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -954,7 +954,7 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) /* Some sanity checking */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !fds) { return -ENODEV; diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index d57eb5aa41..564fbf6229 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -645,7 +645,7 @@ static int cdcacm_setconfig(FAR struct cdcacm_dev_s *priv, uint8_t config) int i; int ret = 0; -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (priv == NULL) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -1765,7 +1765,7 @@ static int cdcuart_setup(FAR struct uart_dev_s *dev) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -1806,7 +1806,7 @@ static void cdcuart_shutdown(FAR struct uart_dev_s *dev) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2065,7 +2065,7 @@ static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2194,7 +2194,7 @@ static void cdcuart_txint(FAR struct uart_dev_s *dev, bool enable) /* Sanity checks */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2237,7 +2237,7 @@ static bool cdcuart_txempty(FAR struct uart_dev_s *dev) usbtrace(CDCACM_CLASSAPI_TXEMPTY, 0); -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index bb98a717ea..526322cbb4 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -1046,7 +1046,7 @@ static int usbclass_setconfig(FAR struct pl2303_dev_s *priv, uint8_t config) int i; int ret = 0; -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (priv == NULL) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2016,7 +2016,7 @@ static int usbser_setup(FAR struct uart_dev_s *dev) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2057,7 +2057,7 @@ static void usbser_shutdown(FAR struct uart_dev_s *dev) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2119,7 +2119,7 @@ static void usbser_rxint(FAR struct uart_dev_s *dev, bool enable) /* Sanity check */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2210,7 +2210,7 @@ static void usbser_txint(FAR struct uart_dev_s *dev, bool enable) /* Sanity checks */ -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!dev || !dev->priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); @@ -2253,7 +2253,7 @@ static bool usbser_txempty(FAR struct uart_dev_s *dev) usbtrace(PL2303_CLASSAPI_TXEMPTY, 0); -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!priv) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 941563494c..6a6d425b04 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -934,7 +934,7 @@ int usbmsc_setconfig(FAR struct usbmsc_dev_s *priv, uint8_t config) int i; int ret = 0; -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (priv == NULL) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_SETCONFIGINVALIDARGS), 0); diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 7256fbc202..1e736f5e07 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -811,7 +811,7 @@ static int ovr2640_chipid(FAR struct i2c_dev_s *i2c) { uint8_t pidl; uint8_t pidh; -#if CONFIG_DEBUG_GRAPHICS +#ifdef CONFIG_DEBUG_GRAPHICS uint8_t midh; uint8_t midl; #endif @@ -829,7 +829,7 @@ static int ovr2640_chipid(FAR struct i2c_dev_s *i2c) pidl = ov2640_getreg(i2c, 0x0a); /* Product ID (MS) */ pidh = ov2640_getreg(i2c, 0x0b); /* Product ID (LS) */ -#if CONFIG_DEBUG_GRAPHICS +#ifdef CONFIG_DEBUG_GRAPHICS midh = ov2640_getreg(i2c, 0x1c); /* Manufacturer ID (high) = 0x7f */ midl = ov2640_getreg(i2c, 0x1d); /* Manufacturer ID (low) = 0xa2 */ #endif diff --git a/graphics/nxbe/nxbe_colormap.c b/graphics/nxbe/nxbe_colormap.c index 536c317541..d5d84e238c 100644 --- a/graphics/nxbe/nxbe_colormap.c +++ b/graphics/nxbe/nxbe_colormap.c @@ -81,7 +81,7 @@ * ****************************************************************************/ -#if CONFIG_FB_CMAP +#ifdef CONFIG_FB_CMAP int nxbe_colormap(FAR NX_DRIVERTYPE *dev) { struct fb_cmap_s cmap; diff --git a/graphics/nxmu/nxmu_server.c b/graphics/nxmu/nxmu_server.c index eb7fbd75ca..1f13dba908 100644 --- a/graphics/nxmu/nxmu_server.c +++ b/graphics/nxmu/nxmu_server.c @@ -192,7 +192,7 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, return ERROR; } -#if CONFIG_FB_CMAP +#ifdef CONFIG_FB_CMAP ret = nxbe_colormap(dev); if (ret < 0) { diff --git a/graphics/nxsu/nx_open.c b/graphics/nxsu/nx_open.c index 5132b36e96..3f4629f90c 100644 --- a/graphics/nxsu/nx_open.c +++ b/graphics/nxsu/nx_open.c @@ -125,7 +125,7 @@ static inline int nxsu_setup(FAR NX_DRIVERTYPE *dev, return ERROR; } -#if CONFIG_FB_CMAP +#ifdef CONFIG_FB_CMAP ret = nxbe_colormap(dev); if (ret < 0) { diff --git a/include/cxx/cmath b/include/cxx/cmath index b30d5548b7..998406c153 100644 --- a/include/cxx/cmath +++ b/include/cxx/cmath @@ -51,7 +51,7 @@ namespace std { -#if CONFIG_HAVE_FLOAT +#ifdef CONFIG_HAVE_FLOAT using ::acosf; using ::asinf; using ::atanf; @@ -78,7 +78,7 @@ namespace std using ::tanhf; #endif -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE using ::acos; using ::asin; using ::atan; diff --git a/include/nuttx/float.h b/include/nuttx/float.h index a8e4aa28b5..a4d8945ee5 100644 --- a/include/nuttx/float.h +++ b/include/nuttx/float.h @@ -61,7 +61,7 @@ #define FLT_MANT_DIG 24 -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MANT_DIG 53 #else # define DBL_MANT_DIG FLT_MANT_DIG @@ -88,7 +88,7 @@ #define FLT_DIG 6 -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_DIG 15 /* 10 */ #else # define DBL_DIG FLT_DIG @@ -106,7 +106,7 @@ #define FLT_MIN_EXP (-125) -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MIN_EXP (-1021) #else # define DBL_MIN_EXP FLT_MIN_EXP @@ -124,7 +124,7 @@ #define FLT_MIN_10_EXP (-37) -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MIN_10_EXP (-307) /* -37 */ #else # define DBL_MIN_10_EXP FLT_MIN_10_EXP @@ -142,7 +142,7 @@ #define FLT_MAX_EXP 128 -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MAX_EXP 1024 #else # define DBL_MAX_EXP FLT_MAX_EXP @@ -160,7 +160,7 @@ #define FLT_MAX_10_EXP 38 /* 37 */ -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MAX_10_EXP 308 /* 37 */ #else # define DBL_MAX_10_EXP FLT_MAX_10_EXP @@ -176,7 +176,7 @@ #define FLT_MAX 3.40282347e+38F /* 1E+37 */ -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_MAX 1.7976931348623157e+308 /* 1E+37 */ #else # define DBL_MAX FLT_MAX @@ -194,7 +194,7 @@ #define FLT_EPSILON 1.1920929e-07F /* 1E-5 */ -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE # define DBL_EPSILON 2.2204460492503131e-16 /* 1E-9 */ #else # define DBL_EPSILON FLT_EPSILON @@ -210,7 +210,7 @@ #define FLT_MIN 1.17549435e-38F /* 1E-37 */ -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE #define DBL_MIN 2.2250738585072014e-308 /* 1E-37 */ #else # define DBL_MIN FLT_MIN diff --git a/include/nuttx/math.h b/include/nuttx/math.h index 40990352af..6ee91eab7e 100644 --- a/include/nuttx/math.h +++ b/include/nuttx/math.h @@ -128,7 +128,7 @@ extern "C" /* General Functions ********************************************************/ float ceilf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double ceil (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -136,7 +136,7 @@ long double ceill (long double x); #endif float floorf(float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double floor (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -144,7 +144,7 @@ long double floorl(long double x); #endif float roundf(float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double round (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -152,7 +152,7 @@ long double roundl(long double x); #endif float rintf(float x); /* Not implemented */ -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double rint(double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -160,7 +160,7 @@ long double rintl(long double x); /* Not implemented */ #endif float fabsf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double fabs (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -168,7 +168,7 @@ long double fabsl (long double x); #endif float modff (float x, float *iptr); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double modf (double x, double *iptr); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -176,7 +176,7 @@ long double modfl (long double x, long double *iptr); #endif float fmodf (float x, float div); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double fmod (double x, double div); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -186,7 +186,7 @@ long double fmodl (long double x, long double div); /* Exponential and Logarithmic Functions ************************************/ float powf (float b, float e); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double pow (double b, double e); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -195,7 +195,7 @@ long double powl (long double b, long double e); float expf (float x); #define expm1f(x) (expf(x) - 1.0) -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double exp (double x); #define expm1(x) (exp(x) - 1.0) #endif @@ -205,7 +205,7 @@ long double expl (long double x); #endif float logf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double log (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -213,7 +213,7 @@ long double logl (long double x); #endif float log10f(float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double log10 (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -221,7 +221,7 @@ long double log10l(long double x); #endif float log2f (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double log2 (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -229,7 +229,7 @@ long double log2l (long double x); #endif float sqrtf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double sqrt (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -237,7 +237,7 @@ long double sqrtl (long double x); #endif float ldexpf(float x, int n); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double ldexp (double x, int n); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -245,7 +245,7 @@ long double ldexpl(long double x, int n); #endif float frexpf(float x, int *exp); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double frexp (double x, int *exp); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -255,7 +255,7 @@ long double frexpl(long double x, int *exp); /* Trigonometric Functions **************************************************/ float sinf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double sin (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -263,7 +263,7 @@ long double sinl (long double x); #endif float cosf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double cos (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -271,7 +271,7 @@ long double cosl (long double x); #endif float tanf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double tan (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -279,7 +279,7 @@ long double tanl (long double x); #endif float asinf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double asin (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -287,7 +287,7 @@ long double asinl (long double x); #endif float acosf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double acos (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -295,7 +295,7 @@ long double acosl (long double x); #endif float atanf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double atan (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -303,7 +303,7 @@ long double atanl (long double x); #endif float atan2f(float y, float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double atan2 (double y, double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -311,7 +311,7 @@ long double atan2l(long double y, long double x); #endif float sinhf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double sinh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -319,7 +319,7 @@ long double sinhl (long double x); #endif float coshf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double cosh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -327,7 +327,7 @@ long double coshl (long double x); #endif float tanhf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double tanh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -335,7 +335,7 @@ long double tanhl (long double x); #endif float asinhf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double asinh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -343,7 +343,7 @@ long double asinhl (long double x); #endif float acoshf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double acosh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -351,7 +351,7 @@ long double acoshl (long double x); #endif float atanhf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double atanh (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -360,7 +360,7 @@ long double atanhl (long double x); float erff (float x); #define erfcf(x) (1 - erff(x)) -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double erf (double x); #define erfc(x) (1 - erf(x)) #endif @@ -370,7 +370,7 @@ long double erfl (long double x); #endif float copysignf (float x, float y); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double copysign (double x, double y); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE @@ -378,7 +378,7 @@ long double copysignl (long double x, long double y); #endif float truncf (float x); -#if CONFIG_HAVE_DOUBLE +#ifdef CONFIG_HAVE_DOUBLE double trunc (double x); #endif #ifdef CONFIG_HAVE_LONG_DOUBLE diff --git a/include/nuttx/timers/rtc.h b/include/nuttx/timers/rtc.h index d714e040f1..7cbc928d92 100644 --- a/include/nuttx/timers/rtc.h +++ b/include/nuttx/timers/rtc.h @@ -111,7 +111,7 @@ * RTC upper half driver is built. */ -#if CONFIG_RTC_DRIVER +#ifdef CONFIG_RTC_DRIVER /* IOCTL Commands ***********************************************************/ /* RTC driver IOCTL commands. These are Linux compatible command names, not diff --git a/libc/stdio/lib_fgetpos.c b/libc/stdio/lib_fgetpos.c index 5727c63ef9..322890613e 100644 --- a/libc/stdio/lib_fgetpos.c +++ b/libc/stdio/lib_fgetpos.c @@ -104,7 +104,7 @@ int fgetpos(FAR FILE *stream, FAR fpos_t *pos) { long position; -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!stream || !pos) { set_errno(EINVAL); diff --git a/libc/stdio/lib_fsetpos.c b/libc/stdio/lib_fsetpos.c index 6cf1c9eedb..d33fe4ca30 100644 --- a/libc/stdio/lib_fsetpos.c +++ b/libc/stdio/lib_fsetpos.c @@ -104,7 +104,7 @@ int fsetpos(FAR FILE *stream, FAR fpos_t *pos) { -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (!stream || !pos) { set_errno(EINVAL); diff --git a/libxx/libxx_cxa_atexit.cxx b/libxx/libxx_cxa_atexit.cxx index d7a82fe5b7..5e01f99f27 100644 --- a/libxx/libxx_cxa_atexit.cxx +++ b/libxx/libxx_cxa_atexit.cxx @@ -83,7 +83,7 @@ extern "C" // //************************************************************************* -#if CONFIG_SCHED_ONEXIT +#ifdef CONFIG_SCHED_ONEXIT static void __cxa_callback(int exitcode, FAR void *arg) { FAR struct __cxa_atexit_s *alloc = (FAR struct __cxa_atexit_s *)arg; @@ -118,7 +118,7 @@ extern "C" int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle) { -#if CONFIG_SCHED_ONEXIT +#ifdef CONFIG_SCHED_ONEXIT // Allocate memory to hold the marshaled __cxa_exitfunc_t call // information. diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 087f1a414c..0a2a1c287f 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -70,7 +70,7 @@ struct neighbor_addr_s { -#if CONFIG_NET_IPv6_NEIGHBOR_ADDRTYPE +#ifdef CONFIG_NET_IPv6_NEIGHBOR_ADDRTYPE CONFIG_NET_IPv6_NEIGHBOR_ADDRTYPE na_addr; #else struct ether_addr na_addr; diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index 6c7e1d1128..83ad061f6e 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -217,7 +217,7 @@ int sockfd_allocate(int minsd) void sock_release(FAR struct socket *psock) { -#if CONFIG_DEBUG +#ifdef CONFIG_DEBUG if (psock) #endif { diff --git a/sched/group/group_killchildren.c b/sched/group/group_killchildren.c index a320d50bc5..265b04036b 100644 --- a/sched/group/group_killchildren.c +++ b/sched/group/group_killchildren.c @@ -43,7 +43,7 @@ #include "group/group.h" -#if HAVE_GROUP_MEMBERS +#ifdef HAVE_GROUP_MEMBERS /**************************************************************************** * Private Functions diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 7546ec8046..8c223d4cb0 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -317,7 +317,7 @@ static void sched_timer_start(unsigned int ticks) { struct timespec ts; -#if CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP +#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP if (ticks > g_oneshot_maxticks) { ticks = g_oneshot_maxticks; diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index 0d86326968..a81115c173 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -151,7 +151,7 @@ int task_restart(pid_t pid) /* Kill any children of this thread */ -#if HAVE_GROUP_MEMBERS +#ifdef HAVE_GROUP_MEMBERS (void)group_killchildren(tcb); #endif -- GitLab From 9fcad39a454a6061b2deb60039ebbb70a87e6090 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Sep 2015 10:09:33 -0600 Subject: [PATCH 113/858] Trivial typo fix --- net/tcp/tcp_netpoll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tcp/tcp_netpoll.c b/net/tcp/tcp_netpoll.c index 41793f3641..dbe8eff03f 100644 --- a/net/tcp/tcp_netpoll.c +++ b/net/tcp/tcp_netpoll.c @@ -127,7 +127,7 @@ static uint16_t tcp_poll_interrupt(FAR struct net_driver_s *dev, FAR void *conn, eventset |= (POLLERR | POLLHUP); } - /* Awaken the caller of poll() is requested event occurred. */ + /* Awaken the caller of poll() if requested event occurred. */ if (eventset) { -- GitLab From f44320d2a61deaadae8608dc501371512bd4c670 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Sep 2015 10:19:47 -0600 Subject: [PATCH 114/858] ST25FL1: SAMV71 QSPI always does transfers in multiples of 4 bytes --- ChangeLog | 4 ++++ arch | 2 +- configs | 2 +- drivers/mtd/st25fl1.c | 39 ++++++++++++++++++++++++--------------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index b52c0672ad..b995e34d8b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10929,3 +10929,7 @@ value is in the domain of the function. This is a fix for the problem but the function should always terminate after a given number of iterations. From Stefan Kolb (2015-09-01). + * arch/arm/src/lpc43xx/lpc43_spi.c: Fix SPI driver. From Ilya + Averyanov (2015-09-02). + * arch/arm/src/lpc43xx/lpc43_ethernet.c: Add Ethernet support. From + Ilya Averyanov (2015-09-02). diff --git a/arch b/arch index f33bbe8b35..13137a4649 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f33bbe8b35c3c18c0f740a7f3c2e08557d996c63 +Subproject commit 13137a4649726a9f1b96208d21e1860ecd6f77f0 diff --git a/configs b/configs index 08a06b5db2..a29659af3e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 08a06b5db223a973e8f25b092f787e27ccc7b400 +Subproject commit a29659af3e80ec0e77f8bc794d5f9a1080e98842 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index d889d77bac..73a7b3ebcd 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -263,7 +263,6 @@ # define STATUS3_W56_63BYTE (3 << STATUS3_W56_SHIFT) /* Bit 7: Reserved */ - /* Chip Geometries ******************************************************************/ /* All members of the family support uniform 4K-byte sectors */ @@ -303,6 +302,15 @@ #define CLR_DIRTY(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) #define CLR_ERASED(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) +/* Misc. ****************************************************************************/ +/* The SAMV7x QSPI driver insists that transfers be performed in multiples of 32- + * bits. Other QSPI drivers could have other requirements but, so far, there seems + * to be no harm in making this unconditional. + */ + +#define ALIGN_MASK 3 +#define ALIGN_UP(n) (((n)+ALIGN_MASK) & ~ALIGN_MASK) + /************************************************************************************ * Private Types ************************************************************************************/ @@ -517,11 +525,11 @@ static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi) { - uint8_t status; + uint8_t status[ALIGN_UP(1)]; DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS1, - (FAR void *)&status, 1)); - return status; + (FAR void *)&status[0], 1)); + return status[0]; } /************************************************************************************ @@ -530,11 +538,11 @@ static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi) static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi) { - uint8_t status; + uint8_t status[ALIGN_UP(1)]; DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS2, - (FAR void *)&status, 1)); - return status; + (FAR void *)&status[0], 1)); + return status[0]; } /************************************************************************************ @@ -543,11 +551,11 @@ static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi) static uint8_t sf25fl1_read_status3(FAR struct qspi_dev_s *qspi) { - uint8_t status; + uint8_t status[ALIGN_UP(1)]; DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS3, - (FAR void *)&status, 1)); - return status; + (FAR void *)&status[0], 1)); + return status[0]; } /************************************************************************************ @@ -586,7 +594,8 @@ static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi) * Name: st25fl1_write_status ************************************************************************************/ -static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[4]) +static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, + uint8_t status[ALIGN_UP(3)]) { st25fl1_write_enable(qspi); st25fl1_command_write(qspi, ST25FL1_WRITE_STATUS, (FAR const void *)status, 3); @@ -599,7 +608,7 @@ static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, uint8_t status[4]) static inline int st25fl1_readid(struct st25fl1_dev_s *priv) { - uint8_t jedecid[4]; + uint8_t jedecid[ALIGN_UP(3)]; /* Lock the QuadSPI bus and configure the bus. */ @@ -663,7 +672,7 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[4]; + unsigned char status[ALIGN_UP(3)]; /* Get the status register value to check the current protection */ @@ -714,7 +723,7 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[4]; + unsigned char status[ALIGN_UP(3)]; /* Get the status register value to check the current protection */ @@ -1435,7 +1444,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) { FAR struct st25fl1_dev_s *priv; - uint8_t status[4]; + uint8_t status[ALIGN_UP(3)]; int ret; fvdbg("qspi: %p\n", qspi); -- GitLab From 0e2986f131ee13aa9938b5419fae32227309dd91 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Sep 2015 19:48:31 -0600 Subject: [PATCH 115/858] net/tcp: The logic that binds a specific networkd device to a connection was faulty for the case of multiple network devices. On bind(), the local address should be used to associate a device with the connection (if the local address is not INADDR_ANY); On connect(), the remote address should be used (in case the local address is INADDR_ANY). On accept(), it does not matter but the remote address is the one guarenteed to be available. --- ChangeLog | 8 +++ net/tcp/tcp.h | 56 +++++++++++++-- net/tcp/tcp_conn.c | 27 ++++---- net/tcp/tcp_finddev.c | 154 +++++++++++++++++++++++++++++++++++------ net/utils/net_chksum.c | 10 +-- 5 files changed, 212 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index b995e34d8b..6d42569e7a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10933,3 +10933,11 @@ Averyanov (2015-09-02). * arch/arm/src/lpc43xx/lpc43_ethernet.c: Add Ethernet support. From Ilya Averyanov (2015-09-02). + * net/tcp: The logic that binds a specific networkd device to + a connection was faulty for the case of multiple network + devices. On bind(), the local address should be used to associate + a device with the connection (if the local address is not INADDR_ANY); + On connect(), the remote address should be used (in case the local + address is INADDR_ANY). On accept(), it does not matter but the + remote address is the one guarenteed to be availalbe (2015-09-02). + diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 759b50deb8..1568cc5329 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -407,10 +407,11 @@ FAR struct tcp_conn_s *tcp_active(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn); /**************************************************************************** - * Function: tcp_find_ipv4_device + * Function: tcp_local_ipv4_device * * Description: - * Select the network driver to use with the IPv4 TCP transaction. + * Select the network driver to use with the IPv4 TCP transaction based + * on the locally bound IPv4 address * * Input Parameters: * conn - TCP connection structure. The locally bound address, laddr, @@ -423,14 +424,36 @@ FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn); ****************************************************************************/ #ifdef CONFIG_NET_IPv4 -int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn); +int tcp_local_ipv4_device(FAR struct tcp_conn_s *conn); #endif /**************************************************************************** - * Function: tcp_find_ipv6_device + * Function: tcp_remote_ipv4_device * * Description: - * Select the network driver to use with the IPv6 TCP transaction. + * Select the network driver to use with the IPv4 TCP transaction based + * on the remotely connected IPv4 address + * + * Input Parameters: + * conn - TCP connection structure. The remotely conected address, raddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -ENODEV is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv4 +int tcp_remote_ipv4_device(FAR struct tcp_conn_s *conn); +#endif + +/**************************************************************************** + * Function: tcp_local_ipv6_device + * + * Description: + * Select the network driver to use with the IPv6 TCP transaction based + * on the locally bound IPv6 address * * Input Parameters: * conn - TCP connection structure. The locally bound address, laddr, @@ -443,7 +466,28 @@ int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn); ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn); +int tcp_local_ipv6_device(FAR struct tcp_conn_s *conn); +#endif + +/**************************************************************************** + * Function: tcp_remote_ipv6_device + * + * Description: + * Select the network driver to use with the IPv6 TCP transaction based + * on the remotely conected IPv6 address + * + * Input Parameters: + * conn - TCP connection structure. The remotely connected address, raddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -EHOSTUNREACH is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int tcp_remote_ipv6_device(FAR struct tcp_conn_s *conn); #endif /**************************************************************************** diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index f6e33e6ac0..6cc9950fc0 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -543,16 +543,16 @@ static inline int tcp_ipv4_bind(FAR struct tcp_conn_s *conn, net_ipv4addr_copy(conn->u.ipv4.laddr, addr->sin_addr.s_addr); #endif - /* Find the device that can receive packets on the network - * associated with this local address. + /* Find the device that can receive packets on the network associated with + * this local address. */ - ret = tcp_find_ipv4_device(conn); + ret = tcp_local_ipv4_device(conn); if (ret < 0) { /* If no device is found, then the address is not reachable */ - ndbg("tcp_find_ipv4_device failed: %d\n", ret); + ndbg("tcp_local_ipv4_device failed: %d\n", ret); /* Back out the local address setting */ @@ -628,12 +628,12 @@ static inline int tcp_ipv6_bind(FAR struct tcp_conn_s *conn, * associated with this local address. */ - ret = tcp_find_ipv6_device(conn); + ret = tcp_local_ipv6_device(conn); if (ret < 0) { /* If no device is found, then the address is not reachable */ - ndbg("tcp_find_ipv6_device failed: %d\n", ret); + ndbg("tcp_local_ipv6_device failed: %d\n", ret); /* Back out the local address setting */ @@ -1016,7 +1016,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, * associated with this local address. */ - ret = tcp_find_ipv6_device(conn); + ret = tcp_remote_ipv6_device(conn); } #endif /* CONFIG_NET_IPv6 */ @@ -1027,12 +1027,15 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, { FAR struct ipv4_hdr_s *ip = IPv4BUF; - /* Set the IPv6 specific MSS and the IPv4 locally bound address. */ + /* Set the IPv6 specific MSS and the IPv4 bound remote address. */ conn->mss = TCP_IPv4_INITIAL_MSS(dev); net_ipv4addr_copy(conn->u.ipv4.raddr, net_ip4addr_conv32(ip->srcipaddr)); + #ifdef CONFIG_NETDEV_MULTINIC + /* Set the local address as well */ + net_ipv4addr_copy(conn->u.ipv4.laddr, net_ip4addr_conv32(ip->destipaddr)); @@ -1048,7 +1051,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, * associated with this local address. */ - ret = tcp_find_ipv4_device(conn); + ret = tcp_remote_ipv4_device(conn); } #endif /* CONFIG_NET_IPv4 */ @@ -1274,10 +1277,10 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) net_ipv4addr_copy(conn->u.ipv4.raddr, inaddr->sin_addr.s_addr); /* Find the device that can receive packets on the network associated - * with this local address. + * with this remote address. */ - ret = tcp_find_ipv4_device(conn); + ret = tcp_remote_ipv4_device(conn); } #endif /* CONFIG_NET_IPv4 */ @@ -1302,7 +1305,7 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) * with this local address. */ - ret = tcp_find_ipv6_device(conn); + ret = tcp_remote_ipv6_device(conn); } #endif /* CONFIG_NET_IPv6 */ diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index fc198e66ad..c6bd0348bd 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -57,39 +57,41 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /**************************************************************************** * Function: tcp_find_ipv4_device * * Description: - * Select the network driver to use with the IPv4 TCP transaction. + * Select the network driver to use with the IPv4 TCP connection. * * Input Parameters: - * conn - TCP connection structure. The locally bound address, laddr, - * should be set to a non-zero value in this structure. + * conn - TCP connection structure. + * addr - The IPv4 address to use * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENETUNREACH is the only expected error value. + * on failure. -ENODEV is the only expected error value. * ****************************************************************************/ #ifdef CONFIG_NET_IPv4 -int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn) +static int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn, in_addr_t addr) { #ifdef CONFIG_NETDEV_MULTINIC + /* Do nothing if a device is already bound to the connection */ + + if (conn->dev != NULL) + { + return OK; + } + /* Return success without using device notification if the locally bound * address is INADDR_ANY. In this case, there may be multiple devices * that can provide data so the exceptional events from any particular * device are not important. */ - if (net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY)) + if (net_ipv4addr_cmp(addr, INADDR_ANY)) { - conn->dev = NULL; return OK; } @@ -97,8 +99,7 @@ int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn) * is going to route the TCP packet based on the provided IP address. */ - conn->dev = netdev_findby_ipv4addr(conn->u.ipv4.laddr, - conn->u.ipv4.laddr); + conn->dev = netdev_findby_ipv4addr(addr, addr); /* Return success if we found the device */ @@ -121,8 +122,8 @@ int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn) * Select the network driver to use with the IPv6 TCP transaction. * * Input Parameters: - * conn - TCP connection structure. The locally bound address, laddr, - * should be set to a non-zero value in this structure. + * conn - TCP connection structure. + * addr - The IPv6 address to use * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned @@ -131,18 +132,24 @@ int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn) ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn) +static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn, const net_ipv6addr_t addr) { #ifdef CONFIG_NETDEV_MULTINIC + /* Do nothing if a device is already bound to the connection */ + + if (conn->dev != NULL) + { + return OK; + } + /* Return success without using device notification if the locally bound * address is IN6ADDR_ANY. In this case, there may be multiple devices * that can provide data so the exceptional events from any particular * device are not important. */ - if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr)) + if (net_ipv6addr_cmp(addr, g_ipv6_allzeroaddr)) { - conn->dev = NULL; return OK; } @@ -150,8 +157,7 @@ int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn) * is going to route the TCP packet based on the provided IP address. */ - conn->dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, - conn->u.ipv6.laddr); + conn->dev = netdev_findby_ipv6addr(addr, addr); /* Return success if we found the device */ @@ -167,4 +173,112 @@ int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn) } #endif /* CONFIG_NET_IPv6 */ +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: tcp_local_ipv4_device + * + * Description: + * Select the network driver to use with the IPv4 TCP transaction based + * on the locally bound IPv4 address + * + * Input Parameters: + * conn - TCP connection structure. The locally bound address, laddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -ENODEV is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv4 +int tcp_local_ipv4_device(FAR struct tcp_conn_s *conn) +{ +#ifdef CONFIG_NETDEV_MULTINIC + return tcp_find_ipv4_device(conn, conn->u.ipv4.laddr); +#else + return tcp_find_ipv4_device(conn, 0); +#endif +} +#endif /* CONFIG_NET_IPv4 */ + +/**************************************************************************** + * Function: tcp_remote_ipv4_device + * + * Description: + * Select the network driver to use with the IPv4 TCP transaction based + * on the remotely connected IPv4 address + * + * Input Parameters: + * conn - TCP connection structure. The remotely conected address, raddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -ENODEV is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv4 +int tcp_remote_ipv4_device(FAR struct tcp_conn_s *conn) +{ + return tcp_find_ipv4_device(conn, conn->u.ipv4.raddr); +} +#endif + +/**************************************************************************** + * Function: tcp_local_ipv6_device + * + * Description: + * Select the network driver to use with the IPv6 TCP transaction. + * + * Input Parameters: + * conn - TCP connection structure. The locally bound address, laddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -ENETUNREACH is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int tcp_local_ipv6_device(FAR struct tcp_conn_s *conn) +{ +#ifdef CONFIG_NETDEV_MULTINIC + return tcp_find_ipv6_device(conn, conn->u.ipv6.laddr); +#else + return tcp_find_ipv6_device(conn, NULL); +#endif + +} +#endif /* CONFIG_NET_IPv6 */ + +/**************************************************************************** + * Function: tcp_remote_ipv6_device + * + * Description: + * Select the network driver to use with the IPv6 TCP transaction based + * on the remotely conected IPv6 address + * + * Input Parameters: + * conn - TCP connection structure. The remotely connected address, raddr, + * should be set to a non-zero value in this structure. + * + * Returned Value: + * Zero (OK) is returned on success. A negated errno value is returned + * on failure. -EHOSTUNREACH is the only expected error value. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int tcp_remote_ipv6_device(FAR struct tcp_conn_s *conn) +{ + return int tcp_find_ipv6_device(conn, conn->u.ipv6.raddr); +} +#endif /* CONFIG_NET_IPv6 */ + #endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/net/utils/net_chksum.c b/net/utils/net_chksum.c index 98732bcc62..526ebf9e88 100644 --- a/net/utils/net_chksum.c +++ b/net/utils/net_chksum.c @@ -71,7 +71,7 @@ * Name: chksum ****************************************************************************/ -#if !CONFIG_NET_ARCH_CHKSUM +#ifndef CONFIG_NET_ARCH_CHKSUM static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len) { FAR const uint8_t *dataptr; @@ -204,7 +204,7 @@ static uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev, * ****************************************************************************/ -#if !CONFIG_NET_ARCH_INCR32 +#ifndef CONFIG_NET_ARCH_INCR32 static inline void net_carry32(FAR uint8_t *sum, uint16_t op16) { if (sum[2] < (op16 >> 8)) @@ -254,7 +254,7 @@ static inline void net_carry32(FAR uint8_t *sum, uint16_t op16) * ****************************************************************************/ -#if !CONFIG_NET_ARCH_INCR32 +#ifndef CONFIG_NET_ARCH_INCR32 void net_incr32(FAR uint8_t *op32, uint16_t op16) { op32[3] += (op16 & 0xff); @@ -288,7 +288,7 @@ void net_incr32(FAR uint8_t *op32, uint16_t op16) * ****************************************************************************/ -#if !CONFIG_NET_ARCH_CHKSUM +#ifndef CONFIG_NET_ARCH_CHKSUM uint16_t net_chksum(FAR uint16_t *data, uint16_t len) { return htons(chksum(0, (uint8_t *)data, len)); @@ -341,7 +341,7 @@ uint16_t ipv4_chksum(FAR struct net_driver_s *dev) * ****************************************************************************/ -#if !CONFIG_NET_ARCH_CHKSUM +#ifndef CONFIG_NET_ARCH_CHKSUM #ifdef CONFIG_NET_IPv4 uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev) { -- GitLab From 0bf6fa0b4327cf57975fdccaa64f2d1e46110b59 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Sep 2015 19:50:00 -0600 Subject: [PATCH 116/858] Typo in ChangeLog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6d42569e7a..0325279a5b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10939,5 +10939,5 @@ a device with the connection (if the local address is not INADDR_ANY); On connect(), the remote address should be used (in case the local address is INADDR_ANY). On accept(), it does not matter but the - remote address is the one guarenteed to be availalbe (2015-09-02). + remote address is the one guarenteed to be available (2015-09-02). -- GitLab From 36f4d0e9fc73fdc440be31a0e38c7bb253d97889 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Sep 2015 20:03:28 -0600 Subject: [PATCH 117/858] Fix a error in some comments --- net/tcp/tcp.h | 4 ++-- net/tcp/tcp_finddev.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 1568cc5329..8662ccd7a7 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -419,7 +419,7 @@ FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn); * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENODEV is the only expected error value. + * on failure. -ENETUNREACH is the only expected error value. * ****************************************************************************/ @@ -440,7 +440,7 @@ int tcp_local_ipv4_device(FAR struct tcp_conn_s *conn); * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENODEV is the only expected error value. + * on failure. -ENETUNREACH is the only expected error value. * ****************************************************************************/ diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index c6bd0348bd..973ac944f3 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -69,7 +69,7 @@ * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENODEV is the only expected error value. + * on failure. -ENETUNREACH is the only expected error value. * ****************************************************************************/ @@ -190,7 +190,7 @@ static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn, const net_ipv6addr_ * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENODEV is the only expected error value. + * on failure. -ENETUNREACH is the only expected error value. * ****************************************************************************/ @@ -218,7 +218,7 @@ int tcp_local_ipv4_device(FAR struct tcp_conn_s *conn) * * Returned Value: * Zero (OK) is returned on success. A negated errno value is returned - * on failure. -ENODEV is the only expected error value. + * on failure. -ENETUNREACH is the only expected error value. * ****************************************************************************/ -- GitLab From 14297afb8307d9ee862d77d75a3f7385dd0f3e6e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 3 Sep 2015 07:33:50 -0600 Subject: [PATCH 118/858] Cosmetic fix to break up long line --- net/tcp/tcp_finddev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index 973ac944f3..82fb5810b5 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -132,7 +132,8 @@ static int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn, in_addr_t addr) ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn, const net_ipv6addr_t addr) +static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn, + const net_ipv6addr_t addr) { #ifdef CONFIG_NETDEV_MULTINIC /* Do nothing if a device is already bound to the connection */ -- GitLab From 381c58777031f8c129276633f824c053abbcfe60 Mon Sep 17 00:00:00 2001 From: OrbitalFox Date: Thu, 3 Sep 2015 07:35:32 -0600 Subject: [PATCH 119/858] Fix typo but should be buf. From OrbitalFox --- libc/netdb/lib_gethostbyaddrr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index 06f5833cf4..ca27473174 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -398,7 +398,7 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, #ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback address */ - if (lib_localhost(addr, len, type, host, but, buflen, h_errnop) == 0) + if (lib_localhost(addr, len, type, host, buf, buflen, h_errnop) == 0) { /* Yes.. we are done */ @@ -417,7 +417,7 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, /* Search the hosts file for a match */ - return lib_hostfile_lookup(addr, len, type, host, but, buflen, h_errnop); + return lib_hostfile_lookup(addr, len, type, host, buf, buflen, h_errnop); } #endif /* CONFIG_NETDB_HOSTFILE */ -- GitLab From b98109c419c71f7626d0148b78822de5a5499a15 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 4 Sep 2015 16:49:06 -0600 Subject: [PATCH 120/858] Update ChangeLog, README file, and submodules --- ChangeLog | 4 +++- README.txt | 4 ++++ arch | 2 +- configs | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0325279a5b..6473559aa4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10940,4 +10940,6 @@ On connect(), the remote address should be used (in case the local address is INADDR_ANY). On accept(), it does not matter but the remote address is the one guarenteed to be available (2015-09-02). - + * configs/board.mk and configs/*/src/Makefile: Simplify configs/ + Makefiles by combining common longic into a new board.mk Makefile + fragment. For Paul Alexander Patience (2015-09-04). diff --git a/README.txt b/README.txt index 53c6873725..9bc3090dc5 100644 --- a/README.txt +++ b/README.txt @@ -79,6 +79,10 @@ Installing Cygwin the answer to that and so will continue to recommend installing EVERYTHING. + You should certainly be able to omit "Science", "Math", and + "Pubishing". You can try omitting KDE, Gnome, GTK, and other + graphics packages if you don't plan to use them. + After installing Cygwin, you will get lots of links for installed tools and shells. I use the RXVT native shell. It is fast and reliable and does not require you to run the Cygwin X server (which is neither diff --git a/arch b/arch index 13137a4649..f228b56a83 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 13137a4649726a9f1b96208d21e1860ecd6f77f0 +Subproject commit f228b56a8311067a4ca6e8cd7ca456686f3fdb56 diff --git a/configs b/configs index a29659af3e..83173e5f40 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a29659af3e80ec0e77f8bc794d5f9a1080e98842 +Subproject commit 83173e5f4078d563f2b9eee6a730f6720a4a00f5 -- GitLab From 12595cc12bb5e9dfcafd9d86b524ed0f40b9c6c2 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Fri, 4 Sep 2015 19:53:28 -0400 Subject: [PATCH 121/858] Fix typos --- ChangeLog | 8 ++++---- README.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6473559aa4..e4ed5f34ed 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10939,7 +10939,7 @@ a device with the connection (if the local address is not INADDR_ANY); On connect(), the remote address should be used (in case the local address is INADDR_ANY). On accept(), it does not matter but the - remote address is the one guarenteed to be available (2015-09-02). - * configs/board.mk and configs/*/src/Makefile: Simplify configs/ - Makefiles by combining common longic into a new board.mk Makefile - fragment. For Paul Alexander Patience (2015-09-04). + remote address is the one guaranteed to be available (2015-09-02). + * configs/Board.mk and configs/*/src/Makefile: Simplify configs/ + Makefiles by combining common logic into a new Board.mk Makefile + fragment. From Paul Alexander Patience (2015-09-04). diff --git a/README.txt b/README.txt index 9bc3090dc5..5db7949443 100644 --- a/README.txt +++ b/README.txt @@ -80,7 +80,7 @@ Installing Cygwin EVERYTHING. You should certainly be able to omit "Science", "Math", and - "Pubishing". You can try omitting KDE, Gnome, GTK, and other + "Publishing". You can try omitting KDE, Gnome, GTK, and other graphics packages if you don't plan to use them. After installing Cygwin, you will get lots of links for installed -- GitLab From 9c66bde5b01674f39f95588be4d9403fa1bd4d0e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Sep 2015 09:10:48 -0600 Subject: [PATCH 122/858] Fix typo in pre-processor command noted by Pierre-noel Bouteville. Also move # of pre-processior command to column 1 --- arch | 2 +- configs | 2 +- drivers/lcd/skeleton.c | 2 +- drivers/lcd/ug-2864ambag01.c | 2 +- include/nuttx/mm/mm.h | 2 +- libc/stdio/lib_fseek.c | 2 +- libc/stdlib/lib_mkstemp.c | 2 +- libc/wqueue/work_usrthread.c | 2 +- net/arp/arp.h | 2 +- net/iob/iob_dump.c | 2 +- net/tcp/tcp_callback.c | 2 +- syscall/syscall_nparms.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch b/arch index f228b56a83..5ab894e788 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f228b56a8311067a4ca6e8cd7ca456686f3fdb56 +Subproject commit 5ab894e788050d6cbbf87178dc80cdbfcc04bc74 diff --git a/configs b/configs index 83173e5f40..5f86fa27a3 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 83173e5f4078d563f2b9eee6a730f6720a4a00f5 +Subproject commit 5f86fa27a334d105764398a58344ad9c0c6c4462 diff --git a/drivers/lcd/skeleton.c b/drivers/lcd/skeleton.c index 2154ed5aea..1c02c40b24 100644 --- a/drivers/lcd/skeleton.c +++ b/drivers/lcd/skeleton.c @@ -395,7 +395,7 @@ FAR struct lcd_dev_s *up_oledinitialize(FAR struct spi_dev_s *spi) #warning "Missing logic" /* Configure and enable LCD */ - #warning "Missing logic" +#warning "Missing logic" return &g_lcddev.dev; } diff --git a/drivers/lcd/ug-2864ambag01.c b/drivers/lcd/ug-2864ambag01.c index 51706026a9..6b8e081b24 100644 --- a/drivers/lcd/ug-2864ambag01.c +++ b/drivers/lcd/ug-2864ambag01.c @@ -175,7 +175,7 @@ # define SH1101A_MRATIO(d) ((d) & 0x3f) #define SH1101A_DCDC_MODE (0xad) /* Set DC-DC OFF/ON: (Double Bytes Command) */ # define SH1101A_DCDC_OFF (0x8a) - # define SH1101A_DCDC_ON (0x8b) +# define SH1101A_DCDC_ON (0x8b) #define SH1101A_DISPOFFON(s) (0xae | ((s) & 0x01)) /* Display OFF/ON: (aeh - afh) */ # define SH1101A_DISPOFF SH1101A_DISPOFFON(0) /* Display off */ # define SH1101A_DISPON SH1101A_DISPOFFON(1) /* Display on */ diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 6a8c27ba46..3d2523eeac 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -287,7 +287,7 @@ extern "C" * no global user heap structure. */ - #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) /* In the kernel build, there a multiple user heaps; one for each task * group. In this build configuration, the user heap structure lies * in a reserved region at the beginning of the .bss/.data address diff --git a/libc/stdio/lib_fseek.c b/libc/stdio/lib_fseek.c index c73d5154a1..f11efa1d09 100644 --- a/libc/stdio/lib_fseek.c +++ b/libc/stdio/lib_fseek.c @@ -107,7 +107,7 @@ int fseek(FAR FILE *stream, long int offset, int whence) { - #if CONFIG_STDIO_BUFFER_SIZE > 0 +#if CONFIG_STDIO_BUFFER_SIZE > 0 /* Flush any valid read/write data in the buffer (also verifies stream) */ if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) diff --git a/libc/stdlib/lib_mkstemp.c b/libc/stdlib/lib_mkstemp.c index 94b6dcc0af..6b92d0093d 100644 --- a/libc/stdlib/lib_mkstemp.c +++ b/libc/stdlib/lib_mkstemp.c @@ -54,7 +54,7 @@ * Pre-processor definitions ****************************************************************************/ - #ifndef CONFIG_LIBC_TMPDIR +#ifndef CONFIG_LIBC_TMPDIR # define CONFIG_LIBC_TMPDIR "/tmp" #endif diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index 0179ed3c51..d359712d83 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -386,7 +386,7 @@ int work_usrstart(void) (void)pthread_attr_init(&attr); (void)pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE); -+#ifdef CONFIG_SCHED_SPORADIC +#ifdef CONFIG_SCHED_SPORADIC /* Get the current sporadic scheduling parameters. Those will not be * modified. */ diff --git a/net/arp/arp.h b/net/arp/arp.h index c4526a65f4..65846b0015 100644 --- a/net/arp/arp.h +++ b/net/arp/arp.h @@ -176,7 +176,7 @@ struct arp_notify_s * Public Function Prototypes ****************************************************************************/ - #ifdef CONFIG_NET_ARP +#ifdef CONFIG_NET_ARP /**************************************************************************** * Name: arp_reset * diff --git a/net/iob/iob_dump.c b/net/iob/iob_dump.c index c9ffc7f4ab..a34dc1ca2a 100644 --- a/net/iob/iob_dump.c +++ b/net/iob/iob_dump.c @@ -50,7 +50,7 @@ * Pre-processor definitions ****************************************************************************/ - #ifndef MIN +#ifndef MIN # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index 68f4277232..d8bcd9dd22 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -116,7 +116,7 @@ tcp_data_event(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, nllvdbg("Dropped %d bytes\n", dev->d_len); - #ifdef CONFIG_NET_STATISTICS +#ifdef CONFIG_NET_STATISTICS g_netstats.tcp.syndrop++; g_netstats.tcp.drop++; #endif diff --git a/syscall/syscall_nparms.c b/syscall/syscall_nparms.c index 292421643b..164ab3e3fd 100644 --- a/syscall/syscall_nparms.c +++ b/syscall/syscall_nparms.c @@ -72,4 +72,4 @@ const uint8_t g_funcnparms[SYS_nsyscalls] = * Public Functions ****************************************************************************/ - #endif /* CONFIG_LIB_SYSCALL */ +#endif /* CONFIG_LIB_SYSCALL */ -- GitLab From cae703e868cff939cd6cc4660452f8af8a4ac079 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Sep 2015 12:17:05 -0600 Subject: [PATCH 123/858] Update README and ChangeLog --- ChangeLog | 3 +++ Documentation | 2 +- README.txt | 3 +++ arch | 2 +- configs | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4ed5f34ed..1fdfbcc0e2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10943,3 +10943,6 @@ * configs/Board.mk and configs/*/src/Makefile: Simplify configs/ Makefiles by combining common logic into a new Board.mk Makefile fragment. From Paul Alexander Patience (2015-09-04). + * configs/sama5d2-xult: Add a very basic configuration for the SAMAD2 + Xplained Ultra board. This configuration is incomplete and only + intended to support the initial board bring-up (2015-09-05). diff --git a/Documentation b/Documentation index 8a30728ae9..a57e68381b 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8a30728ae9a64496f0c9a0ff5dd62bd3b022c145 +Subproject commit a57e68381bdffe6372bc88cf2e74ae4922549ae7 diff --git a/README.txt b/README.txt index 5db7949443..fcd8c53afc 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,5 @@ README +README ^^^^^^ o Installation @@ -1389,6 +1390,8 @@ nuttx/ | | `- README.txt | |- rgmp/ | | `- README.txt + | |- sama5d2-xult/ + | | `- README.txt | |- sama5d3x-ek/ | | `- README.txt | |- sama5d3-xplained/ diff --git a/arch b/arch index 5ab894e788..9585510171 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5ab894e788050d6cbbf87178dc80cdbfcc04bc74 +Subproject commit 9585510171947446d2fb2ff2734879692fcc21e7 diff --git a/configs b/configs index 5f86fa27a3..10aa211d94 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 5f86fa27a334d105764398a58344ad9c0c6c4462 +Subproject commit 10aa211d94336b21088bc8b5a2df4539d501beda -- GitLab From 7d33e858dd8a6b998782ec0d12f8258bf8e05144 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Sep 2015 09:37:34 -0600 Subject: [PATCH 124/858] QSPI interface + ST25FL1 driver: Add methods to allocate properly aligned memory --- ChangeLog | 3 + arch | 2 +- configs | 2 +- drivers/mtd/st25fl1.c | 214 +++++++++++++++++++-------------------- include/nuttx/spi/qspi.h | 55 ++++++++-- 5 files changed, 156 insertions(+), 120 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fdfbcc0e2..1739da9bdf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10946,3 +10946,6 @@ * configs/sama5d2-xult: Add a very basic configuration for the SAMAD2 Xplained Ultra board. This configuration is incomplete and only intended to support the initial board bring-up (2015-09-05). + * up_initialize() all architectures: Automatically initialize all + the TUN device if it is in the configuration (2015-09-06). + diff --git a/arch b/arch index 9585510171..1e8ed1f683 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9585510171947446d2fb2ff2734879692fcc21e7 +Subproject commit 1e8ed1f683eb8cd5ddec57ca978735bbde0af6cd diff --git a/configs b/configs index 10aa211d94..88b49cd40d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 10aa211d94336b21088bc8b5a2df4539d501beda +Subproject commit 88b49cd40d20572ff019525cc959e7b4c3a3c31f diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 73a7b3ebcd..4265fda326 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -302,15 +302,6 @@ #define CLR_DIRTY(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) #define CLR_ERASED(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) -/* Misc. ****************************************************************************/ -/* The SAMV7x QSPI driver insists that transfers be performed in multiples of 32- - * bits. Other QSPI drivers could have other requirements but, so far, there seems - * to be no harm in making this unconditional. - */ - -#define ALIGN_MASK 3 -#define ALIGN_UP(n) (((n)+ALIGN_MASK) & ~ALIGN_MASK) - /************************************************************************************ * Private Types ************************************************************************************/ @@ -322,16 +313,17 @@ struct st25fl1_dev_s { - struct mtd_dev_s mtd; /* MTD interface */ - FAR struct qspi_dev_s *qspi; /* Saved QuadSPI interface instance */ - uint16_t nsectors; /* Number of erase sectors */ - uint8_t sectorshift; /* Log2 of sector size */ - uint8_t pageshift; /* Log2 of page size */ + struct mtd_dev_s mtd; /* MTD interface */ + FAR struct qspi_dev_s *qspi; /* Saved QuadSPI interface instance */ + uint16_t nsectors; /* Number of erase sectors */ + uint8_t sectorshift; /* Log2 of sector size */ + uint8_t pageshift; /* Log2 of page size */ + FAR uint8_t *cmdbuf; /* Allocated command buffer */ #ifdef CONFIG_ST25FL1_SECTOR512 - uint8_t flags; /* Buffered sector flags */ - uint16_t esectno; /* Erase sector number in the cache*/ - FAR uint8_t *sector; /* Allocated sector data */ + uint8_t flags; /* Buffered sector flags */ + uint16_t esectno; /* Erase sector number in the cache*/ + FAR uint8_t *sector; /* Allocated sector data */ #endif }; @@ -353,11 +345,11 @@ static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR void *buffer, size_t buflen); static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR const void *buffer, size_t buflen); -static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi); -static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi); -static uint8_t sf25fl1_read_status3(FAR struct qspi_dev_s *qspi); -static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi); -static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi); +static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv); +static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv); +static uint8_t sf25fl1_read_status3(FAR struct st25fl1_dev_s *priv); +static void st25fl1_write_enable(FAR struct st25fl1_dev_s *priv); +static void st25fl1_write_disable(FAR struct st25fl1_dev_s *priv); static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, @@ -523,53 +515,47 @@ static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, * Name: sf25fl1_read_status1 ************************************************************************************/ -static uint8_t sf25fl1_read_status1(FAR struct qspi_dev_s *qspi) +static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv) { - uint8_t status[ALIGN_UP(1)]; - - DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS1, - (FAR void *)&status[0], 1)); - return status[0]; + DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS1, + (FAR void *)&priv->cmdbuf[0], 1)); + return priv->cmdbuf[0]; } /************************************************************************************ * Name: sf25fl1_read_status2 ************************************************************************************/ -static uint8_t sf25fl1_read_status2(FAR struct qspi_dev_s *qspi) +static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv) { - uint8_t status[ALIGN_UP(1)]; - - DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS2, - (FAR void *)&status[0], 1)); - return status[0]; + DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS2, + (FAR void *)&priv->cmdbuf[0], 1)); + return priv->cmdbuf[0]; } /************************************************************************************ * Name: sf25fl1_read_status3 ************************************************************************************/ -static uint8_t sf25fl1_read_status3(FAR struct qspi_dev_s *qspi) +static uint8_t sf25fl1_read_status3(FAR struct st25fl1_dev_s *priv) { - uint8_t status[ALIGN_UP(1)]; - - DEBUGVERIFY(st25fl1_command_read(qspi, ST25FL1_READ_STATUS3, - (FAR void *)&status[0], 1)); - return status[0]; + DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS3, + (FAR void *)&priv->cmdbuf[0], 1)); + return priv->cmdbuf[0]; } /************************************************************************************ * Name: st25fl1_write_enable ************************************************************************************/ -static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi) +static void st25fl1_write_enable(FAR struct st25fl1_dev_s *priv) { uint8_t status; do { - st25fl1_command(qspi, ST25FL1_WRITE_ENABLE); - status = sf25fl1_read_status1(qspi); + st25fl1_command(priv->qspi, ST25FL1_WRITE_ENABLE); + status = sf25fl1_read_status1(priv); } while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_ENABLED); } @@ -578,14 +564,14 @@ static void st25fl1_write_enable(FAR struct qspi_dev_s *qspi) * Name: st25fl1_write_disable ************************************************************************************/ -static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi) +static void st25fl1_write_disable(FAR struct st25fl1_dev_s *priv) { uint8_t status; do { - st25fl1_command(qspi, ST25FL1_WRITE_DISABLE); - status = sf25fl1_read_status1(qspi); + st25fl1_command(priv->qspi, ST25FL1_WRITE_DISABLE); + status = sf25fl1_read_status1(priv); } while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_DISABLED); } @@ -594,12 +580,12 @@ static void st25fl1_write_disable(FAR struct qspi_dev_s *qspi) * Name: st25fl1_write_status ************************************************************************************/ -static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, - uint8_t status[ALIGN_UP(3)]) +static void st25fl1_write_status(FAR struct st25fl1_dev_s *priv) { - st25fl1_write_enable(qspi); - st25fl1_command_write(qspi, ST25FL1_WRITE_STATUS, (FAR const void *)status, 3); - st25fl1_write_disable(qspi); + st25fl1_write_enable(priv); + st25fl1_command_write(priv->qspi, ST25FL1_WRITE_STATUS, + (FAR const void *)priv->cmdbuf, 3); + st25fl1_write_disable(priv); } /************************************************************************************ @@ -608,34 +594,32 @@ static void st25fl1_write_status(FAR struct qspi_dev_s *qspi, static inline int st25fl1_readid(struct st25fl1_dev_s *priv) { - uint8_t jedecid[ALIGN_UP(3)]; - /* Lock the QuadSPI bus and configure the bus. */ st25fl1_lock(priv->qspi); /* Read the JEDEC ID */ - st25fl1_command_read(priv->qspi, ST25FL1_JEDEC_ID, jedecid, 3); + st25fl1_command_read(priv->qspi, ST25FL1_JEDEC_ID, priv->cmdbuf, 3); /* Unlock the bus */ st25fl1_unlock(priv->qspi); fvdbg("Manufacturer: %02x Device Type %02x, Capacity: %02x", - jedecid[0], jedecid[1], jedecid[2]); + priv->cmdbuf[0], priv->cmdbuf[1], priv->cmdbuf[2]); /* Check for a recognized memory device type */ - if (jedecid[1] != ST25FL1_JEDEC_DEVICE_TYPE) + if (priv->cmdbuf[1] != ST25FL1_JEDEC_DEVICE_TYPE) { - fdbg("ERROR: Unrecognized device type: %02x\n", jedecid[1]); + fdbg("ERROR: Unrecognized device type: %02x\n", priv->cmdbuf[1]); return -ENODEV; } /* Check for a supported capacity */ - switch (jedecid[2]) + switch (priv->cmdbuf[2]) { case S25FL116K_JEDEC_CAPACITY: priv->sectorshift = S25FL116K_SECTOR_SHIFT; @@ -658,7 +642,7 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) /* Support for this part is not implemented yet */ default: - fdbg("ERROR: Unsupported memory capacity: %02x\n", jedecid[2]); + fdbg("ERROR: Unsupported memory capacity: %02x\n", priv->cmdbuf[2]); return -ENODEV; } @@ -672,15 +656,13 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[ALIGN_UP(3)]; - /* Get the status register value to check the current protection */ - status[0] = sf25fl1_read_status1(priv->qspi); - status[1] = sf25fl1_read_status2(priv->qspi); - status[2] = sf25fl1_read_status3(priv->qspi); + priv->cmdbuf[0] = sf25fl1_read_status1(priv); + priv->cmdbuf[1] = sf25fl1_read_status2(priv); + priv->cmdbuf[2] = sf25fl1_read_status3(priv); - if ((status[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) + if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) { /* Protection already disabled */ @@ -689,12 +671,12 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, /* Check if sector protection registers are locked */ - if ((status[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) + if ((priv->cmdbuf[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) { /* Yes.. unprotect section protection registers */ - status[0] &= ~STATUS1_SRP0_MASK; - st25fl1_write_status(priv->qspi, status); + priv->cmdbuf[0] &= ~STATUS1_SRP0_MASK; + st25fl1_write_status(priv); } /* Set the protection mask to zero. @@ -702,13 +684,13 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, * necessary to protect the range of sectors. */ - status[0] |= STATUS1_BP_MASK; - st25fl1_write_status(priv->qspi, status); + priv->cmdbuf[0] |= STATUS1_BP_MASK; + st25fl1_write_status(priv); /* Check the new status */ - status[0] = sf25fl1_read_status1(priv->qspi); - if ((status[0] & STATUS1_BP_MASK) != STATUS1_BP_MASK) + priv->cmdbuf[0] = sf25fl1_read_status1(priv); + if ((priv->cmdbuf[0] & STATUS1_BP_MASK) != STATUS1_BP_MASK) { return -EACCES; } @@ -723,15 +705,13 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, off_t startblock, size_t nblocks) { - unsigned char status[ALIGN_UP(3)]; - /* Get the status register value to check the current protection */ - status[0] = sf25fl1_read_status1(priv->qspi); - status[1] = sf25fl1_read_status2(priv->qspi); - status[2] = sf25fl1_read_status3(priv->qspi); + priv->cmdbuf[0] = sf25fl1_read_status1(priv); + priv->cmdbuf[1] = sf25fl1_read_status2(priv); + priv->cmdbuf[2] = sf25fl1_read_status3(priv); - if ((status[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) + if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) { /* Protection already disabled */ @@ -740,12 +720,12 @@ static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, /* Check if sector protection registers are locked */ - if ((status[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) + if ((priv->cmdbuf[0] & STATUS1_SRP0_MASK) == STATUS1_SRP0_LOCKED) { /* Yes.. unprotect section protection registers */ - status[0] &= ~STATUS1_SRP0_MASK; - st25fl1_write_status(priv->qspi, status); + priv->cmdbuf[0] &= ~STATUS1_SRP0_MASK; + st25fl1_write_status(priv); } /* Set the protection mask to zero. @@ -753,13 +733,13 @@ static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, * necessary to unprotect the range of sectors. */ - status[0] &= ~STATUS1_BP_MASK; - st25fl1_write_status(priv->qspi, status); + priv->cmdbuf[0] &= ~STATUS1_BP_MASK; + st25fl1_write_status(priv); /* Check the new status */ - status[0] = sf25fl1_read_status1(priv->qspi); - if ((status[0] & (STATUS1_SRP0_MASK | STATUS1_BP_MASK)) != 0) + priv->cmdbuf[0] = sf25fl1_read_status1(priv); + if ((priv->cmdbuf[0] & (STATUS1_SRP0_MASK | STATUS1_BP_MASK)) != 0) { return -EACCES; } @@ -845,7 +825,7 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) /* Check that the flash is ready and unprotected */ - status = sf25fl1_read_status1(priv->qspi); + status = sf25fl1_read_status1(priv); if ((status & STATUS1_BUSY_MASK) != STATUS1_READY) { fdbg("ERROR: Flash busy: %02x", status); @@ -865,12 +845,12 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) /* Send the sector erase command */ - st25fl1_write_enable(priv->qspi); + st25fl1_write_enable(priv); st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, address, 3); /* Wait for erasure to finish */ - while ((sf25fl1_read_status1(priv->qspi) & STATUS1_BUSY_MASK) != 0); + while ((sf25fl1_read_status1(priv) & STATUS1_BUSY_MASK) != 0); return OK; } @@ -884,7 +864,7 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) /* Check if the FLASH is protected */ - status = sf25fl1_read_status1(priv->qspi); + status = sf25fl1_read_status1(priv); if ((status & STATUS1_BP_MASK) != 0) { fdbg("ERROR: FLASH is Protected: %02x", status); @@ -893,16 +873,16 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) /* Erase the whole chip */ - st25fl1_write_enable(priv->qspi); + st25fl1_write_enable(priv); st25fl1_command(priv->qspi, ST25FL1_CHIP_ERASE_2); /* Wait for the erasure to complete */ - status = sf25fl1_read_status1(priv->qspi); + status = sf25fl1_read_status1(priv); while ((status & STATUS1_BUSY_MASK) != 0) { usleep(200*1000); - status = sf25fl1_read_status1(priv->qspi); + status = sf25fl1_read_status1(priv); } return OK; @@ -981,7 +961,7 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf /* Write one page */ - st25fl1_write_enable(priv->qspi); + st25fl1_write_enable(priv); ret = QSPI_MEMORY(priv->qspi, &meminfo); if (ret < 0) { @@ -1002,7 +982,7 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf */ DEBUGASSERT(buflen == 0); - st25fl1_write_disable(priv->qspi); + st25fl1_write_disable(priv); return OK; } @@ -1444,10 +1424,10 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) { FAR struct st25fl1_dev_s *priv; - uint8_t status[ALIGN_UP(3)]; int ret; fvdbg("qspi: %p\n", qspi); + DEBUGASSERT(qspi != NULL); /* Allocate a state structure (we allocate the structure instead of using * a fixed, static allocation so that we can handle multiple FLASH devices. @@ -1470,6 +1450,15 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) priv->mtd.ioctl = st25fl1_ioctl; priv->qspi = qspi; + /* Allocate a tiny buffer to support DMA command data */ + + priv->cmdbuf = (FAR uint8_t *)QSPI_ALLOC(qspi, 4); + if (priv->cmdbuf == NULL) + { + fdbg("ERROR Failed to allocate command buffer\n"); + goto errout_with_priv; + } + /* Identify the FLASH chip and get its capacity */ ret = st25fl1_readid(priv); @@ -1478,35 +1467,33 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) /* Unrecognized! Discard all of that work we just did and return NULL */ fdbg("ERROR Unrecognized QSPI device\n"); - kmm_free(priv); - return NULL; + goto errout_with_cmdbuf; } /* Enable quad mode */ - status[0] = sf25fl1_read_status1(priv->qspi); - status[1] = sf25fl1_read_status2(priv->qspi); - status[2] = sf25fl1_read_status3(priv->qspi); + priv->cmdbuf[0] = sf25fl1_read_status1(priv); + priv->cmdbuf[1] = sf25fl1_read_status2(priv); + priv->cmdbuf[2] = sf25fl1_read_status3(priv); - while ((status[1] & STATUS2_QUAD_ENABLE_MASK) == 0) + while ((priv->cmdbuf[1] & STATUS2_QUAD_ENABLE_MASK) == 0) { - status[1] |= STATUS2_QUAD_ENABLE; - st25fl1_write_status(priv->qspi, status); - status[1] = sf25fl1_read_status2(priv->qspi); + priv->cmdbuf[1] |= STATUS2_QUAD_ENABLE; + st25fl1_write_status(priv); + priv->cmdbuf[1] = sf25fl1_read_status2(priv); usleep(50*1000); } -#ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ +#ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ /* Allocate a buffer for the erase block cache */ - priv->sector = (FAR uint8_t *)kmm_malloc((1 << priv->sectorshift)); - if (!priv->sector) + priv->sector = (FAR uint8_t *)QSPI_ALLOC(1 << priv->sectorshift); + if (priv->sector == NULL) { /* Allocation failed! Discard all of that work we just did and return NULL */ - fdbg("ERROR: Allocation failed\n"); - kmm_free(priv); - return NULL; + fdbg("ERROR: Sector allocation failed\n"); + goto errout_with_cmdbuf; } #endif } @@ -1521,4 +1508,11 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) fvdbg("Return %p\n", priv); return (FAR struct mtd_dev_s *)priv; + +errout_with_cmdbuf: + QSPI_FREE(qspi, priv->cmdbuf); + +errout_with_priv: + kmm_free(priv); + return NULL; } diff --git a/include/nuttx/spi/qspi.h b/include/nuttx/spi/qspi.h index 628b5bf629..3db0826c39 100644 --- a/include/nuttx/spi/qspi.h +++ b/include/nuttx/spi/qspi.h @@ -191,6 +191,41 @@ (((f) & (QSPIMEM_SCRAMBLE|QSPIMEM_RANDOM)) == \ (QSPIMEM_SCRAMBLE|QSPIMEM_RANDOM)) +/**************************************************************************** + * Name: QSPI_ALLOC + * + * Description: + * Allocate a buffer suitable for DMA data transfer + * + * Input Parameters: + * dev - Device-specific state data + * buflen - Buffer length to allocate in bytes + * + * Returned Value: + * Address of tha allocated memory on success; NULL is returned on any + * failure. + * + ****************************************************************************/ + +#define QSPI_ALLOC(d,b) (d)->ops->alloc(d,b) + +/**************************************************************************** + * Name: QSPI_FREE + * + * Description: + * Free memory returned by QSPI_ALLOC + * + * Input Parameters: + * dev - Device-specific state data + * buffer - Buffer previously allocated via QSPI_ALLOC + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#define QSPI_FREE(d,b) (d)->ops->free(d,b) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -236,14 +271,18 @@ struct qspi_meminfo_s struct qspi_dev_s; struct qspi_ops_s { - CODE int (*lock)(FAR struct qspi_dev_s *dev, bool lock); - CODE uint32_t (*setfrequency)(FAR struct qspi_dev_s *dev, uint32_t frequency); - CODE void (*setmode)(FAR struct qspi_dev_s *dev, enum qspi_mode_e mode); - CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits); - CODE int (*command)(FAR struct qspi_dev_s *dev, - FAR struct qspi_cmdinfo_s *cmdinfo); - CODE int (*memory)(FAR struct qspi_dev_s *dev, - FAR struct qspi_meminfo_s *meminfo); + CODE int (*lock)(FAR struct qspi_dev_s *dev, bool lock); + CODE uint32_t (*setfrequency)(FAR struct qspi_dev_s *dev, + uint32_t frequency); + CODE void (*setmode)(FAR struct qspi_dev_s *dev, + enum qspi_mode_e mode); + CODE void (*setbits)(FAR struct qspi_dev_s *dev, int nbits); + CODE int (*command)(FAR struct qspi_dev_s *dev, + FAR struct qspi_cmdinfo_s *cmdinfo); + CODE int (*memory)(FAR struct qspi_dev_s *dev, + FAR struct qspi_meminfo_s *meminfo); + CODE FAR void *(*alloc)(FAR struct qspi_dev_s *dev, size_t buflen); + CODE void (*free)(FAR struct qspi_dev_s *dev, FAR void *buffer); }; /* QSPI private data. This structure only defines the initial fields of the -- GitLab From c080146748730aa7aecf20141d1225e75b67642b Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Sun, 6 Sep 2015 12:08:38 -0400 Subject: [PATCH 125/858] SSD1351 driver: add 8-bit parallel interface --- drivers/lcd/Kconfig | 9 + drivers/lcd/ssd1351.c | 464 ++++++++++++++++-------------------- include/nuttx/lcd/ssd1351.h | 18 ++ 3 files changed, 236 insertions(+), 255 deletions(-) diff --git a/drivers/lcd/Kconfig b/drivers/lcd/Kconfig index d996b67a74..a895ca0dea 100644 --- a/drivers/lcd/Kconfig +++ b/drivers/lcd/Kconfig @@ -378,6 +378,11 @@ choice prompt "Interface" default SSD1351_SPI4WIRE +config SSD1351_PARALLEL8BIT + bool "8-bit Parallel Interface" + ---help--- + Enables support for the 8-bit parallel interface. + config SSD1351_SPI3WIRE bool "3-wire SPI Interface" select SPI @@ -393,6 +398,8 @@ config SSD1351_SPI4WIRE endchoice +if SSD1351_SPI3WIRE || SSD1351_SPI4WIRE + config SSD1351_SPIMODE int "SPI Mode" default 0 @@ -406,6 +413,8 @@ config SSD1351_SPIFREQ ---help--- Specifies the SPI frequency. +endif + config SSD1351_NINTERFACES int "Number of SSD1351 Devices" default 1 diff --git a/drivers/lcd/ssd1351.c b/drivers/lcd/ssd1351.c index e11e6b1fb1..88f6e55dbf 100644 --- a/drivers/lcd/ssd1351.c +++ b/drivers/lcd/ssd1351.c @@ -1,6 +1,6 @@ /**************************************************************************** * drivers/lcd/ssd1351.c - * LCD driver for the Solomon Systech SSD1351 LCD controller + * LCD driver for the Solomon Systech SSD1351 OLED controller * * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience @@ -61,6 +61,7 @@ /* Configuration ************************************************************/ /* SSD1351 configuration settings: + * CONFIG_SSD1351_PARALLEL8BIT - 8-bit parallel interface * CONFIG_SSD1351_SPI3WIRE - 3-wire SPI interface * CONFIG_SSD1351_SPI4WIRE - 4-wire SPI interface * CONFIG_SSD1351_SPIMODE - SPI mode @@ -106,28 +107,6 @@ /* Verify that all configuration requirements have been met */ -/* Interface to use */ - -#if !defined(CONFIG_SSD1351_SPI3WIRE) && !defined(CONFIG_SSD1351_SPI4WIRE) -# error "Choose an interface to use" -#endif - -#if defined(CONFIG_SSD1351_SPI3WIRE) && defined(CONFIG_SSD1351_SPI4WIRE) -# error "Cannot choose more than one interface" -#endif - -/* SPI */ - -#ifndef CONFIG_SPI -# error "Requires support for SPI" -#endif - -/* Cmd/data selection */ - -#if defined(CONFIG_SSD1351_SPI4WIRE) && !defined(CONFIG_SPI_CMDDATA) -# error "4-wire SPI interface requires support for SPI_CMDDATA" -#endif - /* Number of bits per pixel */ #ifdef CONFIG_NX_DISABLE_16BPP @@ -136,127 +115,18 @@ /* Max power */ -#ifndef CONFIG_LCD_MAXPOWER -# define CONFIG_LCD_MAXPOWER 1 -#endif - #if CONFIG_LCD_MAXPOWER != 1 # error "CONFIG_LCD_MAXPOWER should be 1" #endif -/* SPI mode */ - -#ifndef CONFIG_SSD1351_SPIMODE -# define CONFIG_SSD1351_SPIMODE SPIDEV_MODE0 -#endif - -/* SPI frequency */ - -#ifndef CONFIG_SSD1351_SPIFREQ -# define CONFIG_SSD1351_SPIFREQ 1000000 -#endif - -/* The number of physical interfaces that will be supported */ - -#ifndef CONFIG_SSD1351_NINTERFACES -# define CONFIG_SSD1351_NINTERFACES 1 -#endif - -#if CONFIG_SSD1351_NINTERFACES != 1 -# error "This implementation supports only a single LCD device" -#endif - -/* X resolution */ - -#ifndef CONFIG_SSD1351_XRES -# define CONFIG_SSD1351_XRES 128 -#endif - -#if CONFIG_SSD1351_XRES < 0 || CONFIG_SSD1351_XRES > 128 -# error "Invalid X resolution" -#endif - -/* Y resolution */ - -#ifndef CONFIG_SSD1351_YRES -# define CONFIG_SSD1351_YRES 128 -#endif - -#if CONFIG_SSD1351_YRES < 0 || CONFIG_SSD1351_YRES > 128 -# error "Invalid Y resolution" -#endif - -/* Reset period */ - -#ifndef CONFIG_SSD1351_TRST -# define CONFIG_SSD1351_TRST 5 -#endif - -/* First pre-charge period */ - -#ifndef CONFIG_SSD1351_TPRECHG1 -# define CONFIG_SSD1351_TPRECHG1 8 -#endif - -/* Clock divider */ - -#ifndef CONFIG_SSD1351_CLKDIV -# define CONFIG_SSD1351_CLKDIV 0 -#endif - -/* Oscillator frequency */ - -#ifndef CONFIG_SSD1351_OSCFREQ -# define CONFIG_SSD1351_OSCFREQ 15 -#endif - -/* Second pre-charge period */ - -#ifndef CONFIG_SSD1351_TPRECHG2 -# define CONFIG_SSD1351_TPRECHG2 8 -#endif - -/* Pre-charge voltage level */ - -#ifndef CONFIG_SSD1351_VPRECHG -# define CONFIG_SSD1351_VPRECHG 50 -#endif - -/* COM deselect voltage level */ - -#ifndef CONFIG_SSD1351_VCOMH -# define CONFIG_SSD1351_VCOMH 82 -#endif - -/* Color A contrast */ - -#ifndef CONFIG_SSD1351_CONTRASTA -# define CONFIG_SSD1351_CONTRASTA 138 -#endif - -/* Color B contrast */ - -#ifndef CONFIG_SSD1351_CONTRASTB -# define CONFIG_SSD1351_CONTRASTB 81 -#endif - -/* Color C contrast */ - -#ifndef CONFIG_SSD1351_CONTRASTC -# define CONFIG_SSD1351_CONTRASTC 138 -#endif - -/* Master contrast ratio */ - -#ifndef CONFIG_SSD1351_MSTRCONTRAST -# define CONFIG_SSD1351_MSTRCONTRAST 16 -#endif - /* 9-bit SPI */ #ifdef CONFIG_SSD1351_SPI3WIRE # define SSD1351_SPICMD 0 # define SSD1351_SPIDATA (1 << 8) +# define SSD1351_SPIBITS 9 +#else +# define SSD1351_SPIBITS 8 #endif /* Macro Helpers ************************************************************/ @@ -503,12 +373,16 @@ struct ssd1351_dev_s { /* Publically visible device structure */ - struct lcd_dev_s dev; + struct lcd_dev_s dev; /* Private LCD-specific information follows */ - FAR struct spi_dev_s *spi; /* Contained SPI driver instance */ - uint8_t power; /* Current power (backlight) setting */ +#ifdef CONFIG_SSD1351_PARALLEL8BIT + FAR struct ssd1351_lcd_s *lcd; /* Contained platform-specific interface */ +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) + FAR struct spi_dev_s *spi; /* Contained SPI driver instance */ +#endif + uint8_t power; /* Current power (backlight) setting */ /* This is working memory allocated by the LCD driver for each LCD device * and for each color plane. This memory will hold one raster line of @@ -522,7 +396,7 @@ struct ssd1351_dev_s * buffers. */ - uint16_t runbuffer[SSD1351_XRES]; + uint16_t runbuffer[SSD1351_XRES]; /* This is another buffer, but used internally by the LCD driver in order * to expand the pixel data into 9-bit data needed by the LCD. There are @@ -533,7 +407,7 @@ struct ssd1351_dev_s */ #ifdef CONFIG_SSD1351_SPI3WIRE - uint16_t rowbuffer[SSD1351_STRIDE+1]; + uint16_t rowbuffer[SSD1351_STRIDE+1]; #endif }; @@ -541,18 +415,22 @@ struct ssd1351_dev_s * Private Function Prototypes ****************************************************************************/ -/* SPI Helpers */ +/* Helpers */ -static inline void ssd1351_configspi(FAR struct spi_dev_s *spi); -#ifdef CONFIG_SPI_OWNBUS -static inline void ssd1351_select(FAR struct spi_dev_s *spi); -static inline void ssd1351_deselect(FAR struct spi_dev_s *spi); -#else -static void ssd1351_select(FAR struct spi_dev_s *spi); -static void ssd1351_deselect(FAR struct spi_dev_s *spi); +#ifdef CONFIG_SSD1351_PARALLEL8BIT +#define ssd1351_select(priv) +#define ssd1351_deselect(priv) +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) +static void ssd1351_select(FAR struct ssd1351_dev_s *priv); +static void ssd1351_deselect(FAR struct ssd1351_dev_s *priv); +#endif + +#if defined(CONFIG_SSD1351_PARALLEL8BIT) && !defined(CONFIG_LCD_NOGETRUN) +static void ssd1351_read(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR uint8_t *data, size_t datlen); #endif -static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, - FAR const uint8_t *data, size_t datlen); +static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen); /* LCD Data Transfer Methods */ @@ -604,25 +482,6 @@ static struct ssd1351_dev_s g_lcddev; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: ssd1351_configspi - * - * Description: - * Configure the SPI. - * - ****************************************************************************/ - -static inline void ssd1351_configspi(FAR struct spi_dev_s *spi) -{ - SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); -#ifdef CONFIG_SSD1351_SPI3WIRE - SPI_SETBITS(spi, 9); -#else - SPI_SETBITS(spi, 8); -#endif - SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); -} - /**************************************************************************** * Name: ssd1351_select * @@ -631,17 +490,11 @@ static inline void ssd1351_configspi(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void ssd1351_select(FAR struct spi_dev_s *spi) +#if defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) +static void ssd1351_select(FAR struct ssd1351_dev_s *priv) { - /* We own the SPI bus, so just select the chip */ + FAR struct spi_dev_s *spi = priv->spi; - gdbg("SELECTED\n"); - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} -#else -static void ssd1351_select(FAR struct spi_dev_s *spi) -{ /* Select the chip, locking the SPI bus in case there are multiple devices * competing for the SPI bus */ @@ -654,7 +507,11 @@ static void ssd1351_select(FAR struct spi_dev_s *spi) * have gotten configured for a different device while unlocked) */ - ssd1351_configspi(spi); +#ifndef CONFIG_SPI_OWNBUS + SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); + SPI_SETBITS(spi, SSD1351_SPIBITS); + SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); +#endif } #endif @@ -666,17 +523,11 @@ static void ssd1351_select(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void ssd1351_deselect(FAR struct spi_dev_s *spi) +#if defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) +static void ssd1351_deselect(FAR struct ssd1351_dev_s *priv) { - /* We own the SPI bus, so just de-select the chip */ + FAR struct spi_dev_s *spi = priv->spi; - gdbg("DE-SELECTED\n"); - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else -static void ssd1351_deselect(FAR struct spi_dev_s *spi) -{ /* De-select the chip and relinquish the SPI bus */ gdbg("DE-SELECTED\n"); @@ -686,16 +537,79 @@ static void ssd1351_deselect(FAR struct spi_dev_s *spi) #endif /**************************************************************************** - * Name: ssd1351_cmddata + * Name: ssd1351_read + * + * Description: + * Send a 1-byte command and read datlen data bytes. + * + ****************************************************************************/ + +#if defined(CONFIG_SSD1351_PARALLEL8BIT) && !defined(CONFIG_LCD_NOGETRUN) +static void ssd1351_read(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR uint8_t *data, size_t datlen) +{ + FAR struct ssd1351_lcd_s *lcd = priv->lcd; + size_t i; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); + + /* Send the command */ + + lcd->cmd(lcd, cmd); + + /* Discard the first data read if reading from the display */ + + if (cmd == SSD1351_CMD_RAMREAD) + { + (void)lcd->read(lcd); + } + + /* Read all of the data */ + + for (i = 0; i < datlen; i++) + { + data[i] = lcd->read(lcd); + } +} +#endif + +/**************************************************************************** + * Name: ssd1351_write * * Description: * Send a 1-byte command followed by datlen data bytes. * ****************************************************************************/ -#ifdef CONFIG_SSD1351_SPI3WIRE -static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, - FAR const uint8_t *data, size_t datlen) +#ifdef CONFIG_SSD1351_PARALLEL8BIT +static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen) +{ + FAR struct ssd1351_lcd_s *lcd = priv->lcd; + size_t i; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); + + /* Send the command */ + + lcd->cmd(lcd, cmd); + + /* Write all of the data */ + + for (i = 0; i < datlen; i++) + { + lcd->write(lcd, data[i]); + } +} +#elif defined(CONFIG_SSD1351_SPI3WIRE) +static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen) { size_t i; @@ -720,10 +634,12 @@ static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, (void)SPI_SNDBLOCK(priv->spi, priv->rowbuffer, datlen+1); } -#else -static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, - FAR const uint8_t *data, size_t datlen) +#elif defined(CONFIG_SSD1351_SPI4WIRE) +static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, + FAR const uint8_t *data, size_t datlen) { + FAR struct spi_dev_s *spi = priv->spi; + /* Sanity check */ DEBUGASSERT(priv != NULL); @@ -731,11 +647,11 @@ static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, /* Select command transfer */ - (void)SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, true); + (void)SPI_CMDDATA(spi, SPIDEV_DISPLAY, true); /* Send the command */ - (void)SPI_SEND(priv->spi, cmd); + (void)SPI_SEND(spi, cmd); /* Do we have any data to send? */ @@ -743,11 +659,11 @@ static void ssd1351_cmddata(FAR struct ssd1351_dev_s *priv, uint8_t cmd, { /* Yes, select data transfer */ - (void)SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, false); + (void)SPI_CMDDATA(spi, SPIDEV_DISPLAY, false); /* Transfer all of the data */ - (void)SPI_SNDBLOCK(priv->spi, data, datlen); + (void)SPI_SNDBLOCK(spi, data, datlen); } } #endif @@ -770,25 +686,25 @@ static void ssd1351_setcursor(FAR struct ssd1351_dev_s *priv, uint8_t col, buf[0] = col; buf[1] = SSD1351_XRES - 1; - ssd1351_cmddata(priv, SSD1351_CMD_COLADDR, buf, 2); + ssd1351_write(priv, SSD1351_CMD_COLADDR, buf, 2); /* Set the row address to the row */ buf[0] = row; buf[1] = SSD1351_YRES - 1; - ssd1351_cmddata(priv, SSD1351_CMD_ROWADDR, buf, 2); -#else + ssd1351_write(priv, SSD1351_CMD_ROWADDR, buf, 2); +#elif defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT) /* Set the column address to the row */ buf[0] = row; buf[1] = SSD1351_YRES - 1; - ssd1351_cmddata(priv, SSD1351_CMD_COLADDR, buf, 2); + ssd1351_write(priv, SSD1351_CMD_COLADDR, buf, 2); /* Set the row address to the column */ buf[0] = col; buf[1] = SSD1351_XRES - 1; - ssd1351_cmddata(priv, SSD1351_CMD_ROWADDR, buf, 2); + ssd1351_write(priv, SSD1351_CMD_ROWADDR, buf, 2); #endif } @@ -820,20 +736,20 @@ static int ssd1351_putrun(fb_coord_t row, fb_coord_t col, /* Select and lock the device */ - ssd1351_select(priv->spi); + ssd1351_select(priv); /* Set the starting position for the run */ ssd1351_setcursor(priv, col, row); - /* Transfer all of the data */ + /* Write all of the data */ - ssd1351_cmddata(priv, SSD1351_CMD_RAMWRITE, buffer, - SSD1351_PIX2BYTES(npixels)); + ssd1351_write(priv, SSD1351_CMD_RAMWRITE, buffer, + SSD1351_PIX2BYTES(npixels)); /* Unlock and de-select the device */ - ssd1351_deselect(priv->spi); + ssd1351_deselect(priv); return OK; } @@ -856,7 +772,36 @@ static int ssd1351_putrun(fb_coord_t row, fb_coord_t col, static int ssd1351_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, size_t npixels) { +#if defined(CONFIG_SSD1351_PARALLEL8BIT) && !defined(CONFIG_LCD_NOGETRUN) + FAR struct ssd1351_dev_s *priv = &g_lcddev; + + /* Sanity check */ + + DEBUGASSERT(buffer != NULL && ((uintptr_t)buffer & 1) == 0 && + col >= 0 && col+npixels <= SSD1351_XRES && + row >= 0 && row < SSD1351_YRES); + + /* Select and lock the device */ + + ssd1351_select(priv); + + /* Set the starting position for the run */ + + ssd1351_setcursor(priv, col, row); + + /* Read all of the data */ + + ssd1351_read(priv, SSD1351_CMD_RAMREAD, buffer, + SSD1351_PIX2BYTES(npixels)); + + /* Unlock and de-select the device */ + + ssd1351_deselect(priv); + + return OK; +#else return -ENOSYS; +#endif } /**************************************************************************** @@ -945,31 +890,31 @@ static int ssd1351_setpower(FAR struct lcd_dev_s *dev, int power) /* Sanity check */ - DEBUGASSERT(priv != NULL && (unsigned int)power <= CONFIG_LCD_MAXPOWER); + DEBUGASSERT(priv != NULL && (unsigned int)power <= LCD_FULL_ON); gvdbg("power: %d\n", power); /* Select and lock the device */ - ssd1351_select(priv->spi); + ssd1351_select(priv); - if (power > 0) + if (power > LCD_FULL_OFF) { /* Turn the display on */ - ssd1351_cmddata(priv, SSD1351_CMD_DISPON, NULL, 0); - priv->power = CONFIG_LCD_MAXPOWER; + ssd1351_write(priv, SSD1351_CMD_DISPON, NULL, 0); + priv->power = LCD_FULL_ON; } else { /* Turn the display off */ - ssd1351_cmddata(priv, SSD1351_CMD_DISPOFF, NULL, 0); - priv->power = 0; + ssd1351_write(priv, SSD1351_CMD_DISPOFF, NULL, 0); + priv->power = LCD_FULL_OFF; } /* Unlock and de-select the device */ - ssd1351_deselect(priv->spi); + ssd1351_deselect(priv); return OK; } @@ -1016,21 +961,21 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) /* Select and lock the device */ - ssd1351_select(priv->spi); + ssd1351_select(priv); /* Unlock most commands */ buf[0] = SSD1351_UNLOCK; - ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + ssd1351_write(priv, SSD1351_CMD_LOCK, buf, 1); /* Unlock the rest of the commands */ buf[0] = SSD1351_ACCESSIBLE; - ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + ssd1351_write(priv, SSD1351_CMD_LOCK, buf, 1); /* Turn the display off */ - ssd1351_cmddata(priv, SSD1351_CMD_DISPOFF, NULL, 0); + ssd1351_write(priv, SSD1351_CMD_DISPOFF, NULL, 0); /* Set the address increment, the column address mapping, the color * sequence, the scan direction, the COM split, and the color depth @@ -1058,7 +1003,7 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) #else buf[0] |= SSD1351_SCANFROMCOM0; #endif - ssd1351_cmddata(priv, SSD1351_CMD_ORIENTATION, buf, 1); + ssd1351_write(priv, SSD1351_CMD_ORIENTATION, buf, 1); /* Set the vertical scroll by RAM */ @@ -1070,19 +1015,19 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) #else buf[0] = SSD1351_STARTLINE(0); #endif - ssd1351_cmddata(priv, SSD1351_CMD_STARTLINE, buf, 1); + ssd1351_write(priv, SSD1351_CMD_STARTLINE, buf, 1); /* Set the vertical scroll by row */ buf[0] = SSD1351_OFFSET(0); - ssd1351_cmddata(priv, SSD1351_CMD_OFFSET, buf, 1); + ssd1351_write(priv, SSD1351_CMD_OFFSET, buf, 1); /* Set the display to normal or inverse */ #ifdef CONFIG_SSD1351_INVERT - ssd1351_cmddata(priv, SSD1351_CMD_INVERSE, NULL, 0); + ssd1351_write(priv, SSD1351_CMD_INVERSE, NULL, 0); #else - ssd1351_cmddata(priv, SSD1351_CMD_NORMAL, NULL, 0); + ssd1351_write(priv, SSD1351_CMD_NORMAL, NULL, 0); #endif /* Set the VDD and the interface */ @@ -1093,13 +1038,13 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) buf[0] = SSD1351_VDDINT; #endif buf[0] |= SSD1351_IFACE8BIT; - ssd1351_cmddata(priv, SSD1351_CMD_VDDIFACE, buf, 1); + ssd1351_write(priv, SSD1351_CMD_VDDIFACE, buf, 1); /* Set the reset period and the first pre-charge period */ buf[0] = SSD1351_TRST(CONFIG_SSD1351_TRST) | SSD1351_TPRECHG1(CONFIG_SSD1351_TPRECHG1); - ssd1351_cmddata(priv, SSD1351_CMD_TRSTTPRECHG1, buf, 1); + ssd1351_write(priv, SSD1351_CMD_TRSTTPRECHG1, buf, 1); /* Set the display performance */ @@ -1110,66 +1055,66 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) #endif buf[1] = SSD1351_PERFDATA2; buf[2] = SSD1351_PERFDATA3; - ssd1351_cmddata(priv, SSD1351_CMD_PERF, buf, 3); + ssd1351_write(priv, SSD1351_CMD_PERF, buf, 3); /* Set the clock divider and the oscillator frequency */ buf[0] = SSD1351_CLKDIV(CONFIG_SSD1351_CLKDIV) | SSD1351_OSCFREQ(CONFIG_SSD1351_OSCFREQ); - ssd1351_cmddata(priv, SSD1351_CMD_DIVFREQ, buf, 1); + ssd1351_write(priv, SSD1351_CMD_DIVFREQ, buf, 1); /* Set the segment low voltage */ buf[0] = SSD1351_VSLEXT; buf[1] = SSD1351_VSLDATA2; buf[2] = SSD1351_VSLDATA3; - ssd1351_cmddata(priv, SSD1351_CMD_VSL, buf, 3); + ssd1351_write(priv, SSD1351_CMD_VSL, buf, 3); /* Set the GPIO pins */ buf[0] = SSD1351_GPIO0(SSD1351_GPIOLOW) | SSD1351_GPIO1(SSD1351_GPIOLOW); - ssd1351_cmddata(priv, SSD1351_CMD_GPIO, buf, 1); + ssd1351_write(priv, SSD1351_CMD_GPIO, buf, 1); /* Set the second pre-charge period */ buf[0] = SSD1351_TPRECHG2(CONFIG_SSD1351_TPRECHG2); - ssd1351_cmddata(priv, SSD1351_CMD_TPRECHG2, buf, 1); + ssd1351_write(priv, SSD1351_CMD_TPRECHG2, buf, 1); /* Use the built-in linear lookup table */ - ssd1351_cmddata(priv, SSD1351_CMD_LINEARLUT, NULL, 0); + ssd1351_write(priv, SSD1351_CMD_LINEARLUT, NULL, 0); /* Set the pre-charge voltage level */ buf[0] = SSD1351_VPRECHG(CONFIG_SSD1351_VPRECHG); - ssd1351_cmddata(priv, SSD1351_CMD_VPRECHG, buf, 1); + ssd1351_write(priv, SSD1351_CMD_VPRECHG, buf, 1); /* Set the COM deselect voltage level */ buf[0] = SSD1351_VCOMH(CONFIG_SSD1351_VCOMH); - ssd1351_cmddata(priv, SSD1351_CMD_VCOMH, buf, 1); + ssd1351_write(priv, SSD1351_CMD_VCOMH, buf, 1); /* Set the contrast */ buf[0] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTA); buf[1] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTB); buf[2] = SSD1351_CONTRAST(CONFIG_SSD1351_CONTRASTC); - ssd1351_cmddata(priv, SSD1351_CMD_CONTRAST, buf, 3); + ssd1351_write(priv, SSD1351_CMD_CONTRAST, buf, 3); /* Set the master contrast ratio */ buf[0] = SSD1351_MSTRCONTRAST(CONFIG_SSD1351_MSTRCONTRAST); - ssd1351_cmddata(priv, SSD1351_CMD_MSTRCONTRAST, buf, 1); + ssd1351_write(priv, SSD1351_CMD_MSTRCONTRAST, buf, 1); /* Set the multiplex ratio */ buf[0] = SSD1351_MUXRATIO(128); - ssd1351_cmddata(priv, SSD1351_CMD_MUXRATIO, buf, 1); + ssd1351_write(priv, SSD1351_CMD_MUXRATIO, buf, 1); /* Lock some of the commands */ buf[0] = SSD1351_INACCESSIBLE; - ssd1351_cmddata(priv, SSD1351_CMD_LOCK, buf, 1); + ssd1351_write(priv, SSD1351_CMD_LOCK, buf, 1); /* Set the cursor position */ @@ -1181,12 +1126,12 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) buf[1] = 0; for (i = 0; i < SSD1351_XRES * SSD1351_YRES; i++) { - ssd1351_cmddata(priv, SSD1351_CMD_RAMWRITE, buf, 2); + ssd1351_write(priv, SSD1351_CMD_RAMWRITE, buf, 2); } /* Unlock and de-select the device */ - ssd1351_deselect(priv->spi); + ssd1351_deselect(priv); } /**************************************************************************** @@ -1198,6 +1143,7 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) * but with the power setting at 0 (full off == sleep mode). * * Input Parameters: + * lcd - A reference to the platform-specific interface. * spi - A reference to the SPI driver instance. * devno - A value in the range of 0 through CONFIG_SSD1351_NINTERFACES-1. * This allows support for multiple devices. @@ -1208,16 +1154,24 @@ static inline void ssd1351_hwinitialize(FAR struct ssd1351_dev_s *priv) * ****************************************************************************/ +#ifdef CONFIG_SSD1351_PARALLEL8BIT +FAR struct lcd_dev_s *ssd1351_initialize(FAR struct ssd1351_lcd_s *lcd, + unsigned int devno) +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, unsigned int devno) +#endif { FAR struct ssd1351_dev_s *priv = &g_lcddev; - size_t i; - uint16_t buf[SSD1351_XRES/2]; /* Sanity check */ - DEBUGASSERT(spi != NULL && devno == 0); +#ifdef CONFIG_SSD1351_PARALLEL8BIT + DEBUGASSERT(lcd != NULL); +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) + DEBUGASSERT(spi != NULL); +#endif + DEBUGASSERT(devno == 0); /* Initialize the driver data structure */ @@ -1227,29 +1181,29 @@ FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, priv->dev.setpower = ssd1351_setpower; priv->dev.getcontrast = ssd1351_getcontrast; priv->dev.setcontrast = ssd1351_setcontrast; +#ifdef CONFIG_SSD1351_PARALLEL8BIT + priv->lcd = lcd; +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) priv->spi = spi; - priv->power = 0; +#endif + priv->power = LCD_FULL_OFF; /* Configure the SPI bus if we own it. Otherwise, don't bother because * it might change. */ +#if defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) #ifdef CONFIG_SPI_OWNBUS - ssd1351_configspi(spi); + SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); + SPI_SETBITS(spi, SSD1351_SPIBITS); + SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); +#endif #endif /* Configure the device */ ssd1351_hwinitialize(priv); - ssd1351_setpower(&priv->dev, 1); - - memset(buf, 0xff, sizeof(buf)); - for (i = 0; i < SSD1351_YRES / 4; i++) - { - ssd1351_putrun(i, 0, (const uint8_t *)buf, SSD1351_XRES/2); - } - return &priv->dev; } diff --git a/include/nuttx/lcd/ssd1351.h b/include/nuttx/lcd/ssd1351.h index 37b0483a92..858ac470e8 100644 --- a/include/nuttx/lcd/ssd1351.h +++ b/include/nuttx/lcd/ssd1351.h @@ -51,6 +51,7 @@ /* Configuration ************************************************************/ /* SSD1351 configuration settings: + * CONFIG_SSD1351_PARALLEL8BIT - 8-bit parallel interface * CONFIG_SSD1351_SPI3WIRE - 3-wire SPI interface * CONFIG_SSD1351_SPI4WIRE - 4-wire SPI interface * CONFIG_SSD1351_SPIMODE - SPI mode @@ -98,7 +99,18 @@ * Public Types ****************************************************************************/ +#ifdef CONFIG_SSD1351_PARALLEL8BIT +struct ssd1351_lcd_s +{ + void (*cmd)(FAR struct ssd1351_lcd_s *lcd, uint8_t cmd); +#ifndef CONFIG_LCD_NOGETRUN + uint8_t (*read)(FAR struct ssd1351_lcd_s *lcd); +#endif + void (*write)(FAR struct ssd1351_lcd_s *lcd, uint8_t data); +}; +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) struct spi_dev_s; +#endif /**************************************************************************** * Public Function Prototypes @@ -118,6 +130,7 @@ extern "C" * but with the power setting at 0 (full off == sleep mode). * * Input Parameters: + * lcd - A reference to the platform-specific interface. * spi - A reference to the SPI driver instance. * devno - A value in the range of 0 through CONFIG_SSD1351_NINTERFACES-1. * This allows support for multiple devices. @@ -128,8 +141,13 @@ extern "C" * ****************************************************************************/ +#ifdef CONFIG_SSD1351_PARALLEL8BIT +FAR struct lcd_dev_s *ssd1351_initialize(FAR struct ssd1351_lcd_s *lcd, + unsigned int devno); +#elif defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, unsigned int devno); +#endif #ifdef __cplusplus } -- GitLab From 77e4e7b2314b52b8abe182eee16cf64898e8184f Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Mon, 7 Sep 2015 13:10:40 -0600 Subject: [PATCH 126/858] Change all references from avsprintf to vasprintf. From Sebastien Lorquet --- ChangeLog | 2 ++ arch | 2 +- include/cxx/cstdio | 2 +- include/stdio.h | 2 +- libc/libc.csv | 2 +- libc/stdio/Make.defs | 2 +- libc/stdio/lib_asprintf.c | 4 ++-- libc/stdio/lib_avsprintf.c | 10 +++++----- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1739da9bdf..f0e17b3f10 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10948,4 +10948,6 @@ intended to support the initial board bring-up (2015-09-05). * up_initialize() all architectures: Automatically initialize all the TUN device if it is in the configuration (2015-09-06). + * Change all references from avsprintf to vasprintf. From Sebastien + Lorquet (2015-09-07). diff --git a/arch b/arch index 1e8ed1f683..4b6d3fced6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1e8ed1f683eb8cd5ddec57ca978735bbde0af6cd +Subproject commit 4b6d3fced65486ad40609ea5d08feb0882f3d80c diff --git a/include/cxx/cstdio b/include/cxx/cstdio index e2de1c23f3..0074091a2f 100644 --- a/include/cxx/cstdio +++ b/include/cxx/cstdio @@ -91,7 +91,7 @@ namespace std using ::vprintf; using ::vfprintf; using ::vsprintf; - using ::avsprintf; + using ::vasprintf; using ::vsnprintf; using ::vsscanf; diff --git a/include/stdio.h b/include/stdio.h index 13e99eb4a9..f75e9928d1 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -163,7 +163,7 @@ void perror(FAR const char *s); int vprintf(FAR const char *format, va_list ap); int vfprintf(FAR FILE *stream, const char *format, va_list ap); int vsprintf(FAR char *buf, const char *format, va_list ap); -int avsprintf(FAR char **ptr, const char *fmt, va_list ap); +int vasprintf(FAR char **ptr, const char *fmt, va_list ap); int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap); int vsscanf(FAR const char *buf, FAR const char *s, va_list ap); diff --git a/libc/libc.csv b/libc/libc.csv index 977a111fbe..d93fe22a27 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -5,7 +5,7 @@ "aio_return","aio.h","defined(CONFIG_FS_AIO)","ssize_t","FAR struct aiocb *" "aio_suspend","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR const struct timespec *" "asprintf","stdio.h","","int","FAR char **","const char *","..." -"avsprintf","stdio.h","","int","FAR char **","const char *","va_list" +"vasprintf","stdio.h","","int","FAR char **","const char *","va_list" "b16atan2","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" "b16cos","fixedmath.h","","b16_t","b16_t" "b16divb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" diff --git a/libc/stdio/Make.defs b/libc/stdio/Make.defs index 66914b30f2..fbda15caaa 100644 --- a/libc/stdio/Make.defs +++ b/libc/stdio/Make.defs @@ -38,7 +38,7 @@ # C streams. CSRCS += lib_fileno.c lib_printf.c lib_sprintf.c lib_asprintf.c -CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_avsprintf.c +CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_vasprintf.c CSRCS += lib_vsnprintf.c lib_libvsprintf.c lib_dprintf.c lib_vdprintf.c CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c CSRCS += lib_memsostream.c lib_lowinstream.c lib_lowoutstream.c diff --git a/libc/stdio/lib_asprintf.c b/libc/stdio/lib_asprintf.c index c08d7360a6..92a17a82b0 100644 --- a/libc/stdio/lib_asprintf.c +++ b/libc/stdio/lib_asprintf.c @@ -97,10 +97,10 @@ int asprintf (FAR char **ptr, const char *fmt, ...) va_list ap; int ret; - /* Let avsprintf do all of the work */ + /* Let vasprintf do all of the work */ va_start(ap, fmt); - ret = avsprintf(ptr, fmt, ap); + ret = vasprintf(ptr, fmt, ap); va_end(ap); return ret; diff --git a/libc/stdio/lib_avsprintf.c b/libc/stdio/lib_avsprintf.c index 6f9e5cb77c..5f0649a174 100644 --- a/libc/stdio/lib_avsprintf.c +++ b/libc/stdio/lib_avsprintf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/stdio/lib_avsprintf.c + * libc/stdio/lib_vasprintf.c * * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -49,7 +49,7 @@ ****************************************************************************/ /* On some architectures, va_list is really a pointer to a structure on the * stack. And the va_arg builtin will modify that instance of va_list. Since - * avsprintf traverse the parameters in the va_list twice, the va_list will + * vasprintf traverse the parameters in the va_list twice, the va_list will * be altered in this first cases and the second usage will fail. So far, I * have seen this only on the X86 family with GCC. */ @@ -95,14 +95,14 @@ ****************************************************************************/ /**************************************************************************** - * Name: avsprintf + * Name: vasprintf * * Description: * This function is similar to vsprintf, except that it dynamically * allocates a string (as with malloc) to hold the output, instead of * putting the output in a buffer you allocate in advance. The ptr * argument should be the address of a char * object, and a successful - * call to avsprintf stores a pointer to the newly allocated string at that + * call to vasprintf stores a pointer to the newly allocated string at that * location. * * Returned Value: @@ -112,7 +112,7 @@ * ****************************************************************************/ -int avsprintf(FAR char **ptr, const char *fmt, va_list ap) +int vasprintf(FAR char **ptr, const char *fmt, va_list ap) { struct lib_outstream_s nulloutstream; struct lib_memoutstream_s memoutstream; -- GitLab From bc46130c70fc6366cd2d0448af68107a48587cc5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 13:28:00 -0600 Subject: [PATCH 127/858] Rename libc/stdio/lib_avsprintf.c to lib_vasprintf.c --- Documentation | 2 +- configs | 2 +- libc/stdio/{lib_avsprintf.c => lib_vasprintf.c} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename libc/stdio/{lib_avsprintf.c => lib_vasprintf.c} (100%) diff --git a/Documentation b/Documentation index a57e68381b..11a3998898 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit a57e68381bdffe6372bc88cf2e74ae4922549ae7 +Subproject commit 11a3998898b783cd758570fef01423182f5a452b diff --git a/configs b/configs index 88b49cd40d..996df29a34 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 88b49cd40d20572ff019525cc959e7b4c3a3c31f +Subproject commit 996df29a34c1c6034871c6ebdfe0c480ff68b8f8 diff --git a/libc/stdio/lib_avsprintf.c b/libc/stdio/lib_vasprintf.c similarity index 100% rename from libc/stdio/lib_avsprintf.c rename to libc/stdio/lib_vasprintf.c -- GitLab From f10a103108a460dded473238285ebf570e2472e1 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Mon, 7 Sep 2015 13:31:35 -0600 Subject: [PATCH 128/858] Fix tcp_send_unbuffered when NET_ETHERNET is not defined. --- net/tcp/tcp_send_unbuffered.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index efffe4793f..4620532342 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -260,7 +260,7 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn) } #else /* CONFIG_NET_ETHERNET */ -# psock_send_addrchck(r) (true) +# define psock_send_addrchck(r) (true) #endif /* CONFIG_NET_ETHERNET */ /**************************************************************************** -- GitLab From 65abe20cdb58b3e59617dc9c2f4ae1a312ff7a83 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 13:51:05 -0600 Subject: [PATCH 129/858] Update ChangeLog --- ChangeLog | 7 +++++++ arch | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f0e17b3f10..d3669a3ece 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10950,4 +10950,11 @@ the TUN device if it is in the configuration (2015-09-06). * Change all references from avsprintf to vasprintf. From Sebastien Lorquet (2015-09-07). + * net/tcp: Fix unbuffered send compilation error when Ethernet is not + enabled. From Alan Cavalho de Assis (2015-09-07). + * LPC31 and SAMA5D EHCI: Fix qh_ioccheck to move bp to next QH. From + Ilya Averyanov (2015-09-07). + * LPC31 and SAMA5D EHCI: Performance improvement: Do not disable the + asynchronous queue when adding a new QH structure. From Ilya + Averyanov (2015-09-07). diff --git a/arch b/arch index 4b6d3fced6..ed8f6a71d4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4b6d3fced65486ad40609ea5d08feb0882f3d80c +Subproject commit ed8f6a71d4014833fa25882aeca664aafdc8774d -- GitLab From d78d3ef4ab229502828fb1f9b92e4d78e6d2df3e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 14:40:18 -0600 Subject: [PATCH 130/858] Logic for delayed memory garbage collection for the case of user space memory will not work as implemented for the case of the kernel build. That is because the correct context is in place in order to free the user memory when sched_kufree is called, but will not be in place later when the memory garbage collection runs. If this feature is really needed, then some more substantial redesign is required --- sched/init/os_start.c | 18 +++++++++++++++--- sched/sched/sched.h | 14 ++++++++++++-- sched/sched/sched_free.c | 18 ++++++++++++++++-- sched/sched/sched_garbage.c | 11 +++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 511e5870c7..cafec16a1d 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -152,13 +152,23 @@ volatile dq_queue_t g_inactivetasks; * while it is within an interrupt handler. */ -volatile sq_queue_t g_delayed_kufree; - #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) volatile sq_queue_t g_delayed_kfree; #endif +#ifndef CONFIG_BUILD_KERNEL +/* REVISIT: It is not safe to defer user allocation in the kernel mode + * build. Why? Because the correct user context will not be in place + * when these deferred de-allocations are performed. In order to make this + * work, we would need to do something like: (1) move g_delayed_kufree + * into the group structure, then traverse the groups to collect garbage + * on a group-by-group basis. + */ + +volatile sq_queue_t g_delayed_kufree; +#endif + /* This is the value of the last process ID assigned to a task */ volatile pid_t g_lastpid; @@ -271,11 +281,13 @@ void os_start(void) dq_init(&g_waitingforfill); #endif dq_init(&g_inactivetasks); - sq_init(&g_delayed_kufree); #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) sq_init(&g_delayed_kfree); #endif +#ifndef CONFIG_BUILD_KERNEL + sq_init(&g_delayed_kufree); +#endif /* Initialize the logic that determine unique process IDs. */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 826be4a708..938f89a768 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -172,13 +172,23 @@ extern volatile dq_queue_t g_inactivetasks; * while it is within an interrupt handler. */ -extern volatile sq_queue_t g_delayed_kufree; - #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) extern volatile sq_queue_t g_delayed_kfree; #endif +#ifndef CONFIG_BUILD_KERNEL +/* REVISIT: It is not safe to defer user allocation in the kernel mode + * build. Why? Because the correct user context will not be in place + * when these deferred de-allocations are performed. In order to make + * this work, we would need to do something like: (1) move g_delayed_kufree + * into the group structure, then traverse the groups to collect garbage on + * a group-by-group basis. + */ + +extern volatile sq_queue_t g_delayed_kufree; +#endif + /* This is the value of the last process ID assigned to a task */ extern volatile pid_t g_lastpid; diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index d5c8dd8d09..a762e09a6a 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -85,8 +85,6 @@ void sched_ufree(FAR void *address) { - irqstate_t flags; - /* Check if this is an attempt to deallocate memory from an exception * handler. If this function is called from the IDLE task, then we * must have exclusive access to the memory manager to do this. @@ -94,6 +92,21 @@ void sched_ufree(FAR void *address) if (up_interrupt_context() || kumm_trysemaphore() != 0) { +#ifdef CONFIG_BUILD_KERNEL + /* REVISIT: It is not safe to defer user allocation in the kernel + * mode build. Why? Because the correct user context is in place + * now but will not be in place when the deferred de-allocation is + * performed. In order to make this work, we would need to do + * something like: (1) move g_delayed_kufree into the group + * structure, then traverse the groups to collect garbage on a + * group-by-group basis. + */ + + PANIC(); + +#else + irqstate_t flags; + /* Yes.. Make sure that this is not a attempt to free kernel memory * using the user deallocator. */ @@ -114,6 +127,7 @@ void sched_ufree(FAR void *address) work_signal(LPWORK); #endif irqrestore(flags); +#endif } else { diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index fb1cdeb8fa..ce394641cf 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -78,6 +78,16 @@ static inline void sched_kucleanup(void) { +#ifdef CONFIG_BUILD_KERNEL + /* REVISIT: It is not safe to defer user allocation in the kernel mode + * build. Why? Because the correct user context will not be in place + * when these deferred de-allocations are performed. In order to make + * this work, we would need to do something like: (1) move + * g_delayed_kufree into the group structure, then traverse the groups to + * collect garbage on a group-by-group basis. + */ + +#else irqstate_t flags; FAR void *address; @@ -106,6 +116,7 @@ static inline void sched_kucleanup(void) kumm_free(address); } } +#endif } /**************************************************************************** -- GitLab From cb2f84e288cd92e807d2fa96427ffe37ba0421be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 15:28:58 -0600 Subject: [PATCH 131/858] Loosen up restriction a little in sched_ufree() --- sched/sched/sched_free.c | 74 ++++++++++++++++++++----------------- sched/sched/sched_garbage.c | 2 +- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index a762e09a6a..1ef1579159 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -1,7 +1,7 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_free.c * - * Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -31,11 +31,13 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ + #include @@ -48,31 +50,37 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ + -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Global Variables - ************************************************************************/ + ****************************************************************************/ + -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ + -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ + -/************************************************************************ +/**************************************************************************** * Name: sched_ufree and sched_kfree * * Description: @@ -81,10 +89,23 @@ * corner cases where the operating system may have to perform * deallocations from within an interrupt handler. * - ************************************************************************/ + ****************************************************************************/ void sched_ufree(FAR void *address) { +#ifdef CONFIG_BUILD_KERNEL + /* REVISIT: It is not safe to defer user allocation in the kernel mode + * build. Why? Because the correct user context is in place now but + * will not be in place when the deferred de-allocation is performed. In + * order to make this work, we would need to do something like: (1) move + * g_delayed_kufree into the group structure, then traverse the groups to + * collect garbage on a group-by-group basis. + */ + + ASSERT(!up_interrupt_context()); + kumm_free(address); + +#else /* Check if this is an attempt to deallocate memory from an exception * handler. If this function is called from the IDLE task, then we * must have exclusive access to the memory manager to do this. @@ -92,19 +113,6 @@ void sched_ufree(FAR void *address) if (up_interrupt_context() || kumm_trysemaphore() != 0) { -#ifdef CONFIG_BUILD_KERNEL - /* REVISIT: It is not safe to defer user allocation in the kernel - * mode build. Why? Because the correct user context is in place - * now but will not be in place when the deferred de-allocation is - * performed. In order to make this work, we would need to do - * something like: (1) move g_delayed_kufree into the group - * structure, then traverse the groups to collect garbage on a - * group-by-group basis. - */ - - PANIC(); - -#else irqstate_t flags; /* Yes.. Make sure that this is not a attempt to free kernel memory @@ -127,7 +135,6 @@ void sched_ufree(FAR void *address) work_signal(LPWORK); #endif irqrestore(flags); -#endif } else { @@ -136,6 +143,7 @@ void sched_ufree(FAR void *address) kumm_free(address); kumm_givesemaphore(); } +#endif } #ifdef CONFIG_MM_KERNEL_HEAP diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index ce394641cf..5ebfe6eaed 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -201,7 +201,7 @@ void sched_garbagecollection(void) sched_kcleanup(); - /* Handle deferred dealloctions for the user heap */ + /* Handle deferred deallocations for the user heap */ sched_kucleanup(); } -- GitLab From d7007930774d86d363ff2cc5273b5a8a5ce3a298 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 16:34:25 -0600 Subject: [PATCH 132/858] Fix a compile error when IPv6 is enabled --- arch | 2 +- net/tcp/tcp_finddev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ed8f6a71d4..2391024361 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ed8f6a71d4014833fa25882aeca664aafdc8774d +Subproject commit 239102436188022a043042e3b6251b5eb891084d diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index 82fb5810b5..8d7d468292 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -278,7 +278,7 @@ int tcp_local_ipv6_device(FAR struct tcp_conn_s *conn) #ifdef CONFIG_NET_IPv6 int tcp_remote_ipv6_device(FAR struct tcp_conn_s *conn) { - return int tcp_find_ipv6_device(conn, conn->u.ipv6.raddr); + return tcp_find_ipv6_device(conn, conn->u.ipv6.raddr); } #endif /* CONFIG_NET_IPv6 */ -- GitLab From dbc9d67b3aad35be8955f236302ee874d264e019 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 07:25:21 -0600 Subject: [PATCH 133/858] USBDEV Kconfig: CONFIG_USBDEV_TRACE_INITIALIDSET missing from Kconfig file --- drivers/usbdev/Kconfig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig index a284917ee6..a08c85e07f 100644 --- a/drivers/usbdev/Kconfig +++ b/drivers/usbdev/Kconfig @@ -102,7 +102,7 @@ config USBDEV_TRACE_NRECORDS Number of trace entries to remember config USBDEV_TRACE_STRINGS -bool "Decode device controller events" + bool "Decode device controller events" default n depends on USBDEV_TRACE || DEBUG_USB ---help--- @@ -116,6 +116,15 @@ bool "Decode device controller events" extern const struct trace_msg_t g_usb_trace_strings_intdecode[]; #endif +config USBDEV_TRACE_INITIALIDSET + bool "Initial enable bits" + default 0 + depends on USBDEV_TRACE + ---help--- + This is the set of initial USB features that are enabled at boot + time. See the event ID class bit definitions in + include/nuttx/usbdev_trace.h. + comment "USB Device Class Driver Options" config USBDEV_COMPOSITE -- GitLab From 48d7930631b2d11960adab0bb398db16502d1d01 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 07:37:19 -0600 Subject: [PATCH 134/858] CC3300: Eliminate some compile time warnings --- drivers/wireless/cc3000/cc3000.c | 7 ++++--- drivers/wireless/cc3000/cc3000drv.c | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index c11064e5af..b2265b33cb 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/wireless/cc3000.c * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David_s5 * @@ -719,7 +719,8 @@ static void * cc3000_worker(FAR void *arg) priv->state = eSPI_STATE_READ_READY; priv->rx_buffer.len = data_to_recv; - ret = mq_send(priv->queue, &priv->rx_buffer, sizeof(priv->rx_buffer), 1); + ret = mq_send(priv->queue, (FAR const char *)&priv->rx_buffer, + sizeof(priv->rx_buffer), 1); DEBUGASSERT(ret >= 0); UNUSED(ret); @@ -886,7 +887,7 @@ static int cc3000_open(FAR struct file *filep) */ snprintf(queuename, QUEUE_NAMELEN, QUEUE_FORMAT, priv->minor); - priv->queue = mq_open(queuename,O_WRONLY|O_CREAT, 0666, &attr); + priv->queue = mq_open(queuename, O_WRONLY|O_CREAT, 0666, &attr); if (priv->queue < 0) { ret = -errno; diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index 712c2803eb..a061fd2468 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -1,6 +1,6 @@ /************************************************************************** - * drivers/wireless/cc3000/cc3000drv.c - Driver wrapper functions to - * conntect nuttx to the TI CC3000 + * drivers/wireless/cc3000/cc3000drv.c + * Driver wrapper functions to conntect nuttx to the TI CC3000 * * Port to nuttx: * David Sidrane @@ -179,7 +179,8 @@ uint8_t *cc3000_wait(void) { DEBUGASSERT(spiconf.cc3000fd >= 0); - mq_receive(spiconf.queue, &spiconf.rx_buffer, sizeof(spiconf.rx_buffer), 0); + mq_receive(spiconf.queue, (FAR char *)&spiconf.rx_buffer, + sizeof(spiconf.rx_buffer), 0); return spiconf.rx_buffer.pbuffer; } @@ -206,7 +207,7 @@ static void *unsoliced_thread_func(void *parameter) ioctl(spiconf.cc3000fd, CC3000IOC_GETQUESEMID, (unsigned long)&minor); snprintf(buff, QUEUE_NAMELEN, QUEUE_FORMAT, minor); - spiconf.queue = mq_open(buff,O_RDONLY); + spiconf.queue = mq_open(buff, O_RDONLY); DEBUGASSERT(spiconf.queue != (mqd_t) -1); DEBUGASSERT(SEM_NAMELEN == QUEUE_NAMELEN); snprintf(buff, SEM_NAMELEN, SEM_FORMAT, minor); @@ -218,7 +219,7 @@ static void *unsoliced_thread_func(void *parameter) while (spiconf.run) { memset(&spiconf.rx_buffer,0,sizeof(spiconf.rx_buffer)); - nbytes = mq_receive(spiconf.queue, &spiconf.rx_buffer, + nbytes = mq_receive(spiconf.queue, (FAR char *)&spiconf.rx_buffer, sizeof(spiconf.rx_buffer), 0); if (nbytes > 0) { -- GitLab From 9cd1e34792123adb907aec220d2221745c7f7b0d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 08:08:46 -0600 Subject: [PATCH 135/858] Eliminate a warning --- configs | 2 +- tools/mkconfig.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/configs b/configs index 996df29a34..11b777b1b5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 996df29a34c1c6034871c6ebdfe0c480ff68b8f8 +Subproject commit 11b777b1b549c662a23d87b8a5321ed9fea9c34a diff --git a/tools/mkconfig.c b/tools/mkconfig.c index 93dc7e3149..db93b709d7 100644 --- a/tools/mkconfig.c +++ b/tools/mkconfig.c @@ -209,8 +209,12 @@ int main(int argc, char **argv, char **envp) printf("/* If the maximum message size is zero, then we assume that message queues\n"); printf(" * support should be disabled\n"); printf(" */\n\n"); + printf("#ifndef CONFIG_MQ_MAXMSGSIZE)\n"); + printf("# define CONFIG_DISABLE_MQUEUE 0\n"); + printf("#endif\n\n"); printf("#if CONFIG_MQ_MAXMSGSIZE <= 0 && !defined(CONFIG_DISABLE_MQUEUE)\n"); - printf("# define CONFIG_DISABLE_MQUEUE 1\n"); + printf("# undef CONFIG_DISABLE_MQUEUE\n"); + printf("# define CONFIG_DISABLE_MQUEUE 0\n"); printf("#endif\n\n"); printf("/* If mountpoint support in not included, then no filesystem can be supported */\n\n"); printf("#ifdef CONFIG_DISABLE_MOUNTPOINT\n"); -- GitLab From a7e43c7fdbfda3d7944c42637dcbf6c25220d1d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 09:20:18 -0600 Subject: [PATCH 136/858] Eliminate some warnings --- arch | 2 +- configs | 2 +- drivers/wireless/cc1101.c | 208 +++++++++++++++++++++----------------- net/iob/iob.h | 3 + 4 files changed, 121 insertions(+), 94 deletions(-) diff --git a/arch b/arch index 2391024361..64609d18df 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 239102436188022a043042e3b6251b5eb891084d +Subproject commit 64609d18df529479e9c5eccd82e67006fedd962b diff --git a/configs b/configs index 11b777b1b5..c706f1adc1 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 11b777b1b549c662a23d87b8a5321ed9fea9c34a +Subproject commit c706f1adc1ff2897ae0e69553cafc3c23bf7c455 diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index 16c1d33fbc..ff0712d9e7 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -300,11 +300,17 @@ struct cc1101_dev_s uint8_t power; }; +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static volatile int cc1101_interrupt = 0; + /**************************************************************************** * Private Functions ****************************************************************************/ -void cc1101_access_begin(struct cc1101_dev_s * dev) +void cc1101_access_begin(FAR struct cc1101_dev_s * dev) { (void)SPI_LOCK(dev->spi, true); SPI_SELECT(dev->spi, SPIDEV_WIRELESS, true); @@ -312,24 +318,28 @@ void cc1101_access_begin(struct cc1101_dev_s * dev) SPI_SETBITS(dev->spi, 8); } -void cc1101_access_end(struct cc1101_dev_s * dev) +void cc1101_access_end(FAR struct cc1101_dev_s * dev) { SPI_SELECT(dev->spi, SPIDEV_WIRELESS, false); (void)SPI_LOCK(dev->spi, false); } -/** CC1101 Access with Range Check +/* CC1101 Access with Range Check * - * \param dev CC1101 Private Structure - * \param addr CC1101 Address - * \param buf Pointer to buffer, either for read or write access - * \param length when >0 it denotes read access, when <0 it denotes write + * Input Paramters: + * dev CC1101 Private Structure + * addr CC1101 Address + * buf Pointer to buffer, either for read or write access + * length when >0 it denotes read access, when <0 it denotes write * access of -length. abs(length) greater of 1 implies burst mode, * however - * \return OK on success or errno is set. + * + * Returned Value: + * OK on success or errno is set. */ -int cc1101_access(struct cc1101_dev_s * dev, uint8_t addr, uint8_t *buf, int length) +int cc1101_access(FAR struct cc1101_dev_s * dev, uint8_t addr, + FAR uint8_t *buf, int length) { int stabyte; @@ -339,143 +349,157 @@ int cc1101_access(struct cc1101_dev_s * dev, uint8_t addr, uint8_t *buf, int len */ if ((addr & CC1101_READ_SINGLE) && length != 1) - return ERROR; + { + return ERROR; + } - /* Prepare SPI */ + /* Prepare SPI */ - cc1101_access_begin(dev); + cc1101_access_begin(dev); - if (length>1 || length < -1) - SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_BURST); - else SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_SINGLE); + if (length>1 || length < -1) + { + SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_BURST); + } + else + { + SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_SINGLE); + } - /* Transfer */ + /* Transfer */ - if (length <= 0) { /* 0 length are command strobes */ - if (length < -1) - addr |= CC1101_WRITE_BURST; + if (length <= 0) + { + /* 0 length are command strobes */ - stabyte = SPI_SEND(dev->spi, addr); - if (length) { - SPI_SNDBLOCK(dev->spi, buf, -length); + if (length < -1) + { + addr |= CC1101_WRITE_BURST; + } + + stabyte = SPI_SEND(dev->spi, addr); + if (length) + { + SPI_SNDBLOCK(dev->spi, buf, -length); } } - else { - addr |= CC1101_READ_SINGLE; - if (length > 1) - addr |= CC1101_READ_BURST; + else + { + addr |= CC1101_READ_SINGLE; + if (length > 1) + { + addr |= CC1101_READ_BURST; + } - stabyte = SPI_SEND(dev->spi, addr); - SPI_RECVBLOCK(dev->spi, buf, length); + stabyte = SPI_SEND(dev->spi, addr); + SPI_RECVBLOCK(dev->spi, buf, length); } - cc1101_access_end(dev); + cc1101_access_end(dev); - return stabyte; + return stabyte; } - -/** Strobes command and returns chip status byte +/* Strobes command and returns chip status byte * * By default commands are send as Write. To a command, * CC1101_READ_SINGLE may be OR'ed to obtain the number of RX bytes * pending in RX FIFO. */ + inline uint8_t cc1101_strobe(struct cc1101_dev_s * dev, uint8_t command) { - uint8_t status; + uint8_t status; - cc1101_access_begin(dev); - SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_SINGLE); + cc1101_access_begin(dev); + SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_SINGLE); - status = SPI_SEND(dev->spi, command); + status = SPI_SEND(dev->spi, command); - cc1101_access_end(dev); + cc1101_access_end(dev); - return status; + return status; } - int cc1101_reset(struct cc1101_dev_s * dev) { - cc1101_strobe(dev, CC1101_SRES); - return OK; + cc1101_strobe(dev, CC1101_SRES); + return OK; } - int cc1101_checkpart(struct cc1101_dev_s * dev) { - uint8_t partnum, version; + uint8_t partnum; + uint8_t version; - if (cc1101_access(dev, CC1101_PARTNUM, &partnum, 1) < 0 || - cc1101_access(dev, CC1101_VERSION, &version, 1) < 0) - return ERROR; + if (cc1101_access(dev, CC1101_PARTNUM, &partnum, 1) < 0 || + cc1101_access(dev, CC1101_VERSION, &version, 1) < 0) + { + return ERROR; + } - if (partnum == CC1101_PARTNUM_VALUE && version == CC1101_VERSION_VALUE) - return OK; + if (partnum == CC1101_PARTNUM_VALUE && version == CC1101_VERSION_VALUE) + { + return OK; + } - return ERROR; + return ERROR; } - void cc1101_dumpregs(struct cc1101_dev_s * dev, uint8_t addr, uint8_t length) { - uint8_t buf[0x30], i; + uint8_t buf[0x30], i; - cc1101_access(dev, addr, buf, length); + cc1101_access(dev, addr, FAR uint8_t *buf, length); - printf("CC1101[%2x]: ", addr); - for (i=0; i RX, RX -> RX: 0x3F */ - values[2] = CC1101_MCSM0_VALUE; /* Calibrate on IDLE -> RX/TX, OSC Timeout = ~500 us - TODO: has XOSC_FORCE_ON */ - cc1101_access(dev, CC1101_MCSM2, values, -3); + values[0] = 0x07; /* No time-out */ + values[1] = 0x00; /* Clear channel if RSSI < thr && !receiving; + * TX -> RX, RX -> RX: 0x3F */ + values[2] = CC1101_MCSM0_VALUE; /* Calibrate on IDLE -> RX/TX, OSC Timeout = ~500 us + TODO: has XOSC_FORCE_ON */ + cc1101_access(dev, CC1101_MCSM2, values, -3); - /* Wake-On Radio Control */ + /* Wake-On Radio Control */ - // Not used yet. + // Not used yet. - // WOREVT1:WOREVT0 - 16-bit timeout register + // WOREVT1:WOREVT0 - 16-bit timeout register } - /**************************************************************************** * Callbacks ****************************************************************************/ -volatile int cc1101_interrupt = 0; - -/** External line triggers this callback +/* External line triggers this callback * * The concept todo is: * - GPIO provides EXTI Interrupt @@ -612,7 +636,7 @@ int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function) /* Force XOSC to stay active even in sleep mode */ int value = CC1101_MCSM0_VALUE | CC1101_MCSM0_XOSC_FORCE_ON; - cc1101_access(dev, CC1101_MCSM0, &value, -1); + cc1101_access(dev, CC1101_MCSM0, (FAR uint8_t *)&value, -1); dev->flags |= FLAGS_XOSCENABLED; } @@ -621,7 +645,7 @@ int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function) /* Disable XOSC in sleep mode */ int value = CC1101_MCSM0_VALUE; - cc1101_access(dev, CC1101_MCSM0, &value, -1); + cc1101_access(dev, CC1101_MCSM0, (FAR uint8_t *)&value, -1); dev->flags &= ~FLAGS_XOSCENABLED; } @@ -634,24 +658,24 @@ int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *set ASSERT(dev); ASSERT(settings); - if (cc1101_access(dev, CC1101_FSCTRL1, &settings->FSCTRL1, -11) < 0) + if (cc1101_access(dev, CC1101_FSCTRL1, (FAR uint8_t *)&settings->FSCTRL1, -11) < 0) { return ERROR; } - if (cc1101_access(dev, CC1101_FOCCFG, &settings->FOCCFG, -5) < 0) + if (cc1101_access(dev, CC1101_FOCCFG, (FAR uint8_t *)&settings->FOCCFG, -5) < 0) { return ERROR; } - if (cc1101_access(dev, CC1101_FREND1, &settings->FREND1, -6) < 0) + if (cc1101_access(dev, CC1101_FREND1, (FAR uint8_t *)&settings->FREND1, -6) < 0) { return ERROR; } /* Load Power Table */ - if (cc1101_access(dev, CC1101_PATABLE, settings->PA, -8) < 0) + if (cc1101_access(dev, CC1101_PATABLE, (FAR uint8_t *)settings->PA, -8) < 0) { return ERROR; } @@ -664,7 +688,7 @@ int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *set cc1101_setchannel(dev, dev->channel); cc1101_setpower(dev, dev->power); - return OK; + return OK; } int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel) @@ -823,7 +847,7 @@ int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size) } cc1101_access(dev, CC1101_TXFIFO, &packetlen, -1); - cc1101_access(dev, CC1101_TXFIFO, buf, -size); + cc1101_access(dev, CC1101_TXFIFO, (FAR uint8_t *)buf, -size); return 0; } diff --git a/net/iob/iob.h b/net/iob/iob.h index 49222bec4e..5b14e7e569 100644 --- a/net/iob/iob.h +++ b/net/iob/iob.h @@ -46,6 +46,8 @@ #include +#ifdef CONFIG_NET_IOB + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -132,4 +134,5 @@ FAR struct iob_s *iob_tryalloc(bool throttled); FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq); +#endif /* CONFIG_NET_IOB */ #endif /* __NET_IOB_IOB_H */ -- GitLab From bb595777fde3f2ea873b824b0e904bfae1e413e6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 10:21:19 -0600 Subject: [PATCH 137/858] Eliminate warnings --- arch | 2 +- configs | 2 +- drivers/lcd/ili9341.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch b/arch index 64609d18df..139a8394ac 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 64609d18df529479e9c5eccd82e67006fedd962b +Subproject commit 139a8394acd4dff3e5983be13543d8a264681c91 diff --git a/configs b/configs index c706f1adc1..ba2b1db6db 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c706f1adc1ff2897ae0e69553cafc3c23bf7c455 +Subproject commit ba2b1db6db4cd8f44047f5817233a922ee69343e diff --git a/drivers/lcd/ili9341.c b/drivers/lcd/ili9341.c index 66c186bf40..d2039c2803 100644 --- a/drivers/lcd/ili9341.c +++ b/drivers/lcd/ili9341.c @@ -324,16 +324,16 @@ /* First LCD display */ #ifdef CONFIG_LCD_ILI9341_IFACE0 -# ifdef CONFIG_LCD_ILI9341_IFACE0_LANDSCAPE +# if defined(CONFIG_LCD_ILI9341_IFACE0_LANDSCAPE) # define ILI9341_IFACE0_ORIENT ILI9341_MADCTL_LANDSCAPE_PARAM1 # define ILI9341_IFACE0_STRIDE ILI9341_YRES -# elif CONFIG_LCD_ILI9341_IFACE0_PORTRAIT +# elif defined(CONFIG_LCD_ILI9341_IFACE0_PORTRAIT) # define ILI9341_IFACE0_ORIENT ILI9341_MADCTL_PORTRAIT_PARAM1 # define ILI9341_IFACE0_STRIDE ILI9341_XRES -# elif CONFIG_LCD_ILI9341_IFACE0_RLANDSCAPE +# elif defined(CONFIG_LCD_ILI9341_IFACE0_RLANDSCAPE) # define ILI9341_IFACE0_ORIENT ILI9341_MADCTL_RLANDSCAPE_PARAM1 # define ILI9341_IFACE0_STRIDE ILI9341_YRES -# elif CONFIG_LCD_ILI9341_IFACE0_RPORTRAIT +# elif defined(CONFIG_LCD_ILI9341_IFACE0_RPORTRAIT) # define ILI9341_IFACE0_ORIENT ILI9341_MADCTL_RPORTRAIT_PARAM1 # define ILI9341_IFACE0_STRIDE ILI9341_XRES # endif -- GitLab From 366e3d3353151d99e2a5bd07fbed67e504407ba5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 10:48:57 -0600 Subject: [PATCH 138/858] Eliminate warnings --- configs | 2 +- tools/mkconfig.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs b/configs index ba2b1db6db..02a07e4dfc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ba2b1db6db4cd8f44047f5817233a922ee69343e +Subproject commit 02a07e4dfc9a5e04a2aeb57f4bd89e80285e2bbc diff --git a/tools/mkconfig.c b/tools/mkconfig.c index db93b709d7..038ad5fada 100644 --- a/tools/mkconfig.c +++ b/tools/mkconfig.c @@ -209,12 +209,12 @@ int main(int argc, char **argv, char **envp) printf("/* If the maximum message size is zero, then we assume that message queues\n"); printf(" * support should be disabled\n"); printf(" */\n\n"); - printf("#ifndef CONFIG_MQ_MAXMSGSIZE)\n"); - printf("# define CONFIG_DISABLE_MQUEUE 0\n"); + printf("#if !defined(CONFIG_MQ_MAXMSGSIZE) || defined(CONFIG_DISABLE_MQUEUE)\n"); + printf("# undef CONFIG_MQ_MAXMSGSIZE\n"); + printf("# define CONFIG_MQ_MAXMSGSIZE 0\n"); printf("#endif\n\n"); printf("#if CONFIG_MQ_MAXMSGSIZE <= 0 && !defined(CONFIG_DISABLE_MQUEUE)\n"); - printf("# undef CONFIG_DISABLE_MQUEUE\n"); - printf("# define CONFIG_DISABLE_MQUEUE 0\n"); + printf("# define CONFIG_DISABLE_MQUEUE 1\n"); printf("#endif\n\n"); printf("/* If mountpoint support in not included, then no filesystem can be supported */\n\n"); printf("#ifdef CONFIG_DISABLE_MOUNTPOINT\n"); -- GitLab From afdb3c751af1b88afdad3b1f65d5ebd17b6b03fe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 12:45:30 -0600 Subject: [PATCH 139/858] Fix typos from a previous commit --- arch | 2 +- configs | 2 +- drivers/wireless/cc1101.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 139a8394ac..a2df8e045e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 139a8394acd4dff3e5983be13543d8a264681c91 +Subproject commit a2df8e045e72541ff4f629e8a4d5e030711588e0 diff --git a/configs b/configs index 02a07e4dfc..a6a7289dbc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 02a07e4dfc9a5e04a2aeb57f4bd89e80285e2bbc +Subproject commit a6a7289dbc478350fce5db2c5f3afe1b59e0499d diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index ff0712d9e7..8289eef371 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -450,7 +450,7 @@ void cc1101_dumpregs(struct cc1101_dev_s * dev, uint8_t addr, uint8_t length) { uint8_t buf[0x30], i; - cc1101_access(dev, addr, FAR uint8_t *buf, length); + cc1101_access(dev, addr, (FAR uint8_t *)buf, length); printf("CC1101[%2x]: ", addr); for (i=0; i Date: Tue, 8 Sep 2015 14:19:13 -0600 Subject: [PATCH 140/858] sync submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index a2df8e045e..c1c1a4c6cb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a2df8e045e72541ff4f629e8a4d5e030711588e0 +Subproject commit c1c1a4c6cb59473efa26e2ea1f4a58bd7072fd96 diff --git a/configs b/configs index a6a7289dbc..3eab5db173 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a6a7289dbc478350fce5db2c5f3afe1b59e0499d +Subproject commit 3eab5db1733b5dcd55505925b0a989d8f2085aa3 -- GitLab From 90ec126b0bb5a1a59f93a00d65a9df90a17c5913 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Sep 2015 16:41:54 -0600 Subject: [PATCH 141/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d3669a3ece..171a92644c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10957,4 +10957,6 @@ * LPC31 and SAMA5D EHCI: Performance improvement: Do not disable the asynchronous queue when adding a new QH structure. From Ilya Averyanov (2015-09-07). + * arch/arm/src/sama5: Separate memory mapping tables for SAMA5D2, 3, + and 4 (2015-09-07). diff --git a/arch b/arch index c1c1a4c6cb..7ad0465595 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c1c1a4c6cb59473efa26e2ea1f4a58bd7072fd96 +Subproject commit 7ad0465595bd053d81012283ca9cfc8d67836d17 -- GitLab From 8a87e3ca6e29c4de5ab0dcb3edb806cf88dddbec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Sep 2015 07:03:05 -0600 Subject: [PATCH 142/858] Add an empty function that can serve as a placeholder for the network shutdown() function --- ChangeLog | 6 ++- include/sys/socket.h | 10 ++++- libc/net/Make.defs | 3 +- libc/net/lib_shutdown.c | 86 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 libc/net/lib_shutdown.c diff --git a/ChangeLog b/ChangeLog index 171a92644c..7edb70f971 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10958,5 +10958,9 @@ asynchronous queue when adding a new QH structure. From Ilya Averyanov (2015-09-07). * arch/arm/src/sama5: Separate memory mapping tables for SAMA5D2, 3, - and 4 (2015-09-07). + and 4 (2015-09-08). + * libc/net/lib_shutdown.c: Add an empty implementatino of the + standard shutdown function. This provides only the framework for + the shutdown function; the internal logic is not included + (2015-09-09). diff --git a/include/sys/socket.h b/include/sys/socket.h index 4c7b79ee79..0f9f10f4d1 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/socket.h * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -155,6 +155,12 @@ #define SOL_SOCKET 0 /* Only socket-level options supported */ +/* Values for the 'how' argument of shutdown() */ + +#define SHUT_RD 1 /* Bit 0: Disables further receive operations */ +#define SHUT_WR 2 /* Bit 1: Disables further send operations */ +#define SHUT_RDWR 3 /* Bits 0+1: Disables further send and receive operations */ + /**************************************************************************** * Type Definitions ****************************************************************************/ @@ -227,6 +233,8 @@ ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags); ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct sockaddr *from, FAR socklen_t *fromlen); +int shutdown(int sockfd, int how); + int setsockopt(int sockfd, int level, int option, FAR const void *value, socklen_t value_len); int getsockopt(int sockfd, int level, int option, diff --git a/libc/net/Make.defs b/libc/net/Make.defs index 6fe3cce9c2..26f39738a5 100644 --- a/libc/net/Make.defs +++ b/libc/net/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libc/net/Make.defs # -# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,6 +37,7 @@ CSRCS += lib_addrconfig.c lib_etherntoa.c lib_htons.c lib_htonl.c CSRCS += lib_inetaddr.c lib_inetntoa.c lib_inetntop.c lib_inetpton.c +CSRCS += lib_shutdown.c # Routing table support diff --git a/libc/net/lib_shutdown.c b/libc/net/lib_shutdown.c new file mode 100644 index 0000000000..a1ef4316ac --- /dev/null +++ b/libc/net/lib_shutdown.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * libc/net/lib_shutdown.c + * + * Copyright (c) 2015, Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public FUnctions + ****************************************************************************/ + +/**************************************************************************** + * Name: shutdown + * + * Description: + * The shutdown() function will cause all or part of a full-duplex + * connection on the socket associated with the file descriptor socket to + * be shut down. + * + * The shutdown() function disables subsequent send and/or receive + * operations on a socket, depending on the value of the how argument. + + * Input Paramteers: + * sockfd - Specifies the file descriptor of the socket. + * how - Specifies the type of shutdown. The values are as follows: + * + * SHUT_RD - Disables further receive operations. + * SHUT_WR - Disables further send operations. + * SHUT_RDWR - Disables further send and receive operations. + * + * Returned Value: + * Upon successful completion, shutdown() will return 0; otherwise, -1 will + * be returned and errno set to indicate the error. + + * EBADF - The socket argument is not a valid file descriptor. + * EINVAL - The how argument is invalid. + * ENOTCONN - The socket is not connected. + * ENOTSOCK - The socket argument does not refer to a socket. + * ENOBUFS - Insufficient resources were available in the system to + * perform the operation. + * + ****************************************************************************/ + +int shutdown(int sockfd, int how) +{ +#warning Missing Logic + return OK; +} -- GitLab From 5058ed3ef43781de5d23c952c1fd8f8a10701c16 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Sep 2015 12:14:04 -0600 Subject: [PATCH 143/858] Only build shutdown if CONFIG_NET=y. The warning is pretty annoying --- arch | 2 +- configs | 2 +- libc/net/Make.defs | 3 +++ libc/net/lib_shutdown.c | 6 +++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 7ad0465595..152bbe9b92 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7ad0465595bd053d81012283ca9cfc8d67836d17 +Subproject commit 152bbe9b9285d4f6141f3e8839ba0fc1d0d96be2 diff --git a/configs b/configs index 3eab5db173..08498337c3 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3eab5db1733b5dcd55505925b0a989d8f2085aa3 +Subproject commit 08498337c384cea7c918676495a9b3e6907cb092 diff --git a/libc/net/Make.defs b/libc/net/Make.defs index 26f39738a5..0d2a7fb4d4 100644 --- a/libc/net/Make.defs +++ b/libc/net/Make.defs @@ -37,7 +37,10 @@ CSRCS += lib_addrconfig.c lib_etherntoa.c lib_htons.c lib_htonl.c CSRCS += lib_inetaddr.c lib_inetntoa.c lib_inetntop.c lib_inetpton.c + +ifeq ($(CONFIG_NET),y) CSRCS += lib_shutdown.c +endif # Routing table support diff --git a/libc/net/lib_shutdown.c b/libc/net/lib_shutdown.c index a1ef4316ac..b533dbd2cf 100644 --- a/libc/net/lib_shutdown.c +++ b/libc/net/lib_shutdown.c @@ -39,12 +39,14 @@ #include +#ifdef CONFIG_NET + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** - * Public FUnctions + * Public Functions ****************************************************************************/ /**************************************************************************** @@ -84,3 +86,5 @@ int shutdown(int sockfd, int how) #warning Missing Logic return OK; } + +#endif /* CONFIG_NET */ -- GitLab From 8651e0f2ca1da89425fbea67b41b5a25e54c655f Mon Sep 17 00:00:00 2001 From: Pierre-noel Bouteville Date: Wed, 9 Sep 2015 16:34:37 -0600 Subject: [PATCH 144/858] CC3300: Add const to pointers in arguments to wlan_connect; remove an unused function prototype --- drivers/wireless/cc3000/cc3000drv.c | 3 --- drivers/wireless/cc3000/wlan.c | 9 +++++---- include/nuttx/wireless/cc3000/wlan.h | 7 ++++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index a061fd2468..491d603aaf 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -357,11 +357,8 @@ int cc3000_wait_data(int sockfd) * ****************************************************************************/ -int to_cc3000_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *addrlen); - int cc3000_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { - //return to_cc3000_accept_socket(sockfd, addr,addrlen); DEBUGASSERT(spiconf.cc3000fd >= 0); cc3000_acceptcfg cfg; diff --git a/drivers/wireless/cc3000/wlan.c b/drivers/wireless/cc3000/wlan.c index e84fd8954f..e0ac1d61a3 100644 --- a/drivers/wireless/cc3000/wlan.c +++ b/drivers/wireless/cc3000/wlan.c @@ -391,8 +391,9 @@ void wlan_stop(void) *****************************************************************************/ #ifndef CC3000_TINY_DRIVER -long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len, - uint8_t *bssid, uint8_t *key, long key_len) +long wlan_connect(unsigned long ulSecType, FAR const char *ssid, + long ssid_len, FAR const uint8_t *bssid, + FAR const uint8_t *key, long key_len) { long ret; uint8_t *ptr; @@ -445,7 +446,7 @@ long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len, return ret; } #else -long wlan_connect(char *ssid, long ssid_len) +long wlan_connect(FAR const char *ssid, long ssid_len) { long ret; uint8_t *ptr; @@ -618,7 +619,7 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, *****************************************************************************/ #ifndef CC3000_TINY_DRIVER -long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid, +long wlan_add_profile(unsigned long ulSecType, uint8_t *ucSsid, unsigned long ulSsidLen, uint8_t *ucBssid, unsigned long ulPriority, unsigned long ulPairwiseCipher_Or_TxKeyLen, diff --git a/include/nuttx/wireless/cc3000/wlan.h b/include/nuttx/wireless/cc3000/wlan.h index e41724a46e..6acf62a56f 100644 --- a/include/nuttx/wireless/cc3000/wlan.h +++ b/include/nuttx/wireless/cc3000/wlan.h @@ -194,10 +194,11 @@ void wlan_stop(void); *****************************************************************************/ #ifndef CC3000_TINY_DRIVER -long wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len, - uint8_t *bssid, uint8_t *key, long key_len); +long wlan_connect(unsigned long ulSecType, FAR const char *ssid, + long ssid_len, FAR const uint8_t *bssid, + FAR const uint8_t *key, long key_len); #else -long wlan_connect(char *ssid, long ssid_len); +long wlan_connect(FAR const char *ssid, long ssid_len); #endif /***************************************************************************** -- GitLab From d0e4df993128edb7e4926f7b7a0d28596cf64d33 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Sep 2015 07:24:58 -0600 Subject: [PATCH 145/858] Update ChangeLog --- ChangeLog | 4 ++++ libc/net/lib_shutdown.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7edb70f971..a6aa6051b8 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10963,4 +10963,8 @@ standard shutdown function. This provides only the framework for the shutdown function; the internal logic is not included (2015-09-09). + * configs/nucleo-f303re: Support for the STMicro Nucleo F303ERE board + from Paul Alexander Patience (2014-09-10). + * arch/arm/src/lpc43xx/lpc32_ehci.c and .h: LPC43xx EHCI driver from + Ilya Averyanov (2015-09-10). diff --git a/libc/net/lib_shutdown.c b/libc/net/lib_shutdown.c index b533dbd2cf..6b71f847c3 100644 --- a/libc/net/lib_shutdown.c +++ b/libc/net/lib_shutdown.c @@ -83,7 +83,8 @@ int shutdown(int sockfd, int how) { -#warning Missing Logic + /* REVISIT: Not implemented. */ + return OK; } -- GitLab From ed0d480d3e81c87dc1097be530aac690c10f970c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Sep 2015 13:07:32 -0600 Subject: [PATCH 146/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 152bbe9b92..1db4677359 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 152bbe9b9285d4f6141f3e8839ba0fc1d0d96be2 +Subproject commit 1db4677359dae966c12a0f3830da14005d887a58 diff --git a/configs b/configs index 08498337c3..7e082490eb 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 08498337c384cea7c918676495a9b3e6907cb092 +Subproject commit 7e082490eb9da35d7635d66a2282383413357d01 -- GitLab From 9f108b7b63c5fe326eeae8be96fd870ceec0ec8d Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 10 Sep 2015 20:59:43 -0400 Subject: [PATCH 147/858] Fix issues detected by clang --- drivers/bch/bchlib_read.c | 2 -- drivers/bch/bchlib_write.c | 2 -- libc/stdio/lib_libfwrite.c | 8 +++++++- libc/stdio/lib_vasprintf.c | 6 +++--- mm/mm_heap/mm_realloc.c | 6 ++---- sched/semaphore/sem_timedwait.c | 6 +++++- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/bch/bchlib_read.c b/drivers/bch/bchlib_read.c index 5257e6f2bb..786f603c8f 100644 --- a/drivers/bch/bchlib_read.c +++ b/drivers/bch/bchlib_read.c @@ -132,7 +132,6 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t le /* Adjust pointers and counts */ - sectoffset = 0; sector++; if (sector >= bch->nsectors) @@ -167,7 +166,6 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t le /* Adjust pointers and counts */ - sectoffset = 0; sector += nsectors; nbytes = nsectors * bch->sectsize; diff --git a/drivers/bch/bchlib_write.c b/drivers/bch/bchlib_write.c index 21fce2cd03..d4563e437a 100644 --- a/drivers/bch/bchlib_write.c +++ b/drivers/bch/bchlib_write.c @@ -132,7 +132,6 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, si /* Adjust pointers and counts */ - sectoffset = 0; sector++; if (sector >= bch->nsectors) @@ -169,7 +168,6 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, si /* Adjust pointers and counts */ - sectoffset = 0; sector += nsectors; nbytes = nsectors * bch->sectsize; diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index ea75da6d7f..26fc0b1845 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -94,7 +94,13 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) /* Make sure that writing to this stream is allowed */ - if (!stream || (stream->fs_oflags & O_WROK) == 0) + if (stream == NULL) + { + set_errno(EBADF); + return ret; + } + + if ((stream->fs_oflags & O_WROK) == 0) { set_errno(EBADF); goto errout; diff --git a/libc/stdio/lib_vasprintf.c b/libc/stdio/lib_vasprintf.c index 5f0649a174..aa17757541 100644 --- a/libc/stdio/lib_vasprintf.c +++ b/libc/stdio/lib_vasprintf.c @@ -112,7 +112,7 @@ * ****************************************************************************/ -int vasprintf(FAR char **ptr, const char *fmt, va_list ap) +int vasprintf(FAR char **ptr, FAR const char *fmt, va_list ap) { struct lib_outstream_s nulloutstream; struct lib_memoutstream_s memoutstream; @@ -130,12 +130,12 @@ int vasprintf(FAR char **ptr, const char *fmt, va_list ap) va_copy(ap2, ap); #endif -/* First, use a nullstream to get the size of the buffer. The number + /* First, use a nullstream to get the size of the buffer. The number * of bytes returned may or may not include the null terminator. */ lib_nulloutstream(&nulloutstream); - nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap1); + (void)lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap1); /* Then allocate a buffer to hold that number of characters, adding one * for the null terminator. diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index 5778975f50..ef592b7cf4 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -258,10 +258,6 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Return the previous free node to the nodelist (with the new size) */ mm_addfreechunk(heap, prev); - - /* Now we want to return newnode */ - - oldnode = newnode; } else { @@ -272,6 +268,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT); } + /* Now we want to return newnode */ + oldnode = newnode; oldsize = newnode->size; diff --git a/sched/semaphore/sem_timedwait.c b/sched/semaphore/sem_timedwait.c index 503aed2322..106a8bc404 100644 --- a/sched/semaphore/sem_timedwait.c +++ b/sched/semaphore/sem_timedwait.c @@ -179,7 +179,6 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) /* Start the watchdog */ - errcode = OK; (void)wd_start(rtcb->waitdog, ticks, (wdentry_t)sem_timeout, 1, getpid()); /* Now perform the blocking wait */ @@ -196,6 +195,11 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) wd_cancel(rtcb->waitdog); + if (errcode != OK) + { + goto errout_with_irqdisabled; + } + /* We can now restore interrupts and delete the watchdog */ /* Success exits */ -- GitLab From ce27334f23e8d6f104f144a4d4278836a5688351 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Sep 2015 14:32:07 -0600 Subject: [PATCH 148/858] Refresh sub-modules --- arch | 2 +- configs | 2 +- drivers/bch/bchlib_read.c | 1 - drivers/bch/bchlib_write.c | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 1db4677359..957515ba01 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1db4677359dae966c12a0f3830da14005d887a58 +Subproject commit 957515ba013f3ced49c7a78104cc9e9aca793e65 diff --git a/configs b/configs index 7e082490eb..bed0650636 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7e082490eb9da35d7635d66a2282383413357d01 +Subproject commit bed0650636147481bb7513901c6f490f29e874b4 diff --git a/drivers/bch/bchlib_read.c b/drivers/bch/bchlib_read.c index 786f603c8f..93210fcaeb 100644 --- a/drivers/bch/bchlib_read.c +++ b/drivers/bch/bchlib_read.c @@ -167,7 +167,6 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t le /* Adjust pointers and counts */ sector += nsectors; - nbytes = nsectors * bch->sectsize; bytesread += nbytes; diff --git a/drivers/bch/bchlib_write.c b/drivers/bch/bchlib_write.c index d4563e437a..07d77ce8a7 100644 --- a/drivers/bch/bchlib_write.c +++ b/drivers/bch/bchlib_write.c @@ -169,7 +169,6 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, si /* Adjust pointers and counts */ sector += nsectors; - nbytes = nsectors * bch->sectsize; byteswritten += nbytes; -- GitLab From 24b0a567960bed5f067f49d89198bfa2627e8bda Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Sep 2015 14:56:18 -0600 Subject: [PATCH 149/858] Refresh submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 957515ba01..71a47cf566 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 957515ba013f3ced49c7a78104cc9e9aca793e65 +Subproject commit 71a47cf566272470da5eb2f90caba3c7f04ac680 diff --git a/configs b/configs index bed0650636..b7d85ef0b4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bed0650636147481bb7513901c6f490f29e874b4 +Subproject commit b7d85ef0b42255261ef209e52e503c9302376a89 -- GitLab From 5e5050179027e02e02dae73af1689619382d6545 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Sep 2015 11:36:28 -0600 Subject: [PATCH 150/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 71a47cf566..a46ffe3c4b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 71a47cf566272470da5eb2f90caba3c7f04ac680 +Subproject commit a46ffe3c4bb631117ad9f5efa8ef77a93172e976 -- GitLab From c4cf5be231c65ec12c33d646397d13569e852fa1 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 13 Sep 2015 15:56:48 -0600 Subject: [PATCH 151/858] Add support to Maxim MAX31855 Thermocouple-to-Digital --- arch | 2 +- configs | 2 +- drivers/sensors/Kconfig | 7 + drivers/sensors/Make.defs | 4 + drivers/sensors/max31855.c | 299 +++++++++++++++++++++++++++++++ include/nuttx/sensors/max31855.h | 98 ++++++++++ include/nuttx/spi/spi.h | 1 + 7 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 drivers/sensors/max31855.c create mode 100644 include/nuttx/sensors/max31855.h diff --git a/arch b/arch index a46ffe3c4b..b185e7bda9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a46ffe3c4bb631117ad9f5efa8ef77a93172e976 +Subproject commit b185e7bda960fe11a2f8f8c6766e6fabb23ff41a diff --git a/configs b/configs index b7d85ef0b4..21767e867c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b7d85ef0b42255261ef209e52e503c9302376a89 +Subproject commit 21767e867c11ee5de08be734f4f8dafb90b82243 diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 4afdae7c85..510696bce7 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -92,6 +92,13 @@ config ADXL345_REGDEBUG endif # SENSORS_ADXL345 +config MAX31855 + bool "Maxim MAX31855 Driver" + default n + select SPI + ---help--- + Enables support for the MAX31855 driver + config I2C_LM75 bool default y if LM75 diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 3625e10e62..9a00862dfa 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -86,6 +86,10 @@ ifeq ($(CONFIG_ADXL345_SPI),y) CSRCS += adxl345_spi.c endif +ifeq ($(CONFIG_MAX31855),y) + CSRCS += max31855.c +endif + ifeq ($(CONFIG_MPL115A),y) CSRCS += mpl115a.c endif diff --git a/drivers/sensors/max31855.c b/drivers/sensors/max31855.c new file mode 100644 index 0000000000..e7aaa82c02 --- /dev/null +++ b/drivers/sensors/max31855.c @@ -0,0 +1,299 @@ +/**************************************************************************** + * drivers/sensors/max31855.c + * Character driver for the Maxim MAX31855 Thermocouple-to-Digital Converter + * + * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* NOTE: Some Maxim MAX31855 chips have an issue it report value 25% lower + * of real temperature, for more info read this thread: + * http://www.eevblog.com/forum/projects/max31855-temperature-error/ +*/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_SPI) && defined(CONFIG_MAX31855) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private + ****************************************************************************/ + +#define MAX31855_FAULT (1 << 16) +#define MAX31855_SHORT_VCC (1 << 2) +#define MAX31855_SHORT_GND (1 << 1) +#define MAX31855_OPEN_CIRCUIT (1 << 0) +#define MAX31855_TEMP_COUPLE 0xFFFFC000 +#define MAX31855_TEMP_JUNCTION 0xFFF0 + +struct max31855_dev_s +{ + FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ + int16_t temp; +}; + + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static int max31855_open(FAR struct file *filep); +static int max31855_close(FAR struct file *filep); +static ssize_t max31855_read(FAR struct file *, FAR char *, size_t); +static ssize_t max31855_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_max31855fops = +{ + max31855_open, + max31855_close, + max31855_read, + max31855_write, + NULL, + NULL +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Name: max31855_open + * + * Description: + * This function is called whenever the MAX31855 device is opened. + * + ****************************************************************************/ + +static int max31855_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max31855_close + * + * Description: + * This routine is called when the MAX31855 device is closed. + * + ****************************************************************************/ + +static int max31855_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max31855_read + ****************************************************************************/ + +static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct max31855_dev_s *priv = inode->i_private; + FAR uint16_t *temp = (FAR uint16_t *) buffer; + int ret = 2; + int32_t regmsb, regval; + + /* Check for issues */ + + if (!buffer) + { + sndbg("Buffer is null\n"); + return -EINVAL; + } + + if (buflen != 2) + { + sndbg("You can't read something other than 16 bits (2 bytes)\n"); + return -EINVAL; + } + + /* Enable MAX31855's chip select */ + + SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, true); + + /* Read temperature */ + + SPI_RECVBLOCK(priv->spi, ®msb, 4); + + /* Disable MAX31855's chip select */ + + SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, false); + + regval = (regmsb & 0xFF000000) >> 24; + regval |= (regmsb & 0xFF0000) >> 8; + regval |= (regmsb & 0xFF00) << 8; + regval |= (regmsb & 0xFF) << 24; + + sndbg("Read from MAX31855 = 0x%08X\n", regval); + + /* If negative, fix signal bits */ + + if (regval & 0x80000000) + { + temp = 0xFFFFC000 | (regval >> 18); + } + else + { + temp = (regval >> 18); + } + + /* Detect any fault */ + + if (regval & MAX31855_FAULT) + { + sndbg("Error: A fault was detected by MAX31855:\n"); + + if (regval & MAX31855_SHORT_VCC) + { + sndbg("The thermocouple input is shorted to VCC!\n"); + } + + if (regval & MAX31855_SHORT_GND) + { + sndbg("The thermocouple input is shorted to GND!\n"); + } + + if (regval & MAX31855_OPEN_CIRCUIT) + { + sndbg("The thermocouple input is not connected!\n"); + } + + ret = -EINVAL; + } + + /* Return two bytes, the temperature is fixed point Q12.2, then divide by 4 + * in your application in other to get real temperature in Celsius degrees. + */ + + return ret; +} + +/**************************************************************************** + * Name: max31855_write + ****************************************************************************/ + +static ssize_t max31855_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: max31855_register + * + * Description: + * Register the MAX31855 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * i2c - An instance of the I2C interface to use to communicate wit + * MAX31855 addr - The I2C address of the MAX31855. The base I2C address + * of the MAX31855 is 0x48. Bits 0-3 can be controlled to get 8 unique + * addresses from 0x48 through 0x4f. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi) +{ + FAR struct max31855_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(spi != NULL); + + /* Initialize the MAX31855 device structure */ + + priv = (FAR struct max31855_dev_s *)kmm_malloc(sizeof(struct max31855_dev_s)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->spi = spi; + priv->temp = 0; + +#ifdef CONFIG_SPI_OWNBUS + /* Configure SPI for the MAX31855 */ + + SPI_SETMODE(priv->spi, SPIDEV_MODE1); + SPI_SETBITS(priv->spi, 8); + SPI_SETFREQUENCY(priv->spi, MAX31855_SPI_MAXFREQ); +#endif + + /* Register the character driver */ + + ret = register_driver(devpath, &g_max31855fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + return ret; +} +#endif /* CONFIG_SPI && CONFIG_MAX31855 */ diff --git a/include/nuttx/sensors/max31855.h b/include/nuttx/sensors/max31855.h new file mode 100644 index 0000000000..4a4a91b9c4 --- /dev/null +++ b/include/nuttx/sensors/max31855.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * include/nuttx/input/max31855.h + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_MAX31855_H +#define __INCLUDE_NUTTX_SENSORS_MAX31855_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_MAX31855) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#define MAX31855_SPI_MAXFREQ 4000000 + +struct spi_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: max31855_register + * + * Description: + * This function will register the max31855 driver as /dev/tempN + * where N is the minor device number + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * spi - An instance of the SPI interface to use to communicate with + * MAX31855 + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_MAX31855 */ +#endif /* __INCLUDE_NUTTX_SENSORS_MAX31855_H */ diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 4f77e0cb79..ebd4d872e1 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -364,6 +364,7 @@ enum spi_dev_e SPIDEV_EEPROM, /* Select SPI EEPROM device */ SPIDEV_ACCELEROMETER, /* Select SPI Accelerometer device */ SPIDEV_BAROMETER, /* Select SPI Pressure/Barometer device */ + SPIDEV_TEMPERATURE, /* Select SPI Temperature sensor device */ SPIDEV_USER /* Board-specific values start here */ }; -- GitLab From bca2b2c07c506c19f905e4f2a3ea7b631276c073 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 14 Sep 2015 07:08:03 -0600 Subject: [PATCH 152/858] Update ChangeLog --- ChangeLog | 5 ++++- arch | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6aa6051b8..24144297c3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10967,4 +10967,7 @@ from Paul Alexander Patience (2014-09-10). * arch/arm/src/lpc43xx/lpc32_ehci.c and .h: LPC43xx EHCI driver from Ilya Averyanov (2015-09-10). - + * ARMv7-M, all "lazy" interrupt stack logic. Assembly instruction + that fetches the saved value is incorrect; replace with more + traditional push and pop. This is an important fix. Noted by + Stefan Kolb (2015-09-14). diff --git a/arch b/arch index b185e7bda9..e97c72f3ce 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b185e7bda960fe11a2f8f8c6766e6fabb23ff41a +Subproject commit e97c72f3ce29b8a776b7e47c21281b3a7d5a6fbc -- GitLab From 3a8b00f09f94dafae3245f4e5f889bac9e41c194 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Mon, 14 Sep 2015 07:47:21 -0600 Subject: [PATCH 153/858] max31855 driver fix from Alan Carvalho de Assis --- drivers/sensors/max31855.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/sensors/max31855.c b/drivers/sensors/max31855.c index e7aaa82c02..bbc0b341fa 100644 --- a/drivers/sensors/max31855.c +++ b/drivers/sensors/max31855.c @@ -144,10 +144,11 @@ static int max31855_close(FAR struct file *filep) static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct inode *inode = filep->f_inode; - FAR struct max31855_dev_s *priv = inode->i_private; - FAR uint16_t *temp = (FAR uint16_t *) buffer; - int ret = 2; - int32_t regmsb, regval; + FAR struct max31855_dev_s *priv = inode->i_private; + FAR uint16_t *temp = (FAR uint16_t *) buffer; + int ret = 2; + int32_t regmsb; + int32_t regval; /* Check for issues */ @@ -186,11 +187,11 @@ static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t bu if (regval & 0x80000000) { - temp = 0xFFFFC000 | (regval >> 18); + *temp = 0xc000 | (regval >> 18); } else { - temp = (regval >> 18); + *temp = (regval >> 18); } /* Detect any fault */ -- GitLab From fec3d2cf62cf41cde2ad8be8f50c782d0b7e1ddc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 14 Sep 2015 09:06:08 -0600 Subject: [PATCH 154/858] recvfrom: Fixes for compilation with only raw, packet sockets --- net/socket/recvfrom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index d7094d21e0..2ee0b5ffda 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -88,7 +88,7 @@ * Private Types ****************************************************************************/ -#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) || defined(CONFIG_NET_PKT) struct recvfrom_s { FAR struct socket *rf_sock; /* The parent socket structure */ @@ -1207,7 +1207,7 @@ static uint16_t recvfrom_udp_interrupt(FAR struct net_driver_s *dev, * ****************************************************************************/ -#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) || defined(CONFIG_NET_PKT) static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len, FAR struct sockaddr *infrom, FAR socklen_t *fromlen, @@ -1255,7 +1255,7 @@ static void recvfrom_init(FAR struct socket *psock, FAR void *buf, * ****************************************************************************/ -#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) || defined(CONFIG_NET_PKT) static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate) { int save_errno = get_errno(); /* In case something we do changes it */ -- GitLab From b77872d1d9236c16444316d63fd0344a39848a50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Sep 2015 07:38:25 -0600 Subject: [PATCH 155/858] Update ChangeLog --- ChangeLog | 3 +++ arch | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 24144297c3..f9a1d2183b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10971,3 +10971,6 @@ that fetches the saved value is incorrect; replace with more traditional push and pop. This is an important fix. Noted by Stefan Kolb (2015-09-14). + * All ARMV7-M: Force 8-byte stack alignment when calling from assembly + to C to interrupt handling (2015-09-15). + diff --git a/arch b/arch index e97c72f3ce..31ae9c3058 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e97c72f3ce29b8a776b7e47c21281b3a7d5a6fbc +Subproject commit 31ae9c30586e9d5e166964ae89bfe7156e38cf6d -- GitLab From 983128e16a06572c271e221bea003e0aad67eead Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Thu, 17 Sep 2015 07:41:33 -0600 Subject: [PATCH 156/858] sscanf: Formats a, A, e, E, g, and G should be treated the same as f and F --- configs | 2 +- libc/stdio/lib_sscanf.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/configs b/configs index 21767e867c..beb85fb360 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 21767e867c11ee5de08be734f4f8dafb90b82243 +Subproject commit beb85fb3609aa8fccd9bd5f7e96e28d7d5a86763 diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c index c9375d35d6..24b36998e1 100644 --- a/libc/stdio/lib_sscanf.c +++ b/libc/stdio/lib_sscanf.c @@ -513,9 +513,11 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) } } - /* Process %f: Floating point conversion */ + /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point + * conversions + */ - else if (*fmt == 'f' || *fmt == 'F') + else if (strchr("aAfFeEgG", *fmt) != NULL) { #ifdef CONFIG_HAVE_DOUBLE FAR double_t *pd = NULL; -- GitLab From 71d5cff0dd5b1756ae908a0f04f5532f01e00385 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 18 Sep 2015 12:48:05 -0600 Subject: [PATCH 157/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 31ae9c3058..4dc3ba30bd 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 31ae9c30586e9d5e166964ae89bfe7156e38cf6d +Subproject commit 4dc3ba30bd14059b76c578694842bda0eaaf9763 diff --git a/configs b/configs index beb85fb360..dd690705a7 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit beb85fb3609aa8fccd9bd5f7e96e28d7d5a86763 +Subproject commit dd690705a75a433318d8accaa1adfed84db47e30 -- GitLab From 9f465fc502efb9363101727a4eeebfa4cde3ad29 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 19 Sep 2015 11:00:14 -0600 Subject: [PATCH 158/858] Rename battery.[ch] to battery_gauge.[ch] --- configs | 2 +- drivers/power/Kconfig | 6 +- drivers/power/Make.defs | 4 +- drivers/power/{battery.c => battery_gauge.c} | 56 +++++++++--------- .../power/{battery.h => battery_gauge.h} | 57 ++++++++++--------- 5 files changed, 66 insertions(+), 59 deletions(-) rename drivers/power/{battery.c => battery_gauge.c} (83%) rename include/nuttx/power/{battery.h => battery_gauge.h} (80%) diff --git a/configs b/configs index dd690705a7..65514bae3f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dd690705a75a433318d8accaa1adfed84db47e30 +Subproject commit 65514bae3f3be07684ea237ddf69ea4c79b2cd56 diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 46456b60f5..cb7c870565 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -2,8 +2,8 @@ # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # -config BATTERY - bool "Battery support" +config BATTERY_GAUGE + bool "Battery Fuel Gauge support" default n config MAX1704X @@ -11,7 +11,7 @@ config MAX1704X default n select I2C select I2C_MAX1704X - depends on BATTERY + depends on BATTERY_GAUGE ---help--- The MAX17040/MAX17041 are ultra-compact, low-cost, host-side fuel-gauge systems for lithium-ion (Li+) batteries in handheld and portable equipment. diff --git a/drivers/power/Make.defs b/drivers/power/Make.defs index e3452120dd..a28ac6255f 100644 --- a/drivers/power/Make.defs +++ b/drivers/power/Make.defs @@ -53,9 +53,9 @@ endif # Add battery drivers -ifeq ($(CONFIG_BATTERY),y) +ifeq ($(CONFIG_BATTERY_GAUGE),y) -CSRCS += battery.c +CSRCS += battery_gauge.c # Add I2C-based battery drivers diff --git a/drivers/power/battery.c b/drivers/power/battery_gauge.c similarity index 83% rename from drivers/power/battery.c rename to drivers/power/battery_gauge.c index b26fe6c6b9..696b29e632 100644 --- a/drivers/power/battery.c +++ b/drivers/power/battery_gauge.c @@ -1,6 +1,6 @@ /**************************************************************************** - * drivers/power/battery.c - * Upper-half, character driver for batteries. + * drivers/power/battery_gauge_gauge.c + * Upper-half, character driver for battery fuel gauge. * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -46,7 +46,7 @@ #include #include -#include +#include /* This driver requires: * @@ -69,11 +69,13 @@ /* Character driver methods */ -static int bat_open(FAR struct file *filep); -static int bat_close(FAR struct file *filep); -static ssize_t bat_read(FAR struct file *, FAR char *, size_t nbytes); -static ssize_t bat_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int bat_ioctl(FAR struct file *filep,int cmd,unsigned long arg); +static int bat_gauge_open(FAR struct file *filep); +static int bat_gauge_close(FAR struct file *filep); +static ssize_t bat_gauge_read(FAR struct file *, FAR char *, size_t nbytes); +static ssize_t bat_gauge_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int bat_gauge_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); /**************************************************************************** * Private Data @@ -81,12 +83,12 @@ static int bat_ioctl(FAR struct file *filep,int cmd,unsigned long arg); static const struct file_operations g_batteryops = { - bat_open, - bat_close, - bat_read, - bat_write, + bat_gauge_open, + bat_gauge_close, + bat_gauge_read, + bat_gauge_write, 0, - bat_ioctl + bat_gauge_ioctl #ifndef CONFIG_DISABLE_POLL , 0 #endif @@ -96,36 +98,37 @@ static const struct file_operations g_batteryops = * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: bat_open + * Name: bat_gauge_open * * Description: * This function is called whenever the battery device is opened. * ****************************************************************************/ -static int bat_open(FAR struct file *filep) +static int bat_gauge_open(FAR struct file *filep) { return OK; } /**************************************************************************** - * Name: bat_close + * Name: bat_gauge_close * * Description: * This routine is called when the battery device is closed. * ****************************************************************************/ -static int bat_close(FAR struct file *filep) +static int bat_gauge_close(FAR struct file *filep) { return OK; } /**************************************************************************** - * Name: bat_read + * Name: bat_gauge_read ****************************************************************************/ -static ssize_t bat_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +static ssize_t bat_gauge_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) { /* Return nothing read */ @@ -133,10 +136,10 @@ static ssize_t bat_read(FAR struct file *filep, FAR char *buffer, size_t buflen) } /**************************************************************************** - * Name: bat_write + * Name: bat_gauge_write ****************************************************************************/ -static ssize_t bat_write(FAR struct file *filep, FAR const char *buffer, +static ssize_t bat_gauge_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { /* Return nothing written */ @@ -145,13 +148,13 @@ static ssize_t bat_write(FAR struct file *filep, FAR const char *buffer, } /**************************************************************************** - * Name: bat_ioctl + * Name: bat_gauge_ioctl ****************************************************************************/ -static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +static int bat_gauge_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct inode *inode = filep->f_inode; - FAR struct battery_dev_s *dev = inode->i_private; + FAR struct battery_gauge_dev_s *dev = inode->i_private; int ret; /* Inforce mutually exclusive access to the battery driver */ @@ -222,7 +225,7 @@ static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ****************************************************************************/ /**************************************************************************** - * Name: battery_register + * Name: battery_gauge_register * * Description: * Register a lower half battery driver with the common, upper-half @@ -238,7 +241,8 @@ static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int battery_register(FAR const char *devpath, FAR struct battery_dev_s *dev) +int battery_gauge_register(FAR const char *devpath, + FAR struct battery_gauge_dev_s *dev) { int ret; diff --git a/include/nuttx/power/battery.h b/include/nuttx/power/battery_gauge.h similarity index 80% rename from include/nuttx/power/battery.h rename to include/nuttx/power/battery_gauge.h index 9fa44fe594..83430582c4 100644 --- a/include/nuttx/power/battery.h +++ b/include/nuttx/power/battery_gauge.h @@ -1,6 +1,6 @@ /**************************************************************************** - * include/nuttx/power/battery.h - * NuttX Battery Interfaces + * include/nuttx/power/battery_gauge.h + * NuttX Battery Fuel Gauge Interfaces * * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -34,8 +34,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_POWER_BATTERY_H -#define __INCLUDE_NUTTX_POWER_BATTERY_H +#ifndef __INCLUDE_NUTTX_POWER_BATTERY_GAUGE_H +#define __INCLUDE_NUTTX_POWER_BATTERY_GAUGE_H /**************************************************************************** * Included Files @@ -48,13 +48,13 @@ #include #include -#ifdef CONFIG_BATTERY +#ifdef CONFIG_BATTERY_GAUGE /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ -/* CONFIG_BATTERY - Upper half battery driver support +/* CONFIG_BATTERY_GAUGE - Upper half battery fuel gauge driver support * * Specific, lower-half drivers will have other configuration requirements * such as: @@ -64,15 +64,16 @@ */ /* IOCTL Commands ***********************************************************/ -/* The upper-half battery driver provides a character driver "wrapper" - * around the lower-half battery driver that does all of the real work. +/* The upper-half battery fuel gauge driver provides a character driver + * "wrapper" * around the lower-half battery driver that does all of the + * real work. * Since there is no real data transfer to/or from a battery, all of the * driver interaction is through IOCTIL commands. The IOCTL commands * supported by the upper-half driver simply provide calls into the the * lower half as summarized below: * * BATIOC_STATE - Return the current state of the battery (see - * enum battery_status_e). + * enum battery_gauge_status_e). * Input value: A pointer to type int. * BATIOC_ONLINE - Return 1 if the battery is online; 0 if offline. * Input value: A pointer to type bool. @@ -95,7 +96,7 @@ ****************************************************************************/ /* Battery status */ -enum battery_status_e +enum battery_gauge_status_e { BATTERY_UNKNOWN = 0, /* Battery state is not known */ BATTERY_IDLE, /* Not full, not charging, not discharging */ @@ -106,33 +107,33 @@ enum battery_status_e /* This structure defines the lower half battery interface */ -struct battery_dev_s; -struct battery_operations_s +struct battery_gauge_dev_s; +struct battery_gauge_operations_s { - /* Return the current battery state (see enum battery_status_e) */ + /* Return the current battery state (see enum battery_gauge_status_e) */ - int (*state)(struct battery_dev_s *dev, int *status); + int (*state)(struct battery_gauge_dev_s *dev, int *status); /* Return true if the batter is online */ - int (*online)(struct battery_dev_s *dev, bool *status); + int (*online)(struct battery_gauge_dev_s *dev, bool *status); /* Current battery voltage */ - int (*voltage)(struct battery_dev_s *dev, b16_t *value); + int (*voltage)(struct battery_gauge_dev_s *dev, b16_t *value); /* Battery capacity */ - int (*capacity)(struct battery_dev_s *dev, b16_t *value); + int (*capacity)(struct battery_gauge_dev_s *dev, b16_t *value); }; /* This structure defines the battery driver state structure */ -struct battery_dev_s +struct battery_gauge_dev_s { /* Fields required by the upper-half driver */ - FAR const struct battery_operations_s *ops; /* Battery operations */ + FAR const struct battery_gauge_operations_s *ops; /* Battery operations */ sem_t batsem; /* Enforce mutually exclusive access */ /* Data fields specific to the lower-half driver may follow */ @@ -156,7 +157,7 @@ extern "C" * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: battery_register + * Name: battery_gauge_register * * Description: * Register a lower half battery driver with the common, upper-half @@ -172,18 +173,19 @@ extern "C" * ****************************************************************************/ -int battery_register(FAR const char *devpath, FAR struct battery_dev_s *dev); +int battery_gauge_register(FAR const char *devpath, + FAR struct battery_gauge_dev_s *dev); /**************************************************************************** * Name: max1704x_initialize * * Description: * Initialize the MAX1704x battery driver and return an instance of the - * lower_half interface that may be used with battery_register(); + * lower_half interface that may be used with battery_gauge_register(); * * This driver requires: * - * CONFIG_BATTERY - Upper half battery driver support + * CONFIG_BATTERY_GAUGE - Upper half battery fuel gauge driver support * CONFIG_I2C - I2C support * CONFIG_I2C_MAX1704X - And the driver must be explictly selected. * CONFIG_I2C_MAX17040 or CONFIG_I2C_MAX17041 - The driver must know which @@ -203,8 +205,9 @@ int battery_register(FAR const char *devpath, FAR struct battery_dev_s *dev); #if defined(CONFIG_I2C) && defined(CONFIG_I2C_MAX1704X) struct i2c_dev_s; /* Forward reference */ -FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c - uint8_t addr, uint32_t frequency); +FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c + uint8_t addr, + uint32_t frequency); #endif #undef EXTERN @@ -213,5 +216,5 @@ FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c #endif #endif /* __ASSEMBLY__ */ -#endif /* CONFIG_BATTERY */ -#endif /* __INCLUDE_NUTTX_POWER_BATTERY_H */ +#endif /* CONFIG_BATTERY_GAUGE */ +#endif /* __INCLUDE_NUTTX_POWER_BATTERY_GAUGE_H */ -- GitLab From 3cd7558a5e128714b367f234dc7da6088d656ac2 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 19 Sep 2015 13:06:43 -0600 Subject: [PATCH 159/858] Add basic infrastructure for Battery Charger --- drivers/power/Kconfig | 5 + drivers/power/Make.defs | 4 + drivers/power/battery_charger.c | 275 ++++++++++++++++++++++++++ include/nuttx/power/battery_charger.h | 238 ++++++++++++++++++++++ 4 files changed, 522 insertions(+) create mode 100644 drivers/power/battery_charger.c create mode 100644 include/nuttx/power/battery_charger.h diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index cb7c870565..6e9292a568 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -2,6 +2,11 @@ # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # + +config BATTERY_CHARGER + bool "Battery Charger support" + default n + config BATTERY_GAUGE bool "Battery Fuel Gauge support" default n diff --git a/drivers/power/Make.defs b/drivers/power/Make.defs index a28ac6255f..0fc143d83a 100644 --- a/drivers/power/Make.defs +++ b/drivers/power/Make.defs @@ -53,6 +53,10 @@ endif # Add battery drivers +ifeq ($(CONFIG_BATTERY_CHARGER),y) +CSRCS += battery_charger.c +endif + ifeq ($(CONFIG_BATTERY_GAUGE),y) CSRCS += battery_gauge.c diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c new file mode 100644 index 0000000000..1e12f7dd2c --- /dev/null +++ b/drivers/power/battery_charger.c @@ -0,0 +1,275 @@ +/**************************************************************************** + * drivers/power/battery_charger.c + * Upper-half, character driver for batteries charger. + * + * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +/* This driver requires: + * + * CONFIG_BATTERY_CHARGER - Upper half battery driver support + */ + +#if defined(CONFIG_BATTERY_CHARGER) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static int bat_charger_open(FAR struct file *filep); +static int bat_charger_close(FAR struct file *filep); +static ssize_t bat_charger_read(FAR struct file *, FAR char *, + size_t nbytes); +static ssize_t bat_charger_write(FAR struct file *filep, + FAR const char *buffer, size_t buflen); +static int bat_charger_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_batteryops = +{ + bat_charger_open, + bat_charger_close, + bat_charger_read, + bat_charger_write, + 0, + bat_charger_ioctl +#ifndef CONFIG_DISABLE_POLL + , 0 +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Name: bat_charger_open + * + * Description: + * This function is called whenever the battery device is opened. + * + ****************************************************************************/ + +static int bat_charger_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: bat_charger_close + * + * Description: + * This routine is called when the battery device is closed. + * + ****************************************************************************/ + +static int bat_charger_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: bat_charger_read + ****************************************************************************/ + +static ssize_t bat_charger_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + /* Return nothing read */ + + return 0; +} + +/**************************************************************************** + * Name: bat_charger_write + ****************************************************************************/ + +static ssize_t bat_charger_write(FAR struct file *filep, + FAR const char *buffer, size_t buflen) +{ + /* Return nothing written */ + + return 0; +} + +/**************************************************************************** + * Name: bat_charger_ioctl + ****************************************************************************/ + +static int bat_charger_ioctl(FAR struct file *filep, int cmd, + unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct battery_charger_dev_s *dev = inode->i_private; + int ret; + + /* Inforce mutually exclusive access to the battery driver */ + + ret = sem_wait(&dev->batsem); + if (ret < 0) + { + return -errno; /* Probably EINTR */ + } + + /* Procss the IOCTL command */ + + ret = -EINVAL; /* Assume a bad argument */ + switch (cmd) + { + case BATIOC_STATE: + { + FAR int *ptr = (FAR int *)((uintptr_t)arg); + if (ptr) + { + ret = dev->ops->state(dev, ptr); + } + } + break; + + case BATIOC_HEALTH: + { + FAR int *ptr = (FAR int *)((uintptr_t)arg); + if (ptr) + { + ret = dev->ops->health(dev, ptr); + } + } + break; + + case BATIOC_ONLINE: + { + FAR bool *ptr = (FAR bool *)((uintptr_t)arg); + if (ptr) + { + ret = dev->ops->online(dev, ptr); + } + } + break; + + case BATIOC_VOLTAGE: + { + int volts; + FAR int *voltsp = (FAR int *)((uintptr_t)arg); + volts = *voltsp; + if (ptr) + { + ret = dev->ops->voltage(dev, volts); + } + } + break; + + case BATIOC_CURRENT: + { + int amps; + FAR int *ampsp = (FAR int *)((uintptr_t)arg); + amps = *ampsp; + if (ptr) + { + ret = dev->ops->current(dev, amps); + } + } + break; + + default: + dbg("Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + break; + } + + sem_post(&dev->batsem); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: battery_charger_register + * + * Description: + * Register a lower half battery driver with the common, upper-half + * battery driver. + * + * Input parameters: + * devpath - The location in the pseudo-filesystem to create the driver. + * Recommended standard is "/dev/bat0", "/dev/bat1", etc. + * dev - An instance of the battery state structure . + * + * Returned value: + * Zero on success or a negated errno value on failure. + * + ****************************************************************************/ + +int battery_charger_register(FAR const char *devpath, + FAR struct battery_charger_dev_s *dev) +{ + int ret; + + /* Register the character driver */ + + ret = register_driver(devpath, &g_batteryops, 0555, dev); + if (ret < 0) + { + dbg("Failed to register driver: %d\n", ret); + } + + return ret; +} +#endif /* CONFIG_BATTERY_CHARGER */ diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h new file mode 100644 index 0000000000..fadb331b21 --- /dev/null +++ b/include/nuttx/power/battery_charger.h @@ -0,0 +1,238 @@ +/**************************************************************************** + * include/nuttx/power/battery_charger.h + * NuttX Battery Charger Interfaces + * + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_POWER_BATTERY_CHARGER_H +#define __INCLUDE_NUTTX_POWER_BATTERY_CHARGER_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include + +#ifdef CONFIG_BATTERY_CHARGER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_BATTERY_CHARGER - Upper half battery charger driver support + * + * Specific, lower-half drivers will have other configuration requirements + * such as: + * + * CONFIG_I2C - I2C support *may* be needed + * CONFIG_I2C_BQ2425X - The BQ2425x driver must be explicitly selected. + */ + +/* IOCTL Commands ***********************************************************/ +/* The upper-half battery charger driver provides a character driver "wrapper" + * around the lower-half battery charger driver that does all of the real work. + * Since there is no real data transfer to/or from a battery, all of the + * driver interaction is through IOCTL commands. The IOCTL commands + * supported by the upper-half driver simply provide calls into the the + * lower half as summarized below: + * + * BATIOC_STATE - Return the current state of the battery (see + * enum battery_charger_status_e). + * Input value: A pointer to type int. + * BATIOC_HEALTH - Return the current health of the battery (see + * enum battery_charger_health_e). + * Input value: A pointer to type int. + * BATIOC_ONLINE - Return 1 if the battery is online; 0 if offline. + * Input value: A pointer to type bool. + * BATIOC_VOLTAGE - Define the wished charger voltage to charge the battery. + * Input value: An int defining the voltage value. + */ + +#define BATIOC_STATE _BATIOC(0x0001) +#define BATIOC_HEALTH _BATIOC(0x0002) +#define BATIOC_ONLINE _BATIOC(0x0003) +#define BATIOC_VOLTAGE _BATIOC(0x0004) +#define BATIOC_CURRENT _BATIOC(0x0005) + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* Battery status */ + +enum battery_charger_status_e +{ + BATTERY_UNKNOWN = 0, /* Battery state is not known */ + BATTERY_IDLE, /* Not full, not charging, not discharging */ + BATTERY_FULL, /* Full, not discharging */ + BATTERY_CHARGING, /* Not full, charging */ + BATTERY_DISCHARGING /* Probably not full, discharging */ +}; + +/* Battery Health status */ + +enum battery_charger_health_e +{ + BATTERY_HEALTH_UNKNOWN = 0, /* Battery health state is not known */ + BATTERY_HEALTH_GOOD, /* Battery is in good condiction */ + BATTERY_HEALTH_DEAD, /* Battery is dead, nothing we can do */ + BATTERY_HEALTH_OVERHEAT, /* Battery is over recommended temperature */ + BATTERY_HEALTH_OVERVOLTAGE, /* Battery voltage is over recommended level */ + BATTERY_HEALTH_UNSPEC_FAIL, /* Battery charger reported an unspected failure */ + BATTERY_HEALTH_COLD, /* Battery is under recommended temperature */ + BATTERY_HEALTH_WD_TMR_EXP, /* Battery WatchDog Timer Expired */ + BATTERY_HEALTH_SAFE_TMR_EXP /* Battery Safety Timer Expired */ +}; + + /* This structure defines the lower half battery interface */ + +struct battery_charger_dev_s; +struct battery_charger_operations_s +{ + /* Return the current battery state (see enum battery_charger_status_e) */ + + int (*state)(struct battery_charger_dev_s *dev, int *status); + + /* Return the current battery health (see enum battery_charger_health_e) */ + + int (*health)(struct battery_charger_dev_s *dev, int *health); + + /* Return true if the batter is online */ + + int (*online)(struct battery_charger_dev_s *dev, bool *status); + + /* Set the wished battery voltage for charging */ + + int (*voltage)(struct battery_charger_dev_s *dev, int value); + + /* Set the wished current rate used for charging */ + + int (*current)(struct battery_charger_dev_s *dev, int value); +}; + +/* This structure defines the battery driver state structure */ + +struct battery_charger_dev_s +{ + /* Fields required by the upper-half driver */ + + FAR const struct battery_charger_operations_s *ops; /* Battery operations */ + sem_t batsem; /* Enforce mutually exclusive access */ + + /* Data fields specific to the lower-half driver may follow */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ +/**************************************************************************** + * Name: battery_charger_register + * + * Description: + * Register a lower half battery driver with the common, upper-half + * battery driver. + * + * Input parameters: + * devpath - The location in the pseudo-filesystem to create the driver. + * Recommended standard is "/dev/bat0", "/dev/bat1", etc. + * dev - An instance of the battery state structure . + * + * Returned value: + * Zero on success or a negated errno value on failure. + * + ****************************************************************************/ + +int battery_charger_register(FAR const char *devpath, + FAR struct battery_charger_dev_s *dev); + +/**************************************************************************** + * Name: bq2425x_initialize + * + * Description: + * Initialize the BQ2425X battery driver and return an instance of the + * lower_half interface that may be used with battery_charger_register(); + * + * This driver requires: + * + * CONFIG_BATTERY_CHARGER - Upper half battery fuel gauge driver support + * CONFIG_I2C - I2C support + * CONFIG_I2C_BQ2425X - And the driver must be explictly selected. + * CONFIG_I2C_BQ24250 or CONFIG_I2C_BQ24251 - The driver must know which + * chip is on the board in order to scale the voltage correctly. + * + * Input Parameters: + * i2c - An instance of the I2C interface to use to communicate with + * the BQ2425X + * addr - The I2C address of the BQ2425X (Better be 0x6A). + * frequency - The I2C frequency + * + * Returned Value: + * A pointer to the initializeed battery driver instance. A NULL pointer + * is returned on a failure to initialize the BQ2425X lower half. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_BQ2425X) +struct i2c_dev_s; /* Forward reference */ + +FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c + uint8_t addr, + uint32_t frequency); +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* CONFIG_BATTERY_CHARGER */ +#endif /* __INCLUDE_NUTTX_POWER_BATTERY_H */ -- GitLab From 895ad29b0d2f1a1863df316aa94f6d77c2fe23ee Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 19 Sep 2015 13:58:49 -0600 Subject: [PATCH 160/858] Fix IOCTL definition to avoid duplication and mess --- drivers/power/battery_charger.c | 1 + drivers/power/battery_gauge.c | 1 + drivers/power/max1704x.c | 35 ++++++++-------- include/nuttx/power/battery_charger.h | 6 --- include/nuttx/power/battery_gauge.h | 5 --- include/nuttx/power/battery_ioctl.h | 58 +++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 include/nuttx/power/battery_ioctl.h diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c index 1e12f7dd2c..20f84bb03d 100644 --- a/drivers/power/battery_charger.c +++ b/drivers/power/battery_charger.c @@ -47,6 +47,7 @@ #include #include +#include /* This driver requires: * diff --git a/drivers/power/battery_gauge.c b/drivers/power/battery_gauge.c index 696b29e632..032b6b1158 100644 --- a/drivers/power/battery_gauge.c +++ b/drivers/power/battery_gauge.c @@ -47,6 +47,7 @@ #include #include +#include /* This driver requires: * diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 2df676fa61..571fe63c3e 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -1,6 +1,6 @@ /**************************************************************************** * drivers/power/max1704x.c - * Lower half driver for MAX1704x battery charger + * Lower half driver for MAX1704x battery fuel gauge * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -55,11 +55,11 @@ #include #include -#include +#include /* This driver requires: * - * CONFIG_BATTERY - Upper half battery driver support + * CONFIG_BATTERY - Upper half battery gauge driver support * CONFIG_I2C - I2C support * CONFIG_I2C_MAX1704X - And the driver must be explictly selected. */ @@ -177,8 +177,8 @@ struct max1704x_dev_s { /* The common part of the battery driver visible to the upper-half driver */ - FAR const struct battery_operations_s *ops; /* Battery operations */ - sem_t batsem; /* Enforce mutually exclusive access */ + FAR const struct battery_gauge_operations_s *ops; /* Battery operations */ + sem_t batsem; /* Enforce mutually exclusive access */ /* Data fields specific to the lower half MAX1704x driver follow */ @@ -208,16 +208,16 @@ static inline int max1704x_reset(FAR struct max1704x_dev_s *priv); /* Battery driver lower half methods */ -static int max1704x_state(struct battery_dev_s *dev, int *status); -static int max1704x_online(struct battery_dev_s *dev, bool *status); -static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value); -static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value); +static int max1704x_state(struct battery_gauge_dev_s *dev, int *status); +static int max1704x_online(struct battery_gauge_dev_s *dev, bool *status); +static int max1704x_voltage(struct battery_gauge_dev_s *dev, b16_t *value); +static int max1704x_capacity(struct battery_gauge_dev_s *dev, b16_t *value); /**************************************************************************** * Private Data ****************************************************************************/ -static const struct battery_operations_s g_max1704xops = +static const struct battery_gauge_operations_s g_max1704xops = { max1704x_state, max1704x_online, @@ -410,7 +410,7 @@ static inline int max1704x_reset(FAR struct max1704x_dev_s *priv) * ****************************************************************************/ -static int max1704x_state(struct battery_dev_s *dev, int *status) +static int max1704x_state(struct battery_gauge_dev_s *dev, int *status) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; b16_t soc = 0; @@ -454,7 +454,7 @@ static int max1704x_state(struct battery_dev_s *dev, int *status) * ****************************************************************************/ -static int max1704x_online(struct battery_dev_s *dev, bool *status) +static int max1704x_online(struct battery_gauge_dev_s *dev, bool *status) { /* There is no concept of online/offline in this driver */ @@ -470,7 +470,7 @@ static int max1704x_online(struct battery_dev_s *dev, bool *status) * ****************************************************************************/ -static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value) +static int max1704x_voltage(struct battery_gauge_dev_s *dev, b16_t *value) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; return max1704x_getvcell(priv, value); @@ -484,7 +484,7 @@ static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value) * ****************************************************************************/ -static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value) +static int max1704x_capacity(struct battery_gauge_dev_s *dev, b16_t *value) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; return max1704x_getsoc(priv, value); @@ -520,8 +520,9 @@ static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value) * ****************************************************************************/ -FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, - uint8_t addr, uint32_t frequency) +FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, + uint8_t addr, + uint32_t frequency) { FAR struct max1704x_dev_s *priv; #if 0 @@ -557,7 +558,7 @@ FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, } #endif } - return (FAR struct battery_dev_s *)priv; + return (FAR struct battery_gauge_dev_s *)priv; } #endif /* CONFIG_BATTERY && CONFIG_I2C && CONFIG_I2C_MAX1704X */ diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index fadb331b21..99be21f88a 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -83,12 +83,6 @@ * Input value: An int defining the voltage value. */ -#define BATIOC_STATE _BATIOC(0x0001) -#define BATIOC_HEALTH _BATIOC(0x0002) -#define BATIOC_ONLINE _BATIOC(0x0003) -#define BATIOC_VOLTAGE _BATIOC(0x0004) -#define BATIOC_CURRENT _BATIOC(0x0005) - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/nuttx/power/battery_gauge.h b/include/nuttx/power/battery_gauge.h index 83430582c4..d087f2213c 100644 --- a/include/nuttx/power/battery_gauge.h +++ b/include/nuttx/power/battery_gauge.h @@ -86,11 +86,6 @@ * Input value: A pointer to type b16_t. */ -#define BATIOC_STATE _BATIOC(0x0001) -#define BATIOC_ONLINE _BATIOC(0x0002) -#define BATIOC_VOLTAGE _BATIOC(0x0003) -#define BATIOC_CAPACITY _BATIOC(0x0004) - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/nuttx/power/battery_ioctl.h b/include/nuttx/power/battery_ioctl.h new file mode 100644 index 0000000000..4bbd46e21b --- /dev/null +++ b/include/nuttx/power/battery_ioctl.h @@ -0,0 +1,58 @@ +/**************************************************************************** + * include/nuttx/power/battery_ioctl.h + * NuttX Battery IOCTLs definition + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H +#define __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BATIOC_STATE _BATIOC(0x0001) +#define BATIOC_HEALTH _BATIOC(0x0002) +#define BATIOC_ONLINE _BATIOC(0x0003) +#define BATIOC_VOLTAGE _BATIOC(0x0004) +#define BATIOC_CURRENT _BATIOC(0x0005) +#define BATIOC_CAPACITY _BATIOC(0x0006) + +#endif /* __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H */ -- GitLab From 2e70cdec95d4e7922eb80c510341baf868aa51ee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 19 Sep 2015 14:05:23 -0600 Subject: [PATCH 161/858] Update ChangeLog --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index f9a1d2183b..ee40a63f61 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10973,4 +10973,10 @@ Stefan Kolb (2015-09-14). * All ARMV7-M: Force 8-byte stack alignment when calling from assembly to C to interrupt handling (2015-09-15). + * drivers/power/battery_gauge.c and include/nuttx/power/battery_gauge.h: + battery.c/h renamed to batter_gauge.c/.h since it really only + implements a battery fuel gauge. From Alan Carvalho de Assis (2015-09-19). + * drivers/power/battery_charter.c and include/nuttx/power/batter_charger.h: + Add a new frame to support a batter charger interface. From Alan + Carvalho de Assis (2015-09-19). -- GitLab From d4fc91d6f63aa1eddb888d9be0776101ad1d777c Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 20 Sep 2015 09:32:06 -0600 Subject: [PATCH 162/858] Add Battery Fault and Battery Disconnected status --- include/nuttx/power/battery_charger.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index 99be21f88a..b67a0125aa 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -91,6 +91,7 @@ enum battery_charger_status_e { BATTERY_UNKNOWN = 0, /* Battery state is not known */ + BATTERY_FAULT, /* Charger reported a fault, get health for more info */ BATTERY_IDLE, /* Not full, not charging, not discharging */ BATTERY_FULL, /* Full, not discharging */ BATTERY_CHARGING, /* Not full, charging */ @@ -109,7 +110,8 @@ enum battery_charger_health_e BATTERY_HEALTH_UNSPEC_FAIL, /* Battery charger reported an unspected failure */ BATTERY_HEALTH_COLD, /* Battery is under recommended temperature */ BATTERY_HEALTH_WD_TMR_EXP, /* Battery WatchDog Timer Expired */ - BATTERY_HEALTH_SAFE_TMR_EXP /* Battery Safety Timer Expired */ + BATTERY_HEALTH_SAFE_TMR_EXP, /* Battery Safety Timer Expired */ + BATTERY_HEALTH_DISCONNECTED /* Battery is not connected */ }; /* This structure defines the lower half battery interface */ -- GitLab From c52e3e017bf59afa256ec1e2385a30dc4fd0546f Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 20 Sep 2015 09:47:00 -0600 Subject: [PATCH 163/858] Battery Charger: Add BQ24250 driver --- ChangeLog | 2 + drivers/power/Kconfig | 15 +- drivers/power/Make.defs | 31 +- drivers/power/battery_charger.c | 8 +- drivers/power/bq2425x.c | 775 ++++++++++++++++++++++++++ drivers/power/bq2425x.h | 272 +++++++++ include/nuttx/power/battery_charger.h | 2 +- 7 files changed, 1095 insertions(+), 10 deletions(-) create mode 100644 drivers/power/bq2425x.c create mode 100644 drivers/power/bq2425x.h diff --git a/ChangeLog b/ChangeLog index ee40a63f61..1102051c4b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10979,4 +10979,6 @@ * drivers/power/battery_charter.c and include/nuttx/power/batter_charger.h: Add a new frame to support a batter charger interface. From Alan Carvalho de Assis (2015-09-19). + * drivers/power/bq2425x.c and .h: Battery Charger: Add BQ24250 driver. + From Alan Carvalho de Assis (2015-09-20). diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 6e9292a568..4084a5284b 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -7,12 +7,21 @@ config BATTERY_CHARGER bool "Battery Charger support" default n +config BQ2425X + bool "BQ2425X Battery charger support" + default n + select I2C + select I2C_BQ2425X + depends on BATTERY_CHARGER + ---help--- + The BQ24250/BQ24251 are battery charger for lithium-ion batteries. + config BATTERY_GAUGE bool "Battery Fuel Gauge support" default n config MAX1704X - bool "MAX1704X Battery charger support" + bool "MAX1704X Battery fuel gauge support" default n select I2C select I2C_MAX1704X @@ -23,6 +32,10 @@ config MAX1704X The MAX17040 is configured to operate with a single lithium cell and the MAX17041 is configured for a dual-cell 2S pack. +config I2C_BQ2425X + bool + default y if BQ2425X + config I2C_MAX1704X bool default y if MAX1704X diff --git a/drivers/power/Make.defs b/drivers/power/Make.defs index 0fc143d83a..40ab591dff 100644 --- a/drivers/power/Make.defs +++ b/drivers/power/Make.defs @@ -41,7 +41,8 @@ POWER_CFLAGS = ifeq ($(CONFIG_PM),y) -CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c pm_register.c pm_update.c +CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c +CSRCS += pm_register.c pm_update.c # Include power management in the build @@ -51,21 +52,43 @@ POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$ endif -# Add battery drivers +# Add battery charger drivers ifeq ($(CONFIG_BATTERY_CHARGER),y) + CSRCS += battery_charger.c + +# Add I2C-based battery charger drivers + +ifeq ($(CONFIG_I2C),y) + +# Add the BQ2425x I2C-based battery charger driver + +ifeq ($(CONFIG_I2C_BQ2425X),y) +CSRCS += bq2425x.c +endif + endif +# Include battery suport in the build + +POWER_DEPPATH := --dep-path power +POWER_VPATH := :power +POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power} + +endif + +# Add battery gauge drivers + ifeq ($(CONFIG_BATTERY_GAUGE),y) CSRCS += battery_gauge.c -# Add I2C-based battery drivers +# Add I2C-based battery gauge drivers ifeq ($(CONFIG_I2C),y) -# Add the MAX1704x I2C-based battery driver +# Add the MAX1704x I2C-based battery guage driver ifeq ($(CONFIG_I2C_MAX1704X),y) CSRCS += max1704x.c diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c index 20f84bb03d..fd6bcc8f6c 100644 --- a/drivers/power/battery_charger.c +++ b/drivers/power/battery_charger.c @@ -207,9 +207,9 @@ static int bat_charger_ioctl(FAR struct file *filep, int cmd, { int volts; FAR int *voltsp = (FAR int *)((uintptr_t)arg); - volts = *voltsp; - if (ptr) + if (voltsp) { + volts = *voltsp; ret = dev->ops->voltage(dev, volts); } } @@ -219,9 +219,9 @@ static int bat_charger_ioctl(FAR struct file *filep, int cmd, { int amps; FAR int *ampsp = (FAR int *)((uintptr_t)arg); - amps = *ampsp; - if (ptr) + if (ampsp) { + amps = *ampsp; ret = dev->ops->current(dev, amps); } } diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c new file mode 100644 index 0000000000..c4d281c392 --- /dev/null +++ b/drivers/power/bq2425x.c @@ -0,0 +1,775 @@ +/**************************************************************************** + * drivers/power/bq2425x.c + * Lower half driver for BQ2425x battery charger + * + * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* The BQ24250/BQ24251 are Li-Ion Battery Charger with Power-Path Management. + * It can be configured to Input Current Limit up to 2A. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "bq2425x.h" + +/* This driver requires: + * + * CONFIG_BATTERY_CHARGER - Upper half battery driver support + * CONFIG_I2C - I2C support + * CONFIG_I2C_BQ2425X - And the driver must be explictly selected. + */ + +#if defined(CONFIG_BATTERY_CHARGER) && defined(CONFIG_I2C) && \ + defined(CONFIG_I2C_BQ2425X) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Debug ********************************************************************/ + +#ifdef CONFIG_DEBUG_BQ2425X +# define batdbg dbg +#else +# ifdef CONFIG_CPP_HAVE_VARARGS +# define batdbg(x...) +# else +# define batdbg (void) +# endif +#endif + +/**************************************************************************** + * Private + ****************************************************************************/ + +struct bq2425x_dev_s +{ + /* The common part of the battery driver visible to the upper-half driver */ + + FAR const struct battery_charger_operations_s *ops; /* Battery operations */ + sem_t batsem; /* Enforce mutually exclusive access */ + + /* Data fields specific to the lower half BQ2425x driver follow */ + + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + uint32_t frequency; /* I2C frequency */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* I2C support */ + +static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, + FAR uint8_t *regval); +static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, + uint8_t regval); + +static inline int bq2425x_getreport(FAR struct bq2425x_dev_s *priv, + uint8_t *report); +static inline int bq2425x_reset(FAR struct bq2425x_dev_s *priv); +static inline int bq2425x_watchdog(FAR struct bq2425x_dev_s *priv, bool enable); +static inline int bq2425x_setvolt(FAR struct bq2425x_dev_s *priv, int volts); +static inline int bq2425x_setcurr(FAR struct bq2425x_dev_s *priv, int current); + +/* Battery driver lower half methods */ + +static int bq2425x_state(struct battery_charger_dev_s *dev, int *status); +static int bq2425x_health(struct battery_charger_dev_s *dev, int *health); +static int bq2425x_online(struct battery_charger_dev_s *dev, bool *status); +static int bq2425x_voltage(struct battery_charger_dev_s *dev, int value); +static int bq2425x_current(struct battery_charger_dev_s *dev, int value); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct battery_charger_operations_s g_bq2425xops = +{ + bq2425x_state, + bq2425x_health, + bq2425x_online, + bq2425x_voltage, + bq2425x_current +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: bq2425x_getreg8 + * + * Description: + * Read a 8-bit value from a BQ2425x register pair. + * + * START ACK ACK + * REPEATED-START ACK Data0 ACK Data1 NO-ACK STOP + * + ****************************************************************************/ + +static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, + FAR uint8_t *regval) +{ + uint8_t val; + int ret; + + /* Set the I2C address and address size */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + + /* Write the register address */ + + ret = I2C_WRITE(priv->i2c, ®addr, 1); + if (ret < 0) + { + batdbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 8-bits from the register */ + + ret = I2C_READ(priv->i2c, &val, 1); + if (ret < 0) + { + batdbg("I2C_READ failed: %d\n", ret); + return ret; + } + + /* Copy 8-bit value to be returned */ + + *regval = val; + return OK; +} + +/**************************************************************************** + * Name: bq2425x_putreg8 + * + * Description: + * Write a 8-bit value to a BQ2425x register pair. + * + * START ACK ACK Data0 ACK Data1 ACK STOP + * + ****************************************************************************/ + +static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, + uint8_t regval) +{ + uint8_t buffer[2]; + + batdbg("addr: %02x regval: %08x\n", regaddr, regval); + + /* Set up a 3 byte message to send */ + + buffer[0] = regaddr; + buffer[1] = regval; + + /* Set the I2C address and address size */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + + /* Write the register address followed by the data (no RESTART) */ + + return I2C_WRITE(priv->i2c, buffer, 2); +} + +/**************************************************************************** + * Name: bq2425x_getreport + * + * Description: + * Read the BQ2425X Register #1 (status and fault) + * + ****************************************************************************/ + +static inline int bq2425x_getreport(FAR struct bq2425x_dev_s *priv, + uint8_t *report) +{ + uint8_t regval = 0; + int ret; + + ret = bq2425x_getreg8(priv, BQ2425X_REG_1, ®val); + if (ret == OK) + { + *report = regval; + } + + return ret; +} + +/**************************************************************************** + * Name: bq2425x_reset + * + * Description: + * Reset the BQ2425x + * + ****************************************************************************/ + +static inline int bq2425x_reset(FAR struct bq2425x_dev_s *priv) +{ + int ret; + uint8_t regval; + + /* Read current register value */ + + ret = bq2425x_getreg8(priv, BQ2425X_REG_2, ®val); + if (ret < 0) + { + batdbg("Error reading from BQ2425X! Error = %d\n", ret); + return ret; + } + + /* Send reset command */ + + regval |= BQ2425X_RESET; + ret = bq2425x_putreg8(priv, BQ2425X_REG_2, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + /* Wait a little bit to clear registers */ + + usleep(500); + + /* There is a BUG in BQ2425X the RESET bit is always read as 1 */ + + regval &= ~(BQ2425X_RESET); + ret = bq2425x_putreg8(priv, BQ2425X_REG_2, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_watchdog + * + * Description: + * Enable/Disable the BQ2425x watchdog + * + ****************************************************************************/ + +static inline int bq2425x_watchdog(FAR struct bq2425x_dev_s *priv, bool enable) +{ + int ret; + uint8_t regval; + + ret = bq2425x_getreg8(priv, BQ2425X_REG_1, ®val); + if (ret < 0) + { + batdbg("Error reading from BQ2425X! Error = %d\n", ret); + return ret; + } + + if (enable) + { + regval |= BQ2425X_WD_EN; + } + else + { + regval &= ~(BQ2425X_WD_EN); + } + + ret = bq2425x_putreg8(priv, BQ2425X_REG_1, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_state + * + * Description: + * Return the current battery state + * + ****************************************************************************/ + +static int bq2425x_state(struct battery_charger_dev_s *dev, int *status) +{ + FAR struct bq2425x_dev_s *priv = (FAR struct bq2425x_dev_s *)dev; + uint8_t regval = 0; + int ret; + + ret = bq2425x_getreport(priv, ®val); + if (ret < 0) + { + *status = BATTERY_UNKNOWN; + return ret; + } + + regval &= BQ2425X_STAT_MASK; + + /* Is there some fault in the battery? */ + + if (regval == BQ2425X_STAT_FAULT) + { + *status = BATTERY_FAULT; + } + + /* Is the charging done? */ + + else if (regval == BQ2425X_STAT_CHG_DONE) + { + *status = BATTERY_FULL; + } + + /* Is the charging in progress? */ + + else if (regval == BQ2425X_STAT_CHG_PROGRESS) + { + *status = BATTERY_CHARGING; + } + + /* Is the charging ready? */ + + else if (regval == BQ2425X_STAT_READY) + { + *status = BATTERY_IDLE; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_health + * + * Description: + * Return the current battery health state + * + * Note: if more than one fault happened the user needs to call this ioctl + * again to read a new fault, repeat until receive a BATTERY_HEALTH_GOOD. + * + ****************************************************************************/ + +static int bq2425x_health(struct battery_charger_dev_s *dev, int *health) +{ + FAR struct bq2425x_dev_s *priv = (FAR struct bq2425x_dev_s *)dev; + uint8_t regval = 0; + int ret; + + ret = bq2425x_getreport(priv, ®val); + if (ret < 0) + { + *health = BATTERY_HEALTH_UNKNOWN; + return ret; + } + + regval &= BQ2425X_FAULT_MASK; + + switch (regval) + { + case BQ2425X_FAULT_NORMAL: + *health = BATTERY_HEALTH_GOOD; + break; + + case BQ2425X_FAULT_SLEEP: + case BQ2425X_FAULT_INP_OVP: + case BQ2425X_FAULT_INP_UVLO: + case BQ2425X_FAULT_ISET_SHORT: + case BQ2425X_FAULT_INP_LDO_LOW: + *health = BATTERY_HEALTH_UNSPEC_FAIL; + break; + + case BQ2425X_FAULT_BAT_OVP: + *health = BATTERY_HEALTH_OVERVOLTAGE; + break; + + case BQ2425X_FAULT_BAT_TEMP: + case BQ2425X_FAULT_THERM_SHUT: + *health = BATTERY_HEALTH_OVERHEAT; + break; + + case BQ2425X_FAULT_TIMER: + *health = BATTERY_HEALTH_SAFE_TMR_EXP; + break; + + case BQ2425X_FAULT_NO_BATTERY: + *health = BATTERY_HEALTH_DISCONNECTED; + break; + + default: + *health = BATTERY_HEALTH_UNKNOWN; + break; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_online + * + * Description: + * Return true if the battery is online + * + ****************************************************************************/ + +static int bq2425x_online(struct battery_charger_dev_s *dev, bool *status) +{ + /* There is no concept of online/offline in this driver */ + + *status = true; + return OK; +} + +/**************************************************************************** + * Name: bq2425x_powersupply + * + * Description: + * Set the Power Supply Current Limit. + * + ****************************************************************************/ + +static inline int bq2425x_powersupply(FAR struct bq2425x_dev_s *priv, int current) +{ + uint8_t regval; + int ret, idx; + + switch (current) + { + case 100: + idx = BQ2425X_INP_CURR_LIM_100MA; + break; + + case 150: + idx = BQ2425X_INP_CURR_LIM_150MA; + break; + + case 500: + idx = BQ2425X_INP_CURR_LIM_500MA; + break; + + case 900: + idx = BQ2425X_INP_CURR_LIM_900MA; + break; + + case 1500: + idx = BQ2425X_INP_CURR_LIM_1500MA; + break; + + case 2000: + idx = BQ2425X_INP_CURR_LIM_2000MA; + break; + + default: + batdbg("Current not supported, setting default to 100mA.!\n"); + idx = BQ2425X_INP_CURR_LIM_100MA; + break; + } + + /* Read current register */ + + ret = bq2425x_getreg8(priv, BQ2425X_REG_2, ®val); + if (ret < 0) + { + batdbg("Error reading from BQ2425X! Error = %d\n", ret); + return ret; + } + + /* Clear previous current and set new value */ + + regval &= ~(BQ2425X_INP_CURR_LIM_MASK); + regval |= idx; + + /* Also clear Reset bit to avoid the resetting BUG */ + + regval &= ~(BQ2425X_RESET); + + ret = bq2425x_putreg8(priv, BQ2425X_REG_2, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_setvolt + * + * Description: + * Set the voltage level to charge the battery. Voltage value in mV. + * + ****************************************************************************/ + +static inline int bq2425x_setvolt(FAR struct bq2425x_dev_s *priv, int volts) +{ + uint8_t regval; + int ret, idx; + + /* Verify if voltage is in the acceptable range */ + + if (volts < BQ2425X_VOLT_MIN || volts > BQ2425X_VOLT_MAX) + { + batdbg("Voltage %d mV is out of range.\n", volts); + return -EINVAL; + } + + ret = bq2425x_getreg8(priv, BQ2425X_REG_3, ®val); + if (ret < 0) + { + batdbg("Error reading from BQ2425X! Error = %d\n", ret); + return ret; + } + + /* Voltage starts at 3500mV and increases in steps of 20mV */ + + idx = volts - BQ2425X_VOLT_MIN; + idx = idx / 20; + + /* Clear previous voltage */ + + regval &= ~(BQ2425X_BAT_VOLT_MASK); + regval |= (idx << BQ2425X_BAT_VOLT_SHIFT); + + ret = bq2425x_putreg8(priv, BQ2425X_REG_3, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_setcurr + * + * Description: + * Set the current to charge the battery. Current value in mA. + * + ****************************************************************************/ + +static inline int bq2425x_setcurr(FAR struct bq2425x_dev_s *priv, int current) +{ + uint8_t regval; + int ret, idx; + + /* Verify if voltage is in the acceptable range */ + + if (current < BQ2425X_CURR_MIN || current > BQ2425X_CURR_MAX) + { + batdbg("Current %d mA is out of range.\n", volts); + return -EINVAL; + } + + ret = bq2425x_getreg8(priv, BQ2425X_REG_4, ®val); + if (ret < 0) + { + batdbg("Error reading from BQ2425X! Error = %d\n", ret); + return ret; + } + + /* Current starts at 500mV and increases in steps of 50mA */ + + idx = current - BQ2425X_CURR_MIN; + idx = idx / 50; + + /* Clear previous current and set new value */ + + regval &= ~(BQ2425X_CHG_CURRENT_MASK); + regval |= (idx << BQ2425X_CHG_CURRENT_SHIFT); + + ret = bq2425x_putreg8(priv, BQ2425X_REG_4, regval); + if (ret < 0) + { + batdbg("Error writing to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + + +/**************************************************************************** + * Name: bq2425x_voltage + * + * Description: + * Set battery charger voltage + * + ****************************************************************************/ + +static int bq2425x_voltage(struct battery_charger_dev_s *dev, int value) +{ + FAR struct bq2425x_dev_s *priv = (FAR struct bq2425x_dev_s *)dev; + int ret; + + /* Set voltage to battery charger */ + + ret = bq2425x_setvolt(priv, value); + if (ret < 0) + { + batdbg("Error setting voltage to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: bq2425x_current + * + * Description: + * Set the battery charger current rate for charging + * + ****************************************************************************/ + +static int bq2425x_current(struct battery_charger_dev_s *dev, int value) +{ + FAR struct bq2425x_dev_s *priv = (FAR struct bq2425x_dev_s *)dev; + int ret; + + /* Set current to battery charger */ + + ret = bq2425x_setcurr(priv, value); + if (ret < 0) + { + batdbg("Error setting current to BQ2425X! Error = %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: bq2425x_initialize + * + * Description: + * Initialize the BQ2425x battery driver and return an instance of the + * lower_half interface that may be used with battery_charger_register(); + * + * This driver requires: + * + * CONFIG_BATTERY_CHARGER - Upper half battery driver support + * CONFIG_I2C - I2C support + * CONFIG_I2C_BQ2425X - And the driver must be explictly selected. + * + * Input Parameters: + * i2c - An instance of the I2C interface to use to communicate with + * the BQ2425x + * addr - The I2C address of the BQ2425x (Better be 0x36). + * frequency - The I2C frequency + * + * Returned Value: + * A pointer to the initializeed lower-half driver instance. A NULL pointer + * is returned on a failure to initialize the BQ2425x lower half. + * + ****************************************************************************/ + +FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c, + uint8_t addr, uint32_t frequency) +{ + FAR struct bq2425x_dev_s *priv; + int ret; + + /* Initialize the BQ2425x device structure */ + + priv = (FAR struct bq2425x_dev_s *)kmm_zalloc(sizeof(struct bq2425x_dev_s)); + if (priv) + { + /* Initialize the BQ2425x device structure */ + + sem_init(&priv->batsem, 0, 1); + priv->ops = &g_bq2425xops; + priv->i2c = i2c; + priv->addr = addr; + priv->frequency = frequency; + + /* Set the I2C frequency (ignoring the returned, actual frequency) */ + + (void)I2C_SETFREQUENCY(i2c, priv->frequency); + + /* Reset the BQ2425x */ + + ret = bq2425x_reset(priv); + if (ret < 0) + { + batdbg("Failed to reset the BQ2425x: %d\n", ret); + kmm_free(priv); + return NULL; + } + + /* Disable watchdog otherwise BQ2425x returns to StandAlone mode */ + + ret = bq2425x_watchdog(priv, false); + if (ret < 0) + { + batdbg("Failed to disable BQ2425x watchdog: %d\n", ret); + kmm_free(priv); + return NULL; + } + + /* Define that our power supply can offer 2000mA to the charger */ + + ret = bq2425x_powersupply(priv, 2000); + if (ret < 0) + { + batdbg("Failed to set BQ2425x power supply current: %d\n", ret); + kmm_free(priv); + return NULL; + } + } + + return (FAR struct battery_charger_dev_s *)priv; +} + +#endif /* CONFIG_BATTERY && CONFIG_I2C && CONFIG_I2C_BQ2425X */ diff --git a/drivers/power/bq2425x.h b/drivers/power/bq2425x.h new file mode 100644 index 0000000000..3dd57f68a5 --- /dev/null +++ b/drivers/power/bq2425x.h @@ -0,0 +1,272 @@ +/**************************************************************************** + * drivers/power/bq2425x.h + * Lower half driver for BQ2425x battery charger + * + * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __DRIVERS_POWER_BQ2425X_H +#define __DRIVERS_POWER_BQ2425X_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Auxiliary Definitions */ + +#define BQ2425X_VOLT_MIN 3500 +#define BQ2425X_VOLT_MAX 4440 + +#define BQ2425X_CURR_MIN 500 +#define BQ2425X_CURR_MAX 2000 + +/* BQ2425x Register Definitions ********************************************/ + +#define BQ2425X_REG_1 0x00 +#define BQ2425X_REG_2 0x01 +#define BQ2425X_REG_3 0x02 +#define BQ2425X_REG_4 0x03 +#define BQ2425X_REG_5 0x04 +#define BQ2425X_REG_6 0x05 +#define BQ2425X_REG_7 0x06 + +/* REG 1 */ + +#define BQ2425X_WD_FAULT (1 << 7) /* If 1 means WD timeout if WD is enabled */ +#define BQ2425X_WD_EN (1 << 6) /* Set 1 will enable and reset timeout */ +#define BQ2425X_STAT_SHIFT 4 /* Battery charger status */ +#define BQ2425X_STAT_MASK (3 << BQ2425X_STAT_SHIFT) +# define BQ2425X_STAT_READY (0 << BQ2425X_STAT_SHIFT) +# define BQ2425X_STAT_CHG_PROGRESS (1 << BQ2425X_STAT_SHIFT) +# define BQ2425X_STAT_CHG_DONE (2 << BQ2425X_STAT_SHIFT) +# define BQ2425X_STAT_FAULT (3 << BQ2425X_STAT_SHIFT) +#define BQ2425X_FAULT_SHIFT 0 /* Battery Fault report */ +#define BQ2425X_FAULT_MASK (15 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_NORMAL (0 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_INP_OVP (1 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_INP_UVLO (2 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_SLEEP (3 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_BAT_TEMP (4 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_BAT_OVP (5 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_THERM_SHUT (6 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_TIMER (7 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_NO_BATTERY (8 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_ISET_SHORT (9 << BQ2425X_FAULT_SHIFT) +# define BQ2425X_FAULT_INP_LDO_LOW (10 << BQ2425X_FAULT_SHIFT) + +/* REG 2 */ + +#define BQ2425X_RESET (1 << 7) /* Write 1 to Reset all register to default values */ +#define BQ2425X_INP_CURR_LIM_SHIFT 4 /* Input Current Limit */ +#define BQ2425X_INP_CURR_LIM_MASK (7 << BQ2425X_INP_CURR_LIM_SHIFT) +# define BQ2425X_INP_CURR_LIM_100MA (0 << BQ2425X_INP_CURR_LIM_SHIFT) /* USB2.0 host with 100mA current limit */ +# define BQ2425X_INP_CURR_LIM_150MA (1 << BQ2425X_INP_CURR_LIM_SHIFT) /* USB3.0 host with 150mA current limit */ +# define BQ2425X_INP_CURR_LIM_500MA (2 << BQ2425X_INP_CURR_LIM_SHIFT) /* USB2.0 host with 500mA current limit */ +# define BQ2425X_INP_CURR_LIM_900MA (3 << BQ2425X_INP_CURR_LIM_SHIFT) /* USB3.0 host with 900mA current limit */ +# define BQ2425X_INP_CURR_LIM_1500MA (4 << BQ2425X_INP_CURR_LIM_SHIFT) /* Charger with 1500mA current limit */ +# define BQ2425X_INP_CURR_LIM_2000MA (5 << BQ2425X_INP_CURR_LIM_SHIFT) /* Charger with 2000mA current limit */ +# define BQ2425X_INP_CURR_EXT_ILIM (6 << BQ2425X_INP_CURR_LIM_SHIFT) /* External ILIM current limit */ +# define BQ2425X_INP_CURR_NO_LIMIT (7 << BQ2425X_INP_CURR_LIM_SHIFT) /* No input current limit with internal clamp at 3A */ +#define BQ2425X_EN_STAT (1 << 3) /* Enable/Disable STAT pin */ +#define BQ2425X_EN_TERM (1 << 2) /* Enable/Disable charge termination */ +#define BQ2425X_CE (1 << 1) /* Enable/Disable the Charger, inverted logic, 0 enables */ +#define BQ2425X_HZ_MODE (1 << 0) /* Sets the charger IC into low power standby mode, but keep BAT FET ON */ + +/* REG 3 */ + +#define BQ2425X_BAT_VOLT_SHIFT 2 +#define BQ2425X_BAT_VOLT_MASK (0x3F << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3500MV (0 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3520MV (1 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3540MV (2 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3560MV (3 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3580MV (4 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3600MV (5 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3620MV (6 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3640MV (7 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3660MV (8 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3680MV (9 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3700MV (10 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3720MV (11 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3740MV (12 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3760MV (13 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3780MV (14 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3800MV (15 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3820MV (16 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3840MV (17 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3860MV (18 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3880MV (19 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3900MV (20 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3920MV (21 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3940MV (22 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3960MV (23 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_3980MV (24 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4000MV (25 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4020MV (26 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4040MV (27 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4060MV (28 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4080MV (29 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4100MV (30 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4120MV (31 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4140MV (32 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4160MV (33 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4180MV (34 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4200MV (35 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4220MV (36 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4240MV (37 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4260MV (38 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4280MV (39 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4300MV (40 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4320MV (41 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4340MV (42 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4360MV (43 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4380MV (44 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4400MV (45 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4420MV (46 << BQ2425X_BAT_VOLT_SHIFT) +# define BQ2425X_BAT_VOLT_4440MV (47 << BQ2425X_BAT_VOLT_SHIFT) +#define BQ2425X_USB_DET_EN_SHIFT 0 +#define BQ2425X_USB_DET_EN_MASK (3 << BQ2425X_USB_DET_EN_SHIFT) +# define BQ2425X_DCP_EN2_0_EN1_0 (0 << BQ2425X_USB_DET_EN_SHIFT) +# define BQ2425X_CDP_EN2_0_EN1_1 (1 << BQ2425X_USB_DET_EN_SHIFT) +# define BQ2425X_SDP_EN2_1_EN1_0 (2 << BQ2425X_USB_DET_EN_SHIFT) +# define BQ2425X_APPLE_EN2_1_EN1_1 (3 << BQ2425X_USB_DET_EN_SHIFT) + +/* REG 4 */ + +#define BQ2425X_CHG_CURRENT_SHIFT 2 +#define BQ2425X_CHG_CURRENT_MASK (0x1F << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_500MA (0 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_550MA (1 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_600MA (2 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_650MA (3 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_700MA (4 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_750MA (5 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_800MA (6 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_850MA (7 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_900MA (8 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_950MA (9 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1000MA (10 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1050MA (11 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1100MA (12 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1150MA (13 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1200MA (14 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1250MA (15 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1300MA (16 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1350MA (17 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1400MA (18 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1450MA (19 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1500MA (20 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1550MA (21 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1600MA (22 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1650MA (23 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1700MA (24 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1750MA (25 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1800MA (26 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1850MA (27 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1900MA (28 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_1950MA (29 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_CURRENT_2000MA (30 << BQ2425X_CHG_CURRENT_SHIFT) +# define BQ2425X_CHG_EXT_ISET_MODE (31 << BQ2425X_CHG_CURRENT_SHIFT) +#define BQ2425X_CHG_CURR_TERM_SHIFT 0 +#define BQ2425X_CHG_CURR_TERM_MASK (7 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_50MA (0 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_75MA (1 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_100MA (2 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_125MA (3 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_150MA (4 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_175MA (5 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_200MA (6 << BQ2425X_CHG_CURR_TERM_SHIFT) +# define BQ2425X_CHG_CURR_TERM_225MA (7 << BQ2425X_CHG_CURR_TERM_SHIFT) + +/* REG 5 */ + +#define BQ2425X_LOOP_STATUS_SHIFT 6 /* Show if there is some active loop that slow down safety timer */ +#define BQ2425X_LOOP_STATUS_MASK (3 << BQ2425X_LOOP_STATUS_SHIFT) +# define BQ2425X_NO_LOOP (0 << BQ2425X_LOOP_STATUS_SHIFT) +# define BQ2425X_VIN_DPM_LOOP (1 << BQ2425X_LOOP_STATUS_SHIFT) +# define BQ2425X_INP_CURR_LIM_LOOP (2 << BQ2425X_LOOP_STATUS_SHIFT) +# define BQ2425X_THERM_REG_LOOP (3 << BQ2425X_LOOP_STATUS_SHIFT) +#define BQ2425X_LOW_CHG (1 << 5) /* 0 = REG 4 defines current; 1 = Low curr 330mA */ +#define BQ2425X_DPDM_EN (1 << 4) /* Force D+/D- detection */ +#define BQ2425X_CE_STATUS (1 << 3) /* 0 = CE low ; 1 = CE high */ +#define BQ2425X_VIN_DPM_SHIFT 0 /* Sets the input VDPM level */ +#define BQ2425X_VIN_DPM_MASK (7 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4200MV (0 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4280MV (1 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4360MV (2 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4440MV (3 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4520MV (4 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4600MV (5 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4680MV (5 << BQ2425X_VIN_DPM_SHIFT) +# define BQ2425X_VIN_DPM_4760MV (5 << BQ2425X_VIN_DPM_SHIFT) + +/* REG 6 */ + +#define BQ2425X_2XTMR_EN (1 << 7) /* Timer slowed 2x when in thermal reg., Vin_dpm or DPPM */ +#define BQ2425X_TIMER_SHIFT 6 /* Safety timer time limit */ +#define BQ2425X_TIMER_MASK (3 << BQ2425X_TIMER_SHIFT) +# define BQ2425X_TIMER_0p74H (0 << BQ2425X_TIMER_SHIFT) /* 0.75 hour fast charge */ +# define BQ2425X_TIMER_6H (1 << BQ2425X_TIMER_SHIFT) /* 6 hour fast charge (default 01) */ +# define BQ2425X_TIMER_9H (2 << BQ2425X_TIMER_SHIFT) /* 9 hour fast charge */ +# define BQ2425X_TIMER_DISABLED (3 << BQ2425X_TIMER_SHIFT) /* Disable safety timers */ +#define BQ2425X_SYSOFF (1 << 4) /* 0 = SYSOFF disabled ; 1 = SYSOFF enabled */ +#define BQ2425X_TS_EN (1 << 3) /* 0 = TS function disabled ; 1 = TS function enabled */ +#define BQ2425X_TS_STATUS_SHIFT 0 /* TS Fault Mode */ +#define BQ2425X_TS_STATUS_MASK (7 << BQ2425X_TS_STATUS_SHIFT) +# define BQ2425X_TS_NORMAL (0 << BQ2425X_TS_STATUS_SHIFT) /* Normal, No TS fault */ +# define BQ2425X_TS_TEMP_HOT (1 << BQ2425X_TS_STATUS_SHIFT) /* TS_temp > T_hot */ +# define BQ2425X_TS_TEMP_WARM (2 << BQ2425X_TS_STATUS_SHIFT) /* T_warm < TS_temp < T_hot */ +# define BQ2425X_TS_TEMP_COOL (3 << BQ2425X_TS_STATUS_SHIFT) /* T_cold < TS_temp < T_cool*/ +# define BQ2425X_TS_TEMP_COLD (4 << BQ2425X_TS_STATUS_SHIFT) /* TS_temp < T_cold */ +# define BQ2425X_TS_TEMP_VERY_COLD (5 << BQ2425X_TS_STATUS_SHIFT) /* T_freeze < TS_temp < T_cold */ +# define BQ2425X_TS_TEMP_FREEZE (6 << BQ2425X_TS_STATUS_SHIFT) /* TS_temp < T_freeze */ +# define BQ2425X_TS_OPEN_DISABLED (7 << BQ2425X_TS_STATUS_SHIFT) /* TS open (TS disabled) */ + +/* REG 7 */ + +#define BQ2425X_VOLT_OVP_SHIFT 5 /* OVP voltage */ +#define BQ2425X_VOLT_OVP_MASK (7 << BQ2425X_VOLT_OVP_SHIFT) +# define BQ2425X_VOLT_OVP_6p0V (0 << BQ2425X_VOLT_OVP_SHIFT) /* 6.0V */ +# define BQ2425X_VOLT_OVP_6p5V (1 << BQ2425X_VOLT_OVP_SHIFT) /* 6.5V */ +# define BQ2425X_VOLT_OVP_7p0V (2 << BQ2425X_VOLT_OVP_SHIFT) /* 7.0V */ +# define BQ2425X_VOLT_OVP_8p0V (3 << BQ2425X_VOLT_OVP_SHIFT) /* 8.0V */ +# define BQ2425X_VOLT_OVP_9p0V (4 << BQ2425X_VOLT_OVP_SHIFT) /* 9.0V */ +# define BQ2425X_VOLT_OVP_9p5V (5 << BQ2425X_VOLT_OVP_SHIFT) /* 9.5V */ +# define BQ2425X_VOLT_OVP_10p0V (6 << BQ2425X_VOLT_OVP_SHIFT) /* 10.0V */ +# define BQ2425X_VOLT_OVP_10p5V (7 << BQ2425X_VOLT_OVP_SHIFT) /* 10.5V */ +#define BQ2425X_CLR_VDP (1 << 4) /* 0 = Keep D+ voltage ; 1 = Turn off D+ voltage */ +#define BQ2425X_FORCE_BAT_DET (1 << 3) /* Enter the battery detection routine */ +#define BQ2425X_FORCE_PTM (1 << 2) /* PTM mode enable */ + /* bit 1: reserved */ + /* bit 0: reserved */ + +#endif /* __DRIVERS_POWER_BQ2425X_H */ diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index b67a0125aa..a2ce96196d 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -219,7 +219,7 @@ int battery_charger_register(FAR const char *devpath, #if defined(CONFIG_I2C) && defined(CONFIG_I2C_BQ2425X) struct i2c_dev_s; /* Forward reference */ -FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c +FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c, uint8_t addr, uint32_t frequency); #endif -- GitLab From cc7130b836c65d3149666bfe4201d90cf6069940 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Sep 2015 10:34:08 -0600 Subject: [PATCH 164/858] Correct a reference counting error in mq_open() --- ChangeLog | 3 +++ arch | 2 +- fs/driver/fs_registerblockdriver.c | 4 +++- fs/driver/fs_registerdriver.c | 4 +++- fs/inode/fs_inodereserve.c | 8 +++++--- fs/mount/fs_mount.c | 2 ++ fs/mqueue/mq_close.c | 2 +- fs/mqueue/mq_open.c | 12 +++++++++--- fs/semaphore/sem_open.c | 9 ++++++--- fs/unionfs/fs_unionfs.c | 1 + fs/vfs/fs_mkdir.c | 5 ++++- fs/vfs/fs_rename.c | 5 ++++- 12 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1102051c4b..d091e4399f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10981,4 +10981,7 @@ Carvalho de Assis (2015-09-19). * drivers/power/bq2425x.c and .h: Battery Charger: Add BQ24250 driver. From Alan Carvalho de Assis (2015-09-20). + * fs/mqueue/mq_open.c: When message queue is opened, inode_reserve() + leaves the reference count at zero. mq_open() logic must assure + that the reference count of the newly created inode is one (2015-09-23). diff --git a/arch b/arch index 4dc3ba30bd..eaeadc582a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4dc3ba30bd14059b76c578694842bda0eaaf9763 +Subproject commit eaeadc582ae79c5abe1ea8d6515585d2b0f5e34b diff --git a/fs/driver/fs_registerblockdriver.c b/fs/driver/fs_registerblockdriver.c index ea611022d3..e0032b581a 100644 --- a/fs/driver/fs_registerblockdriver.c +++ b/fs/driver/fs_registerblockdriver.c @@ -108,7 +108,9 @@ int register_blockdriver(FAR const char *path, ret = inode_reserve(path, &node); if (ret >= 0) { - /* We have it, now populate it with block driver specific information. */ + /* We have it, now populate it with block driver specific information. + * NOTE that the initial reference count on the new inode is zero. + */ INODE_SET_BLOCK(node); diff --git a/fs/driver/fs_registerdriver.c b/fs/driver/fs_registerdriver.c index db635cdfd1..5d8269c25b 100644 --- a/fs/driver/fs_registerdriver.c +++ b/fs/driver/fs_registerdriver.c @@ -103,7 +103,9 @@ int register_driver(FAR const char *path, FAR const struct file_operations *fops ret = inode_reserve(path, &node); if (ret >= 0) { - /* We have it, now populate it with driver specific information. */ + /* We have it, now populate it with driver specific information. + * NOTE that the initial reference count on the new inode is zero. + */ INODE_SET_DRIVER(node); diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index 104a42e0e7..faa6c01237 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -145,9 +145,8 @@ static void inode_insert(FAR struct inode *node, * Name: inode_reserve * * Description: - * Reserve an (initialized) inode the pseudo file system. - * - * NOTE: Caller must hold the inode semaphore + * Reserve an (initialized) inode the pseudo file system. The initial + * reference count on the new inode is zero. * * Input parameters: * path - The path to the inode to create @@ -161,6 +160,9 @@ static void inode_insert(FAR struct inode *node, * EEXIST - An inode already exists at 'path' * ENOMEM - Failed to allocate in-memory resources for the operation * + * Assumptions: + * Caller must hold the inode semaphore + * ****************************************************************************/ int inode_reserve(FAR const char *path, FAR struct inode **inode) diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 3a5602968c..401ff747ba 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -296,6 +296,8 @@ int mount(FAR const char *source, FAR const char *target, /* Insert a dummy node -- we need to hold the inode semaphore * to do this because we will have a momentarily bad structure. + * NOTE that the new inode will be created with an initial reference + * count of zero. */ { diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c index 00a29bbe6b..eb0d313e8f 100644 --- a/fs/mqueue/mq_close.c +++ b/fs/mqueue/mq_close.c @@ -136,7 +136,7 @@ int mq_close(mqd_t mqdes) } /**************************************************************************** - * Name: mq_close + * Name: mq_inode_release * * Description: * Release a reference count on a message queue inode. diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index f2b95b9b5a..f49f5a34c5 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/mqueue/mq_open.c * - * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -139,7 +139,8 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) sched_lock(); /* Get the inode for this mqueue. This should succeed if the message - * queue has already been created. + * queue has already been created. In this case, inode_finde() will + * have incremented the reference count on the inode. */ inode = inode_find(fullpath, &relpath); @@ -206,7 +207,9 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) goto errout_with_lock; } - /* Allocate memory for the new message queue. */ + /* Allocate memory for the new message queue. The new inode will + * be created with a reference count of zero. + */ msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr); if (!msgq) @@ -230,6 +233,9 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) inode->u.i_mqueue = msgq; msgq->inode = inode; + /* Set the initial reference count on this inode to one */ + + inode->i_crefs = 1; } sched_unlock(); diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 292eddc82c..4d422c8503 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -148,8 +148,9 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) snprintf(fullpath, MAX_SEMPATH, CONFIG_FS_NAMED_SEMPATH "/%s", name); - /* Get the inode for this semaphore. This should succeed if the semaphore - * has already been created. + /* Get the inode for this semaphore. This should succeed if the + * semaphore has already been created. In this case, inode_finde() + * will have incremented the reference count on the inode. */ inode = inode_find(fullpath, &relpath); @@ -214,7 +215,9 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) goto errout_with_lock; } - /* Create an inode in the pseudo-filesystem at this path */ + /* Create an inode in the pseudo-filesystem at this path. The new + * inode will be created with a reference count of zero. + */ inode_semtake(); ret = inode_reserve(fullpath, &inode); diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index 9a3c8560b5..994c30b663 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -2568,6 +2568,7 @@ int unionfs_mount(FAR const char *fspath1, FAR const char *prefix1, /* Insert a dummy node -- we need to hold the inode semaphore * to do this because we will have a momentarily bad structure. + * NOTE that the inode will be created with a refernce count of zero. */ inode_semtake(); diff --git a/fs/vfs/fs_mkdir.c b/fs/vfs/fs_mkdir.c index 6d037b37c1..832c5f816a 100644 --- a/fs/vfs/fs_mkdir.c +++ b/fs/vfs/fs_mkdir.c @@ -154,7 +154,10 @@ int mkdir(const char *pathname, mode_t mode) else { - /* Create an inode in the pseudo-filesystem at this path */ + /* Create an inode in the pseudo-filesystem at this path. + * NOTE that the new inode will be created with a reference + * count of zero. + */ inode_semtake(); ret = inode_reserve(pathname, &inode); diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c index cb9173dab9..76f11b0abf 100644 --- a/fs/vfs/fs_rename.c +++ b/fs/vfs/fs_rename.c @@ -175,7 +175,10 @@ int rename(FAR const char *oldpath, FAR const char *newpath) #endif #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS { - /* Create a new, empty inode at the destination location */ + /* Create a new, empty inode at the destination location. + * NOTE that the new inode will be created with a reference count + * of zero. + */ inode_semtake(); ret = inode_reserve(newpath, &newinode); -- GitLab From d078c39b7855e45dcc1ddf0bc1f61237adc7e8db Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Sep 2015 14:42:20 -0600 Subject: [PATCH 165/858] Update ChangeLog; refresh sub-modules --- ChangeLog | 7 ++++++- arch | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d091e4399f..ac1fde3f94 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10984,4 +10984,9 @@ * fs/mqueue/mq_open.c: When message queue is opened, inode_reserve() leaves the reference count at zero. mq_open() logic must assure that the reference count of the newly created inode is one (2015-09-23). - + * arch/sim/src/Kconfig, Makefile, up_setjmp64.S: Modern Cygwin X86_64 + machines follow the Microsoft ABI for parameter passing. The older, + Linux System 5 ABI will not work on X86_64-based Cygwin machines. Also, + the newer Cygwin tool chains do nor pre-pend symbol names with the + underscore character. With these changes the simulator agains works + with the newere Cygwin64 platform (2015-09-24). diff --git a/arch b/arch index eaeadc582a..55821a958e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit eaeadc582ae79c5abe1ea8d6515585d2b0f5e34b +Subproject commit 55821a958e864d1f912fa1f90bdb2afd5e855432 -- GitLab From c01ddfe833d6e0584149ecbe18e52d87505cd70d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Sep 2015 14:42:48 -0600 Subject: [PATCH 166/858] Fix a typo in the ChangeLog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ac1fde3f94..e1178b8c35 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10989,4 +10989,4 @@ Linux System 5 ABI will not work on X86_64-based Cygwin machines. Also, the newer Cygwin tool chains do nor pre-pend symbol names with the underscore character. With these changes the simulator agains works - with the newere Cygwin64 platform (2015-09-24). + with the newer Cygwin64 platform (2015-09-24). -- GitLab From 0ed7ddb8a4d32980ea6044b3a2c4ed5f1bfb01dd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Sep 2015 14:53:50 -0600 Subject: [PATCH 167/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 55821a958e..d1a42540d3 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 55821a958e864d1f912fa1f90bdb2afd5e855432 +Subproject commit d1a42540d3ec4332765f95ac87238f33d98d60d0 diff --git a/configs b/configs index 65514bae3f..45a146aadc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 65514bae3f3be07684ea237ddf69ea4c79b2cd56 +Subproject commit 45a146aadccf84e9eb7c99120f23980b64312561 -- GitLab From 35f85809157c232a45d2f26ec042f176d83d5eb3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Sep 2015 08:52:04 -0600 Subject: [PATCH 168/858] Updata submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 45a146aadc..924373bae4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 45a146aadccf84e9eb7c99120f23980b64312561 +Subproject commit 924373bae401064944bca6d165ee8c7f89753cbc -- GitLab From 3d3a60ee1bee88b5f7aac6790d056cc8d32b4c12 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Sep 2015 07:31:49 -0600 Subject: [PATCH 169/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index d1a42540d3..a298b02019 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d1a42540d3ec4332765f95ac87238f33d98d60d0 +Subproject commit a298b020196a9c2b49ccc01e20b2470a0181b6bf diff --git a/configs b/configs index 924373bae4..f3c64ff461 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 924373bae401064944bca6d165ee8c7f89753cbc +Subproject commit f3c64ff461c5794ed26bf9893af7af6dd899f9fa -- GitLab From 2c7c034baf7963670eecca82a50d790294550b96 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Sep 2015 09:22:39 -0600 Subject: [PATCH 170/858] Update README, ChangeLog, and submodules --- ChangeLog | 4 ++++ Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1178b8c35..cec7f42351 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10990,3 +10990,7 @@ the newer Cygwin tool chains do nor pre-pend symbol names with the underscore character. With these changes the simulator agains works with the newer Cygwin64 platform (2015-09-24). + * arch/arm/src/lpc43xx: Extensive I2C and clocking updates from Lok Tep + (2015-09-29). + * configs/lpc4370-link2: Support for the NXP LPC4370-Link2 development + board from Lok Tep (2015-09-29). \ No newline at end of file diff --git a/Documentation b/Documentation index 11a3998898..21904053f6 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 11a3998898b783cd758570fef01423182f5a452b +Subproject commit 21904053f68cec9388bf8b9ee7e24215d91d2f68 diff --git a/README.txt b/README.txt index fcd8c53afc..ee336105b0 100644 --- a/README.txt +++ b/README.txt @@ -1321,6 +1321,8 @@ nuttx/ | | `- README.txt | |- lpc4357-evb/ | | `- README.txt + | |- lpc4370-link2/ + | | `- README.txt | |- lpcxpresso-lpc1115/ | | `- README.txt | |- lpcxpresso-lpc1768/ diff --git a/arch b/arch index a298b02019..52932b340e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a298b020196a9c2b49ccc01e20b2470a0181b6bf +Subproject commit 52932b340edc13f428308c8edc60279910c7e81e diff --git a/configs b/configs index f3c64ff461..07de30cb5b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f3c64ff461c5794ed26bf9893af7af6dd899f9fa +Subproject commit 07de30cb5b544e636813bbdab51e870cdd548ff4 -- GitLab From cf9100f91771c9972f9757252b63284179fbbd18 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Sep 2015 16:10:35 -0600 Subject: [PATCH 171/858] Upate submodules --- Documentation | 2 +- arch | 2 +- configs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index 21904053f6..6e20db5f17 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 21904053f68cec9388bf8b9ee7e24215d91d2f68 +Subproject commit 6e20db5f174f5ebe95e7ea3def4a67e2b97277ff diff --git a/arch b/arch index 52932b340e..69721cb374 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 52932b340edc13f428308c8edc60279910c7e81e +Subproject commit 69721cb3742b2cb6f399c966b56da00ae3e9cb05 diff --git a/configs b/configs index 07de30cb5b..5a319c2e71 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 07de30cb5b544e636813bbdab51e870cdd548ff4 +Subproject commit 5a319c2e71ccc64e4cb3ebdc6fecc535f544e260 -- GitLab From e35737ca889eaa878df53aaf7b23d3dff53fe5b9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Sep 2015 16:35:07 -0600 Subject: [PATCH 172/858] Update ChangeLog --- ChangeLog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cec7f42351..acadd39a2f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10993,4 +10993,7 @@ * arch/arm/src/lpc43xx: Extensive I2C and clocking updates from Lok Tep (2015-09-29). * configs/lpc4370-link2: Support for the NXP LPC4370-Link2 development - board from Lok Tep (2015-09-29). \ No newline at end of file + board from Lok Tep (2015-09-29). + * configs/nucleo-f303re: Add SSD1351 SPI 4-wire interface. From Paul + Alexander Patience (2015-09-29). + -- GitLab From 4cd57e1e4ee490192203d80809b76a4b20f2e938 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Sep 2015 11:04:29 -0600 Subject: [PATCH 173/858] Work queues: Logic that sets the queued indication and the logic that does the actual queuing must be atomic --- ChangeLog | 5 ++++- arch | 2 +- configs | 2 +- libc/wqueue/work_queue.c | 12 ++++++------ sched/wqueue/kwork_cancel.c | 6 ++++-- sched/wqueue/kwork_queue.c | 16 ++++++++-------- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index acadd39a2f..3a319bcbe3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10996,4 +10996,7 @@ board from Lok Tep (2015-09-29). * configs/nucleo-f303re: Add SSD1351 SPI 4-wire interface. From Paul Alexander Patience (2015-09-29). - + * arch/arm/src/armv7-m/up_schedulesigaction.c: Fix logic that determines + if there is a pending signal action before scheduling the next signal + action. Both the test and the scheduling action need to be atomic + (2015-09-30). diff --git a/arch b/arch index 69721cb374..22e48d4266 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 69721cb3742b2cb6f399c966b56da00ae3e9cb05 +Subproject commit 22e48d4266c8c6a8d31aefabe375dcb78173975b diff --git a/configs b/configs index 5a319c2e71..e2bff41896 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 5a319c2e71ccc64e4cb3ebdc6fecc535f544e260 +Subproject commit e2bff41896393f786062d37bf12b09ec89028921 diff --git a/libc/wqueue/work_queue.c b/libc/wqueue/work_queue.c index ffe98af8c7..ce0bf4024c 100644 --- a/libc/wqueue/work_queue.c +++ b/libc/wqueue/work_queue.c @@ -107,16 +107,16 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, { DEBUGASSERT(work != NULL); - /* First, initialize the work structure */ - - work->worker = worker; /* Work callback */ - work->arg = arg; /* Callback argument */ - work->delay = delay; /* Delay until work performed */ - /* Get exclusive access to the work queue */ while (work_lock() < 0); + /* Initialize the work structure */ + + work->worker = worker; /* Work callback. non-NULL means queued */ + work->arg = arg; /* Callback argument */ + work->delay = delay; /* Delay until work performed */ + /* Now, time-tag that entry and put it in the work queue. */ work->qtime = clock_systimer(); /* Time work queued */ diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 8aa133aaab..99a6ac0fd8 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -109,8 +109,10 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, { /* A little test of the integrity of the work queue */ - DEBUGASSERT(work->dq.flink || (FAR dq_entry_t *)work == wqueue->q.tail); - DEBUGASSERT(work->dq.blink || (FAR dq_entry_t *)work == wqueue->q.head); + DEBUGASSERT(work->dq.flink != NULL || + (FAR dq_entry_t *)work == wqueue->q.tail); + DEBUGASSERT(work->dq.blink != NULL || + (FAR dq_entry_t *)work == wqueue->q.head); /* Remove the entry from the work queue and make sure that it is * mark as available (i.e., the worker field is nullified). diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index 842fe656ff..69eca718c1 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -107,20 +107,20 @@ static void work_qqueue(FAR struct kwork_wqueue_s *wqueue, { irqstate_t flags; - DEBUGASSERT(work != NULL); + DEBUGASSERT(work != NULL && worker != NULL); - /* First, initialize the work structure */ + /* First, initialize the work structure. This must be done with interrupts + * disabled. This permits this function to be called from with task logic + * or interrupt handlers. + */ - work->worker = worker; /* Work callback */ + flags = irqsave(); + work->worker = worker; /* Work callback. non-NULL means queued */ work->arg = arg; /* Callback argument */ work->delay = delay; /* Delay until work performed */ - /* Now, time-tag that entry and put it in the work queue. This must be - * done with interrupts disabled. This permits this function to be called - * from with task logic or interrupt handlers. - */ + /* Now, time-tag that entry and put it in the work queue */ - flags = irqsave(); work->qtime = clock_systimer(); /* Time work queued */ dq_addlast((FAR dq_entry_t *)work, &wqueue->q); -- GitLab From ff67c0765aa1168ae770d986be6e897fdd283bec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Sep 2015 11:21:44 -0600 Subject: [PATCH 174/858] Update changelog; refresh submodules --- ChangeLog | 3 +++ arch | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3a319bcbe3..5698374cb6 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11000,3 +11000,6 @@ if there is a pending signal action before scheduling the next signal action. Both the test and the scheduling action need to be atomic (2015-09-30). + * sched/wqueue/kwork_queue.c and libc/wqueue/work_queue.c: Logic that + sets the queued indication and the logic that does the actual queuing + must be atomic (2015-09-20). diff --git a/arch b/arch index 22e48d4266..932831a0ba 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 22e48d4266c8c6a8d31aefabe375dcb78173975b +Subproject commit 932831a0bafc09a0d62349ae97e9c0386f917957 -- GitLab From a813baef0af04fade2a105fe6955fc00d58578e7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Sep 2015 14:03:55 -0600 Subject: [PATCH 175/858] User workqueue, cosmetic changes --- libc/wqueue/work_cancel.c | 8 +++++--- sched/wqueue/kwork_cancel.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libc/wqueue/work_cancel.c b/libc/wqueue/work_cancel.c index c7b1a8435b..93a82e80c3 100644 --- a/libc/wqueue/work_cancel.c +++ b/libc/wqueue/work_cancel.c @@ -110,11 +110,13 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work { /* A little test of the integrity of the work queue */ - DEBUGASSERT(work->dq.flink || (FAR dq_entry_t *)work == wqueue->q.tail); - DEBUGASSERT(work->dq.blink || (FAR dq_entry_t *)work == wqueue->q.head); + DEBUGASSERT(work->dq.flink != NULL || + (FAR dq_entry_t *)work == wqueue->q.tail); + DEBUGASSERT(work->dq.blink != NULL ||i + (FAR dq_entry_t *)work == wqueue->q.head); /* Remove the entry from the work queue and make sure that it is - * mark as available (i.e., the worker field is nullified). + * marked as available (i.e., the worker field is nullified). */ dq_rem((FAR dq_entry_t *)work, &wqueue->q); diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 99a6ac0fd8..177847679f 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -115,7 +115,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, (FAR dq_entry_t *)work == wqueue->q.head); /* Remove the entry from the work queue and make sure that it is - * mark as available (i.e., the worker field is nullified). + * marked as available (i.e., the worker field is nullified). */ dq_rem((FAR dq_entry_t *)work, &wqueue->q); -- GitLab From 0b3a83e0ea8c328b075695f537a810f25394ada9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 1 Oct 2015 10:01:20 -0600 Subject: [PATCH 176/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 932831a0ba..a4ca7854dd 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 932831a0bafc09a0d62349ae97e9c0386f917957 +Subproject commit a4ca7854dd02301803c47ff566e9e7b1c55fe8c8 diff --git a/configs b/configs index e2bff41896..0c9be9883d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e2bff41896393f786062d37bf12b09ec89028921 +Subproject commit 0c9be9883d3d5b90ecb7015770b771be0a4e3c12 -- GitLab From 49871dde1554c0eadd2b3b34dc98462816aba47b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 1 Oct 2015 11:09:56 -0600 Subject: [PATCH 177/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index a4ca7854dd..228b63193d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a4ca7854dd02301803c47ff566e9e7b1c55fe8c8 +Subproject commit 228b63193d95433f447d9385847e93d86d595352 diff --git a/configs b/configs index 0c9be9883d..be32e67e9b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0c9be9883d3d5b90ecb7015770b771be0a4e3c12 +Subproject commit be32e67e9b3ac14b779a6e3539304c9aa69e3f8c -- GitLab From 4cf28dff1ddec5c366f7da9fbc92698a756d6bda Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 1 Oct 2015 13:10:11 -0600 Subject: [PATCH 178/858] Prep for the 7.12 release --- ChangeLog | 32 +++--- Documentation | 2 +- ReleaseNotes | 292 +++++++++++++++++++++++++++++++++++++++++++++++++- configs | 2 +- 4 files changed, 310 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5698374cb6..0838c1843f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -4114,7 +4114,7 @@ group exits. * sched/waitpid.c, task_exithook.c and include/nuttx/sched.h: Move waitpid data data structures to task group. Callers of - of waitpid() are now only awakened whent he final thread of the + of waitpid() are now only awakened when the final thread of the task group exits. * sched/mq_descreate.c, mq_open.c, mq_remove.c, group_leave.c, and include/nuttx/sched.h: Move list of opened message queues to @@ -4533,7 +4533,7 @@ * arch/arm/src/lpc17_lcd.c: Rommel Marcelo got the LPC1788 framebuffer-based LCD working. Very nice! (2013-4-08). * arch/arm/src/lm/lm_clockconfig.c and configs/lm4f120-launchpad: - Fix handling of the RCC SYSDIV2 field whent the PLL output is + Fix handling of the RCC SYSDIV2 field when the PLL output is 400MHz. Don't forget to set the USERCC2 bit in the register or all is for naught (2013-4-09). * configs/zkit-arm-1769/src/up_lcd.c, up_ssp.c, and up_spi.c: @@ -10814,7 +10814,7 @@ support for an MS5805 altimeter. From Paul Alexander Patience (2015-08-12). -7.12 2015-xx-xx Gregory Nutt +7.12 2015-10-01 Gregory Nutt * fs/vfs/fs_poll.c: Use sem_tickwait() instead of sem_timedwait() From Macs Neklyudov (2015-08-13). @@ -10828,7 +10828,7 @@ * include/signal.h and files that include it: Add si_errno to siginfo_t (2015-08-14). * drivers/sensors/mx58xx.c and include/nuttx/sensors/ms58xx.h: - General the MS5805 altimeter driver to support other family + Generalize the MS5805 altimeter driver to support other family members and rename to ms58xx. From Paul Alexander Patience (2015-08-14). * Network drivers. Fix bug in tun interface driver. From Max @@ -10866,12 +10866,12 @@ as defined in the standard. Original implementation used that for numeric addresses but for DNS lookup returned pointer to whole sockaddr_in or sockaddr_in6. From Pavel Pisa (2015-08-21). - * tools/mksymtab: declare g_symtab array as conts to occupy RO + * tools/mksymtab: declare g_symtab array as const to occupy RO section (Flash). From Pavel Pisa (2015-08-23). * libc/libc.csv and syscalls/syscalls.csv: Define some symbol export conditions, correct errno and add sleep and usleep. From Pavel Pisa (2015-08-23). - * net/ ande include/nuttx/net: Remove references to PPP as a + * net/ and include/nuttx/net: Remove references to PPP as a link layer protocol (2015-08-24). * net/, drivers/net, and include/net: Add definitions to support a local loopback device and link layer (2015-08-24). @@ -10889,7 +10889,7 @@ with the SAMV71 QSPI hardware (2015-08-25). * drivers/rwbuffer.c: Fix some logic errors. From Dmitry Nikolaev via Juha Niskanen (2015-08-26). - * net/socket and net/tcp: Fix a problem in whent there are multiple + * net/socket and net/tcp: Fix a problem in when there are multiple network devices. Polls were being sent to all TCP sockets before. This is not good because it means that packets may sometimes be sent out on the wrong device. That is inefficient because it @@ -10908,7 +10908,7 @@ * fs/romfs: One allocation was not being freed if there was a subsequent failure to allocation I/O buffers resulting in a memory leak on certain error conditions. From Bruno Herrera (2015-08-30). - * arch/arm/src/up_iternal.h and several ARM Make.defs files: In the + * arch/arm/src/up_internal.h and several ARM Make.defs files: In the original implementation, !defined(CONFIG_ARMV7M_CMNVECTOR) was a sufficient test to determine if lazy floating point register saving was being used. But recents changes added common lazy register as @@ -10924,7 +10924,7 @@ * libc/math/lib_asin.c: The function did not convert for some input values. Asin did not convert for values which do not belong to the domain of the function. But aside of that the function also did not - convert for sine allowed values. I achieved a conversion of the + converge for some allowed values. I achieved a conversion of the function by reducing the DBL_EPSION and by checking if the input value is in the domain of the function. This is a fix for the problem but the function should always terminate after a given @@ -10933,7 +10933,7 @@ Averyanov (2015-09-02). * arch/arm/src/lpc43xx/lpc43_ethernet.c: Add Ethernet support. From Ilya Averyanov (2015-09-02). - * net/tcp: The logic that binds a specific networkd device to + * net/tcp: The logic that binds a specific network device to a connection was faulty for the case of multiple network devices. On bind(), the local address should be used to associate a device with the connection (if the local address is not INADDR_ANY); @@ -10959,12 +10959,12 @@ Averyanov (2015-09-07). * arch/arm/src/sama5: Separate memory mapping tables for SAMA5D2, 3, and 4 (2015-09-08). - * libc/net/lib_shutdown.c: Add an empty implementatino of the + * libc/net/lib_shutdown.c: Add an empty implementation of the standard shutdown function. This provides only the framework for the shutdown function; the internal logic is not included (2015-09-09). - * configs/nucleo-f303re: Support for the STMicro Nucleo F303ERE board - from Paul Alexander Patience (2014-09-10). + * configs/nucleo-f303re: Support for the STMicro Nucleo F303RE board + from Paul Alexander Patience (2015-09-10). * arch/arm/src/lpc43xx/lpc32_ehci.c and .h: LPC43xx EHCI driver from Ilya Averyanov (2015-09-10). * ARMv7-M, all "lazy" interrupt stack logic. Assembly instruction @@ -10976,8 +10976,8 @@ * drivers/power/battery_gauge.c and include/nuttx/power/battery_gauge.h: battery.c/h renamed to batter_gauge.c/.h since it really only implements a battery fuel gauge. From Alan Carvalho de Assis (2015-09-19). - * drivers/power/battery_charter.c and include/nuttx/power/batter_charger.h: - Add a new frame to support a batter charger interface. From Alan + * drivers/power/battery_charger.c and include/nuttx/power/batter_charger.h: + Add a new framework to support a batter charger interface. From Alan Carvalho de Assis (2015-09-19). * drivers/power/bq2425x.c and .h: Battery Charger: Add BQ24250 driver. From Alan Carvalho de Assis (2015-09-20). @@ -11003,3 +11003,5 @@ * sched/wqueue/kwork_queue.c and libc/wqueue/work_queue.c: Logic that sets the queued indication and the logic that does the actual queuing must be atomic (2015-09-20). + +7.13 2015-xx-xx Gregory Nutt diff --git a/Documentation b/Documentation index 6e20db5f17..b705a3fefb 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 6e20db5f174f5ebe95e7ea3def4a67e2b97277ff +Subproject commit b705a3fefb00ce13be249f47a17d80cdfa7bf71c diff --git a/ReleaseNotes b/ReleaseNotes index d4b8dd72d9..1e5eb013d7 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -9620,6 +9620,296 @@ detailed bugfix information): anti-aliasing OFF. but I don't have the wherewithal for that change today. - OS test: Improve synchronization in round robin tests. On very fast - processors, there are race conditions that make the test failure. + processors, there are race conditions that make the test fail. Need better interlocking to assure that the threads actually do start at the same time. + +NuttX-7.12 Release Notes +------------------------ + +The 112th release of NuttX, Version 7.12, was made on October 1, 2015, +and is available for download from the Bitbucket.org website. Note +that release consists of two tarballs: nuttx-7.12.tar.gz and +apps-7.12.tar.gz. These are available from: + + https://bitbucket.org/patacongo/nuttx/downloads + https://bitbucket.org/nuttx/apps/downloads + +Both may be needed (see the top-level nuttx/README.txt file for build +information). + +Additional new features and extended functionality: + + * Graphics/Graphic Drivers: + + - Added SSD1351 OLED controller support. Contributed by Paul + Alexander Patience. + + * Common Device Drivers: + + - MS58xx: Generalize the MS5805 altimeter driver to support other + family members. From Paul Alexander Patience. + - CAN driver interface: Add an error indication bit to the CAN + message report. + - Developed a new interface for QSPI. Most QSPI hardware (such as the + SAMV71) used a programmed interface to access the QuadSPI FLASH. + That programmed interface is no compatible with the simpler NuttX + SPI data transfer interface. + - Added a driver for ST25L1*K QuadSPI parts. + - Renamed the battery driver interface to battery_gauge since it + really only implements a battery fuel gauge. From Alan Carvalho de + Assis. + - Added a new framework to support a batter charger interface. From + Alan Carvalho de Assis. + - Added a BQ24250 battery charger driver. From Alan Carvalho de Assis. + + * Networking: + + - Added support for the local loopback device (dev lo, hostname localhost). + - Added NetDB support for the local loopback device. + - Network initialization: Automatically initialize all the TUN and + loopback devices if they arein the configuration. + + * Simulation Platform: + + - The simulation now runs under Cygwin64. Modern Cygwin X86_64 + machines follow the Microsoft ABI for parameter passing. The Linux + System 5 ABI would not work on X86_64-based Cygwin machines. Newer + Cygwin tool chains do nor pre-pend symbol names with the underscore + character. + + * Atmel SAMA5Dx: + + - Added architectural support for the Atmel SAMA5D2 parts. Not fully + verified in this NuttX release. + + * Atmel SAMA5Dx Boards: + + - Added support for the Atmel SAMA45D2 Xplained Ultra board. Not + fully verified in this NuttX release. + + * Atmel SAMV7 Drivers: + + - SAMV7 USBHS DCD: The device controller driver is (finally) + functional. + + * NXP LPC17xx: + + - Implement options to use external SDRAM and or SRAM for the heap. + From Pavel Pisa. + + * NXP LPC43x: + + - Added architectural support for the LPC4370. From Lok Tep. + + * NXP LPC43xx Drivers: + + - Added Ethernet support. From Ilya Averyanov. + - Added LPC43xx EHCI driver from Ilya Averyanov. + + * NXP LPC43xx Drivers: + + - Added support for the NXP LPC4370-Link2 development board from Lok + Tep. + + * STMicro STM32: + + - Added architectural for STM32F303K6, STM32F303K8, STM32F303C6, + STM32F303C8, STM32F303RD, and STM32F303RE devices. From Paul + Alexander Patience. + + * STMicro STM32 Drivers: + + - Added OTG support for STM32F44x. From David Sidrane. + + * STMicro STM32 Boards: + + - Added support for the STMicro Nucleo F303ERE board from Paul + Alexander Patience. + + * C Library/Header Files: + + - stdlib: Add support for div() to the C library. From OrbitalFox. + Also added ldiv() and lldiv() which are equivalent to div() with + long and long long types, respectively, instead of int. + - Added an implementation of the standard shutdown function. + + * Tools: + + - tools/mksymtab: declare g_symtab array as const to occupy RO section + (Flash). From Pavel Pisa. + + * Build/Configuration System: + + - Simplify configs/ Makefiles by combining common logic into a new + Board.mk Makefile fragment. From Paul Alexander Patience. + + * Applications: apps/system: + + - apps/system/symtab: Optional canned symtab inclusion to the build. + When option CONFIG_SYSTEM_SYMTAB is selected and symbol table file + libc/symtab/canned_symtab.inc is prepared then application can use + system provided complete symbol table. The option has substantial + effect on system image size. Mainly code/text. If loading of + applications at runtime is not planned do not select this. From + Pavel Pisa. + + * Applications: apps/canutils: + + - apps/canutils/uavcan: Add support for libuavcan. From Paul Alexander Patience. + + * Applications: apps/examples: + + - apps/examples/can: Extend the CAN loopback test by adding more + command line options. + - apps/examples/usbserial: Can now be run as an NSH builtin-function. + Now uses a configurable IO buffer size. + - apps/examples/nettest: Add option to suppress network initialization. + This is necessary if the nettest is run from NSH which has already + initialized the network. + - apps/examples/nettest: Extend test so that can be performed using + the local loopback device. + - apps/examples/netloop: Add a test of the local loopback device. + - apps/examples/udpblaster: Add a test to stress the network by + sending UDP packets at a very high rate. . + - apps/examples/uavcan: libuavcan example from Paul Alexander Patience. + +Bugfixes. Only the most critical bugfixes are listed here (see the +ChangeLog for the complete list of bugfixes and for additional, more +detailed bugfix information): + + * Core OS: + + - wd_create(): Correct a counting error in the number of available + watchdog timers. When the number of free timers is low, the counter + could be incremented below zero. + - mq_open(): When message queue is opened, inode_reserve() leaves the + reference count at zero. mq_open() logic must assure that the + reference count of the newly created inode is one. + - work_queue(): Logic that sets the queued indication and the logic + that does the actual queuing must be atomic. + + * Binary Loader: + + - Fix a memory leak in the built-in application logic: File was not + being closed. From Bruno Herrera. + + * File System/Block Drivers: + + - poll(): If we fail to setup the poll for any file descriptor, for + any reason, set the POLLERR bit. + - rwbuffer: Fix some logic errors. From Dmitry Nikolaev via Juha + Niskanen. + - ROMFS: One allocation was not being freed if there was a subsequent + failure to allocation I/O buffers resulting in a memory leak on + certain error conditions. From Bruno Herrera. + + * Networking/Network Drivers: + + - Fix a bug in tun interface driver. From Max Neklyudov. + - recvfrom(): Correct wait for new data when NET_UDP_READAHEAD is + enabled. Fix size accounting when recvfrom_udpreadahead() sets + state.rf_recvlen == -1. I have not checked if data are accumulated + to the right position in the buffer however. From Pavel Pisa. + - networking: Correct return value from psock_tcp_accept(). From + SaeHie Park. + - TCP: Fix a problem in when there are multiple network devices. + Polls were being sent to all TCP sockets before. This is not good + because it means that packets may sometimes be sent out on the wrong + device. That is inefficient because it will cause retransmissions + and bad performance. But, worse, when one of the devices is not + Ethernet, it will have a different MSS and, as a result, incorrect + data transfers can cause crashes. The fix is to lock into a single + device once the MSS is locked locked down. + - net/tcp: The logic that binds a specific network device to a + connection was faulty for the case of multiple network devices. On + bind(), the local address should be used to associate a device with + the connection (if the local address is not INADDR_ANY); On connect(), + the remote address should be used (in case the local address is + INADDR_ANY). On accept(), it does not matter but the remote address + is the one guaranteed to be available. + - net/tcp: Fix unbuffered send compilation error when Ethernet is not + enabled. From Alan Cavalho de Assis. + + * ARMv7-M: + + - All ARMV7-M IRQ setup: Always set the NVIC vector table address + unconditionally. This is needed in cases where the code is running + with a bootload and when the code is running from RAM. It is also + needed by the logic of up_ramvec_initialize() which gets the vector + base address from the NVIC. Suggested by Pavel Pisa. + - Fix some H/W floating point logic: In the original implementation, + !defined(CONFIG_ARMV7M_CMNVECTOR) was a sufficient test to determine + if lazy floating point register saving was being used. But recents + changes added common lazy register as well so now that test must be + (!defined(CONFIG_ARMV7M_CMNVECTOR) || defined(CONFIG_ARMV7M_LAZYFPU)). + - ARMv7-M, all "lazy" interrupt stack logic. Assembly instruction + that fetches the saved value is incorrect; replace with more + traditional push and pop. This is an important fix. Noted by + Stefan Kolb. + - All ARMV7-M: Force 8-byte stack alignment when calling from assembly + to C to interrupt handling. + - up_schedulesigaction(): Fix logic that determines if there is a + pending signal action before scheduling the next signal action. + Both the test and the scheduling action need to be atomic. This + problem was fixed on the ARMv7-M but also ported to other + architectures that had the same issue. + + * NXP LPC43xx: + + - LPC43xx: Fix NVIC_SYSH_PRIORITY_STEP define. From Ilya Averyanov. + - LPC43xx: Fix missing #define in eeprom. From Ilya Averyanov. + + * NXP LPC43xx Drivers: + + - Fixed the SPI driver. From Ilya Averyanov. + + * Atmel SAMA5 Drivers: + + - LPC31 and SAMA5D EHCI: Fix qh_ioccheck to move bp to next QH. From + Ilya Averyanov. + - LPC31 and SAMA5D EHCI: Performance improvement: Do not disable the + asynchronous queue when adding a new QH structure. From Ilya + Averyanov. + + * C Library/Header Files: + + - gethostbyname(): correct returned address format when DNS is used. + The hostent.h_addr_list should point to raw in_addr or in6_addr + as defined in the standard. Original implementation used that for + numeric addresses but for DNS lookup returned pointer to whole + sockaddr_in or sockaddr_in6. From Pavel Pisa . + - asin(): The function did not convert for some input values. asing() + did not convert for values which do not belong to the domain of the + function. But aside of that the function also did not converge for + allowed values. I achieved a conversion of the function by + reducing the DBL_EPSION and by checking if the input value is in + the domain of the function. This is a fix for the problem but the + function should always terminate after a given number of iterations. + From Stefan Kolb. + - Change all references from avsprintf to vasprintf. From Sebastien + Lorquet. + + * Applications: apps/nshlib: + + - Fix error handling in 'cat' command. On a failure to allocate + memory, a file was not being closed. From Bruno Herrera. + - Fix error handling in 'mv' command. On a failure to expand the + second path, the memory allocated for the expansion of the first + path was not being freed. From Bruno Herrera. + + * Applications: apps/system: + + - apps/system/netdb: Failed to build if CONFIG_NET_HOSTFILE was not + defined because gethostbyaddr() was not available. Noted by + OrbitalFox. + + * Applications: apps/netutils: + + - Various Kconfig files in netutils: Fix some changes from from + NETUTILS_DNSCLIENT to NETDB_DNSCLIENT. From Pavel Pisa. + + * Applications: apps/modbus: + + - Macros PR_BEGIN_EXTERN_C and PR_END_EXTERN_C were not defined in + all contexts. Replace with explicit expansion in all cases. From Stefan Kolb. diff --git a/configs b/configs index be32e67e9b..bb669000c7 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit be32e67e9b3ac14b779a6e3539304c9aa69e3f8c +Subproject commit bb669000c76498d9a0a769948a403784fec897e1 -- GitLab From ba9fc4ee2b4daa1fc857709060866b57c1ecb1c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 1 Oct 2015 13:11:19 -0600 Subject: [PATCH 179/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 228b63193d..a4ca7854dd 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 228b63193d95433f447d9385847e93d86d595352 +Subproject commit a4ca7854dd02301803c47ff566e9e7b1c55fe8c8 -- GitLab From 337798f1bec282218e48ed1c7a89b6de6423771f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 1 Oct 2015 13:14:46 -0600 Subject: [PATCH 180/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index a4ca7854dd..228b63193d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a4ca7854dd02301803c47ff566e9e7b1c55fe8c8 +Subproject commit 228b63193d95433f447d9385847e93d86d595352 -- GitLab From 2ba224eca2998f56751a6dfe21c7a624dd949dd3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 12:33:58 -0600 Subject: [PATCH 181/858] Add support for bsearch() in C library --- ChangeLog | 3 + configs | 2 +- include/stdlib.h | 16 +++-- libc/stdlib/Make.defs | 2 +- libc/stdlib/lib_bsearch.c | 138 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 libc/stdlib/lib_bsearch.c diff --git a/ChangeLog b/ChangeLog index 0838c1843f..7f35156b3e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11005,3 +11005,6 @@ must be atomic (2015-09-20). 7.13 2015-xx-xx Gregory Nutt + + * libc/stdlib/lib_bsearch.c and include/stdlib.h: Add the bsearch() + function from NetBSD (2015-10-02). diff --git a/configs b/configs index bb669000c7..5c519b6b0a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bb669000c76498d9a0a769948a403784fec897e1 +Subproject commit 5c519b6b0a7a28e785266190874adf297322589d diff --git a/include/stdlib.h b/include/stdlib.h index 12a1b951a9..fffcd83f8a 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -200,6 +200,12 @@ FAR void *memalign(size_t, size_t); FAR void *zalloc(size_t); FAR void *calloc(size_t, size_t); +#ifdef CONFIG_CAN_PASS_STRUCTS +struct mallinfo mallinfo(void); +#else +int mallinfo(struct mallinfo *info); +#endif + /* Arithmetic */ int abs(int j); @@ -226,11 +232,11 @@ int mkstemp(FAR char *path_template); void qsort(FAR void *base, size_t nmemb, size_t size, int (*compar)(FAR const void *, FAR const void *)); -#ifdef CONFIG_CAN_PASS_STRUCTS -struct mallinfo mallinfo(void); -#else -int mallinfo(struct mallinfo *info); -#endif +/* Binary search */ + +FAR void *bsearch(FAR const void *key, FAR const void *base, size_t nel, + size_t width, CODE int (*compar)(FAR const void *, + FAR const void *)); #undef EXTERN #if defined(__cplusplus) diff --git a/libc/stdlib/Make.defs b/libc/stdlib/Make.defs index 5f1b7a06a0..68eb75e68b 100644 --- a/libc/stdlib/Make.defs +++ b/libc/stdlib/Make.defs @@ -37,7 +37,7 @@ CSRCS += lib_abs.c lib_abort.c lib_div.c lib_ldiv.c lib_lldiv.c CSRCS += lib_imaxabs.c lib_itoa.c lib_labs.c lib_llabs.c -CSRCS += lib_rand.c lib_qsort.c +CSRCS += lib_bsearch.c lib_rand.c lib_qsort.c CSRCS += lib_strtol.c lib_strtoll.c lib_strtoul.c lib_strtoull.c CSRCS += lib_strtod.c lib_checkbase.c diff --git a/libc/stdlib/lib_bsearch.c b/libc/stdlib/lib_bsearch.c new file mode 100644 index 0000000000..538bac6a61 --- /dev/null +++ b/libc/stdlib/lib_bsearch.c @@ -0,0 +1,138 @@ +/***************************************************************************** + * libc/stdlib/lib_bsearch.c + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include +#include + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: bsearch + * + * Description: + * Per OpenGroup.org: + * + * The bsearch() function will search an array of nel objects, the initial + * element of which is pointed to by 'base', for an element that matches + * the object pointed to by 'key'. The size of each element in the array + * is specified by 'width'. If the nel argument has the value zero, the + * comparison function pointed to by 'compar' will not be called and no + * match will be found. + * + * The comparison function pointed to by 'compar' will be called with two + * arguments that point to the 'key' object and to an array element, in + * that order. + * + * The application will ensure that the comparison function pointed to by + * 'compar 'does not alter the contents of the array. The implementation + * may reorder elements of the array between calls to the comparison + * function, but will not alter the contents of any individual element. + * + * The implementation will ensure that the first argument is always a + * pointer to the 'key'. + * + * When the same objects (consisting of width bytes, irrespective of their + * current positions in the array) are passed more than once to the + * comparison function, the results will be consistent with one another. + * That is, the same object will always compare the same way with the key. + * + * The application will ensure that the function returns an integer less + * than, equal to, or greater than 0 if the key object is considered, + * respectively, to be less than, to match, or to be greater than the + * array element. The application will ensure that the array consists of + * all the elements that compare less than, all the elements that compare + * equal to, and all the elements that compare greater than the key + * object, in that order. + * + * Returned Value: + * The bsearch() function will return a pointer to a matching member of + * the array, or a null pointer if no match is found. If two or more + * members compare equal, which member is returned is unspecified. + * + * Notes from the NetBSD version: + * The code below is a bit sneaky. After a comparison fails, we divide + * the work in half by moving either left or right. If 'lim' is odd, + * moving left simply involves halving 'lim': e.g., when 'lim' is 5 we + * look at item 2, so we change 'lim' to 2 so that we will look at items + * 0 & 1. If 'lim' is even, the same applies. If 'lim' is odd, moving + * right again involes halving 'lim', this time moving the base up one + * item past 'ptr': e.g., when 'lim' is 5 we change base to item 3 and + * make 'lim' 2 so that we will look at items 3 and 4. If 'lim' is + * even, however, we have to shrink it by one before halving: e.g., + * when 'lim' is 4, we still looked at item 2, so we have to make 'lim' + * 3, then halve, obtaining 1, so that we will only look at item 3. + * + *****************************************************************************/ + +FAR void *bsearch(FAR const void *key, FAR const void *base, size_t nel, + size_t width, CODE int (*compar)(FAR const void *, + FAR const void *)) +{ + FAR const void *ptr; + size_t lim; + int cmp; + + DEBUGASSERT(key != NULL); + DEBUGASSERT(base != NULL || nel == 0); + DEBUGASSERT(compar != NULL); + + for (lim = nel; lim != 0; lim >>= 1) + { + ptr = base + (lim >> 1) * width; + cmp = (*compar)(key, ptr); + + if (cmp == 0) + { + return (FAR void *)ptr; + } + + if (cmp > 0) + { + /* key > ptr: move right (else move left) */ + + base = (FAR const char *)ptr + width; + lim--; + } + } + + return NULL; +} -- GitLab From 38e6142ae87af85def3de28222322425ea144b10 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 12:58:40 -0600 Subject: [PATCH 182/858] Make coding style more conformant, take description from OpenGroup.org, rename formal parameters to match names used on OpenGroup.org --- ChangeLog | 3 + include/stdlib.h | 2 +- libc/stdlib/lib_bsearch.c | 4 +- libc/stdlib/lib_qsort.c | 147 ++++++++++++++++++++++++++------------ 4 files changed, 108 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f35156b3e..e3968d2772 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11008,3 +11008,6 @@ * libc/stdlib/lib_bsearch.c and include/stdlib.h: Add the bsearch() function from NetBSD (2015-10-02). + * libc/stdlib/lib_qsort.c and include/stdlib.h: Make coding style + more conformant, take description from OpenGroup.org, rename formal + parameters to match names used on OpenGroup.org (2015-10-02). diff --git a/include/stdlib.h b/include/stdlib.h index fffcd83f8a..ff10da14c5 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -229,7 +229,7 @@ int mkstemp(FAR char *path_template); /* Sorting */ -void qsort(FAR void *base, size_t nmemb, size_t size, +void qsort(FAR void *base, size_t nel, size_t width, int (*compar)(FAR const void *, FAR const void *)); /* Binary search */ diff --git a/libc/stdlib/lib_bsearch.c b/libc/stdlib/lib_bsearch.c index 538bac6a61..c7c3dc5b60 100644 --- a/libc/stdlib/lib_bsearch.c +++ b/libc/stdlib/lib_bsearch.c @@ -49,8 +49,6 @@ * Name: bsearch * * Description: - * Per OpenGroup.org: - * * The bsearch() function will search an array of nel objects, the initial * element of which is pointed to by 'base', for an element that matches * the object pointed to by 'key'. The size of each element in the array @@ -83,6 +81,8 @@ * equal to, and all the elements that compare greater than the key * object, in that order. * + * (Based on description from OpenGroup.org). + * * Returned Value: * The bsearch() function will return a pointer to a matching member of * the array, or a null pointer if no match is found. If two or more diff --git a/libc/stdlib/lib_qsort.c b/libc/stdlib/lib_qsort.c index 8850f50c10..32f10c0469 100644 --- a/libc/stdlib/lib_qsort.c +++ b/libc/stdlib/lib_qsort.c @@ -58,8 +58,8 @@ #define swapcode(TYPE, parmi, parmj, n) \ { \ long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ + register TYPE *pi = (TYPE *)(parmi); \ + register TYPE *pj = (TYPE *)(parmj); \ do { \ register TYPE t = *pi; \ *pi++ = *pj; \ @@ -67,9 +67,9 @@ } while (--i > 0); \ } -#define SWAPINIT(a, size) \ - swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - size % sizeof(long) ? 2 : size == sizeof(long)? 0 : 1; +#define SWAPINIT(a, width) \ + swaptype = ((FAR char *)a - (FAR char *)0) % sizeof(long) || \ + width % sizeof(long) ? 2 : width == sizeof(long)? 0 : 1; #define swap(a, b) \ if (swaptype == 0) \ @@ -80,7 +80,7 @@ } \ else \ { \ - swapfunc(a, b, size, swaptype); \ + swapfunc(a, b, width, swaptype); \ } #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) @@ -89,15 +89,16 @@ * Private Function Prototypes ****************************************************************************/ -static inline void swapfunc(char *a, char *b, int n, int swaptype); -static inline char *med3(char *a, char *b, char *c, - int (*compar)(const void *, const void *)); +static inline void swapfunc(FAR char *a, FAR char *b, int n, int swaptype); +static inline FAR char *med3(FAR char *a, FAR char *b, FAR char *c, + CODE int (*compar)(FAR const void *, + FAR const void *)); /**************************************************************************** * Private Functions ****************************************************************************/ -static inline void swapfunc(char *a, char *b, int n, int swaptype) +static inline void swapfunc(FAR char *a, FAR char *b, int n, int swaptype) { if (swaptype <= 1) { @@ -109,8 +110,9 @@ static inline void swapfunc(char *a, char *b, int n, int swaptype) } } -static inline char *med3(char *a, char *b, char *c, - int (*compar)(const void *, const void *)) +static inline FAR char *med3(FAR char *a, FAR char *b, FAR char *c, + CODE int (*compar)(FAR const void *, + FAR const void *)) { return compar(a, b) < 0 ? (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a )) @@ -125,49 +127,97 @@ static inline char *med3(char *a, char *b, char *c, * Name: qsort * * Description: + * The qsort() function will sort an array of 'nel' objects, the initial + * element of which is pointed to by 'base'. The size of each object, in + * bytes, is specified by the 'width" argument. If the 'nel' argument has + * the value zero, the comparison function pointed to by 'compar' will not + * be called and no rearrangement will take place. + * + * The application will ensure that the comparison function pointed to by + * 'compar' does not alter the contents of the array. The implementation + * may reorder elements of the array between calls to the comparison + * function, but will not alter the contents of any individual element. + * + * When the same objects (consisting of 'width" bytes, irrespective of + * their current positions in the array) are passed more than once to + * the comparison function, the results will be consistent with one + * another. That is, they will define a total ordering on the array. + * + * The contents of the array will be sorted in ascending order according + * to a comparison function. The 'compar' argument is a pointer to the + * comparison function, which is called with two arguments that point to + * the elements being compared. The application will ensure that the + * function returns an integer less than, equal to, or greater than 0, + * if the first argument is considered respectively less than, equal to, + * or greater than the second. If two members compare as equal, their + * order in the sorted array is unspecified. + * + * (Based on description from OpenGroup.org). + * + * Returned Value: + * The qsort() function will not return a value. + * + * Notes from the original BSD version: * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". * ****************************************************************************/ -void qsort(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)) +void qsort(FAR void *base, size_t nel, size_t width, + CODE int(*compar)(FAR const void *, FAR const void *)) { - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; + FAR char *pa; + FAR char *pb; + FAR char *pc; + FAR char *pd; + FAR char *pl; + FAR char *pm; + FAR char *pn; + int swaptype; + int swap_cnt; + int d; + int r; loop: - SWAPINIT(base, size); + SWAPINIT(base, width); swap_cnt = 0; - if (nmemb < 7) + + if (nel < 7) { - for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) + for (pm = (FAR char *)base + width; + pm < (FAR char *)base + nel * width; + pm += width) { - for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) + for (pl = pm; + pl > (FAR char *)base && compar(pl - width, pl) > 0; + pl -= width) { - swap(pl, pl - size); + swap(pl, pl - width); } } + return; } - pm = (char *) base + (nmemb / 2) * size; - if (nmemb > 7) + pm = (FAR char *)base + (nel / 2) * width; + if (nel > 7) { pl = base; - pn = (char *) base + (nmemb - 1) * size; - if (nmemb > 40) + pn = (FAR char *)base + (nel - 1) * width; + if (nel > 40) { - d = (nmemb / 8) * size; + d = (nel / 8) * width; pl = med3(pl, pl + d, pl + 2 * d, compar); pm = med3(pm - d, pm, pm + d, compar); pn = med3(pn - 2 * d, pn - d, pn, compar); } + pm = med3(pl, pm, pn, compar); } + swap(base, pm); - pa = pb = (char *) base + size; + pa = pb = (FAR char *)base + width; - pc = pd = (char *) base + (nmemb - 1) * size; + pc = pd = (FAR char *)base + (nel - 1) * width; for (;;) { while (pb <= pc && (r = compar(pb, base)) <= 0) @@ -176,19 +226,22 @@ loop: { swap_cnt = 1; swap(pa, pb); - pa += size; + pa += width; } - pb += size; + + pb += width; } + while (pb <= pc && (r = compar(pc, base)) >= 0) { if (r == 0) { swap_cnt = 1; swap(pc, pd); - pd -= size; + pd -= width; } - pc -= size; + + pc -= width; } if (pb > pc) @@ -198,43 +251,47 @@ loop: swap(pb, pc); swap_cnt = 1; - pb += size; - pc -= size; + pb += width; + pc -= width; } if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) + for (pm = (FAR char *)base + width; + pm < (FAR char *)base + nel * width; + pm += width) { - for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) + for (pl = pm; + pl > (FAR char *)base && compar(pl - width, pl) > 0; + pl -= width) { - swap(pl, pl - size); + swap(pl, pl - width); } } return; } - pn = (char *) base + nmemb * size; - r = min(pa - (char *)base, pb - pa); + pn = (FAR char *)base + nel * width; + r = min(pa - (FAR char *)base, pb - pa); vecswap(base, pb - r, r); - r = min(pd - pc, pn - pd - size); + + r = min(pd - pc, pn - pd - width); vecswap(pb, pn - r, r); - if ((r = pb - pa) > size) + if ((r = pb - pa) > width) { - qsort(base, r / size, size, compar); + qsort(base, r / width, width, compar); } - if ((r = pd - pc) > size) + if ((r = pd - pc) > width) { /* Iterate rather than recurse to save stack space */ base = pn - r; - nmemb = r / size; + nel = r / width; goto loop; } } - -- GitLab From ac394041bfda7e919715540464e590f886b63f56 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 14:17:29 -0600 Subject: [PATCH 183/858] Standardize nameing of the pre-processor definitiongs group header --- arch | 2 +- configs | 2 +- drivers/lcd/pcf8833.h | 2 +- drivers/lcd/s1d15g10.h | 2 +- libnx/nxcontext.h | 2 +- libnx/nxtk/nxtk_events.c | 2 +- libnx/nxtk/nxtk_setsubwindows.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch b/arch index 228b63193d..8cd57d72bc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 228b63193d95433f447d9385847e93d86d595352 +Subproject commit 8cd57d72bc48ab44b21fa36aa117367c2e8d0129 diff --git a/configs b/configs index 5c519b6b0a..7e3617b292 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 5c519b6b0a7a28e785266190874adf297322589d +Subproject commit 7e3617b29222394a5bcc1f20dab7ab9c8a35cda1 diff --git a/drivers/lcd/pcf8833.h b/drivers/lcd/pcf8833.h index 36dc65ac3f..bc58ea6f5a 100644 --- a/drivers/lcd/pcf8833.h +++ b/drivers/lcd/pcf8833.h @@ -149,4 +149,4 @@ /* Byte 4: All zero */ -#endif /* __DRIVERS_LCD_PCF8833_H */ \ No newline at end of file +#endif /* __DRIVERS_LCD_PCF8833_H */ diff --git a/drivers/lcd/s1d15g10.h b/drivers/lcd/s1d15g10.h index 9b5f7738fe..09cd7286dc 100644 --- a/drivers/lcd/s1d15g10.h +++ b/drivers/lcd/s1d15g10.h @@ -138,4 +138,4 @@ #define S1D15G10_SR_RRATIO 0x07 /* Bits 0-2: Built-in resistance ratio */ -#endif /* __DRIVERS_LCD_S1D15G10_H */ \ No newline at end of file +#endif /* __DRIVERS_LCD_S1D15G10_H */ diff --git a/libnx/nxcontext.h b/libnx/nxcontext.h index 95fdf7a82e..16ec327628 100644 --- a/libnx/nxcontext.h +++ b/libnx/nxcontext.h @@ -51,7 +51,7 @@ #include /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* The NuttX NX library an be build in two modes: (1) as a standard, C-library diff --git a/libnx/nxtk/nxtk_events.c b/libnx/nxtk/nxtk_events.c index d22d04aa85..33d496e19a 100644 --- a/libnx/nxtk/nxtk_events.c +++ b/libnx/nxtk/nxtk_events.c @@ -51,7 +51,7 @@ #include "nxtk_internal.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/libnx/nxtk/nxtk_setsubwindows.c b/libnx/nxtk/nxtk_setsubwindows.c index e528f43e9a..5ebd5f2be7 100644 --- a/libnx/nxtk/nxtk_setsubwindows.c +++ b/libnx/nxtk/nxtk_setsubwindows.c @@ -48,7 +48,7 @@ #include "nxtk_internal.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** -- GitLab From cb9e27c3b07f13404cdf37a00a162c9c7e862e47 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 16:30:35 -0600 Subject: [PATCH 184/858] Standardize naming used for public data and function groupings --- binfmt/binfmt_execsymtab.c | 2 +- drivers/bch/bch_internal.h | 2 +- drivers/mtd/mtd_procfs.c | 2 +- drivers/rwbuffer.c | 2 +- fs/binfs/fs_binfs.c | 2 +- fs/driver/driver.h | 2 +- fs/driver/fs_registerblockdriver.c | 2 +- fs/driver/fs_registerdriver.c | 2 +- fs/driver/fs_unregisterblockdriver.c | 2 +- fs/driver/fs_unregisterdriver.c | 2 +- fs/fat/fs_configfat.c | 2 +- fs/fat/fs_fat32.c | 2 +- fs/fat/fs_fat32.h | 2 +- fs/fat/fs_fat32attrib.c | 2 +- fs/fat/fs_fat32dirent.c | 2 +- fs/fat/fs_fat32util.c | 2 +- fs/fat/fs_mkfatfs.h | 2 +- fs/fat/fs_writefat.c | 2 +- fs/inode/fs_inode.c | 2 +- fs/inode/fs_inodeaddref.c | 2 +- fs/inode/fs_inodebasename.c | 2 +- fs/inode/fs_inodefind.c | 2 +- fs/inode/fs_inoderelease.c | 2 +- fs/inode/fs_inoderemove.c | 2 +- fs/inode/fs_inodereserve.c | 2 +- fs/inode/inode.h | 2 +- fs/mmap/fs_mmap.c | 2 +- fs/mmap/fs_munmap.c | 2 +- fs/mmap/fs_rammap.c | 4 ++-- fs/mmap/fs_rammap.h | 2 +- fs/mount/fs_mount.c | 2 +- fs/mount/fs_umount2.c | 2 +- fs/mqueue/mq_close.c | 2 +- fs/mqueue/mq_open.c | 2 +- fs/mqueue/mq_unlink.c | 2 +- fs/mqueue/mqueue.h | 2 +- fs/nfs/nfs_util.c | 2 +- fs/nfs/nfs_vfsops.c | 2 +- fs/nxffs/nxffs.h | 2 +- fs/nxffs/nxffs_block.c | 2 +- fs/nxffs/nxffs_blockstats.c | 2 +- fs/nxffs/nxffs_cache.c | 2 +- fs/nxffs/nxffs_dirent.c | 2 +- fs/nxffs/nxffs_initialize.c | 2 +- fs/nxffs/nxffs_inode.c | 2 +- fs/nxffs/nxffs_ioctl.c | 2 +- fs/nxffs/nxffs_pack.c | 2 +- fs/nxffs/nxffs_read.c | 2 +- fs/nxffs/nxffs_reformat.c | 2 +- fs/nxffs/nxffs_stat.c | 2 +- fs/nxffs/nxffs_unlink.c | 2 +- fs/nxffs/nxffs_util.c | 2 +- fs/procfs/fs_procfs.c | 2 +- fs/procfs/fs_procfscpuload.c | 2 +- fs/procfs/fs_procfsproc.c | 2 +- fs/procfs/fs_procfsuptime.c | 2 +- fs/procfs/fs_skeleton.c | 2 +- fs/romfs/fs_romfs.c | 2 +- fs/romfs/fs_romfs.h | 2 +- fs/romfs/fs_romfsutil.c | 2 +- fs/semaphore/sem_close.c | 2 +- fs/semaphore/sem_open.c | 2 +- fs/semaphore/sem_unlink.c | 2 +- fs/semaphore/semaphore.h | 2 +- fs/smartfs/smartfs.h | 2 +- fs/smartfs/smartfs_procfs.c | 2 +- fs/smartfs/smartfs_smart.c | 2 +- fs/smartfs/smartfs_utils.c | 2 +- fs/vfs/fs_close.c | 2 +- fs/vfs/fs_dup.c | 2 +- fs/vfs/fs_dup2.c | 2 +- fs/vfs/fs_dupfd2.c | 2 +- fs/vfs/fs_fsync.c | 2 +- fs/vfs/fs_ioctl.c | 2 +- fs/vfs/fs_mkdir.c | 2 +- fs/vfs/fs_rename.c | 2 +- fs/vfs/fs_rmdir.c | 2 +- fs/vfs/fs_sendfile.c | 2 +- fs/vfs/fs_stat.c | 2 +- fs/vfs/fs_unlink.c | 2 +- graphics/nxterm/nxterm.h | 2 +- include/debug.h | 2 +- include/dirent.h | 2 +- include/nuttx/arch.h | 2 +- include/nuttx/compiler.h | 4 ++-- include/nuttx/fs/dirent.h | 2 +- include/nuttx/fs/fs.h | 2 +- include/nuttx/fs/mkfatfs.h | 2 +- include/nuttx/fs/mksmartfs.h | 2 +- include/nuttx/init.h | 4 ++-- include/nuttx/irq.h | 2 +- include/nuttx/mqueue.h | 6 +++--- include/nuttx/net/iob.h | 2 +- include/nuttx/net/netdev.h | 2 +- include/nuttx/rwbuffer.h | 4 ++-- include/nuttx/streams.h | 2 +- include/poll.h | 2 +- include/semaphore.h | 2 +- include/stdio.h | 2 +- include/sys/stat.h | 2 +- include/sys/types.h | 2 +- include/syslog.h | 2 +- libc/aio/aio.h | 2 +- libc/aio/aio_error.c | 2 +- libc/aio/aio_return.c | 2 +- libc/aio/aio_suspend.c | 2 +- libc/aio/lio_listio.c | 2 +- libc/audio/lib_buffer.c | 2 +- libc/fixedmath/lib_b16atan2.c | 2 +- libc/fixedmath/lib_b16cos.c | 2 +- libc/fixedmath/lib_b16sin.c | 2 +- libc/libgen/lib_basename.c | 2 +- libc/libgen/lib_dirname.c | 2 +- libc/math/lib_rint.c | 4 ++-- libc/math/lib_rintf.c | 4 ++-- libc/math/lib_rintl.c | 4 ++-- libc/misc/lib_filesem.c | 2 +- libc/misc/lib_sendfile.c | 2 +- libc/misc/lib_streamsem.c | 2 +- libc/net/lib_addroute.c | 2 +- libc/net/lib_delroute.c | 2 +- libc/net/lib_etherntoa.c | 2 +- libc/net/lib_htonl.c | 2 +- libc/net/lib_htons.c | 2 +- libc/net/lib_inetntoa.c | 2 +- libc/pthread/pthread_attrdestroy.c | 2 +- libc/pthread/pthread_attrgetinheritsched.c | 2 +- libc/pthread/pthread_attrgetschedpolicy.c | 2 +- libc/pthread/pthread_attrgetstacksize.c | 2 +- libc/pthread/pthread_attrinit.c | 2 +- libc/pthread/pthread_attrsetinheritsched.c | 2 +- libc/pthread/pthread_attrsetstacksize.c | 2 +- libc/pthread/pthread_barrierattrdestroy.c | 2 +- libc/pthread/pthread_barrierattrgetpshared.c | 2 +- libc/pthread/pthread_barrierattrinit.c | 2 +- libc/pthread/pthread_barrierattrsetpshared.c | 2 +- libc/pthread/pthread_condattrdestroy.c | 2 +- libc/pthread/pthread_condattrinit.c | 2 +- libc/pthread/pthread_mutexattrdestroy.c | 2 +- libc/pthread/pthread_mutexattrgetpshared.c | 2 +- libc/pthread/pthread_mutexattrgettype.c | 2 +- libc/pthread/pthread_mutexattrinit.c | 2 +- libc/pthread/pthread_mutexattrsetpshared.c | 2 +- libc/pthread/pthread_mutexattrsettype.c | 2 +- libc/pthread/pthread_startup.c | 2 +- libc/sched/task_startup.c | 2 +- libc/semaphore/sem_getvalue.c | 2 +- libc/semaphore/sem_init.c | 2 +- libc/signal/sig_fillset.c | 2 +- libc/signal/sig_ismember.c | 2 +- libc/spawn/lib_psa_dump.c | 2 +- libc/spawn/lib_psa_getflags.c | 2 +- libc/spawn/lib_psa_getschedparam.c | 2 +- libc/spawn/lib_psa_getschedpolicy.c | 2 +- libc/spawn/lib_psa_getsigmask.c | 2 +- libc/spawn/lib_psa_setflags.c | 2 +- libc/spawn/lib_psa_setschedpolicy.c | 2 +- libc/spawn/lib_psa_setsigmask.c | 2 +- libc/spawn/lib_psfa_addaction.c | 2 +- libc/spawn/lib_psfa_addclose.c | 2 +- libc/spawn/lib_psfa_adddup2.c | 2 +- libc/spawn/lib_psfa_addopen.c | 2 +- libc/spawn/lib_psfa_destroy.c | 2 +- libc/spawn/lib_psfa_init.c | 2 +- libc/stdio/lib_asprintf.c | 6 +++--- libc/stdio/lib_fclose.c | 2 +- libc/stdio/lib_fflush.c | 6 +++--- libc/stdio/lib_fgetc.c | 8 ++++---- libc/stdio/lib_fgetpos.c | 4 ++-- libc/stdio/lib_fileno.c | 2 +- libc/stdio/lib_fprintf.c | 4 ++-- libc/stdio/lib_fputc.c | 8 ++++---- libc/stdio/lib_fputs.c | 6 +++--- libc/stdio/lib_fread.c | 4 ++-- libc/stdio/lib_fseek.c | 4 ++-- libc/stdio/lib_fsetpos.c | 4 ++-- libc/stdio/lib_ftell.c | 4 ++-- libc/stdio/lib_fwrite.c | 4 ++-- libc/stdio/lib_libdtoa.c | 4 ++-- libc/stdio/lib_libfflush.c | 4 ++-- libc/stdio/lib_libflushall.c | 6 +++--- libc/stdio/lib_libfread.c | 4 ++-- libc/stdio/lib_libfwrite.c | 4 ++-- libc/stdio/lib_libnoflush.c | 6 +++--- libc/stdio/lib_libsnoflush.c | 6 +++--- libc/stdio/lib_libsprintf.c | 4 ++-- libc/stdio/lib_libvsprintf.c | 4 ++-- libc/stdio/lib_printf.c | 8 ++++---- libc/stdio/lib_puts.c | 4 ++-- libc/stdio/lib_rdflush.c | 6 +++--- libc/stdio/lib_snprintf.c | 6 +++--- libc/stdio/lib_sprintf.c | 6 +++--- libc/stdio/lib_sscanf.c | 6 +++--- libc/stdio/lib_ungetc.c | 6 +++--- libc/stdio/lib_vasprintf.c | 6 +++--- libc/stdio/lib_vfprintf.c | 4 ++-- libc/stdio/lib_vprintf.c | 6 +++--- libc/stdio/lib_vsnprintf.c | 4 ++-- libc/stdio/lib_vsprintf.c | 4 ++-- libc/stdio/lib_wrflush.c | 4 ++-- libc/stdlib/lib_abort.c | 2 +- libc/stdlib/lib_abs.c | 2 +- libc/stdlib/lib_imaxabs.c | 2 +- libc/stdlib/lib_itoa.c | 2 +- libc/stdlib/lib_labs.c | 2 +- libc/stdlib/lib_llabs.c | 2 +- libc/string/lib_memccpy.c | 2 +- libc/string/lib_memchr.c | 2 +- libc/string/lib_memcmp.c | 2 +- libc/string/lib_memcpy.c | 2 +- libc/string/lib_memmove.c | 2 +- libc/string/lib_memset.c | 2 +- libc/string/lib_strcasestr.c | 2 +- libc/string/lib_strcat.c | 2 +- libc/string/lib_strchr.c | 2 +- libc/string/lib_strcspn.c | 2 +- libc/string/lib_strdup.c | 2 +- libc/string/lib_strlen.c | 2 +- libc/string/lib_strncasecmp.c | 2 +- libc/string/lib_strncat.c | 2 +- libc/string/lib_strncmp.c | 2 +- libc/string/lib_strndup.c | 2 +- libc/string/lib_strnlen.c | 2 +- libc/string/lib_strpbrk.c | 2 +- libc/string/lib_strrchr.c | 2 +- libc/string/lib_strspn.c | 2 +- libc/string/lib_strstr.c | 2 +- libc/syslog/lib_lowsyslog.c | 6 +++--- libc/syslog/lib_syslog.c | 6 +++--- libc/termios/lib_cfgetspeed.c | 2 +- libc/termios/lib_cfsetspeed.c | 2 +- libc/termios/lib_tcflush.c | 2 +- libc/termios/lib_tcgetattr.c | 2 +- libc/termios/lib_tcsetattr.c | 2 +- libc/time/lib_calendar2utc.c | 2 +- libc/time/lib_dayofweek.c | 2 +- libc/time/lib_daysbeforemonth.c | 2 +- libc/time/lib_gmtime.c | 2 +- libc/time/lib_gmtimer.c | 2 +- libc/time/lib_isleapyear.c | 2 +- libc/time/lib_mktime.c | 2 +- libc/unistd/lib_access.c | 2 +- libc/unistd/lib_chdir.c | 2 +- libc/unistd/lib_execl.c | 4 ++-- libc/unistd/lib_getcwd.c | 2 +- libc/unistd/lib_getopt.c | 4 ++-- libc/unistd/lib_getoptargp.c | 4 ++-- libc/unistd/lib_getoptindp.c | 4 ++-- libc/unistd/lib_getoptoptp.c | 4 ++-- libc/unistd/lib_sleep.c | 2 +- libc/unistd/lib_usleep.c | 2 +- libc/wqueue/work_cancel.c | 2 +- libc/wqueue/work_lock.c | 2 +- libc/wqueue/work_queue.c | 2 +- libc/wqueue/work_signal.c | 2 +- libnx/nxcontext.h | 2 +- mm/mm_gran/mm_granalloc.c | 2 +- mm/mm_gran/mm_granfree.c | 2 +- mm/mm_heap/mm_addfreechunk.c | 2 +- mm/mm_heap/mm_initialize.c | 2 +- mm/mm_heap/mm_shrinkchunk.c | 2 +- net/devif/devif_initialize.c | 2 +- net/devif/devif_iobsend.c | 2 +- net/devif/devif_pktsend.c | 2 +- net/devif/devif_send.c | 2 +- net/icmp/icmp_ping.c | 2 +- net/icmp/icmp_poll.c | 2 +- net/icmp/icmp_send.c | 2 +- net/icmpv6/icmpv6_ping.c | 2 +- net/icmpv6/icmpv6_poll.c | 2 +- net/igmp/igmp_send.c | 2 +- net/pkt/pkt_input.c | 2 +- net/pkt/pkt_poll.c | 2 +- net/socket/socket.h | 2 +- net/tcp/tcp_appsend.c | 2 +- net/tcp/tcp_devpoll.c | 2 +- net/tcp/tcp_input.c | 2 +- net/tcp/tcp_send.c | 2 +- net/tcp/tcp_timer.c | 2 +- net/udp/udp_devpoll.c | 2 +- net/udp/udp_input.c | 2 +- net/udp/udp_send.c | 2 +- sched/clock/clock.h | 2 +- sched/clock/clock_abstime2ticks.c | 2 +- sched/clock/clock_getres.c | 2 +- sched/clock/clock_gettime.c | 2 +- sched/clock/clock_initialize.c | 2 +- sched/clock/clock_settime.c | 2 +- sched/clock/clock_ticks2time.c | 2 +- sched/clock/clock_time2ticks.c | 2 +- sched/environ/environ.h | 2 +- sched/group/group_free.c | 2 +- sched/group/group_malloc.c | 2 +- sched/group/group_zalloc.c | 2 +- sched/init/init.h | 2 +- sched/init/os_start.c | 2 +- sched/irq/irq.h | 2 +- sched/irq/irq_attach.c | 2 +- sched/irq/irq_dispatch.c | 2 +- sched/irq/irq_initialize.c | 2 +- sched/irq/irq_unexpectedisr.c | 2 +- sched/mqueue/mq_desclose.c | 2 +- sched/mqueue/mq_descreate.c | 2 +- sched/mqueue/mq_initialize.c | 2 +- sched/mqueue/mq_msgfree.c | 2 +- sched/mqueue/mq_msgqalloc.c | 2 +- sched/mqueue/mq_msgqfree.c | 2 +- sched/mqueue/mq_notify.c | 2 +- sched/mqueue/mq_rcvinternal.c | 2 +- sched/mqueue/mq_receive.c | 2 +- sched/mqueue/mq_recover.c | 2 +- sched/mqueue/mq_release.c | 2 +- sched/mqueue/mq_send.c | 2 +- sched/mqueue/mq_sndinternal.c | 2 +- sched/mqueue/mq_timedreceive.c | 2 +- sched/mqueue/mq_timedsend.c | 2 +- sched/mqueue/mq_waitirq.c | 2 +- sched/mqueue/mqueue.h | 2 +- sched/paging/pg_miss.c | 2 +- sched/paging/pg_worker.c | 2 +- sched/pthread/pthread.h | 2 +- sched/pthread/pthread_barrierdestroy.c | 2 +- sched/pthread/pthread_barrierinit.c | 2 +- sched/pthread/pthread_barrierwait.c | 2 +- sched/pthread/pthread_cancel.c | 2 +- sched/pthread/pthread_completejoin.c | 2 +- sched/pthread/pthread_condbroadcast.c | 2 +- sched/pthread/pthread_conddestroy.c | 2 +- sched/pthread/pthread_condinit.c | 2 +- sched/pthread/pthread_condsignal.c | 2 +- sched/pthread/pthread_condtimedwait.c | 2 +- sched/pthread/pthread_condwait.c | 2 +- sched/pthread/pthread_detach.c | 2 +- sched/pthread/pthread_exit.c | 2 +- sched/pthread/pthread_findjoininfo.c | 2 +- sched/pthread/pthread_getschedparam.c | 2 +- sched/pthread/pthread_getspecific.c | 2 +- sched/pthread/pthread_initialize.c | 2 +- sched/pthread/pthread_join.c | 2 +- sched/pthread/pthread_keycreate.c | 2 +- sched/pthread/pthread_keydelete.c | 2 +- sched/pthread/pthread_mutexdestroy.c | 2 +- sched/pthread/pthread_mutexinit.c | 2 +- sched/pthread/pthread_mutexlock.c | 2 +- sched/pthread/pthread_mutextrylock.c | 2 +- sched/pthread/pthread_mutexunlock.c | 2 +- sched/pthread/pthread_once.c | 2 +- sched/pthread/pthread_release.c | 2 +- sched/pthread/pthread_setcancelstate.c | 2 +- sched/pthread/pthread_setschedparam.c | 2 +- sched/pthread/pthread_setschedprio.c | 2 +- sched/pthread/pthread_setspecific.c | 2 +- sched/pthread/pthread_sigmask.c | 2 +- sched/pthread/pthread_yield.c | 2 +- sched/sched/sched.h | 2 +- sched/sched/sched_addblocked.c | 2 +- sched/sched/sched_addprioritized.c | 2 +- sched/sched/sched_addreadytorun.c | 2 +- sched/sched/sched_cpuload.c | 2 +- sched/sched/sched_free.c | 2 +- sched/sched/sched_garbage.c | 2 +- sched/sched/sched_getparam.c | 2 +- sched/sched/sched_getscheduler.c | 2 +- sched/sched/sched_gettcb.c | 2 +- sched/sched/sched_lock.c | 2 +- sched/sched/sched_lockcount.c | 2 +- sched/sched/sched_mergepending.c | 2 +- sched/sched/sched_processtimer.c | 2 +- sched/sched/sched_removeblocked.c | 2 +- sched/sched/sched_removereadytorun.c | 2 +- sched/sched/sched_reprioritize.c | 2 +- sched/sched/sched_self.c | 2 +- sched/sched/sched_setpriority.c | 2 +- sched/sched/sched_verifytcb.c | 2 +- sched/sched/sched_yield.c | 2 +- sched/semaphore/sem_destroy.c | 2 +- sched/semaphore/sem_holder.c | 2 +- sched/semaphore/sem_post.c | 2 +- sched/semaphore/sem_recover.c | 2 +- sched/semaphore/sem_trywait.c | 2 +- sched/semaphore/sem_wait.c | 2 +- sched/semaphore/semaphore.h | 2 +- sched/signal/sig_action.c | 2 +- sched/signal/sig_allocatependingsigaction.c | 2 +- sched/signal/sig_cleanup.c | 2 +- sched/signal/sig_deliver.c | 2 +- sched/signal/sig_dispatch.c | 2 +- sched/signal/sig_findaction.c | 2 +- sched/signal/sig_initialize.c | 2 +- sched/signal/sig_kill.c | 2 +- sched/signal/sig_lowest.c | 2 +- sched/signal/sig_mqnotempty.c | 2 +- sched/signal/sig_nanosleep.c | 2 +- sched/signal/sig_pause.c | 2 +- sched/signal/sig_pending.c | 2 +- sched/signal/sig_procmask.c | 2 +- sched/signal/sig_queue.c | 2 +- sched/signal/sig_releasependingsigaction.c | 2 +- sched/signal/sig_releasependingsignal.c | 2 +- sched/signal/sig_removependingsignal.c | 2 +- sched/signal/sig_suspend.c | 2 +- sched/signal/sig_timedwait.c | 2 +- sched/signal/sig_unmaskpendingsignal.c | 2 +- sched/signal/sig_waitinfo.c | 2 +- sched/signal/signal.h | 2 +- sched/task/exit.c | 2 +- sched/task/task.h | 2 +- sched/task/task_activate.c | 2 +- sched/task/task_atexit.c | 2 +- sched/task/task_create.c | 2 +- sched/task/task_delete.c | 2 +- sched/task/task_exit.c | 2 +- sched/task/task_exithook.c | 2 +- sched/task/task_getpid.c | 2 +- sched/task/task_init.c | 2 +- sched/task/task_onexit.c | 2 +- sched/task/task_restart.c | 2 +- sched/task/task_setup.c | 2 +- sched/task/task_start.c | 2 +- sched/task/task_starthook.c | 2 +- sched/task/task_terminate.c | 2 +- sched/wdog/wd_cancel.c | 2 +- sched/wdog/wd_create.c | 2 +- sched/wdog/wd_delete.c | 2 +- sched/wdog/wd_gettime.c | 2 +- sched/wdog/wd_initialize.c | 2 +- sched/wdog/wd_recover.c | 2 +- sched/wdog/wd_start.c | 2 +- sched/wdog/wdog.h | 2 +- sched/wqueue/kwork_cancel.c | 2 +- sched/wqueue/kwork_queue.c | 2 +- sched/wqueue/kwork_signal.c | 2 +- 432 files changed, 503 insertions(+), 503 deletions(-) diff --git a/binfmt/binfmt_execsymtab.c b/binfmt/binfmt_execsymtab.c index 63fa14adb2..ceb532d94c 100644 --- a/binfmt/binfmt_execsymtab.c +++ b/binfmt/binfmt_execsymtab.c @@ -68,7 +68,7 @@ #endif /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB diff --git a/drivers/bch/bch_internal.h b/drivers/bch/bch_internal.h index dabd2f5c50..3a12c50c9b 100644 --- a/drivers/bch/bch_internal.h +++ b/drivers/bch/bch_internal.h @@ -77,7 +77,7 @@ struct bchlib_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/drivers/mtd/mtd_procfs.c b/drivers/mtd/mtd_procfs.c index fd27917e0c..2a2137a098 100644 --- a/drivers/mtd/mtd_procfs.c +++ b/drivers/mtd/mtd_procfs.c @@ -97,7 +97,7 @@ static int mtd_stat(FAR const char *relpath, FAR struct stat *buf); ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index 9c443df7b5..584b25b091 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 52a801560f..5e5a09f576 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -97,7 +97,7 @@ static int binfs_stat(FAR struct inode *mountpt, FAR const char *relpath, ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly extern'ed there. diff --git a/fs/driver/driver.h b/fs/driver/driver.h index 02e98b071a..066d3ebd64 100644 --- a/fs/driver/driver.h +++ b/fs/driver/driver.h @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/fs/driver/fs_registerblockdriver.c b/fs/driver/fs_registerblockdriver.c index e0032b581a..ddcaef3671 100644 --- a/fs/driver/fs_registerblockdriver.c +++ b/fs/driver/fs_registerblockdriver.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_registerdriver.c b/fs/driver/fs_registerdriver.c index 5d8269c25b..6d60aeaf5c 100644 --- a/fs/driver/fs_registerdriver.c +++ b/fs/driver/fs_registerdriver.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_unregisterblockdriver.c b/fs/driver/fs_unregisterblockdriver.c index 1669a4d4ed..f032d1b347 100644 --- a/fs/driver/fs_unregisterblockdriver.c +++ b/fs/driver/fs_unregisterblockdriver.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_unregisterdriver.c b/fs/driver/fs_unregisterdriver.c index 96e9e9bae1..cd28debe50 100644 --- a/fs/driver/fs_unregisterdriver.c +++ b/fs/driver/fs_unregisterdriver.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_configfat.c b/fs/fat/fs_configfat.c index 59e174ef58..8fe7c576f2 100644 --- a/fs/fat/fs_configfat.c +++ b/fs/fat/fs_configfat.c @@ -853,7 +853,7 @@ mkfatfs_clustersearch(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var) } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index f993e7d6d6..e4dfbe19b8 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -122,7 +122,7 @@ static int fat_stat(struct inode *mountpt, const char *relpath, ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly extern'ed there. diff --git a/fs/fat/fs_fat32.h b/fs/fat/fs_fat32.h index cfb97f37d8..c3581e78ef 100644 --- a/fs/fat/fs_fat32.h +++ b/fs/fat/fs_fat32.h @@ -847,7 +847,7 @@ struct fat_dirinfo_s #endif /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32attrib.c b/fs/fat/fs_fat32attrib.c index b79e5275eb..1880dc6819 100644 --- a/fs/fat/fs_fat32attrib.c +++ b/fs/fat/fs_fat32attrib.c @@ -166,7 +166,7 @@ errout: } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c index c52de5e86a..4a46ecab95 100644 --- a/fs/fat/fs_fat32dirent.c +++ b/fs/fat/fs_fat32dirent.c @@ -160,7 +160,7 @@ static int fat_putsfdirentry(struct fat_mountpt_s *fs, ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c index ac2f53365c..07a31d2b89 100644 --- a/fs/fat/fs_fat32util.c +++ b/fs/fat/fs_fat32util.c @@ -80,7 +80,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_mkfatfs.h b/fs/fat/fs_mkfatfs.h index d9212b1e4b..1e1fc05e15 100644 --- a/fs/fat/fs_mkfatfs.h +++ b/fs/fat/fs_mkfatfs.h @@ -110,7 +110,7 @@ struct fat_var_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_writefat.c b/fs/fat/fs_writefat.c index f994d49efe..c784a35f6f 100644 --- a/fs/fat/fs_writefat.c +++ b/fs/fat/fs_writefat.c @@ -498,7 +498,7 @@ static inline int mkfatfs_writerootdir(FAR struct fat_format_s *fmt, } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c index c16d35bcc4..d5d58102ea 100644 --- a/fs/inode/fs_inode.c +++ b/fs/inode/fs_inode.c @@ -79,7 +79,7 @@ struct inode_sem_s static struct inode_sem_s g_inode_sem; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ FAR struct inode *g_root_inode = NULL; diff --git a/fs/inode/fs_inodeaddref.c b/fs/inode/fs_inodeaddref.c index 493c81e297..7378dc15be 100644 --- a/fs/inode/fs_inodeaddref.c +++ b/fs/inode/fs_inodeaddref.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inodebasename.c b/fs/inode/fs_inodebasename.c index 517d968d2b..afd1e56592 100644 --- a/fs/inode/fs_inodebasename.c +++ b/fs/inode/fs_inodebasename.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inodefind.c b/fs/inode/fs_inodefind.c index 7534a3441d..a2b761a233 100644 --- a/fs/inode/fs_inodefind.c +++ b/fs/inode/fs_inodefind.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inoderelease.c b/fs/inode/fs_inoderelease.c index e459fddd07..d4044e3b4d 100644 --- a/fs/inode/fs_inoderelease.c +++ b/fs/inode/fs_inoderelease.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c index ac76a20594..76fcd62c0f 100644 --- a/fs/inode/fs_inoderemove.c +++ b/fs/inode/fs_inoderemove.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index faa6c01237..a241cef0e4 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/inode.h b/fs/inode/inode.h index a76b1b22fa..3437c3858b 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -111,7 +111,7 @@ typedef int (*foreach_inode_t)(FAR struct inode *node, FAR void *arg); /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index 762b0d8325..0cb6f5db58 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -50,7 +50,7 @@ #include "fs_rammap.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/mmap/fs_munmap.c b/fs/mmap/fs_munmap.c index ecd0e6d71f..04800d35ac 100644 --- a/fs/mmap/fs_munmap.c +++ b/fs/mmap/fs_munmap.c @@ -55,7 +55,7 @@ #ifdef CONFIG_FS_RAMMAP /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index e0b32504fd..2aaced1d0d 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -55,7 +55,7 @@ #ifdef CONFIG_FS_RAMMAP /**************************************************************************** - * Global Data + * Public Data ****************************************************************************/ /* This is the list of all mapped files */ @@ -63,7 +63,7 @@ struct fs_allmaps_s g_rammaps; /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/mmap/fs_rammap.h b/fs/mmap/fs_rammap.h index 4f9df60070..d4a7b05a37 100644 --- a/fs/mmap/fs_rammap.h +++ b/fs/mmap/fs_rammap.h @@ -92,7 +92,7 @@ struct fs_allmaps_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* This is the list of all mapped files */ diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 401ff747ba..9c5e6d3fdf 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -154,7 +154,7 @@ static const struct fsmap_t g_nonbdfsmap[] = #endif /* NONBDFS_SUPPORT */ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mount/fs_umount2.c b/fs/mount/fs_umount2.c index 796d7e37b2..8d56aa31bf 100644 --- a/fs/mount/fs_umount2.c +++ b/fs/mount/fs_umount2.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c index eb0d313e8f..5b6db2369e 100644 --- a/fs/mqueue/mq_close.c +++ b/fs/mqueue/mq_close.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index f49f5a34c5..f20e69579f 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index 496571163c..3d6f6e039d 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -58,7 +58,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/fs/mqueue/mqueue.h b/fs/mqueue/mqueue.h index 775ff220eb..4392412ddf 100644 --- a/fs/mqueue/mqueue.h +++ b/fs/mqueue/mqueue.h @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef __cplusplus diff --git a/fs/nfs/nfs_util.c b/fs/nfs/nfs_util.c index 46ee56db6d..19e78ea650 100644 --- a/fs/nfs/nfs_util.c +++ b/fs/nfs/nfs_util.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c index 029885dea7..576ee589f7 100644 --- a/fs/nfs/nfs_vfsops.c +++ b/fs/nfs/nfs_vfsops.c @@ -104,7 +104,7 @@ #endif /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ uint32_t nfs_true; diff --git a/fs/nxffs/nxffs.h b/fs/nxffs/nxffs.h index 89adb6dac1..04dba9f3af 100644 --- a/fs/nxffs/nxffs.h +++ b/fs/nxffs/nxffs.h @@ -316,7 +316,7 @@ struct nxffs_blkstats_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* The magic number that appears that the beginning of each NXFFS (logical) diff --git a/fs/nxffs/nxffs_block.c b/fs/nxffs/nxffs_block.c index ff62811b8b..8dd6a47ee8 100644 --- a/fs/nxffs/nxffs_block.c +++ b/fs/nxffs/nxffs_block.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_blockstats.c b/fs/nxffs/nxffs_blockstats.c index 62753e5a87..859423ca48 100644 --- a/fs/nxffs/nxffs_blockstats.c +++ b/fs/nxffs/nxffs_blockstats.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_cache.c b/fs/nxffs/nxffs_cache.c index 5d87cb2393..2a04d6b0a9 100644 --- a/fs/nxffs/nxffs_cache.c +++ b/fs/nxffs/nxffs_cache.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_dirent.c b/fs/nxffs/nxffs_dirent.c index 2afc694e52..34d8654bf5 100644 --- a/fs/nxffs/nxffs_dirent.c +++ b/fs/nxffs/nxffs_dirent.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_initialize.c b/fs/nxffs/nxffs_initialize.c index 13081b6c1d..66476f4874 100644 --- a/fs/nxffs/nxffs_initialize.c +++ b/fs/nxffs/nxffs_initialize.c @@ -103,7 +103,7 @@ const struct mountpt_operations nxffs_operations = }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* The magic number that appears that the beginning of each NXFFS (logical) diff --git a/fs/nxffs/nxffs_inode.c b/fs/nxffs/nxffs_inode.c index fb18478939..a8bf821861 100644 --- a/fs/nxffs/nxffs_inode.c +++ b/fs/nxffs/nxffs_inode.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_ioctl.c b/fs/nxffs/nxffs_ioctl.c index 96d39c3392..ec2cd041de 100644 --- a/fs/nxffs/nxffs_ioctl.c +++ b/fs/nxffs/nxffs_ioctl.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_pack.c b/fs/nxffs/nxffs_pack.c index 373b480bb5..8706e8009a 100644 --- a/fs/nxffs/nxffs_pack.c +++ b/fs/nxffs/nxffs_pack.c @@ -89,7 +89,7 @@ struct nxffs_pack_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_read.c b/fs/nxffs/nxffs_read.c index c548f5e50e..934a640bf6 100644 --- a/fs/nxffs/nxffs_read.c +++ b/fs/nxffs/nxffs_read.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_reformat.c b/fs/nxffs/nxffs_reformat.c index ec85ee05c9..b969a398b3 100644 --- a/fs/nxffs/nxffs_reformat.c +++ b/fs/nxffs/nxffs_reformat.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_stat.c b/fs/nxffs/nxffs_stat.c index 2a5b610449..9f45b5a4b1 100644 --- a/fs/nxffs/nxffs_stat.c +++ b/fs/nxffs/nxffs_stat.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_unlink.c b/fs/nxffs/nxffs_unlink.c index ec61979596..8422616057 100644 --- a/fs/nxffs/nxffs_unlink.c +++ b/fs/nxffs/nxffs_unlink.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_util.c b/fs/nxffs/nxffs_util.c index f424e71e07..12392aa585 100644 --- a/fs/nxffs/nxffs_util.c +++ b/fs/nxffs/nxffs_util.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 6ed06f3891..d23ea195bd 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -183,7 +183,7 @@ static int procfs_stat(FAR struct inode *mountpt, ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/procfs/fs_procfscpuload.c b/fs/procfs/fs_procfscpuload.c index 8641f39335..f60789a768 100644 --- a/fs/procfs/fs_procfscpuload.c +++ b/fs/procfs/fs_procfscpuload.c @@ -104,7 +104,7 @@ static int cpuload_stat(FAR const char *relpath, FAR struct stat *buf); ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 869d00f9b4..80ea40583c 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -190,7 +190,7 @@ static int proc_stat(FAR const char *relpath, FAR struct stat *buf); ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index 0135e07178..7d924087c8 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -106,7 +106,7 @@ static int uptime_stat(FAR const char *relpath, FAR struct stat *buf); ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c index 6034bd8404..0dd573f562 100644 --- a/fs/procfs/fs_skeleton.c +++ b/fs/procfs/fs_skeleton.c @@ -122,7 +122,7 @@ static int skel_stat(FAR const char *relpath, FAR struct stat *buf); ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See include/nutts/fs/procfs.h diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 14c68ef7e8..8198b2b657 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -105,7 +105,7 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath, ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/romfs/fs_romfs.h b/fs/romfs/fs_romfs.h index 88e673b10d..8b1d5fc5b1 100644 --- a/fs/romfs/fs_romfs.h +++ b/fs/romfs/fs_romfs.h @@ -185,7 +185,7 @@ struct romfs_dirinfo_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index ce945a6694..65528d1378 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_close.c b/fs/semaphore/sem_close.c index d1a7ed4f45..3e9dfffa5c 100644 --- a/fs/semaphore/sem_close.c +++ b/fs/semaphore/sem_close.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 4d422c8503..7ba2d93c1e 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_unlink.c b/fs/semaphore/sem_unlink.c index 393b435d4a..bdeb826b81 100644 --- a/fs/semaphore/sem_unlink.c +++ b/fs/semaphore/sem_unlink.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/semaphore.h b/fs/semaphore/semaphore.h index de8985727c..5ef28b3aac 100644 --- a/fs/semaphore/semaphore.h +++ b/fs/semaphore/semaphore.h @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef __cplusplus diff --git a/fs/smartfs/smartfs.h b/fs/smartfs/smartfs.h index ac83a0c0cf..36ed65b41b 100644 --- a/fs/smartfs/smartfs.h +++ b/fs/smartfs/smartfs.h @@ -330,7 +330,7 @@ struct smartfs_mountpt_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/smartfs/smartfs_procfs.c b/fs/smartfs/smartfs_procfs.c index 6153cde80a..960f37893a 100644 --- a/fs/smartfs/smartfs_procfs.c +++ b/fs/smartfs/smartfs_procfs.c @@ -172,7 +172,7 @@ static const uint8_t g_direntrycount = sizeof(g_direntry) / sizeof(struct smartfs_procfs_entry_s); /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See include/nutts/fs/procfs.h diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index 857c284e2b..55228b2a5d 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -117,7 +117,7 @@ static uint8_t g_seminitialized = FALSE; static sem_t g_sem; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/smartfs/smartfs_utils.c b/fs/smartfs/smartfs_utils.c index 23d0cff13a..db0de34fa0 100644 --- a/fs/smartfs/smartfs_utils.c +++ b/fs/smartfs/smartfs_utils.c @@ -78,7 +78,7 @@ static struct smartfs_mountpt_s* g_mounthead = NULL; #endif /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_close.c b/fs/vfs/fs_close.c index dd34641197..b784b2c9e0 100644 --- a/fs/vfs/fs_close.c +++ b/fs/vfs/fs_close.c @@ -51,7 +51,7 @@ #include "inode/inode.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_dup.c b/fs/vfs/fs_dup.c index 5981dc8cd5..8e8edb86fa 100644 --- a/fs/vfs/fs_dup.c +++ b/fs/vfs/fs_dup.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c index 3164e0b2f5..c81e7b6eae 100644 --- a/fs/vfs/fs_dup2.c +++ b/fs/vfs/fs_dup2.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_dupfd2.c b/fs/vfs/fs_dupfd2.c index 6043430bdc..8857c767f8 100644 --- a/fs/vfs/fs_dupfd2.c +++ b/fs/vfs/fs_dupfd2.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_fsync.c b/fs/vfs/fs_fsync.c index 4d2311ea0c..246dc51d89 100644 --- a/fs/vfs/fs_fsync.c +++ b/fs/vfs/fs_fsync.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c index eb48d5c343..593eae963a 100644 --- a/fs/vfs/fs_ioctl.c +++ b/fs/vfs/fs_ioctl.c @@ -53,7 +53,7 @@ #include "inode/inode.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_mkdir.c b/fs/vfs/fs_mkdir.c index 832c5f816a..1add02d44d 100644 --- a/fs/vfs/fs_mkdir.c +++ b/fs/vfs/fs_mkdir.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c index 76f11b0abf..820193cf5d 100644 --- a/fs/vfs/fs_rename.c +++ b/fs/vfs/fs_rename.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_rmdir.c b/fs/vfs/fs_rmdir.c index 685704e0de..234b11399d 100644 --- a/fs/vfs/fs_rmdir.c +++ b/fs/vfs/fs_rmdir.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_sendfile.c b/fs/vfs/fs_sendfile.c index 05c3d976eb..0935460c16 100644 --- a/fs/vfs/fs_sendfile.c +++ b/fs/vfs/fs_sendfile.c @@ -60,7 +60,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index b8b62080bb..1bd9d05d8e 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -143,7 +143,7 @@ static inline int statroot(FAR struct stat *buf) } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c index 0d70cfa606..a05462dec0 100644 --- a/fs/vfs/fs_unlink.c +++ b/fs/vfs/fs_unlink.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/graphics/nxterm/nxterm.h b/graphics/nxterm/nxterm.h index f94cd6f093..1a082e5283 100644 --- a/graphics/nxterm/nxterm.h +++ b/graphics/nxterm/nxterm.h @@ -194,7 +194,7 @@ struct nxterm_state_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* This is the common NX driver file operations */ diff --git a/include/debug.h b/include/debug.h index 10ef6889e9..b1bb2fc9d1 100644 --- a/include/debug.h +++ b/include/debug.h @@ -644,7 +644,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/dirent.h b/include/dirent.h index 82381189c4..ea6b18a142 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -83,7 +83,7 @@ struct dirent typedef void DIR; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 5f615cd51e..950e4ae0f9 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -120,7 +120,7 @@ typedef CODE void (*sig_deliver_t)(FAR struct tcb_s *tcb); typedef CODE void (*phy_enable_t)(bool enable); /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 9cf1192c57..f43de0b671 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -476,11 +476,11 @@ #endif /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ #ifdef __cplusplus diff --git a/include/nuttx/fs/dirent.h b/include/nuttx/fs/dirent.h index 26b3d7bc26..645a2351f6 100644 --- a/include/nuttx/fs/dirent.h +++ b/include/nuttx/fs/dirent.h @@ -236,7 +236,7 @@ struct fs_dirent_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 3d2d6c3c73..b55ba8b505 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -352,7 +352,7 @@ typedef int (*foreach_mountpoint_t)(FAR const char *mountpoint, #endif /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ #undef EXTERN diff --git a/include/nuttx/fs/mkfatfs.h b/include/nuttx/fs/mkfatfs.h index e7a5a4c904..03ca6ef956 100644 --- a/include/nuttx/fs/mkfatfs.h +++ b/include/nuttx/fs/mkfatfs.h @@ -95,7 +95,7 @@ struct fat_format_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/fs/mksmartfs.h b/include/nuttx/fs/mksmartfs.h index e0a841ca0f..f907ba305a 100644 --- a/include/nuttx/fs/mksmartfs.h +++ b/include/nuttx/fs/mksmartfs.h @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/init.h b/include/nuttx/init.h index 2038427f39..553dc3a4af 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Data + * Public Data ****************************************************************************/ #ifdef __cplusplus @@ -60,7 +60,7 @@ extern "C" #endif /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /* This entry point must be supplied by the application */ diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index 9bdc1cf7d2..43b9992cfd 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -70,7 +70,7 @@ typedef int (*xcpt_t)(int irq, FAR void *context); #include /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifndef __ASSEMBLY__ diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 857bbfa0ea..612d2488d1 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Type Declarations + * Public Type Declarations ****************************************************************************/ /* This structure defines a message queue */ @@ -97,11 +97,11 @@ struct mq_des }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ #ifdef __cplusplus diff --git a/include/nuttx/net/iob.h b/include/nuttx/net/iob.h index 121d82ae1f..b9ff53d78c 100644 --- a/include/nuttx/net/iob.h +++ b/include/nuttx/net/iob.h @@ -157,7 +157,7 @@ struct iob_queue_s #endif /* CONFIG_IOB_NCHAINS > 0 */ /**************************************************************************** - * Global Data + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 49a90723be..2fada4fdbf 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -239,7 +239,7 @@ struct net_driver_s typedef int (*devif_poll_callback_t)(FAR struct net_driver_s *dev); /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/rwbuffer.h b/include/nuttx/rwbuffer.h index 7a97ff65c6..1f11cf47bc 100644 --- a/include/nuttx/rwbuffer.h +++ b/include/nuttx/rwbuffer.h @@ -155,7 +155,7 @@ struct rwbuffer_s }; /********************************************************************** - * Global Variables + * Public Data **********************************************************************/ #undef EXTERN @@ -168,7 +168,7 @@ extern "C" #endif /********************************************************************** - * Global Function Prototypes + * Public Function Prototypes **********************************************************************/ /* Buffer initialization */ diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index 139741ff05..3358765bed 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -194,7 +194,7 @@ struct lib_rawsostream_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/include/poll.h b/include/poll.h index 3c47ca1983..859163af39 100644 --- a/include/poll.h +++ b/include/poll.h @@ -115,7 +115,7 @@ struct pollfd }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/include/semaphore.h b/include/semaphore.h index 5818f0fb7e..de4394c4e1 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -115,7 +115,7 @@ typedef struct sem_s sem_t; #endif /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/include/stdio.h b/include/stdio.h index f75e9928d1..3a0745c84f 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -107,7 +107,7 @@ typedef struct file_struct FILE; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/include/sys/stat.h b/include/sys/stat.h index a27d224365..3f2658b5f1 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -117,7 +117,7 @@ struct stat }; /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ #undef EXTERN diff --git a/include/sys/types.h b/include/sys/types.h index 14c04e9c78..babc723d92 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -263,7 +263,7 @@ typedef CODE int (*main_t)(int argc, char *argv[]); #endif /* __ASSEMBLY__ */ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ #endif /* __INCLUDE_SYS_TYPES_H */ diff --git a/include/syslog.h b/include/syslog.h index b06997f1f3..2dfef54b24 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -132,7 +132,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio.h b/libc/aio/aio.h index f1376be9ab..f28340f3c2 100644 --- a/libc/aio/aio.h +++ b/libc/aio/aio.h @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/libc/aio/aio_error.c b/libc/aio/aio_error.c index 4d1eca99c5..8bfa1978fb 100644 --- a/libc/aio/aio_error.c +++ b/libc/aio/aio_error.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio_return.c b/libc/aio/aio_return.c index 076d8fb293..4672de0855 100644 --- a/libc/aio/aio_return.c +++ b/libc/aio/aio_return.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio_suspend.c b/libc/aio/aio_suspend.c index 89982fc89d..5e5fe33715 100644 --- a/libc/aio/aio_suspend.c +++ b/libc/aio/aio_suspend.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index 5b2277347b..e4e4a71a7e 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -74,7 +74,7 @@ struct lio_sighand_s ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/audio/lib_buffer.c b/libc/audio/lib_buffer.c index cfcf43f2dc..f69a2066ed 100644 --- a/libc/audio/lib_buffer.c +++ b/libc/audio/lib_buffer.c @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/fixedmath/lib_b16atan2.c b/libc/fixedmath/lib_b16atan2.c index f0a00f8df4..4cdb76e09c 100644 --- a/libc/fixedmath/lib_b16atan2.c +++ b/libc/fixedmath/lib_b16atan2.c @@ -65,7 +65,7 @@ #endif /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/fixedmath/lib_b16cos.c b/libc/fixedmath/lib_b16cos.c index 0ebe482624..5ff4215cf0 100644 --- a/libc/fixedmath/lib_b16cos.c +++ b/libc/fixedmath/lib_b16cos.c @@ -44,7 +44,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/fixedmath/lib_b16sin.c b/libc/fixedmath/lib_b16sin.c index 9cd2f0da3e..c63e170a76 100644 --- a/libc/fixedmath/lib_b16sin.c +++ b/libc/fixedmath/lib_b16sin.c @@ -48,7 +48,7 @@ #define b16_1P27323954 0x000145f3 /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/libgen/lib_basename.c b/libc/libgen/lib_basename.c index 68188edbf5..94df071200 100644 --- a/libc/libgen/lib_basename.c +++ b/libc/libgen/lib_basename.c @@ -49,7 +49,7 @@ static char g_retchar[2]; /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/libgen/lib_dirname.c b/libc/libgen/lib_dirname.c index 6d076fd610..b7760c3a1f 100644 --- a/libc/libgen/lib_dirname.c +++ b/libc/libgen/lib_dirname.c @@ -49,7 +49,7 @@ static char g_retchar[2]; /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index 48a2d762f5..d26e1b9736 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -60,11 +60,11 @@ ************************************************************/ /********************************************************** - * Global Constant Data + * Public Constant Data **********************************************************/ /************************************************************ - * Global Variables + * Public Data ************************************************************/ /********************************************************** diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c index 83147d82b1..cd03168828 100644 --- a/libc/math/lib_rintf.c +++ b/libc/math/lib_rintf.c @@ -60,11 +60,11 @@ ************************************************************/ /********************************************************** - * Global Constant Data + * Public Constant Data **********************************************************/ /************************************************************ - * Global Variables + * Public Data ************************************************************/ /********************************************************** diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c index 5bc6cadbd7..92ec28bcea 100644 --- a/libc/math/lib_rintl.c +++ b/libc/math/lib_rintl.c @@ -60,11 +60,11 @@ ************************************************************/ /********************************************************** - * Global Constant Data + * Public Constant Data **********************************************************/ /************************************************************ - * Global Variables + * Public Data ************************************************************/ /********************************************************** diff --git a/libc/misc/lib_filesem.c b/libc/misc/lib_filesem.c index f38ff5f238..1dd88454f8 100644 --- a/libc/misc/lib_filesem.c +++ b/libc/misc/lib_filesem.c @@ -58,7 +58,7 @@ ************************************************************************/ /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ /************************************************************************ diff --git a/libc/misc/lib_sendfile.c b/libc/misc/lib_sendfile.c index 56651674f4..187e689cfd 100644 --- a/libc/misc/lib_sendfile.c +++ b/libc/misc/lib_sendfile.c @@ -58,7 +58,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/libc/misc/lib_streamsem.c b/libc/misc/lib_streamsem.c index 3397f99074..7972a61f32 100644 --- a/libc/misc/lib_streamsem.c +++ b/libc/misc/lib_streamsem.c @@ -57,7 +57,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/libc/net/lib_addroute.c b/libc/net/lib_addroute.c index b588b4754f..a5d6dd8709 100644 --- a/libc/net/lib_addroute.c +++ b/libc/net/lib_addroute.c @@ -49,7 +49,7 @@ #include /*************************************************************************** - * Global Functions + * Public Functions ***************************************************************************/ /**************************************************************************** diff --git a/libc/net/lib_delroute.c b/libc/net/lib_delroute.c index fecec3a834..f508e35afc 100644 --- a/libc/net/lib_delroute.c +++ b/libc/net/lib_delroute.c @@ -50,7 +50,7 @@ #include /*************************************************************************** - * Global Functions + * Public Functions ***************************************************************************/ /**************************************************************************** diff --git a/libc/net/lib_etherntoa.c b/libc/net/lib_etherntoa.c index 91fb01c570..728b48ae89 100644 --- a/libc/net/lib_etherntoa.c +++ b/libc/net/lib_etherntoa.c @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/net/lib_htonl.c b/libc/net/lib_htonl.c index a10f54f379..919cf2f9d7 100644 --- a/libc/net/lib_htonl.c +++ b/libc/net/lib_htonl.c @@ -43,7 +43,7 @@ #include /************************************************************ - * Global Functions + * Public Functions ************************************************************/ uint32_t htonl(uint32_t hl) diff --git a/libc/net/lib_htons.c b/libc/net/lib_htons.c index 13addd9136..c3ff0fd66f 100644 --- a/libc/net/lib_htons.c +++ b/libc/net/lib_htons.c @@ -47,7 +47,7 @@ #include /*************************************************************************** - * Global Functions + * Public Functions ***************************************************************************/ uint16_t htons(uint16_t hs) diff --git a/libc/net/lib_inetntoa.c b/libc/net/lib_inetntoa.c index 9e763de6b4..60c5742871 100644 --- a/libc/net/lib_inetntoa.c +++ b/libc/net/lib_inetntoa.c @@ -47,7 +47,7 @@ #ifdef CONFIG_NET_IPv4 /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrdestroy.c b/libc/pthread/pthread_attrdestroy.c index 0e2091808a..22a7d8e894 100644 --- a/libc/pthread/pthread_attrdestroy.c +++ b/libc/pthread/pthread_attrdestroy.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrgetinheritsched.c b/libc/pthread/pthread_attrgetinheritsched.c index 4471c98e59..5fad0456c2 100644 --- a/libc/pthread/pthread_attrgetinheritsched.c +++ b/libc/pthread/pthread_attrgetinheritsched.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrgetschedpolicy.c b/libc/pthread/pthread_attrgetschedpolicy.c index 1c3b47ba67..ff67f5ad96 100644 --- a/libc/pthread/pthread_attrgetschedpolicy.c +++ b/libc/pthread/pthread_attrgetschedpolicy.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrgetstacksize.c b/libc/pthread/pthread_attrgetstacksize.c index 4b3cd4b914..fc65f3d65f 100644 --- a/libc/pthread/pthread_attrgetstacksize.c +++ b/libc/pthread/pthread_attrgetstacksize.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrinit.c b/libc/pthread/pthread_attrinit.c index 3a304629f2..e40dfa81f4 100644 --- a/libc/pthread/pthread_attrinit.c +++ b/libc/pthread/pthread_attrinit.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /* Default pthread attributes (see include/nuttx/pthread.h). When configured diff --git a/libc/pthread/pthread_attrsetinheritsched.c b/libc/pthread/pthread_attrsetinheritsched.c index ccbe81626d..34d8ce277d 100644 --- a/libc/pthread/pthread_attrsetinheritsched.c +++ b/libc/pthread/pthread_attrsetinheritsched.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_attrsetstacksize.c b/libc/pthread/pthread_attrsetstacksize.c index 8a19105981..96379dd0e6 100644 --- a/libc/pthread/pthread_attrsetstacksize.c +++ b/libc/pthread/pthread_attrsetstacksize.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_barrierattrdestroy.c b/libc/pthread/pthread_barrierattrdestroy.c index 7699ecdfda..55f735a1c2 100644 --- a/libc/pthread/pthread_barrierattrdestroy.c +++ b/libc/pthread/pthread_barrierattrdestroy.c @@ -52,7 +52,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/libc/pthread/pthread_barrierattrgetpshared.c b/libc/pthread/pthread_barrierattrgetpshared.c index ebd2ef81e9..d64423499e 100644 --- a/libc/pthread/pthread_barrierattrgetpshared.c +++ b/libc/pthread/pthread_barrierattrgetpshared.c @@ -52,7 +52,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/libc/pthread/pthread_barrierattrinit.c b/libc/pthread/pthread_barrierattrinit.c index c1fc8f95d0..2deb60ba56 100644 --- a/libc/pthread/pthread_barrierattrinit.c +++ b/libc/pthread/pthread_barrierattrinit.c @@ -52,7 +52,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/libc/pthread/pthread_barrierattrsetpshared.c b/libc/pthread/pthread_barrierattrsetpshared.c index da08de5384..2fd224bad6 100644 --- a/libc/pthread/pthread_barrierattrsetpshared.c +++ b/libc/pthread/pthread_barrierattrsetpshared.c @@ -52,7 +52,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/libc/pthread/pthread_condattrdestroy.c b/libc/pthread/pthread_condattrdestroy.c index 30a0c4db1b..5e25a7d421 100644 --- a/libc/pthread/pthread_condattrdestroy.c +++ b/libc/pthread/pthread_condattrdestroy.c @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_condattrinit.c b/libc/pthread/pthread_condattrinit.c index 1cc0a93e73..220d972e10 100644 --- a/libc/pthread/pthread_condattrinit.c +++ b/libc/pthread/pthread_condattrinit.c @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrdestroy.c b/libc/pthread/pthread_mutexattrdestroy.c index ad92c4c156..c59478d880 100644 --- a/libc/pthread/pthread_mutexattrdestroy.c +++ b/libc/pthread/pthread_mutexattrdestroy.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrgetpshared.c b/libc/pthread/pthread_mutexattrgetpshared.c index e930a38a57..97f69b0d77 100644 --- a/libc/pthread/pthread_mutexattrgetpshared.c +++ b/libc/pthread/pthread_mutexattrgetpshared.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrgettype.c b/libc/pthread/pthread_mutexattrgettype.c index f5d662f7b1..240a157055 100644 --- a/libc/pthread/pthread_mutexattrgettype.c +++ b/libc/pthread/pthread_mutexattrgettype.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrinit.c b/libc/pthread/pthread_mutexattrinit.c index cbb2f29ead..17dbd9e849 100644 --- a/libc/pthread/pthread_mutexattrinit.c +++ b/libc/pthread/pthread_mutexattrinit.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrsetpshared.c b/libc/pthread/pthread_mutexattrsetpshared.c index 94a07dda05..075820df52 100644 --- a/libc/pthread/pthread_mutexattrsetpshared.c +++ b/libc/pthread/pthread_mutexattrsetpshared.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_mutexattrsettype.c b/libc/pthread/pthread_mutexattrsettype.c index b0641b384a..b3f23f4da0 100644 --- a/libc/pthread/pthread_mutexattrsettype.c +++ b/libc/pthread/pthread_mutexattrsettype.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_startup.c b/libc/pthread/pthread_startup.c index 6dea37c4eb..7bbac36cd0 100644 --- a/libc/pthread/pthread_startup.c +++ b/libc/pthread/pthread_startup.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/sched/task_startup.c b/libc/sched/task_startup.c index 8c81c0b50f..754e5aee3c 100644 --- a/libc/sched/task_startup.c +++ b/libc/sched/task_startup.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/semaphore/sem_getvalue.c b/libc/semaphore/sem_getvalue.c index 3c92aa2663..b1412a85ce 100644 --- a/libc/semaphore/sem_getvalue.c +++ b/libc/semaphore/sem_getvalue.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/semaphore/sem_init.c b/libc/semaphore/sem_init.c index c0554ef51b..c7a4f70261 100644 --- a/libc/semaphore/sem_init.c +++ b/libc/semaphore/sem_init.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/signal/sig_fillset.c b/libc/signal/sig_fillset.c index ceeafdd313..ecd5a82bc9 100644 --- a/libc/signal/sig_fillset.c +++ b/libc/signal/sig_fillset.c @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/signal/sig_ismember.c b/libc/signal/sig_ismember.c index 1a8590e003..e03f5fbe97 100644 --- a/libc/signal/sig_ismember.c +++ b/libc/signal/sig_ismember.c @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_dump.c b/libc/spawn/lib_psa_dump.c index b949d230a2..935de174ed 100644 --- a/libc/spawn/lib_psa_dump.c +++ b/libc/spawn/lib_psa_dump.c @@ -45,7 +45,7 @@ #ifdef CONFIG_DEBUG /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_getflags.c b/libc/spawn/lib_psa_getflags.c index f0e07f0c22..d365030caf 100644 --- a/libc/spawn/lib_psa_getflags.c +++ b/libc/spawn/lib_psa_getflags.c @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_getschedparam.c b/libc/spawn/lib_psa_getschedparam.c index 3a4e48d921..8de95a27c1 100644 --- a/libc/spawn/lib_psa_getschedparam.c +++ b/libc/spawn/lib_psa_getschedparam.c @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_getschedpolicy.c b/libc/spawn/lib_psa_getschedpolicy.c index 8f36456664..52cabb265b 100644 --- a/libc/spawn/lib_psa_getschedpolicy.c +++ b/libc/spawn/lib_psa_getschedpolicy.c @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_getsigmask.c b/libc/spawn/lib_psa_getsigmask.c index dd3495b4d0..db25257ead 100644 --- a/libc/spawn/lib_psa_getsigmask.c +++ b/libc/spawn/lib_psa_getsigmask.c @@ -46,7 +46,7 @@ #ifndef CONFIG_DISABLE_SIGNALS /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_setflags.c b/libc/spawn/lib_psa_setflags.c index 34b71d841c..d0362c81d8 100644 --- a/libc/spawn/lib_psa_setflags.c +++ b/libc/spawn/lib_psa_setflags.c @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_setschedpolicy.c b/libc/spawn/lib_psa_setschedpolicy.c index 136a6f0fdb..d123db25dd 100644 --- a/libc/spawn/lib_psa_setschedpolicy.c +++ b/libc/spawn/lib_psa_setschedpolicy.c @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psa_setsigmask.c b/libc/spawn/lib_psa_setsigmask.c index 28b7daf779..038efa6905 100644 --- a/libc/spawn/lib_psa_setsigmask.c +++ b/libc/spawn/lib_psa_setsigmask.c @@ -46,7 +46,7 @@ #ifndef CONFIG_DISABLE_SIGNALS /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_addaction.c b/libc/spawn/lib_psfa_addaction.c index 8700efc2a5..62c927b2e4 100644 --- a/libc/spawn/lib_psfa_addaction.c +++ b/libc/spawn/lib_psfa_addaction.c @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_addclose.c b/libc/spawn/lib_psfa_addclose.c index 4f813f65c2..eaf3e08892 100644 --- a/libc/spawn/lib_psfa_addclose.c +++ b/libc/spawn/lib_psfa_addclose.c @@ -49,7 +49,7 @@ #include "lib_internal.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_adddup2.c b/libc/spawn/lib_psfa_adddup2.c index a10f476f1b..5b4833c5b0 100644 --- a/libc/spawn/lib_psfa_adddup2.c +++ b/libc/spawn/lib_psfa_adddup2.c @@ -49,7 +49,7 @@ #include "lib_internal.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_addopen.c b/libc/spawn/lib_psfa_addopen.c index 4be80ff1c3..4bb096efb7 100644 --- a/libc/spawn/lib_psfa_addopen.c +++ b/libc/spawn/lib_psfa_addopen.c @@ -50,7 +50,7 @@ #include "lib_internal.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_destroy.c b/libc/spawn/lib_psfa_destroy.c index 9bbc3d906f..e4020304b1 100644 --- a/libc/spawn/lib_psfa_destroy.c +++ b/libc/spawn/lib_psfa_destroy.c @@ -48,7 +48,7 @@ #include "lib_internal.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/spawn/lib_psfa_init.c b/libc/spawn/lib_psfa_init.c index 5c902125a8..64d900a22c 100644 --- a/libc/spawn/lib_psfa_init.c +++ b/libc/spawn/lib_psfa_init.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_asprintf.c b/libc/stdio/lib_asprintf.c index 92a17a82b0..09e6f42e93 100644 --- a/libc/stdio/lib_asprintf.c +++ b/libc/stdio/lib_asprintf.c @@ -55,11 +55,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fclose.c b/libc/stdio/lib_fclose.c index 50e7e63bcb..ff54efba4c 100644 --- a/libc/stdio/lib_fclose.c +++ b/libc/stdio/lib_fclose.c @@ -48,7 +48,7 @@ #include "lib_internal.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fflush.c b/libc/stdio/lib_fflush.c index a84a14a599..bb3d0313cd 100644 --- a/libc/stdio/lib_fflush.c +++ b/libc/stdio/lib_fflush.c @@ -61,11 +61,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -77,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fgetc.c b/libc/stdio/lib_fgetc.c index 297d5e7164..20ebd41b29 100644 --- a/libc/stdio/lib_fgetc.c +++ b/libc/stdio/lib_fgetc.c @@ -57,15 +57,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /************************************************************************** - * Global Constant Data + * Public Constant Data **************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /************************************************************************** @@ -77,7 +77,7 @@ **************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions **************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fgetpos.c b/libc/stdio/lib_fgetpos.c index 322890613e..e2c4d0c696 100644 --- a/libc/stdio/lib_fgetpos.c +++ b/libc/stdio/lib_fgetpos.c @@ -62,11 +62,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fileno.c b/libc/stdio/lib_fileno.c index dff72becc4..555d288759 100644 --- a/libc/stdio/lib_fileno.c +++ b/libc/stdio/lib_fileno.c @@ -47,7 +47,7 @@ #if CONFIG_NFILE_STREAMS > 0 /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ int fileno(FAR FILE *stream) diff --git a/libc/stdio/lib_fprintf.c b/libc/stdio/lib_fprintf.c index 718dc40f5b..d4420ada23 100644 --- a/libc/stdio/lib_fprintf.c +++ b/libc/stdio/lib_fprintf.c @@ -56,11 +56,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fputc.c b/libc/stdio/lib_fputc.c index d6029b07b9..f434d442e2 100644 --- a/libc/stdio/lib_fputc.c +++ b/libc/stdio/lib_fputc.c @@ -57,15 +57,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -77,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fputs.c b/libc/stdio/lib_fputs.c index fdfbd53904..a1bcd89c3d 100644 --- a/libc/stdio/lib_fputs.c +++ b/libc/stdio/lib_fputs.c @@ -64,15 +64,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fread.c b/libc/stdio/lib_fread.c index 3bfac69956..9c8b2d378a 100644 --- a/libc/stdio/lib_fread.c +++ b/libc/stdio/lib_fread.c @@ -57,11 +57,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fseek.c b/libc/stdio/lib_fseek.c index f11efa1d09..f09155dc0a 100644 --- a/libc/stdio/lib_fseek.c +++ b/libc/stdio/lib_fseek.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fsetpos.c b/libc/stdio/lib_fsetpos.c index d33fe4ca30..71093d4ce8 100644 --- a/libc/stdio/lib_fsetpos.c +++ b/libc/stdio/lib_fsetpos.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_ftell.c b/libc/stdio/lib_ftell.c index 85390c918a..c72e4e1b85 100644 --- a/libc/stdio/lib_ftell.c +++ b/libc/stdio/lib_ftell.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fwrite.c b/libc/stdio/lib_fwrite.c index e10eef8e19..ed2dce16d8 100644 --- a/libc/stdio/lib_fwrite.c +++ b/libc/stdio/lib_fwrite.c @@ -57,11 +57,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libdtoa.c b/libc/stdio/lib_libdtoa.c index 0120bafd2d..95a5dcc70b 100644 --- a/libc/stdio/lib_libdtoa.c +++ b/libc/stdio/lib_libdtoa.c @@ -71,11 +71,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index 842de018a8..6c0dfabe83 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -62,11 +62,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libflushall.c b/libc/stdio/lib_libflushall.c index 9bb94c5c8e..7c7b8d9b66 100644 --- a/libc/stdio/lib_libflushall.c +++ b/libc/stdio/lib_libflushall.c @@ -60,11 +60,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index 684f33b743..27011738c9 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -61,11 +61,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index 26fc0b1845..76c8d72797 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -61,11 +61,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libnoflush.c b/libc/stdio/lib_libnoflush.c index eafe63977b..63e4d52950 100644 --- a/libc/stdio/lib_libnoflush.c +++ b/libc/stdio/lib_libnoflush.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -80,7 +80,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libsnoflush.c b/libc/stdio/lib_libsnoflush.c index d3cf8c0f48..1e5af1474b 100644 --- a/libc/stdio/lib_libsnoflush.c +++ b/libc/stdio/lib_libsnoflush.c @@ -63,11 +63,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libsprintf.c b/libc/stdio/lib_libsprintf.c index fd7fa56e32..1d8abbced7 100644 --- a/libc/stdio/lib_libsprintf.c +++ b/libc/stdio/lib_libsprintf.c @@ -53,11 +53,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index b075487821..61cac29283 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -203,11 +203,11 @@ static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, #endif /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index b306ca3b34..1c210a7c0d 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -59,15 +59,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /************************************************************************** - * Global Constant Data + * Public Constant Data **************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /************************************************************************** @@ -79,7 +79,7 @@ **************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions **************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_puts.c b/libc/stdio/lib_puts.c index a9317dc499..4d2ab4c4ed 100644 --- a/libc/stdio/lib_puts.c +++ b/libc/stdio/lib_puts.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_rdflush.c b/libc/stdio/lib_rdflush.c index efc5d4ea02..65d37ac356 100644 --- a/libc/stdio/lib_rdflush.c +++ b/libc/stdio/lib_rdflush.c @@ -63,11 +63,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_snprintf.c b/libc/stdio/lib_snprintf.c index d1232e11a9..63d0b2a5df 100644 --- a/libc/stdio/lib_snprintf.c +++ b/libc/stdio/lib_snprintf.c @@ -57,11 +57,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_sprintf.c b/libc/stdio/lib_sprintf.c index 347efc59cb..a0b3321bb1 100644 --- a/libc/stdio/lib_sprintf.c +++ b/libc/stdio/lib_sprintf.c @@ -53,11 +53,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c index 24b36998e1..c094cb1fb3 100644 --- a/libc/stdio/lib_sscanf.c +++ b/libc/stdio/lib_sscanf.c @@ -73,17 +73,17 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap); /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_ungetc.c b/libc/stdio/lib_ungetc.c index 68eb5d5c03..473262d09f 100644 --- a/libc/stdio/lib_ungetc.c +++ b/libc/stdio/lib_ungetc.c @@ -61,15 +61,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /************************************************************************** - * Global Constant Data + * Public Constant Data **************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /************************************************************************** diff --git a/libc/stdio/lib_vasprintf.c b/libc/stdio/lib_vasprintf.c index aa17757541..f7b2402712 100644 --- a/libc/stdio/lib_vasprintf.c +++ b/libc/stdio/lib_vasprintf.c @@ -75,11 +75,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -91,7 +91,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vfprintf.c b/libc/stdio/lib_vfprintf.c index c6bfe588c7..8681b2151d 100644 --- a/libc/stdio/lib_vfprintf.c +++ b/libc/stdio/lib_vfprintf.c @@ -57,11 +57,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vprintf.c b/libc/stdio/lib_vprintf.c index 13890e928b..7db042bcf5 100644 --- a/libc/stdio/lib_vprintf.c +++ b/libc/stdio/lib_vprintf.c @@ -56,15 +56,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /************************************************************************** - * Global Constant Data + * Public Constant Data **************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /************************************************************************** diff --git a/libc/stdio/lib_vsnprintf.c b/libc/stdio/lib_vsnprintf.c index dca39e61eb..5fd300f7fe 100644 --- a/libc/stdio/lib_vsnprintf.c +++ b/libc/stdio/lib_vsnprintf.c @@ -57,11 +57,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vsprintf.c b/libc/stdio/lib_vsprintf.c index 737cfdc5b9..57589cef56 100644 --- a/libc/stdio/lib_vsprintf.c +++ b/libc/stdio/lib_vsprintf.c @@ -56,11 +56,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_wrflush.c b/libc/stdio/lib_wrflush.c index 40b8e38c8d..0587e417eb 100644 --- a/libc/stdio/lib_wrflush.c +++ b/libc/stdio/lib_wrflush.c @@ -58,11 +58,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdlib/lib_abort.c b/libc/stdlib/lib_abort.c index 1c7442c7f5..0cbeff3c00 100644 --- a/libc/stdlib/lib_abort.c +++ b/libc/stdlib/lib_abort.c @@ -51,7 +51,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/libc/stdlib/lib_abs.c b/libc/stdlib/lib_abs.c index a4e4ec6694..677ea7dfdb 100644 --- a/libc/stdlib/lib_abs.c +++ b/libc/stdlib/lib_abs.c @@ -41,7 +41,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ int abs(int j) diff --git a/libc/stdlib/lib_imaxabs.c b/libc/stdlib/lib_imaxabs.c index d365043727..fca9fe7f03 100644 --- a/libc/stdlib/lib_imaxabs.c +++ b/libc/stdlib/lib_imaxabs.c @@ -41,7 +41,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ intmax_t imaxabs(intmax_t j) diff --git a/libc/stdlib/lib_itoa.c b/libc/stdlib/lib_itoa.c index 553591c097..4e6b2feec3 100644 --- a/libc/stdlib/lib_itoa.c +++ b/libc/stdlib/lib_itoa.c @@ -46,7 +46,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ char *itoa(int val, char *str, int base) diff --git a/libc/stdlib/lib_labs.c b/libc/stdlib/lib_labs.c index 7cf92a0a19..7eef741631 100644 --- a/libc/stdlib/lib_labs.c +++ b/libc/stdlib/lib_labs.c @@ -41,7 +41,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ long int labs(long int j) diff --git a/libc/stdlib/lib_llabs.c b/libc/stdlib/lib_llabs.c index 3630d1716f..452b624c3b 100644 --- a/libc/stdlib/lib_llabs.c +++ b/libc/stdlib/lib_llabs.c @@ -42,7 +42,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ #ifdef CONFIG_HAVE_LONG_LONG diff --git a/libc/string/lib_memccpy.c b/libc/string/lib_memccpy.c index 1d77f58fe9..525eb872c5 100644 --- a/libc/string/lib_memccpy.c +++ b/libc/string/lib_memccpy.c @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ diff --git a/libc/string/lib_memchr.c b/libc/string/lib_memchr.c index 0ac6091042..f1fe85baf2 100644 --- a/libc/string/lib_memchr.c +++ b/libc/string/lib_memchr.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/string/lib_memcmp.c b/libc/string/lib_memcmp.c index 5434bb8474..66acb1fdfb 100644 --- a/libc/string/lib_memcmp.c +++ b/libc/string/lib_memcmp.c @@ -46,7 +46,7 @@ #include /************************************************************ - * Global Functions + * Public Functions ************************************************************/ #ifndef CONFIG_ARCH_MEMCMP diff --git a/libc/string/lib_memcpy.c b/libc/string/lib_memcpy.c index 2ebd5beee1..aff9c34347 100644 --- a/libc/string/lib_memcpy.c +++ b/libc/string/lib_memcpy.c @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/string/lib_memmove.c b/libc/string/lib_memmove.c index cc83172238..6c37fb2224 100644 --- a/libc/string/lib_memmove.c +++ b/libc/string/lib_memmove.c @@ -46,7 +46,7 @@ #include /************************************************************ - * Global Functions + * Public Functions ************************************************************/ #ifndef CONFIG_ARCH_MEMMOVE diff --git a/libc/string/lib_memset.c b/libc/string/lib_memset.c index 0b98ebf96f..67f45ab6a9 100644 --- a/libc/string/lib_memset.c +++ b/libc/string/lib_memset.c @@ -60,7 +60,7 @@ #endif /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ #ifndef CONFIG_ARCH_MEMSET diff --git a/libc/string/lib_strcasestr.c b/libc/string/lib_strcasestr.c index 7f17a686d0..85cb9a043a 100644 --- a/libc/string/lib_strcasestr.c +++ b/libc/string/lib_strcasestr.c @@ -66,7 +66,7 @@ static FAR char *strcasechr(FAR const char *s, int uc) } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ FAR char *strcasestr(FAR const char *str, FAR const char *substr) diff --git a/libc/string/lib_strcat.c b/libc/string/lib_strcat.c index b331d3f1c1..bc1cfde522 100644 --- a/libc/string/lib_strcat.c +++ b/libc/string/lib_strcat.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ #ifndef CONFIG_ARCH_STRCAT diff --git a/libc/string/lib_strchr.c b/libc/string/lib_strchr.c index 7d7cf3757c..371c8492b0 100644 --- a/libc/string/lib_strchr.c +++ b/libc/string/lib_strchr.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/string/lib_strcspn.c b/libc/string/lib_strcspn.c index 23e913fadf..dd4a692875 100644 --- a/libc/string/lib_strcspn.c +++ b/libc/string/lib_strcspn.c @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/string/lib_strdup.c b/libc/string/lib_strdup.c index 38eed709c5..ee626e184e 100644 --- a/libc/string/lib_strdup.c +++ b/libc/string/lib_strdup.c @@ -44,7 +44,7 @@ #include "lib_internal.h" /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ FAR char *strdup(const char *s) diff --git a/libc/string/lib_strlen.c b/libc/string/lib_strlen.c index 6077858e23..e897354e54 100644 --- a/libc/string/lib_strlen.c +++ b/libc/string/lib_strlen.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ #ifndef CONFIG_ARCH_STRLEN diff --git a/libc/string/lib_strncasecmp.c b/libc/string/lib_strncasecmp.c index 35f701c5ef..35aba40c05 100644 --- a/libc/string/lib_strncasecmp.c +++ b/libc/string/lib_strncasecmp.c @@ -48,7 +48,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions *****************************************************************************/ #ifndef CONFIG_ARCH_STRNCASECMP diff --git a/libc/string/lib_strncat.c b/libc/string/lib_strncat.c index 78c54835e0..d9deed58b7 100644 --- a/libc/string/lib_strncat.c +++ b/libc/string/lib_strncat.c @@ -42,7 +42,7 @@ #include /************************************************************ - * Global Functions + * Public Functions ************************************************************/ #ifndef CONFIG_ARCH_STRNCAT diff --git a/libc/string/lib_strncmp.c b/libc/string/lib_strncmp.c index 179cf031a4..bdeb98720a 100644 --- a/libc/string/lib_strncmp.c +++ b/libc/string/lib_strncmp.c @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions *****************************************************************************/ #ifndef CONFIG_ARCH_STRNCMP diff --git a/libc/string/lib_strndup.c b/libc/string/lib_strndup.c index 5a78e2dcfe..bac9128c5d 100644 --- a/libc/string/lib_strndup.c +++ b/libc/string/lib_strndup.c @@ -44,7 +44,7 @@ #include "lib_internal.h" /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ /************************************************************************ * Name: strndup diff --git a/libc/string/lib_strnlen.c b/libc/string/lib_strnlen.c index 9bc3064cb1..863a310caa 100644 --- a/libc/string/lib_strnlen.c +++ b/libc/string/lib_strnlen.c @@ -49,7 +49,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ #ifndef CONFIG_ARCH_STRNLEN diff --git a/libc/string/lib_strpbrk.c b/libc/string/lib_strpbrk.c index 3f19dec6e6..c97b395e51 100644 --- a/libc/string/lib_strpbrk.c +++ b/libc/string/lib_strpbrk.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ char *strpbrk(const char *str, const char *charset) diff --git a/libc/string/lib_strrchr.c b/libc/string/lib_strrchr.c index 08575c82bf..2432853d73 100644 --- a/libc/string/lib_strrchr.c +++ b/libc/string/lib_strrchr.c @@ -42,7 +42,7 @@ #include /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ /* The strrchr() function returns a pointer to the last diff --git a/libc/string/lib_strspn.c b/libc/string/lib_strspn.c index 6894b2b9dc..47ab34d8b2 100644 --- a/libc/string/lib_strspn.c +++ b/libc/string/lib_strspn.c @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/string/lib_strstr.c b/libc/string/lib_strstr.c index 0c695f7de2..eb629b709a 100644 --- a/libc/string/lib_strstr.c +++ b/libc/string/lib_strstr.c @@ -42,7 +42,7 @@ #include /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ FAR char *strstr(FAR const char *str, FAR const char *substr) diff --git a/libc/syslog/lib_lowsyslog.c b/libc/syslog/lib_lowsyslog.c index 79c4a99ff8..7cbc59180b 100644 --- a/libc/syslog/lib_lowsyslog.c +++ b/libc/syslog/lib_lowsyslog.c @@ -61,15 +61,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/syslog/lib_syslog.c b/libc/syslog/lib_syslog.c index 6364010461..533f61bec5 100644 --- a/libc/syslog/lib_syslog.c +++ b/libc/syslog/lib_syslog.c @@ -60,15 +60,15 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Global Constant Data + * Public Constant Data ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_cfgetspeed.c b/libc/termios/lib_cfgetspeed.c index 1cd5ee96d3..b20e881604 100644 --- a/libc/termios/lib_cfgetspeed.c +++ b/libc/termios/lib_cfgetspeed.c @@ -49,7 +49,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_cfsetspeed.c b/libc/termios/lib_cfsetspeed.c index bb1bde7011..8c76117536 100644 --- a/libc/termios/lib_cfsetspeed.c +++ b/libc/termios/lib_cfsetspeed.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcflush.c b/libc/termios/lib_tcflush.c index 1a9710f6a0..3203493432 100644 --- a/libc/termios/lib_tcflush.c +++ b/libc/termios/lib_tcflush.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcgetattr.c b/libc/termios/lib_tcgetattr.c index 631bb60638..5c9c671d76 100644 --- a/libc/termios/lib_tcgetattr.c +++ b/libc/termios/lib_tcgetattr.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcsetattr.c b/libc/termios/lib_tcsetattr.c index 8d7b5ccb07..85e96111cf 100644 --- a/libc/termios/lib_tcsetattr.c +++ b/libc/termios/lib_tcsetattr.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_calendar2utc.c b/libc/time/lib_calendar2utc.c index 4ed9f1d608..95b33e2321 100644 --- a/libc/time/lib_calendar2utc.c +++ b/libc/time/lib_calendar2utc.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_dayofweek.c b/libc/time/lib_dayofweek.c index 40d7516dc4..b630c838cb 100644 --- a/libc/time/lib_dayofweek.c +++ b/libc/time/lib_dayofweek.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_daysbeforemonth.c b/libc/time/lib_daysbeforemonth.c index ec08afbdae..e0cad2d206 100644 --- a/libc/time/lib_daysbeforemonth.c +++ b/libc/time/lib_daysbeforemonth.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_gmtime.c b/libc/time/lib_gmtime.c index 9ad6709003..487969bab7 100644 --- a/libc/time/lib_gmtime.c +++ b/libc/time/lib_gmtime.c @@ -62,7 +62,7 @@ **************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /************************************************************************** diff --git a/libc/time/lib_gmtimer.c b/libc/time/lib_gmtimer.c index 59b32fe57e..c397ae772d 100644 --- a/libc/time/lib_gmtimer.c +++ b/libc/time/lib_gmtimer.c @@ -78,7 +78,7 @@ static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); **************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /************************************************************************** diff --git a/libc/time/lib_isleapyear.c b/libc/time/lib_isleapyear.c index 2a1a8664c4..faa1412189 100644 --- a/libc/time/lib_isleapyear.c +++ b/libc/time/lib_isleapyear.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_mktime.c b/libc/time/lib_mktime.c index b216c8dc35..84b00ae79a 100644 --- a/libc/time/lib_mktime.c +++ b/libc/time/lib_mktime.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_access.c b/libc/unistd/lib_access.c index ce7e24c7ed..f700a2d6ae 100644 --- a/libc/unistd/lib_access.c +++ b/libc/unistd/lib_access.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_chdir.c b/libc/unistd/lib_chdir.c index 8953fb19b6..969b06a2da 100644 --- a/libc/unistd/lib_chdir.c +++ b/libc/unistd/lib_chdir.c @@ -50,7 +50,7 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_execl.c b/libc/unistd/lib_execl.c index 040941c170..86bb3aed69 100644 --- a/libc/unistd/lib_execl.c +++ b/libc/unistd/lib_execl.c @@ -56,7 +56,7 @@ #define MAX_EXECL_ARGS 256 /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getcwd.c b/libc/unistd/lib_getcwd.c index 694af4070d..9a25399996 100644 --- a/libc/unistd/lib_getcwd.c +++ b/libc/unistd/lib_getcwd.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getopt.c b/libc/unistd/lib_getopt.c index bda9666be5..0c939fc420 100644 --- a/libc/unistd/lib_getopt.c +++ b/libc/unistd/lib_getopt.c @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ FAR char *optarg; /* Optional argument following option */ @@ -63,7 +63,7 @@ static FAR char *g_optptr = NULL; static bool g_binitialized = false; /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getoptargp.c b/libc/unistd/lib_getoptargp.c index 5cd1a55d3d..826132e07d 100644 --- a/libc/unistd/lib_getoptargp.c +++ b/libc/unistd/lib_getoptargp.c @@ -46,7 +46,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getoptindp.c b/libc/unistd/lib_getoptindp.c index 2563aa3848..a487d9b126 100644 --- a/libc/unistd/lib_getoptindp.c +++ b/libc/unistd/lib_getoptindp.c @@ -46,7 +46,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getoptoptp.c b/libc/unistd/lib_getoptoptp.c index 95e024a726..238d68ac53 100644 --- a/libc/unistd/lib_getoptoptp.c +++ b/libc/unistd/lib_getoptoptp.c @@ -46,7 +46,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_sleep.c b/libc/unistd/lib_sleep.c index 23b6cfb838..26f8d5b91e 100644 --- a/libc/unistd/lib_sleep.c +++ b/libc/unistd/lib_sleep.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c index c09de769d8..09a06feeeb 100644 --- a/libc/unistd/lib_usleep.c +++ b/libc/unistd/lib_usleep.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_cancel.c b/libc/wqueue/work_cancel.c index 93a82e80c3..393c84359c 100644 --- a/libc/wqueue/work_cancel.c +++ b/libc/wqueue/work_cancel.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_lock.c b/libc/wqueue/work_lock.c index 6ae5d11e83..7b6635991c 100644 --- a/libc/wqueue/work_lock.c +++ b/libc/wqueue/work_lock.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_queue.c b/libc/wqueue/work_queue.c index ce0bf4024c..ae3a412c57 100644 --- a/libc/wqueue/work_queue.c +++ b/libc/wqueue/work_queue.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_signal.c b/libc/wqueue/work_signal.c index 7e0cfb1ade..a474c2bc36 100644 --- a/libc/wqueue/work_signal.c +++ b/libc/wqueue/work_signal.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/libnx/nxcontext.h b/libnx/nxcontext.h index 16ec327628..59bf928327 100644 --- a/libnx/nxcontext.h +++ b/libnx/nxcontext.h @@ -105,7 +105,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/mm/mm_gran/mm_granalloc.c b/mm/mm_gran/mm_granalloc.c index f66e5168bc..f3537c7d6a 100644 --- a/mm/mm_gran/mm_granalloc.c +++ b/mm/mm_gran/mm_granalloc.c @@ -253,7 +253,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/mm/mm_gran/mm_granfree.c b/mm/mm_gran/mm_granfree.c index d2df5cd4d4..a1b9db9917 100644 --- a/mm/mm_gran/mm_granfree.c +++ b/mm/mm_gran/mm_granfree.c @@ -137,7 +137,7 @@ static inline void gran_common_free(FAR struct gran_s *priv, } /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/mm/mm_heap/mm_addfreechunk.c b/mm/mm_heap/mm_addfreechunk.c index 64b503dd74..7119eebe78 100644 --- a/mm/mm_heap/mm_addfreechunk.c +++ b/mm/mm_heap/mm_addfreechunk.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index f2d02d64bd..188b55dd83 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index 05fc3a7a0d..ab6c39c20a 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/net/devif/devif_initialize.c b/net/devif/devif_initialize.c index 58fcd8cd03..606a22f9b7 100644 --- a/net/devif/devif_initialize.c +++ b/net/devif/devif_initialize.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* IP/TCP/UDP/ICMP statistics for all network interfaces */ diff --git a/net/devif/devif_iobsend.c b/net/devif/devif_iobsend.c index d05109f90f..157064b0c0 100644 --- a/net/devif/devif_iobsend.c +++ b/net/devif/devif_iobsend.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/devif/devif_pktsend.c b/net/devif/devif_pktsend.c index 8cfd091c0d..1f65182efd 100644 --- a/net/devif/devif_pktsend.c +++ b/net/devif/devif_pktsend.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/devif/devif_send.c b/net/devif/devif_send.c index d2299ebdc5..69781a87fb 100644 --- a/net/devif/devif_send.c +++ b/net/devif/devif_send.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index d350d0c35c..9f23161227 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -94,7 +94,7 @@ struct icmp_ping_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmp/icmp_poll.c b/net/icmp/icmp_poll.c index 06ccb8cd19..a2da120887 100644 --- a/net/icmp/icmp_poll.c +++ b/net/icmp/icmp_poll.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmp/icmp_send.c b/net/icmp/icmp_send.c index e966242740..076d598a0c 100644 --- a/net/icmp/icmp_send.c +++ b/net/icmp/icmp_send.c @@ -60,7 +60,7 @@ #define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index 333b708072..3cb74d3a48 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -97,7 +97,7 @@ struct icmpv6_ping_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmpv6/icmpv6_poll.c b/net/icmpv6/icmpv6_poll.c index a87f42161c..7db797cb2c 100644 --- a/net/icmpv6/icmpv6_poll.c +++ b/net/icmpv6/icmpv6_poll.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index ad1fe8f8e6..f800503ff2 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -79,7 +79,7 @@ #define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index 733da5596f..f21c3716fc 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -61,7 +61,7 @@ #define PKTBUF ((struct eth_hdr_s *)&dev->d_buf) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index 701ce01176..14c536fbc1 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/socket/socket.h b/net/socket/socket.h index 7137b143ef..3793573961 100644 --- a/net/socket/socket.h +++ b/net/socket/socket.h @@ -135,7 +135,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #undef EXTERN diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index ab799d975a..b1580112bb 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_devpoll.c b/net/tcp/tcp_devpoll.c index 9f971db286..92f7c57668 100644 --- a/net/tcp/tcp_devpoll.c +++ b/net/tcp/tcp_devpoll.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index f6af2bbbdc..c63a08557c 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 536cf2dc44..dc1d3496f0 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -69,7 +69,7 @@ #define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 25659790ab..16dd2e3226 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_devpoll.c b/net/udp/udp_devpoll.c index 8352b7b266..a142db1543 100644 --- a/net/udp/udp_devpoll.c +++ b/net/udp/udp_devpoll.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_input.c b/net/udp/udp_input.c index f699e74ffb..a77371d0e8 100644 --- a/net/udp/udp_input.c +++ b/net/udp/udp_input.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index c54933d715..b505a5953f 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -75,7 +75,7 @@ ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/clock/clock.h b/sched/clock/clock.h index 154af6f5a3..8a5c55a3e7 100644 --- a/sched/clock/clock.h +++ b/sched/clock/clock.h @@ -64,7 +64,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ #if !defined(CONFIG_SCHED_TICKLESS) && !defined(__HAVE_KERNEL_GLOBALS) diff --git a/sched/clock/clock_abstime2ticks.c b/sched/clock/clock_abstime2ticks.c index 46b1086856..a33b2acc1b 100644 --- a/sched/clock/clock_abstime2ticks.c +++ b/sched/clock/clock_abstime2ticks.c @@ -53,7 +53,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/clock/clock_getres.c b/sched/clock/clock_getres.c index ef48a363eb..656b794553 100644 --- a/sched/clock/clock_getres.c +++ b/sched/clock/clock_getres.c @@ -63,7 +63,7 @@ **********************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /********************************************************************** diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index ddd71a2e17..1a92a66bc5 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -67,7 +67,7 @@ **********************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /********************************************************************** diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 50a9af1050..c1a155707f 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -77,7 +77,7 @@ **************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifndef CONFIG_SCHED_TICKLESS diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index e9f27f0f6a..8d247f0c6c 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -66,7 +66,7 @@ **********************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /********************************************************************** diff --git a/sched/clock/clock_ticks2time.c b/sched/clock/clock_ticks2time.c index d77f8497f6..07b7c915bc 100644 --- a/sched/clock/clock_ticks2time.c +++ b/sched/clock/clock_ticks2time.c @@ -51,7 +51,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/clock/clock_time2ticks.c b/sched/clock/clock_time2ticks.c index df3407f2af..f01d91b402 100644 --- a/sched/clock/clock_time2ticks.c +++ b/sched/clock/clock_time2ticks.c @@ -53,7 +53,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/environ/environ.h b/sched/environ/environ.h index 98fc98728a..c570835c87 100644 --- a/sched/environ/environ.h +++ b/sched/environ/environ.h @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef __cplusplus diff --git a/sched/group/group_free.c b/sched/group/group_free.c index ce0cc9cad7..b3830e4f7a 100644 --- a/sched/group/group_free.c +++ b/sched/group/group_free.c @@ -59,7 +59,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/group/group_malloc.c b/sched/group/group_malloc.c index 89c0eccfde..03c603953c 100644 --- a/sched/group/group_malloc.c +++ b/sched/group/group_malloc.c @@ -59,7 +59,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/group/group_zalloc.c b/sched/group/group_zalloc.c index 2fcea0d5ed..e45deaf4b3 100644 --- a/sched/group/group_zalloc.c +++ b/sched/group/group_zalloc.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/init/init.h b/sched/init/init.h index d3f3ae9132..8d60a71694 100644 --- a/sched/init/init.h +++ b/sched/init/init.h @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/init/os_start.c b/sched/init/os_start.c index cafec16a1d..29d3bc68f1 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -81,7 +81,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /* Task Lists ***************************************************************/ diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 25bda551e5..2e0269243b 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -57,7 +57,7 @@ extern FAR xcpt_t g_irqvector[NR_IRQS+1]; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/irq/irq_attach.c b/sched/irq/irq_attach.c index 8e7d2d275e..e218a7015c 100644 --- a/sched/irq/irq_attach.c +++ b/sched/irq/irq_attach.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c index 1da5d49c1a..98f6f28e3d 100644 --- a/sched/irq/irq_dispatch.c +++ b/sched/irq/irq_dispatch.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/irq/irq_initialize.c b/sched/irq/irq_initialize.c index f9e97e933d..9043260914 100644 --- a/sched/irq/irq_initialize.c +++ b/sched/irq/irq_initialize.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ FAR xcpt_t g_irqvector[NR_IRQS+1]; diff --git a/sched/irq/irq_unexpectedisr.c b/sched/irq/irq_unexpectedisr.c index d4eacbee1d..9f207ae860 100644 --- a/sched/irq/irq_unexpectedisr.c +++ b/sched/irq/irq_unexpectedisr.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_desclose.c b/sched/mqueue/mq_desclose.c index ea77793d36..ae0dc1cefe 100644 --- a/sched/mqueue/mq_desclose.c +++ b/sched/mqueue/mq_desclose.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_descreate.c b/sched/mqueue/mq_descreate.c index df6c8fcdc3..f7f2eba5da 100644 --- a/sched/mqueue/mq_descreate.c +++ b/sched/mqueue/mq_descreate.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index fa0afa40ed..9d98fe4170 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -62,7 +62,7 @@ struct mq_des_block_s }; /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /* The g_msgfree is a list of messages that are available for general diff --git a/sched/mqueue/mq_msgfree.c b/sched/mqueue/mq_msgfree.c index 1630c09d06..7944e7d1cd 100644 --- a/sched/mqueue/mq_msgfree.c +++ b/sched/mqueue/mq_msgfree.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_msgqalloc.c b/sched/mqueue/mq_msgqalloc.c index 280f1f1821..39c7e04c3a 100644 --- a/sched/mqueue/mq_msgqalloc.c +++ b/sched/mqueue/mq_msgqalloc.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_msgqfree.c b/sched/mqueue/mq_msgqfree.c index 4d899fb3c9..08360c239e 100644 --- a/sched/mqueue/mq_msgqfree.c +++ b/sched/mqueue/mq_msgqfree.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index 81852513d7..e6efa8a781 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -58,7 +58,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index 9c69dfe642..fa7932f0c2 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c index 8468daebd6..7db59ebb5e 100644 --- a/sched/mqueue/mq_receive.c +++ b/sched/mqueue/mq_receive.c @@ -57,7 +57,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_recover.c b/sched/mqueue/mq_recover.c index 3e1ce7e307..667df72907 100644 --- a/sched/mqueue/mq_recover.c +++ b/sched/mqueue/mq_recover.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_release.c b/sched/mqueue/mq_release.c index 42276d124b..9c0e3409c3 100644 --- a/sched/mqueue/mq_release.c +++ b/sched/mqueue/mq_release.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index 457b26922d..7ba1d1ca9c 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index d70c165d2c..3bfb4d9e56 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index eb1822f7e4..858bf60e96 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 929a5bc610..03fa03265e 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c index e22f67d2bb..092319f8e4 100644 --- a/sched/mqueue/mq_waitirq.c +++ b/sched/mqueue/mq_waitirq.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mqueue.h b/sched/mqueue/mqueue.h index bd771e140e..170fcd7a56 100644 --- a/sched/mqueue/mqueue.h +++ b/sched/mqueue/mqueue.h @@ -102,7 +102,7 @@ struct mqueue_msg_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef __cplusplus diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index 21717231a6..7ebdc16829 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -52,7 +52,7 @@ #include "paging/paging.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 1ccc123d30..25643dd3a7 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /* This is the task ID of the page fill worker thread. This value was set in diff --git a/sched/pthread/pthread.h b/sched/pthread/pthread.h index a436bd090c..1c4faa3441 100644 --- a/sched/pthread/pthread.h +++ b/sched/pthread/pthread.h @@ -79,7 +79,7 @@ struct join_s }; /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ #ifdef __cplusplus diff --git a/sched/pthread/pthread_barrierdestroy.c b/sched/pthread/pthread_barrierdestroy.c index b2535b0e41..edf88a28f9 100644 --- a/sched/pthread/pthread_barrierdestroy.c +++ b/sched/pthread/pthread_barrierdestroy.c @@ -53,7 +53,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/pthread/pthread_barrierinit.c b/sched/pthread/pthread_barrierinit.c index 4185d71807..4686985144 100644 --- a/sched/pthread/pthread_barrierinit.c +++ b/sched/pthread/pthread_barrierinit.c @@ -53,7 +53,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/pthread/pthread_barrierwait.c b/sched/pthread/pthread_barrierwait.c index 7d0126eebe..74a459137f 100644 --- a/sched/pthread/pthread_barrierwait.c +++ b/sched/pthread/pthread_barrierwait.c @@ -54,7 +54,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index d8694eb519..09f3b829fd 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -60,7 +60,7 @@ **************************************************************************/ /************************************************************************** - * Global Variables + * Public Data **************************************************************************/ /************************************************************************** diff --git a/sched/pthread/pthread_completejoin.c b/sched/pthread/pthread_completejoin.c index 0546edf5b5..6af2774e1b 100644 --- a/sched/pthread/pthread_completejoin.c +++ b/sched/pthread/pthread_completejoin.c @@ -58,7 +58,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_condbroadcast.c b/sched/pthread/pthread_condbroadcast.c index 2983fb2e9e..98aa73f363 100644 --- a/sched/pthread/pthread_condbroadcast.c +++ b/sched/pthread/pthread_condbroadcast.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_conddestroy.c b/sched/pthread/pthread_conddestroy.c index 1b144be728..5cb5823ad4 100644 --- a/sched/pthread/pthread_conddestroy.c +++ b/sched/pthread/pthread_conddestroy.c @@ -45,7 +45,7 @@ #include "pthread/pthread.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_condinit.c b/sched/pthread/pthread_condinit.c index ce7c1acbf2..5671840233 100644 --- a/sched/pthread/pthread_condinit.c +++ b/sched/pthread/pthread_condinit.c @@ -46,7 +46,7 @@ #include "pthread/pthread.h" /**************************************************************************** - * Global Functions + * Public Functions ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_condsignal.c b/sched/pthread/pthread_condsignal.c index c798f0d2c1..85d020bc31 100644 --- a/sched/pthread/pthread_condsignal.c +++ b/sched/pthread/pthread_condsignal.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 3a3e6f21f7..6e9fa60dec 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 7460510a14..5c907ceac9 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 450ff76a53..704a296dc2 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -59,7 +59,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 133cc52151..03b3f6f2f4 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -62,7 +62,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_findjoininfo.c b/sched/pthread/pthread_findjoininfo.c index df5c82b033..35ea396c33 100644 --- a/sched/pthread/pthread_findjoininfo.c +++ b/sched/pthread/pthread_findjoininfo.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index 984902704c..d0c13a717d 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index c616fb764f..6fb0e29deb 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -56,7 +56,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_initialize.c b/sched/pthread/pthread_initialize.c index e946220b7b..05dd8d8fad 100644 --- a/sched/pthread/pthread_initialize.c +++ b/sched/pthread/pthread_initialize.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index 43843deed0..003f06ccef 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c index 9e4dccdc25..68af593a63 100644 --- a/sched/pthread/pthread_keycreate.c +++ b/sched/pthread/pthread_keycreate.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_keydelete.c b/sched/pthread/pthread_keydelete.c index ff1fba7bff..64a633af3e 100644 --- a/sched/pthread/pthread_keydelete.c +++ b/sched/pthread/pthread_keydelete.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index 3f768e1458..04e2b37835 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_mutexinit.c b/sched/pthread/pthread_mutexinit.c index 0236830a06..7bba3ae6a4 100644 --- a/sched/pthread/pthread_mutexinit.c +++ b/sched/pthread/pthread_mutexinit.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index dad492c814..d1bce84e67 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index ec6357ce3b..0591ecf25d 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 0d340d08c7..55ffa8b9f0 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_once.c b/sched/pthread/pthread_once.c index 1854515110..7254fdbc88 100644 --- a/sched/pthread/pthread_once.c +++ b/sched/pthread/pthread_once.c @@ -54,7 +54,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/pthread/pthread_release.c b/sched/pthread/pthread_release.c index 183053145a..86254ef12b 100644 --- a/sched/pthread/pthread_release.c +++ b/sched/pthread/pthread_release.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_setcancelstate.c b/sched/pthread/pthread_setcancelstate.c index be157a9f0d..b898c211f0 100644 --- a/sched/pthread/pthread_setcancelstate.c +++ b/sched/pthread/pthread_setcancelstate.c @@ -54,7 +54,7 @@ ******************************************************************************************/ /****************************************************************************************** - * Global Variables + * Public Data ******************************************************************************************/ /****************************************************************************************** diff --git a/sched/pthread/pthread_setschedparam.c b/sched/pthread/pthread_setschedparam.c index 8ff54a0227..972593c67c 100644 --- a/sched/pthread/pthread_setschedparam.c +++ b/sched/pthread/pthread_setschedparam.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_setschedprio.c b/sched/pthread/pthread_setschedprio.c index 7813c5df97..823386859b 100644 --- a/sched/pthread/pthread_setschedprio.c +++ b/sched/pthread/pthread_setschedprio.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c index f21c171bff..9b7e382ada 100644 --- a/sched/pthread/pthread_setspecific.c +++ b/sched/pthread/pthread_setspecific.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/pthread/pthread_sigmask.c b/sched/pthread/pthread_sigmask.c index 2950a7957a..4789f4aa98 100644 --- a/sched/pthread/pthread_sigmask.c +++ b/sched/pthread/pthread_sigmask.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/pthread/pthread_yield.c b/sched/pthread/pthread_yield.c index 0d5e99b3df..c6f5a2a41a 100644 --- a/sched/pthread/pthread_yield.c +++ b/sched/pthread/pthread_yield.c @@ -49,7 +49,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 938f89a768..2924e5bef7 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -100,7 +100,7 @@ struct tasklist_s }; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /* Declared in os_start.c ***************************************************/ diff --git a/sched/sched/sched_addblocked.c b/sched/sched/sched_addblocked.c index 5f95a6c9f8..af0f043c09 100644 --- a/sched/sched/sched_addblocked.c +++ b/sched/sched/sched_addblocked.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_addprioritized.c b/sched/sched/sched_addprioritized.c index d132f335e3..ad85e7d2db 100644 --- a/sched/sched/sched_addprioritized.c +++ b/sched/sched/sched_addprioritized.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 04cc2afcb4..129f78c75e 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index fe9305b3d2..cb75a8436d 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -70,7 +70,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index 1ef1579159..210c467340 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -61,7 +61,7 @@ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index 5ebfe6eaed..2edaafc7db 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index b42c831603..2743d9fe79 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index 58714df155..077fc61c80 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -56,7 +56,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_gettcb.c b/sched/sched/sched_gettcb.c index f54e51571d..174af730ac 100644 --- a/sched/sched/sched_gettcb.c +++ b/sched/sched/sched_gettcb.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index e07a7433b1..fc2887cd1a 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_lockcount.c b/sched/sched/sched_lockcount.c index 72561650c4..5e44c14f60 100644 --- a/sched/sched/sched_lockcount.c +++ b/sched/sched/sched_lockcount.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 6ba03662a0..993a3a00ce 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -55,7 +55,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index 05f9bfdf8b..0555cb67dc 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -63,7 +63,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_removeblocked.c b/sched/sched/sched_removeblocked.c index b17ec045a1..944e3fa932 100644 --- a/sched/sched/sched_removeblocked.c +++ b/sched/sched/sched_removeblocked.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 0fdcc1a294..9cad532f8c 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_reprioritize.c b/sched/sched/sched_reprioritize.c index 6728547d2a..e6ac01e58c 100644 --- a/sched/sched/sched_reprioritize.c +++ b/sched/sched/sched_reprioritize.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_self.c b/sched/sched/sched_self.c index 75e4084cd8..9dda2161b8 100644 --- a/sched/sched/sched_self.c +++ b/sched/sched/sched_self.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index a34fdba955..191b972f2c 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_verifytcb.c b/sched/sched/sched_verifytcb.c index 33ead33f66..31ff091884 100644 --- a/sched/sched/sched_verifytcb.c +++ b/sched/sched/sched_verifytcb.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/sched/sched_yield.c b/sched/sched/sched_yield.c index 933d03ede2..c7051d8d73 100644 --- a/sched/sched/sched_yield.c +++ b/sched/sched/sched_yield.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c index 1d1a955d10..adaef3e552 100644 --- a/sched/semaphore/sem_destroy.c +++ b/sched/semaphore/sem_destroy.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 22082b6130..b8bdd6c2ee 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -68,7 +68,7 @@ typedef int (*holderhandler_t)(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg); /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 974b6d20be..25edceb89b 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_recover.c b/sched/semaphore/sem_recover.c index fd40e6b7dc..f34662b81d 100644 --- a/sched/semaphore/sem_recover.c +++ b/sched/semaphore/sem_recover.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index ed8ceab707..da4547b47e 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index f4e267f6aa..883a2c3adc 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index e40141c9cb..c0d77f07c3 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 4d0f845875..5619dec045 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_allocatependingsigaction.c b/sched/signal/sig_allocatependingsigaction.c index 3ea627a298..55f7727cda 100644 --- a/sched/signal/sig_allocatependingsigaction.c +++ b/sched/signal/sig_allocatependingsigaction.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_cleanup.c b/sched/signal/sig_cleanup.c index 58fc1093c7..c0ce3a10d0 100644 --- a/sched/signal/sig_cleanup.c +++ b/sched/signal/sig_cleanup.c @@ -51,7 +51,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_deliver.c b/sched/signal/sig_deliver.c index c91a10e403..7f2291b4b6 100644 --- a/sched/signal/sig_deliver.c +++ b/sched/signal/sig_deliver.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 2113487e55..a292424784 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index 62a7807c1a..21062ff102 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -49,7 +49,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index 66d24b9753..ef217e92d6 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /* The g_sigfreeaction data structure is a list of available signal diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 2183598602..b0ef01dacb 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -48,7 +48,7 @@ #include "signal/signal.h" /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_lowest.c b/sched/signal/sig_lowest.c index 46f0de0c9b..76f2d04c04 100644 --- a/sched/signal/sig_lowest.c +++ b/sched/signal/sig_lowest.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_mqnotempty.c b/sched/signal/sig_mqnotempty.c index 4fa0196a17..25ce0e3ae1 100644 --- a/sched/signal/sig_mqnotempty.c +++ b/sched/signal/sig_mqnotempty.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index c540d34514..25f9f30231 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_pause.c b/sched/signal/sig_pause.c index 9344c2bec3..9c390308f4 100644 --- a/sched/signal/sig_pause.c +++ b/sched/signal/sig_pause.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index f60c56e907..947813b4a9 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index 0ef425a2dc..d5213a7e97 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index bc0aa01012..8b09528f80 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_releasependingsigaction.c b/sched/signal/sig_releasependingsigaction.c index 424d733684..b7d80d1c2e 100644 --- a/sched/signal/sig_releasependingsigaction.c +++ b/sched/signal/sig_releasependingsigaction.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_releasependingsignal.c b/sched/signal/sig_releasependingsignal.c index 0b58a35cba..88ec8297a7 100644 --- a/sched/signal/sig_releasependingsignal.c +++ b/sched/signal/sig_releasependingsignal.c @@ -61,7 +61,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_removependingsignal.c b/sched/signal/sig_removependingsignal.c index 1eeef02d3a..299babbc39 100644 --- a/sched/signal/sig_removependingsignal.c +++ b/sched/signal/sig_removependingsignal.c @@ -61,7 +61,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_suspend.c b/sched/signal/sig_suspend.c index 807eb25176..11b41fbf04 100644 --- a/sched/signal/sig_suspend.c +++ b/sched/signal/sig_suspend.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 18ab5075c4..67b0032a7b 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/sig_unmaskpendingsignal.c b/sched/signal/sig_unmaskpendingsignal.c index 9c4c9ba2ea..01bf2403e1 100644 --- a/sched/signal/sig_unmaskpendingsignal.c +++ b/sched/signal/sig_unmaskpendingsignal.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/signal/sig_waitinfo.c b/sched/signal/sig_waitinfo.c index 6e7fc1b170..2107071160 100644 --- a/sched/signal/sig_waitinfo.c +++ b/sched/signal/sig_waitinfo.c @@ -49,7 +49,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/signal/signal.h b/sched/signal/signal.h index fce53f916c..bce55af8bd 100644 --- a/sched/signal/signal.h +++ b/sched/signal/signal.h @@ -117,7 +117,7 @@ struct sigq_s typedef struct sigq_s sigq_t; /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /* The g_sigfreeaction data structure is a list of available signal action diff --git a/sched/task/exit.c b/sched/task/exit.c index 85cc99cba3..c968315803 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task.h b/sched/task/task.h index 17f4931516..b4967c799a 100644 --- a/sched/task/task.h +++ b/sched/task/task.h @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** * Public Function Prototypes diff --git a/sched/task/task_activate.c b/sched/task/task_activate.c index 43cc553aa0..1c97f60dd1 100644 --- a/sched/task/task_activate.c +++ b/sched/task/task_activate.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c index d8d99eb9e6..8e13709b9a 100644 --- a/sched/task/task_atexit.c +++ b/sched/task/task_atexit.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_create.c b/sched/task/task_create.c index 0da676fb42..0ab710b90b 100644 --- a/sched/task/task_create.c +++ b/sched/task/task_create.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_delete.c b/sched/task/task_delete.c index ae5ab231f6..7b0f06a06d 100644 --- a/sched/task/task_delete.c +++ b/sched/task/task_delete.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index 89e2c0603c..39c52c9b75 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index e471e64578..f6b5ffa550 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index 7f538bd1b5..058fd70892 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Data ************************************************************************/ /************************************************************************ diff --git a/sched/task/task_init.c b/sched/task/task_init.c index 8a05cf6035..7b7fc6215a 100644 --- a/sched/task/task_init.c +++ b/sched/task/task_init.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c index 71d6710264..424d4428c1 100644 --- a/sched/task/task_onexit.c +++ b/sched/task/task_onexit.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index a81115c173..eaf25ab73d 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 5474c91265..5b36fe5d61 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_start.c b/sched/task/task_start.c index 9432c537e5..48ab75a3ad 100644 --- a/sched/task/task_start.c +++ b/sched/task/task_start.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_starthook.c b/sched/task/task_starthook.c index 7c43b7b267..c36517599e 100644 --- a/sched/task/task_starthook.c +++ b/sched/task/task_starthook.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_terminate.c b/sched/task/task_terminate.c index c8192f50bc..b3f5678b90 100644 --- a/sched/task/task_terminate.c +++ b/sched/task/task_terminate.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wd_cancel.c b/sched/wdog/wd_cancel.c index 1a53801d46..3a20cd611d 100644 --- a/sched/wdog/wd_cancel.c +++ b/sched/wdog/wd_cancel.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wd_create.c b/sched/wdog/wd_create.c index db303d1627..82078cde58 100644 --- a/sched/wdog/wd_create.c +++ b/sched/wdog/wd_create.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wd_delete.c b/sched/wdog/wd_delete.c index 11345ae055..789f0b007f 100644 --- a/sched/wdog/wd_delete.c +++ b/sched/wdog/wd_delete.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wd_gettime.c b/sched/wdog/wd_gettime.c index 3c553fde8e..03b815f815 100644 --- a/sched/wdog/wd_gettime.c +++ b/sched/wdog/wd_gettime.c @@ -53,7 +53,7 @@ ********************************************************************************/ /******************************************************************************** - * Global Variables + * Public Data ********************************************************************************/ /******************************************************************************** diff --git a/sched/wdog/wd_initialize.c b/sched/wdog/wd_initialize.c index 23242b6bf5..bd3f9644c1 100644 --- a/sched/wdog/wd_initialize.c +++ b/sched/wdog/wd_initialize.c @@ -52,7 +52,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ /* The g_wdfreelist data structure is a singly linked list of watchdogs diff --git a/sched/wdog/wd_recover.c b/sched/wdog/wd_recover.c index bc1b3a839e..f9471a64b3 100644 --- a/sched/wdog/wd_recover.c +++ b/sched/wdog/wd_recover.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index ba7cc06aa2..90ce73c151 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -86,7 +86,7 @@ typedef void (*wdentry4_t)(int argc, wdparm_t arg1, wdparm_t arg2, #endif /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wdog/wdog.h b/sched/wdog/wdog.h index f26b90f910..ccc7ac458c 100644 --- a/sched/wdog/wdog.h +++ b/sched/wdog/wdog.h @@ -57,7 +57,7 @@ ************************************************************************/ /************************************************************************ - * Public Variables + * Public Data ************************************************************************/ #ifdef __cplusplus diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 177847679f..c4175f7f03 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index 69eca718c1..45bd740600 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/wqueue/kwork_signal.c b/sched/wqueue/kwork_signal.c index d08263b5e9..885652f27e 100644 --- a/sched/wqueue/kwork_signal.c +++ b/sched/wqueue/kwork_signal.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** -- GitLab From 5b51a9fcddaa5fa91dbf86cc25f474925411bfa0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 17:43:18 -0600 Subject: [PATCH 185/858] Standardize the width of all comment boxes in C files --- arch | 2 +- binfmt/binfmt_dumpmodule.c | 8 ++-- binfmt/nxflat.c | 8 ++-- binfmt/symtab_findbyname.c | 4 +- binfmt/symtab_findbyvalue.c | 4 +- binfmt/symtab_findorderedbyname.c | 4 +- binfmt/symtab_findorderedbyvalue.c | 4 +- configs | 2 +- drivers/sercomm/console.c | 2 +- drivers/sercomm/uart.c | 2 +- drivers/spi/spi_bitbang.c | 2 +- drivers/usbdev/composite.c | 2 +- drivers/wireless/cc3000/cc3000drv.c | 2 +- fs/mqueue/mq_unlink.c | 36 +++++++------- fs/vfs/fs_sendfile.c | 32 ++++++------- fs/vfs/fs_write.c | 2 +- libc/fixedmath/lib_fixedmath.c | 10 ++-- libc/math/lib_acos.c | 12 ++--- libc/math/lib_acosf.c | 12 ++--- libc/math/lib_acosh.c | 10 ++-- libc/math/lib_acoshf.c | 10 ++-- libc/math/lib_acoshl.c | 10 ++-- libc/math/lib_acosl.c | 12 ++--- libc/math/lib_asin.c | 16 +++---- libc/math/lib_asinf.c | 12 ++--- libc/math/lib_asinh.c | 10 ++-- libc/math/lib_asinhf.c | 10 ++-- libc/math/lib_asinhl.c | 10 ++-- libc/math/lib_asinl.c | 12 ++--- libc/math/lib_atan.c | 12 ++--- libc/math/lib_atan2.c | 12 ++--- libc/math/lib_atan2f.c | 12 ++--- libc/math/lib_atan2l.c | 12 ++--- libc/math/lib_atanf.c | 12 ++--- libc/math/lib_atanh.c | 10 ++-- libc/math/lib_atanhf.c | 10 ++-- libc/math/lib_atanhl.c | 10 ++-- libc/math/lib_atanl.c | 12 ++--- libc/math/lib_ceil.c | 12 ++--- libc/math/lib_ceilf.c | 12 ++--- libc/math/lib_ceill.c | 12 ++--- libc/math/lib_copysign.c | 8 ++-- libc/math/lib_copysignf.c | 8 ++-- libc/math/lib_copysignl.c | 8 ++-- libc/math/lib_cos.c | 12 ++--- libc/math/lib_cosf.c | 12 ++--- libc/math/lib_cosh.c | 12 ++--- libc/math/lib_coshf.c | 12 ++--- libc/math/lib_coshl.c | 12 ++--- libc/math/lib_cosl.c | 12 ++--- libc/math/lib_erf.c | 10 ++-- libc/math/lib_erff.c | 10 ++-- libc/math/lib_erfl.c | 10 ++-- libc/math/lib_exp.c | 16 +++---- libc/math/lib_expf.c | 16 +++---- libc/math/lib_expl.c | 16 +++---- libc/math/lib_fabs.c | 12 ++--- libc/math/lib_fabsf.c | 12 ++--- libc/math/lib_fabsl.c | 12 ++--- libc/math/lib_floor.c | 12 ++--- libc/math/lib_floorf.c | 12 ++--- libc/math/lib_floorl.c | 12 ++--- libc/math/lib_fmod.c | 12 ++--- libc/math/lib_fmodf.c | 12 ++--- libc/math/lib_fmodl.c | 12 ++--- libc/math/lib_frexp.c | 12 ++--- libc/math/lib_frexpf.c | 12 ++--- libc/math/lib_frexpl.c | 12 ++--- libc/math/lib_ldexp.c | 12 ++--- libc/math/lib_ldexpf.c | 12 ++--- libc/math/lib_ldexpl.c | 12 ++--- libc/math/lib_libexpi.c | 24 +++++----- libc/math/lib_libsqrtapprox.c | 12 ++--- libc/math/lib_log.c | 12 ++--- libc/math/lib_log10.c | 12 ++--- libc/math/lib_log10f.c | 12 ++--- libc/math/lib_log10l.c | 12 ++--- libc/math/lib_log2.c | 12 ++--- libc/math/lib_log2f.c | 12 ++--- libc/math/lib_log2l.c | 12 ++--- libc/math/lib_logf.c | 12 ++--- libc/math/lib_logl.c | 12 ++--- libc/math/lib_modf.c | 12 ++--- libc/math/lib_modff.c | 12 ++--- libc/math/lib_modfl.c | 12 ++--- libc/math/lib_pow.c | 12 ++--- libc/math/lib_powf.c | 12 ++--- libc/math/lib_powl.c | 12 ++--- libc/math/lib_rint.c | 40 ++++++++-------- libc/math/lib_rintf.c | 40 ++++++++-------- libc/math/lib_rintl.c | 40 ++++++++-------- libc/math/lib_round.c | 12 ++--- libc/math/lib_roundf.c | 12 ++--- libc/math/lib_roundl.c | 12 ++--- libc/math/lib_sin.c | 16 +++---- libc/math/lib_sinf.c | 16 +++---- libc/math/lib_sinh.c | 12 ++--- libc/math/lib_sinhf.c | 12 ++--- libc/math/lib_sinhl.c | 12 ++--- libc/math/lib_sinl.c | 16 +++---- libc/math/lib_sqrt.c | 12 ++--- libc/math/lib_sqrtf.c | 12 ++--- libc/math/lib_sqrtl.c | 12 ++--- libc/math/lib_tan.c | 12 ++--- libc/math/lib_tanf.c | 12 ++--- libc/math/lib_tanh.c | 12 ++--- libc/math/lib_tanhf.c | 12 ++--- libc/math/lib_tanhl.c | 12 ++--- libc/math/lib_tanl.c | 12 ++--- libc/math/lib_trunc.c | 8 ++-- libc/math/lib_truncf.c | 8 ++-- libc/math/lib_truncl.c | 8 ++-- libc/misc/lib_filesem.c | 32 ++++++------- libc/misc/lib_sendfile.c | 32 ++++++------- libc/misc/lib_streamsem.c | 28 +++++------ libc/net/lib_addroute.c | 16 +++---- libc/net/lib_delroute.c | 16 +++---- libc/net/lib_htonl.c | 12 ++--- libc/net/lib_htons.c | 16 +++---- libc/sched/sched_getprioritymax.c | 16 +++---- libc/sched/sched_getprioritymin.c | 16 +++---- libc/stdio/lib_dprintf.c | 4 +- libc/stdio/lib_fgetc.c | 14 +++--- libc/stdio/lib_fgets.c | 2 +- libc/stdio/lib_gets.c | 2 +- libc/stdio/lib_gets_s.c | 2 +- libc/stdio/lib_libfgets.c | 4 +- libc/stdio/lib_printf.c | 14 +++--- libc/stdio/lib_ungetc.c | 14 +++--- libc/stdio/lib_vprintf.c | 14 +++--- libc/stdlib/lib_abort.c | 40 ++++++++-------- libc/stdlib/lib_abs.c | 12 ++--- libc/stdlib/lib_div.c | 2 +- libc/stdlib/lib_imaxabs.c | 12 ++--- libc/stdlib/lib_itoa.c | 12 ++--- libc/stdlib/lib_labs.c | 12 ++--- libc/stdlib/lib_ldiv.c | 2 +- libc/stdlib/lib_llabs.c | 12 ++--- libc/stdlib/lib_lldiv.c | 2 +- libc/string/lib_memcmp.c | 16 +++---- libc/string/lib_memmove.c | 16 +++---- libc/string/lib_stpcpy.c | 16 +++---- libc/string/lib_strcpy.c | 16 +++---- libc/string/lib_strdup.c | 12 ++--- libc/string/lib_strerror.c | 32 ++++++------- libc/string/lib_strncat.c | 12 ++--- libc/string/lib_strncpy.c | 16 +++---- libc/string/lib_strndup.c | 16 +++---- libc/string/lib_strrchr.c | 12 ++--- libc/string/lib_vikmemcpy.c | 32 ++++++------- libc/time/lib_gmtime.c | 8 ++-- libc/time/lib_gmtimer.c | 8 ++-- mm/kmm_heap/kmm_addregion.c | 32 ++++++------- mm/kmm_heap/kmm_free.c | 4 +- mm/kmm_heap/kmm_heapmember.c | 32 ++++++------- mm/kmm_heap/kmm_initialize.c | 32 ++++++------- mm/kmm_heap/kmm_kernel.c | 32 ++++++------- mm/kmm_heap/kmm_malloc.c | 4 +- mm/kmm_heap/kmm_memalign.c | 4 +- mm/kmm_heap/kmm_sem.c | 36 +++++++------- mm/kmm_heap/kmm_zalloc.c | 4 +- mm/umm_heap/umm_addregion.c | 16 +++---- mm/umm_heap/umm_globals.c | 12 ++--- mm/umm_heap/umm_initialize.c | 16 +++---- mm/umm_heap/umm_malloc.c | 4 +- mm/umm_heap/umm_sem.c | 20 ++++---- mm/umm_heap/umm_zalloc.c | 4 +- sched/clock/clock_getres.c | 44 ++++++++--------- sched/clock/clock_gettime.c | 44 ++++++++--------- sched/clock/clock_initialize.c | 12 ++--- sched/clock/clock_settime.c | 44 ++++++++--------- sched/clock/clock_timespec_add.c | 4 +- sched/clock/clock_timespec_subtract.c | 4 +- sched/group/group_free.c | 36 +++++++------- sched/group/group_malloc.c | 36 +++++++------- sched/group/group_zalloc.c | 36 +++++++------- sched/irq/irq_dispatch.c | 2 +- sched/mqueue/mq_getattr.c | 16 +++---- sched/mqueue/mq_initialize.c | 44 ++++++++--------- sched/mqueue/mq_msgfree.c | 36 +++++++------- sched/mqueue/mq_msgqfree.c | 36 +++++++------- sched/mqueue/mq_notify.c | 36 +++++++------- sched/mqueue/mq_receive.c | 36 +++++++------- sched/mqueue/mq_recover.c | 36 +++++++------- sched/mqueue/mq_release.c | 36 +++++++------- sched/mqueue/mq_setattr.c | 16 +++---- sched/pthread/pthread_cancel.c | 36 +++++++------- sched/pthread/pthread_completejoin.c | 48 +++++++++---------- sched/pthread/pthread_detach.c | 36 +++++++------- sched/pthread/pthread_exit.c | 36 +++++++------- sched/pthread/pthread_findjoininfo.c | 36 +++++++------- sched/pthread/pthread_getspecific.c | 36 +++++++------- sched/pthread/pthread_keydelete.c | 36 +++++++------- sched/pthread/pthread_kill.c | 16 +++---- sched/pthread/pthread_release.c | 36 +++++++------- sched/pthread/pthread_sigmask.c | 36 +++++++------- sched/pthread/pthread_yield.c | 36 +++++++------- sched/sched/sched_addblocked.c | 36 +++++++------- sched/sched/sched_addprioritized.c | 36 +++++++------- sched/sched/sched_cpuload.c | 36 +++++++------- sched/sched/sched_foreach.c | 16 +++---- sched/sched/sched_getfiles.c | 20 ++++---- sched/sched/sched_getparam.c | 40 ++++++++-------- sched/sched/sched_getscheduler.c | 40 ++++++++-------- sched/sched/sched_getsockets.c | 20 ++++---- sched/sched/sched_lock.c | 40 ++++++++-------- sched/sched/sched_lockcount.c | 40 ++++++++-------- sched/sched/sched_mergepending.c | 36 +++++++------- sched/sched/sched_processtimer.c | 44 ++++++++--------- sched/sched/sched_releasetcb.c | 24 +++++----- sched/sched/sched_removeblocked.c | 36 +++++++------- sched/sched/sched_roundrobin.c | 20 ++++---- sched/sched/sched_rrgetinterval.c | 16 +++---- sched/sched/sched_sporadic.c | 0 sched/sched/sched_timerexpiration.c | 32 ++++++------- sched/sched/sched_unlock.c | 16 +++---- sched/sched/sched_waitpid.c | 4 +- sched/signal/sig_allocatependingsigaction.c | 36 +++++++------- sched/signal/sig_cleanup.c | 40 ++++++++-------- sched/signal/sig_findaction.c | 36 +++++++------- sched/signal/sig_initialize.c | 52 ++++++++++----------- sched/signal/sig_kill.c | 16 +++---- sched/signal/sig_lowest.c | 36 +++++++------- sched/signal/sig_releasependingsigaction.c | 36 +++++++------- sched/signal/sig_releasependingsignal.c | 36 +++++++------- sched/signal/sig_removependingsignal.c | 36 +++++++------- sched/signal/sig_unmaskpendingsignal.c | 36 +++++++------- sched/task/task_getpid.c | 36 +++++++------- sched/task/task_prctl.c | 16 +++---- sched/wdog/wd_initialize.c | 36 +++++++------- 230 files changed, 2054 insertions(+), 2054 deletions(-) mode change 100755 => 100644 sched/sched/sched_sporadic.c diff --git a/arch b/arch index 8cd57d72bc..6a1d7e2d00 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8cd57d72bc48ab44b21fa36aa117367c2e8d0129 +Subproject commit 6a1d7e2d00220168220fd511937fe3680f3627ef diff --git a/binfmt/binfmt_dumpmodule.c b/binfmt/binfmt_dumpmodule.c index 8fec9adb7e..59ed17a94e 100644 --- a/binfmt/binfmt_dumpmodule.c +++ b/binfmt/binfmt_dumpmodule.c @@ -65,11 +65,11 @@ * Private Functions ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Name: dump_module * * Description: @@ -80,7 +80,7 @@ * 0 (OK) is returned on success and a negated errno is returned on * failure. * - ***********************************************************************/ + ****************************************************************************/ int dump_module(FAR const struct binary_s *bin) { diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c index a839bbc07c..f308de73b0 100644 --- a/binfmt/nxflat.c +++ b/binfmt/nxflat.c @@ -227,11 +227,11 @@ errout: return ret; } -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Name: nxflat_initialize * * Description: @@ -244,7 +244,7 @@ errout: * 0 (OK) is returned on success and a negated errno is returned on * failure. * - ***********************************************************************/ + ****************************************************************************/ int nxflat_initialize(void) { diff --git a/binfmt/symtab_findbyname.c b/binfmt/symtab_findbyname.c index c0343e2708..ecbd1bd7ee 100644 --- a/binfmt/symtab_findbyname.c +++ b/binfmt/symtab_findbyname.c @@ -62,9 +62,9 @@ * Private Functions ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: symtab_findbyname diff --git a/binfmt/symtab_findbyvalue.c b/binfmt/symtab_findbyvalue.c index c47d5c7518..600614a1e3 100644 --- a/binfmt/symtab_findbyvalue.c +++ b/binfmt/symtab_findbyvalue.c @@ -62,9 +62,9 @@ * Private Functions ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: symtab_findbyvalue diff --git a/binfmt/symtab_findorderedbyname.c b/binfmt/symtab_findorderedbyname.c index ce63b458b0..e058bd770c 100644 --- a/binfmt/symtab_findorderedbyname.c +++ b/binfmt/symtab_findorderedbyname.c @@ -62,9 +62,9 @@ * Private Functions ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: symtab_findorderedbyname diff --git a/binfmt/symtab_findorderedbyvalue.c b/binfmt/symtab_findorderedbyvalue.c index bad4bf8cd7..7af0d6a218 100644 --- a/binfmt/symtab_findorderedbyvalue.c +++ b/binfmt/symtab_findorderedbyvalue.c @@ -62,9 +62,9 @@ * Private Functions ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Public Functions - ***********************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: symtab_findorderedbyvalue diff --git a/configs b/configs index 7e3617b292..35414c3a91 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7e3617b29222394a5bcc1f20dab7ab9c8a35cda1 +Subproject commit 35414c3a91d471276c7ff7ddc2ef8ba8a47aa9cd diff --git a/drivers/sercomm/console.c b/drivers/sercomm/console.c index c066e8fe7a..9b9a9063e7 100644 --- a/drivers/sercomm/console.c +++ b/drivers/sercomm/console.c @@ -35,7 +35,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ****************************************************************************/ #include #include diff --git a/drivers/sercomm/uart.c b/drivers/sercomm/uart.c index 3cf52f7dbb..234f600dd8 100644 --- a/drivers/sercomm/uart.c +++ b/drivers/sercomm/uart.c @@ -32,7 +32,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ****************************************************************************/ #include #include diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index b720266ee7..bc88eac5be 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c @@ -438,7 +438,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev, } } -/*************************************************************************** +/**************************************************************************** * Name: spi_sndblock * * Description: diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index e3ff43a19d..0fc6a52a0c 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -872,7 +872,7 @@ errout_with_alloc: * Returned Value: * None * - ***************************************************************************/ + ****************************************************************************/ void composite_uninitialize(FAR void *handle) { diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index 491d603aaf..d563696db9 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -1,4 +1,4 @@ -/************************************************************************** +/**************************************************************************** * drivers/wireless/cc3000/cc3000drv.c * Driver wrapper functions to conntect nuttx to the TI CC3000 * diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index 3d6f6e039d..f71b12d45a 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * fs/mqueue/mq_unlink.c * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,31 +49,31 @@ #include "inode/inode.h" #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_unlink * * Description: @@ -90,7 +90,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int mq_unlink(FAR const char *mq_name) { diff --git a/fs/vfs/fs_sendfile.c b/fs/vfs/fs_sendfile.c index 0935460c16..8e68c8514b 100644 --- a/fs/vfs/fs_sendfile.c +++ b/fs/vfs/fs_sendfile.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * fs/vfs/fs_sendfile.c * * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -51,27 +51,27 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_SENDFILE -/************************************************************************ +/**************************************************************************** * Private types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sendfile * * Description: @@ -114,7 +114,7 @@ * EINVAL - Bad input parameters. * ENOMEM - Could not allocated an I/O buffer * - ************************************************************************/ + ****************************************************************************/ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) { diff --git a/fs/vfs/fs_write.c b/fs/vfs/fs_write.c index 830e56dcc0..b7f71a2265 100644 --- a/fs/vfs/fs_write.c +++ b/fs/vfs/fs_write.c @@ -108,7 +108,7 @@ errout: return ERROR; } -/*************************************************************************** +/**************************************************************************** * Name: write * * Description: diff --git a/libc/fixedmath/lib_fixedmath.c b/libc/fixedmath/lib_fixedmath.c index 9e9213b4fc..cf072fd541 100644 --- a/libc/fixedmath/lib_fixedmath.c +++ b/libc/fixedmath/lib_fixedmath.c @@ -140,7 +140,7 @@ b16_t b16mulb16(b16_t m1, b16_t m2) /**************************************************************************** * Name: ub16mulub16 - **************************************************************************/ + ****************************************************************************/ ub16_t ub16mulub16(ub16_t m1, ub16_t m2) { @@ -166,7 +166,7 @@ ub16_t ub16mulub16(ub16_t m1, ub16_t m2) /**************************************************************************** * Name: b16sqr - **************************************************************************/ + ****************************************************************************/ b16_t b16sqr(b16_t a) { @@ -191,7 +191,7 @@ b16_t b16sqr(b16_t a) /**************************************************************************** * Name: b16divb16 - **************************************************************************/ + ****************************************************************************/ ub16_t ub16sqr(ub16_t a) { @@ -213,7 +213,7 @@ ub16_t ub16sqr(ub16_t a) /**************************************************************************** * Name: b16divb16 - **************************************************************************/ + ****************************************************************************/ b16_t b16divb16(b16_t num, b16_t denom) { @@ -227,7 +227,7 @@ b16_t b16divb16(b16_t num, b16_t denom) /**************************************************************************** * Name: ub16divub16 - **************************************************************************/ + ****************************************************************************/ ub16_t ub16divub16(ub16_t num, ub16_t denom) { diff --git a/libc/math/lib_acos.c b/libc/math/lib_acos.c index c1da957f92..4903af43bc 100644 --- a/libc/math/lib_acos.c +++ b/libc/math/lib_acos.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acos.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double acos(double x) diff --git a/libc/math/lib_acosf.c b/libc/math/lib_acosf.c index e75325dc01..6719e54a67 100644 --- a/libc/math/lib_acosf.c +++ b/libc/math/lib_acosf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acosf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float acosf(float x) { diff --git a/libc/math/lib_acosh.c b/libc/math/lib_acosh.c index cd9fde5598..278c454e9d 100644 --- a/libc/math/lib_acosh.c +++ b/libc/math/lib_acosh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acosh.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double acosh(double x) diff --git a/libc/math/lib_acoshf.c b/libc/math/lib_acoshf.c index fa5c9549d8..a676d6a40e 100644 --- a/libc/math/lib_acoshf.c +++ b/libc/math/lib_acoshf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acoshf.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float acoshf(float x) { diff --git a/libc/math/lib_acoshl.c b/libc/math/lib_acoshl.c index bc2cd31da1..34a1dec361 100644 --- a/libc/math/lib_acoshl.c +++ b/libc/math/lib_acoshl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acoshl.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double acoshl(long double x) diff --git a/libc/math/lib_acosl.c b/libc/math/lib_acosl.c index 588d7ed58e..f13cb00a04 100644 --- a/libc/math/lib_acosl.c +++ b/libc/math/lib_acosl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_acos.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double acosl(long double x) diff --git a/libc/math/lib_asin.c b/libc/math/lib_asin.c index 5940ce8215..08a2dc9573 100644 --- a/libc/math/lib_asin.c +++ b/libc/math/lib_asin.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sin.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,16 +35,16 @@ #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ #undef DBL_EPSILON #define DBL_EPSILON 1e-12 -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double asin(double x) diff --git a/libc/math/lib_asinf.c b/libc/math/lib_asinf.c index 1da555ab86..e22d32fe79 100644 --- a/libc/math/lib_asinf.c +++ b/libc/math/lib_asinf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinf.c * * This file is a part of NuttX: @@ -23,18 +23,18 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float asinf(float x) { diff --git a/libc/math/lib_asinh.c b/libc/math/lib_asinh.c index 5a30ac1aa2..ef52323b97 100644 --- a/libc/math/lib_asinh.c +++ b/libc/math/lib_asinh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_asinh.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double asinh(double x) diff --git a/libc/math/lib_asinhf.c b/libc/math/lib_asinhf.c index 37141a65c4..ba749a6569 100644 --- a/libc/math/lib_asinhf.c +++ b/libc/math/lib_asinhf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_asinhf.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float asinhf(float x) { diff --git a/libc/math/lib_asinhl.c b/libc/math/lib_asinhl.c index b2fb201a38..bbbb3d66f6 100644 --- a/libc/math/lib_asinhl.c +++ b/libc/math/lib_asinhl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_asinhl.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double asinhl(long double x) diff --git a/libc/math/lib_asinl.c b/libc/math/lib_asinl.c index f51e7deb3d..466910daf3 100644 --- a/libc/math/lib_asinl.c +++ b/libc/math/lib_asinl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,9 +35,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double asinl(long double x) diff --git a/libc/math/lib_atan.c b/libc/math/lib_atan.c index daf5b26034..91930bf03e 100644 --- a/libc/math/lib_atan.c +++ b/libc/math/lib_atan.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atan.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -36,9 +36,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double atan(double x) diff --git a/libc/math/lib_atan2.c b/libc/math/lib_atan2.c index 4255214fea..5b0f7e2989 100644 --- a/libc/math/lib_atan2.c +++ b/libc/math/lib_atan2.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atan2.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double atan2(double y, double x) diff --git a/libc/math/lib_atan2f.c b/libc/math/lib_atan2f.c index 8e7d9cea93..5d766df99d 100644 --- a/libc/math/lib_atan2f.c +++ b/libc/math/lib_atan2f.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atan2f.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float atan2f(float y, float x) { diff --git a/libc/math/lib_atan2l.c b/libc/math/lib_atan2l.c index 5ea4616be8..4c384e8089 100644 --- a/libc/math/lib_atan2l.c +++ b/libc/math/lib_atan2l.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atan2l.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double atan2l(long double y, long double x) diff --git a/libc/math/lib_atanf.c b/libc/math/lib_atanf.c index 2f3638d172..c9835c6f24 100644 --- a/libc/math/lib_atanf.c +++ b/libc/math/lib_atanf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atanf.c * * This file is a part of NuttX: @@ -23,19 +23,19 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float atanf(float x) { diff --git a/libc/math/lib_atanh.c b/libc/math/lib_atanh.c index 396e80852a..4858f41f5b 100644 --- a/libc/math/lib_atanh.c +++ b/libc/math/lib_atanh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atanh.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double atanh(double x) diff --git a/libc/math/lib_atanhf.c b/libc/math/lib_atanhf.c index a49ba995c5..60a6696f73 100644 --- a/libc/math/lib_atanhf.c +++ b/libc/math/lib_atanhf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atanhf.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float atanhf(float x) { diff --git a/libc/math/lib_atanhl.c b/libc/math/lib_atanhl.c index 77a187e51b..7b3e8367b3 100644 --- a/libc/math/lib_atanhl.c +++ b/libc/math/lib_atanhl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atanhl.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE long double atanhl(long double x) diff --git a/libc/math/lib_atanl.c b/libc/math/lib_atanl.c index 48dcb03e21..50376c26a0 100644 --- a/libc/math/lib_atanl.c +++ b/libc/math/lib_atanl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_atanl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -36,9 +36,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double atanl(long double x) diff --git a/libc/math/lib_ceil.c b/libc/math/lib_ceil.c index 73e4b8ee4a..6d367a51c7 100644 --- a/libc/math/lib_ceil.c +++ b/libc/math/lib_ceil.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ceil.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double ceil(double x) diff --git a/libc/math/lib_ceilf.c b/libc/math/lib_ceilf.c index 850e762f25..8378141abd 100644 --- a/libc/math/lib_ceilf.c +++ b/libc/math/lib_ceilf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ceilf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float ceilf(float x) { diff --git a/libc/math/lib_ceill.c b/libc/math/lib_ceill.c index 3e15ee302d..ac54c2c3db 100644 --- a/libc/math/lib_ceill.c +++ b/libc/math/lib_ceill.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ceil;.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double ceill(long double x) diff --git a/libc/math/lib_copysign.c b/libc/math/lib_copysign.c index ee62504db1..689457cf5f 100644 --- a/libc/math/lib_copysign.c +++ b/libc/math/lib_copysign.c @@ -34,18 +34,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double copysign(double x, double y) diff --git a/libc/math/lib_copysignf.c b/libc/math/lib_copysignf.c index 0d12640cc3..9684f68a74 100644 --- a/libc/math/lib_copysignf.c +++ b/libc/math/lib_copysignf.c @@ -34,18 +34,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float copysignf(float x, float y) { diff --git a/libc/math/lib_copysignl.c b/libc/math/lib_copysignl.c index 3a49713b58..b7f99e7728 100644 --- a/libc/math/lib_copysignl.c +++ b/libc/math/lib_copysignl.c @@ -34,18 +34,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double copysignl(long double x, long double y) diff --git a/libc/math/lib_cos.c b/libc/math/lib_cos.c index cfa0a9a4b9..34d90716af 100644 --- a/libc/math/lib_cos.c +++ b/libc/math/lib_cos.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_cos.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double cos(double x) diff --git a/libc/math/lib_cosf.c b/libc/math/lib_cosf.c index 2e23419a1d..55ba93c1c8 100644 --- a/libc/math/lib_cosf.c +++ b/libc/math/lib_cosf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_cosf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float cosf(float x) { diff --git a/libc/math/lib_cosh.c b/libc/math/lib_cosh.c index 40d9ce0c19..73283589b5 100644 --- a/libc/math/lib_cosh.c +++ b/libc/math/lib_cosh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_cosh.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double cosh(double x) diff --git a/libc/math/lib_coshf.c b/libc/math/lib_coshf.c index 9a3f728531..7cb575822f 100644 --- a/libc/math/lib_coshf.c +++ b/libc/math/lib_coshf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_coshf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float coshf(float x) { diff --git a/libc/math/lib_coshl.c b/libc/math/lib_coshl.c index b7e58ec7ef..445629c24e 100644 --- a/libc/math/lib_coshl.c +++ b/libc/math/lib_coshl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_coshl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double coshl(long double x) diff --git a/libc/math/lib_cosl.c b/libc/math/lib_cosl.c index f328b994a6..89109db77d 100644 --- a/libc/math/lib_cosl.c +++ b/libc/math/lib_cosl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_cosl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double cosl(long double x) diff --git a/libc/math/lib_erf.c b/libc/math/lib_erf.c index a410170161..ecb1e36dbd 100644 --- a/libc/math/lib_erf.c +++ b/libc/math/lib_erf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_erf.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double erf(double x) diff --git a/libc/math/lib_erff.c b/libc/math/lib_erff.c index 4e773320a1..2b38808caa 100644 --- a/libc/math/lib_erff.c +++ b/libc/math/lib_erff.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_erff.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float erff(float x) { diff --git a/libc/math/lib_erfl.c b/libc/math/lib_erfl.c index 594e9183bc..1ebb736db2 100644 --- a/libc/math/lib_erfl.c +++ b/libc/math/lib_erfl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_erfl.c * * Copyright (C) 2015 Brennan Ashton. All rights reserved. @@ -33,18 +33,18 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double erfl(long double x) diff --git a/libc/math/lib_exp.c b/libc/math/lib_exp.c index c07e6783c9..738bd3f76b 100644 --- a/libc/math/lib_exp.c +++ b/libc/math/lib_exp.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_exp.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -39,9 +39,9 @@ #ifdef CONFIG_HAVE_DOUBLE -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static double _dbl_inv_fact[] = { @@ -66,9 +66,9 @@ static double _dbl_inv_fact[] = 1.0 / 6402373705728000.0, /* 1 / 18! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ double exp(double x) { diff --git a/libc/math/lib_expf.c b/libc/math/lib_expf.c index eaa9e0d068..36788b60ad 100644 --- a/libc/math/lib_expf.c +++ b/libc/math/lib_expf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_expf.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static float _flt_inv_fact[] = { @@ -53,9 +53,9 @@ static float _flt_inv_fact[] = 1.0 / 3628800.0, /* 1/10! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float expf(float x) { diff --git a/libc/math/lib_expl.c b/libc/math/lib_expl.c index e14eb586d7..29f30ecd13 100644 --- a/libc/math/lib_expl.c +++ b/libc/math/lib_expl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_expl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -39,9 +39,9 @@ #ifdef CONFIG_HAVE_LONG_DOUBLE -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static long double _ldbl_inv_fact[] = { @@ -66,9 +66,9 @@ static long double _ldbl_inv_fact[] = 1.0 / 6402373705728000.0, /* 1 / 18! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ long double expl(long double x) { diff --git a/libc/math/lib_fabs.c b/libc/math/lib_fabs.c index 635be443f4..35f98e6818 100644 --- a/libc/math/lib_fabs.c +++ b/libc/math/lib_fabs.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fabs.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double fabs(double x) diff --git a/libc/math/lib_fabsf.c b/libc/math/lib_fabsf.c index 629846af3b..2bee12097d 100644 --- a/libc/math/lib_fabsf.c +++ b/libc/math/lib_fabsf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fabsf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float fabsf(float x) { diff --git a/libc/math/lib_fabsl.c b/libc/math/lib_fabsl.c index 0ce73a6744..1762f91416 100644 --- a/libc/math/lib_fabsl.c +++ b/libc/math/lib_fabsl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fabsl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double fabsl(long double x) diff --git a/libc/math/lib_floor.c b/libc/math/lib_floor.c index ba6278239c..f583dfa6b7 100644 --- a/libc/math/lib_floor.c +++ b/libc/math/lib_floor.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_floor.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double floor(double x) diff --git a/libc/math/lib_floorf.c b/libc/math/lib_floorf.c index 63a2fa7221..4a4ef1a4f7 100644 --- a/libc/math/lib_floorf.c +++ b/libc/math/lib_floorf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_floorf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float floorf(float x) { diff --git a/libc/math/lib_floorl.c b/libc/math/lib_floorl.c index 28c7e0029f..214ade8ee2 100644 --- a/libc/math/lib_floorl.c +++ b/libc/math/lib_floorl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_floorl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double floorl(long double x) diff --git a/libc/math/lib_fmod.c b/libc/math/lib_fmod.c index 1bdf3134d8..e096d62988 100644 --- a/libc/math/lib_fmod.c +++ b/libc/math/lib_fmod.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fmod.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double fmod(double x, double div) diff --git a/libc/math/lib_fmodf.c b/libc/math/lib_fmodf.c index ee1b9070c8..ba2d375b8e 100644 --- a/libc/math/lib_fmodf.c +++ b/libc/math/lib_fmodf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fmodf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float fmodf(float x, float div) { diff --git a/libc/math/lib_fmodl.c b/libc/math/lib_fmodl.c index c5b14e8596..f72f2de4d7 100644 --- a/libc/math/lib_fmodl.c +++ b/libc/math/lib_fmodl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_fmodl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double fmodl(long double x, long double div) diff --git a/libc/math/lib_frexp.c b/libc/math/lib_frexp.c index 3319a6bf37..12eccadbe7 100644 --- a/libc/math/lib_frexp.c +++ b/libc/math/lib_frexp.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_frexp.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double frexp(double x, int *exponent) diff --git a/libc/math/lib_frexpf.c b/libc/math/lib_frexpf.c index 9cab980fb3..6ec5aa7442 100644 --- a/libc/math/lib_frexpf.c +++ b/libc/math/lib_frexpf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_frexpf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float frexpf(float x, int *exponent) { diff --git a/libc/math/lib_frexpl.c b/libc/math/lib_frexpl.c index 627f0e0b5b..ae2ec4eb73 100644 --- a/libc/math/lib_frexpl.c +++ b/libc/math/lib_frexpl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_frexpl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double frexpl(long double x, int *exponent) diff --git a/libc/math/lib_ldexp.c b/libc/math/lib_ldexp.c index 1d6eded8a5..ac4d23dccb 100644 --- a/libc/math/lib_ldexp.c +++ b/libc/math/lib_ldexp.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ldexp.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double ldexp(double x, int n) diff --git a/libc/math/lib_ldexpf.c b/libc/math/lib_ldexpf.c index e1500d77e1..12503438b8 100644 --- a/libc/math/lib_ldexpf.c +++ b/libc/math/lib_ldexpf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ldexpf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float ldexpf(float x, int n) { diff --git a/libc/math/lib_ldexpl.c b/libc/math/lib_ldexpl.c index cf12370e0b..da02bf7e60 100644 --- a/libc/math/lib_ldexpl.c +++ b/libc/math/lib_ldexpl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_ldexpl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double ldexpl(long double x, int n) diff --git a/libc/math/lib_libexpi.c b/libc/math/lib_libexpi.c index 6c26d6b918..c8f5793d39 100644 --- a/libc/math/lib_libexpi.c +++ b/libc/math/lib_libexpi.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_libexpi.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,13 +35,13 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ #define M_E2 (M_E * M_E) #define M_E4 (M_E2 * M_E2) @@ -54,9 +54,9 @@ #define M_E512 (M_E256 * M_E256) #define M_E1024 (M_E512 * M_E512) -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static double _expi_square_tbl[11] = { @@ -73,9 +73,9 @@ static double _expi_square_tbl[11] = M_E1024, /* e^1024 */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ double lib_expi(size_t n) { diff --git a/libc/math/lib_libsqrtapprox.c b/libc/math/lib_libsqrtapprox.c index a153f6ed9d..60db0770ad 100644 --- a/libc/math/lib_libsqrtapprox.c +++ b/libc/math/lib_libsqrtapprox.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_libsqrtapprox.c * * This file is a part of NuttX: @@ -23,18 +23,18 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float lib_sqrtapprox(float x) { diff --git a/libc/math/lib_log.c b/libc/math/lib_log.c index 764726baec..8bcfe75bff 100644 --- a/libc/math/lib_log.c +++ b/libc/math/lib_log.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,9 +35,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double log(double x) diff --git a/libc/math/lib_log10.c b/libc/math/lib_log10.c index 321b53f208..0830bd7e66 100644 --- a/libc/math/lib_log10.c +++ b/libc/math/lib_log10.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log10.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double log10(double x) diff --git a/libc/math/lib_log10f.c b/libc/math/lib_log10f.c index 3f4ba13281..f0ec9b0589 100644 --- a/libc/math/lib_log10f.c +++ b/libc/math/lib_log10f.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log10f.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float log10f(float x) { diff --git a/libc/math/lib_log10l.c b/libc/math/lib_log10l.c index 713e007de6..69e3e7e978 100644 --- a/libc/math/lib_log10l.c +++ b/libc/math/lib_log10l.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log10l.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double log10l(long double x) diff --git a/libc/math/lib_log2.c b/libc/math/lib_log2.c index e929b70cc7..2e2007796b 100644 --- a/libc/math/lib_log2.c +++ b/libc/math/lib_log2.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log2.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double log2(double x) diff --git a/libc/math/lib_log2f.c b/libc/math/lib_log2f.c index 58d291f6c4..a2d351bb12 100644 --- a/libc/math/lib_log2f.c +++ b/libc/math/lib_log2f.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log2f.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float log2f(float x) { diff --git a/libc/math/lib_log2l.c b/libc/math/lib_log2l.c index e130fe6c8f..0b4450a809 100644 --- a/libc/math/lib_log2l.c +++ b/libc/math/lib_log2l.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_log2l.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double log2l(long double x) diff --git a/libc/math/lib_logf.c b/libc/math/lib_logf.c index cc4f850d0d..80eff85c3c 100644 --- a/libc/math/lib_logf.c +++ b/libc/math/lib_logf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_logf.c * * This file is a part of NuttX: @@ -23,18 +23,18 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float logf(float x) { diff --git a/libc/math/lib_logl.c b/libc/math/lib_logl.c index 9426a506ab..c8babc17a8 100644 --- a/libc/math/lib_logl.c +++ b/libc/math/lib_logl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_lol.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,9 +35,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double logl(long double x) diff --git a/libc/math/lib_modf.c b/libc/math/lib_modf.c index eb56e9c0e6..5c0921997c 100644 --- a/libc/math/lib_modf.c +++ b/libc/math/lib_modf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_modf.c * * This file is a part of NuttX: @@ -23,18 +23,18 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double modf(double x, double *iptr) diff --git a/libc/math/lib_modff.c b/libc/math/lib_modff.c index 81b799253e..ad07a4f70c 100644 --- a/libc/math/lib_modff.c +++ b/libc/math/lib_modff.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_modff.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float modff(float x, float *iptr) { diff --git a/libc/math/lib_modfl.c b/libc/math/lib_modfl.c index f4c30ae051..45f5f4f8fe 100644 --- a/libc/math/lib_modfl.c +++ b/libc/math/lib_modfl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_modfl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -35,9 +35,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double modfl(long double x, long double *iptr) diff --git a/libc/math/lib_pow.c b/libc/math/lib_pow.c index f8fe18b5ec..47eb8d1248 100644 --- a/libc/math/lib_pow.c +++ b/libc/math/lib_pow.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_pow.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double pow(double b, double e) diff --git a/libc/math/lib_powf.c b/libc/math/lib_powf.c index 1797324d4f..b1614a2500 100644 --- a/libc/math/lib_powf.c +++ b/libc/math/lib_powf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_powf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float powf(float b, float e) { diff --git a/libc/math/lib_powl.c b/libc/math/lib_powl.c index 7d943c58a8..2efb848015 100644 --- a/libc/math/lib_powl.c +++ b/libc/math/lib_powl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_powl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double powl(long double b, long double e) diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index d26e1b9736..c424d05365 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/fixedmath/lib_rint.c * * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include @@ -47,33 +47,33 @@ #include #include -/************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Data - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Private Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Variables - ************************************************************/ + ****************************************************************************/ double rint(double x) { diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c index cd03168828..f0a329733f 100644 --- a/libc/math/lib_rintf.c +++ b/libc/math/lib_rintf.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/fixedmath/lib_rintf.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include @@ -47,33 +47,33 @@ #include #include -/************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Data - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Private Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Variables - ************************************************************/ + ****************************************************************************/ float rintf(float x) { diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c index 92ec28bcea..439c75566f 100644 --- a/libc/math/lib_rintl.c +++ b/libc/math/lib_rintl.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/fixedmath/lib_rint.c * * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include @@ -47,33 +47,33 @@ #include #include -/************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Data - ************************************************************/ + ****************************************************************************/ -/********************************************************** +/**************************************************************************** * Private Constant Data - **********************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Variables - ************************************************************/ + ****************************************************************************/ long double rintl(long double x) { diff --git a/libc/math/lib_round.c b/libc/math/lib_round.c index 1cf8ba43b8..bc3b332fcc 100644 --- a/libc/math/lib_round.c +++ b/libc/math/lib_round.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * lib/math/lib_round.c * * This file is a part of NuttX: @@ -6,20 +6,20 @@ * Copyright (C) 2012 Gregory Nutt. All rights reserved. * (C) 2012 Petteri Aimonen * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double round(double x) diff --git a/libc/math/lib_roundf.c b/libc/math/lib_roundf.c index b4c0050c0c..d85322ddcf 100644 --- a/libc/math/lib_roundf.c +++ b/libc/math/lib_roundf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * lib/math/lib_roundf.c * * This file is a part of NuttX: @@ -6,20 +6,20 @@ * Copyright (C) 2012 Gregory Nutt. All rights reserved. * (C) 2012 Petteri Aimonen * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float roundf(float x) { diff --git a/libc/math/lib_roundl.c b/libc/math/lib_roundl.c index b75bb61f5b..d35c38bf09 100644 --- a/libc/math/lib_roundl.c +++ b/libc/math/lib_roundl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * lib/math/lib_round.c * * This file is a part of NuttX: @@ -6,20 +6,20 @@ * Copyright (C) 2012 Gregory Nutt. All rights reserved. * (C) 2012 Petteri Aimonen * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double roundl(long double x) diff --git a/libc/math/lib_sin.c b/libc/math/lib_sin.c index 46d8992f89..7ff716b059 100644 --- a/libc/math/lib_sin.c +++ b/libc/math/lib_sin.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sin.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #ifdef CONFIG_HAVE_DOUBLE -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static double _dbl_inv_fact[] = { @@ -55,9 +55,9 @@ static double _dbl_inv_fact[] = 1.0 / 121645100408832000.0, /* 1 / 19! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ double sin(double x) { diff --git a/libc/math/lib_sinf.c b/libc/math/lib_sinf.c index ba2a553eba..5f17eb212b 100644 --- a/libc/math/lib_sinf.c +++ b/libc/math/lib_sinf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinf.c * * This file is a part of NuttX: @@ -23,18 +23,18 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static float _flt_inv_fact[] = { @@ -46,9 +46,9 @@ static float _flt_inv_fact[] = 1.0 / 39916800.0, /* 1 / 11! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float sinf(float x) { diff --git a/libc/math/lib_sinh.c b/libc/math/lib_sinh.c index 714a52816b..81e84807b9 100644 --- a/libc/math/lib_sinh.c +++ b/libc/math/lib_sinh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinh.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double sinh(double x) diff --git a/libc/math/lib_sinhf.c b/libc/math/lib_sinhf.c index b7fc5af13a..6b27f59508 100644 --- a/libc/math/lib_sinhf.c +++ b/libc/math/lib_sinhf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinhf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float sinhf(float x) { diff --git a/libc/math/lib_sinhl.c b/libc/math/lib_sinhl.c index b6ee9764e7..ff3aaedb7d 100644 --- a/libc/math/lib_sinhl.c +++ b/libc/math/lib_sinhl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinhl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double sinhl(long double x) diff --git a/libc/math/lib_sinl.c b/libc/math/lib_sinl.c index b288316b14..dc3df8a4ba 100644 --- a/libc/math/lib_sinl.c +++ b/libc/math/lib_sinl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sinl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #ifdef CONFIG_HAVE_LONG_DOUBLE -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ static long double _ldbl_inv_fact[] = { @@ -55,9 +55,9 @@ static long double _ldbl_inv_fact[] = 1.0 / 121645100408832000.0, /* 1 / 19! */ }; -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ long double sinl(long double x) { diff --git a/libc/math/lib_sqrt.c b/libc/math/lib_sqrt.c index 9190ac42bb..7a3af561c6 100644 --- a/libc/math/lib_sqrt.c +++ b/libc/math/lib_sqrt.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sqrt.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double sqrt(double x) diff --git a/libc/math/lib_sqrtf.c b/libc/math/lib_sqrtf.c index a2089c13f1..0e9a55ac24 100644 --- a/libc/math/lib_sqrtf.c +++ b/libc/math/lib_sqrtf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sqrtf.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float sqrtf(float x) { diff --git a/libc/math/lib_sqrtl.c b/libc/math/lib_sqrtl.c index 010d36489c..15280a83f9 100644 --- a/libc/math/lib_sqrtl.c +++ b/libc/math/lib_sqrtl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_sqrtl.c * * This file is a part of NuttX: @@ -23,11 +23,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double sqrtl(long double x) diff --git a/libc/math/lib_tan.c b/libc/math/lib_tan.c index 02f4d6b8e8..31cde4cdde 100644 --- a/libc/math/lib_tan.c +++ b/libc/math/lib_tan.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tan.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double tan(double x) diff --git a/libc/math/lib_tanf.c b/libc/math/lib_tanf.c index 4e0e502d5f..97ffae017d 100644 --- a/libc/math/lib_tanf.c +++ b/libc/math/lib_tanf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tanf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float tanf(float x) { diff --git a/libc/math/lib_tanh.c b/libc/math/lib_tanh.c index 6bed476e20..e68fcd528c 100644 --- a/libc/math/lib_tanh.c +++ b/libc/math/lib_tanh.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tanh.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double tanh(double x) diff --git a/libc/math/lib_tanhf.c b/libc/math/lib_tanhf.c index 15a57bd8b5..70edb57ec4 100644 --- a/libc/math/lib_tanhf.c +++ b/libc/math/lib_tanhf.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tanhf.c * * This file is a part of NuttX: @@ -23,17 +23,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float tanhf(float x) { diff --git a/libc/math/lib_tanhl.c b/libc/math/lib_tanhl.c index c74ec27caf..ef2250941c 100644 --- a/libc/math/lib_tanhl.c +++ b/libc/math/lib_tanhl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tanhl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double tanhl(long double x) diff --git a/libc/math/lib_tanl.c b/libc/math/lib_tanl.c index bc32b9b494..16ebce8a7a 100644 --- a/libc/math/lib_tanl.c +++ b/libc/math/lib_tanl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/math/lib_tanl.c * * This file is a part of NuttX: @@ -23,20 +23,20 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE long double tanl(long double x) diff --git a/libc/math/lib_trunc.c b/libc/math/lib_trunc.c index 1de0f4b520..b0a93f4575 100644 --- a/libc/math/lib_trunc.c +++ b/libc/math/lib_trunc.c @@ -26,9 +26,9 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -36,9 +36,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_DOUBLE double trunc(double x) diff --git a/libc/math/lib_truncf.c b/libc/math/lib_truncf.c index 6093de7334..73ce7b0ad8 100644 --- a/libc/math/lib_truncf.c +++ b/libc/math/lib_truncf.c @@ -26,9 +26,9 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -36,9 +36,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ float truncf(float x) { diff --git a/libc/math/lib_truncl.c b/libc/math/lib_truncl.c index 29f9402063..fce958557c 100644 --- a/libc/math/lib_truncl.c +++ b/libc/math/lib_truncl.c @@ -26,9 +26,9 @@ * ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -37,9 +37,9 @@ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE static const long double toint = 1 / LDBL_EPSILON; diff --git a/libc/misc/lib_filesem.c b/libc/misc/lib_filesem.c index 1dd88454f8..da52b5ae36 100644 --- a/libc/misc/lib_filesem.c +++ b/libc/misc/lib_filesem.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/misc/lib_filesem.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,21 +49,21 @@ #if CONFIG_STDIO_BUFFER_SIZE > 0 -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * lib_sem_initialize - ************************************************************************/ + ****************************************************************************/ void lib_sem_initialize(FAR struct file_struct *stream) { @@ -77,9 +77,9 @@ void lib_sem_initialize(FAR struct file_struct *stream) stream->fs_counts = 0; } -/************************************************************************ +/**************************************************************************** * lib_take_semaphore - ************************************************************************/ + ****************************************************************************/ void lib_take_semaphore(FAR struct file_struct *stream) { @@ -113,9 +113,9 @@ void lib_take_semaphore(FAR struct file_struct *stream) } } -/************************************************************************ +/**************************************************************************** * lib_give_semaphore - ************************************************************************/ + ****************************************************************************/ void lib_give_semaphore(FAR struct file_struct *stream) { diff --git a/libc/misc/lib_sendfile.c b/libc/misc/lib_sendfile.c index 187e689cfd..4fa19b66a7 100644 --- a/libc/misc/lib_sendfile.c +++ b/libc/misc/lib_sendfile.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/misc/lib_sendfile.c * * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,27 +49,27 @@ #if CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 -/************************************************************************ +/**************************************************************************** * Private types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sendfile / lib_sendfile * * Description: @@ -111,7 +111,7 @@ * EINVAL - Bad input parameters. * ENOMEM - Could not allocated an I/O buffer * - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_NET_SENDFILE ssize_t lib_sendfile(int outfd, int infd, off_t *offset, size_t count) diff --git a/libc/misc/lib_streamsem.c b/libc/misc/lib_streamsem.c index 7972a61f32..a403b71028 100644 --- a/libc/misc/lib_streamsem.c +++ b/libc/misc/lib_streamsem.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/misc/lib_streamsem.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -48,25 +48,25 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Private types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ void stream_semtake(FAR struct streamlist *list) { diff --git a/libc/net/lib_addroute.c b/libc/net/lib_addroute.c index a5d6dd8709..33a8dd0aad 100644 --- a/libc/net/lib_addroute.c +++ b/libc/net/lib_addroute.c @@ -1,4 +1,4 @@ -/*************************************************************************** +/**************************************************************************** * libc/net/lib_addroute.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Compilation Switches - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Included Files - ***************************************************************************/ + ****************************************************************************/ #include @@ -48,9 +48,9 @@ #include #include -/*************************************************************************** +/**************************************************************************** * Public Functions - ***************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Function: net_addroute diff --git a/libc/net/lib_delroute.c b/libc/net/lib_delroute.c index f508e35afc..862e8ebcbf 100644 --- a/libc/net/lib_delroute.c +++ b/libc/net/lib_delroute.c @@ -1,4 +1,4 @@ -/*************************************************************************** +/**************************************************************************** * libc/net/lib_delroute.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Compilation Switches - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Included Files - ***************************************************************************/ + ****************************************************************************/ #include @@ -49,9 +49,9 @@ #include #include -/*************************************************************************** +/**************************************************************************** * Public Functions - ***************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Function: net_delroute diff --git a/libc/net/lib_htonl.c b/libc/net/lib_htonl.c index 919cf2f9d7..c499a71f1e 100644 --- a/libc/net/lib_htonl.c +++ b/libc/net/lib_htonl.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/net/lib_ntohl.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,20 +31,20 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ uint32_t htonl(uint32_t hl) { diff --git a/libc/net/lib_htons.c b/libc/net/lib_htons.c index c3ff0fd66f..ce33b879ea 100644 --- a/libc/net/lib_htons.c +++ b/libc/net/lib_htons.c @@ -1,4 +1,4 @@ -/*************************************************************************** +/**************************************************************************** * libc/net/lib_htons.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. @@ -31,24 +31,24 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Compilation Switches - ***************************************************************************/ + ****************************************************************************/ -/*************************************************************************** +/**************************************************************************** * Included Files - ***************************************************************************/ + ****************************************************************************/ #include #include #include -/*************************************************************************** +/**************************************************************************** * Public Functions - ***************************************************************************/ + ****************************************************************************/ uint16_t htons(uint16_t hs) { diff --git a/libc/sched/sched_getprioritymax.c b/libc/sched/sched_getprioritymax.c index e65c25d603..03660cbb8d 100644 --- a/libc/sched/sched_getprioritymax.c +++ b/libc/sched/sched_getprioritymax.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/sched/sched_getprioritymax.c * * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,11 +43,11 @@ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: ched_get_priority_max * * Description: @@ -63,7 +63,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int sched_get_priority_max(int policy) { diff --git a/libc/sched/sched_getprioritymin.c b/libc/sched/sched_getprioritymin.c index 23a06f5d3b..660677f8ca 100644 --- a/libc/sched/sched_getprioritymin.c +++ b/libc/sched/sched_getprioritymin.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/sched/sched_getprioritymin.c * * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,11 +43,11 @@ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_get_priority_min * * Description: @@ -63,7 +63,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int sched_get_priority_min(int policy) { diff --git a/libc/stdio/lib_dprintf.c b/libc/stdio/lib_dprintf.c index 0ea6475170..f3f9de8ee5 100644 --- a/libc/stdio/lib_dprintf.c +++ b/libc/stdio/lib_dprintf.c @@ -41,11 +41,11 @@ /**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: dprintf - **************************************************************************/ + ****************************************************************************/ int dprintf(int fd, FAR const char *fmt, ...) { diff --git a/libc/stdio/lib_fgetc.c b/libc/stdio/lib_fgetc.c index 20ebd41b29..022aed1dcc 100644 --- a/libc/stdio/lib_fgetc.c +++ b/libc/stdio/lib_fgetc.c @@ -60,29 +60,29 @@ * Public Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * fgetc - **************************************************************************/ + ****************************************************************************/ int fgetc(FAR FILE *stream) { diff --git a/libc/stdio/lib_fgets.c b/libc/stdio/lib_fgets.c index 47f35597c1..88dfca3ad1 100644 --- a/libc/stdio/lib_fgets.c +++ b/libc/stdio/lib_fgets.c @@ -65,7 +65,7 @@ * buffer. A null terminator is stored after the last character in the * buffer. * - **************************************************************************/ + ****************************************************************************/ char *fgets(FAR char *buf, int buflen, FILE *stream) { diff --git a/libc/stdio/lib_gets.c b/libc/stdio/lib_gets.c index d15c8bd08a..f793fbc445 100644 --- a/libc/stdio/lib_gets.c +++ b/libc/stdio/lib_gets.c @@ -67,7 +67,7 @@ * This API should not be used because it is inherently unsafe. Consider * using fgets which is safer and slightly more efficient. * - **************************************************************************/ + ****************************************************************************/ FAR char *gets(FAR char *s) { diff --git a/libc/stdio/lib_gets_s.c b/libc/stdio/lib_gets_s.c index 54f8891f91..a5a4c50059 100644 --- a/libc/stdio/lib_gets_s.c +++ b/libc/stdio/lib_gets_s.c @@ -77,7 +77,7 @@ * characters from stdin until new-line character, end-of-file condition, * or read error. * - **************************************************************************/ + ****************************************************************************/ FAR char *gets_s(FAR char *s, rsize_t n) { diff --git a/libc/stdio/lib_libfgets.c b/libc/stdio/lib_libfgets.c index 73cf47adc7..210d273bf3 100644 --- a/libc/stdio/lib_libfgets.c +++ b/libc/stdio/lib_libfgets.c @@ -92,7 +92,7 @@ * 'stream' until an EOF or a newline encountered or until a read error * occurs. * - **************************************************************************/ + ****************************************************************************/ static void consume_eol(FILE *stream, bool consume) { @@ -139,7 +139,7 @@ static void consume_eol(FILE *stream, bool consume) * until a read error occurs. Otherwise, lib_fgets() returns with the * remaining of the incoming stream buffer. * - **************************************************************************/ + ****************************************************************************/ FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream, bool keepnl, bool consume) diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index 1c210a7c0d..b38257f230 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -62,29 +62,29 @@ * Public Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: printf - **************************************************************************/ + ****************************************************************************/ int printf(FAR const char *fmt, ...) { diff --git a/libc/stdio/lib_ungetc.c b/libc/stdio/lib_ungetc.c index 473262d09f..c8baf9a266 100644 --- a/libc/stdio/lib_ungetc.c +++ b/libc/stdio/lib_ungetc.c @@ -64,29 +64,29 @@ * Public Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: ungetc - **************************************************************************/ + ****************************************************************************/ int ungetc(int c, FAR FILE *stream) { diff --git a/libc/stdio/lib_vprintf.c b/libc/stdio/lib_vprintf.c index 7db042bcf5..52e6fc9107 100644 --- a/libc/stdio/lib_vprintf.c +++ b/libc/stdio/lib_vprintf.c @@ -59,29 +59,29 @@ * Public Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: vprintf - **************************************************************************/ + ****************************************************************************/ int vprintf(FAR const char *fmt, va_list ap) { diff --git a/libc/stdlib/lib_abort.c b/libc/stdlib/lib_abort.c index 0cbeff3c00..86bad40726 100644 --- a/libc/stdlib/lib_abort.c +++ b/libc/stdlib/lib_abort.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib/lib_abort.c * * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. @@ -31,46 +31,46 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: Abort * * Description: @@ -93,7 +93,7 @@ * Returned Value: * This function does not return, * - ************************************************************************/ + ****************************************************************************/ void abort(void) { diff --git a/libc/stdlib/lib_abs.c b/libc/stdlib/lib_abs.c index 677ea7dfdb..b3a7854f7c 100644 --- a/libc/stdlib/lib_abs.c +++ b/libc/stdlib/lib_abs.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib/lib_abs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. @@ -31,18 +31,18 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ int abs(int j) { diff --git a/libc/stdlib/lib_div.c b/libc/stdlib/lib_div.c index 03274a1da4..290cc7a1c4 100644 --- a/libc/stdlib/lib_div.c +++ b/libc/stdlib/lib_div.c @@ -31,7 +31,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files diff --git a/libc/stdlib/lib_imaxabs.c b/libc/stdlib/lib_imaxabs.c index fca9fe7f03..12c5dc15a7 100644 --- a/libc/stdlib/lib_imaxabs.c +++ b/libc/stdlib/lib_imaxabs.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib//lib_abs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. @@ -31,18 +31,18 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ intmax_t imaxabs(intmax_t j) { diff --git a/libc/stdlib/lib_itoa.c b/libc/stdlib/lib_itoa.c index 4e6b2feec3..16170160aa 100644 --- a/libc/stdlib/lib_itoa.c +++ b/libc/stdlib/lib_itoa.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib/lib_itoa.c * * Copyright (C) 2013 Brooks Automation, Inc. All rights reserved. @@ -36,18 +36,18 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ char *itoa(int val, char *str, int base) { diff --git a/libc/stdlib/lib_labs.c b/libc/stdlib/lib_labs.c index 7eef741631..ad398d0beb 100644 --- a/libc/stdlib/lib_labs.c +++ b/libc/stdlib/lib_labs.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib/lib_labs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. @@ -31,18 +31,18 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ long int labs(long int j) { diff --git a/libc/stdlib/lib_ldiv.c b/libc/stdlib/lib_ldiv.c index 84a4343fd5..66b2a88e3d 100644 --- a/libc/stdlib/lib_ldiv.c +++ b/libc/stdlib/lib_ldiv.c @@ -36,7 +36,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files diff --git a/libc/stdlib/lib_llabs.c b/libc/stdlib/lib_llabs.c index 452b624c3b..ee8b76225e 100644 --- a/libc/stdlib/lib_llabs.c +++ b/libc/stdlib/lib_llabs.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/stdlib/lib_llabs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. @@ -31,19 +31,19 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_LONG long long int llabs(long long int j) diff --git a/libc/stdlib/lib_lldiv.c b/libc/stdlib/lib_lldiv.c index 0c4e4da192..753cdd93ae 100644 --- a/libc/stdlib/lib_lldiv.c +++ b/libc/stdlib/lib_lldiv.c @@ -36,7 +36,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files diff --git a/libc/string/lib_memcmp.c b/libc/string/lib_memcmp.c index 66acb1fdfb..a4f5004bfd 100644 --- a/libc/string/lib_memcmp.c +++ b/libc/string/lib_memcmp.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/string/lib_memcmp.c * * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. @@ -31,23 +31,23 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_MEMCMP int memcmp(FAR const void *s1, FAR const void *s2, size_t n) diff --git a/libc/string/lib_memmove.c b/libc/string/lib_memmove.c index 6c37fb2224..8c70998e81 100644 --- a/libc/string/lib_memmove.c +++ b/libc/string/lib_memmove.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/string/lib_memmove.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. @@ -31,23 +31,23 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_MEMMOVE FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) diff --git a/libc/string/lib_stpcpy.c b/libc/string/lib_stpcpy.c index 046846468e..dd2917f7bc 100644 --- a/libc/string/lib_stpcpy.c +++ b/libc/string/lib_stpcpy.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string/lib_strppy.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,21 +31,21 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: stpcpy * * Description: @@ -56,7 +56,7 @@ * The stpcpy() function returns a pointer to the terminating NUL * character copied into the 'dest' buffer * - ************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STPCPY FAR char *stpcpy(FAR char *dest, FAR const char *src) diff --git a/libc/string/lib_strcpy.c b/libc/string/lib_strcpy.c index efd4f2aca1..f5413688f5 100644 --- a/libc/string/lib_strcpy.c +++ b/libc/string/lib_strcpy.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string/lib_strcpy.c * * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,21 +31,21 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: strcpy * * Description: @@ -55,7 +55,7 @@ * Returned value: * The strcpy() function returns the 'dest' pointer * - ************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRCPY FAR char *strcpy(FAR char *dest, FAR const char *src) diff --git a/libc/string/lib_strdup.c b/libc/string/lib_strdup.c index ee626e184e..5ba87ae27b 100644 --- a/libc/string/lib_strdup.c +++ b/libc/string/lib_strdup.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string//lib_strdup.c * * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,9 +43,9 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ FAR char *strdup(const char *s) { diff --git a/libc/string/lib_strerror.c b/libc/string/lib_strerror.c index 58724de35c..00eb2248a2 100644 --- a/libc/string/lib_strerror.c +++ b/libc/string/lib_strerror.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string/lib_strerror.c * * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,13 +43,13 @@ #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ struct errno_strmap_s { @@ -57,9 +57,9 @@ struct errno_strmap_s const char *str; }; -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_LIBC_STRERROR @@ -334,17 +334,17 @@ static const struct errno_strmap_s g_errnomap[] = #endif /* CONFIG_LIBC_STRERROR */ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: strerror - ************************************************************************/ + ****************************************************************************/ FAR const char *strerror(int errnum) { diff --git a/libc/string/lib_strncat.c b/libc/string/lib_strncat.c index d9deed58b7..91ebbf608f 100644 --- a/libc/string/lib_strncat.c +++ b/libc/string/lib_strncat.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/string/lib_strncat.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. @@ -31,19 +31,19 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRNCAT char *strncat(char *dest, const char *src, size_t n) diff --git a/libc/string/lib_strncpy.c b/libc/string/lib_strncpy.c index 095111c94d..dbafc1c3a1 100644 --- a/libc/string/lib_strncpy.c +++ b/libc/string/lib_strncpy.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * libc/string/lib_strncpy.c * * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,23 +31,23 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: strncpy - ************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRNCPY char *strncpy(FAR char *dest, FAR const char *src, size_t n) diff --git a/libc/string/lib_strndup.c b/libc/string/lib_strndup.c index bac9128c5d..1b9d868067 100644 --- a/libc/string/lib_strndup.c +++ b/libc/string/lib_strndup.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string//lib_strndup.c * * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,10 +43,10 @@ #include "lib_internal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ -/************************************************************************ + ****************************************************************************/ +/**************************************************************************** * Name: strndup * * Description: @@ -61,7 +61,7 @@ * character. The newly created string will always be properly * terminated. * - ************************************************************************/ + ****************************************************************************/ FAR char *strndup(FAR const char *s, size_t size) { diff --git a/libc/string/lib_strrchr.c b/libc/string/lib_strrchr.c index 2432853d73..601f655b43 100644 --- a/libc/string/lib_strrchr.c +++ b/libc/string/lib_strrchr.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * libc/string/lib_strrchr.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,19 +31,19 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ /* The strrchr() function returns a pointer to the last * occurrence of the character c in the string s. diff --git a/libc/string/lib_vikmemcpy.c b/libc/string/lib_vikmemcpy.c index 264b2f2511..7dbcd331b2 100644 --- a/libc/string/lib_vikmemcpy.c +++ b/libc/string/lib_vikmemcpy.c @@ -57,9 +57,9 @@ #define CONFIG_MEMCPY_INDEXED_COPY -/******************************************************************** +/**************************************************************************** * Included Files - *******************************************************************/ + ****************************************************************************/ #include #include @@ -68,9 +68,9 @@ #include #include -/******************************************************************** +/**************************************************************************** * Pre-processor Definitions - *******************************************************************/ + ****************************************************************************/ /* Can't support CONFIG_MEMCPY_64BIT if the platform does not have 64-bit * integer types. @@ -124,10 +124,10 @@ #endif /* CONFIG_ENDIAN_BIG */ -/******************************************************************** +/**************************************************************************** * Macros for copying words of different alignment. * Uses incremening pointers. - *******************************************************************/ + ****************************************************************************/ #define CP_INCR() \ { \ @@ -142,10 +142,10 @@ INC_VAL(dstN) = dstWord; \ } -/******************************************************************** +/**************************************************************************** * Macros for copying words of different alignment. * Uses array indexes. - *******************************************************************/ + ****************************************************************************/ #define CP_INDEX(idx) \ { \ @@ -160,11 +160,11 @@ dstN[x] = dstWord; \ } -/******************************************************************** +/**************************************************************************** * Macros for copying words of different alignment. * Uses incremening pointers or array indexes depending on * configuration. - *******************************************************************/ + ****************************************************************************/ #if defined (CONFIG_MEMCPY_INDEXED_COPY) @@ -279,9 +279,9 @@ return dest; \ } -/******************************************************************** +/**************************************************************************** * Type Definitions - *******************************************************************/ + ****************************************************************************/ #ifdef CONFIG_MEMCPY_64BIT typedef uint64_t UIntN; @@ -291,10 +291,10 @@ typedef uint32_t UIntN; # define TYPE_WIDTH 4L #endif -/******************************************************************** +/**************************************************************************** * Public Functions - *******************************************************************/ -/******************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: memcpy * * Description: @@ -308,7 +308,7 @@ typedef uint32_t UIntN; * Returned Value: * A pointer to destination buffer * - *******************************************************************/ + ****************************************************************************/ void *memcpy(void *dest, const void *src, size_t count) { diff --git a/libc/time/lib_gmtime.c b/libc/time/lib_gmtime.c index 487969bab7..bd0addf295 100644 --- a/libc/time/lib_gmtime.c +++ b/libc/time/lib_gmtime.c @@ -57,17 +57,17 @@ * Private Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Functions diff --git a/libc/time/lib_gmtimer.c b/libc/time/lib_gmtimer.c index c397ae772d..b42d7a7c90 100644 --- a/libc/time/lib_gmtimer.c +++ b/libc/time/lib_gmtimer.c @@ -73,17 +73,17 @@ static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); #endif /* CONFIG_JULIAN_TIME */ #endif /* CONFIG_GREGORIAN_TIME */ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Private Functions diff --git a/mm/kmm_heap/kmm_addregion.c b/mm/kmm_heap/kmm_addregion.c index cccb202699..47dcbd54fb 100644 --- a/mm/kmm_heap/kmm_addregion.c +++ b/mm/kmm_heap/kmm_addregion.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/kmm_heap/kmm_addregion.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,27 +43,27 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/************************************************************************ +/**************************************************************************** * Pre-processor definition - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_addregion * * Description: @@ -76,7 +76,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void kmm_addregion(FAR void *heap_start, size_t heap_size) { diff --git a/mm/kmm_heap/kmm_free.c b/mm/kmm_heap/kmm_free.c index 1b300158b3..7b47fae7b1 100644 --- a/mm/kmm_heap/kmm_free.c +++ b/mm/kmm_heap/kmm_free.c @@ -58,7 +58,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_free * * Description: @@ -71,7 +71,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void kmm_free(FAR void *mem) { diff --git a/mm/kmm_heap/kmm_heapmember.c b/mm/kmm_heap/kmm_heapmember.c index d872288721..3fbe96adcb 100644 --- a/mm/kmm_heap/kmm_heapmember.c +++ b/mm/kmm_heap/kmm_heapmember.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/kmm_heap/kmm_heapmember.c * * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,27 +45,27 @@ #if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG) -/************************************************************************ +/**************************************************************************** * Pre-processor definition - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_heapmember * * Description: @@ -79,7 +79,7 @@ * not. If the address is not a member of the kernel heap, then it * must be a member of the user-space heap (unchecked) * - ************************************************************************/ + ****************************************************************************/ bool kmm_heapmember(FAR void *mem) { diff --git a/mm/kmm_heap/kmm_initialize.c b/mm/kmm_heap/kmm_initialize.c index ed4cbc926a..07c679e28b 100644 --- a/mm/kmm_heap/kmm_initialize.c +++ b/mm/kmm_heap/kmm_initialize.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/kmm_heap/kmm_initialize.c * * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,31 +43,31 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/************************************************************************ +/**************************************************************************** * Pre-processor definition - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ /* This is the kernel heap */ struct mm_heap_s g_kmmheap; -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_initialize * * Description: @@ -81,7 +81,7 @@ struct mm_heap_s g_kmmheap; * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void kmm_initialize(FAR void *heap_start, size_t heap_size) { diff --git a/mm/kmm_heap/kmm_kernel.c b/mm/kmm_heap/kmm_kernel.c index 4ab8e1b2bc..f2477e228a 100644 --- a/mm/kmm_heap/kmm_kernel.c +++ b/mm/kmm_heap/kmm_kernel.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/kmm_heap/kmm_kernel.c * * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,27 +46,27 @@ #if ((defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ defined(CONFIG_BUILD_KERNEL)) && defined(CONFIG_MM_KERNEL_HEAP) -/************************************************************************ +/**************************************************************************** * Pre-processor definition - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_heapmember * * Description: @@ -80,7 +80,7 @@ * not. If the address is not a member of the kernel heap, then it * must be a member of the user-space heap (unchecked) * - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_DEBUG bool kmm_heapmember(FAR void *mem) diff --git a/mm/kmm_heap/kmm_malloc.c b/mm/kmm_heap/kmm_malloc.c index a92e5e5449..a360c50f8f 100644 --- a/mm/kmm_heap/kmm_malloc.c +++ b/mm/kmm_heap/kmm_malloc.c @@ -67,7 +67,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_malloc * * Description: @@ -79,7 +79,7 @@ * Return Value: * The address of the allocated memory (NULL on failure to allocate) * - ************************************************************************/ + ****************************************************************************/ FAR void *kmm_malloc(size_t size) { diff --git a/mm/kmm_heap/kmm_memalign.c b/mm/kmm_heap/kmm_memalign.c index 40327e1d82..1fde19f7e4 100644 --- a/mm/kmm_heap/kmm_memalign.c +++ b/mm/kmm_heap/kmm_memalign.c @@ -57,7 +57,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_memalign * * Description: @@ -70,7 +70,7 @@ * Return Value: * The address of the re-allocated memory (NULL on failure to allocate) * - ************************************************************************/ + ****************************************************************************/ FAR void *kmm_memalign(size_t alignment, size_t size) { diff --git a/mm/kmm_heap/kmm_sem.c b/mm/kmm_heap/kmm_sem.c index 47fce18d41..ffff92920f 100644 --- a/mm/kmm_heap/kmm_sem.c +++ b/mm/kmm_heap/kmm_sem.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/kmm_heap/kmm_sem.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,27 +43,27 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/************************************************************************ +/**************************************************************************** * Pre-processor definition - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_trysemaphore * * Description: @@ -75,14 +75,14 @@ * Return Value: * OK on success; a negated errno on failure * - ************************************************************************/ + ****************************************************************************/ int kmm_trysemaphore(void) { return mm_trysemaphore(&g_kmmheap); } -/************************************************************************ +/**************************************************************************** * Name: kmm_givesemaphore * * Description: @@ -94,7 +94,7 @@ int kmm_trysemaphore(void) * Return Value: * OK on success; a negated errno on failure * - ************************************************************************/ + ****************************************************************************/ void kmm_givesemaphore(void) { diff --git a/mm/kmm_heap/kmm_zalloc.c b/mm/kmm_heap/kmm_zalloc.c index c09f329045..303d1f0040 100644 --- a/mm/kmm_heap/kmm_zalloc.c +++ b/mm/kmm_heap/kmm_zalloc.c @@ -51,7 +51,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kmm_zalloc * * Description: @@ -63,7 +63,7 @@ * Return Value: * The address of the allocated memory (NULL on failure to allocate) * - ************************************************************************/ + ****************************************************************************/ FAR void *kmm_zalloc(size_t size) { diff --git a/mm/umm_heap/umm_addregion.c b/mm/umm_heap/umm_addregion.c index 3aaa890aa2..00e5372ee8 100644 --- a/mm/umm_heap/umm_addregion.c +++ b/mm/umm_heap/umm_addregion.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/umm_heap/umm_addregion.c * * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,11 +43,11 @@ #include "umm_heap/umm_heap.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: umm_addregion * * Description: @@ -62,7 +62,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void umm_addregion(FAR void *heap_start, size_t heap_size) { diff --git a/mm/umm_heap/umm_globals.c b/mm/umm_heap/umm_globals.c index 8242769c0c..012aac7631 100644 --- a/mm/umm_heap/umm_globals.c +++ b/mm/umm_heap/umm_globals.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/umm_heap/umm_globals.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,9 +43,9 @@ #include "umm_heap/umm_heap.h" -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) /* In the kernel build, there a multiple user heaps; one for each task diff --git a/mm/umm_heap/umm_initialize.c b/mm/umm_heap/umm_initialize.c index f4d319844a..04e045e073 100644 --- a/mm/umm_heap/umm_initialize.c +++ b/mm/umm_heap/umm_initialize.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/umm_heap/umm_initialize.c * * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,11 +45,11 @@ #include "umm_heap/umm_heap.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: umm_initialize * * Description: @@ -92,7 +92,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void umm_initialize(FAR void *heap_start, size_t heap_size) { diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c index 19dfa89918..7832af4e29 100644 --- a/mm/umm_heap/umm_malloc.c +++ b/mm/umm_heap/umm_malloc.c @@ -50,7 +50,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: malloc * * Description: @@ -62,7 +62,7 @@ * Return Value: * The address of the allocated memory (NULL on failure to allocate) * - ************************************************************************/ + ****************************************************************************/ FAR void *malloc(size_t size) { diff --git a/mm/umm_heap/umm_sem.c b/mm/umm_heap/umm_sem.c index f8cf11b6c8..a9012e542c 100644 --- a/mm/umm_heap/umm_sem.c +++ b/mm/umm_heap/umm_sem.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * mm/umm_heap/umm_sem.c * * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,11 +43,11 @@ #include "umm_heap/umm_heap.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: umm_trysemaphore * * Description: @@ -61,14 +61,14 @@ * Return Value: * OK on success; a negated errno on failure * - ************************************************************************/ + ****************************************************************************/ int umm_trysemaphore(void) { return mm_trysemaphore(USR_HEAP); } -/************************************************************************ +/**************************************************************************** * Name: umm_givesemaphore * * Description: @@ -82,7 +82,7 @@ int umm_trysemaphore(void) * Return Value: * OK on success; a negated errno on failure * - ************************************************************************/ + ****************************************************************************/ void umm_givesemaphore(void) { diff --git a/mm/umm_heap/umm_zalloc.c b/mm/umm_heap/umm_zalloc.c index 95080427cf..7103e3233b 100644 --- a/mm/umm_heap/umm_zalloc.c +++ b/mm/umm_heap/umm_zalloc.c @@ -50,7 +50,7 @@ * Public Functions ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: zalloc * * Description: @@ -62,7 +62,7 @@ * Return Value: * The address of the allocated memory (NULL on failure to allocate) * - ************************************************************************/ + ****************************************************************************/ FAR void *zalloc(size_t size) { diff --git a/sched/clock/clock_getres.c b/sched/clock/clock_getres.c index 656b794553..4c154ea6f8 100644 --- a/sched/clock/clock_getres.c +++ b/sched/clock/clock_getres.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/clock/clock_getres.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,45 +46,45 @@ #include "clock/clock.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Private Variables - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: clock_getres * * Description: * Clock Functions based on POSIX APIs * - ************************************************************************/ + ****************************************************************************/ int clock_getres(clockid_t clock_id, struct timespec *res) { diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index 1a92a66bc5..519785d9ea 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/clock/clock_gettime.c * * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,45 +50,45 @@ #include "clock/clock.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Private Variables - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: clock_gettime * * Description: * Clock Functions based on POSIX APIs * - ************************************************************************/ + ****************************************************************************/ int clock_gettime(clockid_t clock_id, struct timespec *tp) { diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index c1a155707f..1871e90d2b 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -72,9 +72,9 @@ * Private Function Prototypes ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Constant Data - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Public Data @@ -90,13 +90,13 @@ volatile uint32_t g_system_timer; struct timespec g_basetime; -/************************************************************************** +/**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Functions - **************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: clock_basetime diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index 8d247f0c6c..3749fa43df 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/clock/clock_settime.c * * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,45 +49,45 @@ #include "clock/clock.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Public Constant Data - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Private Variables - **********************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: clock_settime * * Description: * Clock Functions based on POSIX APIs * - ************************************************************************/ + ****************************************************************************/ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp) { diff --git a/sched/clock/clock_timespec_add.c b/sched/clock/clock_timespec_add.c index 21688a2b81..f2eae0dac2 100644 --- a/sched/clock/clock_timespec_add.c +++ b/sched/clock/clock_timespec_add.c @@ -48,7 +48,7 @@ * Public Functions ********************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: clock_timespec_add * * Description: @@ -61,7 +61,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void clock_timespec_add(FAR const struct timespec *ts1, FAR const struct timespec *ts2, diff --git a/sched/clock/clock_timespec_subtract.c b/sched/clock/clock_timespec_subtract.c index 34b0725426..c47ea35562 100644 --- a/sched/clock/clock_timespec_subtract.c +++ b/sched/clock/clock_timespec_subtract.c @@ -48,7 +48,7 @@ * Public Functions ********************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: clock_timespec_subtract * * Description: @@ -62,7 +62,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void clock_timespec_subtract(FAR const struct timespec *ts1, FAR const struct timespec *ts2, diff --git a/sched/group/group_free.c b/sched/group/group_free.c index b3830e4f7a..2a4f309739 100644 --- a/sched/group/group_free.c +++ b/sched/group/group_free.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/group/group_free.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,38 +50,38 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: group_free * * Description: * Free memory appropriate previously allocated via group_malloc() using * the appropriate memory manager. * - ************************************************************************/ + ****************************************************************************/ void group_free(FAR struct task_group_s *group, FAR void *mem) { diff --git a/sched/group/group_malloc.c b/sched/group/group_malloc.c index 03c603953c..f47a6f74aa 100644 --- a/sched/group/group_malloc.c +++ b/sched/group/group_malloc.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/group/group_malloc.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,31 +50,31 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: group_malloc * * Description: @@ -84,7 +84,7 @@ * group and must be allocated so that it accessible by unprivileged * code. * - ************************************************************************/ + ****************************************************************************/ FAR void *group_malloc(FAR struct task_group_s *group, size_t nbytes) { diff --git a/sched/group/group_zalloc.c b/sched/group/group_zalloc.c index e45deaf4b3..23ddea6f8b 100644 --- a/sched/group/group_zalloc.c +++ b/sched/group/group_zalloc.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/group/group_zalloc.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: group_malloc * * Description: @@ -79,7 +79,7 @@ * that it is only accessed by privileged code; Otherwise, it must be * allocated so that it accessible by unprivileged code. * - ************************************************************************/ + ****************************************************************************/ FAR void *group_zalloc(FAR struct task_group_s *group, size_t nbytes) { diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c index 98f6f28e3d..6073c3edf7 100644 --- a/sched/irq/irq_dispatch.c +++ b/sched/irq/irq_dispatch.c @@ -77,7 +77,7 @@ * order to dispatch an interrupt to the appropriate, registered handling * logic. * - ***************************************************************************/ + ****************************************************************************/ void irq_dispatch(int irq, FAR void *context) { diff --git a/sched/mqueue/mq_getattr.c b/sched/mqueue/mq_getattr.c index 9e997dfe36..3c0725320f 100644 --- a/sched/mqueue/mq_getattr.c +++ b/sched/mqueue/mq_getattr.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_getattr.c * * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. @@ -31,22 +31,22 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Function: mq_getattr * * Description: @@ -62,7 +62,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat) { diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index 9d98fe4170..ee54e28ce5 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_initialize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,13 +45,13 @@ #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ /* This is a container for a list of message queue descriptors. */ @@ -61,9 +61,9 @@ struct mq_des_block_s struct mq_des mqdes[NUM_MSG_DESCRIPTORS]; }; -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ /* The g_msgfree is a list of messages that are available for general * use. The number of messages in this list is a system configuration @@ -85,9 +85,9 @@ sq_queue_t g_msgfreeirq; sq_queue_t g_desfree; -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ /* g_msgalloc is a pointer to the start of the allocated block of * messages. @@ -105,11 +105,11 @@ static struct mqueue_msg_s *g_msgfreeirqalloc; static sq_queue_t g_desalloc; -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_msgblockalloc * * Description: @@ -118,7 +118,7 @@ static sq_queue_t g_desalloc; * Inputs Parameters: * queue * - ************************************************************************/ + ****************************************************************************/ static struct mqueue_msg_s * mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, @@ -148,11 +148,11 @@ mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, return mqmsgblock; } -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_initialize * * Description: @@ -166,7 +166,7 @@ mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_initialize(void) { @@ -195,7 +195,7 @@ void mq_initialize(void) mq_desblockalloc(); } -/************************************************************************ +/**************************************************************************** * Name: mq_desblockalloc * * Description: @@ -208,7 +208,7 @@ void mq_initialize(void) * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_desblockalloc(void) { diff --git a/sched/mqueue/mq_msgfree.c b/sched/mqueue/mq_msgfree.c index 7944e7d1cd..96e9a95546 100644 --- a/sched/mqueue/mq_msgfree.c +++ b/sched/mqueue/mq_msgfree.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_msgfree.c * * Copyright (C) 2007, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_msgfree * * Description: @@ -84,7 +84,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) { diff --git a/sched/mqueue/mq_msgqfree.c b/sched/mqueue/mq_msgqfree.c index 08360c239e..85a591502f 100644 --- a/sched/mqueue/mq_msgqfree.c +++ b/sched/mqueue/mq_msgqfree.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_msgqfree.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,31 +43,31 @@ #include #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_msgqfree * * Description: @@ -83,7 +83,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_msgqfree(FAR struct mqueue_inode_s *msgq) { diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index e6efa8a781..a9a57c3f07 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_notify.c * * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,31 +49,31 @@ #include "sched/sched.h" #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_notify * * Description: @@ -124,7 +124,7 @@ * message shall satisfy mq_receive()... The resulting behavior is as if * the message queue remains empty, and no notification shall be sent." * - ************************************************************************/ + ****************************************************************************/ int mq_notify(mqd_t mqdes, const struct sigevent *notification) { diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c index 7db59ebb5e..173c147a5a 100644 --- a/sched/mqueue/mq_receive.c +++ b/sched/mqueue/mq_receive.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_receive.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -48,31 +48,31 @@ #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_receive * * Description: @@ -110,7 +110,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio) diff --git a/sched/mqueue/mq_recover.c b/sched/mqueue/mq_recover.c index 667df72907..d4514549fe 100644 --- a/sched/mqueue/mq_recover.c +++ b/sched/mqueue/mq_recover.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_recover.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_recover * * Description: @@ -87,7 +87,7 @@ * Assumptions: * This function is called from task deletion logic in a safe context. * - ************************************************************************/ + ****************************************************************************/ void mq_recover(FAR struct tcb_s *tcb) { diff --git a/sched/mqueue/mq_release.c b/sched/mqueue/mq_release.c index 9c0e3409c3..cf9db170af 100644 --- a/sched/mqueue/mq_release.c +++ b/sched/mqueue/mq_release.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_release.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,31 +43,31 @@ #include "mqueue/mqueue.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: mq_release * * Description: @@ -81,7 +81,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_release(FAR struct task_group_s *group) { diff --git a/sched/mqueue/mq_setattr.c b/sched/mqueue/mq_setattr.c index 858621a15c..71fe8df728 100644 --- a/sched/mqueue/mq_setattr.c +++ b/sched/mqueue/mq_setattr.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/mqueue/mq_setattr.c * * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,11 +44,11 @@ #include -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Function: mq_setattr * * Description: @@ -71,7 +71,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat, struct mq_attr *oldstat) diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 09f3b829fd..60c2ba6585 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -1,4 +1,4 @@ -/************************************************************************** +/**************************************************************************** * sched/pthread/pthread_cancel.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Included Files - **************************************************************************/ + ****************************************************************************/ #include @@ -47,33 +47,33 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/************************************************************************** +/**************************************************************************** * Pre-processor Definitions - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Types - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Function Prototypes - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Data - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Variables - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Private Functions - **************************************************************************/ + ****************************************************************************/ -/************************************************************************** +/**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ int pthread_cancel(pthread_t thread) { diff --git a/sched/pthread/pthread_completejoin.c b/sched/pthread/pthread_completejoin.c index 6af2774e1b..ec7bb96af6 100644 --- a/sched/pthread/pthread_completejoin.c +++ b/sched/pthread/pthread_completejoin.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_completejoin.c * * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,27 +49,27 @@ #include "group/group.h" #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_notifywaiters * * Description: @@ -77,7 +77,7 @@ * exit data. This must be done by the child at child thread * destruction time. * - ************************************************************************/ + ****************************************************************************/ static bool pthread_notifywaiters(FAR struct join_s *pjoin) { @@ -122,7 +122,7 @@ static bool pthread_notifywaiters(FAR struct join_s *pjoin) return false; } -/************************************************************************ +/**************************************************************************** * Name: pthread_removejoininfo * * Description: @@ -137,7 +137,7 @@ static bool pthread_notifywaiters(FAR struct join_s *pjoin) * Assumptions: * The caller has provided protection from re-entrancy. * - ************************************************************************/ + ****************************************************************************/ static void pthread_removejoininfo(FAR struct task_group_s *group, pid_t pid) @@ -192,11 +192,11 @@ static void pthread_removejoininfo(FAR struct task_group_s *group, } } -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_completejoin * * Description: @@ -214,7 +214,7 @@ static void pthread_removejoininfo(FAR struct task_group_s *group, * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int pthread_completejoin(pid_t pid, FAR void *exit_value) { @@ -268,7 +268,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) return OK; } -/************************************************************************ +/**************************************************************************** * Name: pthread_destroyjoin * * Description: @@ -282,7 +282,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) * Assumptions: * The caller holds tg_joinsem * - ************************************************************************/ + ****************************************************************************/ void pthread_destroyjoin(FAR struct task_group_s *group, FAR struct join_s *pjoin) diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 704a296dc2..587502cd66 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_detach.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,31 +50,31 @@ #include "group/group.h" #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_detach * * Description: @@ -93,7 +93,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int pthread_detach(pthread_t thread) { diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 03b3f6f2f4..6a8e2463a2 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_exit.c * * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -53,31 +53,31 @@ #include "task/task.h" #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_exit * * Description: @@ -91,7 +91,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ void pthread_exit(FAR void *exit_value) { diff --git a/sched/pthread/pthread_findjoininfo.c b/sched/pthread/pthread_findjoininfo.c index 35ea396c33..28174becd8 100644 --- a/sched/pthread/pthread_findjoininfo.c +++ b/sched/pthread/pthread_findjoininfo.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * pthread_findjoininfo.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,31 +44,31 @@ #include "group/group.h" #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: thread_findjoininfo * * Description: @@ -84,7 +84,7 @@ * Assumptions: * The caller has provided protection from re-entrancy. * - ************************************************************************/ + ****************************************************************************/ FAR struct join_s *pthread_findjoininfo(FAR struct task_group_s *group, pid_t pid) diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index 6fb0e29deb..34435a2ef4 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_getspecific.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -47,31 +47,31 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_getspecific * * Description: @@ -99,7 +99,7 @@ * may be called from a thread-specific data destructor * function. * - ************************************************************************/ + ****************************************************************************/ FAR void *pthread_getspecific(pthread_key_t key) { diff --git a/sched/pthread/pthread_keydelete.c b/sched/pthread/pthread_keydelete.c index 64a633af3e..7915ed6e3e 100644 --- a/sched/pthread/pthread_keydelete.c +++ b/sched/pthread/pthread_keydelete.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_keydelete.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,31 +45,31 @@ #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_key_delete * * Description: @@ -87,7 +87,7 @@ * * POSIX Compatibility: * - ************************************************************************/ + ****************************************************************************/ int pthread_key_delete(pthread_key_t key) { diff --git a/sched/pthread/pthread_kill.c b/sched/pthread/pthread_kill.c index 78da939d08..870cb15a41 100644 --- a/sched/pthread/pthread_kill.c +++ b/sched/pthread/pthread_kill.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_kill.c * * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,11 +50,11 @@ #include "sched/sched.h" #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_kill * * Description: @@ -81,7 +81,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int pthread_kill(pthread_t thread, int signo) { diff --git a/sched/pthread/pthread_release.c b/sched/pthread/pthread_release.c index 86254ef12b..b06f8d3c9a 100644 --- a/sched/pthread/pthread_release.c +++ b/sched/pthread/pthread_release.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_release.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #include "pthread/pthread.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_release * * Description: @@ -88,7 +88,7 @@ * * POSIX Compatibility: * - ************************************************************************/ + ****************************************************************************/ void pthread_release(FAR struct task_group_s *group) { diff --git a/sched/pthread/pthread_sigmask.c b/sched/pthread/pthread_sigmask.c index 4789f4aa98..ac541d8f8e 100644 --- a/sched/pthread/pthread_sigmask.c +++ b/sched/pthread/pthread_sigmask.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_sigmask.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,31 +44,31 @@ #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_sigmask * * Description: @@ -94,7 +94,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { diff --git a/sched/pthread/pthread_yield.c b/sched/pthread/pthread_yield.c index c6f5a2a41a..c5bf47bb53 100644 --- a/sched/pthread/pthread_yield.c +++ b/sched/pthread/pthread_yield.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/pthread/pthread_yield.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,40 +31,40 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: pthread_yield * * Description: @@ -79,7 +79,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ void pthread_yield(void) { diff --git a/sched/sched/sched_addblocked.c b/sched/sched/sched_addblocked.c index af0f043c09..87915f624b 100644 --- a/sched/sched/sched_addblocked.c +++ b/sched/sched/sched_addblocked.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_addblocked.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,31 +44,31 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_addblocked * * Description: @@ -86,7 +86,7 @@ * - The caller has established a critical section before * calling this function. * - ************************************************************************/ + ****************************************************************************/ void sched_addblocked(FAR struct tcb_s *btcb, tstate_t task_state) { diff --git a/sched/sched/sched_addprioritized.c b/sched/sched/sched_addprioritized.c index ad85e7d2db..babb31ef0d 100644 --- a/sched/sched/sched_addprioritized.c +++ b/sched/sched/sched_addprioritized.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_addprioritized.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_addprioritized * * Description: @@ -93,7 +93,7 @@ * the head of the task list is changed. * - The caller must set the task_state field of the TCB to * match the state associated with the list. - ************************************************************************/ + ****************************************************************************/ bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list) { diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index cb75a8436d..aa84ee9603 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_cpuload.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -49,9 +49,9 @@ #ifdef CONFIG_SCHED_CPULOAD -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ /* Are we using the system timer, or an external clock? Get the rate * of the sampling in ticks per second for the selected timer. */ @@ -65,17 +65,17 @@ # define CPULOAD_TICKSPERSEC CLOCKS_PER_SEC #endif -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ /* This is the total number of clock tick counts. Essentially the * 'denominator' for all CPU load calculations. @@ -83,15 +83,15 @@ volatile uint32_t g_cpuload_total; -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_process_cpuload * * Description: @@ -107,7 +107,7 @@ volatile uint32_t g_cpuload_total; * This function is called from a timer interrupt handler with all * interrupts disabled. * - ************************************************************************/ + ****************************************************************************/ void weak_function sched_process_cpuload(void) { diff --git a/sched/sched/sched_foreach.c b/sched/sched/sched_foreach.c index 016aef79bf..64ac809996 100644 --- a/sched/sched/sched_foreach.c +++ b/sched/sched/sched_foreach.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_foreach.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,20 +31,20 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_foreach * * Description: @@ -61,7 +61,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ void sched_foreach(sched_foreach_t handler, FAR void *arg) { diff --git a/sched/sched/sched_getfiles.c b/sched/sched/sched_getfiles.c index b31999371f..685f9a44ab 100644 --- a/sched/sched/sched_getfiles.c +++ b/sched/sched/sched_getfiles.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_getfiles.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,25 +31,25 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_getfiles * * Description: @@ -63,7 +63,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 2743d9fe79..93794b7eec 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_getparam.c * * Copyright (C) 2007, 2009, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,35 +45,35 @@ #include "clock/clock.h" #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_getparam * * Description: @@ -95,7 +95,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int sched_getparam (pid_t pid, FAR struct sched_param *param) { diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index 077fc61c80..8c4bb9de43 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_getscheduler.c * * Copyright (C) 2007, 2009, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -47,35 +47,35 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_getscheduler * * Description: @@ -96,7 +96,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int sched_getscheduler(pid_t pid) { diff --git a/sched/sched/sched_getsockets.c b/sched/sched/sched_getsockets.c index 764e2ffd21..372f4eeaee 100644 --- a/sched/sched/sched_getsockets.c +++ b/sched/sched/sched_getsockets.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_getsockets.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,15 +44,15 @@ #if CONFIG_NSOCKET_DESCRIPTORS > 0 -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_getsockets * * Description: @@ -66,7 +66,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ FAR struct socketlist *sched_getsockets(void) { diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index fc2887cd1a..7c1e28a500 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_lock.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,35 +45,35 @@ #include #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functionss - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_lock * * Description: @@ -89,7 +89,7 @@ * Return Value: * OK on success; ERROR on failure * - ************************************************************************/ + ****************************************************************************/ int sched_lock(void) { diff --git a/sched/sched/sched_lockcount.c b/sched/sched/sched_lockcount.c index 5e44c14f60..355f08d902 100644 --- a/sched/sched/sched_lockcount.c +++ b/sched/sched/sched_lockcount.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_lockcount.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,35 +43,35 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functionss - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_lockcount * * Description: @@ -87,7 +87,7 @@ * Return Value: * lockcount * - ************************************************************************/ + ****************************************************************************/ int sched_lockcount(void) { diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 993a3a00ce..1a172f9150 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_mergepending.c * * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -46,31 +46,31 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_mergepending * * Description: @@ -90,7 +90,7 @@ * - The caller handles the condition that occurs if the * the head of the sched_mergTSTATE_TASK_PENDINGs is changed. * - ************************************************************************/ + ****************************************************************************/ bool sched_mergepending(void) { diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index 0555cb67dc..648ea800b3 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_processtimer.c * * Copyright (C) 2007, 2009, 2014-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -50,31 +50,31 @@ #include "wdog/wdog.h" #include "clock/clock.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_SCHED_CPULOAD_TIMECONSTANT # define CONFIG_SCHED_CPULOAD_TIMECONSTANT 2 #endif -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_process_scheduler * * Description: @@ -87,7 +87,7 @@ * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline void sched_process_scheduler(void) @@ -124,19 +124,19 @@ static inline void sched_process_scheduler(void) # define sched_process_scheduler() #endif -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * System Timer Hooks * * These are standard interfaces that are exported by the OS * for use by the architecture specific logic * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_process_timer * * Description: @@ -152,7 +152,7 @@ static inline void sched_process_scheduler(void) * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void sched_process_timer(void) { diff --git a/sched/sched/sched_releasetcb.c b/sched/sched/sched_releasetcb.c index 79fcb20105..aebf546630 100644 --- a/sched/sched/sched_releasetcb.c +++ b/sched/sched/sched_releasetcb.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_releasetcb.c * * Copyright (C) 2007, 2009, 2012-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,16 +50,16 @@ #include "group/group.h" #include "timer/timer.h" -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_releasepid * * Description: When a task is destroyed, this function must * be called to make its process ID available for re-use. - ************************************************************************/ + ****************************************************************************/ static void sched_releasepid(pid_t pid) { @@ -84,11 +84,11 @@ static void sched_releasepid(pid_t pid) #endif } -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_releasetcb * * Description: @@ -108,7 +108,7 @@ static void sched_releasepid(pid_t pid) * Assumptions: * Interrupts are disabled. * - ************************************************************************/ + ****************************************************************************/ int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype) { diff --git a/sched/sched/sched_removeblocked.c b/sched/sched/sched_removeblocked.c index 944e3fa932..e09958b848 100644 --- a/sched/sched/sched_removeblocked.c +++ b/sched/sched/sched_removeblocked.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_removeblocked.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,31 +44,31 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_removeblocked * * Description: @@ -85,7 +85,7 @@ * - The caller has established a critical section before * calling this function. * - ************************************************************************/ + ****************************************************************************/ void sched_removeblocked(FAR struct tcb_s *btcb) { diff --git a/sched/sched/sched_roundrobin.c b/sched/sched/sched_roundrobin.c index 0c369dd02e..8e4ea37f13 100644 --- a/sched/sched/sched_roundrobin.c +++ b/sched/sched/sched_roundrobin.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_roundrobin.c * * Copyright (C) 2007, 2009, 2014-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -51,9 +51,9 @@ #if CONFIG_RR_INTERVAL > 0 -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ #ifndef MIN # define MIN(a,b) (((a) < (b)) ? (a) : (b)) @@ -63,11 +63,11 @@ # define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_roundrobin_process * * Description: @@ -94,7 +94,7 @@ * - The task associated with TCB uses the round robin scheduling * policy * - ************************************************************************/ + ****************************************************************************/ uint32_t sched_roundrobin_process(FAR struct tcb_s *tcb, uint32_t ticks, bool noswitches) diff --git a/sched/sched/sched_rrgetinterval.c b/sched/sched/sched_rrgetinterval.c index bb8a0152a2..8c54ab00f5 100644 --- a/sched/sched/sched_rrgetinterval.c +++ b/sched/sched/sched_rrgetinterval.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_rrgetinterval.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -48,11 +48,11 @@ #include "sched/sched.h" #include "clock/clock.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_rr_get_interval * * Description: @@ -78,7 +78,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int sched_rr_get_interval(pid_t pid, struct timespec *interval) { diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c old mode 100755 new mode 100644 diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 8c223d4cb0..c765c075cb 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_timerexpiration.c * * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -55,9 +55,9 @@ #ifdef CONFIG_SCHED_TICKLESS -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ /* In the original design, it was planned that sched_timer_reasses() be * called whenever there was a change at the head of the ready-to-run * list. That call was intended to establish a new time-slice or to @@ -87,9 +87,9 @@ # define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP /* By default, the RTOS tickless logic assumes that range of times that can @@ -108,9 +108,9 @@ uint32_t g_oneshot_maxticks = UINT32_MAX; #endif -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ /* This is the duration of the currently active timer or, when * sched_timer_expiration() is called, the duration of interval timer * that just expired. The value zero means that no timer was active. @@ -133,11 +133,11 @@ static struct timespec g_sched_time; static struct timespec g_stop_time; #endif -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_process_scheduler * * Description: @@ -159,7 +159,7 @@ static struct timespec g_stop_time; * that a context switch is needed now, but cannot be performed because * noswitches == true. * - ************************************************************************/ + ****************************************************************************/ #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) @@ -368,9 +368,9 @@ static void sched_timer_start(unsigned int ticks) } } -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: sched_alarm_expiration diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 6ac0ad49ab..81b75f0af0 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_unlock.c * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,11 +44,11 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sched_unlock * * Description: @@ -59,7 +59,7 @@ * decremented to zero, any tasks that were eligible to preempt the * current task will execute. * - ************************************************************************/ + ****************************************************************************/ int sched_unlock(void) { diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index c612f85edb..13241bf780 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -274,7 +274,7 @@ errout: return ERROR; } -/*************************************************************************** +/**************************************************************************** * * If CONFIG_SCHED_HAVE_PARENT is defined, then waitpid will use the SIGHCLD * signal. It can also handle the pid == (pid_t)-1 arguement. This is @@ -285,7 +285,7 @@ errout: * lost (or to have the data in the struct siginfo to be overwritten by * the next signal). * - ***************************************************************************/ + ****************************************************************************/ #else pid_t waitpid(pid_t pid, int *stat_loc, int options) diff --git a/sched/signal/sig_allocatependingsigaction.c b/sched/signal/sig_allocatependingsigaction.c index 55f7727cda..12e65093c5 100644 --- a/sched/signal/sig_allocatependingsigaction.c +++ b/sched/signal/sig_allocatependingsigaction.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_allocatependingsigaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,37 +45,37 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_allocatependingsigaction * * Description: * Allocate a new element for the pending signal action queue * - ************************************************************************/ + ****************************************************************************/ FAR sigq_t *sig_allocatependingsigaction(void) { diff --git a/sched/signal/sig_cleanup.c b/sched/signal/sig_cleanup.c index c0ce3a10d0..862defa546 100644 --- a/sched/signal/sig_cleanup.c +++ b/sched/signal/sig_cleanup.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_cleanup.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,42 +31,42 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_cleanup * * Description: @@ -74,7 +74,7 @@ * called only at task deletion time. The caller is expected to have * assured the critical section necessary to perform this action. * - ************************************************************************/ + ****************************************************************************/ void sig_cleanup(FAR struct tcb_s *stcb) { @@ -108,7 +108,7 @@ void sig_cleanup(FAR struct tcb_s *stcb) stcb->sigwaitmask = NULL_SIGNAL_SET; } -/************************************************************************ +/**************************************************************************** * Name: sig_release * * Description: @@ -117,7 +117,7 @@ void sig_cleanup(FAR struct tcb_s *stcb) * expected to have assured the critical section necessary to perform * this action. * - ************************************************************************/ + ****************************************************************************/ void sig_release(FAR struct task_group_s *group) { diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index 21062ff102..32616bfd3d 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_findaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,46 +31,46 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_findaction * * Description: * Allocate a new element for a signal queue * - ************************************************************************/ + ****************************************************************************/ FAR sigactq_t *sig_findaction(FAR struct tcb_s *stcb, int signo) { diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index ef217e92d6..bcdbc23020 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_initialize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -45,17 +45,17 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ /* The g_sigfreeaction data structure is a list of available signal * action structures. @@ -88,9 +88,9 @@ sq_queue_t g_sigpendingsignal; sq_queue_t g_sigpendingirqsignal; -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ /* g_sigactionalloc is a pointer to the start of the allocated blocks of * signal actions. @@ -122,27 +122,27 @@ static sigpendq_t *g_sigpendingsignalalloc; static sigpendq_t *g_sigpendingirqsignalalloc; -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype); static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype); -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_allocateblock * * Description: * Allocate a block of pending signal actions and place them * on the free list. * - ************************************************************************/ + ****************************************************************************/ static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype) @@ -165,14 +165,14 @@ static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, return sigqalloc; } -/************************************************************************ +/**************************************************************************** * Name: sig_allocatependingsignalblock * * Description: * Allocate a block of pending signal structures and place them on * the free list. * - ************************************************************************/ + ****************************************************************************/ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype) @@ -196,17 +196,17 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, return sigpendalloc; } -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_initialize * * Description: * Perform one-time power-up initialization * - ************************************************************************/ + ****************************************************************************/ void sig_initialize(void) { @@ -243,14 +243,14 @@ void sig_initialize(void) SIG_ALLOC_IRQ); } -/************************************************************************ +/**************************************************************************** * Name: sig_allocateactionblock * * Description: * Allocate a block of signal actions and place them * on the free list. * - ************************************************************************/ + ****************************************************************************/ void sig_allocateactionblock(void) { diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index b0ef01dacb..08416f3a3e 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_kill.c * * Copyright (C) 2007, 2009, 2011, 2013, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -47,11 +47,11 @@ #include "sched/sched.h" #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: kill * * Description: @@ -80,7 +80,7 @@ * * Assumptions: * - ************************************************************************/ + ****************************************************************************/ int kill(pid_t pid, int signo) { diff --git a/sched/signal/sig_lowest.c b/sched/signal/sig_lowest.c index 76f2d04c04..9f8b6d5179 100644 --- a/sched/signal/sig_lowest.c +++ b/sched/signal/sig_lowest.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_lowest.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,37 +43,37 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_lowest * * Description: * Return the lowest signal number that is a member of a set of signals. * - ************************************************************************/ + ****************************************************************************/ int sig_lowest(sigset_t *set) { diff --git a/sched/signal/sig_releasependingsigaction.c b/sched/signal/sig_releasependingsigaction.c index b7d80d1c2e..688af823dd 100644 --- a/sched/signal/sig_releasependingsigaction.c +++ b/sched/signal/sig_releasependingsigaction.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_releasependingsigaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,37 +43,37 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_releasependingsigaction * * Description: * Deallocate a pending signal action Q entry * - ************************************************************************/ + ****************************************************************************/ void sig_releasependingsigaction(FAR sigq_t *sigq) { diff --git a/sched/signal/sig_releasependingsignal.c b/sched/signal/sig_releasependingsignal.c index 88ec8297a7..a6090850c0 100644 --- a/sched/signal/sig_releasependingsignal.c +++ b/sched/signal/sig_releasependingsignal.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_releasependingsignal.c * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -52,37 +52,37 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_releasependingsignal * * Description: * Deallocate a pending signal list entry * - ************************************************************************/ + ****************************************************************************/ void sig_releasependingsignal(FAR sigpendq_t *sigpend) { diff --git a/sched/signal/sig_removependingsignal.c b/sched/signal/sig_removependingsignal.c index 299babbc39..e8fdac9112 100644 --- a/sched/signal/sig_removependingsignal.c +++ b/sched/signal/sig_removependingsignal.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_removependingsignal.c * * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -52,37 +52,37 @@ #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_removependingsignal * * Description: * Remove the specified signal from the signal pending list * - ************************************************************************/ + ****************************************************************************/ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) { diff --git a/sched/signal/sig_unmaskpendingsignal.c b/sched/signal/sig_unmaskpendingsignal.c index 01bf2403e1..a6df2fa19a 100644 --- a/sched/signal/sig_unmaskpendingsignal.c +++ b/sched/signal/sig_unmaskpendingsignal.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/signal/sig_unmaskpendingsignal.c * * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -44,31 +44,31 @@ #include "sched/sched.h" #include "signal/signal.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: sig_unmaskpendingsignal * * Description: @@ -76,7 +76,7 @@ * unmasks and processes any pending signals. This function should * be called whenever the sigprocmask is changed. * - ************************************************************************/ + ****************************************************************************/ void sig_unmaskpendingsignal(void) { diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index 058fd70892..e1400d6bfd 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/task/task_getpid.c * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include #include @@ -44,37 +44,37 @@ #include "sched/sched.h" #include "task/task.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: getpid * * Description: * Get the task ID of the currently executing task. * - ************************************************************************/ + ****************************************************************************/ pid_t getpid(void) { diff --git a/sched/task/task_prctl.c b/sched/task/task_prctl.c index 5bbac6b9f9..b89c578709 100644 --- a/sched/task/task_prctl.c +++ b/sched/task/task_prctl.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/task/task_prctl.c * * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -50,13 +50,13 @@ #include "sched/sched.h" #include "task/task.h" -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: prctl diff --git a/sched/wdog/wd_initialize.c b/sched/wdog/wd_initialize.c index bd3f9644c1..b745c19b66 100644 --- a/sched/wdog/wd_initialize.c +++ b/sched/wdog/wd_initialize.c @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/wdog/wd_initialize.c * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -43,17 +43,17 @@ #include "wdog/wdog.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ /* The g_wdfreelist data structure is a singly linked list of watchdogs * available to the system for delayed function use. @@ -75,9 +75,9 @@ sq_queue_t g_wdactivelist; uint16_t g_wdnfree; -/************************************************************************ +/**************************************************************************** * Private Data - ************************************************************************/ + ****************************************************************************/ /* g_wdpool is a list of pre-allocated watchdogs. The number of watchdogs * in the pool is a configuration item. @@ -85,15 +85,15 @@ uint16_t g_wdnfree; static struct wdog_s g_wdpool[CONFIG_PREALLOC_WDOGS]; -/************************************************************************ +/**************************************************************************** * Private Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: wd_initialize * * Description: @@ -110,7 +110,7 @@ static struct wdog_s g_wdpool[CONFIG_PREALLOC_WDOGS]; * before the timer interrupt is attached and before any watchdog * services are used. * - ************************************************************************/ + ****************************************************************************/ void wd_initialize(void) { -- GitLab From 0f90500f724d03a2afa9ad2a3a3e40ed5a1677d0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Oct 2015 17:48:24 -0600 Subject: [PATCH 186/858] Standardize the width of all comment boxes in header files --- arch | 2 +- binfmt/binfmt_internal.h | 4 ++-- configs | 2 +- drivers/wireless/cc3000/cc3000drv.h | 2 +- include/errno.h | 20 ++++++++++---------- include/fixedmath.h | 12 ++++++------ include/nuttx/arch.h | 10 +++++----- include/nuttx/binfmt/nxflat.h | 4 ++-- include/nuttx/board.h | 2 +- include/nuttx/mqueue.h | 4 ++-- include/nuttx/poff.h | 16 ++++++++-------- include/nuttx/rwbuffer.h | 20 ++++++++++---------- include/nuttx/sercomm/msgb.h | 20 ++++++++++---------- include/nuttx/usb/composite.h | 2 +- include/nuttx/video/fb.h | 2 +- include/sys/sendfile.h | 4 ++-- sched/wdog/wdog.h | 28 ++++++++++++++-------------- 17 files changed, 77 insertions(+), 77 deletions(-) diff --git a/arch b/arch index 6a1d7e2d00..277302f14a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6a1d7e2d00220168220fd511937fe3680f3627ef +Subproject commit 277302f14a5869aa14c705b2a928488961fd97de diff --git a/binfmt/binfmt_internal.h b/binfmt/binfmt_internal.h index 184263183c..11b036fe74 100644 --- a/binfmt/binfmt_internal.h +++ b/binfmt/binfmt_internal.h @@ -68,9 +68,9 @@ extern "C" EXTERN FAR struct binfmt_s *g_binfmts; -/*********************************************************************** +/**************************************************************************** * Public Function Prototypes - ***********************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: dump_module diff --git a/configs b/configs index 35414c3a91..55aaa32ed3 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 35414c3a91d471276c7ff7ddc2ef8ba8a47aa9cd +Subproject commit 55aaa32ed3d637d86ccbd538fc75203cd123d485 diff --git a/drivers/wireless/cc3000/cc3000drv.h b/drivers/wireless/cc3000/cc3000drv.h index f23eaf164a..7c8af0e9b7 100644 --- a/drivers/wireless/cc3000/cc3000drv.h +++ b/drivers/wireless/cc3000/cc3000drv.h @@ -1,4 +1,4 @@ -/************************************************************************** +/**************************************************************************** * drivers/wireless/cc3000/cc3000drv.h - Driver wrapper functions to * connect nuttx to the TI CC3000 * diff --git a/include/errno.h b/include/errno.h index f215269c73..d6d4ec8e19 100644 --- a/include/errno.h +++ b/include/errno.h @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * include/errno.h * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. @@ -31,20 +31,20 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_ERRNO_H #define __INCLUDE_ERRNO_H -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ /* How can we access the errno variable? */ #if !defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL) @@ -378,13 +378,13 @@ #define ECANCELED 125 #define ECANCELED_STR "Operation cancelled" -/************************************************************************ +/**************************************************************************** * Public Type Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Function Prototypes - ************************************************************************/ + ****************************************************************************/ #undef EXTERN #if defined(__cplusplus) diff --git a/include/fixedmath.h b/include/fixedmath.h index 38a991136b..665179c427 100644 --- a/include/fixedmath.h +++ b/include/fixedmath.h @@ -42,9 +42,9 @@ #include -/************************************************************************** +/**************************************************************************** * Pre-processor Definitions - **************************************************************************/ + ****************************************************************************/ /* Common numbers */ @@ -191,9 +191,9 @@ # define ub16divub16(a,b) (ub16_t)(ub16toub32(a)/(ub32_t)(b)) #endif -/************************************************************************** +/**************************************************************************** * Public Types - **************************************************************************/ + ****************************************************************************/ typedef int16_t b8_t; typedef uint16_t ub8_t; @@ -204,9 +204,9 @@ typedef int64_t b32_t; typedef uint64_t ub32_t; #endif -/************************************************************************** +/**************************************************************************** * Public Functions - **************************************************************************/ + ****************************************************************************/ #undef EXTERN #if defined(__cplusplus) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 950e4ae0f9..4c070a7d1a 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1604,7 +1604,7 @@ char up_romgetc(FAR const char *ptr); * Some device drivers may require that the plaform-specific logic * provide these timing loops for short delays. * - ***************************************************************************/ + ****************************************************************************/ void up_mdelay(unsigned int milliseconds); void up_udelay(useconds_t microseconds); @@ -1623,7 +1623,7 @@ void up_udelay(useconds_t microseconds); * definition only provides the 'contract' between application * specific C++ code and platform-specific toolchain support * - ***************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) void up_cxxinitialize(void); @@ -1698,7 +1698,7 @@ void sched_timer_expiration(void); void sched_alarm_expiration(FAR const struct timespec *ts); #endif -/************************************************************************ +/**************************************************************************** * Name: sched_process_cpuload * * Description: @@ -1714,7 +1714,7 @@ void sched_alarm_expiration(FAR const struct timespec *ts); * This function is called from a timer interrupt handler with all * interrupts disabled. * - ************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_SCHED_CPULOAD) && defined(CONFIG_SCHED_CPULOAD_EXTCLK) void weak_function sched_process_cpuload(void); @@ -1728,7 +1728,7 @@ void weak_function sched_process_cpuload(void); * order to dispatch an interrupt to the appropriate, registered handling * logic. * - ***************************************************************************/ + ****************************************************************************/ void irq_dispatch(int irq, FAR void *context); diff --git a/include/nuttx/binfmt/nxflat.h b/include/nuttx/binfmt/nxflat.h index eb039f40a1..31b173209e 100644 --- a/include/nuttx/binfmt/nxflat.h +++ b/include/nuttx/binfmt/nxflat.h @@ -249,7 +249,7 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo); /**************************************************************************** * These are APIs used internally only by NuttX: ****************************************************************************/ -/*********************************************************************** +/**************************************************************************** * Name: nxflat_initialize * * Description: @@ -262,7 +262,7 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo); * 0 (OK) is returned on success and a negated errno is returned on * failure. * - ***********************************************************************/ + ****************************************************************************/ int nxflat_initialize(void); diff --git a/include/nuttx/board.h b/include/nuttx/board.h index d482591584..6a22d515af 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -351,7 +351,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg); * multiple LCD devices. * board_lcd_uninitialize - Uninitialize the LCD support * - ***************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_LCD struct lcd_dev_s; /* Forward reference */ diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 612d2488d1..68f7b1b2bf 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -112,7 +112,7 @@ extern "C" #define EXTERN extern #endif -/************************************************************************ +/**************************************************************************** * Name: mq_msgqfree * * Description: @@ -128,7 +128,7 @@ extern "C" * Return Value: * None * - ************************************************************************/ + ****************************************************************************/ void mq_msgqfree(FAR struct mqueue_inode_s *msgq); diff --git a/include/nuttx/poff.h b/include/nuttx/poff.h index 05349e53a8..cda48805e4 100644 --- a/include/nuttx/poff.h +++ b/include/nuttx/poff.h @@ -1,4 +1,4 @@ -/*************************************************************************** +/**************************************************************************** * include/nuttx/poff.h * Definitions for the P-Code Object File Format (POFF) * @@ -32,21 +32,21 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_NUXX_POFF_H #define __INCLUDE_NUXX_POFF_H -/*************************************************************************** +/**************************************************************************** * Included Files - ***************************************************************************/ + ****************************************************************************/ #include #include -/*************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ***************************************************************************/ + ****************************************************************************/ /* Definitions for the fh_ident field of the poffHdr_t */ @@ -157,9 +157,9 @@ #define RLI_TYPE(x) ((x) & 0xff) /* Reloc type */ #define RLI_MAKE(s,t) (((uint32_t)(s) << 8) | ((t) & 0xff)) -/*************************************************************************** +/**************************************************************************** * Public Types - ***************************************************************************/ + ****************************************************************************/ /* POFF file header */ diff --git a/include/nuttx/rwbuffer.h b/include/nuttx/rwbuffer.h index 1f11cf47bc..c658117b68 100644 --- a/include/nuttx/rwbuffer.h +++ b/include/nuttx/rwbuffer.h @@ -36,9 +36,9 @@ #ifndef __INCLUDE_NUTTX_RWBUFFER_H #define __INCLUDE_NUTTX_RWBUFFER_H -/********************************************************************** +/**************************************************************************** * Included Files - **********************************************************************/ + ****************************************************************************/ #include @@ -49,13 +49,13 @@ #if defined(CONFIG_DRVR_WRITEBUFFER) || defined(CONFIG_DRVR_READAHEAD) -/********************************************************************** +/**************************************************************************** * Pre-processor Definitions - **********************************************************************/ + ****************************************************************************/ -/********************************************************************** +/**************************************************************************** * Public Types - **********************************************************************/ + ****************************************************************************/ /* Data transfer callouts. These must be provided by the block driver * logic in order to flush the write buffer when appropriate or to @@ -154,9 +154,9 @@ struct rwbuffer_s #endif }; -/********************************************************************** +/**************************************************************************** * Public Data - **********************************************************************/ + ****************************************************************************/ #undef EXTERN #if defined(__cplusplus) @@ -167,9 +167,9 @@ extern "C" #define EXTERN extern #endif -/********************************************************************** +/**************************************************************************** * Public Function Prototypes - **********************************************************************/ + ****************************************************************************/ /* Buffer initialization */ diff --git a/include/nuttx/sercomm/msgb.h b/include/nuttx/sercomm/msgb.h index 68005bbb46..39067c3ba3 100644 --- a/include/nuttx/sercomm/msgb.h +++ b/include/nuttx/sercomm/msgb.h @@ -1,4 +1,4 @@ -/************************************************************************** +/**************************************************************************** * (C) 2008-2010 by Harald Welte * * This source code is derivated from Osmocom-BB project and was @@ -31,21 +31,21 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_NUTTX_SERCOM_MSGB_H #define __INCLUDE_NUTTX_SERCOM_MSGB_H -/************************************************************************** +/**************************************************************************** * Included Files - **************************************************************************/ + ****************************************************************************/ #include #include -/************************************************************************** +/**************************************************************************** * Public Types - **************************************************************************/ + ****************************************************************************/ struct msgb { @@ -72,9 +72,9 @@ struct msgb unsigned char _data[0]; }; -/************************************************************************** +/**************************************************************************** * Public Function Prototypes - **************************************************************************/ + ****************************************************************************/ struct msgb *msgb_alloc(uint16_t size, const char *name); void msgb_free(struct msgb *m); @@ -82,9 +82,9 @@ void msgb_enqueue(struct llist_head *queue, struct msgb *msg); struct msgb *msgb_dequeue(struct llist_head *queue); void msgb_reset(struct msgb *m); -/************************************************************************** +/**************************************************************************** * Inline Functions - **************************************************************************/ + ****************************************************************************/ #define msgb_l1(m) ((void *)(m->l1h)) #define msgb_l2(m) ((void *)(m->l2h)) diff --git a/include/nuttx/usb/composite.h b/include/nuttx/usb/composite.h index 6b5fd8db8e..722f9c4667 100644 --- a/include/nuttx/usb/composite.h +++ b/include/nuttx/usb/composite.h @@ -131,7 +131,7 @@ FAR void *composite_initialize(void); * Returned Value: * None * - ***************************************************************************/ + ****************************************************************************/ void composite_uninitialize(FAR void *handle); diff --git a/include/nuttx/video/fb.h b/include/nuttx/video/fb.h index da41267719..4046fb546c 100644 --- a/include/nuttx/video/fb.h +++ b/include/nuttx/video/fb.h @@ -372,7 +372,7 @@ extern "C" * multiple planes of video. * up_fbuninitialize - Uninitialize the framebuffer support * - ***************************************************************************/ + ****************************************************************************/ int up_fbinitialize(void); FAR struct fb_vtable_s *up_fbgetvplane(int vplane); diff --git a/include/sys/sendfile.h b/include/sys/sendfile.h index 5db6ff70c3..22cb8271ef 100644 --- a/include/sys/sendfile.h +++ b/include/sys/sendfile.h @@ -70,7 +70,7 @@ extern "C" #define EXTERN extern #endif -/************************************************************************ +/**************************************************************************** * Name: sendfile * * Description: @@ -112,7 +112,7 @@ extern "C" * EINVAL - Bad input parameters. * ENOMEM - Could not allocated an I/O buffer * - ************************************************************************/ + ****************************************************************************/ ssize_t sendfile(int outfd, int infd, FAR off_t *offset, size_t count); diff --git a/sched/wdog/wdog.h b/sched/wdog/wdog.h index ccc7ac458c..e1cacf1fa5 100644 --- a/sched/wdog/wdog.h +++ b/sched/wdog/wdog.h @@ -1,4 +1,4 @@ -/************************************************************************ +/**************************************************************************** * sched/wdog/wdog.h * * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. @@ -31,14 +31,14 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ #ifndef __SCHED_WDOG_WDOG_H #define __SCHED_WDOG_WDOG_H -/************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ #include @@ -48,17 +48,17 @@ #include #include -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" @@ -88,11 +88,11 @@ extern sq_queue_t g_wdactivelist; extern uint16_t g_wdnfree; -/************************************************************************ +/**************************************************************************** * Public Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ +/**************************************************************************** * Name: wd_initialize * * Description: @@ -109,7 +109,7 @@ extern uint16_t g_wdnfree; * before the timer interrupt is attached and before any watchdog * services are used. * - ************************************************************************/ + ****************************************************************************/ void weak_function wd_initialize(void); -- GitLab From 16b32bbadd71201d99cd31f2b377de196376c812 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 3 Oct 2015 07:25:53 -0600 Subject: [PATCH 187/858] Standardize the width of all comment boxes in C files --- arch | 2 +- configs | 2 +- crypto/testmngr.c | 4 +- drivers/lcd/ili9341.c | 96 ++++++++++++------------- drivers/lcd/memlcd.c | 92 ++++++++++++------------ drivers/usbdev/usbdev_trace.c | 12 ++-- drivers/usbdev/usbdev_trprintf.c | 8 +-- drivers/usbhost/usbhost_devaddr.c | 50 ++++++------- drivers/usbhost/usbhost_enumerate.c | 56 +++++++-------- drivers/usbhost/usbhost_trace.c | 4 +- drivers/wireless/cc3000/cc3000_common.c | 28 ++++---- drivers/wireless/cc3000/cc3000drv.c | 46 ++++++------ drivers/wireless/cc3000/evnt_handler.c | 64 ++++++++--------- drivers/wireless/cc3000/hci.c | 32 ++++----- drivers/wireless/cc3000/netapp.c | 52 +++++++------- drivers/wireless/cc3000/nvmem.c | 44 ++++++------ drivers/wireless/cc3000/security.c | 32 ++++----- drivers/wireless/cc3000/socket.c | 72 +++++++++---------- drivers/wireless/cc3000/socket_imp.c | 86 +++++++++++----------- drivers/wireless/cc3000/wlan.c | 96 ++++++++++++------------- libc/stdlib/lib_bsearch.c | 16 ++--- libc/string/lib_strcasecmp.c | 6 +- libc/string/lib_strcmp.c | 6 +- libc/string/lib_strncasecmp.c | 8 +-- libc/string/lib_strncmp.c | 8 +-- sched/group/group_childstatus.c | 64 ++++++++--------- sched/group/group_create.c | 44 ++++++------ sched/group/group_find.c | 40 +++++------ sched/group/group_join.c | 40 +++++------ sched/group/group_killchildren.c | 4 +- sched/group/group_leave.c | 44 ++++++------ sched/group/group_signal.c | 36 +++++----- sched/pthread/pthread_getschedparam.c | 2 +- sched/sched/sched_wait.c | 20 +++--- sched/sched/sched_waitid.c | 24 +++---- sched/sched/sched_waitpid.c | 20 +++--- sched/task/task_getgroup.c | 36 +++++----- sched/task/task_reparent.c | 20 +++--- 38 files changed, 658 insertions(+), 658 deletions(-) diff --git a/arch b/arch index 277302f14a..5fa7ebb25b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 277302f14a5869aa14c705b2a928488961fd97de +Subproject commit 5fa7ebb25b9d0b3f58d987ec3255709fa70ef368 diff --git a/configs b/configs index 55aaa32ed3..d074eda220 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 55aaa32ed3d637d86ccbd538fc75203cd123d485 +Subproject commit d074eda220e892489e53a3cca49165619b18a607 diff --git a/crypto/testmngr.c b/crypto/testmngr.c index 4002a2d980..2dacdd0c42 100644 --- a/crypto/testmngr.c +++ b/crypto/testmngr.c @@ -54,9 +54,9 @@ #include "testmngr.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #ifndef ARRAY_SIZE # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/drivers/lcd/ili9341.c b/drivers/lcd/ili9341.c index d2039c2803..c5f58aae9b 100644 --- a/drivers/lcd/ili9341.c +++ b/drivers/lcd/ili9341.c @@ -1,4 +1,4 @@ -/****************************************************************************** +/**************************************************************************** * drivers/lcd/ili9341.c * * LCD driver for the ILI9341 LCD Single Chip Driver @@ -37,11 +37,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ******************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -58,9 +58,9 @@ #include -/****************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ /* * This is the generic lcd driver interface for the ili9341 Single Chip LCD @@ -383,9 +383,9 @@ # define lcdvdbg(x...) #endif -/****************************************************************************** +/**************************************************************************** * Private Type Definition - ******************************************************************************/ + ****************************************************************************/ /* * Each single connected ili9341 LCD driver needs an own driver instance @@ -436,9 +436,9 @@ struct ili9341_dev_s }; -/****************************************************************************** +/**************************************************************************** * Private Function Protototypes - ******************************************************************************/ + ****************************************************************************/ /* Internal low level helpers */ @@ -492,9 +492,9 @@ static int ili9341_setpower(struct lcd_dev_s *dev, int power); static int ili9341_getcontrast(struct lcd_dev_s *dev); static int ili9341_setcontrast(struct lcd_dev_s *dev, unsigned int contrast); -/****************************************************************************** +/**************************************************************************** * Private Data - ******************************************************************************/ + ****************************************************************************/ /* Initialize driver instance 1 < LCD_ILI9341_NINTERFACES */ @@ -537,11 +537,11 @@ static struct ili9341_dev_s g_lcddev[CONFIG_LCD_ILI9341_NINTERFACES] = #endif }; -/****************************************************************************** +/**************************************************************************** * Private Functions - ******************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Name: ili9341_getxres * * Description: @@ -555,7 +555,7 @@ static struct ili9341_dev_s g_lcddev[CONFIG_LCD_ILI9341_NINTERFACES] = * * Horicontal resolution * - ******************************************************************************/ + ****************************************************************************/ static inline uint16_t ili9341_getxres(FAR struct ili9341_dev_s *dev) { @@ -569,7 +569,7 @@ static inline uint16_t ili9341_getxres(FAR struct ili9341_dev_s *dev) } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getyres * * Description: @@ -583,7 +583,7 @@ static inline uint16_t ili9341_getxres(FAR struct ili9341_dev_s *dev) * * Vertical resolution * - ******************************************************************************/ + ****************************************************************************/ static inline uint16_t ili9341_getyres(FAR struct ili9341_dev_s *dev) { @@ -597,7 +597,7 @@ static inline uint16_t ili9341_getyres(FAR struct ili9341_dev_s *dev) } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_selectarea * * Description: @@ -610,7 +610,7 @@ static inline uint16_t ili9341_getyres(FAR struct ili9341_dev_s *dev) * x1 - End x position * y1 - End y position * - ******************************************************************************/ + ****************************************************************************/ static void ili9341_selectarea(FAR struct ili9341_lcd_s *lcd, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) @@ -633,7 +633,7 @@ static void ili9341_selectarea(FAR struct ili9341_lcd_s *lcd, } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_putrun * * Description: @@ -652,7 +652,7 @@ static void ili9341_selectarea(FAR struct ili9341_lcd_s *lcd, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_putrun(int devno, fb_coord_t row, fb_coord_t col, FAR const uint8_t * buffer, size_t npixels) @@ -693,7 +693,7 @@ static int ili9341_putrun(int devno, fb_coord_t row, fb_coord_t col, } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getrun * * Description: @@ -712,7 +712,7 @@ static int ili9341_putrun(int devno, fb_coord_t row, fb_coord_t col, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ # ifndef CONFIG_LCD_NOGETRUN static int ili9341_getrun(int devno, fb_coord_t row, fb_coord_t col, @@ -754,7 +754,7 @@ static int ili9341_getrun(int devno, fb_coord_t row, fb_coord_t col, } #endif -/******************************************************************************* +/**************************************************************************** * Name: ili9341_hwinitialize * * Description: @@ -768,7 +768,7 @@ static int ili9341_getrun(int devno, fb_coord_t row, fb_coord_t col, * On success - OK * On error - EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_hwinitialize(FAR struct ili9341_dev_s *dev) { @@ -846,11 +846,11 @@ static int ili9341_hwinitialize(FAR struct ili9341_dev_s *dev) } -/******************************************************************************* +/**************************************************************************** * Public Functions - ******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: ili9341_putrunx * * Description: @@ -868,7 +868,7 @@ static int ili9341_hwinitialize(FAR struct ili9341_dev_s *dev) * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_LCD_ILI9341_IFACE0 static int ili9341_putrun0(fb_coord_t row, fb_coord_t col, @@ -887,7 +887,7 @@ static int ili9341_putrun1(fb_coord_t row, fb_coord_t col, #endif -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getrunx * * Description: @@ -905,7 +905,7 @@ static int ili9341_putrun1(fb_coord_t row, fb_coord_t col, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_LCD_NOGETRUN # ifdef CONFIG_LCD_ILI9341_IFACE0 @@ -926,7 +926,7 @@ static int ili9341_getrun1(fb_coord_t row, fb_coord_t col, #endif -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getvideoinfo * * Description: @@ -941,7 +941,7 @@ static int ili9341_getrun1(fb_coord_t row, fb_coord_t col, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_getvideoinfo(FAR struct lcd_dev_s *dev, FAR struct fb_videoinfo_s *vinfo) @@ -964,7 +964,7 @@ static int ili9341_getvideoinfo(FAR struct lcd_dev_s *dev, return -EINVAL; } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getplaneinfo * * Description: @@ -980,7 +980,7 @@ static int ili9341_getvideoinfo(FAR struct lcd_dev_s *dev, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, FAR struct lcd_planeinfo_s *pinfo) @@ -1004,7 +1004,7 @@ static int ili9341_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, return -EINVAL; } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getpower * * Description: @@ -1019,7 +1019,7 @@ static int ili9341_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_getpower(FAR struct lcd_dev_s *dev) { @@ -1035,7 +1035,7 @@ static int ili9341_getpower(FAR struct lcd_dev_s *dev) return -EINVAL; } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_setpower * * Description: @@ -1051,7 +1051,7 @@ static int ili9341_getpower(FAR struct lcd_dev_s *dev) * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_setpower(FAR struct lcd_dev_s *dev, int power) { @@ -1092,7 +1092,7 @@ static int ili9341_setpower(FAR struct lcd_dev_s *dev, int power) return -EINVAL; } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_getcontrast * * Description: @@ -1106,7 +1106,7 @@ static int ili9341_setpower(FAR struct lcd_dev_s *dev, int power) * On success - current contrast value * On error - -ENOSYS, not supported by the ili9341. * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_getcontrast(struct lcd_dev_s *dev) { @@ -1114,7 +1114,7 @@ static int ili9341_getcontrast(struct lcd_dev_s *dev) return -ENOSYS; } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_setcontrast * * Description: @@ -1128,7 +1128,7 @@ static int ili9341_getcontrast(struct lcd_dev_s *dev) * On success - OK * On error - -ENOSYS, not supported by the ili9341. * - ******************************************************************************/ + ****************************************************************************/ static int ili9341_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) { @@ -1137,7 +1137,7 @@ static int ili9341_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) } -/******************************************************************************* +/**************************************************************************** * Name: ili9341_initialize * * Description: @@ -1158,7 +1158,7 @@ static int ili9341_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) * On success, this function returns a reference to the LCD driver object for * the specified LCD driver. NULL is returned on any failure. * - ******************************************************************************/ + ****************************************************************************/ FAR struct lcd_dev_s *ili9341_initialize( FAR struct ili9341_lcd_s *lcd, int devno) @@ -1201,7 +1201,7 @@ FAR struct lcd_dev_s *ili9341_initialize( } -/****************************************************************************** +/**************************************************************************** * Name: ili9341_clear * * Description: @@ -1219,7 +1219,7 @@ FAR struct lcd_dev_s *ili9341_initialize( * On success - OK * On error - -EINVAL * - ******************************************************************************/ + ****************************************************************************/ int ili9341_clear(FAR struct lcd_dev_s *dev, uint16_t color) { diff --git a/drivers/lcd/memlcd.c b/drivers/lcd/memlcd.c index 578c30a1c3..4046f882b5 100644 --- a/drivers/lcd/memlcd.c +++ b/drivers/lcd/memlcd.c @@ -1,4 +1,4 @@ -/****************************************************************************** +/**************************************************************************** * drivers/lcd/memlcd.c * Driver for Sharp Memory LCD. * @@ -33,11 +33,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ******************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -55,9 +55,9 @@ #include -/****************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ /* Configuration */ @@ -119,9 +119,9 @@ # define lcdvdbg(x...) #endif -/****************************************************************************** +/**************************************************************************** * Private Type Definition - ******************************************************************************/ + ****************************************************************************/ struct memlcd_dev_s { @@ -144,9 +144,9 @@ struct memlcd_dev_s uint8_t fb[MEMLCD_FBSIZE]; }; -/****************************************************************************** +/**************************************************************************** * Private Function Protototypes - ******************************************************************************/ + ****************************************************************************/ /* Low-level spi helpers */ @@ -180,9 +180,9 @@ static int memlcd_setpower(struct lcd_dev_s *dev, int power); static int memlcd_getcontrast(struct lcd_dev_s *dev); static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast); -/****************************************************************************** +/**************************************************************************** * Private Data - ******************************************************************************/ + ****************************************************************************/ static uint8_t g_runbuffer[MEMLCD_BPP * MEMLCD_XRES / 8]; @@ -226,11 +226,11 @@ static struct memlcd_dev_s g_memlcddev = }, }; -/****************************************************************************** +/**************************************************************************** * Private Functions - ******************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * __set_bit - Set a bit in memory * * @nr: the bit to set @@ -240,7 +240,7 @@ static struct memlcd_dev_s g_memlcddev = * If it's called on the same region of memory simultaneously, the effect * may be that only one operation succeeds. * - ******************************************************************************/ + ****************************************************************************/ #define BIT(nr) (1 << (nr)) #define BITS_PER_BYTE 8 @@ -266,7 +266,7 @@ static inline int __test_bit(int nr, const volatile uint8_t * addr) return 1 & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE - 1))); } -/****************************************************************************** +/**************************************************************************** * Name: memlcd_configspi * * Description: @@ -280,7 +280,7 @@ static inline int __test_bit(int nr, const volatile uint8_t * addr) * * Assumptions: * - ******************************************************************************/ + ****************************************************************************/ static inline void memlcd_configspi(FAR struct spi_dev_s *spi) { @@ -307,7 +307,7 @@ static inline void memlcd_configspi(FAR struct spi_dev_s *spi) #endif } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_select * * Description: @@ -321,7 +321,7 @@ static inline void memlcd_configspi(FAR struct spi_dev_s *spi) * * Assumptions: * - ******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_SPI_OWNBUS static inline void memlcd_select(FAR struct spi_dev_s *spi) @@ -354,7 +354,7 @@ static void memlcd_select(FAR struct spi_dev_s *spi) } #endif -/******************************************************************************* +/**************************************************************************** * Name: memlcd_deselect * * Description: @@ -368,7 +368,7 @@ static void memlcd_select(FAR struct spi_dev_s *spi) * * Assumptions: * - ******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_SPI_OWNBUS static inline void memlcd_deselect(FAR struct spi_dev_s *spi) @@ -385,7 +385,7 @@ static void memlcd_deselect(FAR struct spi_dev_s *spi) } #endif -/******************************************************************************* +/**************************************************************************** * Name: memlcd_clear * * Description: @@ -396,7 +396,7 @@ static void memlcd_deselect(FAR struct spi_dev_s *spi) * * Assumptions: * - ******************************************************************************/ + ****************************************************************************/ static inline void memlcd_clear(FAR struct memlcd_dev_s *mlcd) { @@ -409,7 +409,7 @@ static inline void memlcd_clear(FAR struct memlcd_dev_s *mlcd) memlcd_deselect(mlcd->spi); } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_extcominisr * * Description: @@ -427,7 +427,7 @@ static inline void memlcd_clear(FAR struct memlcd_dev_s *mlcd) * Assumptions: * Board specific logic needs to be provided to support it. * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_extcominisr(int irq, FAR void *context) { @@ -445,7 +445,7 @@ static int memlcd_extcominisr(int irq, FAR void *context) return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_putrun * * Description: @@ -458,7 +458,7 @@ static int memlcd_extcominisr(int irq, FAR void *context) * npixels - The number of pixels to write to the LCD * (range: 0 < npixels <= xres-col) * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t * buffer, size_t npixels) @@ -538,7 +538,7 @@ static int memlcd_putrun(fb_coord_t row, fb_coord_t col, return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_getrun * * Description: @@ -550,7 +550,7 @@ static int memlcd_putrun(fb_coord_t row, fb_coord_t col, * npixels - The number of pixels to read from the LCD * (range: 0 < npixels <= xres-col) * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t * buffer, size_t npixels) @@ -609,13 +609,13 @@ static int memlcd_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t * buffer, return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_getvideoinfo * * Description: * Get information about the LCD video controller configuration. * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_getvideoinfo(FAR struct lcd_dev_s *dev, FAR struct fb_videoinfo_s *vinfo) { @@ -627,13 +627,13 @@ static int memlcd_getvideoinfo(FAR struct lcd_dev_s *dev, return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_getplaneinfo * * Description: * Get information about the configuration of each LCD color plane. * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, FAR struct lcd_planeinfo_s *pinfo) @@ -644,14 +644,14 @@ static int memlcd_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_getpower * * Description: * Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER: full on. * On backlit LCDs, this setting may correspond to the backlight setting. * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_getpower(FAR struct lcd_dev_s *dev) { @@ -661,14 +661,14 @@ static int memlcd_getpower(FAR struct lcd_dev_s *dev) return mlcd->power; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_setpower * * Description: * Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER: full on). * On backlit LCDs, this setting may correspond to the backlight setting. * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_setpower(FAR struct lcd_dev_s *dev, int power) { @@ -690,13 +690,13 @@ static int memlcd_setpower(FAR struct lcd_dev_s *dev, int power) return OK; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_getcontrast * * Description: * Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST). * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_getcontrast(struct lcd_dev_s *dev) { @@ -706,13 +706,13 @@ static int memlcd_getcontrast(struct lcd_dev_s *dev) return mlcd->contrast; } -/******************************************************************************* +/**************************************************************************** * Name: memlcd_setcontrast * * Description: * Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST). * - ******************************************************************************/ + ****************************************************************************/ static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) { @@ -734,11 +734,11 @@ static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) return OK; } -/******************************************************************************* +/**************************************************************************** * Public Functions - ******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: memlcd_initialize * * Description: @@ -757,7 +757,7 @@ static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) * On success, this function returns a reference to the LCD object for * the specified LCD. NULL is returned on any failure. * - ******************************************************************************/ + ****************************************************************************/ FAR struct lcd_dev_s *memlcd_initialize(FAR struct spi_dev_s *spi, FAR struct memlcd_priv_s *priv, unsigned int devno) diff --git a/drivers/usbdev/usbdev_trace.c b/drivers/usbdev/usbdev_trace.c index 24f18fe5cd..b7f00e93fb 100644 --- a/drivers/usbdev/usbdev_trace.c +++ b/drivers/usbdev/usbdev_trace.c @@ -113,7 +113,7 @@ static int usbtrace_syslog(const char *fmt, ...) * Public Functions ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_enable * * Description: @@ -129,7 +129,7 @@ static int usbtrace_syslog(const char *fmt, ...) * Assumptions: * - May be called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_USBDEV_TRACE) || \ (defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_USB)) @@ -148,7 +148,7 @@ usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset) } #endif /* CONFIG_USBDEV_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace * * Description: @@ -157,7 +157,7 @@ usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset) * Assumptions: * May be called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_USBDEV_TRACE) || (defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_USB)) void usbtrace(uint16_t event, uint16_t value) @@ -200,7 +200,7 @@ void usbtrace(uint16_t event, uint16_t value) } #endif /* CONFIG_USBDEV_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_enumerate * * Description: @@ -209,7 +209,7 @@ void usbtrace(uint16_t event, uint16_t value) * Assumptions: * NEVER called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_USBDEV_TRACE int usbtrace_enumerate(trace_callback_t callback, void *arg) diff --git a/drivers/usbdev/usbdev_trprintf.c b/drivers/usbdev/usbdev_trprintf.c index 7616a15d7c..58b4c57d61 100644 --- a/drivers/usbdev/usbdev_trprintf.c +++ b/drivers/usbdev/usbdev_trprintf.c @@ -65,13 +65,13 @@ * Private Functions ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: get_trstring * * Description: * Search the driver string data to find the string matching the provided ID. * - *******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_USBDEV_TRACE_STRINGS static FAR const char *get_trstring(FAR const struct trace_msg_t *array, @@ -95,13 +95,13 @@ static FAR const char *get_trstring(FAR const struct trace_msg_t *array, * Public Functions ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_trprintf * * Description: * Print the trace record using the supplied printing function * - *******************************************************************************/ + ****************************************************************************/ void usbtrace_trprintf(trprintf_t trprintf, uint16_t event, uint16_t value) { diff --git a/drivers/usbhost/usbhost_devaddr.c b/drivers/usbhost/usbhost_devaddr.c index 578e2ea684..83392d0ed4 100644 --- a/drivers/usbhost/usbhost_devaddr.c +++ b/drivers/usbhost/usbhost_devaddr.c @@ -1,4 +1,4 @@ -/******************************************************************************* +/**************************************************************************** * drivers/usbhost/usbhost_devaddr.c * Manage USB device addresses * @@ -32,11 +32,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Included Files - *******************************************************************************/ + ****************************************************************************/ #include @@ -48,13 +48,13 @@ #include #include -/******************************************************************************* +/**************************************************************************** * Pre-processor Definitions - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Private Functions - *******************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: usbhost_takesem and usbhost_givesem @@ -63,7 +63,7 @@ * This is just a wrapper to handle the annoying behavior of semaphore * waits that return due to the receipt of a signal. * - *******************************************************************************/ + ****************************************************************************/ static void usbhost_takesem(FAR struct usbhost_devaddr_s *devgen) { @@ -81,7 +81,7 @@ static void usbhost_takesem(FAR struct usbhost_devaddr_s *devgen) #define usbhost_givesem(devgen) sem_post(&devgen->exclsem) -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_allocate * * Description: @@ -90,7 +90,7 @@ static void usbhost_takesem(FAR struct usbhost_devaddr_s *devgen) * Assumptions: * Caller hold the exclsem * - *******************************************************************************/ + ****************************************************************************/ static int usbhost_devaddr_allocate(FAR struct usbhost_devaddr_s *devgen) { @@ -140,7 +140,7 @@ static int usbhost_devaddr_allocate(FAR struct usbhost_devaddr_s *devgen) } } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_free * * Description: @@ -149,7 +149,7 @@ static int usbhost_devaddr_allocate(FAR struct usbhost_devaddr_s *devgen) * Assumptions: * Caller hold the exclsem * - *******************************************************************************/ + ****************************************************************************/ static void usbhost_devaddr_free(FAR struct usbhost_devaddr_s *devgen, uint8_t devaddr) @@ -173,13 +173,13 @@ static void usbhost_devaddr_free(FAR struct usbhost_devaddr_s *devgen, } } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_roothubport * * Description: * Find and return a reference the root hub port. * - *******************************************************************************/ + ****************************************************************************/ static inline FAR struct usbhost_roothubport_s * usbhost_roothubport(FAR struct usbhost_hubport_s *hport) @@ -203,14 +203,14 @@ usbhost_roothubport(FAR struct usbhost_hubport_s *hport) return (FAR struct usbhost_roothubport_s *)hport; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_gen * * Description: * Find root hub port and return a reference to the device function address * data set. * - *******************************************************************************/ + ****************************************************************************/ static FAR struct usbhost_devaddr_s * usbhost_devaddr_gen(FAR struct usbhost_hubport_s *hport) @@ -226,11 +226,11 @@ usbhost_devaddr_gen(FAR struct usbhost_hubport_s *hport) return NULL; } -/******************************************************************************* +/**************************************************************************** * Public Functions - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_initialize * * Description: @@ -244,7 +244,7 @@ usbhost_devaddr_gen(FAR struct usbhost_hubport_s *hport) * Returned Value: * None * - *******************************************************************************/ + ****************************************************************************/ void usbhost_devaddr_initialize(FAR struct usbhost_roothubport_s *rhport) { @@ -258,7 +258,7 @@ void usbhost_devaddr_initialize(FAR struct usbhost_roothubport_s *rhport) devgen->next = 1; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_create * * Description: @@ -272,7 +272,7 @@ void usbhost_devaddr_initialize(FAR struct usbhost_roothubport_s *rhport) * On success, a new device function address in the the range 0x01 to 0x7f * is returned. On failure, a negated errno value is returned. * - *******************************************************************************/ + ****************************************************************************/ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport) { @@ -302,7 +302,7 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport) return devaddr; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_destroy * * Description: @@ -316,7 +316,7 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport) * Returned Value: * None * - *******************************************************************************/ + ****************************************************************************/ void usbhost_devaddr_destroy(FAR struct usbhost_hubport_s *hport, uint8_t devaddr) { diff --git a/drivers/usbhost/usbhost_enumerate.c b/drivers/usbhost/usbhost_enumerate.c index 8f60e5c085..647d0ab7a9 100644 --- a/drivers/usbhost/usbhost_enumerate.c +++ b/drivers/usbhost/usbhost_enumerate.c @@ -1,4 +1,4 @@ -/******************************************************************************* +/**************************************************************************** * drivers/usbhost/usbhost_enumerate.c * * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Included Files - *******************************************************************************/ + ****************************************************************************/ #include @@ -53,17 +53,17 @@ #include #include -/******************************************************************************* +/**************************************************************************** * Pre-processor Definitions - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Private Types - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Private Function Prototypes - *******************************************************************************/ + ****************************************************************************/ static inline uint16_t usbhost_getle16(const uint8_t *val); static void usbhost_putle16(uint8_t *dest, uint16_t val); @@ -77,17 +77,17 @@ static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport, FAR struct usbhost_id_s *id, FAR struct usbhost_class_s **devclass); -/******************************************************************************* +/**************************************************************************** * Private Data - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Public Data - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Private Functions - *******************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: usbhost_getle16 @@ -95,7 +95,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport, * Description: * Get a (possibly unaligned) 16-bit little endian value. * - *******************************************************************************/ + ****************************************************************************/ static inline uint16_t usbhost_getle16(const uint8_t *val) { @@ -108,7 +108,7 @@ static inline uint16_t usbhost_getle16(const uint8_t *val) * Description: * Put a (possibly unaligned) 16-bit little endian value. * - *******************************************************************************/ + ****************************************************************************/ static void usbhost_putle16(uint8_t *dest, uint16_t val) { @@ -116,14 +116,14 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val) dest[1] = val >> 8; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devdesc * * Description: * A configuration descriptor has been obtained from the device. Find the * ID information for the class that supports this device. * - *******************************************************************************/ + ****************************************************************************/ static inline int usbhost_devdesc(FAR const struct usb_devdesc_s *devdesc, FAR struct usbhost_id_s *id) @@ -148,14 +148,14 @@ static inline int usbhost_devdesc(FAR const struct usb_devdesc_s *devdesc, return OK; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_configdesc * * Description: * A configuration descriptor has been obtained from the device. Find the * ID information for the class that supports this device. * - *******************************************************************************/ + ****************************************************************************/ static inline int usbhost_configdesc(const uint8_t *configdesc, int cfglen, struct usbhost_id_s *id) @@ -214,14 +214,14 @@ static inline int usbhost_configdesc(const uint8_t *configdesc, int cfglen, return -ENOENT; } -/******************************************************************************* +/**************************************************************************** * Name: usbhost_classbind * * Description: * A configuration descriptor has been obtained from the device. Try to * bind this configuration descriptor with a supported class. * - *******************************************************************************/ + ****************************************************************************/ static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport, const uint8_t *configdesc, int desclen, @@ -270,11 +270,11 @@ static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport, return ret; } -/******************************************************************************* +/**************************************************************************** * Public Functions - *******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: usbhost_enumerate * * Description: @@ -302,7 +302,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport, * - Called from a single thread so no mutual exclusion is required. * - Never called from an interrupt handler. * - *******************************************************************************/ + ****************************************************************************/ int usbhost_enumerate(FAR struct usbhost_hubport_s *hport, FAR struct usbhost_class_s **devclass) diff --git a/drivers/usbhost/usbhost_trace.c b/drivers/usbhost/usbhost_trace.c index e99261b50e..20a30a0c34 100644 --- a/drivers/usbhost/usbhost_trace.c +++ b/drivers/usbhost/usbhost_trace.c @@ -230,7 +230,7 @@ void usbhost_trace2(uint16_t id, uint8_t u7, uint16_t u16) #endif /* CONFIG_USBHOST_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_enumerate * * Description: @@ -239,7 +239,7 @@ void usbhost_trace2(uint16_t id, uint8_t u7, uint16_t u16) * Assumptions: * NEVER called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_USBHOST_TRACE int usbhost_trenumerate(usbhost_trcallback_t callback, FAR void *arg) diff --git a/drivers/wireless/cc3000/cc3000_common.c b/drivers/wireless/cc3000/cc3000_common.c index b23ea46bb6..bda6508308 100644 --- a/drivers/wireless/cc3000/cc3000_common.c +++ b/drivers/wireless/cc3000/cc3000_common.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * cc3000_common.c.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,15 +30,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ -/****************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Included files - *****************************************************************************/ + ****************************************************************************/ #include #include -/***************************************************************************** +/**************************************************************************** * Name:__error__ * * Description: @@ -51,9 +51,9 @@ * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: UINT32_TO_STREAM_f * * Description: @@ -67,7 +67,7 @@ * Returned Value: * Pointer to the new stream * - *****************************************************************************/ + ****************************************************************************/ uint8_t *UINT32_TO_STREAM_f(uint8_t *p, unsigned long u32) { @@ -78,7 +78,7 @@ uint8_t *UINT32_TO_STREAM_f(uint8_t *p, unsigned long u32) return p; } -/***************************************************************************** +/**************************************************************************** * Name: UINT16_TO_STREAM_f * * Description: @@ -92,7 +92,7 @@ uint8_t *UINT32_TO_STREAM_f(uint8_t *p, unsigned long u32) * Returned Value: * Pointer to the new stream * - *****************************************************************************/ + ****************************************************************************/ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16) { @@ -101,7 +101,7 @@ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16) return p; } -/***************************************************************************** +/**************************************************************************** * Name: STREAM_TO_UINT16_f * * Description: @@ -115,7 +115,7 @@ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16) * Returned Value: * Pointer to the new 16 bit * - *****************************************************************************/ + ****************************************************************************/ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset) { @@ -123,7 +123,7 @@ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset) (*(p + offset + 1)) << 8) + (uint16_t)(*(p + offset))); } -/***************************************************************************** +/**************************************************************************** * Name: STREAM_TO_UINT32_f * * Description: @@ -137,7 +137,7 @@ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset) * Returned Value: * Pointer to the new 32 bit * - *****************************************************************************/ + ****************************************************************************/ unsigned long STREAM_TO_UINT32_f(char* p, uint16_t offset) { diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index d563696db9..d120162c99 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -33,11 +33,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -57,9 +57,9 @@ #include #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #undef SPI_DEBUG /* Define to enable debug */ #undef SPI_VERBOSE /* Define to enable verbose debug */ @@ -77,9 +77,9 @@ # define spivdbg(x...) #endif -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ static struct { @@ -96,11 +96,11 @@ static struct -1, }; -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: cc3000_resume * * Description: @@ -112,7 +112,7 @@ static struct * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void cc3000_resume(void) { @@ -121,7 +121,7 @@ void cc3000_resume(void) nllvdbg("Done\n"); } -/***************************************************************************** +/**************************************************************************** * Name: cc3000_write * * Description: @@ -133,7 +133,7 @@ void cc3000_resume(void) * * Returned Value: * - *****************************************************************************/ + ****************************************************************************/ long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) { @@ -141,7 +141,7 @@ long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) return write(spiconf.cc3000fd,pUserBuffer,usLength) == usLength ? 0 : -errno; } -/***************************************************************************** +/**************************************************************************** * Name: cc3000_read * * Description: @@ -154,7 +154,7 @@ long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) * * Returned Value: * - *****************************************************************************/ + ****************************************************************************/ long cc3000_read(uint8_t *pUserBuffer, uint16_t usLength) { @@ -162,7 +162,7 @@ long cc3000_read(uint8_t *pUserBuffer, uint16_t usLength) return read(spiconf.cc3000fd,pUserBuffer,usLength); } -/***************************************************************************** +/**************************************************************************** * Name: cc3000_wait * * Description: @@ -173,7 +173,7 @@ long cc3000_read(uint8_t *pUserBuffer, uint16_t usLength) * * Returned Value: * - *****************************************************************************/ + ****************************************************************************/ uint8_t *cc3000_wait(void) { @@ -184,7 +184,7 @@ uint8_t *cc3000_wait(void) return spiconf.rx_buffer.pbuffer; } -/***************************************************************************** +/**************************************************************************** * Name: unsoliced_thread_func * * Description: @@ -196,7 +196,7 @@ uint8_t *cc3000_wait(void) * * Returned Value: * - *****************************************************************************/ + ****************************************************************************/ static void *unsoliced_thread_func(void *parameter) { @@ -234,7 +234,7 @@ static void *unsoliced_thread_func(void *parameter) return (pthread_addr_t)status; } -/***************************************************************************** +/**************************************************************************** * Name: cc3000_open * * Description: @@ -246,7 +246,7 @@ static void *unsoliced_thread_func(void *parameter) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void cc3000_open(gcSpiHandleRx pfRxHandler) { @@ -286,7 +286,7 @@ void cc3000_open(gcSpiHandleRx pfRxHandler) DEBUGASSERT(spiconf.cc3000fd >= 0); } -/***************************************************************************** +/**************************************************************************** * Name: cc3000_close * * Description: @@ -298,7 +298,7 @@ void cc3000_open(gcSpiHandleRx pfRxHandler) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void cc3000_close(void) { diff --git a/drivers/wireless/cc3000/evnt_handler.c b/drivers/wireless/cc3000/evnt_handler.c index 9a1a2eee85..ebda7af9ee 100644 --- a/drivers/wireless/cc3000/evnt_handler.c +++ b/drivers/wireless/cc3000/evnt_handler.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * evnt_handler.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -51,9 +51,9 @@ #include "cc3000drv.h" #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define FLOW_CONTROL_EVENT_HANDLE_OFFSET (0) #define FLOW_CONTROL_EVENT_BLOCK_MODE_OFFSET (1) @@ -103,23 +103,23 @@ #define GET_SCAN_RESULTS_FRAME_TIME_OFFSET (10) #define GET_SCAN_RESULTS_SSID_MAC_LENGTH (38) -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ unsigned long socket_active_status = SOCKET_STATUS_INIT_VAL; -/***************************************************************************** +/**************************************************************************** * Private Function Prototypes - *****************************************************************************/ + ****************************************************************************/ static long hci_event_unsol_flowcontrol_handler(char *pEvent); static void update_socket_active_status(char *resp_params); -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ -/***************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: hci_unsol_handle_patch_request * * Description: @@ -131,7 +131,7 @@ static void update_socket_active_status(char *resp_params); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void hci_unsol_handle_patch_request(char *event_hdr) { @@ -208,7 +208,7 @@ void hci_unsol_handle_patch_request(char *event_hdr) } } -/***************************************************************************** +/**************************************************************************** * Name: hci_event_handler * * Description: @@ -223,7 +223,7 @@ void hci_unsol_handle_patch_request(char *event_hdr) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) { @@ -552,7 +552,7 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) return NULL; } -/***************************************************************************** +/**************************************************************************** * Name: hci_unsol_event_handler * * Description: @@ -565,7 +565,7 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) * 1 if event supported and handled * 0 if event is not supported * - *****************************************************************************/ + ****************************************************************************/ long hci_unsol_event_handler(char *event_hdr) { @@ -737,7 +737,7 @@ long hci_unsol_event_handler(char *event_hdr) return 0; } -/***************************************************************************** +/**************************************************************************** * Name: hci_unsolicited_event_handler * * Description: @@ -750,7 +750,7 @@ long hci_unsol_event_handler(char *event_hdr) * Returned Value: * ESUCCESS if successful, EFAIL if an error occurred * - *****************************************************************************/ + ****************************************************************************/ long hci_unsolicited_event_handler(void) { @@ -782,7 +782,7 @@ long hci_unsolicited_event_handler(void) return res; } -/***************************************************************************** +/**************************************************************************** * Name: set_socket_active_status * * Description: @@ -796,7 +796,7 @@ long hci_unsolicited_event_handler(void) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void set_socket_active_status(long Sd, long Status) { @@ -807,7 +807,7 @@ void set_socket_active_status(long Sd, long Status) } } -/***************************************************************************** +/**************************************************************************** * Name: hci_event_unsol_flowcontrol_handler * * Description: @@ -821,7 +821,7 @@ void set_socket_active_status(long Sd, long Status) * Returned Value: * ESUCCESS if successful, EFAIL if an error occurred * - *****************************************************************************/ + ****************************************************************************/ long hci_event_unsol_flowcontrol_handler(char *pEvent) { @@ -848,7 +848,7 @@ long hci_event_unsol_flowcontrol_handler(char *pEvent) return(ESUCCESS); } -/***************************************************************************** +/**************************************************************************** * Name: get_socket_active_status * * Description: @@ -860,7 +860,7 @@ long hci_event_unsol_flowcontrol_handler(char *pEvent) * Returned Value: * Current status of the socket. * - *****************************************************************************/ + ****************************************************************************/ long get_socket_active_status(long Sd) { @@ -873,7 +873,7 @@ long get_socket_active_status(long Sd) return SOCKET_STATUS_INACTIVE; } -/***************************************************************************** +/**************************************************************************** * Name: update_socket_active_status * * Description: @@ -885,7 +885,7 @@ long get_socket_active_status(long Sd) * Returned Value: * Current status of the socket. * - *****************************************************************************/ + ****************************************************************************/ void update_socket_active_status(char *resp_params) { @@ -900,7 +900,7 @@ void update_socket_active_status(char *resp_params) } } -/***************************************************************************** +/**************************************************************************** * Name: SimpleLinkWaitEvent * * Description: @@ -914,7 +914,7 @@ void update_socket_active_status(char *resp_params) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void SimpleLinkWaitEvent(uint16_t opcode, void *pRetParams) { @@ -956,7 +956,7 @@ void SimpleLinkWaitEvent(uint16_t opcode, void *pRetParams) nllvdbg("Done for opcode 0x%x\n",opcode); } -/***************************************************************************** +/**************************************************************************** * Name: SimpleLinkWaitData * * Description: @@ -971,7 +971,7 @@ void SimpleLinkWaitEvent(uint16_t opcode, void *pRetParams) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen) { diff --git a/drivers/wireless/cc3000/hci.c b/drivers/wireless/cc3000/hci.c index e82fd842df..e51d45cbbc 100644 --- a/drivers/wireless/cc3000/hci.c +++ b/drivers/wireless/cc3000/hci.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * hci.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -47,16 +47,16 @@ #include #include -/****************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ #define SL_PATCH_PORTION_SIZE (1000) -/****************************************************************************** +/**************************************************************************** * Public Functions - ******************************************************************************/ -/****************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: hci_command_send * * Description: @@ -70,7 +70,7 @@ * Returned Value: * Zero * - *****************************************************************************/ + ****************************************************************************/ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLength) @@ -92,7 +92,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, return 0; } -/****************************************************************************** +/**************************************************************************** * Name: hci_data_send * * Description: @@ -108,7 +108,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, uint16_t usDataLength, const uint8_t *ucTail, @@ -132,7 +132,7 @@ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, return ESUCCESS; } -/****************************************************************************** +/**************************************************************************** * Name: hci_data_command_send * * Description: @@ -147,7 +147,7 @@ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLength,uint16_t ucDataLength) @@ -166,7 +166,7 @@ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE); } -/****************************************************************************** +/**************************************************************************** * Name: hci_patch_send * * Description: @@ -181,7 +181,7 @@ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void hci_patch_send(uint8_t ucOpcode, uint8_t *pucBuff, char *patch, uint16_t usDataLength) diff --git a/drivers/wireless/cc3000/netapp.c b/drivers/wireless/cc3000/netapp.c index b6a76ed4fc..973f1e9ad8 100644 --- a/drivers/wireless/cc3000/netapp.c +++ b/drivers/wireless/cc3000/netapp.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * netapp.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -46,9 +46,9 @@ #include "cc3000.h" #include "cc3000_socket.h" -/****************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ #define MIN_TIMER_VAL_SECONDS 20 #define MIN_TIMER_SET(t) if ((0 != t) && (t < MIN_TIMER_VAL_SECONDS)) \ @@ -62,11 +62,11 @@ #define NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN (4) #define NETAPP_PING_SEND_PARAMS_LEN (16) -/****************************************************************************** +/**************************************************************************** * Public Functions - ******************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Name: netapp_config_mac_adrress * * Description: @@ -80,14 +80,14 @@ * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ long netapp_config_mac_adrress(uint8_t *mac) { return nvmem_set_mac_address(mac); } -/****************************************************************************** +/**************************************************************************** * Name: netapp_dhcp * * Description: @@ -112,7 +112,7 @@ long netapp_config_mac_adrress(uint8_t *mac) * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, unsigned long *aucDefaultGateway, unsigned long *aucDNSServer) @@ -148,7 +148,7 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, return(scRet); } -/****************************************************************************** +/**************************************************************************** * Name: netapp_timeout_values * * Description: @@ -196,7 +196,7 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, @@ -241,7 +241,7 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_send * * Description: @@ -263,7 +263,7 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, @@ -299,7 +299,7 @@ long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_report * * Description: @@ -324,7 +324,7 @@ long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER void netapp_ping_report(void) @@ -349,7 +349,7 @@ void netapp_ping_report(void) } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_stop * * Description: @@ -361,7 +361,7 @@ void netapp_ping_report(void) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_ping_stop(void) @@ -388,7 +388,7 @@ long netapp_ping_stop(void) } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ipconfig * * Description: @@ -416,7 +416,7 @@ long netapp_ping_stop(void) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig) @@ -443,7 +443,7 @@ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig) } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_arp_flush * * Description: @@ -455,7 +455,7 @@ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_arp_flush(void) @@ -483,7 +483,7 @@ long netapp_arp_flush(void) } #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_set_debug_level * * Description: @@ -507,7 +507,7 @@ long netapp_arp_flush(void) * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_set_debug_level(unsigned long ulLevel) diff --git a/drivers/wireless/cc3000/nvmem.c b/drivers/wireless/cc3000/nvmem.c index 82fac1de68..c8bd1b5be7 100644 --- a/drivers/wireless/cc3000/nvmem.c +++ b/drivers/wireless/cc3000/nvmem.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * nvmem.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include #include @@ -44,18 +44,18 @@ #include #include "cc3000.h" -/****************************************************************************** +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ #define NVMEM_READ_PARAMS_LEN (12) #define NVMEM_CREATE_PARAMS_LEN (8) #define NVMEM_WRITE_PARAMS_LEN (16) -/****************************************************************************** +/**************************************************************************** * Public Functions - ******************************************************************************/ -/****************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: nvmem_read * * Description: @@ -79,7 +79,7 @@ * Returned Value: * Number of bytes read, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, uint8_t *buff) @@ -120,7 +120,7 @@ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, return ucStatus; } -/****************************************************************************** +/**************************************************************************** * Name: nvmem_write * * Description: @@ -141,7 +141,7 @@ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, uint8_t *buff) @@ -179,7 +179,7 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, return iRes; } -/****************************************************************************** +/**************************************************************************** * Name: nvmem_set_mac_address * * Description: @@ -192,14 +192,14 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_set_mac_address(uint8_t *mac) { return nvmem_write(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac); } -/****************************************************************************** +/**************************************************************************** * Name: nvmem_get_mac_address * * Description: @@ -212,14 +212,14 @@ uint8_t nvmem_set_mac_address(uint8_t *mac) * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_get_mac_address(uint8_t *mac) { return nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac); } -/****************************************************************************** +/**************************************************************************** * Name: nvmem_write_patch * * Description: @@ -236,7 +236,7 @@ uint8_t nvmem_get_mac_address(uint8_t *mac) * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const uint8_t *spData) @@ -270,7 +270,7 @@ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, return status; } -/****************************************************************************** +/**************************************************************************** * Name: nvmem_read_sp_version * * Description: @@ -284,7 +284,7 @@ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER uint8_t nvmem_read_sp_version(uint8_t *patchVer) @@ -316,7 +316,7 @@ uint8_t nvmem_read_sp_version(uint8_t *patchVer) } #endif -/****************************************************************************** +/**************************************************************************** * Name: nvmem_create_entry * * Description: @@ -336,7 +336,7 @@ uint8_t nvmem_read_sp_version(uint8_t *patchVer) * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen) { diff --git a/drivers/wireless/cc3000/security.c b/drivers/wireless/cc3000/security.c index 990828b10e..5d0c406faa 100644 --- a/drivers/wireless/cc3000/security.c +++ b/drivers/wireless/cc3000/security.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * security.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,19 +30,19 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #ifndef CC3000_UNENCRYPTED_SMART_CONFIG -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ // foreward sbox @@ -98,9 +98,9 @@ const uint8_t Rcon[11] = uint8_t aexpandedKey[176]; -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ //***************************************************************************** // //! expandKey @@ -443,7 +443,7 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) } -/***************************************************************************** +/**************************************************************************** * Name: aes_encrypt * * Description: @@ -458,7 +458,7 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) * Returned Value * None * - *****************************************************************************/ + ****************************************************************************/ void aes_encrypt(uint8_t *state, uint8_t *key) { @@ -467,7 +467,7 @@ void aes_encrypt(uint8_t *state, uint8_t *key) aes_encr(state, aexpandedKey); } -/***************************************************************************** +/**************************************************************************** * Name: aes_decrypt * * Description: @@ -482,7 +482,7 @@ void aes_encrypt(uint8_t *state, uint8_t *key) * Returned Value * None * - *****************************************************************************/ + ****************************************************************************/ void aes_decrypt(uint8_t *state, uint8_t *key) { @@ -490,7 +490,7 @@ void aes_decrypt(uint8_t *state, uint8_t *key) aes_decr(state, aexpandedKey); } -/***************************************************************************** +/**************************************************************************** * Name: aes_read_key * * Description: @@ -503,7 +503,7 @@ void aes_decrypt(uint8_t *state, uint8_t *key) * Returned Value * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long aes_read_key(uint8_t *key) { @@ -514,7 +514,7 @@ signed long aes_read_key(uint8_t *key) return returnValue; } -/***************************************************************************** +/**************************************************************************** * Name: aes_write_key * * Description: @@ -527,7 +527,7 @@ signed long aes_read_key(uint8_t *key) * Returned Value * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long aes_write_key(uint8_t *key) { diff --git a/drivers/wireless/cc3000/socket.c b/drivers/wireless/cc3000/socket.c index 87d7f4dacb..aa8b10af9a 100644 --- a/drivers/wireless/cc3000/socket.c +++ b/drivers/wireless/cc3000/socket.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * socket.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -54,9 +54,9 @@ #include "cc3000drv.h" #include "cc3000.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #ifndef ARRAY_SIZE # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -99,7 +99,7 @@ static const int bsd2ti_types[] = * Public Functions ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: socket * * Description: @@ -120,7 +120,7 @@ static const int bsd2ti_types[] = * On success, socket handle that is used for consequent socket * operations. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_socket(int domain, int type, int protocol) { @@ -175,7 +175,7 @@ int cc3000_socket(int domain, int type, int protocol) return sd; } -/***************************************************************************** +/**************************************************************************** * Name: closesocket * * Description: @@ -187,7 +187,7 @@ int cc3000_socket(int domain, int type, int protocol) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_closesocket(int sockfd) { @@ -205,7 +205,7 @@ int cc3000_closesocket(int sockfd) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: accept, cc3000_do_accept * * Description: @@ -248,7 +248,7 @@ int cc3000_closesocket(int sockfd) * - On connection pending, SOC_IN_PROGRESS (-2) * - On failure, SOC_ERROR (-1) * - *****************************************************************************/ + ****************************************************************************/ int cc3000_do_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { @@ -290,7 +290,7 @@ int cc3000_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) } #endif -/***************************************************************************** +/**************************************************************************** * Name: bind * * Description: @@ -311,7 +311,7 @@ int cc3000_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) { @@ -323,7 +323,7 @@ int cc3000_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: listen * * Description: @@ -345,7 +345,7 @@ int cc3000_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_listen(int sockfd, int backlog) { @@ -357,7 +357,7 @@ int cc3000_listen(int sockfd, int backlog) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: connect * * Description: @@ -385,7 +385,7 @@ int cc3000_listen(int sockfd, int backlog) * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) { @@ -397,7 +397,7 @@ int cc3000_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrle return ret; } -/***************************************************************************** +/**************************************************************************** * Name: select * * Description: @@ -434,7 +434,7 @@ int cc3000_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrle * will return without delay. * *exceptfds - return the sockets which closed recently. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout) @@ -450,7 +450,7 @@ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, } #ifndef CC3000_TINY_DRIVER -/***************************************************************************** +/**************************************************************************** * Name: setsockopt * * Description: @@ -496,7 +496,7 @@ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_setsockopt(int sockfd, int level, int option, FAR const void *value, socklen_t value_len) @@ -510,7 +510,7 @@ int cc3000_setsockopt(int sockfd, int level, int option, } #endif -/***************************************************************************** +/**************************************************************************** * Name: getsockopt * * Description: @@ -556,7 +556,7 @@ int cc3000_setsockopt(int sockfd, int level, int option, * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_getsockopt(int sockfd, int level, int option, FAR void *value, FAR socklen_t *value_len) @@ -569,7 +569,7 @@ int cc3000_getsockopt(int sockfd, int level, int option, FAR void *value, return ret; } -/***************************************************************************** +/**************************************************************************** * Name: recv * * Description: @@ -589,7 +589,7 @@ int cc3000_getsockopt(int sockfd, int level, int option, FAR void *value, * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t cc3000_recv(int sockfd, FAR void *buf, size_t len, int flags) { @@ -619,7 +619,7 @@ ssize_t cc3000_recv(int sockfd, FAR void *buf, size_t len, int flags) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: recvfrom * * Description: @@ -646,7 +646,7 @@ ssize_t cc3000_recv(int sockfd, FAR void *buf, size_t len, int flags) * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t cc3000_recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct sockaddr *from, FAR socklen_t *fromlen) @@ -672,7 +672,7 @@ ssize_t cc3000_recvfrom(int sockfd, FAR void *buf, size_t len, int flags, return ret; } -/***************************************************************************** +/**************************************************************************** * Name: send * * Description: @@ -692,7 +692,7 @@ ssize_t cc3000_recvfrom(int sockfd, FAR void *buf, size_t len, int flags, * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t cc3000_send(int sockfd, FAR const void *buf, size_t len, int flags) { @@ -704,7 +704,7 @@ ssize_t cc3000_send(int sockfd, FAR const void *buf, size_t len, int flags) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: sendto * * Description: @@ -728,7 +728,7 @@ ssize_t cc3000_send(int sockfd, FAR const void *buf, size_t len, int flags) * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t cc3000_sendto(int sockfd, FAR const void *buf, size_t len, int flags, FAR const struct sockaddr *to, socklen_t tolen) @@ -741,7 +741,7 @@ ssize_t cc3000_sendto(int sockfd, FAR const void *buf, size_t len, int flags, return ret; } -/***************************************************************************** +/**************************************************************************** * Name: gethostbyname * * Description: @@ -762,7 +762,7 @@ ssize_t cc3000_sendto(int sockfd, FAR const void *buf, size_t len, int flags, * Returned Value: * On success, positive is returned. On error, negative is returned * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER // TODO: Standard is struct hostent *gethostbyname(const char *name); @@ -777,7 +777,7 @@ int cc3000_gethostbyname(char * hostname, uint16_t usNameLen, unsigned long* out } #endif -/***************************************************************************** +/**************************************************************************** * Name: mdnsAdvertiser * * Description: @@ -793,7 +793,7 @@ int cc3000_gethostbyname(char * hostname, uint16_t usNameLen, unsigned long* out * On success, zero is returned, return SOC_ERROR if socket was not * opened successfully, or if an error occurred. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, uint16_t deviceServiceNameLength) diff --git a/drivers/wireless/cc3000/socket_imp.c b/drivers/wireless/cc3000/socket_imp.c index d52fe270d3..3e810757d7 100644 --- a/drivers/wireless/cc3000/socket_imp.c +++ b/drivers/wireless/cc3000/socket_imp.c @@ -33,11 +33,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -51,9 +51,9 @@ #include #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* Enable this flag if and only if you must comply with BSD socket close() * function @@ -101,10 +101,10 @@ #define MDNS_DEVICE_SERVICE_MAX_LENGTH (32) -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ -/***************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: HostFlowControlConsumeBuff * * Input Parameters: @@ -121,7 +121,7 @@ * becomes available, else return immediately with correct status * regarding the buffers available. * - *****************************************************************************/ + ****************************************************************************/ int HostFlowControlConsumeBuff(int sd) { @@ -197,7 +197,7 @@ int HostFlowControlConsumeBuff(int sd) #endif } -/***************************************************************************** +/**************************************************************************** * Name: socket * * Decription: @@ -218,7 +218,7 @@ int HostFlowControlConsumeBuff(int sd) * On success, socket handle that is used for consequent socket * operations. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_socket_impl(long domain, long type, long protocol) { @@ -250,7 +250,7 @@ int cc3000_socket_impl(long domain, long type, long protocol) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: closesocket * * Decription: @@ -262,7 +262,7 @@ int cc3000_socket_impl(long domain, long type, long protocol) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_closesocket_impl(long sd) { @@ -296,7 +296,7 @@ long cc3000_closesocket_impl(long sd) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: accept * * Decription: @@ -339,7 +339,7 @@ long cc3000_closesocket_impl(long sd) * - On connection pending, SOC_IN_PROGRESS (-2) * - On failure, SOC_ERROR (-1) * - *****************************************************************************/ + ****************************************************************************/ long cc3000_accept_impl(long sd, struct sockaddr *addr, socklen_t *addrlen) { @@ -385,7 +385,7 @@ long cc3000_accept_impl(long sd, struct sockaddr *addr, socklen_t *addrlen) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: bind * * Decription: @@ -406,7 +406,7 @@ long cc3000_accept_impl(long sd, struct sockaddr *addr, socklen_t *addrlen) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_bind_impl(long sd, const struct sockaddr *addr, socklen_t addrlen) { @@ -439,7 +439,7 @@ long cc3000_bind_impl(long sd, const struct sockaddr *addr, socklen_t addrlen) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: listen * * Decription: @@ -461,7 +461,7 @@ long cc3000_bind_impl(long sd, const struct sockaddr *addr, socklen_t addrlen) * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_listen_impl(long sd, long backlog) { @@ -490,7 +490,7 @@ long cc3000_listen_impl(long sd, long backlog) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: gethostbyname * * Decription: @@ -511,7 +511,7 @@ long cc3000_listen_impl(long sd, long backlog) * Returned Value: * On success, positive is returned. On error, negative is returned * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long* out_ip_addr) @@ -552,7 +552,7 @@ int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long } #endif -/***************************************************************************** +/**************************************************************************** * Name: connect * * Decription: @@ -580,7 +580,7 @@ int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ long cc3000_connect_impl(long sd, const struct sockaddr *addr, socklen_t addrlen) { @@ -612,7 +612,7 @@ long cc3000_connect_impl(long sd, const struct sockaddr *addr, socklen_t addrlen return (long)ret; } -/***************************************************************************** +/**************************************************************************** * Name: select * * Decription: @@ -649,7 +649,7 @@ long cc3000_connect_impl(long sd, const struct sockaddr *addr, socklen_t addrlen * will return without delay. * *exceptsds - return the sockets which closed recently. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_select_impl(long nfds, TICC3000fd_set *readsds, TICC3000fd_set *writesds, TICC3000fd_set *exceptsds, struct timeval *timeout) @@ -732,7 +732,7 @@ int cc3000_select_impl(long nfds, TICC3000fd_set *readsds, TICC3000fd_set *write } } -/***************************************************************************** +/**************************************************************************** * Name: setsockopt * * Decription: @@ -778,7 +778,7 @@ int cc3000_select_impl(long nfds, TICC3000fd_set *readsds, TICC3000fd_set *write * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER int cc3000_setsockopt_impl(long sd, long level, long optname, const void *optval, socklen_t optlen) @@ -819,7 +819,7 @@ int cc3000_setsockopt_impl(long sd, long level, long optname, const void *optval } #endif -/***************************************************************************** +/**************************************************************************** * Name: getsockopt * * Decription: @@ -865,7 +865,7 @@ int cc3000_setsockopt_impl(long sd, long level, long optname, const void *optval * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_getsockopt_impl(long sd, long level, long optname, void *optval, socklen_t *optlen) { @@ -903,7 +903,7 @@ int cc3000_getsockopt_impl(long sd, long level, long optname, void *optval, sock } } -/***************************************************************************** +/**************************************************************************** * Name: simple_link_recv * * Input Parameters: @@ -925,7 +925,7 @@ int cc3000_getsockopt_impl(long sd, long level, long optname, void *optval, sock * excess bytes may be discarded depending on the type of * socket the message is received from * - *****************************************************************************/ + ****************************************************************************/ int simple_link_recv(long sd, void *buf, long len, long flags, struct sockaddr *from, socklen_t *fromlen, long opcode) @@ -965,7 +965,7 @@ int simple_link_recv(long sd, void *buf, long len, long flags, struct sockaddr * return tSocketReadEvent.iNumberOfBytes; } -/***************************************************************************** +/**************************************************************************** * Name: recv * * Decription: @@ -985,14 +985,14 @@ int simple_link_recv(long sd, void *buf, long len, long flags, struct sockaddr * * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_recv_impl(long sd, void *buf, long len, long flags) { return(simple_link_recv(sd, buf, len, flags, NULL, NULL, HCI_CMND_RECV)); } -/***************************************************************************** +/**************************************************************************** * Name: recvfrom * * Decription: @@ -1019,7 +1019,7 @@ int cc3000_recv_impl(long sd, void *buf, long len, long flags) * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_recvfrom_impl(long sd, void *buf, long len, long flags, struct sockaddr *from, socklen_t *fromlen) @@ -1028,7 +1028,7 @@ int cc3000_recvfrom_impl(long sd, void *buf, long len, long flags, struct sockad HCI_CMND_RECVFROM)); } -/***************************************************************************** +/**************************************************************************** * Name: simple_link_send * * Input Parameters: @@ -1049,7 +1049,7 @@ int cc3000_recvfrom_impl(long sd, void *buf, long len, long flags, struct sockad * This function is used to transmit a message to another * socket * - *****************************************************************************/ + ****************************************************************************/ int simple_link_send(long sd, const void *buf, long len, long flags, const struct sockaddr *to, long tolen, long opcode) @@ -1144,7 +1144,7 @@ int simple_link_send(long sd, const void *buf, long len, long flags, return len; } -/***************************************************************************** +/**************************************************************************** * Name: send * * Decription: @@ -1164,14 +1164,14 @@ int simple_link_send(long sd, const void *buf, long len, long flags, * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_send_impl(long sd, const void *buf, long len, long flags) { return(simple_link_send(sd, buf, len, flags, NULL, 0, HCI_CMND_SEND)); } -/***************************************************************************** +/**************************************************************************** * Name: sendto * * Decription: @@ -1195,7 +1195,7 @@ int cc3000_send_impl(long sd, const void *buf, long len, long flags) * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_sendto_impl(long sd, const void *buf, long len, long flags, const struct sockaddr *to, socklen_t tolen) @@ -1203,7 +1203,7 @@ int cc3000_sendto_impl(long sd, const void *buf, long len, long flags, const str return(simple_link_send(sd, buf, len, flags, to, tolen, HCI_CMND_SENDTO)); } -/***************************************************************************** +/**************************************************************************** * Name: mdnsAdvertiser * * Decription: @@ -1219,7 +1219,7 @@ int cc3000_sendto_impl(long sd, const void *buf, long len, long flags, const str * On success, zero is returned, return SOC_ERROR if socket was not * opened successfully, or if an error occurred. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_mdnsadvertiser_impl(uint16_t mdnsEnabled, char * deviceServiceName, uint16_t deviceServiceNameLength) diff --git a/drivers/wireless/cc3000/wlan.c b/drivers/wireless/cc3000/wlan.c index e0ac1d61a3..227a633cb4 100644 --- a/drivers/wireless/cc3000/wlan.c +++ b/drivers/wireless/cc3000/wlan.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * wlan.c - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,11 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -53,9 +53,9 @@ #include "cc3000.h" #include "cc3000drv.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define SMART_CONFIG_PROFILE_SIZE 67 /* 67 = 32 (max ssid) + 32 (max key) + * 1 (SSID length) + 1 (security type) + @@ -102,9 +102,9 @@ * Private Variables ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ volatile sSimplLinkInformation tSLInformation; #ifndef CC3000_UNENCRYPTED_SMART_CONFIG @@ -112,10 +112,10 @@ uint8_t akey[AES128_KEY_SIZE]; uint8_t profileArray[SMART_CONFIG_PROFILE_SIZE]; #endif /* CC3000_UNENCRYPTED_SMART_CONFIG */ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ -/***************************************************************************** + ****************************************************************************/ +/**************************************************************************** * Name: SimpleLink_Init_Start * * Input Parameters: @@ -132,7 +132,7 @@ uint8_t profileArray[SMART_CONFIG_PROFILE_SIZE]; * Description: * Send HCI_CMND_SIMPLE_LINK_START to CC3000 * - *****************************************************************************/ + ****************************************************************************/ static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost) { @@ -157,7 +157,7 @@ static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost) SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0); } -/***************************************************************************** +/**************************************************************************** * Name: wlan_init * * Input Parameters: @@ -193,7 +193,7 @@ static void SimpleLink_Init_Start(uint16_t usPatchesAvailableAtHost) * * WARNING: This function must be called before ANY other wlan driver function * - *****************************************************************************/ + ****************************************************************************/ void wlan_init(size_t max_tx_len, tWlanCB sWlanCB, @@ -235,7 +235,7 @@ void wlan_init(size_t max_tx_len, } } -/***************************************************************************** +/**************************************************************************** * Name: SpiReceiveHandler * * Input Parameters: @@ -248,7 +248,7 @@ void wlan_init(size_t max_tx_len, * The function triggers Received event/data processing. It is * called from the SPI library to receive the data * - *****************************************************************************/ + ****************************************************************************/ void SpiReceiveHandler(void *pvBuffer) { @@ -266,7 +266,7 @@ void SpiReceiveHandler(void *pvBuffer) hci_unsolicited_event_handler(); } -/***************************************************************************** +/**************************************************************************** * Name: wlan_start * * Input Parameters: @@ -291,7 +291,7 @@ void SpiReceiveHandler(void *pvBuffer) * WARNING: This function must be called after wlan_init and before any * other wlan API * - *****************************************************************************/ + ****************************************************************************/ void wlan_start(uint16_t usPatchesAvailableAtHost) { @@ -321,7 +321,7 @@ void wlan_start(uint16_t usPatchesAvailableAtHost) cc3000_lib_unlock(); } -/***************************************************************************** +/**************************************************************************** * Name: wlan_get_buffer * * Input Parameters: @@ -330,14 +330,14 @@ void wlan_start(uint16_t usPatchesAvailableAtHost) * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void wlan_get_buffer(wlan_buffer_desc *pdes) { *pdes = tSLInformation.usrBuffer; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_stop * * Input Parameters: @@ -349,7 +349,7 @@ void wlan_get_buffer(wlan_buffer_desc *pdes) * Description: * Stop WLAN device by putting it into reset state. * - *****************************************************************************/ + ****************************************************************************/ void wlan_stop(void) { @@ -358,7 +358,7 @@ void wlan_stop(void) cc3000_lib_unlock(); } -/***************************************************************************** +/**************************************************************************** * Name: wlan_connect * * Input Parameters: @@ -388,7 +388,7 @@ void wlan_stop(void) * type WEP, please confirm that the key is set as ASCII and not * as HEX. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_connect(unsigned long ulSecType, FAR const char *ssid, @@ -489,7 +489,7 @@ long wlan_connect(FAR const char *ssid, long ssid_len) } #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_disconnect * * Input Parameters: @@ -501,7 +501,7 @@ long wlan_connect(FAR const char *ssid, long ssid_len) * Description: * Disconnect connection from AP. * - *****************************************************************************/ + ****************************************************************************/ long wlan_disconnect(void) { @@ -525,7 +525,7 @@ long wlan_disconnect(void) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_set_connection_policy * * Input Parameters: @@ -555,7 +555,7 @@ long wlan_disconnect(void) * enabled, the device will try to connect to any AP. * * Note that the policy settings are stored in the CC3000 NVMEM. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, unsigned long ulShouldUseFastConnect, @@ -590,7 +590,7 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_add_profile * * Input Parameters: @@ -616,7 +616,7 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, * profile based on security policy, signal strength, etc * parameters. All the profiles are stored in CC3000 NVMEM. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_add_profile(unsigned long ulSecType, uint8_t *ucSsid, @@ -756,7 +756,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t * ucSsid, uint8_t ulSsidL } #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_del_profile * * Input Parameters: @@ -770,7 +770,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t * ucSsid, uint8_t ulSsidL * * @Note In order to delete all stored profile, set index to 255. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_del_profile(unsigned long ulIndex) { @@ -802,7 +802,7 @@ long wlan_ioctl_del_profile(unsigned long ulIndex) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_get_scan_results * * Input Parameters: @@ -833,7 +833,7 @@ long wlan_ioctl_del_profile(unsigned long ulIndex) * * NOTE: scan_timeout, is not supported on this version. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults) @@ -865,7 +865,7 @@ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults } #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_set_scan_params * * Input Parameters: @@ -900,7 +900,7 @@ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults * * @Note uiDefaultTxPower, is not supported on this version. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_ioctl_set_scan_params(unsigned long uiEnable, @@ -950,7 +950,7 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable, } #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_set_event_mask * * Input Parameters: @@ -972,7 +972,7 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable, * Mask event according to bit mask. In case that event is * masked (1), the device will not send the masked event to host. * - *****************************************************************************/ + ****************************************************************************/ long wlan_set_event_mask(unsigned long ulMask) { @@ -1025,7 +1025,7 @@ long wlan_set_event_mask(unsigned long ulMask) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_statusget * * Input Parameters: @@ -1038,7 +1038,7 @@ long wlan_set_event_mask(unsigned long ulMask) * Description: * get wlan status: disconnected, scanning, connecting or connected * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_ioctl_statusget(void) @@ -1064,7 +1064,7 @@ long wlan_ioctl_statusget(void) } #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_start * * Input Parameters: @@ -1083,7 +1083,7 @@ long wlan_ioctl_statusget(void) * @Note An asynchronous event - Smart Config Done will be generated as soon * as the process finishes successfully. * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_start(unsigned long algoEncryptedFlag) { @@ -1112,7 +1112,7 @@ long wlan_smart_config_start(unsigned long algoEncryptedFlag) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_stop * * Input Parameters: @@ -1124,7 +1124,7 @@ long wlan_smart_config_start(unsigned long algoEncryptedFlag) * Description: * Stop the acquire profile procedure * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_stop(void) { @@ -1146,7 +1146,7 @@ long wlan_smart_config_stop(void) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_set_prefix * * Input Parameters: @@ -1161,7 +1161,7 @@ long wlan_smart_config_stop(void) * * @Note The prefix is stored in CC3000 NVMEM * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_set_prefix(char* cNewPrefix) { @@ -1203,7 +1203,7 @@ long wlan_smart_config_set_prefix(char* cNewPrefix) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_process * * Input Parameters: @@ -1218,7 +1218,7 @@ long wlan_smart_config_set_prefix(char* cNewPrefix) * The encrypted data is decrypted and stored as a profile. * behavior is as defined by connection policy. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_UNENCRYPTED_SMART_CONFIG long wlan_smart_config_process() diff --git a/libc/stdlib/lib_bsearch.c b/libc/stdlib/lib_bsearch.c index c7c3dc5b60..b6586cc9d2 100644 --- a/libc/stdlib/lib_bsearch.c +++ b/libc/stdlib/lib_bsearch.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * libc/stdlib/lib_bsearch.c * * Copyright (c) 1990, 1993 @@ -32,20 +32,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: bsearch * * Description: @@ -101,7 +101,7 @@ * when 'lim' is 4, we still looked at item 2, so we have to make 'lim' * 3, then halve, obtaining 1, so that we will only look at item 3. * - *****************************************************************************/ + ****************************************************************************/ FAR void *bsearch(FAR const void *key, FAR const void *base, size_t nel, size_t width, CODE int (*compar)(FAR const void *, diff --git a/libc/string/lib_strcasecmp.c b/libc/string/lib_strcasecmp.c index df6f08118d..4aec2826a5 100644 --- a/libc/string/lib_strcasecmp.c +++ b/libc/string/lib_strcasecmp.c @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -44,7 +44,7 @@ /**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP int strcasecmp(const char *cs, const char *ct) diff --git a/libc/string/lib_strcmp.c b/libc/string/lib_strcmp.c index d4036cd3ea..a871c4a854 100644 --- a/libc/string/lib_strcmp.c +++ b/libc/string/lib_strcmp.c @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -43,7 +43,7 @@ /**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP int strcmp(const char *cs, const char *ct) diff --git a/libc/string/lib_strncasecmp.c b/libc/string/lib_strncasecmp.c index 35aba40c05..05d795b0a2 100644 --- a/libc/string/lib_strncasecmp.c +++ b/libc/string/lib_strncasecmp.c @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Compilation Switches - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -49,7 +49,7 @@ /**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRNCASECMP int strncasecmp(const char *cs, const char *ct, size_t nb) diff --git a/libc/string/lib_strncmp.c b/libc/string/lib_strncmp.c index bdeb98720a..92df02a20b 100644 --- a/libc/string/lib_strncmp.c +++ b/libc/string/lib_strncmp.c @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Compilation Switches - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -47,7 +47,7 @@ /**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_ARCH_STRNCMP int strncmp(const char *cs, const char *ct, size_t nb) diff --git a/sched/group/group_childstatus.c b/sched/group/group_childstatus.c index d67aad6067..00e78b4322 100644 --- a/sched/group/group_childstatus.c +++ b/sched/group/group_childstatus.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_childstatus.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -48,9 +48,9 @@ #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* Note that there cannot be more that CONFIG_MAX_TASKS tasks in total. * However, the number of child status structures may need to be significantly * larger because this number includes the maximum number of tasks that are @@ -70,9 +70,9 @@ # undef CONFIG_DEBUG_CHILDSTATUS #endif -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ /* Globals are maintained in a structure to minimize name collisions. */ struct child_pool_s @@ -81,17 +81,17 @@ struct child_pool_s FAR struct child_status_s *freelist; }; -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ static struct child_pool_s g_child_pool; -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_dumpchildren * * Description: @@ -106,7 +106,7 @@ static struct child_pool_s g_child_pool; * Assumptions: * Called early in initialization. No special precautions are required. * - *****************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_DEBUG_CHILDSTATUS static void group_dumpchildren(FAR struct task_group_s *group, @@ -126,11 +126,11 @@ static void group_dumpchildren(FAR struct task_group_s *group, # define group_dumpchildren(t,m) #endif -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: task_initialize * * Description: @@ -146,7 +146,7 @@ static void group_dumpchildren(FAR struct task_group_s *group, * Assumptions: * Called early in initialization. No special precautions are required. * - *****************************************************************************/ + ****************************************************************************/ void task_initialize(void) { @@ -166,7 +166,7 @@ void task_initialize(void) } } -/***************************************************************************** +/**************************************************************************** * Name: group_allocchild * * Description: @@ -184,7 +184,7 @@ void task_initialize(void) * Called during task creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ FAR struct child_status_s *group_allocchild(void) { @@ -202,7 +202,7 @@ FAR struct child_status_s *group_allocchild(void) return ret; } -/***************************************************************************** +/**************************************************************************** * Name: group_freechild * * Description: @@ -218,7 +218,7 @@ FAR struct child_status_s *group_allocchild(void) * Called during task creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ void group_freechild(FAR struct child_status_s *child) { @@ -231,7 +231,7 @@ void group_freechild(FAR struct child_status_s *child) } } -/***************************************************************************** +/**************************************************************************** * Name: group_addchild * * Description: @@ -248,7 +248,7 @@ void group_freechild(FAR struct child_status_s *child) * Called during task creation processing in a safe context. No special * precautions are required here. * - *****************************************************************************/ + ****************************************************************************/ void group_addchild(FAR struct task_group_s *group, FAR struct child_status_s *child) @@ -261,7 +261,7 @@ void group_addchild(FAR struct task_group_s *group, group_dumpchildren(group, "group_addchild"); } -/***************************************************************************** +/**************************************************************************** * Name: group_findchild * * Description: @@ -281,7 +281,7 @@ void group_addchild(FAR struct task_group_s *group, * Called during SIGCHLD processing in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ FAR struct child_status_s *group_findchild(FAR struct task_group_s *group, pid_t pid) @@ -303,7 +303,7 @@ FAR struct child_status_s *group_findchild(FAR struct task_group_s *group, return NULL; } -/***************************************************************************** +/**************************************************************************** * Name: group_exitchild * * Description: @@ -320,7 +320,7 @@ FAR struct child_status_s *group_findchild(FAR struct task_group_s *group, * Called during SIGCHLD processing in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ FAR struct child_status_s *group_exitchild(FAR struct task_group_s *group) { @@ -339,7 +339,7 @@ FAR struct child_status_s *group_exitchild(FAR struct task_group_s *group) return NULL; } -/***************************************************************************** +/**************************************************************************** * Name: group_removechild * * Description: @@ -359,7 +359,7 @@ FAR struct child_status_s *group_exitchild(FAR struct task_group_s *group) * Called during SIGCHLD processing in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, pid_t pid) @@ -403,7 +403,7 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, return curr; } -/***************************************************************************** +/**************************************************************************** * Name: group_removechildren * * Description: @@ -419,7 +419,7 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, * Called during task exit processing in a safe context. No special * precautions are required here. * - *****************************************************************************/ + ****************************************************************************/ void group_removechildren(FAR struct task_group_s *group) { diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 7d84e3e206..edacec0490 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_create.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -51,29 +51,29 @@ #ifdef HAVE_TASK_GROUP -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* Is this worth making a configuration option? */ #define GROUP_INITIAL_MEMBERS 4 -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ /* This is counter that is used to generate unique task group IDs */ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) static gid_t g_gidcounter; #endif -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) /* This is the head of a list of all group members */ @@ -81,11 +81,11 @@ static gid_t g_gidcounter; FAR struct task_group_s *g_grouphead; #endif -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_assigngid * * Description: @@ -101,7 +101,7 @@ FAR struct task_group_s *g_grouphead; * Called during task creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) static void group_assigngid(FAR struct task_group_s *group) @@ -147,11 +147,11 @@ static void group_assigngid(FAR struct task_group_s *group) } #endif /* HAVE_GROUP_MEMBERS */ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_allocate * * Description: @@ -174,7 +174,7 @@ static void group_assigngid(FAR struct task_group_s *group) * Called during task creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) { @@ -253,7 +253,7 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) return OK; } -/***************************************************************************** +/**************************************************************************** * Name: group_initialize * * Description: @@ -272,7 +272,7 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) * Called during task creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ int group_initialize(FAR struct task_tcb_s *tcb) { diff --git a/sched/group/group_find.c b/sched/group/group_find.c index c0c70bbc75..ab88163cac 100644 --- a/sched/group/group_find.c +++ b/sched/group/group_find.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_find.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -51,31 +51,31 @@ #ifdef HAVE_TASK_GROUP -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_findbygid * * Description: @@ -97,7 +97,7 @@ * precautions should be required here. However, extra care is taken when * accessing the global g_grouphead list. * - *****************************************************************************/ + ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) FAR struct task_group_s *group_findbygid(gid_t gid) @@ -122,7 +122,7 @@ FAR struct task_group_s *group_findbygid(gid_t gid) } #endif -/***************************************************************************** +/**************************************************************************** * Name: group_findbypid * * Description: @@ -143,7 +143,7 @@ FAR struct task_group_s *group_findbygid(gid_t gid) * precautions should be required here. However, extra care is taken when * accessing the global g_grouphead list. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS FAR struct task_group_s *group_findbypid(pid_t pid) diff --git a/sched/group/group_join.c b/sched/group/group_join.c index 662db69bc8..0e16f317a7 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_join.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -52,26 +52,26 @@ #if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_PTHREAD) -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* Is this worth making a configuration option? */ #define GROUP_REALLOC_MEMBERS 4 -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_addmember * * Description: @@ -88,7 +88,7 @@ * Called during thread creation and during reparenting in a safe context. * No special precautions are required here. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) @@ -141,11 +141,11 @@ static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) } #endif /* HAVE_GROUP_MEMBERS */ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_bind * * Description: @@ -168,7 +168,7 @@ static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) * - Called during thread creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ int group_bind(FAR struct pthread_tcb_s *tcb) { @@ -182,7 +182,7 @@ int group_bind(FAR struct pthread_tcb_s *tcb) return OK; } -/***************************************************************************** +/**************************************************************************** * Name: group_join * * Description: @@ -205,7 +205,7 @@ int group_bind(FAR struct pthread_tcb_s *tcb) * - Called during thread creation in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ int group_join(FAR struct pthread_tcb_s *tcb) { diff --git a/sched/group/group_killchildren.c b/sched/group/group_killchildren.c index 265b04036b..d549da8658 100644 --- a/sched/group/group_killchildren.c +++ b/sched/group/group_killchildren.c @@ -49,7 +49,7 @@ * Private Functions ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_killchildren_handler * * Description: @@ -62,7 +62,7 @@ * Return Value: * 0 (OK) on success; a negated errno value on failure. * - *****************************************************************************/ + ****************************************************************************/ static int group_killchildren_handler(pid_t pid, FAR void *arg) { diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 7fadb31fc4..2bc3015e24 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_leave.c * * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -56,23 +56,23 @@ #ifdef HAVE_TASK_GROUP -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_remove * * Description: @@ -88,7 +88,7 @@ * Called during task deletion in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) static void group_remove(FAR struct task_group_s *group) @@ -131,7 +131,7 @@ static void group_remove(FAR struct task_group_s *group) } #endif -/***************************************************************************** +/**************************************************************************** * Name: group_release * * Description: @@ -147,7 +147,7 @@ static void group_remove(FAR struct task_group_s *group) * Called during task deletion in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ static inline void group_release(FAR struct task_group_s *group) { @@ -276,7 +276,7 @@ static inline void group_release(FAR struct task_group_s *group) sched_kfree(group); } -/***************************************************************************** +/**************************************************************************** * Name: group_removemember * * Description: @@ -295,7 +295,7 @@ static inline void group_release(FAR struct task_group_s *group) * Called during task deletion and also from the reparenting logic, both * in a safe context. No special precautions are required here. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS static inline void group_removemember(FAR struct task_group_s *group, pid_t pid) @@ -327,11 +327,11 @@ static inline void group_removemember(FAR struct task_group_s *group, pid_t pid) } #endif /* HAVE_GROUP_MEMBERS */ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_leave * * Description: @@ -350,7 +350,7 @@ static inline void group_removemember(FAR struct task_group_s *group, pid_t pid) * Called during task deletion in a safe context. No special precautions * are required here. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS void group_leave(FAR struct tcb_s *tcb) diff --git a/sched/group/group_signal.c b/sched/group/group_signal.c index 4569fdb9c7..565c8ffda8 100644 --- a/sched/group/group_signal.c +++ b/sched/group/group_signal.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/group/group_signal.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -51,13 +51,13 @@ #if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_SIGNALS) -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS struct group_signal_s @@ -70,15 +70,15 @@ struct group_signal_s }; #endif -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_signal_handler * * Description: @@ -91,7 +91,7 @@ struct group_signal_s * Return Value: * 0 (OK) on success; a negated errno value on failure. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS static int group_signal_handler(pid_t pid, FAR void *arg) @@ -191,11 +191,11 @@ static int group_signal_handler(pid_t pid, FAR void *arg) } #endif -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: group_signal * * Description: @@ -213,7 +213,7 @@ static int group_signal_handler(pid_t pid, FAR void *arg) * this function may be called indirectly in the context of an interrupt * handler. * - *****************************************************************************/ + ****************************************************************************/ int group_signal(FAR struct task_group_s *group, FAR siginfo_t *siginfo) { diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index d0c13a717d..eaf9931a68 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -66,7 +66,7 @@ /**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ /**************************************************************************** * Name: pthread_getschedparam diff --git a/sched/sched/sched_wait.c b/sched/sched/sched_wait.c index d2efd8ee2a..553ec529dd 100644 --- a/sched/sched/sched_wait.c +++ b/sched/sched/sched_wait.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/sched/sched_wait.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -49,15 +49,15 @@ #if defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT) -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: wait * * Description: @@ -80,7 +80,7 @@ * Returned Value: * See waitpid(); * - *****************************************************************************/ + ****************************************************************************/ pid_t wait(FAR int *stat_loc) { diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index ca9054ba88..9e49f9a1cd 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/sched/sched_waitid.c * * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -50,18 +50,18 @@ #if defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT) -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: exited_child * * Description: * Handle the case where a child exited properlay was we (apparently) lost * the detch of child signal. * - *****************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_SCHED_CHILD_STATUS static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *child, @@ -85,11 +85,11 @@ static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *chil } #endif -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: waitid * * Description: @@ -150,7 +150,7 @@ static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *chil * EINVAL - An invalid value was specified for options, or idtype and id * specify an invalid set of processes. * - *****************************************************************************/ + ****************************************************************************/ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 13241bf780..55d2ef3bc2 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/sched/sched_waitpid.c * * Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -51,15 +51,15 @@ #ifdef CONFIG_SCHED_WAITPID -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: waitpid * * Description: @@ -176,7 +176,7 @@ * defined), then waitpid() is still available, but does not obey the * restriction that the pid be a child of the caller. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_SCHED_HAVE_PARENT pid_t waitpid(pid_t pid, int *stat_loc, int options) diff --git a/sched/task/task_getgroup.c b/sched/task/task_getgroup.c index 0145709c57..6b18aaac14 100644 --- a/sched/task/task_getgroup.c +++ b/sched/task/task_getgroup.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/task/task_getgroup.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -47,31 +47,31 @@ #ifdef HAVE_TASK_GROUP -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: task_getgroup * * Description: @@ -90,7 +90,7 @@ * precautions should be required here. However, extra care is taken when * accessing the global g_grouphead list. * - *****************************************************************************/ + ****************************************************************************/ FAR struct task_group_s *task_getgroup(pid_t pid) { diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index 424356457a..7ce7feed9c 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * sched/task/task_reparent.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include @@ -47,15 +47,15 @@ #ifdef CONFIG_SCHED_HAVE_PARENT -/***************************************************************************** +/**************************************************************************** * Private Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Functions - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: task_reparent * * Description: @@ -69,7 +69,7 @@ * Return Value: * 0 (OK) on success; A negated errno value on failure. * - *****************************************************************************/ + ****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS int task_reparent(pid_t ppid, pid_t chpid) -- GitLab From 863ded358446f7c868be3fddb557204c52ff4d22 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 3 Oct 2015 07:45:15 -0600 Subject: [PATCH 188/858] Standardize the width of all comment boxes in C header files --- arch | 2 +- configs | 2 +- drivers/wireless/cc3000/cc3000_socket.h | 80 +++++++++--------- drivers/wireless/cc3000/cc3000drv.h | 18 ++-- drivers/wireless/cc3000/host_driver_version.h | 2 +- drivers/wireless/cc3000/spi_version.h | 2 +- include/nuttx/board.h | 2 +- include/nuttx/lcd/memlcd.h | 28 +++---- include/nuttx/usb/usbdev_trace.h | 16 ++-- include/nuttx/usb/usbhost.h | 8 +- include/nuttx/usb/usbhost_devaddr.h | 38 ++++----- include/nuttx/wireless/cc3000.h | 4 +- include/nuttx/wireless/cc3000/cc3000_common.h | 52 ++++++------ include/nuttx/wireless/cc3000/evnt_handler.h | 2 +- include/nuttx/wireless/cc3000/hci.h | 36 ++++---- .../wireless/cc3000/include/sys/socket.h | 80 +++++++++--------- include/nuttx/wireless/cc3000/netapp.h | 56 ++++++------- include/nuttx/wireless/cc3000/nvmem.h | 48 +++++------ include/nuttx/wireless/cc3000/security.h | 36 ++++---- include/nuttx/wireless/cc3000/wlan.h | 84 +++++++++---------- 20 files changed, 298 insertions(+), 298 deletions(-) diff --git a/arch b/arch index 5fa7ebb25b..0c8200c21f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5fa7ebb25b9d0b3f58d987ec3255709fa70ef368 +Subproject commit 0c8200c21f76a67e621d364b51e73bda4f6ba28c diff --git a/configs b/configs index d074eda220..87c0e8d612 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d074eda220e892489e53a3cca49165619b18a607 +Subproject commit 87c0e8d6124f7e0ec849e5430534eedd9495aba9 diff --git a/drivers/wireless/cc3000/cc3000_socket.h b/drivers/wireless/cc3000/cc3000_socket.h index 4287e9cf5d..0218221abc 100644 --- a/drivers/wireless/cc3000/cc3000_socket.h +++ b/drivers/wireless/cc3000/cc3000_socket.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * drivers/wireless/cc3000_socket.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,7 +30,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef __DRIVERS_WIRELESS_CC3000_SOCKET_H #define __DRIVERS_WIRELESS_CC3000_SOCKET_H @@ -43,9 +43,9 @@ #include #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define CC3000_HOSTNAME_MAX_LENGTH (230) /* 230 bytes + header shouldn't exceed 8 * bit value */ @@ -150,9 +150,9 @@ sockaddr.sa_data[4] = 0x0; \ sockaddr.sa_data[5] = 0xfb; -/***************************************************************************** +/**************************************************************************** * Public Types - *****************************************************************************/ + ****************************************************************************/ /* The fd_set member is required to be an array of longs. */ @@ -165,19 +165,19 @@ typedef struct __fd_mask fds_bits[CC3000_FD_SETSIZE / __NFDBITS]; } TICC3000fd_set; -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: cc3000_socket_impl * * Decription: @@ -198,11 +198,11 @@ extern "C" { * On success, socket handle that is used for consequent socket * operations. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_socket_impl(long domain, long type, long protocol); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_closesocket_impl * * Decription: @@ -214,11 +214,11 @@ int cc3000_socket_impl(long domain, long type, long protocol); * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_closesocket_impl(long sd); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_accept_impl * * Decription: @@ -261,11 +261,11 @@ long cc3000_closesocket_impl(long sd); * - On connection pending, SOC_IN_PROGRESS (-2) * - On failure, SOC_ERROR (-1) * - *****************************************************************************/ + ****************************************************************************/ long cc3000_accept_impl(long sd, struct sockaddr *addr, socklen_t *addrlen); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_bind_impl * * Decription: @@ -286,11 +286,11 @@ long cc3000_accept_impl(long sd, struct sockaddr *addr, socklen_t *addrlen); * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_bind_impl(long sd, FAR const struct sockaddr *addr, socklen_t addrlen); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_listen_impl * * Decription: @@ -312,11 +312,11 @@ long cc3000_bind_impl(long sd, FAR const struct sockaddr *addr, socklen_t addrle * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ long cc3000_listen_impl(long sd, long backlog); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_connect_impl * * Decription: @@ -344,11 +344,11 @@ long cc3000_listen_impl(long sd, long backlog); * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ long cc3000_connect_impl(long sd, FAR const struct sockaddr *addr, socklen_t addrlen); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_select_impl * * Decription: @@ -385,7 +385,7 @@ long cc3000_connect_impl(long sd, FAR const struct sockaddr *addr, socklen_t add * will return without delay. * *exceptfds - return the sockets which closed recently. * - *****************************************************************************/ + ****************************************************************************/ struct timeval; @@ -396,7 +396,7 @@ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, #ifndef CC3000_TINY_DRIVER -/***************************************************************************** +/**************************************************************************** * Name: cc3000_setsockopt_impl * * Decription: @@ -442,12 +442,12 @@ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_setsockopt_impl(long sd, long level, long optname, const void *optval, socklen_t optlen); #endif -/***************************************************************************** +/**************************************************************************** * Name: cc3000_getsockopt_impl * * Decription: @@ -493,12 +493,12 @@ int cc3000_setsockopt_impl(long sd, long level, long optname, const void *optval * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int cc3000_getsockopt_impl(long sd, long level, long optname, void *optval, socklen_t *optlen); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_recv_impl * * Decription: @@ -518,11 +518,11 @@ int cc3000_getsockopt_impl(long sd, long level, long optname, void *optval, sock * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_recv_impl(long sd, void *buf, long len, long flags); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_recvfrom_impl * * Decription: @@ -549,12 +549,12 @@ int cc3000_recv_impl(long sd, void *buf, long len, long flags); * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_recvfrom_impl(long sd, void *buf, long len, long flags, struct sockaddr *from, socklen_t *fromlen); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_send_impl * * Decription: @@ -574,11 +574,11 @@ int cc3000_recvfrom_impl(long sd, void *buf, long len, long flags, * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_send_impl(long sd, const void *buf, long len, long flags); -/***************************************************************************** +/**************************************************************************** * Name: cc3000_sendto_impl * * Decription: @@ -602,13 +602,13 @@ int cc3000_send_impl(long sd, const void *buf, long len, long flags); * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ int cc3000_sendto_impl(long sd, FAR const void *buf, long len, long flags, FAR const struct sockaddr *to, socklen_t tolen); #ifndef CC3000_TINY_DRIVER -/***************************************************************************** +/**************************************************************************** * Name: cc3000_gethostbyname_impl * * Decription: @@ -629,13 +629,13 @@ int cc3000_sendto_impl(long sd, FAR const void *buf, long len, long flags, * Returned Value: * On success, positive is returned. On error, negative is returned * - *****************************************************************************/ + ****************************************************************************/ //struct hostent *gethostbyname(const char *name); int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long* out_ip_addr); #endif -/***************************************************************************** +/**************************************************************************** * Name: cc3000_mdnsAdvertiser_impl * * Decription: @@ -651,7 +651,7 @@ int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long * On success, zero is returned, return SOC_ERROR if socket was not * opened successfully, or if an error occurred. * - *****************************************************************************/ + ****************************************************************************/ int cc3000_mdnsadvertiser_impl(uint16_t mdnsEnabled, char * deviceServiceName, uint16_t deviceServiceNameLength); diff --git a/drivers/wireless/cc3000/cc3000drv.h b/drivers/wireless/cc3000/cc3000drv.h index 7c8af0e9b7..4c67fa2fe4 100644 --- a/drivers/wireless/cc3000/cc3000drv.h +++ b/drivers/wireless/cc3000/cc3000drv.h @@ -33,31 +33,31 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef __DRIVERS_WIRELESS_CC3000_CC3000DRV_H #define __DRIVERS_WIRELESS_CC3000_CC3000DRV_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include #include -/***************************************************************************** +/**************************************************************************** * Public Types - *****************************************************************************/ + ****************************************************************************/ typedef void (*gcSpiHandleRx)(void *p); -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" diff --git a/drivers/wireless/cc3000/host_driver_version.h b/drivers/wireless/cc3000/host_driver_version.h index 70204b17fa..e191ba1ae0 100644 --- a/drivers/wireless/cc3000/host_driver_version.h +++ b/drivers/wireless/cc3000/host_driver_version.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * * host_driver_version.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ diff --git a/drivers/wireless/cc3000/spi_version.h b/drivers/wireless/cc3000/spi_version.h index 0ca1516f99..607988fb0e 100644 --- a/drivers/wireless/cc3000/spi_version.h +++ b/drivers/wireless/cc3000/spi_version.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * * spi_version.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 6a22d515af..74431a16eb 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -301,7 +301,7 @@ struct fb_vtable_s; FAR struct fb_vtable_s *board_graphics_setup(unsigned int devno); #endif -/***************************************************************************** +/**************************************************************************** * Name: board_can_initialize * * Description: diff --git a/include/nuttx/lcd/memlcd.h b/include/nuttx/lcd/memlcd.h index 629e79cfa1..afdc7bf3bd 100644 --- a/include/nuttx/lcd/memlcd.h +++ b/include/nuttx/lcd/memlcd.h @@ -1,4 +1,4 @@ -/******************************************************************************* +/**************************************************************************** * include/nuttx/lcd/memlcd.h * Common definitions for the Sharp Memory LCD driver * @@ -32,14 +32,14 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ******************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_NUTTX_MEMLCD_H #define __INCLUDE_NUTTX_MEMLCD_H -/******************************************************************************* +/**************************************************************************** * Included Files - ******************************************************************************/ + ****************************************************************************/ #include @@ -51,13 +51,13 @@ extern "C" # define EXTERN extern #endif -/******************************************************************************* +/**************************************************************************** * Pre-processor Definitions - ******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Public Types - ******************************************************************************/ + ****************************************************************************/ /* A reference to a structure of this type must be passed to the initialization * method. It provides some board-specific hooks used by driver to manage the @@ -89,15 +89,15 @@ struct memlcd_priv_s void (*setvcomfreq) (unsigned int freq); }; -/******************************************************************************* +/**************************************************************************** * Public Data - ******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Public Function Prototypes - ******************************************************************************/ + ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: memlcd_initialize * * Description: @@ -114,7 +114,7 @@ struct memlcd_priv_s * On success, this function returns a reference to the LCD object for the * specified LCD. NULL is returned on any failure. * - ******************************************************************************/ + ****************************************************************************/ struct lcd_dev_s; /* see nuttx/lcd.h */ struct spi_dev_s; /* see nuttx/spi/spi.h */ diff --git a/include/nuttx/usb/usbdev_trace.h b/include/nuttx/usb/usbdev_trace.h index b05eaca210..445ef5f560 100644 --- a/include/nuttx/usb/usbdev_trace.h +++ b/include/nuttx/usb/usbdev_trace.h @@ -462,7 +462,7 @@ EXTERN const struct trace_msg_t g_usb_trace_strings_intdecode[]; * Public Function Prototypes ****************************************************************************/ -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_enable * * Description: @@ -478,7 +478,7 @@ EXTERN const struct trace_msg_t g_usb_trace_strings_intdecode[]; * Assumptions: * - May be called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_USBDEV_TRACE) || (defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_USB)) usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset); @@ -486,7 +486,7 @@ usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset); # define usbtrace_enable(idset) #endif -/******************************************************************************* +/**************************************************************************** * Name: usbtrace * * Description: @@ -495,7 +495,7 @@ usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset); * Assumptions: * May be called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #if defined(CONFIG_USBDEV_TRACE) || (defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_USB)) void usbtrace(uint16_t event, uint16_t value); @@ -503,7 +503,7 @@ void usbtrace(uint16_t event, uint16_t value); # define usbtrace(event, value) #endif -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_enumerate * * Description: @@ -512,7 +512,7 @@ void usbtrace(uint16_t event, uint16_t value); * Assumptions: * NEVER called from an interrupt handler * - *******************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_USBDEV_TRACE int usbtrace_enumerate(trace_callback_t callback, void *arg); @@ -520,13 +520,13 @@ int usbtrace_enumerate(trace_callback_t callback, void *arg); # define usbtrace_enumerate(event) #endif -/******************************************************************************* +/**************************************************************************** * Name: usbtrace_trprint * * Description: * Print the trace record using the supplied printing function * - *******************************************************************************/ + ****************************************************************************/ void usbtrace_trprintf(trprintf_t trprintf, uint16_t event, uint16_t value); diff --git a/include/nuttx/usb/usbhost.h b/include/nuttx/usb/usbhost.h index 1e72ae2635..587917701c 100644 --- a/include/nuttx/usb/usbhost.h +++ b/include/nuttx/usb/usbhost.h @@ -163,7 +163,7 @@ #define CLASS_DISCONNECTED(devclass) ((devclass)->disconnected(devclass)) -/******************************************************************************* +/**************************************************************************** * Name: CONN_WAIT * * Description: @@ -186,7 +186,7 @@ * - Called from a single thread so no mutual exclusion is required. * - Never called from an interrupt handler. * - *******************************************************************************/ + ****************************************************************************/ #define CONN_WAIT(conn,hport) ((conn)->wait(conn,hport)) @@ -1103,7 +1103,7 @@ int usbhost_mouse_init(void); int usbhost_wlaninit(void); -/******************************************************************************* +/**************************************************************************** * Name: usbhost_enumerate * * Description: @@ -1135,7 +1135,7 @@ int usbhost_wlaninit(void); * - Called from a single thread so no mutual exclusion is required. * - Never called from an interrupt handler. * - *******************************************************************************/ + ****************************************************************************/ int usbhost_enumerate(FAR struct usbhost_hubport_s *hub, FAR struct usbhost_class_s **devclass); diff --git a/include/nuttx/usb/usbhost_devaddr.h b/include/nuttx/usb/usbhost_devaddr.h index 718d804cae..df4514f395 100644 --- a/include/nuttx/usb/usbhost_devaddr.h +++ b/include/nuttx/usb/usbhost_devaddr.h @@ -1,4 +1,4 @@ -/******************************************************************************* +/**************************************************************************** * include/nuttx/usb/usbhost_devaddr.h * Manage USB device addresses * @@ -38,31 +38,31 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - *******************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_USB_USBHOST_DEVADDR_H #define _INCLUDE_NUTTX_USB_USBHOST_DEVADDR_H -/******************************************************************************* +/**************************************************************************** * Included Files - *******************************************************************************/ + ****************************************************************************/ #include #include #include -/******************************************************************************* +/**************************************************************************** * Pre-processor Definitions - *******************************************************************************/ -/* Configuration ***************************************************************/ + ****************************************************************************/ +/* Configuration ************************************************************/ #define USBHOST_DEVADDR_HASHSIZE 8 #define USBHOST_DEVADDR_HASHMASK (USBHOST_DEVADDR_HASHSIZE-1) -/******************************************************************************* +/**************************************************************************** * Public Types - *******************************************************************************/ + ****************************************************************************/ struct usbhost_devaddr_s { @@ -71,9 +71,9 @@ struct usbhost_devaddr_s uint32_t alloctab[4]; /* Bit allocation table */ }; -/******************************************************************************* +/**************************************************************************** * Public Data - *******************************************************************************/ + ****************************************************************************/ #undef EXTERN #if defined(__cplusplus) @@ -84,14 +84,14 @@ extern "C" # define EXTERN extern #endif -/******************************************************************************* +/**************************************************************************** * Public Functions - *******************************************************************************/ + ****************************************************************************/ struct usbhost_hubport_s; /* Forward reference */ struct usbhost_roothubport_s; /* Forward reference */ -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_initialize * * Description: @@ -105,11 +105,11 @@ struct usbhost_roothubport_s; /* Forward reference */ * Returned Value: * None * - *******************************************************************************/ + ****************************************************************************/ void usbhost_devaddr_initialize(FAR struct usbhost_roothubport_s *rhport); -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_create * * Description: @@ -123,11 +123,11 @@ void usbhost_devaddr_initialize(FAR struct usbhost_roothubport_s *rhport); * On success, a new device function address in the the range 0x01 to 0x7f * is returned. On failure, a negated errno value is returned. * - *******************************************************************************/ + ****************************************************************************/ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport); -/******************************************************************************* +/**************************************************************************** * Name: usbhost_devaddr_destroy * * Description: @@ -141,7 +141,7 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport); * Returned Value: * None * - *******************************************************************************/ + ****************************************************************************/ void usbhost_devaddr_destroy(FAR struct usbhost_hubport_s *hport, uint8_t devaddr); diff --git a/include/nuttx/wireless/cc3000.h b/include/nuttx/wireless/cc3000.h index 6747bd7193..f369dc0794 100644 --- a/include/nuttx/wireless/cc3000.h +++ b/include/nuttx/wireless/cc3000.h @@ -110,7 +110,7 @@ extern "C" #define EXTERN extern #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_init * * Description: @@ -146,7 +146,7 @@ extern "C" * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void wlan_init(size_t max_tx_len, tWlanCB sWlanCB, tFWPatches sFWPatches, diff --git a/include/nuttx/wireless/cc3000/cc3000_common.h b/include/nuttx/wireless/cc3000/cc3000_common.h index b28ef353c8..4a11f74591 100644 --- a/include/nuttx/wireless/cc3000/cc3000_common.h +++ b/include/nuttx/wireless/cc3000/cc3000_common.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * cc3000_common.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,14 +30,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_CC3000_COMMON_H #define _INCLUDE_NUTTX_WIRELESS_CC3000_CC3000_COMMON_H -/***************************************************************************** +/**************************************************************************** * Included files - *****************************************************************************/ + ****************************************************************************/ #include #include @@ -46,9 +46,9 @@ #include #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* Error codes */ @@ -199,9 +199,9 @@ #define STREAM_TO_STREAM(p, a, l) {register int16_t _i; for (_i = 0; _i < l; _i++) *(a)++= ((uint8_t *) p)[_i];} -/***************************************************************************** +/**************************************************************************** * Public Types - *****************************************************************************/ + ****************************************************************************/ typedef struct wlan_buffer_desc_s { @@ -250,9 +250,9 @@ typedef struct uint8_t InformHostOnTxComplete; } sSimplLinkInformation; -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" @@ -261,11 +261,11 @@ extern "C" extern volatile sSimplLinkInformation tSLInformation; -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: wlan_get_buffer * * Input Parameters: @@ -274,11 +274,11 @@ extern volatile sSimplLinkInformation tSLInformation; * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void wlan_get_buffer(wlan_buffer_desc *pdes); -/***************************************************************************** +/**************************************************************************** * Name: SimpleLinkWaitEvent * * Description: @@ -292,11 +292,11 @@ void wlan_get_buffer(wlan_buffer_desc *pdes); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void SimpleLinkWaitEvent(uint16_t usOpcode, void *pRetParams); -/***************************************************************************** +/**************************************************************************** * Name: SimpleLinkWaitData * * Description: @@ -311,11 +311,11 @@ void SimpleLinkWaitEvent(uint16_t usOpcode, void *pRetParams); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen); -/***************************************************************************** +/**************************************************************************** * Name: UINT32_TO_STREAM_f * * Description: @@ -329,11 +329,11 @@ void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen); * Returned Value: * Pointer to the new stream * - *****************************************************************************/ + ****************************************************************************/ uint8_t *UINT32_TO_STREAM_f(uint8_t *p, unsigned long u32); -/***************************************************************************** +/**************************************************************************** * Name: UINT16_TO_STREAM_f * * Description: @@ -347,11 +347,11 @@ uint8_t *UINT32_TO_STREAM_f(uint8_t *p, unsigned long u32); * Returned Value: * Pointer to the new stream * - *****************************************************************************/ + ****************************************************************************/ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16); -/***************************************************************************** +/**************************************************************************** * Name: STREAM_TO_UINT16_f * * Description: @@ -365,11 +365,11 @@ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16); * Returned Value: * Pointer to the new 16 bit * - *****************************************************************************/ + ****************************************************************************/ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset); -/***************************************************************************** +/**************************************************************************** * Name: STREAM_TO_UINT32_f * * Description: @@ -383,7 +383,7 @@ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset); * Returned Value: * Pointer to the new 32 bit * - *****************************************************************************/ + ****************************************************************************/ unsigned long STREAM_TO_UINT32_f(char* p, uint16_t offset); diff --git a/include/nuttx/wireless/cc3000/evnt_handler.h b/include/nuttx/wireless/cc3000/evnt_handler.h index 6ffaa2c369..fe5f4ecdad 100644 --- a/include/nuttx/wireless/cc3000/evnt_handler.h +++ b/include/nuttx/wireless/cc3000/evnt_handler.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * * evnt_handler.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ diff --git a/include/nuttx/wireless/cc3000/hci.h b/include/nuttx/wireless/cc3000/hci.h index 42c162b4e4..409fd9d1e9 100644 --- a/include/nuttx/wireless/cc3000/hci.h +++ b/include/nuttx/wireless/cc3000/hci.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * hci.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,20 +30,20 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_HCI_H #define _INCLUDE_NUTTX_WIRELESS_CC3000_HCI_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include "cc3000_common.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define SPI_HEADER_SIZE (5) #define SIMPLE_LINK_HCI_CMND_HEADER_SIZE (4) @@ -197,20 +197,20 @@ #define HCI_EVENT_STATUS_OFFSET (4) #define HCI_DATA_LENGTH_OFFSET (3) -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Name: hci_command_send * * Description: @@ -224,13 +224,13 @@ extern "C" * Returned Value: * Zero * - *****************************************************************************/ + ****************************************************************************/ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLength); -/****************************************************************************** +/**************************************************************************** * Name: hci_data_send * * Description: @@ -246,13 +246,13 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, uint16_t usDataLength, const uint8_t *ucTail, uint16_t usTailLength); -/****************************************************************************** +/**************************************************************************** * Name: hci_data_command_send * * Description: @@ -267,12 +267,12 @@ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, uint8_t ucArgsLength,uint16_t ucDataLength); -/****************************************************************************** +/**************************************************************************** * Name: hci_patch_send * * Description: @@ -287,7 +287,7 @@ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void hci_patch_send(uint8_t ucOpcode, uint8_t *pucBuff, char *patch, uint16_t usDataLength); diff --git a/include/nuttx/wireless/cc3000/include/sys/socket.h b/include/nuttx/wireless/cc3000/include/sys/socket.h index 87e39c9501..f40f7b6406 100644 --- a/include/nuttx/wireless/cc3000/include/sys/socket.h +++ b/include/nuttx/wireless/cc3000/include/sys/socket.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * socket.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,7 +30,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_NUTTX_WIRELESS_CC3000_INCLUDE_SYS_SOCKET_H #define __INCLUDE_NUTTX_WIRELESS_CC3000_INCLUDE_SYS_SOCKET_H @@ -43,9 +43,9 @@ #include #include -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define socket(a,t,p) cc3000_socket(a,t,p) #define closesocket(s) cc3000_closesocket(s) @@ -62,24 +62,24 @@ #define gethostbyname(h,l,i) cc3000_gethostbyname(h,l,i) #define mdnsadvertiser(e,n,l) cc3000_mdnsadvertiser(e,n,l) -/***************************************************************************** +/**************************************************************************** * Public Types - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: socket * * Decription: @@ -100,11 +100,11 @@ extern "C" * On success, socket handle that is used for consequent socket * operations. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int socket(int domain, int type, int protocol); -/***************************************************************************** +/**************************************************************************** * Name: closesocket * * Decription: @@ -116,11 +116,11 @@ int socket(int domain, int type, int protocol); * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int closesocket(int sockfd); -/***************************************************************************** +/**************************************************************************** * Name: accept * * Decription: @@ -163,11 +163,11 @@ int closesocket(int sockfd); * - On connection pending, SOC_IN_PROGRESS (-2) * - On failure, SOC_ERROR (-1) * - *****************************************************************************/ + ****************************************************************************/ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); -/***************************************************************************** +/**************************************************************************** * Name: bind * * Decription: @@ -188,11 +188,11 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); -/***************************************************************************** +/**************************************************************************** * Name: listen * * Decription: @@ -214,11 +214,11 @@ int bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ int listen(int sockfd, int backlog); -/***************************************************************************** +/**************************************************************************** * Name: connect * * Decription: @@ -246,11 +246,11 @@ int listen(int sockfd, int backlog); * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); -/***************************************************************************** +/**************************************************************************** * Name: select * * Decription: @@ -287,14 +287,14 @@ int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); * will return without delay. * *exceptfds - return the sockets which closed recently. * - *****************************************************************************/ + ****************************************************************************/ struct timeval; int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout); #ifndef CC3000_TINY_DRIVER -/***************************************************************************** +/**************************************************************************** * Name: setsockopt * * Decription: @@ -340,12 +340,12 @@ int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int setsockopt(int sockfd, int level, int option, FAR const void *value, socklen_t value_len); #endif -/***************************************************************************** +/**************************************************************************** * Name: getsockopt * * Decription: @@ -391,11 +391,11 @@ int setsockopt(int sockfd, int level, int option, FAR const void *value, socklen * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ int getsockopt(int sockfd, int level, int option, FAR void *value, FAR socklen_t *value_len); -/***************************************************************************** +/**************************************************************************** * Name: recv * * Decription: @@ -415,11 +415,11 @@ int getsockopt(int sockfd, int level, int option, FAR void *value, FAR socklen_t * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags); -/***************************************************************************** +/**************************************************************************** * Name: recvfrom * * Decription: @@ -446,12 +446,12 @@ ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags); * Return the number of bytes received, or -1 if an error * occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct sockaddr *from, FAR socklen_t *fromlen); -/***************************************************************************** +/**************************************************************************** * Name: send * * Decription: @@ -471,11 +471,11 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags); -/***************************************************************************** +/**************************************************************************** * Name: sendto * * Decription: @@ -499,13 +499,13 @@ ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags); * Return the number of bytes transmitted, or -1 if an * error occurred * - *****************************************************************************/ + ****************************************************************************/ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags, FAR const struct sockaddr *to, socklen_t tolen); #ifndef CC3000_TINY_DRIVER -/***************************************************************************** +/**************************************************************************** * Name: gethostbyname * * Decription: @@ -526,12 +526,12 @@ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags, * Returned Value: * On success, positive is returned. On error, negative is returned * - *****************************************************************************/ + ****************************************************************************/ int gethostbyname(char * hostname, uint16_t usNameLen, unsigned long* out_ip_addr); #endif -/***************************************************************************** +/**************************************************************************** * Name: mdnsAdvertiser * * Decription: @@ -547,7 +547,7 @@ int gethostbyname(char * hostname, uint16_t usNameLen, unsigned long* out_ip_add * On success, zero is returned, return SOC_ERROR if socket was not * opened successfully, or if an error occurred. * - *****************************************************************************/ + ****************************************************************************/ int mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, uint16_t deviceServiceNameLength); diff --git a/include/nuttx/wireless/cc3000/netapp.h b/include/nuttx/wireless/cc3000/netapp.h index 8d0785c73c..e42b5876a4 100644 --- a/include/nuttx/wireless/cc3000/netapp.h +++ b/include/nuttx/wireless/cc3000/netapp.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * netapp.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,18 +30,18 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_NETAPP_H #define _INCLUDE_NUTTX_WIRELESS_CC3000_NETAPP_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Public Types - *****************************************************************************/ + ****************************************************************************/ typedef struct _netapp_dhcp_ret_args_t { @@ -74,20 +74,20 @@ typedef struct _netapp_pingreport_args unsigned long avg_round_time; } netapp_pingreport_args_t; -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Name: netapp_config_mac_adrress * * Description: @@ -101,11 +101,11 @@ extern "C" * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ long netapp_config_mac_adrress(uint8_t *mac); -/****************************************************************************** +/**************************************************************************** * Name: netapp_dhcp * * Description: @@ -130,12 +130,12 @@ long netapp_config_mac_adrress(uint8_t *mac); * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, unsigned long *aucDefaultGateway, unsigned long *aucDNSServer); -/****************************************************************************** +/**************************************************************************** * Name: netapp_timeout_values * * Description: @@ -183,7 +183,7 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, @@ -191,7 +191,7 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, unsigned long *aucInactivity); #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_send * * Description: @@ -213,14 +213,14 @@ long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, * Returned Value: * Return on success 0, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout); #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_stop * * Description: @@ -232,13 +232,13 @@ long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, * Returned Value: * On success, zero is returned. On error, -1 is returned. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_ping_stop(void); #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ping_report * * Description: @@ -263,14 +263,14 @@ long netapp_ping_stop(void); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER void netapp_ping_report(void); #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_ipconfig * * Description: @@ -298,11 +298,11 @@ void netapp_ping_report(void); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig); -/****************************************************************************** +/**************************************************************************** * Name: netapp_arp_flush * * Description: @@ -314,13 +314,13 @@ void netapp_ipconfig(tNetappIpconfigRetArgs * ipconfig); * Returned Value: * None * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_arp_flush(void); #endif -/****************************************************************************** +/**************************************************************************** * Name: netapp_set_debug_level * * Description: @@ -344,7 +344,7 @@ long netapp_arp_flush(void); * Returned Value: * On success, zero is returned. On error, -1 is returned * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long netapp_set_debug_level(unsigned long ulLevel); diff --git a/include/nuttx/wireless/cc3000/nvmem.h b/include/nuttx/wireless/cc3000/nvmem.h index 35902def69..f9b3b48695 100644 --- a/include/nuttx/wireless/cc3000/nvmem.h +++ b/include/nuttx/wireless/cc3000/nvmem.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * nvmem.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,20 +30,20 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_NVMEM_H #define _INCLUDE_NUTTX_WIRELESS_CC3000_NVMEM_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include "cc3000_common.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ /* NVMEM file ID - system files*/ @@ -69,20 +69,20 @@ #define NVMEM_MAX_ENTRY (16) -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/****************************************************************************** +/**************************************************************************** * Name: nvmem_read * * Description: @@ -106,12 +106,12 @@ extern "C" * Returned Value: * Number of bytes read, otherwise error. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, uint8_t *buff); -/****************************************************************************** +/**************************************************************************** * Name: nvmem_write * * Description: @@ -132,12 +132,12 @@ signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, uint8_t *buff); -/****************************************************************************** +/**************************************************************************** * Name: nvmem_set_mac_address * * Description: @@ -150,11 +150,11 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_set_mac_address(uint8_t *mac); -/****************************************************************************** +/**************************************************************************** * Name: nvmem_get_mac_address * * Description: @@ -167,11 +167,11 @@ uint8_t nvmem_set_mac_address(uint8_t *mac); * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_get_mac_address(uint8_t *mac); -/****************************************************************************** +/**************************************************************************** * Name: nvmem_write_patch * * Description: @@ -188,12 +188,12 @@ uint8_t nvmem_get_mac_address(uint8_t *mac); * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const uint8_t *spData); -/****************************************************************************** +/**************************************************************************** * Name: nvmem_read_sp_version * * Description: @@ -207,13 +207,13 @@ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER uint8_t nvmem_read_sp_version(uint8_t *patchVer); #endif -/****************************************************************************** +/**************************************************************************** * Name: nvmem_create_entry * * Description: @@ -233,7 +233,7 @@ uint8_t nvmem_read_sp_version(uint8_t *patchVer); * Returned Value: * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen); diff --git a/include/nuttx/wireless/cc3000/security.h b/include/nuttx/wireless/cc3000/security.h index c3ed8f40e7..4a57340bb1 100644 --- a/include/nuttx/wireless/cc3000/security.h +++ b/include/nuttx/wireless/cc3000/security.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * security.h - CC3000 Host Driver Implementation. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * @@ -30,39 +30,39 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_SECURITY_H #define _INCLUDE_NUTTX_WIRELESS_CC3000_SECURITY_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include "nvmem.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define AES128_KEY_SIZE 16 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes -/***************************************************************************** +/**************************************************************************** -/***************************************************************************** +/**************************************************************************** * Name: aes_encrypt * * Description: @@ -77,11 +77,11 @@ extern "C" * Returned Value * None * - *****************************************************************************/ + ****************************************************************************/ void aes_encrypt(uint8_t *state, uint8_t *key); -/***************************************************************************** +/**************************************************************************** * Name: aes_decrypt * * Description: @@ -96,11 +96,11 @@ void aes_encrypt(uint8_t *state, uint8_t *key); * Returned Value * None * - *****************************************************************************/ + ****************************************************************************/ void aes_decrypt(uint8_t *state, uint8_t *key); -/***************************************************************************** +/**************************************************************************** * Name: aes_read_key * * Description: @@ -113,11 +113,11 @@ void aes_decrypt(uint8_t *state, uint8_t *key); * Returned Value * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long aes_read_key(uint8_t *key); -/***************************************************************************** +/**************************************************************************** * Name: aes_write_key * * Description: @@ -130,7 +130,7 @@ signed long aes_read_key(uint8_t *key); * Returned Value * On success 0, error otherwise. * - *****************************************************************************/ + ****************************************************************************/ signed long aes_write_key(uint8_t *key); diff --git a/include/nuttx/wireless/cc3000/wlan.h b/include/nuttx/wireless/cc3000/wlan.h index 6acf62a56f..867ea2032b 100644 --- a/include/nuttx/wireless/cc3000/wlan.h +++ b/include/nuttx/wireless/cc3000/wlan.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/**************************************************************************** * include/nuttx/wireless/cc3000/wlan.h * * wlan.h - CC3000 Host Driver Implementation. @@ -32,40 +32,40 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - *****************************************************************************/ + ****************************************************************************/ #ifndef __INCLUDE_NUTTX_WIRELESS_CC3000_WLAN_H #define __INCLUDE_NUTTX_WIRELESS_CC3000_WLAN_H -/***************************************************************************** +/**************************************************************************** * Included Files - *****************************************************************************/ + ****************************************************************************/ #include "cc3000_common.h" -/***************************************************************************** +/**************************************************************************** * Pre-processor Definitions - *****************************************************************************/ + ****************************************************************************/ #define WLAN_SEC_UNSEC (0) #define WLAN_SEC_WEP (1) #define WLAN_SEC_WPA (2) #define WLAN_SEC_WPA2 (3) -/***************************************************************************** +/**************************************************************************** * Public Data - *****************************************************************************/ + ****************************************************************************/ #ifdef __cplusplus extern "C" { #endif -/***************************************************************************** +/**************************************************************************** * Public Function Prototypes - *****************************************************************************/ + ****************************************************************************/ -/***************************************************************************** +/**************************************************************************** * Name: wlan_init * * Input Parameters: @@ -109,14 +109,14 @@ extern "C" * * WARNING: This function must be called before ANY other wlan driver function * - *****************************************************************************/ + ****************************************************************************/ void wlan_init(size_t max_tx_len, tWlanCB sWlanCB, tFWPatches sFWPatches, tDriverPatches sDriverPatches, tBootLoaderPatches sBootLoaderPatches); -/***************************************************************************** +/**************************************************************************** * Name: wlan_start * * Input Parameters: @@ -141,11 +141,11 @@ void wlan_init(size_t max_tx_len, * WARNING: This function must be called after wlan_init and before any * other wlan API * - *****************************************************************************/ + ****************************************************************************/ void wlan_start(uint16_t usPatchesAvailableAtHost); -/***************************************************************************** +/**************************************************************************** * Name: wlan_stop * * Input Parameters: @@ -157,11 +157,11 @@ void wlan_start(uint16_t usPatchesAvailableAtHost); * Description: * Stop WLAN device by putting it into reset state. * - *****************************************************************************/ + ****************************************************************************/ void wlan_stop(void); -/***************************************************************************** +/**************************************************************************** * Name: wlan_connect * * Input Parameters: @@ -191,7 +191,7 @@ void wlan_stop(void); * type WEP, please confirm that the key is set as ASCII and not * as HEX. * - *****************************************************************************/ + ****************************************************************************/ #ifndef CC3000_TINY_DRIVER long wlan_connect(unsigned long ulSecType, FAR const char *ssid, @@ -201,7 +201,7 @@ long wlan_connect(unsigned long ulSecType, FAR const char *ssid, long wlan_connect(FAR const char *ssid, long ssid_len); #endif -/***************************************************************************** +/**************************************************************************** * Name: wlan_disconnect * * Input Parameters: @@ -213,11 +213,11 @@ long wlan_connect(FAR const char *ssid, long ssid_len); * Description: * Disconnect connection from AP. * - *****************************************************************************/ + ****************************************************************************/ long wlan_disconnect(void); -/***************************************************************************** +/**************************************************************************** * Name: wlan_add_profile * * Input Parameters: @@ -243,7 +243,7 @@ long wlan_disconnect(void); * profile based on security policy, signal strength, etc * parameters. All the profiles are stored in CC3000 NVMEM. * - *****************************************************************************/ + ****************************************************************************/ long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid, unsigned long ulSsidLen, uint8_t *ucBssid, @@ -253,7 +253,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid, unsigned long ulKeyMgmt, uint8_t* ucPf_OrKey, unsigned long ulPassPhraseLen); -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_del_profile * * Input Parameters: @@ -267,11 +267,11 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t* ucSsid, * * @Note In order to delete all stored profile, set index to 255. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_del_profile(unsigned long ulIndex); -/***************************************************************************** +/**************************************************************************** * Name: wlan_set_event_mask * * Input Parameters: @@ -293,11 +293,11 @@ long wlan_ioctl_del_profile(unsigned long ulIndex); * Mask event according to bit mask. In case that event is * masked (1), the device will not send the masked event to host. * - *****************************************************************************/ + ****************************************************************************/ long wlan_set_event_mask(unsigned long ulMask); -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_statusget * * Input Parameters: @@ -310,11 +310,11 @@ long wlan_set_event_mask(unsigned long ulMask); * Description: * get wlan status: disconnected, scanning, connecting or connected * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_statusget(void); -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_set_connection_policy * * Input Parameters: @@ -344,13 +344,13 @@ long wlan_ioctl_statusget(void); * enabled, the device will try to connect to any AP. * * Note that the policy settings are stored in the CC3000 NVMEM. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, unsigned long ulShouldUseFastConnect, unsigned long ulUseProfiles); -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_get_scan_results * * Input Parameters: @@ -381,11 +381,11 @@ long wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, * * NOTE: scan_timeout, is not supported on this version. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults); -/***************************************************************************** +/**************************************************************************** * Name: wlan_ioctl_set_scan_params * * Input Parameters: @@ -420,7 +420,7 @@ long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, uint8_t *ucResults * * @Note uiDefaultTxPower, is not supported on this version. * - *****************************************************************************/ + ****************************************************************************/ long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime, @@ -431,7 +431,7 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiDefaultTxPower, unsigned long *aiIntervalList); -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_start * * Input Parameters: @@ -450,11 +450,11 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable, * @Note An asynchronous event - Smart Config Done will be generated as soon * as the process finishes successfully. * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_start(unsigned long algoEncryptedFlag); -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_stop * * Input Parameters: @@ -466,11 +466,11 @@ long wlan_smart_config_start(unsigned long algoEncryptedFlag); * Description: * Stop the acquire profile procedure * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_stop(void); -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_set_prefix * * Input Parameters: @@ -485,11 +485,11 @@ long wlan_smart_config_stop(void); * * @Note The prefix is stored in CC3000 NVMEM * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_set_prefix(char* cNewPrefix); -/***************************************************************************** +/**************************************************************************** * Name: wlan_smart_config_process * * Input Parameters: @@ -504,7 +504,7 @@ long wlan_smart_config_set_prefix(char* cNewPrefix); * The encrypted data is decrypted and stored as a profile. * behavior is as defined by connection policy. * - *****************************************************************************/ + ****************************************************************************/ long wlan_smart_config_process(void); -- GitLab From 0b12dbf95dbee28eafd8f66208bb6cf75e1d423d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 4 Oct 2015 15:04:00 -0600 Subject: [PATCH 189/858] Fix some spacing problems --- arch | 2 +- binfmt/binfmt_exepath.c | 2 +- binfmt/symtab_findorderedbyname.c | 14 +++---- binfmt/symtab_findorderedbyvalue.c | 14 +++---- configs | 2 +- drivers/analog/dac.c | 16 ++++---- drivers/can.c | 16 ++++---- drivers/lcd/mio283qt2.c | 2 +- drivers/lcd/mio283qt9a.c | 2 +- drivers/lcd/p14201.c | 2 +- drivers/lcd/ra8875.c | 2 +- drivers/lcd/ssd1289.c | 2 +- drivers/lcd/st7567.c | 8 ++-- drivers/lcd/ug-2864ambag01.c | 8 ++-- drivers/lcd/ug-9664hswag01.c | 8 ++-- drivers/mtd/at45db.c | 2 +- drivers/mtd/mtd_nand.c | 2 +- drivers/mtd/mtd_onfi.c | 2 +- drivers/mtd/st25fl1.c | 4 +- drivers/net/dm90x0.c | 8 ++-- drivers/net/enc28j60.c | 2 +- drivers/net/loopback.c | 6 +-- drivers/net/slip.c | 6 +-- drivers/pipes/pipe_common.c | 2 +- drivers/serial/serial.c | 7 +--- drivers/serial/uart_16550.c | 4 +- drivers/spi/spi_bitbang.c | 2 +- drivers/syslog/ramlog.c | 16 ++++---- drivers/timers/cs2100-cp.c | 2 +- drivers/usbdev/cdcacm.c | 2 +- drivers/usbdev/composite.c | 2 +- drivers/usbdev/pl2303.c | 2 +- drivers/usbdev/usbmsc_desc.c | 2 +- drivers/usbhost/usbhost_hidkbd.c | 2 +- drivers/usbhost/usbhost_hidmouse.c | 2 +- drivers/usbhost/usbhost_skeleton.c | 2 +- drivers/usbhost/usbhost_storage.c | 2 +- fs/driver/fs_devsyslog.c | 10 ++--- fs/fat/fs_fat32dirent.c | 4 +- fs/fat/fs_fat32util.c | 4 +- fs/fat/fs_writefat.c | 2 +- fs/mount/fs_foreachmountpoint.c | 2 +- fs/mount/fs_mount.c | 10 ++--- fs/nxffs/nxffs_util.c | 2 +- fs/semaphore/sem_open.c | 4 +- fs/unionfs/fs_unionfs.c | 2 +- fs/vfs/fs_mkdir.c | 4 +- fs/vfs/fs_open.c | 6 +-- fs/vfs/fs_rename.c | 6 +-- fs/vfs/fs_unlink.c | 4 +- graphics/nxsu/nx_mousein.c | 2 +- graphics/nxsu/nx_open.c | 2 +- graphics/nxterm/nxterm_kbdin.c | 16 ++++---- libc/fixedmath/lib_fixedmath.c | 60 ++++++++++++++--------------- libc/misc/lib_utsname.c | 2 +- libc/netdb/lib_gethostbyaddrr.c | 4 +- libc/netdb/lib_gethostbynamer.c | 12 +++--- libc/netdb/lib_parsehostfile.c | 2 +- libc/signal/sig_set.c | 2 +- libc/stdio/lib_stdinstream.c | 2 +- libc/stdio/lib_stdsistream.c | 2 +- libc/time/lib_settimeofday.c | 4 +- libc/unistd/lib_chdir.c | 10 ++--- mm/shm/shmdt.c | 2 +- net/arp/arp_out.c | 4 +- net/arp/arp_send.c | 2 +- net/arp/arp_timer.c | 2 +- net/icmpv6/icmpv6_autoconfig.c | 12 +++--- net/iob/iob_test.c | 10 ++--- net/local/local_conn.c | 2 +- net/socket/net_dupsd.c | 2 +- net/socket/net_sendfile.c | 6 +-- net/socket/recvfrom.c | 4 +- net/socket/socket.c | 6 +-- net/tcp/tcp_appsend.c | 2 +- net/tcp/tcp_ipselect.c | 8 ++-- net/tcp/tcp_send_buffered.c | 4 +- net/tcp/tcp_send_unbuffered.c | 2 +- net/udp/udp_ipselect.c | 8 ++-- sched/group/group_killchildren.c | 2 +- sched/sched/sched_timerexpiration.c | 6 +-- sched/semaphore/sem_holder.c | 2 +- sched/task/task_init.c | 2 +- sched/task/task_spawn.c | 2 +- tools/cfgdefine.c | 2 +- tools/cfgparser.c | 2 +- tools/mkconfig.c | 2 +- tools/mkdeps.c | 2 +- 88 files changed, 228 insertions(+), 231 deletions(-) diff --git a/arch b/arch index 0c8200c21f..cc863e71f9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0c8200c21f76a67e621d364b51e73bda4f6ba28c +Subproject commit cc863e71f9fdf2b418365ff58ec2103dc1abbfcd diff --git a/binfmt/binfmt_exepath.c b/binfmt/binfmt_exepath.c index 1e05d55f3b..3caf02e40d 100644 --- a/binfmt/binfmt_exepath.c +++ b/binfmt/binfmt_exepath.c @@ -142,7 +142,7 @@ EXEPATH_HANDLE exepath_init(void) return (EXEPATH_HANDLE)exepath; } - /**************************************************************************** +/**************************************************************************** * Name: exepath_next * * Description: diff --git a/binfmt/symtab_findorderedbyname.c b/binfmt/symtab_findorderedbyname.c index e058bd770c..2771400194 100644 --- a/binfmt/symtab_findorderedbyname.c +++ b/binfmt/symtab_findorderedbyname.c @@ -129,13 +129,13 @@ symtab_findorderedbyname(FAR const struct symtab_s *symtab, } } - /* low == high... One final check. We might not have actually tested - * the final symtab[] name. - * - * Example: Only the last pass through loop, suppose low = 1, high = 2, - * mid = 1, and symtab[high].sym_name == name. Then we would get here with - * low = 2, high = 2, but symtab[2].sym_name was never tested. - */ + /* low == high... One final check. We might not have actually tested + * the final symtab[] name. + * + * Example: Only the last pass through loop, suppose low = 1, high = 2, + * mid = 1, and symtab[high].sym_name == name. Then we would get here with + * low = 2, high = 2, but symtab[2].sym_name was never tested. + */ return strcmp(name, symtab[low].sym_name) == 0 ? &symtab[low] : NULL; } diff --git a/binfmt/symtab_findorderedbyvalue.c b/binfmt/symtab_findorderedbyvalue.c index 7af0d6a218..7b2c76e748 100644 --- a/binfmt/symtab_findorderedbyvalue.c +++ b/binfmt/symtab_findorderedbyvalue.c @@ -114,13 +114,13 @@ symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, } } - /* low == high... One final check. We might not have actually tested - * the final symtab[] name. - * - * Example: Only the last pass through loop, suppose low = 1, high = 2, - * mid = 1, and symtab[high].sym_name == name. Then we would get here with - * low = 2, high = 2, but symtab[2].sym_name was never tested. - */ + /* low == high... One final check. We might not have actually tested + * the final symtab[] name. + * + * Example: Only the last pass through loop, suppose low = 1, high = 2, + * mid = 1, and symtab[high].sym_name == name. Then we would get here with + * low = 2, high = 2, but symtab[2].sym_name was never tested. + */ return value == symtab[low].sym_value ? &symtab[low] : NULL; } diff --git a/configs b/configs index 87c0e8d612..dbc09272e2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 87c0e8d6124f7e0ec849e5430534eedd9495aba9 +Subproject commit dbc09272e2e97c118372075d47281a563dc61db1 diff --git a/drivers/analog/dac.c b/drivers/analog/dac.c index 515fc26842..c4cd10a6af 100644 --- a/drivers/analog/dac.c +++ b/drivers/analog/dac.c @@ -426,14 +426,14 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t nsent += msglen; } - /* We get here after all messages have been added to the FIFO. Check if - * we need to kick of the XMIT sequence. - */ - - if (empty) - { - dac_xmit(dev); - } + /* We get here after all messages have been added to the FIFO. Check if + * we need to kick of the XMIT sequence. + */ + + if (empty) + { + dac_xmit(dev); + } /* Return the number of bytes that were sent */ diff --git a/drivers/can.c b/drivers/can.c index f37557205b..3e836ff5c5 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -698,14 +698,14 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, nsent += msglen; } - /* We get here after all messages have been added to the FIFO. Check if - * we need to kick of the XMIT sequence. - */ - - if (inactive) - { - can_xmit(dev); - } + /* We get here after all messages have been added to the FIFO. Check if + * we need to kick of the XMIT sequence. + */ + + if (inactive) + { + can_xmit(dev); + } /* Return the number of bytes that were sent */ diff --git a/drivers/lcd/mio283qt2.c b/drivers/lcd/mio283qt2.c index 6b87c670e5..5e68c953ef 100644 --- a/drivers/lcd/mio283qt2.c +++ b/drivers/lcd/mio283qt2.c @@ -937,7 +937,7 @@ static inline int mio283qt2_hwinitialize(FAR struct mio283qt2_dev_s *priv) return ret; } - /************************************************************************************* +/************************************************************************************** * Public Functions **************************************************************************************/ diff --git a/drivers/lcd/mio283qt9a.c b/drivers/lcd/mio283qt9a.c index 8ec36a3abd..2a17fe763e 100644 --- a/drivers/lcd/mio283qt9a.c +++ b/drivers/lcd/mio283qt9a.c @@ -833,7 +833,7 @@ static inline int mio283qt9a_hwinitialize(FAR struct mio283qt9a_dev_s *priv) return ret; } - /************************************************************************************* +/************************************************************************************** * Public Functions **************************************************************************************/ diff --git a/drivers/lcd/p14201.c b/drivers/lcd/p14201.c index dbd69a271d..26ded62a28 100644 --- a/drivers/lcd/p14201.c +++ b/drivers/lcd/p14201.c @@ -405,7 +405,7 @@ static const uint8_t g_sleepon[] = static const uint8_t g_horzinc[] = { SSD1329_GDDRAM_REMAP, - (SSD1329_COM_SPLIT|SSD1329_COM_REMAP|SSD1329_NIBBLE_REMAP), + (SSD1329_COM_SPLIT|SSD1329_COM_REMAP|SSD1329_NIBBLE_REMAP), }; /* The following set a window that covers the entire display */ diff --git a/drivers/lcd/ra8875.c b/drivers/lcd/ra8875.c index 53fb973619..cef1157a79 100644 --- a/drivers/lcd/ra8875.c +++ b/drivers/lcd/ra8875.c @@ -1079,7 +1079,7 @@ static inline int ra8875_hwinitialize(FAR struct ra8875_dev_s *priv) return OK; } - /************************************************************************************* +/************************************************************************************** * Public Functions **************************************************************************************/ diff --git a/drivers/lcd/ssd1289.c b/drivers/lcd/ssd1289.c index bcc3348324..8385101191 100644 --- a/drivers/lcd/ssd1289.c +++ b/drivers/lcd/ssd1289.c @@ -1284,7 +1284,7 @@ static inline int ssd1289_hwinitialize(FAR struct ssd1289_dev_s *priv) return ret; } - /************************************************************************************* +/************************************************************************************** * Public Functions **************************************************************************************/ diff --git a/drivers/lcd/st7567.c b/drivers/lcd/st7567.c index f138e14794..9e8405c64b 100644 --- a/drivers/lcd/st7567.c +++ b/drivers/lcd/st7567.c @@ -232,10 +232,10 @@ struct st7567_dev_s uint8_t contrast; uint8_t powered; - /* The ST7567 does not support reading from the display memory in SPI mode. - * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep - * a shadow copy of the framebuffer memory. - */ + /* The ST7567 does not support reading from the display memory in SPI mode. + * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep + * a shadow copy of the framebuffer memory. + */ uint8_t fb[ST7567_FBSIZE]; }; diff --git a/drivers/lcd/ug-2864ambag01.c b/drivers/lcd/ug-2864ambag01.c index 6b8e081b24..7987c3b7c8 100644 --- a/drivers/lcd/ug-2864ambag01.c +++ b/drivers/lcd/ug-2864ambag01.c @@ -287,10 +287,10 @@ struct ug2864ambag01_dev_s bool on; /* true: display is on */ - /* The SH1101A does not support reading from the display memory in SPI mode. - * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep - * a shadow copy of the framebuffer memory. At 128x64, this amounts to 1KB. - */ + /* The SH1101A does not support reading from the display memory in SPI mode. + * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep + * a shadow copy of the framebuffer memory. At 128x64, this amounts to 1KB. + */ uint8_t fb[UG2864AMBAG01_FBSIZE]; }; diff --git a/drivers/lcd/ug-9664hswag01.c b/drivers/lcd/ug-9664hswag01.c index c649e26ca1..107703a53a 100644 --- a/drivers/lcd/ug-9664hswag01.c +++ b/drivers/lcd/ug-9664hswag01.c @@ -247,10 +247,10 @@ struct ug_dev_s uint8_t contrast; uint8_t powered; - /* The SSD1305 does not support reading from the display memory in SPI mode. - * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep - * a shadow copy of the framebuffer memory. - */ + /* The SSD1305 does not support reading from the display memory in SPI mode. + * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep + * a shadow copy of the framebuffer memory. + */ uint8_t fb[UG_FBSIZE]; }; diff --git a/drivers/mtd/at45db.c b/drivers/mtd/at45db.c index c9095172a2..2c8689ab21 100644 --- a/drivers/mtd/at45db.c +++ b/drivers/mtd/at45db.c @@ -640,7 +640,7 @@ static ssize_t at45db_bread(FAR struct mtd_dev_s *mtd, off_t startblock, FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd; ssize_t nbytes; - /* On this device, we can handle the block read just like the byte-oriented read */ + /* On this device, we can handle the block read just like the byte-oriented read */ nbytes = at45db_read(mtd, startblock << priv->pageshift, nblocks << priv->pageshift, buffer); diff --git a/drivers/mtd/mtd_nand.c b/drivers/mtd/mtd_nand.c index 3c333dd477..2261725d26 100644 --- a/drivers/mtd/mtd_nand.c +++ b/drivers/mtd/mtd_nand.c @@ -540,7 +540,7 @@ static int nand_writepage(FAR struct nand_dev_s *nand, off_t block, * ECC calculations. */ - else + else #endif { return NAND_WRITEPAGE(nand->raw, block, page, data, NULL); diff --git a/drivers/mtd/mtd_onfi.c b/drivers/mtd/mtd_onfi.c index 5f9781b295..62b955a81c 100644 --- a/drivers/mtd/mtd_onfi.c +++ b/drivers/mtd/mtd_onfi.c @@ -88,7 +88,7 @@ #define EBICSA_EBI_DBPDC (1 << 9) #define EBICSA_NAND_D0_ON_D16 (1 << 24) - /* Misc. definitions */ +/* Misc. definitions */ #define MAX_READ_STATUS_COUNT 100000 /* Read status timeout */ #define ONFI_PARAM_TABLE_SIZE 116 /* Not all 256 bytes are useful */ diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 4265fda326..2eaf4221d1 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -644,9 +644,9 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) default: fdbg("ERROR: Unsupported memory capacity: %02x\n", priv->cmdbuf[2]); return -ENODEV; - } + } - return OK; + return OK; } /************************************************************************************ diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index d9f3644a43..ae2884ed98 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -1257,16 +1257,16 @@ static int dm9x_interrupt(int irq, FAR void *context) ndbg("delay: %dmS speed: %s\n", i, dm9x->dm_b100M ? "100M" : "10M"); } - /* Check if we received an incoming packet */ + /* Check if we received an incoming packet */ - if (isr & DM9X_INT_PR) + if (isr & DM9X_INT_PR) { dm9x_receive(dm9x); } - /* Check if we are able to transmit a packet */ + /* Check if we are able to transmit a packet */ - if (isr & DM9X_INT_PT) + if (isr & DM9X_INT_PT) { dm9x_txdone(dm9x); } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 34bffa07c7..3d0c43e94d 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1615,7 +1615,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) enc_wrbreg(priv, ENC_ERXRDPTL, (priv->nextpkt)); enc_wrbreg(priv, ENC_ERXRDPTH, (priv->nextpkt) >> 8); - /* Decrement the packet counter indicate we are done with this packet */ + /* Decrement the packet counter indicate we are done with this packet */ enc_bfsgreg(priv, ENC_ECON2, ECON2_PKTDEC); } diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index aa50d035af..7e50890208 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -561,9 +561,9 @@ int localhost_initialize(void) #endif #ifdef CONFIG_NET_IPv6 - net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr); - net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr); - net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_alloneaddr); + net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr); + net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr); + net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_alloneaddr); #endif /* Put the network in the UP state */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index bbabc1527e..203f9f7090 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -183,9 +183,9 @@ struct slip_driver_s * Private Data ****************************************************************************/ - /* We really should get rid of CONFIG_NET_SLIP_NINTERFACES and, instead, - * kmm_malloc() new interface instances as needed. - */ +/* We really should get rid of CONFIG_NET_SLIP_NINTERFACES and, instead, + * kmm_malloc() new interface instances as needed. + */ static struct slip_driver_s g_slip[CONFIG_NET_SLIP_NINTERFACES]; diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index c077ea537f..bfe043ebf4 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -161,7 +161,7 @@ static void pipecommon_pollnotify(FAR struct pipe_dev_s *dev, pollevent_t events FAR struct pipe_dev_s *pipecommon_allocdev(void) { - struct pipe_dev_s *dev; + FAR struct pipe_dev_s *dev; /* Allocate a private structure to manage the pipe */ diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index b07f655466..560aa7af22 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -792,7 +792,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; } - /* Is the level now below the watermark level that we need to report? */ + /* Is the level now below the watermark level that we need to report? */ watermark = (CONFIG_SERIAL_IFLOWCONTROL_LOWER_WATERMARK * rxbuf->size) / 100; if (nbuffered <= watermark) @@ -1170,7 +1170,7 @@ static int uart_close(FAR struct file *filep) uart_givesem(&dev->closesem); return OK; - } +} /************************************************************************************ * Name: uart_open @@ -1443,6 +1443,3 @@ void uart_connected(FAR uart_dev_t *dev, bool connected) irqrestore(flags); } #endif - - - diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index ffa7f7a4c9..adc193deeb 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -708,10 +708,10 @@ static int u16550_attach(struct uart_dev_s *dev) * ****************************************************************************/ -static void u16550_detach(struct uart_dev_s *dev) +static void u16550_detach(FAR struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_SERIAL_INTS - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (struct u16550_s*)dev->priv; #ifndef CONFIG_ARCH_NOINTC up_disable_irq(priv->irq); #endif diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index bc88eac5be..fae90a75ad 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c @@ -49,7 +49,7 @@ #ifdef CONFIG_SPI_BITBANG - /**************************************************************************** +/**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* This file holds the static, device-independ portion of the generica SPI- diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index fde47c1c62..a06bdcbdd3 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -426,14 +426,14 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size DEBUGASSERT(inode && inode->i_private); priv = inode->i_private; - /* Loop until all of the bytes have been written. This function may be - * called from an interrupt handler! Semaphores cannot be used! - * - * The write logic only needs to modify the rl_head index. Therefore, - * there is a difference in the way that rl_head and rl_tail are protected: - * rl_tail is protected with a semaphore; rl_tail is protected by disabling - * interrupts. - */ + /* Loop until all of the bytes have been written. This function may be + * called from an interrupt handler! Semaphores cannot be used! + * + * The write logic only needs to modify the rl_head index. Therefore, + * there is a difference in the way that rl_head and rl_tail are protected: + * rl_tail is protected with a semaphore; rl_tail is protected by disabling + * interrupts. + */ for (nwritten = 0; nwritten < len; nwritten++) { diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index 65530678a1..2fb4f29f92 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -199,7 +199,7 @@ static int cs2100_read_reg(FAR const struct cs2100_config_s *config, } } - return ret; + return ret; } #endif diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index 564fbf6229..43cc465815 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -2202,7 +2202,7 @@ static void cdcuart_txint(FAR struct uart_dev_s *dev, bool enable) } #endif - /* Extract references to private data */ + /* Extract references to private data */ priv = (FAR struct cdcacm_dev_s*)dev->priv; diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index 0fc6a52a0c..e23f3c20f6 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -146,7 +146,7 @@ const char g_compvendorstr[] = CONFIG_COMPOSITE_VENDORSTR; const char g_compproductstr[] = CONFIG_COMPOSITE_PRODUCTSTR; const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR; - /**************************************************************************** +/**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index 526322cbb4..b978dfb349 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -2218,7 +2218,7 @@ static void usbser_txint(FAR struct uart_dev_s *dev, bool enable) } #endif - /* Extract references to private data */ + /* Extract references to private data */ priv = (FAR struct pl2303_dev_s*)dev->priv; diff --git a/drivers/usbdev/usbmsc_desc.c b/drivers/usbdev/usbmsc_desc.c index e958392f4e..1a97da8224 100644 --- a/drivers/usbdev/usbmsc_desc.c +++ b/drivers/usbdev/usbmsc_desc.c @@ -260,7 +260,7 @@ int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) return 4; } - case USBMSC_MANUFACTURERSTRID: + case USBMSC_MANUFACTURERSTRID: str = g_mscvendorstr; break; diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index f390289e04..d7a49fd671 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -1712,7 +1712,7 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val) static inline uint32_t usbhost_getle32(const uint8_t *val) { - /* Little endian means LS halfword first in byte stream */ + /* Little endian means LS halfword first in byte stream */ return (uint32_t)usbhost_getle16(&val[2]) << 16 | (uint32_t)usbhost_getle16(val); } diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index 62c659a5b1..0befef80af 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -1783,7 +1783,7 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val) static inline uint32_t usbhost_getle32(const uint8_t *val) { - /* Little endian means LS halfword first in byte stream */ + /* Little endian means LS halfword first in byte stream */ return (uint32_t)usbhost_getle16(&val[2]) << 16 | (uint32_t)usbhost_getle16(val); } diff --git a/drivers/usbhost/usbhost_skeleton.c b/drivers/usbhost/usbhost_skeleton.c index 3c2879969a..cb30aff9ec 100644 --- a/drivers/usbhost/usbhost_skeleton.c +++ b/drivers/usbhost/usbhost_skeleton.c @@ -742,7 +742,7 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val) static inline uint32_t usbhost_getle32(const uint8_t *val) { - /* Little endian means LS halfword first in byte stream */ + /* Little endian means LS halfword first in byte stream */ return (uint32_t)usbhost_getle16(&val[2]) << 16 | (uint32_t)usbhost_getle16(val); } diff --git a/drivers/usbhost/usbhost_storage.c b/drivers/usbhost/usbhost_storage.c index baefebb516..288ad99e5e 100644 --- a/drivers/usbhost/usbhost_storage.c +++ b/drivers/usbhost/usbhost_storage.c @@ -1481,7 +1481,7 @@ static void usbhost_putbe16(uint8_t *dest, uint16_t val) static inline uint32_t usbhost_getle32(const uint8_t *val) { - /* Little endian means LS halfword first in byte stream */ + /* Little endian means LS halfword first in byte stream */ return (uint32_t)usbhost_getle16(&val[2]) << 16 | (uint32_t)usbhost_getle16(val); } diff --git a/fs/driver/fs_devsyslog.c b/fs/driver/fs_devsyslog.c index 526a9e0b28..991506fe0f 100644 --- a/fs/driver/fs_devsyslog.c +++ b/fs/driver/fs_devsyslog.c @@ -61,10 +61,10 @@ * Pre-processor Definitions ****************************************************************************/ - /* Open the device/file write-only, try to create (file) it if it doesn't - * exist, if the file that already exists, then append the new log data to - * end of the file. - */ +/* Open the device/file write-only, try to create (file) it if it doesn't + * exist, if the file that already exists, then append the new log data to + * end of the file. + */ #define SYSLOG_OFLAGS (O_WRONLY | O_CREAT | O_APPEND) @@ -348,7 +348,7 @@ int syslog_initialize(void) g_sysdev.sl_state = SYSLOG_OPENED; return OK; - errout_with_inode: +errout_with_inode: inode_release(inode); g_sysdev.sl_state = SYSLOG_FAILURE; return ret; diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c index 4a46ecab95..9d349c9495 100644 --- a/fs/fat/fs_fat32dirent.c +++ b/fs/fat/fs_fat32dirent.c @@ -463,7 +463,7 @@ static inline int fat_parsesfname(const char **path, dirinfo->fd_name[ndx++] = ch; } - errout: +errout: return -EINVAL; } @@ -552,7 +552,7 @@ static inline int fat_parselfname(const char **path, dirinfo->fd_lfname[ndx++] = ch; } - errout: +errout: dirinfo->fd_lfname[0] = '\0'; return -EINVAL; } diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c index 07a31d2b89..3d70032582 100644 --- a/fs/fat/fs_fat32util.c +++ b/fs/fat/fs_fat32util.c @@ -683,11 +683,11 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) return OK; - errout_with_buffer: +errout_with_buffer: fat_io_free(fs->fs_buffer, fs->fs_hwsectorsize); fs->fs_buffer = 0; - errout: +errout: fs->fs_mounted = false; return ret; } diff --git a/fs/fat/fs_writefat.c b/fs/fat/fs_writefat.c index c784a35f6f..51e71e278d 100644 --- a/fs/fat/fs_writefat.c +++ b/fs/fat/fs_writefat.c @@ -333,7 +333,7 @@ static inline int mkfatfs_writembr(FAR struct fat_format_s *fmt, /* Write all of the reserved sectors */ memset(var->fv_sect, 0, var->fv_sectorsize); - for (sectno = 1; sectno < fmt->ff_rsvdseccount && ret >= 0; sectno++) + for (sectno = 1; sectno < fmt->ff_rsvdseccount && ret >= 0; sectno++) { ret = DEV_WRITE(var->fv_sect, sectno, 1); } diff --git a/fs/mount/fs_foreachmountpoint.c b/fs/mount/fs_foreachmountpoint.c index b3ab33abc7..fece2702e5 100644 --- a/fs/mount/fs_foreachmountpoint.c +++ b/fs/mount/fs_foreachmountpoint.c @@ -142,7 +142,7 @@ static int mountpoint_filter(FAR struct inode *node, * Public Functions ****************************************************************************/ - /**************************************************************************** +/**************************************************************************** * Name: foreach_mountpoint * * Description: diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 9c5e6d3fdf..2aa5fc6faf 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -381,11 +381,11 @@ int mount(FAR const char *source, FAR const char *target, mountpt_inode->i_private = fshandle; inode_semgive(); - /* We can release our reference to the blkdrver_inode, if the filesystem - * wants to retain the blockdriver inode (which it should), then it must - * have called inode_addref(). There is one reference on mountpt_inode - * that will persist until umount2() is called. - */ + /* We can release our reference to the blkdrver_inode, if the filesystem + * wants to retain the blockdriver inode (which it should), then it must + * have called inode_addref(). There is one reference on mountpt_inode + * that will persist until umount2() is called. + */ #ifdef BDFS_SUPPORT #ifdef NONBDFS_SUPPORT diff --git a/fs/nxffs/nxffs_util.c b/fs/nxffs/nxffs_util.c index 12392aa585..52354d33f9 100644 --- a/fs/nxffs/nxffs_util.c +++ b/fs/nxffs/nxffs_util.c @@ -121,7 +121,7 @@ void nxffs_wrle16(uint8_t *dest, uint16_t val) uint32_t nxffs_rdle32(FAR const uint8_t *val) { - /* Little endian means LS halfword first in byte stream */ + /* Little endian means LS halfword first in byte stream */ return (uint32_t)nxffs_rdle16(&val[2]) << 16 | (uint32_t)nxffs_rdle16(val); } diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 7ba2d93c1e..e5e46d9ba6 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -264,9 +264,9 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) return sem; - errout_with_inode: +errout_with_inode: inode_release(inode); - errout_with_lock: +errout_with_lock: set_errno(errcode); sched_unlock(); return (FAR sem_t *)ERROR; diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index 994c30b663..f57d3dd2a7 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -2444,7 +2444,7 @@ static int unionfs_stat(FAR struct inode *mountpt, FAR const char *relpath, static int unionfs_getmount(FAR const char *path, FAR struct inode **inode) { - FAR struct inode *minode; + FAR struct inode *minode; /* Find the mountpt */ diff --git a/fs/vfs/fs_mkdir.c b/fs/vfs/fs_mkdir.c index 1add02d44d..01ed5bb629 100644 --- a/fs/vfs/fs_mkdir.c +++ b/fs/vfs/fs_mkdir.c @@ -181,9 +181,9 @@ int mkdir(const char *pathname, mode_t mode) return OK; - errout_with_inode: +errout_with_inode: inode_release(inode); - errout: +errout: set_errno(errcode); return ERROR; } diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 1fb0cb538a..ed44e47e21 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -201,11 +201,11 @@ int open(const char *path, int oflags, ...) return fd; - errout_with_fd: +errout_with_fd: files_release(fd); - errout_with_inode: +errout_with_inode: inode_release(inode); - errout: +errout: set_errno(ret); return ERROR; } diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c index 820193cf5d..e6ebfd3d63 100644 --- a/fs/vfs/fs_rename.c +++ b/fs/vfs/fs_rename.c @@ -245,12 +245,12 @@ int rename(FAR const char *oldpath, FAR const char *newpath) return OK; #ifndef CONFIG_DISABLE_MOUNTPOINT - errout_with_newinode: +errout_with_newinode: inode_release(newinode); #endif - errout_with_oldinode: +errout_with_oldinode: inode_release(oldinode); - errout: +errout: set_errno(errcode); return ERROR; } diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c index a05462dec0..126caf2adc 100644 --- a/fs/vfs/fs_unlink.c +++ b/fs/vfs/fs_unlink.c @@ -225,9 +225,9 @@ int unlink(FAR const char *pathname) inode_release(inode); return OK; - errout_with_inode: +errout_with_inode: inode_release(inode); - errout: +errout: set_errno(errcode); return ERROR; } diff --git a/graphics/nxsu/nx_mousein.c b/graphics/nxsu/nx_mousein.c index 1b3027019c..374ba80411 100644 --- a/graphics/nxsu/nx_mousein.c +++ b/graphics/nxsu/nx_mousein.c @@ -172,7 +172,7 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) y = g_mrange.y - 1; } - /* Look any change in values */ + /* Look any change in values */ if (x != g_mpos.x || y != g_mpos.y || buttons != g_mbutton) { diff --git a/graphics/nxsu/nx_open.c b/graphics/nxsu/nx_open.c index 3f4629f90c..2c646c8b3e 100644 --- a/graphics/nxsu/nx_open.c +++ b/graphics/nxsu/nx_open.c @@ -151,7 +151,7 @@ static inline int nxsu_setup(FAR NX_DRIVERTYPE *dev, fe->be.topwnd = &fe->be.bkgd; - /* Initialize the mouse position */ + /* Initialize the mouse position */ #ifdef CONFIG_NX_XYINPUT nxsu_mouseinit(fe->be.vinfo.xres, fe->be.vinfo.yres); diff --git a/graphics/nxterm/nxterm_kbdin.c b/graphics/nxterm/nxterm_kbdin.c index 46c6e200be..3b53514ec1 100644 --- a/graphics/nxterm/nxterm_kbdin.c +++ b/graphics/nxterm/nxterm_kbdin.c @@ -418,14 +418,14 @@ void nxterm_kbdin(NXTERM handle, FAR const uint8_t *buffer, uint8_t buflen) return; } - /* Loop until all of the bytes have been written. This function may be - * called from an interrupt handler! Semaphores cannot be used! - * - * The write logic only needs to modify the head index. Therefore, - * there is a difference in the way that head and tail are protected: - * tail is protected with a semaphore; tail is protected by disabling - * interrupts. - */ + /* Loop until all of the bytes have been written. This function may be + * called from an interrupt handler! Semaphores cannot be used! + * + * The write logic only needs to modify the head index. Therefore, + * there is a difference in the way that head and tail are protected: + * tail is protected with a semaphore; tail is protected by disabling + * interrupts. + */ for (nwritten = 0; nwritten < buflen; nwritten++) { diff --git a/libc/fixedmath/lib_fixedmath.c b/libc/fixedmath/lib_fixedmath.c index cf072fd541..d5dff82243 100644 --- a/libc/fixedmath/lib_fixedmath.c +++ b/libc/fixedmath/lib_fixedmath.c @@ -144,17 +144,17 @@ b16_t b16mulb16(b16_t m1, b16_t m2) ub16_t ub16mulub16(ub16_t m1, ub16_t m2) { - /* Let: - * - * m1 = m1i*2**16 + m1f (b16) - * m2 = m2i*2**16 + m2f (b16) - * - * Then: - * - * m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32) - * = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16) - * = a*2**16 + b + c*2**-16 - */ + /* Let: + * + * m1 = m1i*2**16 + m1f (b16) + * m2 = m2i*2**16 + m2f (b16) + * + * Then: + * + * m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32) + * = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16) + * = a*2**16 + b + c*2**-16 + */ uint32_t m1i = ((uint32_t)m1 >> 16); uint32_t m2i = ((uint32_t)m1 >> 16); @@ -195,15 +195,15 @@ b16_t b16sqr(b16_t a) ub16_t ub16sqr(ub16_t a) { - /* Let: - * - * m = mi*2**16 + mf (b16) - * - * Then: - * - * m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32) - * = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16) - */ + /* Let: + * + * m = mi*2**16 + mf (b16) + * + * Then: + * + * m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32) + * = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16) + */ uint32_t mi = ((uint32_t)a >> 16); uint32_t mf = ((uint32_t)a & 0x0000ffff); @@ -235,16 +235,16 @@ ub16_t ub16divub16(ub16_t num, ub16_t denom) uint32_t numf; uint32_t product; - /* Let: - * - * num = numi*2**16 + numf (b16) - * den = deni*2**16 + denf (b16) - * - * Then: - * - * num/den = numi*2**16 / den + numf / den (b0) - * = numi*2**32 / den + numf*2**16 /den (b16) - */ + /* Let: + * + * num = numi*2**16 + numf (b16) + * den = deni*2**16 + denf (b16) + * + * Then: + * + * num/den = numi*2**16 / den + numf / den (b0) + * = numi*2**32 / den + numf*2**16 /den (b16) + */ /* Check for overflow in the first part of the quotient */ diff --git a/libc/misc/lib_utsname.c b/libc/misc/lib_utsname.c index f61584e963..ff69aa1af4 100644 --- a/libc/misc/lib_utsname.c +++ b/libc/misc/lib_utsname.c @@ -121,6 +121,6 @@ int uname(FAR struct utsname *name) name->machine[SYS_NAMELEN-1] = '\0'; return ret; - } +} #endif /* (!CONFIG_BUILD_PROTECTED) && !CONFIG_BUILD_KERNEL) || __KERNEL__ */ diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index ca27473174..f32fdc1d29 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -228,7 +228,7 @@ errorout_with_herrnocode: *h_errnop = herrnocode; } - return ERROR; + return ERROR; } #endif @@ -341,7 +341,7 @@ errorout_with_herrnocode: *h_errnop = herrnocode; } - return ERROR; + return ERROR; } /**************************************************************************** diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 6ae638ead2..6b005743cf 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -112,7 +112,7 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, * be big enough). */ - if (buflen <= sizeof(struct hostent_info_s)) + if (buflen <= sizeof(struct hostent_info_s)) { return -ERANGE; } @@ -335,7 +335,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, * be big enough). */ - if (buflen <= sizeof(struct hostent_info_s)) + if (buflen <= sizeof(struct hostent_info_s)) { return -ERANGE; } @@ -360,7 +360,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, return ret; } - /* Get the address type; verify the address size. */ + /* Get the address type; verify the address size. */ #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 @@ -479,7 +479,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, * be big enough). */ - if (buflen <= sizeof(struct hostent_info_s)) + if (buflen <= sizeof(struct hostent_info_s)) { return -ERANGE; } @@ -676,7 +676,7 @@ errorout_with_herrnocode: *h_errnop = herrnocode; } - return ERROR; + return ERROR; } #endif /* CONFIG_NETDB_HOSTFILE */ @@ -793,7 +793,7 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host, *h_errnop = HOST_NOT_FOUND; } - return ERROR; + return ERROR; #endif } diff --git a/libc/netdb/lib_parsehostfile.c b/libc/netdb/lib_parsehostfile.c index f09c5b85c3..8913a8a2b2 100644 --- a/libc/netdb/lib_parsehostfile.c +++ b/libc/netdb/lib_parsehostfile.c @@ -279,7 +279,7 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host, * be big enough). */ - if (buflen <= sizeof(struct hostent_info_s)) + if (buflen <= sizeof(struct hostent_info_s)) { return -ERANGE; } diff --git a/libc/signal/sig_set.c b/libc/signal/sig_set.c index a98d7b7ebd..bbf42a587b 100644 --- a/libc/signal/sig_set.c +++ b/libc/signal/sig_set.c @@ -118,7 +118,7 @@ void (*sigset(int signo, void (*disp)(int)))(int) * indicate the error. */ - if (ret == OK) + if (ret == OK) { return oact.sa_handler; } diff --git a/libc/stdio/lib_stdinstream.c b/libc/stdio/lib_stdinstream.c index 4b00888787..240763613f 100644 --- a/libc/stdio/lib_stdinstream.c +++ b/libc/stdio/lib_stdinstream.c @@ -64,7 +64,7 @@ static int stdinstream_getc(FAR struct lib_instream_s *this) this->nget++; } - return ret; + return ret; } /**************************************************************************** diff --git a/libc/stdio/lib_stdsistream.c b/libc/stdio/lib_stdsistream.c index 85eaf0fe71..0999f85132 100644 --- a/libc/stdio/lib_stdsistream.c +++ b/libc/stdio/lib_stdsistream.c @@ -64,7 +64,7 @@ static int stdsistream_getc(FAR struct lib_sistream_s *this) this->nget++; } - return ret; + return ret; } /**************************************************************************** diff --git a/libc/time/lib_settimeofday.c b/libc/time/lib_settimeofday.c index a28b634a7e..ea404b7e03 100644 --- a/libc/time/lib_settimeofday.c +++ b/libc/time/lib_settimeofday.c @@ -83,8 +83,8 @@ int settimeofday(FAR const struct timeval *tv, FAR struct timezone *tz) /* Convert the timeval to a timespec */ - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * NSEC_PER_USEC; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * NSEC_PER_USEC; /* Let clock_settime do the work */ diff --git a/libc/unistd/lib_chdir.c b/libc/unistd/lib_chdir.c index 969b06a2da..87353b546d 100644 --- a/libc/unistd/lib_chdir.c +++ b/libc/unistd/lib_chdir.c @@ -64,14 +64,14 @@ #if 0 static inline void _trimdir(char *path) { - /* Skip any trailing '/' characters (unless it is also the leading '/') */ + /* Skip any trailing '/' characters (unless it is also the leading '/') */ - int len = strlen(path) - 1; - while (len > 0 && path[len] == '/') - { + int len = strlen(path) - 1; + while (len > 0 && path[len] == '/') + { path[len] = '\0'; len--; - } + } } #else # define _trimdir(p) diff --git a/mm/shm/shmdt.c b/mm/shm/shmdt.c index 0ecee2ab30..2215b03785 100644 --- a/mm/shm/shmdt.c +++ b/mm/shm/shmdt.c @@ -87,7 +87,7 @@ * of the attached shared memory segment and return 0. * * Otherwise, the shared memory segment will not be detached, shmdt() - & will return -1, and errno will be set to indicate the error. + * will return -1, and errno will be set to indicate the error. * * - EINVAL * The value of shmaddr is not the data segment start address of a diff --git a/net/arp/arp_out.c b/net/arp/arp_out.c index a50e9dee68..a815715c63 100644 --- a/net/arp/arp_out.c +++ b/net/arp/arp_out.c @@ -178,8 +178,8 @@ void arp_out(FAR struct net_driver_s *dev) * addresses=0xff (ff00::/8.) */ - else if (NTOHS(pip->eh_destipaddr[0]) >= 0xe000 && - NTOHS(pip->eh_destipaddr[0]) <= 0xefff) + else if (NTOHS(pip->eh_destipaddr[0]) >= 0xe000 && + NTOHS(pip->eh_destipaddr[0]) <= 0xefff) { /* Build the well-known IPv4 IGMP Ethernet address. The first * three bytes are fixed; the final three variable come from the diff --git a/net/arp/arp_send.c b/net/arp/arp_send.c index fbb6bdd6ae..1b19e91a43 100644 --- a/net/arp/arp_send.c +++ b/net/arp/arp_send.c @@ -221,7 +221,7 @@ int arp_send(in_addr_t ipaddr) * addresses=0xff (ff00::/8.) */ - if (NTOHL(ipaddr) >= 0xe0000000 && NTOHL(ipaddr) <= 0xefffffff) + if (NTOHL(ipaddr) >= 0xe0000000 && NTOHL(ipaddr) <= 0xefffffff) { /* We don't need to send the ARP request */ diff --git a/net/arp/arp_timer.c b/net/arp/arp_timer.c index c1b23c4bcd..b610e7b8a5 100644 --- a/net/arp/arp_timer.c +++ b/net/arp/arp_timer.c @@ -126,7 +126,7 @@ void arp_timer_initialize(void) /* Create and start the ARP timer */ g_arptimer = wd_create(); - (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); + (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); } #endif /* CONFIG_NET_ARP */ diff --git a/net/icmpv6/icmpv6_autoconfig.c b/net/icmpv6/icmpv6_autoconfig.c index 051542ea57..add6e328b5 100644 --- a/net/icmpv6/icmpv6_autoconfig.c +++ b/net/icmpv6/icmpv6_autoconfig.c @@ -301,9 +301,9 @@ static int icmpv6_wait_radvertise(FAR struct net_driver_s *dev, ret = icmpv6_rwait(notify, &delay); - /* icmpv6_wait will return OK if and only if the matching Router - * Advertisement is received. Otherwise, it will return -ETIMEDOUT. - */ + /* icmpv6_wait will return OK if and only if the matching Router + * Advertisement is received. Otherwise, it will return -ETIMEDOUT. + */ return ret; } @@ -368,9 +368,9 @@ int icmpv6_autoconfig(FAR struct net_driver_s *dev) /* The interface should be in the down state */ - save = net_lock(); - netdev_ifdown(dev); - net_unlock(save); + save = net_lock(); + netdev_ifdown(dev); + net_unlock(save); /* IPv6 Stateless Autoconfiguration * Reference: http://www.tcpipguide.com/free/t_IPv6AutoconfigurationandRenumbering.htm diff --git a/net/iob/iob_test.c b/net/iob/iob_test.c index 5c58852cff..871f1e0126 100644 --- a/net/iob/iob_test.c +++ b/net/iob/iob_test.c @@ -199,10 +199,10 @@ int main(int argc, char **argv) void my_assert(bool value) { - if (!value) - { - fprintf(stderr, "Assertion failed\n"); + if (!value) + { + fprintf(stderr, "Assertion failed\n"); - abort(); - } + abort(); + } } diff --git a/net/local/local_conn.c b/net/local/local_conn.c index c45b49832f..a369f04b7c 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -64,7 +64,7 @@ * ****************************************************************************/ - void local_initialize(void) +void local_initialize(void) { #ifdef CONFIG_NET_LOCAL_STREAM dq_init(&g_local_listeners); diff --git a/net/socket/net_dupsd.c b/net/socket/net_dupsd.c index 6381c45d52..9ebe0b30b7 100644 --- a/net/socket/net_dupsd.c +++ b/net/socket/net_dupsd.c @@ -99,7 +99,7 @@ int net_dupsd(int sockfd, int minsd) psock1 = sockfd_socket(sockfd); - /* Verify that the sockfd corresponds to valid, allocated socket */ + /* Verify that the sockfd corresponds to valid, allocated socket */ if (!psock1 || psock1->s_crefs <= 0) { diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 9bb413cefd..d28ec93e9b 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -744,15 +744,15 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, tcp_callback_free(conn, state.snd_ackcb); - errout_datacb: +errout_datacb: tcp_callback_free(conn, state.snd_datacb); - errout_locked: +errout_locked: sem_destroy(&state. snd_sem); net_unlock(save); - errout: +errout: if (err) { diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 2ee0b5ffda..43ef798b6d 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -265,8 +265,8 @@ static inline void recvfrom_newtcpdata(FAR struct net_driver_s *dev, * add it to the read-ahead buffers. */ - if (recvlen < dev->d_len) - { + if (recvlen < dev->d_len) + { #ifdef CONFIG_NET_TCP_READAHEAD FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pstate->rf_sock->s_conn; FAR uint8_t *buffer = (FAR uint8_t *)dev->d_appdata + recvlen; diff --git a/net/socket/socket.c b/net/socket/socket.c index 2c8376e1e7..93fd41a278 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -185,9 +185,9 @@ static int psock_local_alloc(FAR struct socket *psock) return -ENOMEM; } - /* Set the reference count on the connection structure. This reference - * count will be incremented only if the socket is dup'ed - */ + /* Set the reference count on the connection structure. This reference + * count will be incremented only if the socket is dup'ed + */ DEBUGASSERT(conn->lc_crefs == 0); conn->lc_crefs = 1; diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index b1580112bb..03ad447464 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -253,7 +253,7 @@ void tcp_rexmit(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, } #endif /* CONFIG_NET_IPv6 */ - /* If the application has data to be sent, or if the incoming packet had + /* If the application has data to be sent, or if the incoming packet had * new data in it, we must send out a packet. */ diff --git a/net/tcp/tcp_ipselect.c b/net/tcp/tcp_ipselect.c index 9463fe4b30..6669b3be0c 100644 --- a/net/tcp/tcp_ipselect.c +++ b/net/tcp/tcp_ipselect.c @@ -76,9 +76,9 @@ void tcp_ipv4_select(FAR struct net_driver_s *dev) IFF_SET_IPv4(dev->d_flags); - /* Set the offset to the beginning of the TCP data payload */ + /* Set the offset to the beginning of the TCP data payload */ - dev->d_appdata = &dev->d_buf[IPv4TCP_HDRLEN + NET_LL_HDRLEN(dev)]; + dev->d_appdata = &dev->d_buf[IPv4TCP_HDRLEN + NET_LL_HDRLEN(dev)]; } #endif /* CONFIG_NET_IPv4 */ @@ -97,9 +97,9 @@ void tcp_ipv6_select(FAR struct net_driver_s *dev) IFF_SET_IPv6(dev->d_flags); - /* Set the offset to the beginning of the TCP data payload */ + /* Set the offset to the beginning of the TCP data payload */ - dev->d_appdata = &dev->d_buf[IPv6TCP_HDRLEN + NET_LL_HDRLEN(dev)]; + dev->d_appdata = &dev->d_buf[IPv6TCP_HDRLEN + NET_LL_HDRLEN(dev)]; } #endif /* CONFIG_NET_IPv6 */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 34e9100ad0..0a24144ccf 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -589,7 +589,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, conn->expired++; } } - + /* Move all segments that have been sent but not ACKed to the write * queue again note, the un-ACKed segments are put at the head of the * write_q so they can be resent as soon as possible. @@ -726,7 +726,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, * retransmitting, then the sequence number will already * be set for this write buffer. */ - + if (WRB_SEQNO(wrb) == (unsigned)-1) { WRB_SEQNO(wrb) = conn->isn + conn->sent; diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 4620532342..c8ee594fbd 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -386,7 +386,7 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, /* Fall through to re-send data from the last that was ACKed */ } - /* Check for a loss of connection */ + /* Check for a loss of connection */ else if ((flags & TCP_DISCONN_EVENTS) != 0) { diff --git a/net/udp/udp_ipselect.c b/net/udp/udp_ipselect.c index 7c5227ba25..b11fb00ac6 100644 --- a/net/udp/udp_ipselect.c +++ b/net/udp/udp_ipselect.c @@ -77,9 +77,9 @@ void udp_ipv4_select(FAR struct net_driver_s *dev) IFF_SET_IPv4(dev->d_flags); - /* Set the offset to the beginning of the UDP data payload */ + /* Set the offset to the beginning of the UDP data payload */ - dev->d_appdata = &dev->d_buf[IPv4UDP_HDRLEN + NET_LL_HDRLEN(dev)]; + dev->d_appdata = &dev->d_buf[IPv4UDP_HDRLEN + NET_LL_HDRLEN(dev)]; } #endif /* CONFIG_NET_IPv4 */ @@ -98,9 +98,9 @@ void udp_ipv6_select(FAR struct net_driver_s *dev) IFF_SET_IPv6(dev->d_flags); - /* Set the offset to the beginning of the UDP data payload */ + /* Set the offset to the beginning of the UDP data payload */ - dev->d_appdata = &dev->d_buf[IPv6UDP_HDRLEN + NET_LL_HDRLEN(dev)]; + dev->d_appdata = &dev->d_buf[IPv6UDP_HDRLEN + NET_LL_HDRLEN(dev)]; } #endif /* CONFIG_NET_IPv6 */ diff --git a/sched/group/group_killchildren.c b/sched/group/group_killchildren.c index d549da8658..9ec7465f98 100644 --- a/sched/group/group_killchildren.c +++ b/sched/group/group_killchildren.c @@ -77,7 +77,7 @@ static int group_killchildren_handler(pid_t pid, FAR void *arg) ret = pthread_cancel(pid); } - return ret; + return ret; } /**************************************************************************** diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index c765c075cb..c968da6bc8 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -271,9 +271,9 @@ static unsigned int sched_timer_process(unsigned int ticks, bool noswitches) rettime = tmp; } - /* Check for operations specific to scheduling policy of the currently - * active task. - */ + /* Check for operations specific to scheduling policy of the currently + * active task. + */ tmp = sched_process_scheduler(ticks, noswitches); if (tmp > 0 && tmp < cmptime) diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index b8bdd6c2ee..c08f90bb5a 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -780,7 +780,7 @@ static inline void sem_restorebaseprio_task(FAR struct tcb_s *stcb, void sem_initholders(void) { #if CONFIG_SEM_PREALLOCHOLDERS > 0 - int i; + int i; /* Put all of the pre-allocated holder structures into the free list */ diff --git a/sched/task/task_init.c b/sched/task/task_init.c index 7b7fc6215a..7f6fc14d8a 100644 --- a/sched/task/task_init.c +++ b/sched/task/task_init.c @@ -138,7 +138,7 @@ int task_init(FAR struct tcb_s *tcb, const char *name, int priority, } #endif - /* Associate file descriptors with the new task */ + /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 ret = group_setuptaskfiles(ttcb); diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c index 9853507829..02083a19ac 100644 --- a/sched/task/task_spawn.c +++ b/sched/task/task_spawn.c @@ -216,7 +216,7 @@ errout: static int task_spawn_proxy(int argc, FAR char *argv[]) { - int ret; + int ret; /* Perform file actions and/or set a custom signal mask. We get here only * if the file_actions parameter to task_spawn[p] was non-NULL and/or the diff --git a/tools/cfgdefine.c b/tools/cfgdefine.c index de91882a56..bb9a81eee2 100644 --- a/tools/cfgdefine.c +++ b/tools/cfgdefine.c @@ -98,7 +98,7 @@ static const char *dequote_list[] = * Private Functions ****************************************************************************/ - /* Skip over any spaces */ +/* Skip over any spaces */ static char *skip_space(char *ptr) { diff --git a/tools/cfgparser.c b/tools/cfgparser.c index 8ac52a5890..959cf9e5eb 100644 --- a/tools/cfgparser.c +++ b/tools/cfgparser.c @@ -61,7 +61,7 @@ char line[LINESIZE+1]; * Private Functions ****************************************************************************/ - /* Skip over any spaces */ +/* Skip over any spaces */ static char *skip_space(char *ptr) { diff --git a/tools/mkconfig.c b/tools/mkconfig.c index 038ad5fada..70160aa0bb 100644 --- a/tools/mkconfig.c +++ b/tools/mkconfig.c @@ -53,7 +53,7 @@ * Private Functions ****************************************************************************/ - static inline char *getfilepath(const char *name) +static inline char *getfilepath(const char *name) { snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name); line[PATH_MAX] = '\0'; diff --git a/tools/mkdeps.c b/tools/mkdeps.c index d6819ab25d..91e4147171 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -115,7 +115,7 @@ static char g_command[MAX_BUFFER]; * Private Functions ****************************************************************************/ - /* MinGW does not seem to provide strtok_r */ +/* MinGW does not seem to provide strtok_r */ #ifndef HAVE_STRTOK_R static char *MY_strtok_r(char *str, const char *delim, char **saveptr) -- GitLab From af086c40ff6f42b7254189f2b6f566bfcd0c3b7d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 4 Oct 2015 15:28:54 -0600 Subject: [PATCH 190/858] Remove dangling whitespace --- arch | 2 +- configs | 2 +- drivers/lcd/ssd1351.c | 4 ++-- drivers/net/tun.c | 2 +- drivers/sensors/adxl345_spi.c | 6 +++--- drivers/sensors/ms58xx.c | 2 +- drivers/timers/cs2100-cp.c | 4 ++-- drivers/timers/timer.c | 8 ++++---- drivers/usbhost/usbhost_cdcacm.c | 10 +++++----- fs/mount/fs_automount.c | 2 +- libc/math/lib_erf.c | 2 +- libc/math/lib_erff.c | 2 +- libc/math/lib_erfl.c | 2 +- libc/stdlib/lib_mkstemp.c | 4 ++-- mm/mm_gran/mm_pgalloc.c | 2 +- net/devif/devif_callback.c | 2 +- net/icmp/icmp_ping.c | 2 +- net/icmpv6/icmpv6_solicit.c | 2 +- net/iob/iob_concat.c | 2 +- net/iob/iob_test.c | 2 +- net/iob/iob_trimtail.c | 2 +- net/local/local_recvfrom.c | 2 +- sched/group/group_addrenv.c | 2 +- sched/sched/sched_timerexpiration.c | 4 ++-- 24 files changed, 37 insertions(+), 37 deletions(-) diff --git a/arch b/arch index cc863e71f9..4664ce223d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cc863e71f9fdf2b418365ff58ec2103dc1abbfcd +Subproject commit 4664ce223dba7c4190fca215b74a74b9bafcf30a diff --git a/configs b/configs index dbc09272e2..bc95908f1b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dbc09272e2e97c118372075d47281a563dc61db1 +Subproject commit bc95908f1bc1fd8f2895d91509cba860fe381474 diff --git a/drivers/lcd/ssd1351.c b/drivers/lcd/ssd1351.c index 88f6e55dbf..45e768a879 100644 --- a/drivers/lcd/ssd1351.c +++ b/drivers/lcd/ssd1351.c @@ -892,9 +892,9 @@ static int ssd1351_setpower(FAR struct lcd_dev_s *dev, int power) DEBUGASSERT(priv != NULL && (unsigned int)power <= LCD_FULL_ON); gvdbg("power: %d\n", power); - + /* Select and lock the device */ - + ssd1351_select(priv); if (power > LCD_FULL_OFF) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index d804eea2cb..b8c5ca09d3 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1112,7 +1112,7 @@ int tun_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) FAR struct tun_device_s *priv = filep->f_priv; pollevent_t eventset; int ret = OK; - + if (!priv) { return -EINVAL; diff --git a/drivers/sensors/adxl345_spi.c b/drivers/sensors/adxl345_spi.c index a87765e819..0c9cf0b118 100644 --- a/drivers/sensors/adxl345_spi.c +++ b/drivers/sensors/adxl345_spi.c @@ -101,7 +101,7 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Select the ADXL345 */ SPI_SELECT(priv->spi, SPIDEV_ACCELEROMETER, true); - + /* Send register to read and get the next byte */ (void)SPI_SEND(priv->spi, regaddr); @@ -148,7 +148,7 @@ void adxl345_putreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr, /* Select the ADXL345 */ SPI_SELECT(priv->spi, SPIDEV_ACCELEROMETER, true); - + /* Send register address and set the value */ (void)SPI_SEND(priv->spi, regaddr); @@ -186,7 +186,7 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Select the ADXL345 */ SPI_SELECT(priv->spi, SPIDEV_ACCELEROMETER, true); - + /* Send register to read and get the next 2 bytes */ (void)SPI_SEND(priv->spi, regaddr); diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index e539b1eaa8..ad5108f6cf 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -991,7 +991,7 @@ int ms58xx_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, priv->sensdivhs = 0; break; } - + switch (priv->model) { case MS58XX_MODEL_MS5803_02: diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index 2fb4f29f92..76ec3232aa 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -409,7 +409,7 @@ static int cs2100_refclk(FAR const struct cs2100_config_s *config) csdbg("ERROR: Failed to set CS2100_FNCCFG3: %d\n", ret); return ret; } - + /* Configure so that CLK_OUT will be enabled when the registers are * unlocked (also clears other settings). * NOTE: This implicitly sets High Multiplier mode for the Rud. @@ -446,7 +446,7 @@ static int cs2100_ratio(FAR const struct cs2100_config_s *config) bool highmul; int rmod; int ret; - + DEBUGASSERT(config->clkin > 0 && config->clkout > 0); /* Calculate a 64-bit RUD value: diff --git a/drivers/timers/timer.c b/drivers/timers/timer.c index 57c2c0eca9..c1c8a9ee42 100644 --- a/drivers/timers/timer.c +++ b/drivers/timers/timer.c @@ -88,7 +88,7 @@ struct timer_upperhalf_s FAR char *path; /* Registration path */ /* The contained lower-half driver */ - + FAR struct timer_lowerhalf_s *lower; }; @@ -173,7 +173,7 @@ static int timer_open(FAR struct file *filep) errout_with_sem: // sem_post(&upper->exclsem); - + errout: return ret; } @@ -214,7 +214,7 @@ static int timer_close(FAR struct file *filep) //sem_post(&upper->exclsem); ret = OK; - + errout: return ret; } @@ -254,7 +254,7 @@ static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer, * Description: * The standard ioctl method. This is where ALL of the timer work is * done. - * + * ************************************************************************************/ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) diff --git a/drivers/usbhost/usbhost_cdcacm.c b/drivers/usbhost/usbhost_cdcacm.c index ee63960394..eb3fe49cd5 100644 --- a/drivers/usbhost/usbhost_cdcacm.c +++ b/drivers/usbhost/usbhost_cdcacm.c @@ -1129,12 +1129,12 @@ static void usbhost_rxdata_work(FAR void *arg) rxbuf->head = nexthead; priv->rxndx = rxndx; - + /* Update the head point for for the next pass through the loop * handling. If nexthead incremented to rxbuf->tail, then the * RX buffer will and we will exit the loop at the top. */ - + if (++nexthead >= rxbuf->size) { nexthead = 0; @@ -1759,7 +1759,7 @@ static int usbhost_alloc_buffers(FAR struct usbhost_cdcacm_s *priv) ret, priv->pktsize); goto errout; } - + /* Allocate a TX buffer for Bulk IN transfers */ ret = DRVR_IOALLOC(hport->drvr, &priv->outbuf, priv->pktsize); @@ -2213,7 +2213,7 @@ static int usbhost_setup(FAR struct uart_dev_s *uartdev) usbhost_takesem(&priv->exclsem); /* Check if the CDC/ACM device is still connected. We need to disable - * interrupts momentarily to assure that there are no asynchronous + * interrupts momentarily to assure that there are no asynchronous * isconnect events. */ @@ -2592,7 +2592,7 @@ static void usbhost_rxint(FAR struct uart_dev_s *uartdev, bool enable) static bool usbhost_rxavailable(FAR struct uart_dev_s *uartdev) { - + FAR struct usbhost_cdcacm_s *priv; DEBUGASSERT(uartdev && uartdev->priv); diff --git a/fs/mount/fs_automount.c b/fs/mount/fs_automount.c index 1efa80ada0..e961fb5db8 100644 --- a/fs/mount/fs_automount.c +++ b/fs/mount/fs_automount.c @@ -249,7 +249,7 @@ static void automount_mount(FAR struct automounter_state_s *priv) priv->mounted = true; break; - + default: fdbg("ERROR: automount_findinode failed: %d\n", ret); break; diff --git a/libc/math/lib_erf.c b/libc/math/lib_erf.c index ecb1e36dbd..1923638dba 100644 --- a/libc/math/lib_erf.c +++ b/libc/math/lib_erf.c @@ -64,7 +64,7 @@ double erf(double x) a4 = -1.453152027; a5 = 1.061405429; p = 0.3275911; - + sign = (x >= 0 ? 1 : -1); t = 1.0/(1.0 + p*x); return sign * (1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * expf(-x * x)); diff --git a/libc/math/lib_erff.c b/libc/math/lib_erff.c index 2b38808caa..75199c828c 100644 --- a/libc/math/lib_erff.c +++ b/libc/math/lib_erff.c @@ -63,7 +63,7 @@ float erff(float x) a4 = -1.453152027; a5 = 1.061405429; p = 0.3275911; - + sign = (x >= 0 ? 1 : -1); t = 1.0/(1.0 + p*x); return sign * (1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * expf(-x * x)); diff --git a/libc/math/lib_erfl.c b/libc/math/lib_erfl.c index 1ebb736db2..44d6238980 100644 --- a/libc/math/lib_erfl.c +++ b/libc/math/lib_erfl.c @@ -64,7 +64,7 @@ long double erfl(long double x) a4 = -1.453152027; a5 = 1.061405429; p = 0.3275911; - + sign = (x >= 0 ? 1 : -1); t = 1.0/(1.0 + p*x); return sign * (1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * expf(-x * x)); diff --git a/libc/stdlib/lib_mkstemp.c b/libc/stdlib/lib_mkstemp.c index 6b92d0093d..fdf93cdfaf 100644 --- a/libc/stdlib/lib_mkstemp.c +++ b/libc/stdlib/lib_mkstemp.c @@ -61,7 +61,7 @@ #define MAX_XS 6 #define MIN_NUMERIC 0 /* 0-9: Numeric */ #define MAX_NUMERIC 9 -#define MIN_UPPERCASE 10 /* 10-35: Upper case */ +#define MIN_UPPERCASE 10 /* 10-35: Upper case */ #define MAX_UPPERCASE 35 #define MIN_LOWERCASE 36 /* 36-61: Lower case */ #define MAX_LOWERCASE 61 @@ -153,7 +153,7 @@ static void get_base62(FAR uint8_t *ptr) { DEBUGASSERT(errno == EINTR); } - + memcpy(ptr, g_base62, MAX_XS); incr_base62(); sem_post(&g_b62sem); diff --git a/mm/mm_gran/mm_pgalloc.c b/mm/mm_gran/mm_pgalloc.c index 6f7b33acdf..c4bda32d32 100644 --- a/mm/mm_gran/mm_pgalloc.c +++ b/mm/mm_gran/mm_pgalloc.c @@ -61,7 +61,7 @@ * * Dependencies: CONFIG_ARCH_USE_MMU and CONFIG_GRAN */ - + /* Debug */ #ifdef CONFIG_CPP_HAVE_VARARGS diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c index a72b15b4bf..fc89eaf7d5 100644 --- a/net/devif/devif_callback.c +++ b/net/devif/devif_callback.c @@ -226,7 +226,7 @@ FAR struct devif_callback_s * /* Add the newly allocated instance to the head of the device event * list. */ - + if (dev) { /* Verify that the device pointer is valid, i.e., that it still diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 9f23161227..41bc604dfd 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -345,7 +345,7 @@ int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen, #ifdef CONFIG_NET_ARP_SEND int ret; #endif - + /* Get the device that will be used to route this ICMP ECHO request */ #ifdef CONFIG_NETDEV_MULTINIC diff --git a/net/icmpv6/icmpv6_solicit.c b/net/icmpv6/icmpv6_solicit.c index 0548620020..cceac688da 100644 --- a/net/icmpv6/icmpv6_solicit.c +++ b/net/icmpv6/icmpv6_solicit.c @@ -126,7 +126,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev, icmp->destipaddr[7] = ipaddr[7]; /* Add out IPv6 address as the source address */ - + net_ipv6addr_copy(icmp->srcipaddr, dev->d_ipv6addr); /* Set up the ICMPv6 Neighbor Solicitation message */ diff --git a/net/iob/iob_concat.c b/net/iob/iob_concat.c index ecaa33b87e..21ad4e1fc0 100644 --- a/net/iob/iob_concat.c +++ b/net/iob/iob_concat.c @@ -83,7 +83,7 @@ void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2) { /* Find the last buffer in the iob1 buffer chain */ - + while (iob1->io_flink) { iob1 = iob1->io_flink; diff --git a/net/iob/iob_test.c b/net/iob/iob_test.c index 871f1e0126..fe683f9d2d 100644 --- a/net/iob/iob_test.c +++ b/net/iob/iob_test.c @@ -77,7 +77,7 @@ static void dump_chain(struct iob_s *iob) struct iob_s *head = iob; unsigned int pktlen; int n; - + printf("=========================================================\n"); printf("pktlen: %d\n", iob->io_pktlen); diff --git a/net/iob/iob_trimtail.c b/net/iob/iob_trimtail.c index 36eebb26f8..6305069860 100644 --- a/net/iob/iob_trimtail.c +++ b/net/iob/iob_trimtail.c @@ -143,7 +143,7 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen) penultimate->io_flink = NULL; } - + else { /* No, then just take what we need from this I/O buffer and diff --git a/net/local/local_recvfrom.c b/net/local/local_recvfrom.c index 1197285e5a..5ea052cd42 100644 --- a/net/local/local_recvfrom.c +++ b/net/local/local_recvfrom.c @@ -115,7 +115,7 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf, return ret; } } - + return OK; } diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index c1ddb07b6e..da25bdacdc 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -174,7 +174,7 @@ int group_addrenv(FAR struct tcb_s *tcb) } /* Save the new, current group */ - + g_gid_current = gid; } diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index c968da6bc8..76d5a1de28 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -111,7 +111,7 @@ uint32_t g_oneshot_maxticks = UINT32_MAX; /**************************************************************************** * Private Variables ****************************************************************************/ -/* This is the duration of the currently active timer or, when +/* This is the duration of the currently active timer or, when * sched_timer_expiration() is called, the duration of interval timer * that just expired. The value zero means that no timer was active. */ @@ -211,7 +211,7 @@ static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) /* If a context switch occurred, then need to return delay remaining for * the new task at the head of the ready to run list. */ - + ntcb = (FAR struct tcb_s*)g_readytorun.head; /* Check if the new task at the head of the ready-to-run has changed. */ -- GitLab From bb05de4b6ec5ee7797610c88abf3b56001a5b63c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 4 Oct 2015 16:01:21 -0600 Subject: [PATCH 191/858] Remove TABs --- arch | 2 +- configs | 2 +- drivers/sensors/as5048b.c | 2 +- libc/net/lib_htonl.c | 2 +- libc/semaphore/sem_getvalue.c | 2 +- libc/string/lib_memmove.c | 4 ++-- libc/string/lib_strcmp.c | 3 ++- libc/string/lib_strpbrk.c | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arch b/arch index 4664ce223d..0f4940ff63 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4664ce223dba7c4190fca215b74a74b9bafcf30a +Subproject commit 0f4940ff6339d4a4e4b8fdfeb3af8dd54f77b93f diff --git a/configs b/configs index bc95908f1b..2386155376 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bc95908f1bc1fd8f2895d91509cba860fe381474 +Subproject commit 2386155376e4ebcbcdcb15b3dfb1e6205f33c54a diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index f0e8d4f907..e33ea6e038 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -197,7 +197,7 @@ static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, uint8_t regval) { uint8_t buffer[2]; - int ret; + int ret; sndbg("addr: %02x value: %02x\n", regaddr, regval); diff --git a/libc/net/lib_htonl.c b/libc/net/lib_htonl.c index c499a71f1e..dba465583f 100644 --- a/libc/net/lib_htonl.c +++ b/libc/net/lib_htonl.c @@ -54,7 +54,7 @@ uint32_t htonl(uint32_t hl) return (( (hl) >> 24) | (((hl) >> 8) & 0x0000ff00) | (((hl) << 8) & 0x00ff0000) | - ( (hl) << 24)); + ( (hl) << 24)); #endif } diff --git a/libc/semaphore/sem_getvalue.c b/libc/semaphore/sem_getvalue.c index b1412a85ce..6233e60298 100644 --- a/libc/semaphore/sem_getvalue.c +++ b/libc/semaphore/sem_getvalue.c @@ -103,6 +103,6 @@ int sem_getvalue(FAR sem_t *sem, FAR int *sval) else { set_errno(EINVAL); - return ERROR; + return ERROR; } } diff --git a/libc/string/lib_memmove.c b/libc/string/lib_memmove.c index 8c70998e81..d4b28b4f05 100644 --- a/libc/string/lib_memmove.c +++ b/libc/string/lib_memmove.c @@ -59,7 +59,7 @@ FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) s = (char*) src; while (count--) { - *tmp++ = *s++; + *tmp++ = *s++; } } else @@ -68,7 +68,7 @@ FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) s = (char*) src + count; while (count--) { - *--tmp = *--s; + *--tmp = *--s; } } diff --git a/libc/string/lib_strcmp.c b/libc/string/lib_strcmp.c index a871c4a854..364caa7f5f 100644 --- a/libc/string/lib_strcmp.c +++ b/libc/string/lib_strcmp.c @@ -52,8 +52,9 @@ int strcmp(const char *cs, const char *ct) for (;;) { if ((result = *cs - *ct++) != 0 || !*cs++) - break; + break; } + return result; } #endif diff --git a/libc/string/lib_strpbrk.c b/libc/string/lib_strpbrk.c index c97b395e51..78d54ba407 100644 --- a/libc/string/lib_strpbrk.c +++ b/libc/string/lib_strpbrk.c @@ -67,7 +67,7 @@ char *strpbrk(const char *str, const char *charset) /* Yes, then this position must be the first occurrence in string */ return (char*)str; - } + } /* This character from the strings matches none of those in the charset. * Try the next character from the string. -- GitLab From d803b64f6b28a610e139eb0992b8c797994b9acd Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 6 Oct 2015 12:44:05 -0400 Subject: [PATCH 192/858] libxx: Add __cxa_guard_acquire, __cxa_guard_release and __cxa_guard_abort --- libxx/Makefile | 2 +- libxx/libxx_cxa_guard.cxx | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 libxx/libxx_cxa_guard.cxx diff --git a/libxx/Makefile b/libxx/Makefile index 5c5be9c41c..2fee701186 100644 --- a/libxx/Makefile +++ b/libxx/Makefile @@ -50,7 +50,7 @@ endif ifneq ($(CONFIG_UCLIBCXX),y) CXXSRCS += libxx_delete.cxx libxx_deletea.cxx libxx_new.cxx libxx_newa.cxx -CXXSRCS += libxx_stdthrow.cxx +CXXSRCS += libxx_stdthrow.cxx libxx_cxa_guard.cxx else ifneq ($(UCLIBCXX_EXCEPTION),y) CXXSRCS += libxx_stdthrow.cxx diff --git a/libxx/libxx_cxa_guard.cxx b/libxx/libxx_cxa_guard.cxx new file mode 100644 index 0000000000..47e9c4ea8d --- /dev/null +++ b/libxx/libxx_cxa_guard.cxx @@ -0,0 +1,87 @@ +//*************************************************************************** +// libxx/libxx_cxa_guard.cxx +// +// Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. +// Author: Paul Alexander Patience +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX nor the names of its contributors may be +// used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +//*************************************************************************** + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include + +//*************************************************************************** +// Pre-processor Definitions +//*************************************************************************** + +//*************************************************************************** +// Private Types +//*************************************************************************** + +__extension__ typedef int __guard __attribute__((mode(__DI__))); + +//*************************************************************************** +// Private Data +//*************************************************************************** + +//*************************************************************************** +// Public Functions +//*************************************************************************** + +extern "C" +{ + //************************************************************************* + // Name: __cxa_guard_acquire + //************************************************************************* + + int __cxa_guard_acquire(FAR __guard *g) + { + return !*g; + } + + //************************************************************************* + // Name: __cxa_guard_release + //************************************************************************* + + void __cxa_guard_release(FAR __guard *g) + { + *g = 1; + } + + //************************************************************************* + // Name: __cxa_guard_abort + //************************************************************************* + + void __cxa_guard_abort(FAR __guard *) + { + } +} -- GitLab From 59e5e2f5cc58779d0dcc7ea49db336114f57bb34 Mon Sep 17 00:00:00 2001 From: Pierre-noel Bouteville Date: Wed, 7 Oct 2015 14:29:23 -0600 Subject: [PATCH 193/858] drivers/lcd/st7565.c: Extend to include support for the ERC12864-3. From Pierre-noel Bouteville --- ChangeLog | 3 +++ arch | 2 +- drivers/lcd/Kconfig | 3 +++ drivers/lcd/st7565.c | 11 +++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e3968d2772..6aa0e2b1ef 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11011,3 +11011,6 @@ * libc/stdlib/lib_qsort.c and include/stdlib.h: Make coding style more conformant, take description from OpenGroup.org, rename formal parameters to match names used on OpenGroup.org (2015-10-02). + * drivers/lcd/st7565.c: Extend to include support for the ERC12864-3. + From Pierre-noel Bouteville (2015-10-07). + diff --git a/arch b/arch index 0f4940ff63..0b8c98bfac 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0f4940ff6339d4a4e4b8fdfeb3af8dd54f77b93f +Subproject commit 0b8c98bfac171b330430a02070ecbe8bb9618de3 diff --git a/drivers/lcd/Kconfig b/drivers/lcd/Kconfig index a895ca0dea..a7be77550c 100644 --- a/drivers/lcd/Kconfig +++ b/drivers/lcd/Kconfig @@ -564,6 +564,9 @@ choice config NHD_C12864KGZ bool "like NHD C12864KGZ" +config ERC_12864_3 + bool "like ERC12864-3" + endchoice config ST7565_NINTERFACES diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c index 592c39d3ae..fb42531d2a 100644 --- a/drivers/lcd/st7565.c +++ b/drivers/lcd/st7565.c @@ -1025,6 +1025,17 @@ FAR struct lcd_dev_s *st7565_initialize(FAR struct st7565_lcd_s *lcd, (void)st7565_send_one_data(priv, ST7565_POWERCTRL_INT); (void)st7565_send_one_data(priv, ST7565_SETSTARTLINE); +#elif CONFIG_ERC_12864_3 + + (void)st7565_send_one_data(priv, ST7565_ADCNORMAL); + (void)st7565_send_one_data(priv, ST7565_SETCOMREVERSE); + (void)st7565_send_one_data(priv, ST7565_BIAS_1_9); + (void)st7565_send_one_data(priv, ST7565_POWERCTRL_INT); + (void)st7565_send_one_data(priv, ST7565_REG_RES_5_5); + (void)st7565_send_one_data(priv, ST7565_SETEVMODE); + (void)st7565_send_one_data(priv, ST7565_SETEVREG(0x24)); + (void)st7565_send_one_data(priv, ST7565_SETSTARTLINE); + #else # error "No initialization sequence selected" #endif -- GitLab From 79d554939ea9a8e65f917ca5d00ce15af07a10c8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 7 Oct 2015 19:59:14 -0600 Subject: [PATCH 194/858] sched/: Fix some spacing issues --- arch | 2 +- configs | 2 +- sched/clock/clock_abstime2ticks.c | 2 +- sched/environ/env_clearenv.c | 2 +- sched/environ/env_dup.c | 2 +- sched/environ/env_findvar.c | 2 +- sched/environ/env_getenv.c | 5 ++- sched/environ/env_getenvironptr.c | 4 +-- sched/environ/env_putenv.c | 2 +- sched/environ/env_setenv.c | 2 +- sched/environ/env_unsetenv.c | 2 +- sched/errno/errno_getptr.c | 2 +- sched/group/group_create.c | 2 +- sched/group/group_foreachchild.c | 10 +++--- sched/group/group_leave.c | 2 +- sched/group/group_setupstreams.c | 6 ++-- sched/group/group_setuptaskfiles.c | 6 ++-- sched/init/os_start.c | 6 ++-- sched/mqueue/mq_desclose.c | 8 ++--- sched/mqueue/mq_descreate.c | 2 +- sched/mqueue/mq_initialize.c | 8 ++--- sched/mqueue/mq_msgfree.c | 4 +-- sched/mqueue/mq_msgqalloc.c | 2 +- sched/mqueue/mq_msgqfree.c | 2 +- sched/mqueue/mq_notify.c | 2 +- sched/mqueue/mq_rcvinternal.c | 8 ++--- sched/mqueue/mq_sndinternal.c | 20 ++++++------ sched/paging/pg_miss.c | 2 +- sched/paging/pg_worker.c | 14 ++++----- sched/pthread/pthread_cancel.c | 2 +- sched/pthread/pthread_condbroadcast.c | 4 +-- sched/pthread/pthread_conddestroy.c | 4 +-- sched/pthread/pthread_condinit.c | 2 +- sched/pthread/pthread_condsignal.c | 4 +-- sched/pthread/pthread_condtimedwait.c | 6 ++-- sched/pthread/pthread_condwait.c | 6 ++-- sched/pthread/pthread_create.c | 8 ++--- sched/pthread/pthread_exit.c | 2 +- sched/pthread/pthread_getspecific.c | 2 +- sched/pthread/pthread_keycreate.c | 5 +-- sched/pthread/pthread_mutexdestroy.c | 2 +- sched/pthread/pthread_mutexinit.c | 2 +- sched/pthread/pthread_mutexlock.c | 2 +- sched/pthread/pthread_mutextrylock.c | 2 +- sched/pthread/pthread_mutexunlock.c | 2 +- sched/pthread/pthread_setcancelstate.c | 4 +-- sched/pthread/pthread_setspecific.c | 4 +-- sched/sched/sched_addblocked.c | 6 ++-- sched/sched/sched_addprioritized.c | 14 ++++----- sched/sched/sched_addreadytorun.c | 6 ++-- sched/sched/sched_cpuload.c | 2 +- sched/sched/sched_foreach.c | 8 ++--- sched/sched/sched_free.c | 6 ++-- sched/sched/sched_garbage.c | 24 +++++++-------- sched/sched/sched_getfiles.c | 2 +- sched/sched/sched_getparam.c | 6 ++-- sched/sched/sched_getscheduler.c | 2 +- sched/sched/sched_getsockets.c | 2 +- sched/sched/sched_getstreams.c | 2 +- sched/sched/sched_gettcb.c | 2 +- sched/sched/sched_lock.c | 2 +- sched/sched/sched_lockcount.c | 2 +- sched/sched/sched_mergepending.c | 6 ++-- sched/sched/sched_processtimer.c | 2 +- sched/sched/sched_releasetcb.c | 2 +- sched/sched/sched_removeblocked.c | 3 +- sched/sched/sched_reprioritize.c | 12 ++++---- sched/sched/sched_rrgetinterval.c | 2 +- sched/sched/sched_self.c | 2 +- sched/sched/sched_setparam.c | 2 +- sched/sched/sched_setpriority.c | 8 +++-- sched/sched/sched_setscheduler.c | 2 +- sched/sched/sched_sporadic.c | 20 ++++++------ sched/sched/sched_timerexpiration.c | 14 ++++----- sched/sched/sched_unlock.c | 6 ++-- sched/sched/sched_waitid.c | 8 ++--- sched/sched/sched_waitpid.c | 10 +++--- sched/sched/sched_yield.c | 2 +- sched/semaphore/sem_holder.c | 20 ++++++------ sched/semaphore/sem_post.c | 2 +- sched/semaphore/sem_tickwait.c | 2 +- sched/semaphore/sem_trywait.c | 2 +- sched/semaphore/sem_wait.c | 2 +- sched/signal/sig_action.c | 16 +++++----- sched/signal/sig_allocatependingsigaction.c | 6 ++-- sched/signal/sig_cleanup.c | 14 ++++----- sched/signal/sig_deliver.c | 10 +++--- sched/signal/sig_dispatch.c | 24 +++++++-------- sched/signal/sig_findaction.c | 2 +- sched/signal/sig_initialize.c | 24 +++++++-------- sched/signal/sig_pending.c | 4 +-- sched/signal/sig_procmask.c | 2 +- sched/signal/sig_releasependingsigaction.c | 6 ++-- sched/signal/sig_releasependingsignal.c | 4 +-- sched/signal/sig_removependingsignal.c | 4 +-- sched/signal/sig_suspend.c | 2 +- sched/signal/sig_timedwait.c | 10 +++--- sched/signal/sig_unmaskpendingsignal.c | 34 ++++++++++----------- sched/task/exit.c | 2 +- sched/task/task_atexit.c | 4 +-- sched/task/task_create.c | 2 +- sched/task/task_delete.c | 2 +- sched/task/task_exit.c | 4 +-- sched/task/task_exithook.c | 4 +-- sched/task/task_onexit.c | 4 +-- sched/task/task_posixspawn.c | 20 ++++++------ sched/task/task_restart.c | 6 ++-- sched/task/task_setup.c | 12 ++++---- sched/task/task_spawn.c | 22 ++++++------- sched/task/task_start.c | 2 +- sched/task/task_terminate.c | 3 +- sched/task/task_vfork.c | 2 +- sched/timer/timer_create.c | 12 ++++---- sched/timer/timer_initialize.c | 9 +++--- sched/timer/timer_release.c | 4 +-- sched/timer/timer_settime.c | 2 +- sched/wdog/wd_cancel.c | 2 +- sched/wdog/wd_delete.c | 2 +- sched/wdog/wd_initialize.c | 4 +-- sched/wdog/wd_start.c | 18 +++++------ sched/wqueue/kwork_hpthread.c | 2 +- sched/wqueue/kwork_lpthread.c | 18 +++++------ sched/wqueue/kwork_process.c | 20 ++++++------ 123 files changed, 381 insertions(+), 374 deletions(-) diff --git a/arch b/arch index 0b8c98bfac..ecb6712035 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0b8c98bfac171b330430a02070ecbe8bb9618de3 +Subproject commit ecb67120352a5acc46c6ea06fe882ddfb597824f diff --git a/configs b/configs index 2386155376..20921ccad2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2386155376e4ebcbcdcb15b3dfb1e6205f33c54a +Subproject commit 20921ccad2cf456d6828d5d9f4ec8763a5f31f1f diff --git a/sched/clock/clock_abstime2ticks.c b/sched/clock/clock_abstime2ticks.c index a33b2acc1b..30027d7617 100644 --- a/sched/clock/clock_abstime2ticks.c +++ b/sched/clock/clock_abstime2ticks.c @@ -85,7 +85,7 @@ static long compare_timespec(FAR const struct timespec *a, if (a->tv_sec > b->tv_sec) { return 1; - } + } return (long)a->tv_nsec -(long)b->tv_nsec; } diff --git a/sched/environ/env_clearenv.c b/sched/environ/env_clearenv.c index e45939ce0e..acfb6b2f46 100644 --- a/sched/environ/env_clearenv.c +++ b/sched/environ/env_clearenv.c @@ -74,7 +74,7 @@ int clearenv(void) { - FAR struct tcb_s *tcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; DEBUGASSERT(tcb->group); env_release(tcb->group); diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 90abc1c98f..542774f892 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -81,7 +81,7 @@ int env_dup(FAR struct task_group_s *group) { - FAR struct tcb_s *ptcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; FAR char *envp = NULL; size_t envlen; int ret = OK; diff --git a/sched/environ/env_findvar.c b/sched/environ/env_findvar.c index 2112c14118..2a5b959da7 100644 --- a/sched/environ/env_findvar.c +++ b/sched/environ/env_findvar.c @@ -67,7 +67,7 @@ static bool env_cmpname(const char *pszname, const char *peqname) /* On sucess, pszname will end with '\0' and peqname with '=' */ - if ( *pszname == '\0' && *peqname == '=' ) + if (*pszname == '\0' && *peqname == '=') { return true; } diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c index 51f886fe0f..ae1408d045 100644 --- a/sched/environ/env_getenv.c +++ b/sched/environ/env_getenv.c @@ -94,12 +94,12 @@ FAR char *getenv(const char *name) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; group = rtcb->group; /* Check if the variable exists */ - if ( !group || (pvar = env_findvar(group, name)) == NULL) + if (!group || (pvar = env_findvar(group, name)) == NULL) { ret = ENOENT; goto errout_with_lock; @@ -130,4 +130,3 @@ errout: } #endif /* CONFIG_DISABLE_ENVIRON */ - diff --git a/sched/environ/env_getenvironptr.c b/sched/environ/env_getenvironptr.c index f56a08a1b0..447fff2b89 100644 --- a/sched/environ/env_getenvironptr.c +++ b/sched/environ/env_getenvironptr.c @@ -71,7 +71,7 @@ * ****************************************************************************/ -FAR char **get_environ_ptr( void ) +FAR char **get_environ_ptr(void) { #if 1 @@ -85,7 +85,7 @@ FAR char **get_environ_ptr( void ) /* Return a reference to the thread-private environ in the TCB. */ - FAR struct tcb_s *ptcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; if (ptcb->envp) { return &ptcb->envp->ev_env; diff --git a/sched/environ/env_putenv.c b/sched/environ/env_putenv.c index aef05fc829..1d10d798a1 100644 --- a/sched/environ/env_putenv.c +++ b/sched/environ/env_putenv.c @@ -100,7 +100,7 @@ int putenv(FAR const char *string) goto errout; } - pequal = strchr( pname, '='); + pequal = strchr(pname, '='); if (pequal) { /* Then let setenv do all of the work */ diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index 92b118cfc8..250a14c365 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -124,7 +124,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index 013b9e6804..39a87265d9 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -77,7 +77,7 @@ int unsetenv(FAR const char *name) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->group; FAR char *pvar; FAR char *newenvp; diff --git a/sched/errno/errno_getptr.c b/sched/errno/errno_getptr.c index 50a753d021..c24bed5a49 100644 --- a/sched/errno/errno_getptr.c +++ b/sched/errno/errno_getptr.c @@ -101,7 +101,7 @@ FAR int *get_errno_ptr(void) * may be NULL. */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; if (rtcb && rtcb->task_state == TSTATE_TASK_RUNNING) { /* Yes.. the task is running normally. Return a reference to the diff --git a/sched/group/group_create.c b/sched/group/group_create.c index edacec0490..683b234400 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -115,7 +115,7 @@ static void group_assigngid(FAR struct task_group_s *group) /* Loop until we create a unique ID */ - for (;;) + for (; ; ) { /* Increment the ID counter. This is global data so be extra paranoid. */ diff --git a/sched/group/group_foreachchild.c b/sched/group/group_foreachchild.c index deaeea2cde..72c1c3b93e 100644 --- a/sched/group/group_foreachchild.c +++ b/sched/group/group_foreachchild.c @@ -83,11 +83,11 @@ int group_foreachchild(FAR struct task_group_s *group, for (i = 0; i < group->tg_nmembers; i++) { - ret = handler(group->tg_members[i], arg); - if (ret != 0) - { - return ret; - } + ret = handler(group->tg_members[i], arg); + if (ret != 0) + { + return ret; + } } return 0; diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 2bc3015e24..276617c2bb 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -312,7 +312,7 @@ static inline void group_removemember(FAR struct task_group_s *group, pid_t pid) /* Does this member have the matching pid */ if (group->tg_members[i] == pid) - { + { /* Remove the member from the array of members. This must be an * atomic operation because the member array may be accessed from * interrupt handlers (read-only). diff --git a/sched/group/group_setupstreams.c b/sched/group/group_setupstreams.c index 292f0a6fe4..ea57f32fc7 100644 --- a/sched/group/group_setupstreams.c +++ b/sched/group/group_setupstreams.c @@ -88,9 +88,9 @@ int group_setupstreams(FAR struct task_tcb_s *tcb) * fd = 2 is stderr (write-only, append) */ - (void)fs_fdopen(0, O_RDONLY, (FAR struct tcb_s *)tcb); - (void)fs_fdopen(1, O_WROK|O_CREAT, (FAR struct tcb_s *)tcb); - (void)fs_fdopen(2, O_WROK|O_CREAT, (FAR struct tcb_s *)tcb); + (void)fs_fdopen(0, O_RDONLY, (FAR struct tcb_s *)tcb); + (void)fs_fdopen(1, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb); + (void)fs_fdopen(2, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb); return OK; } diff --git a/sched/group/group_setuptaskfiles.c b/sched/group/group_setuptaskfiles.c index a1db88023f..c9b08cc934 100644 --- a/sched/group/group_setuptaskfiles.c +++ b/sched/group/group_setuptaskfiles.c @@ -89,7 +89,7 @@ static inline void sched_dupfiles(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct file *parent; FAR struct file *child; int i; @@ -102,7 +102,7 @@ static inline void sched_dupfiles(FAR struct task_tcb_s *tcb) * accordingly above. */ - /* Get pointers to the parent and child task file lists */ + /* Get pointers to the parent and child task file lists */ parent = rtcb->group->tg_filelist.fl_files; child = tcb->cmn.group->tg_filelist.fl_files; @@ -147,7 +147,7 @@ static inline void sched_dupsockets(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct socket *parent; FAR struct socket *child; int i; diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 29d3bc68f1..8e5d52cf06 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -311,7 +311,7 @@ void os_start(void) * that has pid == 0 and sched_priority == 0. */ - bzero((void*)&g_idletcb, sizeof(struct task_tcb_s)); + bzero((void *)&g_idletcb, sizeof(struct task_tcb_s)); g_idletcb.cmn.task_state = TSTATE_TASK_RUNNING; g_idletcb.cmn.entry.main = (main_t)os_start; g_idletcb.cmn.flags = TCB_FLAG_TTYPE_KERNEL; @@ -341,7 +341,7 @@ void os_start(void) /* Then add the idle task's TCB to the head of the ready to run list */ - dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun); + dq_addfirst((FAR dq_entry_t *)&g_idletcb, (FAR dq_queue_t *)&g_readytorun); /* Initialize the processor-specific portion of the TCB */ @@ -550,7 +550,7 @@ void os_start(void) /* When control is return to this point, the system is idle. */ sdbg("Beginning Idle Loop\n"); - for (;;) + for (; ; ) { /* Perform garbage collection (if it is not being done by the worker * thread). This cleans-up memory de-allocations that were queued diff --git a/sched/mqueue/mq_desclose.c b/sched/mqueue/mq_desclose.c index ae0dc1cefe..ca7bfc5b8a 100644 --- a/sched/mqueue/mq_desclose.c +++ b/sched/mqueue/mq_desclose.c @@ -105,7 +105,7 @@ void mq_desclose(mqd_t mqdes) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)sched_self(); + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)sched_self(); FAR struct task_group_s *group = rtcb->group; FAR struct mqueue_inode_s *msgq; @@ -115,7 +115,7 @@ void mq_desclose(mqd_t mqdes) * descriptors. */ - sq_rem((FAR sq_entry_t*)mqdes, &group->tg_msgdesq); + sq_rem((FAR sq_entry_t *)mqdes, &group->tg_msgdesq); /* Find the message queue associated with the message descriptor */ @@ -135,8 +135,8 @@ void mq_desclose(mqd_t mqdes) } #endif - /* Deallocate the message descriptor */ + /* Deallocate the message descriptor */ - mq_desfree(mqdes); + mq_desfree(mqdes); } diff --git a/sched/mqueue/mq_descreate.c b/sched/mqueue/mq_descreate.c index f7f2eba5da..957b52815c 100644 --- a/sched/mqueue/mq_descreate.c +++ b/sched/mqueue/mq_descreate.c @@ -166,7 +166,7 @@ mqd_t mq_descreate(FAR struct tcb_s *mtcb, FAR struct mqueue_inode_s *msgq, /* And add it to the specified task's TCB */ - sq_addlast((FAR sq_entry_t*)mqdes, &group->tg_msgdesq); + sq_addlast((FAR sq_entry_t *)mqdes, &group->tg_msgdesq); } return mqdes; diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index ee54e28ce5..c60fd9038a 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -130,7 +130,7 @@ mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, * configured number of messages. */ - mqmsgblock = (FAR struct mqueue_msg_s*) + mqmsgblock = (FAR struct mqueue_msg_s *) kmm_malloc(sizeof(struct mqueue_msg_s) * nmsgs); if (mqmsgblock) @@ -141,7 +141,7 @@ mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, for (i = 0; i < nmsgs; i++) { mqmsg->type = alloc_type; - sq_addlast((FAR sq_entry_t*)mqmsg++, queue); + sq_addlast((FAR sq_entry_t *)mqmsg++, queue); } } @@ -225,13 +225,13 @@ void mq_desblockalloc(void) * we ever need to reclaim the memory. */ - sq_addlast((FAR sq_entry_t*)&mqdesblock->queue, &g_desalloc); + sq_addlast((FAR sq_entry_t *)&mqdesblock->queue, &g_desalloc); /* Then add each message queue descriptor to the free list */ for (i = 0; i < NUM_MSG_DESCRIPTORS; i++) { - sq_addlast((FAR sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree); + sq_addlast((FAR sq_entry_t *)&mqdesblock->mqdes[i], &g_desfree); } } } diff --git a/sched/mqueue/mq_msgfree.c b/sched/mqueue/mq_msgfree.c index 96e9a95546..9d83f7be28 100644 --- a/sched/mqueue/mq_msgfree.c +++ b/sched/mqueue/mq_msgfree.c @@ -101,7 +101,7 @@ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfree); + sq_addlast((FAR sq_entry_t *)mqmsg, &g_msgfree); irqrestore(saved_state); } @@ -116,7 +116,7 @@ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfreeirq); + sq_addlast((FAR sq_entry_t *)mqmsg, &g_msgfreeirq); irqrestore(saved_state); } diff --git a/sched/mqueue/mq_msgqalloc.c b/sched/mqueue/mq_msgqalloc.c index 39c7e04c3a..6d9ccb0501 100644 --- a/sched/mqueue/mq_msgqalloc.c +++ b/sched/mqueue/mq_msgqalloc.c @@ -109,7 +109,7 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode, /* Allocate memory for the new message queue. */ - msgq = (FAR struct mqueue_inode_s*) + msgq = (FAR struct mqueue_inode_s *) kmm_zalloc(sizeof(struct mqueue_inode_s)); if (msgq) diff --git a/sched/mqueue/mq_msgqfree.c b/sched/mqueue/mq_msgqfree.c index 85a591502f..ac3627898b 100644 --- a/sched/mqueue/mq_msgqfree.c +++ b/sched/mqueue/mq_msgqfree.c @@ -92,7 +92,7 @@ void mq_msgqfree(FAR struct mqueue_inode_s *msgq) /* Deallocate any stranded messages in the message queue. */ - curr = (FAR struct mqueue_msg_s*)msgq->msglist.head; + curr = (FAR struct mqueue_msg_s *)msgq->msglist.head; while (curr) { /* Deallocate the message structure. */ diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index a9a57c3f07..c9836715fe 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -149,7 +149,7 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification) /* Get the current process ID */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = (struct tcb_s *)g_readytorun.head; /* Is there already a notification attached */ diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index fa7932f0c2..bcc7059b86 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -166,7 +166,7 @@ FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes) /* Get the message from the head of the queue */ - while ((rcvmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&msgq->msglist)) == NULL) + while ((rcvmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&msgq->msglist)) == NULL) { /* The queue is empty! Should we block until there the above condition * has been satisfied? @@ -176,7 +176,7 @@ FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes) { /* Yes.. Block and try again */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; rtcb->msgwaitq = msgq; msgq->nwaitnotempty++; @@ -259,7 +259,7 @@ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, /* Copy the message into the caller's buffer */ - memcpy(ubuffer, (const void*)mqmsg->mail, rcvmsglen); + memcpy(ubuffer, (FAR const void *)mqmsg->mail, rcvmsglen); /* Copy the message priority as well (if a buffer is provided) */ @@ -284,7 +284,7 @@ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, */ saved_state = irqsave(); - for (btcb = (FAR struct tcb_s*)g_waitingformqnotfull.head; + for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head; btcb && btcb->msgwaitq != msgq; btcb = btcb->flink); diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index 3bfb4d9e56..f2a312f8ef 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -174,12 +174,12 @@ FAR struct mqueue_msg_s *mq_msgalloc(void) { /* Try the general free list */ - mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfree); + mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); if (!mqmsg) { /* Try the free list reserved for interrupt handlers */ - mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfreeirq); + mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfreeirq); } } @@ -192,7 +192,7 @@ FAR struct mqueue_msg_s *mq_msgalloc(void) */ saved_state = irqsave(); - mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfree); + mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); irqrestore(saved_state); /* If we cannot a message from the free list, then we will have to allocate one. */ @@ -278,7 +278,7 @@ int mq_waitsend(mqd_t mqdes) * When we are unblocked, we will try again */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; rtcb->msgwaitq = msgq; msgq->nwaitnotfull++; @@ -293,7 +293,7 @@ int mq_waitsend(mqd_t mqdes) if (get_errno() != OK) { - return ERROR; + return ERROR; } } } @@ -346,7 +346,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, /* Copy the message data into the message */ - memcpy((void*)mqmsg->mail, (FAR const void*)msg, msglen); + memcpy((FAR void *)mqmsg->mail, (FAR const void *)msg, msglen); /* Insert the new message in the message queue */ @@ -356,7 +356,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, * message. Each is list is maintained in ascending priority order. */ - for (prev = NULL, next = (FAR struct mqueue_msg_s*)msgq->msglist.head; + for (prev = NULL, next = (FAR struct mqueue_msg_s *)msgq->msglist.head; next && prio <= next->priority; prev = next, next = next->next); @@ -364,12 +364,12 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, if (prev) { - sq_addafter((FAR sq_entry_t*)prev, (FAR sq_entry_t*)mqmsg, + sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)mqmsg, &msgq->msglist); } else { - sq_addfirst((FAR sq_entry_t*)mqmsg, &msgq->msglist); + sq_addfirst((FAR sq_entry_t *)mqmsg, &msgq->msglist); } /* Increment the count of messages in the queue */ @@ -422,7 +422,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, * interrupts should never cause a change in this list */ - for (btcb = (FAR struct tcb_s*)g_waitingformqnotempty.head; + for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head; btcb && btcb->msgwaitq != msgq; btcb = btcb->flink); diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index 7ebdc16829..d41821bc4f 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -121,7 +121,7 @@ void pg_miss(void) { - FAR struct tcb_s *ftcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *ftcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct tcb_s *wtcb; /* Sanity checking diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 25643dd3a7..1a661a8af2 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -249,7 +249,7 @@ static inline bool pg_dequeue(void) { /* Remove the TCB from the head of the list (if any) */ - g_pftcb = (FAR struct tcb_s *)dq_remfirst((dq_queue_t*)&g_waitingforfill); + g_pftcb = (FAR struct tcb_s *)dq_remfirst((dq_queue_t *)&g_waitingforfill); pgllvdbg("g_pftcb: %p\n", g_pftcb); if (g_pftcb != NULL) { @@ -538,7 +538,7 @@ int pg_worker(int argc, char *argv[]) pglldbg("Started\n"); (void)irqsave(); - for (;;) + for (; ; ) { /* Wait awhile. We will wait here until either the configurable timeout * elapses or until we are awakened by a signal (which terminates the @@ -585,7 +585,7 @@ int pg_worker(int argc, char *argv[]) */ pglldbg("Restarting TCB: %p\n", g_pftcb); - up_unblock_task(g_pftcb);; + up_unblock_task(g_pftcb); /* Yes .. Start the next asynchronous fill. Check the return * value to see a fill was actually started (false means that @@ -638,7 +638,7 @@ int pg_worker(int argc, char *argv[]) * pending fills have been processed. */ - for (;;) + for (; ; ) { /* Yes .. Start the fill and block until the fill completes. * Check the return value to see a fill was actually performed. @@ -648,9 +648,9 @@ int pg_worker(int argc, char *argv[]) pgllvdbg("Calling pg_startfill\n"); if (!pg_startfill()) { - /* Break out of the loop -- there is nothing more to do */ + /* Break out of the loop -- there is nothing more to do */ - break; + break; } /* Handle the page fill complete event by restarting the @@ -661,7 +661,7 @@ int pg_worker(int argc, char *argv[]) */ pgllvdbg("Restarting TCB: %p\n", g_pftcb); - up_unblock_task(g_pftcb);; + up_unblock_task(g_pftcb); } /* All queued fills have been processed */ diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 60c2ba6585..8892dc6a43 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -132,7 +132,7 @@ int pthread_cancel(pthread_t thread) * same as pthread_exit(PTHREAD_CANCELED). */ - if (tcb == (struct tcb_s*)g_readytorun.head) + if (tcb == (struct tcb_s *)g_readytorun.head) { pthread_exit(PTHREAD_CANCELED); } diff --git a/sched/pthread/pthread_condbroadcast.c b/sched/pthread/pthread_condbroadcast.c index 98aa73f363..812b701ea9 100644 --- a/sched/pthread/pthread_condbroadcast.c +++ b/sched/pthread/pthread_condbroadcast.c @@ -108,7 +108,7 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond) /* Get the current value of the semaphore */ - if (sem_getvalue((sem_t*)&cond->sem, &sval) != OK) + if (sem_getvalue((FAR sem_t *)&cond->sem, &sval) != OK) { ret = EINVAL; } @@ -123,7 +123,7 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond) * Only the highest priority waiting thread will get to execute */ - ret = pthread_givesemaphore((sem_t*)&cond->sem); + ret = pthread_givesemaphore((FAR sem_t *)&cond->sem); /* Increment the semaphore count (as was done by the * above post). diff --git a/sched/pthread/pthread_conddestroy.c b/sched/pthread/pthread_conddestroy.c index 5cb5823ad4..2584e8dbae 100644 --- a/sched/pthread/pthread_conddestroy.c +++ b/sched/pthread/pthread_conddestroy.c @@ -75,9 +75,9 @@ int pthread_cond_destroy(FAR pthread_cond_t *cond) ret = EINVAL; } - /* Destroy the semaphore contained in the structure */ + /* Destroy the semaphore contained in the structure */ - else if (sem_destroy((sem_t*)&cond->sem) != OK) + else if (sem_destroy((FAR sem_t *)&cond->sem) != OK) { ret = EINVAL; } diff --git a/sched/pthread/pthread_condinit.c b/sched/pthread/pthread_condinit.c index 5671840233..a73811e078 100644 --- a/sched/pthread/pthread_condinit.c +++ b/sched/pthread/pthread_condinit.c @@ -80,7 +80,7 @@ int pthread_cond_init(FAR pthread_cond_t *cond, FAR const pthread_condattr_t *at * with initial count = 0 */ - else if (sem_init((sem_t*)&cond->sem, 0, 0) != OK) + else if (sem_init((FAR sem_t *)&cond->sem, 0, 0) != OK) { ret = EINVAL; } diff --git a/sched/pthread/pthread_condsignal.c b/sched/pthread/pthread_condsignal.c index 85d020bc31..e6b30adac5 100644 --- a/sched/pthread/pthread_condsignal.c +++ b/sched/pthread/pthread_condsignal.c @@ -100,7 +100,7 @@ int pthread_cond_signal(FAR pthread_cond_t *cond) { /* Get the current value of the semaphore */ - if (sem_getvalue((sem_t*)&cond->sem, &sval) != OK) + if (sem_getvalue((FAR sem_t *)&cond->sem, &sval) != OK) { ret = EINVAL; } @@ -125,7 +125,7 @@ int pthread_cond_signal(FAR pthread_cond_t *cond) if (sval < 0) { sdbg("Signalling...\n"); - ret = pthread_givesemaphore((sem_t*)&cond->sem); + ret = pthread_givesemaphore((FAR sem_t *)&cond->sem); } } } diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 6e9fa60dec..9a02ef912a 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -272,7 +272,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, /* Give up the mutex */ mutex->pid = -1; - ret = pthread_givesemaphore((sem_t*)&mutex->sem); + ret = pthread_givesemaphore((FAR sem_t *)&mutex->sem); if (ret) { /* Restore interrupts (pre-emption will be enabled when @@ -294,7 +294,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * are started atomically. */ - status = sem_wait((sem_t*)&cond->sem); + status = sem_wait((FAR sem_t *)&cond->sem); /* Did we get the condition semaphore. */ @@ -328,7 +328,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, /* Reacquire the mutex (retaining the ret). */ sdbg("Re-locking...\n"); - status = pthread_takesemaphore((sem_t*)&mutex->sem); + status = pthread_takesemaphore((FAR sem_t *)&mutex->sem); if (!status) { mutex->pid = mypid; diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 5c907ceac9..ab85895807 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -114,17 +114,17 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) sched_lock(); mutex->pid = -1; - ret = pthread_givesemaphore((sem_t*)&mutex->sem); + ret = pthread_givesemaphore((FAR sem_t *)&mutex->sem); /* Take the semaphore */ - ret |= pthread_takesemaphore((sem_t*)&cond->sem); + ret |= pthread_takesemaphore((FAR sem_t *)&cond->sem); sched_unlock(); /* Reacquire the mutex */ sdbg("Reacquire mutex...\n"); - ret |= pthread_takesemaphore((sem_t*)&mutex->sem); + ret |= pthread_takesemaphore((FAR sem_t *)&mutex->sem); if (!ret) { mutex->pid = getpid(); diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index b5df6364c7..c22cead9a9 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -165,9 +165,9 @@ static inline void pthread_addjoininfo(FAR struct task_group_s *group, static void pthread_start(void) { - FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s*)g_readytorun.head; + FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)g_readytorun.head; FAR struct task_group_s *group = ptcb->cmn.group; - FAR struct join_s *pjoin = (FAR struct join_s*)ptcb->joininfo; + FAR struct join_s *pjoin = (FAR struct join_s *)ptcb->joininfo; pthread_addr_t exit_status; DEBUGASSERT(group && pjoin); @@ -280,7 +280,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, /* Allocate a detachable structure to support pthread_join logic */ - pjoin = (FAR struct join_s*)kmm_zalloc(sizeof(struct join_s)); + pjoin = (FAR struct join_s *)kmm_zalloc(sizeof(struct join_s)); if (!pjoin) { sdbg("ERROR: Failed to allocate join\n"); @@ -509,7 +509,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, else { sched_unlock(); - dq_rem((FAR dq_entry_t*)ptcb, (dq_queue_t*)&g_inactivetasks); + dq_rem((FAR dq_entry_t *)ptcb, (FAR dq_queue_t *)&g_inactivetasks); (void)sem_destroy(&pjoin->data_sem); (void)sem_destroy(&pjoin->exit_sem); diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 6a8e2463a2..1fda5c2755 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -95,7 +95,7 @@ void pthread_exit(FAR void *exit_value) { - struct tcb_s *tcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; int status; sdbg("exit_value=%p\n", exit_value); diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index 34435a2ef4..8a470455f0 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -104,7 +104,7 @@ FAR void *pthread_getspecific(pthread_key_t key) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s*)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->cmn.group; FAR void *ret = NULL; diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c index 68af593a63..03d8486b48 100644 --- a/sched/pthread/pthread_keycreate.c +++ b/sched/pthread/pthread_keycreate.c @@ -108,10 +108,11 @@ * ****************************************************************************/ -int pthread_key_create(FAR pthread_key_t *key, CODE void (*destructor)(void*)) +int pthread_key_create(FAR pthread_key_t *key, + CODE void (*destructor)(FAR void *)) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->group; int ret = EAGAIN; diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index 04e2b37835..95fc8abef1 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -116,7 +116,7 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) { /* Destroy the semaphore */ - status = sem_destroy((sem_t*)&mutex->sem); + status = sem_destroy((FAR sem_t *)&mutex->sem); if (status != OK) { ret = EINVAL; diff --git a/sched/pthread/pthread_mutexinit.c b/sched/pthread/pthread_mutexinit.c index 7bba3ae6a4..9ed0b6ecb8 100644 --- a/sched/pthread/pthread_mutexinit.c +++ b/sched/pthread/pthread_mutexinit.c @@ -119,7 +119,7 @@ int pthread_mutex_init(FAR pthread_mutex_t *mutex, FAR const pthread_mutexattr_t /* Initialize the mutex like a semaphore with initial count = 1 */ - status = sem_init((sem_t*)&mutex->sem, pshared, 1); + status = sem_init((FAR sem_t *)&mutex->sem, pshared, 1); if (status != OK) { ret = EINVAL; diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index d1bce84e67..0ff12ab512 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -168,7 +168,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) { /* Take the semaphore */ - ret = pthread_takesemaphore((sem_t*)&mutex->sem); + ret = pthread_takesemaphore((FAR sem_t *)&mutex->sem); /* If we succussfully obtained the semaphore, then indicate * that we own it. diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index 0591ecf25d..d7b182c875 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -123,7 +123,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) /* Try to get the semaphore. */ - if (sem_trywait((sem_t*)&mutex->sem) == OK) + if (sem_trywait((FAR sem_t *)&mutex->sem) == OK) { /* If we successfully obtained the semaphore, then indicate * that we own it. diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 55ffa8b9f0..5ec784b8cc 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -152,7 +152,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) #ifdef CONFIG_MUTEX_TYPES mutex->nlocks = 0; #endif - ret = pthread_givesemaphore((sem_t*)&mutex->sem); + ret = pthread_givesemaphore((FAR sem_t *)&mutex->sem); } sched_unlock(); } diff --git a/sched/pthread/pthread_setcancelstate.c b/sched/pthread/pthread_setcancelstate.c index b898c211f0..4d4ba360f9 100644 --- a/sched/pthread/pthread_setcancelstate.c +++ b/sched/pthread/pthread_setcancelstate.c @@ -75,7 +75,7 @@ int pthread_setcancelstate(int state, FAR int *oldstate) { - struct tcb_s *tcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; int ret = OK; /* Suppress context changes for a bit so that the flags are stable. (the @@ -106,7 +106,7 @@ int pthread_setcancelstate(int state, FAR int *oldstate) /* Clear the non-cancelable and cancel pending flags */ - tcb->flags &= ~(TCB_FLAG_NONCANCELABLE|TCB_FLAG_CANCEL_PENDING); + tcb->flags &= ~(TCB_FLAG_NONCANCELABLE | TCB_FLAG_CANCEL_PENDING); /* If the cancel was pending, then just exit as requested */ diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c index 9b7e382ada..a91dc5e137 100644 --- a/sched/pthread/pthread_setspecific.c +++ b/sched/pthread/pthread_setspecific.c @@ -115,7 +115,7 @@ int pthread_setspecific(pthread_key_t key, FAR const void *value) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s*)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->cmn.group; int ret = EINVAL; @@ -128,7 +128,7 @@ int pthread_setspecific(pthread_key_t key, FAR const void *value) { /* Store the data in the TCB. */ - rtcb->pthread_data[key] = (FAR void*)value; + rtcb->pthread_data[key] = (FAR void *)value; /* Return success. */ diff --git a/sched/sched/sched_addblocked.c b/sched/sched/sched_addblocked.c index 87915f624b..05a8742431 100644 --- a/sched/sched/sched_addblocked.c +++ b/sched/sched/sched_addblocked.c @@ -105,14 +105,14 @@ void sched_addblocked(FAR struct tcb_s *btcb, tstate_t task_state) /* Add the task to a prioritized list */ sched_addprioritized(btcb, - (FAR dq_queue_t*)g_tasklisttable[task_state].list); + (FAR dq_queue_t *)g_tasklisttable[task_state].list); } else { /* Add the task to a non-prioritized list */ - dq_addlast((FAR dq_entry_t*)btcb, - (FAR dq_queue_t*)g_tasklisttable[task_state].list); + dq_addlast((FAR dq_entry_t *)btcb, + (FAR dq_queue_t *)g_tasklisttable[task_state].list); } /* Make sure the TCB's state corresponds to the list */ diff --git a/sched/sched/sched_addprioritized.c b/sched/sched/sched_addprioritized.c index babb31ef0d..3eff24b82c 100644 --- a/sched/sched/sched_addprioritized.c +++ b/sched/sched/sched_addprioritized.c @@ -110,7 +110,7 @@ bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list) * Each is list is maintained in ascending sched_priority order. */ - for (next = (FAR struct tcb_s*)list->head; + for (next = (FAR struct tcb_s *)list->head; (next && sched_priority <= next->sched_priority); next = next->flink); @@ -123,15 +123,15 @@ bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list) { /* The tcb goes at the end of the list. */ - prev = (FAR struct tcb_s*)list->tail; + prev = (FAR struct tcb_s *)list->tail; if (!prev) { /* Special case: The list is empty */ tcb->flink = NULL; tcb->blink = NULL; - list->head = (FAR dq_entry_t*)tcb; - list->tail = (FAR dq_entry_t*)tcb; + list->head = (FAR dq_entry_t *)tcb; + list->tail = (FAR dq_entry_t *)tcb; ret = true; } else @@ -141,14 +141,14 @@ bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list) tcb->flink = NULL; tcb->blink = prev; prev->flink = tcb; - list->tail = (FAR dq_entry_t*)tcb; + list->tail = (FAR dq_entry_t *)tcb; } } else { /* The tcb goes just before next */ - prev = (FAR struct tcb_s*)next->blink; + prev = (FAR struct tcb_s *)next->blink; if (!prev) { /* Special case: Insert at the head of the list */ @@ -156,7 +156,7 @@ bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list) tcb->flink = next; tcb->blink = NULL; next->blink = tcb; - list->head = (FAR dq_entry_t*)tcb; + list->head = (FAR dq_entry_t *)tcb; ret = true; } else diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 129f78c75e..2ebfcc49fe 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -100,7 +100,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; bool ret; /* Check if pre-emption is disabled for the current running task and if @@ -114,14 +114,14 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * g_pendingtasks task list for now. */ - sched_addprioritized(btcb, (FAR dq_queue_t*)&g_pendingtasks); + sched_addprioritized(btcb, (FAR dq_queue_t *)&g_pendingtasks); btcb->task_state = TSTATE_TASK_PENDING; ret = false; } /* Otherwise, add the new task to the ready-to-run task list */ - else if (sched_addprioritized(btcb, (FAR dq_queue_t*)&g_readytorun)) + else if (sched_addprioritized(btcb, (FAR dq_queue_t *)&g_readytorun)) { /* Inform the instrumentation logic that we are switching tasks */ diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index aa84ee9603..2cbef4c739 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -111,7 +111,7 @@ volatile uint32_t g_cpuload_total; void weak_function sched_process_cpuload(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; int hash_index; int i; diff --git a/sched/sched/sched_foreach.c b/sched/sched/sched_foreach.c index 64ac809996..ecd7437d13 100644 --- a/sched/sched/sched_foreach.c +++ b/sched/sched/sched_foreach.c @@ -72,10 +72,10 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) for (ndx = 0; ndx < CONFIG_MAX_TASKS; ndx++) { - if (g_pidhash[ndx].tcb) - { - handler(g_pidhash[ndx].tcb, arg); - } + if (g_pidhash[ndx].tcb) + { + handler(g_pidhash[ndx].tcb, arg); + } } irqrestore(flags); diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index 210c467340..e642a57921 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -127,7 +127,8 @@ void sched_ufree(FAR void *address) /* Delay the deallocation until a more appropriate time. */ - sq_addlast((FAR sq_entry_t*)address, (sq_queue_t*)&g_delayed_kufree); + sq_addlast((FAR sq_entry_t *)address, + (FAR sq_queue_t *)&g_delayed_kufree); /* Signal the worker thread that is has some clean up to do */ @@ -167,7 +168,8 @@ void sched_kfree(FAR void *address) /* Delay the deallocation until a more appropriate time. */ - sq_addlast((FAR sq_entry_t*)address, (sq_queue_t*)&g_delayed_kfree); + sq_addlast((FAR sq_entry_t *)address, + (FAR sq_queue_t *)&g_delayed_kfree); /* Signal the worker thread that is has some clean up to do */ diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index 2edaafc7db..f51a442caf 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -91,18 +91,18 @@ static inline void sched_kucleanup(void) irqstate_t flags; FAR void *address; - /* Test if the delayed deallocation queue is empty. No special protection - * is needed because this is an atomic test. - */ + /* Test if the delayed deallocation queue is empty. No special protection + * is needed because this is an atomic test. + */ - while (g_delayed_kufree.head) + while (g_delayed_kufree.head) { /* Remove the first delayed deallocation. This is not atomic and so * we must disable interrupts around the queue operation. */ flags = irqsave(); - address = (FAR void*)sq_remfirst((FAR sq_queue_t*)&g_delayed_kufree); + address = (FAR void *)sq_remfirst((FAR sq_queue_t *)&g_delayed_kufree); irqrestore(flags); /* The address should always be non-NULL since that was checked in the @@ -137,21 +137,21 @@ static inline void sched_kucleanup(void) defined(CONFIG_MM_KERNEL_HEAP) static inline void sched_kcleanup(void) { - irqstate_t flags; - FAR void *address; + irqstate_t flags; + FAR void *address; - /* Test if the delayed deallocation queue is empty. No special protection - * is needed because this is an atomic test. - */ + /* Test if the delayed deallocation queue is empty. No special protection + * is needed because this is an atomic test. + */ - while (g_delayed_kfree.head) + while (g_delayed_kfree.head) { /* Remove the first delayed deallocation. This is not atomic and so * we must disable interrupts around the queue operation. */ flags = irqsave(); - address = (FAR void*)sq_remfirst((FAR sq_queue_t*)&g_delayed_kfree); + address = (FAR void *)sq_remfirst((FAR sq_queue_t *)&g_delayed_kfree); irqrestore(flags); /* The address should always be non-NULL since that was checked in the diff --git a/sched/sched/sched_getfiles.c b/sched/sched/sched_getfiles.c index 685f9a44ab..f0608a465d 100644 --- a/sched/sched/sched_getfiles.c +++ b/sched/sched/sched_getfiles.c @@ -69,7 +69,7 @@ FAR struct filelist *sched_getfiles(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->group; /* The group may be NULL under certain conditions. For example, if diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 93794b7eec..44f9e885fa 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -110,12 +110,12 @@ int sched_getparam (pid_t pid, FAR struct sched_param *param) /* Check if the task to restart is the calling task */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; if ((pid == 0) || (pid == rtcb->pid)) { - /* Return the priority if the calling task. */ + /* Return the priority if the calling task. */ - param->sched_priority = (int)rtcb->sched_priority; + param->sched_priority = (int)rtcb->sched_priority; } /* Ths pid is not for the calling task, we will have to look it up */ diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index 8c4bb9de43..dfbb0e2818 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -107,7 +107,7 @@ int sched_getscheduler(pid_t pid) if (!pid) { - tcb = (struct tcb_s*)g_readytorun.head; + tcb = (struct tcb_s *)g_readytorun.head; } else { diff --git a/sched/sched/sched_getsockets.c b/sched/sched/sched_getsockets.c index 372f4eeaee..b292cd38ed 100644 --- a/sched/sched/sched_getsockets.c +++ b/sched/sched/sched_getsockets.c @@ -70,7 +70,7 @@ FAR struct socketlist *sched_getsockets(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_getstreams.c b/sched/sched/sched_getstreams.c index a87c95306c..29f3074b7a 100644 --- a/sched/sched/sched_getstreams.c +++ b/sched/sched/sched_getstreams.c @@ -69,7 +69,7 @@ FAR struct streamlist *sched_getstreams(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_gettcb.c b/sched/sched/sched_gettcb.c index 174af730ac..83de9358c7 100644 --- a/sched/sched/sched_gettcb.c +++ b/sched/sched/sched_gettcb.c @@ -84,7 +84,7 @@ FAR struct tcb_s *sched_gettcb(pid_t pid) /* Verify that the PID is within range */ - if (pid >= 0 ) + if (pid >= 0) { /* Get the hash_ndx associated with the pid */ diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 7c1e28a500..b01134d5c7 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -93,7 +93,7 @@ int sched_lock(void) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_lock() should have no diff --git a/sched/sched/sched_lockcount.c b/sched/sched/sched_lockcount.c index 355f08d902..b7f7730a73 100644 --- a/sched/sched/sched_lockcount.c +++ b/sched/sched/sched_lockcount.c @@ -91,7 +91,7 @@ int sched_lockcount(void) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; return (int)rtcb->lockcount; } diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 1a172f9150..b5028e2008 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -102,11 +102,11 @@ bool sched_mergepending(void) /* Initialize the inner search loop */ - rtrtcb = (FAR struct tcb_s*)g_readytorun.head; + rtrtcb = (FAR struct tcb_s *)g_readytorun.head; /* Process every TCB in the g_pendingtasks list */ - for (pndtcb = (FAR struct tcb_s*)g_pendingtasks.head; pndtcb; pndtcb = pndnext) + for (pndtcb = (FAR struct tcb_s *)g_pendingtasks.head; pndtcb; pndtcb = pndnext) { pndnext = pndtcb->flink; @@ -142,7 +142,7 @@ bool sched_mergepending(void) pndtcb->flink = rtrtcb; pndtcb->blink = NULL; rtrtcb->blink = pndtcb; - g_readytorun.head = (FAR dq_entry_t*)pndtcb; + g_readytorun.head = (FAR dq_entry_t *)pndtcb; rtrtcb->task_state = TSTATE_TASK_READYTORUN; pndtcb->task_state = TSTATE_TASK_RUNNING; ret = true; diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index 648ea800b3..4a7b246434 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -92,7 +92,7 @@ #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline void sched_process_scheduler(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; #if CONFIG_RR_INTERVAL > 0 /* Check if the currently executing task uses round robin scheduling. */ diff --git a/sched/sched/sched_releasetcb.c b/sched/sched/sched_releasetcb.c index aebf546630..b7046aa790 100644 --- a/sched/sched/sched_releasetcb.c +++ b/sched/sched/sched_releasetcb.c @@ -124,7 +124,7 @@ int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype) */ #ifdef CONFIG_HAVE_WEAKFUNCTIONS - if (timer_deleteall != NULL) + if (timer_deleteall != NULL) #endif { timer_deleteall(tcb->pid); diff --git a/sched/sched/sched_removeblocked.c b/sched/sched/sched_removeblocked.c index e09958b848..7b6b983b04 100644 --- a/sched/sched/sched_removeblocked.c +++ b/sched/sched/sched_removeblocked.c @@ -100,7 +100,8 @@ void sched_removeblocked(FAR struct tcb_s *btcb) * with this state */ - dq_rem((FAR dq_entry_t*)btcb, (dq_queue_t*)g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t *)btcb, + (FAR dq_queue_t *)g_tasklisttable[task_state].list); /* Make sure the TCB's state corresponds to not being in * any list diff --git a/sched/sched/sched_reprioritize.c b/sched/sched/sched_reprioritize.c index e6ac01e58c..b9bff17f36 100644 --- a/sched/sched/sched_reprioritize.c +++ b/sched/sched/sched_reprioritize.c @@ -112,16 +112,16 @@ int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority) int ret = sched_setpriority(tcb, sched_priority); if (ret == 0) { - /* Reset the base_priority -- the priority that the thread would return - * to once it posts the semaphore. - */ + /* Reset the base_priority -- the priority that the thread would return + * to once it posts the semaphore. + */ - tcb->base_priority = (uint8_t)sched_priority; + tcb->base_priority = (uint8_t)sched_priority; - /* Discard any pending reprioritizations as well */ + /* Discard any pending reprioritizations as well */ #if CONFIG_SEM_NNESTPRIO > 0 - tcb->npend_reprio = 0; + tcb->npend_reprio = 0; #endif } diff --git a/sched/sched/sched_rrgetinterval.c b/sched/sched/sched_rrgetinterval.c index 8c54ab00f5..5347f64166 100644 --- a/sched/sched/sched_rrgetinterval.c +++ b/sched/sched/sched_rrgetinterval.c @@ -91,7 +91,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) if (!pid) { - rrtcb = (FAR struct tcb_s*)g_readytorun.head; + rrtcb = (FAR struct tcb_s *)g_readytorun.head; } /* Return a special error code on invalid PID */ diff --git a/sched/sched/sched_self.c b/sched/sched/sched_self.c index 9dda2161b8..6302aa2208 100644 --- a/sched/sched/sched_self.c +++ b/sched/sched/sched_self.c @@ -77,7 +77,7 @@ FAR struct tcb_s *sched_self(void) { - return (FAR struct tcb_s*)g_readytorun.head; + return (FAR struct tcb_s *)g_readytorun.head; } diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index fa355c884a..cadda71bd3 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -106,7 +106,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param) /* Check if the task to reprioritize is the calling task */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; if (pid == 0 || pid == rtcb->pid) { tcb = rtcb; diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 191b972f2c..abb660cb3c 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -103,7 +103,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; tstate_t task_state; irqstate_t saved_state; @@ -204,7 +204,8 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { /* Remove the TCB from the prioritized task list */ - dq_rem((FAR dq_entry_t*)tcb, (FAR dq_queue_t*)g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t *)tcb, + (FAR dq_queue_t *)g_tasklisttable[task_state].list); /* Change the task priority */ @@ -214,7 +215,8 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) * position */ - sched_addprioritized(tcb, (FAR dq_queue_t*)g_tasklisttable[task_state].list); + sched_addprioritized(tcb, + (FAR dq_queue_t *)g_tasklisttable[task_state].list); } /* CASE 3b. The task resides in a non-prioritized list. */ diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index 841d9eb165..d3650374bb 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -109,7 +109,7 @@ int sched_setscheduler(pid_t pid, int policy, /* Check if the task to modify the calling task */ - if (pid == 0 ) + if (pid == 0) { pid = getpid(); } diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index afd3325de5..7cfa152b09 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -768,16 +768,16 @@ int sched_sporadic_initialize(FAR struct tcb_s *tcb) * sporadic scheduling parameters and state data. */ - sporadic = (FAR struct sporadic_s *)kmm_zalloc(sizeof(struct sporadic_s)); - if (sporadic == NULL) - { - slldbg("ERROR: Failed to allocate sporadic data structure\n"); - return -ENOMEM; - } + sporadic = (FAR struct sporadic_s *)kmm_zalloc(sizeof(struct sporadic_s)); + if (sporadic == NULL) + { + slldbg("ERROR: Failed to allocate sporadic data structure\n"); + return -ENOMEM; + } - /* The initialize required is to set the back pointer to the TCB in - * each of the replenishment structures. - */ + /* The initialize required is to set the back pointer to the TCB in + * each of the replenishment structures. + */ for (i = 0; i < CONFIG_SCHED_SPORADIC_MAXREPL; i++) { @@ -1145,7 +1145,7 @@ int sched_sporadic_suspend(FAR struct tcb_s *tcb) * * Input Parameters: * tcb - The TCB of the thread that is beginning sporadic - scheduling. + * scheduling. * ticks - The number of elapsed ticks since the last time this * function was called. * noswitches - We are running in a context where context switching is diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 76d5a1de28..41b12c4022 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -164,8 +164,8 @@ static struct timespec g_stop_time; #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; - FAR struct tcb_s *ntcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ntcb = (FAR struct tcb_s *)g_readytorun.head; uint32_t ret = 0; #if CONFIG_RR_INTERVAL > 0 @@ -212,15 +212,15 @@ static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) * the new task at the head of the ready to run list. */ - ntcb = (FAR struct tcb_s*)g_readytorun.head; + ntcb = (FAR struct tcb_s *)g_readytorun.head; /* Check if the new task at the head of the ready-to-run has changed. */ if (rtcb != ntcb) { - /* Recurse just to get the correct return value */ + /* Recurse just to get the correct return value */ - return sched_process_scheduler(0, true); + return sched_process_scheduler(0, true); } /* Returning zero means that there is no interesting event to be timed */ @@ -355,9 +355,9 @@ static void sched_timer_start(unsigned int ticks) ret = up_alarm_start(&ts); #else - /* [Re-]start the interval timer */ + /* [Re-]start the interval timer */ - ret = up_timer_start(&ts); + ret = up_timer_start(&ts); #endif if (ret < 0) diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 81b75f0af0..8c18aac6f1 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -63,7 +63,7 @@ int sched_unlock(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_unlock() should have no @@ -118,7 +118,7 @@ int sched_unlock(void) * maximum. */ - if (rtcb != (FAR struct tcb_s*)g_readytorun.head) + if (rtcb != (FAR struct tcb_s *)g_readytorun.head) { rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } @@ -156,7 +156,7 @@ int sched_unlock(void) * change the currently active task. */ - if (rtcb == (FAR struct tcb_s*)g_readytorun.head) + if (rtcb == (FAR struct tcb_s *)g_readytorun.head) { sched_timer_reassess(); } diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 9e49f9a1cd..8c24744945 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -225,9 +225,9 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) /* Does this task retain child status? */ - if (retains) + if (retains) { - /* Check if this specific pid has allocated child status? */ + /* Check if this specific pid has allocated child status? */ if (group_findchild(rtcb->group, (pid_t)id) == NULL) { @@ -248,7 +248,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) } else if (idtype == P_PID) { - /* Get the TCB corresponding to this PID and make sure it is our child. */ + /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb((pid_t)id); #ifdef HAVE_GROUP_MEMBERS @@ -265,7 +265,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) /* Loop until the child that we are waiting for dies */ - for (;;) + for (; ; ) { #ifdef CONFIG_SCHED_CHILD_STATUS /* Check if the task has already died. Signals are not queued in diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 55d2ef3bc2..e6d4ff96ce 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -353,11 +353,11 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Does this task retain child status? */ - if (retains) + if (retains) { - /* Check if this specific pid has allocated child status? */ + /* Check if this specific pid has allocated child status? */ - if (group_findchild(rtcb->group, pid) == NULL) + if (group_findchild(rtcb->group, pid) == NULL) { err = ECHILD; goto errout_with_errno; @@ -376,7 +376,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) } else if (pid != (pid_t)-1) { - /* Get the TCB corresponding to this PID and make sure it is our child. */ + /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb(pid); #ifdef HAVE_GROUP_MEMBERS @@ -394,7 +394,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Loop until the child that we are waiting for dies */ - for (;;) + for (; ; ) { #ifdef CONFIG_SCHED_CHILD_STATUS /* Check if the task has already died. Signals are not queued in diff --git a/sched/sched/sched_yield.c b/sched/sched/sched_yield.c index c7051d8d73..17d3bb0bbf 100644 --- a/sched/sched/sched_yield.c +++ b/sched/sched/sched_yield.c @@ -90,7 +90,7 @@ int sched_yield(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; /* This equivalent to just resetting the task priority to its current value * since this will cause the task to be rescheduled behind any other tasks diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index c08f90bb5a..7a2db8d0b4 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -290,10 +290,10 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, */ if (!sched_verifytcb(htcb)) - { + { sdbg("TCB 0x%08x is a stale handle, counts lost\n", htcb); sem_freeholder(sem, pholder); - } + } #if CONFIG_SEM_NNESTPRIO > 0 @@ -441,10 +441,10 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, */ if (!sched_verifytcb(htcb)) - { + { sdbg("TCB 0x%08x is a stale handle, counts lost\n", htcb); sem_freeholder(sem, pholder); - } + } /* Was the priority of the holder thread boosted? If so, then drop its * priority back to the correct level. What is the correct level? @@ -573,7 +573,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; if (pholder->htcb != rtcb) { return sem_restoreholderprio(pholder, sem, arg); @@ -593,7 +593,7 @@ static int sem_restoreholderprioA(FAR struct semholder_s *pholder, static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; if (pholder->htcb == rtcb) { (void)sem_restoreholderprio(pholder, sem, arg); @@ -699,7 +699,7 @@ static inline void sem_restorebaseprio_irq(FAR struct tcb_s *stcb, static inline void sem_restorebaseprio_task(FAR struct tcb_s *stcb, FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct semholder_s *pholder; /* Perform the following actions only if a new thread was given a count. @@ -858,7 +858,7 @@ void sem_destroyholder(FAR sem_t *sem) void sem_addholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct semholder_s *pholder; /* Find or allocate a container for this new holder */ @@ -893,7 +893,7 @@ void sem_addholder(FAR sem_t *sem) void sem_boostpriority(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; /* Boost the priority of every thread holding counts on this semaphore * that are lower in priority than the new thread that is waiting for a @@ -922,7 +922,7 @@ void sem_boostpriority(FAR sem_t *sem) void sem_releaseholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct semholder_s *pholder; /* Find the container for this holder */ diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 25edceb89b..43e78bf154 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -144,7 +144,7 @@ int sem_post(FAR sem_t *sem) * that we want. */ - for (stcb = (FAR struct tcb_s*)g_waitingforsemaphore.head; + for (stcb = (FAR struct tcb_s *)g_waitingforsemaphore.head; (stcb && stcb->waitsem != sem); stcb = stcb->flink); diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 57e36d1f0c..a72370383e 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -136,7 +136,7 @@ int sem_tickwait(FAR sem_t *sem, uint32_t start, uint32_t delay) /* Adjust the delay for any time since the delay was calculated */ elapsed = clock_systimer() - start; - if (/*elapsed >= (UINT32_MAX / 2) || */ elapsed >= delay) + if (/* elapsed >= (UINT32_MAX / 2) || */ elapsed >= delay) { ret = -ETIMEDOUT; goto errout_with_irqdisabled; diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index da4547b47e..75c92dd7b5 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -96,7 +96,7 @@ int sem_trywait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; irqstate_t saved_state; int ret = ERROR; diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index 883a2c3adc..5804fac1c5 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -96,7 +96,7 @@ int sem_wait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; irqstate_t saved_state; int ret = ERROR; diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 5619dec045..99b8aa51e8 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -88,7 +88,7 @@ static FAR sigactq_t *sig_allocateaction(void) /* Try to get the signal action structure from the free list */ - sigact = (FAR sigactq_t*)sq_remfirst(&g_sigfreeaction); + sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction); /* Check if we got one. */ @@ -100,7 +100,7 @@ static FAR sigactq_t *sig_allocateaction(void) /* And try again */ - sigact = (FAR sigactq_t*)sq_remfirst(&g_sigfreeaction); + sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction); ASSERT(sigact); } @@ -165,7 +165,7 @@ static FAR sigactq_t *sig_allocateaction(void) int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction *oact) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR sigactq_t *sigact; /* Since sigactions can only be installed from the running thread of @@ -254,7 +254,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * { /* Yes.. Remove it from sigactionq */ - sq_rem((FAR sq_entry_t*)sigact, &rtcb->sigactionq); + sq_rem((FAR sq_entry_t *)sigact, &rtcb->sigactionq); /* And deallocate it */ @@ -279,10 +279,10 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * /* An error has occurred if we could not allocate the sigaction */ if (!sigact) - { + { set_errno(ENOMEM); return ERROR; - } + } /* Put the signal number in the queue entry */ @@ -290,7 +290,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * /* Add the new sigaction to sigactionq */ - sq_addlast((FAR sq_entry_t*)sigact, &rtcb->sigactionq); + sq_addlast((FAR sq_entry_t *)sigact, &rtcb->sigactionq); } /* Set the new sigaction */ @@ -313,5 +313,5 @@ void sig_releaseaction(FAR sigactq_t *sigact) { /* Just put it back on the free list */ - sq_addlast((FAR sq_entry_t*)sigact, &g_sigfreeaction); + sq_addlast((FAR sq_entry_t *)sigact, &g_sigfreeaction); } diff --git a/sched/signal/sig_allocatependingsigaction.c b/sched/signal/sig_allocatependingsigaction.c index 12e65093c5..7b40802130 100644 --- a/sched/signal/sig_allocatependingsigaction.c +++ b/sched/signal/sig_allocatependingsigaction.c @@ -88,7 +88,7 @@ FAR sigq_t *sig_allocatependingsigaction(void) { /* Try to get the pending signal action structure from the free list */ - sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingaction); + sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingaction); /* If so, then try the special list of structures reserved for * interrupt handlers @@ -96,7 +96,7 @@ FAR sigq_t *sig_allocatependingsigaction(void) if (!sigq) { - sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingirqaction); + sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingirqaction); } } @@ -108,7 +108,7 @@ FAR sigq_t *sig_allocatependingsigaction(void) /* Try to get the pending signal action structure from the free list */ saved_state = irqsave(); - sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingaction); + sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingaction); irqrestore(saved_state); /* Check if we got one. */ diff --git a/sched/signal/sig_cleanup.c b/sched/signal/sig_cleanup.c index 862defa546..0d623e504c 100644 --- a/sched/signal/sig_cleanup.c +++ b/sched/signal/sig_cleanup.c @@ -83,29 +83,29 @@ void sig_cleanup(FAR struct tcb_s *stcb) /* Deallocate all entries in the list of signal actions */ - while ((sigact = (FAR sigactq_t*)sq_remfirst(&stcb->sigactionq)) != NULL) + while ((sigact = (FAR sigactq_t *)sq_remfirst(&stcb->sigactionq)) != NULL) { sig_releaseaction(sigact); } /* Deallocate all entries in the list of pending signal actions */ - while ((sigq = (FAR sigq_t*)sq_remfirst(&stcb->sigpendactionq)) != NULL) + while ((sigq = (FAR sigq_t *)sq_remfirst(&stcb->sigpendactionq)) != NULL) { sig_releasependingsigaction(sigq); } /* Deallocate all entries in the list of posted signal actions */ - while ((sigq = (FAR sigq_t*)sq_remfirst(&stcb->sigpostedq)) != NULL) + while ((sigq = (FAR sigq_t *)sq_remfirst(&stcb->sigpostedq)) != NULL) { sig_releasependingsigaction(sigq); } - /* Misc. signal-related clean-up */ + /* Misc. signal-related clean-up */ - stcb->sigprocmask = ALL_SIGNAL_SET; - stcb->sigwaitmask = NULL_SIGNAL_SET; + stcb->sigprocmask = ALL_SIGNAL_SET; + stcb->sigwaitmask = NULL_SIGNAL_SET; } /**************************************************************************** @@ -125,7 +125,7 @@ void sig_release(FAR struct task_group_s *group) /* Deallocate all entries in the list of pending signals */ - while ((sigpend = (FAR sigpendq_t*)sq_remfirst(&group->sigpendingq)) != NULL) + while ((sigpend = (FAR sigpendq_t *)sq_remfirst(&group->sigpendingq)) != NULL) { sig_releasependingsignal(sigpend); } diff --git a/sched/signal/sig_deliver.c b/sched/signal/sig_deliver.c index 7f2291b4b6..212b49151b 100644 --- a/sched/signal/sig_deliver.c +++ b/sched/signal/sig_deliver.c @@ -101,7 +101,7 @@ void sig_deliver(FAR struct tcb_s *stcb) */ saved_errno = stcb->pterrno; - for (sigq = (FAR sigq_t*)stcb->sigpendactionq.head; (sigq); sigq = next) + for (sigq = (FAR sigq_t *)stcb->sigpendactionq.head; (sigq); sigq = next) { next = sigq->flink; sdbg("Sending signal sigq=0x%x\n", sigq); @@ -112,8 +112,8 @@ void sig_deliver(FAR struct tcb_s *stcb) */ saved_state = irqsave(); - sq_rem((FAR sq_entry_t*)sigq, &(stcb->sigpendactionq)); - sq_addlast((FAR sq_entry_t*)sigq, &(stcb->sigpostedq)); + sq_rem((FAR sq_entry_t *)sigq, &(stcb->sigpendactionq)); + sq_addlast((FAR sq_entry_t *)sigq, &(stcb->sigpostedq)); irqrestore(saved_state); /* Call the signal handler (unless the signal was cancelled) @@ -173,13 +173,13 @@ void sig_deliver(FAR struct tcb_s *stcb) /* Remove the signal from the sigpostedq */ saved_state = irqsave(); - sq_rem((FAR sq_entry_t*)sigq, &(stcb->sigpostedq)); + sq_rem((FAR sq_entry_t *)sigq, &(stcb->sigpostedq)); irqrestore(saved_state); /* Then deallocate it */ sig_releasependingsigaction(sigq); - } + } stcb->pterrno = saved_errno; sched_unlock(); diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index a292424784..9027fddddb 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -117,15 +117,15 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) { /* Populate the new signal queue element */ - sigq->action.sighandler = sigact->act.sa_u._sa_sigaction; - sigq->mask = sigact->act.sa_mask; - memcpy(&sigq->info, info, sizeof(siginfo_t)); + sigq->action.sighandler = sigact->act.sa_u._sa_sigaction; + sigq->mask = sigact->act.sa_mask; + memcpy(&sigq->info, info, sizeof(siginfo_t)); - /* Put it at the end of the pending signals list */ + /* Put it at the end of the pending signals list */ - saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigq, &(stcb->sigpendactionq)); - irqrestore(saved_state); + saved_state = irqsave(); + sq_addlast((FAR sq_entry_t *)sigq, &(stcb->sigpendactionq)); + irqrestore(saved_state); } } @@ -152,7 +152,7 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) { /* Try to get the pending signal structure from the free list */ - sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingsignal); + sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal); if (!sigpend) { /* If no pending signal structure is available in the free list, @@ -160,7 +160,7 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) * interrupt handlers */ - sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingirqsignal); + sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingirqsignal); } } @@ -172,7 +172,7 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) /* Try to get the pending signal structure from the free list */ saved_state = irqsave(); - sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingsignal); + sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal); irqrestore(saved_state); /* Check if we got one. */ @@ -220,7 +220,7 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, /* Seach the list for a sigpendion on this signal */ - for (sigpend = (FAR sigpendq_t*)group->sigpendingq.head; + for (sigpend = (FAR sigpendq_t *)group->sigpendingq.head; (sigpend && sigpend->info.si_signo != signo); sigpend = sigpend->flink); @@ -274,7 +274,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, /* Add the structure to the pending signal list */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigpend, &group->sigpendingq); + sq_addlast((FAR sq_entry_t *)sigpend, &group->sigpendingq); irqrestore(saved_state); } } diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index 32616bfd3d..659e832002 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -89,7 +89,7 @@ FAR sigactq_t *sig_findaction(FAR struct tcb_s *stcb, int signo) /* Seach the list for a sigaction on this signal */ - for (sigact = (FAR sigactq_t*)stcb->sigactionq.head; + for (sigact = (FAR sigactq_t *)stcb->sigactionq.head; ((sigact) && (sigact->signo != signo)); sigact = sigact->flink); diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index bcdbc23020..5056325ec9 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -147,19 +147,19 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype) { - sigq_t *sigqalloc; - sigq_t *sigq; - int i; + FAR sigq_t *sigqalloc; + FAR sigq_t *sigq; + int i; /* Allocate a block of pending signal actions */ - sigqalloc = (sigq_t*)kmm_malloc((sizeof(sigq_t)) * nsigs); + sigqalloc = (FAR sigq_t *)kmm_malloc((sizeof(sigq_t)) * nsigs); sigq = sigqalloc; for (i = 0; i < nsigs; i++) { sigq->type = sigtype; - sq_addlast((FAR sq_entry_t*)sigq++, siglist); + sq_addlast((FAR sq_entry_t *)sigq++, siglist); } return sigqalloc; @@ -177,20 +177,20 @@ static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, uint16_t nsigs, uint8_t sigtype) { - sigpendq_t *sigpendalloc; - sigpendq_t *sigpend; + FAR sigpendq_t *sigpendalloc; + FAR sigpendq_t *sigpend; int i; /* Allocate a block of pending signal structures */ sigpendalloc = - (sigpendq_t*)kmm_malloc((sizeof(sigpendq_t)) * nsigs); + (FAR sigpendq_t *)kmm_malloc((sizeof(sigpendq_t)) * nsigs); sigpend = sigpendalloc; for (i = 0; i < nsigs; i++) { sigpend->type = sigtype; - sq_addlast((FAR sq_entry_t*)sigpend++, siglist); + sq_addlast((FAR sq_entry_t *)sigpend++, siglist); } return sigpendalloc; @@ -254,17 +254,17 @@ void sig_initialize(void) void sig_allocateactionblock(void) { - sigactq_t *sigact; + FAR sigactq_t *sigact; int i; /* Allocate a block of signal actions */ g_sigactionalloc = - (sigactq_t*)kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS); + (FAR sigactq_t *)kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS); sigact = g_sigactionalloc; for (i = 0; i < NUM_SIGNAL_ACTIONS; i++) { - sq_addlast((FAR sq_entry_t*)sigact++, &g_sigfreeaction); + sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction); } } diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index 947813b4a9..7615096e41 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -89,7 +89,7 @@ int sigpending(FAR sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; int ret = ERROR; if (set) @@ -121,7 +121,7 @@ sigset_t sig_pendingset(FAR struct tcb_s *stcb) sigpendset = NULL_SIGNAL_SET; saved_state = irqsave(); - for (sigpend = (FAR sigpendq_t*)group->sigpendingq.head; + for (sigpend = (FAR sigpendq_t *)group->sigpendingq.head; (sigpend); sigpend = sigpend->flink) { sigaddset(&sigpendset, sigpend->info.si_signo); diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index d5213a7e97..2e18c3cd9e 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -113,7 +113,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; sigset_t oldsigprocmask; irqstate_t saved_state; int ret = OK; diff --git a/sched/signal/sig_releasependingsigaction.c b/sched/signal/sig_releasependingsigaction.c index 688af823dd..3d47b7f2d0 100644 --- a/sched/signal/sig_releasependingsigaction.c +++ b/sched/signal/sig_releasependingsigaction.c @@ -89,9 +89,9 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) * list from interrupt handlers. */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigq, &g_sigpendingaction); + sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingaction); irqrestore(saved_state); - } + } /* If this is a message pre-allocated for interrupts, * then put it back in the correct free list. @@ -103,7 +103,7 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) * list from interrupt handlers. */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigq, &g_sigpendingirqaction); + sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction); irqrestore(saved_state); } diff --git a/sched/signal/sig_releasependingsignal.c b/sched/signal/sig_releasependingsignal.c index a6090850c0..97ed25c02a 100644 --- a/sched/signal/sig_releasependingsignal.c +++ b/sched/signal/sig_releasependingsignal.c @@ -99,7 +99,7 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingsignal); + sq_addlast((FAR sq_entry_t *)sigpend, &g_sigpendingsignal); irqrestore(saved_state); } @@ -114,7 +114,7 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) */ saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingirqsignal); + sq_addlast((FAR sq_entry_t *)sigpend, &g_sigpendingirqsignal); irqrestore(saved_state); } diff --git a/sched/signal/sig_removependingsignal.c b/sched/signal/sig_removependingsignal.c index e8fdac9112..7f2a53ee9c 100644 --- a/sched/signal/sig_removependingsignal.c +++ b/sched/signal/sig_removependingsignal.c @@ -95,7 +95,7 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) saved_state = irqsave(); - for (prevsig = NULL, currsig = (FAR sigpendq_t*)group->sigpendingq.head; + for (prevsig = NULL, currsig = (FAR sigpendq_t *)group->sigpendingq.head; (currsig && currsig->info.si_signo != signo); prevsig = currsig, currsig = currsig->flink); @@ -103,7 +103,7 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) { if (prevsig) { - sq_remafter((FAR sq_entry_t*)prevsig, &group->sigpendingq); + sq_remafter((FAR sq_entry_t *)prevsig, &group->sigpendingq); } else { diff --git a/sched/signal/sig_suspend.c b/sched/signal/sig_suspend.c index 11b41fbf04..6e9e964b70 100644 --- a/sched/signal/sig_suspend.c +++ b/sched/signal/sig_suspend.c @@ -110,7 +110,7 @@ int sigsuspend(FAR const sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; sigset_t intersection; sigset_t saved_sigprocmask; FAR sigpendq_t *sigpend; diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 67b0032a7b..7443fd17fc 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -93,7 +93,7 @@ static void sig_timeout(int argc, wdparm_t itcb) { /* On many small machines, pointers are encoded and cannot be simply cast - * from uint32_t to struct tcb_s*. The following union works around this + * from uint32_t to struct tcb_s *. The following union works around this * (see wdogparm_t). This odd logic could be conditioned on * CONFIG_CAN_CAST_POINTERS, but it is not too bad in any case. */ @@ -175,7 +175,7 @@ static void sig_timeout(int argc, wdparm_t itcb) int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, FAR const struct timespec *timeout) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; sigset_t intersection; FAR sigpendq_t *sigpend; irqstate_t saved_state; @@ -351,8 +351,8 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, } irqrestore(saved_state); - } + } - sched_unlock(); - return ret; + sched_unlock(); + return ret; } diff --git a/sched/signal/sig_unmaskpendingsignal.c b/sched/signal/sig_unmaskpendingsignal.c index a6df2fa19a..5b22af6765 100644 --- a/sched/signal/sig_unmaskpendingsignal.c +++ b/sched/signal/sig_unmaskpendingsignal.c @@ -80,29 +80,29 @@ void sig_unmaskpendingsignal(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; - sigset_t unmaskedset; - FAR sigpendq_t *pendingsig; - int signo; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + sigset_t unmaskedset; + FAR sigpendq_t *pendingsig; + int signo; - /* Prohibit any context switches until we are done with this. - * We may still be performing signal operations from interrupt - * handlers, however, none of the pending signals that we - * are concerned with here should be effected. - */ + /* Prohibit any context switches until we are done with this. + * We may still be performing signal operations from interrupt + * handlers, however, none of the pending signals that we + * are concerned with here should be effected. + */ - sched_lock(); + sched_lock(); - /* Get the set of pending signals that were just unmasked. The - * following operation should be safe because the sigprocmask - * can only be changed on this thread of execution. - */ + /* Get the set of pending signals that were just unmasked. The + * following operation should be safe because the sigprocmask + * can only be changed on this thread of execution. + */ - unmaskedset = ~(rtcb->sigprocmask) & sig_pendingset(rtcb); + unmaskedset = ~(rtcb->sigprocmask) & sig_pendingset(rtcb); - /* Loop while there are unmasked pending signals to be processed. */ + /* Loop while there are unmasked pending signals to be processed. */ - while (unmaskedset != NULL_SIGNAL_SET) + while (unmaskedset != NULL_SIGNAL_SET) { /* Pending signals will be processed from lowest numbered signal * to highest diff --git a/sched/task/exit.c b/sched/task/exit.c index c968315803..f9011cb83c 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -93,7 +93,7 @@ void exit(int status) { - struct tcb_s *tcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; /* Only the lower 8-bits of status are used */ diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c index 8e13709b9a..07eab08644 100644 --- a/sched/task/task_atexit.c +++ b/sched/task/task_atexit.c @@ -121,7 +121,7 @@ int atexit(void (*func)(void)) return on_exit((onexitfunc_t)func, NULL); #elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = tcb->group; int index; int ret = ERROR; @@ -155,7 +155,7 @@ int atexit(void (*func)(void)) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = tcb->group; int ret = ERROR; diff --git a/sched/task/task_create.c b/sched/task/task_create.c index 0ab710b90b..e853b7d521 100644 --- a/sched/task/task_create.c +++ b/sched/task/task_create.c @@ -188,7 +188,7 @@ static int thread_create(FAR const char *name, uint8_t ttype, int priority, /* The TCB was added to the active task list by task_schedsetup() */ - dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); + dq_rem((FAR dq_entry_t *)tcb, (FAR dq_queue_t *)&g_inactivetasks); goto errout_with_tcb; } diff --git a/sched/task/task_delete.c b/sched/task/task_delete.c index 7b0f06a06d..fea823d5e8 100644 --- a/sched/task/task_delete.c +++ b/sched/task/task_delete.c @@ -117,7 +117,7 @@ int task_delete(pid_t pid) /* Check if the task to delete is the calling task */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; if (pid == 0 || pid == rtcb->pid) { /* If it is, then what we really wanted to do was exit. Note that we diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index 39c52c9b75..ce9c2ad38e 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -106,7 +106,7 @@ int task_exit(void) { - FAR struct tcb_s *dtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *dtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct tcb_s *rtcb; int ret; @@ -119,7 +119,7 @@ int task_exit(void) */ (void)sched_removereadytorun(dtcb); - rtcb = (FAR struct tcb_s*)g_readytorun.head; + rtcb = (FAR struct tcb_s *)g_readytorun.head; /* We are now in a bad state -- the head of the ready to run task list * does not correspond to the thread that is running. Disabling pre- diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index f6b5ffa550..bc72151be1 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -529,8 +529,8 @@ static inline void task_exitwakeup(FAR struct tcb_s *tcb, int status) { /* Yes.. Wakeup any tasks waiting for this task to exit */ - group->tg_statloc = NULL; - while (group->tg_exitsem.semcount < 0) + group->tg_statloc = NULL; + while (group->tg_exitsem.semcount < 0) { /* Wake up the thread */ diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c index 424d4428c1..a1172abd06 100644 --- a/sched/task/task_onexit.c +++ b/sched/task/task_onexit.c @@ -116,7 +116,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) { #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = tcb->group; int index; int ret = ENOSPC; @@ -151,7 +151,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct task_group_s *group = tcb->group; int ret = ENOSPC; diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index 65ee785ab3..17172086fc 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -438,22 +438,22 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, goto errout_with_lock; } - /* Wait for the proxy to complete its job */ + /* Wait for the proxy to complete its job */ #ifdef CONFIG_SCHED_WAITPID - ret = waitpid(proxy, &status, 0); - if (ret < 0) - { - sdbg("ERROR: waitpid() failed: %d\n", errno); - goto errout_with_lock; - } + ret = waitpid(proxy, &status, 0); + if (ret < 0) + { + sdbg("ERROR: waitpid() failed: %d\n", errno); + goto errout_with_lock; + } #else - spawn_semtake(&g_spawn_execsem); + spawn_semtake(&g_spawn_execsem); #endif - /* Get the result and relinquish our access to the parameter structure */ + /* Get the result and relinquish our access to the parameter structure */ - ret = g_spawn_parms.result; + ret = g_spawn_parms.result; errout_with_lock: #ifdef CONFIG_SCHED_WAITPID diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index eaf25ab73d..e6229adf4f 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -160,8 +160,8 @@ int task_restart(pid_t pid) */ state = irqsave(); - dq_rem((FAR dq_entry_t*)tcb, - (dq_queue_t*)g_tasklisttable[tcb->cmn.task_state].list); + dq_rem((FAR dq_entry_t *)tcb, + (FAR dq_queue_t *)g_tasklisttable[tcb->cmn.task_state].list); tcb->cmn.task_state = TSTATE_TASK_INVALID; irqrestore(state); @@ -190,7 +190,7 @@ int task_restart(pid_t pid) /* Add the task to the inactive task list */ - dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); + dq_addfirst((FAR dq_entry_t *)tcb, (FAR dq_queue_t *)&g_inactivetasks); tcb->cmn.task_state = TSTATE_TASK_INACTIVE; /* Activate the task */ diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 5b36fe5d61..feb45b83fd 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -82,7 +82,7 @@ static const char g_noname[] = ""; * Private Function Prototypes ****************************************************************************/ -static int task_assignpid(FAR struct tcb_s* tcb); +static int task_assignpid(FAR struct tcb_s * tcb); /**************************************************************************** * Private Functions @@ -183,7 +183,7 @@ static int task_assignpid(FAR struct tcb_s *tcb) #ifdef CONFIG_SCHED_HAVE_PARENT static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_SCHED_CHILD_STATUS) DEBUGASSERT(tcb && tcb->group && rtcb->group); @@ -288,7 +288,7 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) #ifdef CONFIG_PIC static inline void task_dupdspace(FAR struct tcb_s *tcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; if (rtcb->dspace != NULL) { /* Copy the D-Space structure reference and increment the reference @@ -390,7 +390,7 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority, /* Add the task to the inactive task list */ sched_lock(); - dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); + dq_addfirst((FAR dq_entry_t *)tcb, (FAR dq_queue_t *)&g_inactivetasks); tcb->task_state = TSTATE_TASK_INACTIVE; sched_unlock(); } @@ -499,7 +499,7 @@ static inline int task_stackargsetup(FAR struct task_tcb_s *tcb, strtablen += (strlen(argv[argc]) + 1); if (strtablen >= tcb->cmn.adj_stack_size) { - return -ENAMETOOLONG; + return -ENAMETOOLONG; } /* Increment the number of args. Here is a sanity check to @@ -520,7 +520,7 @@ static inline int task_stackargsetup(FAR struct task_tcb_s *tcb, * task name plus a NULL argv[] entry to terminate the list. */ - argvlen = (argc + 2)*sizeof(FAR char*); + argvlen = (argc + 2) * sizeof(FAR char *); stackargv = (FAR char **)up_stack_frame(&tcb->cmn, argvlen + strtablen); DEBUGASSERT(stackargv != NULL); diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c index 02083a19ac..ef686e03ad 100644 --- a/sched/task/task_spawn.c +++ b/sched/task/task_spawn.c @@ -421,7 +421,7 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry, proxy = task_create("task_spawn_proxy", param.sched_priority, CONFIG_POSIX_SPAWN_PROXY_STACKSIZE, (main_t)task_spawn_proxy, - (FAR char * const*)NULL); + (FAR char * const *)NULL); if (proxy < 0) { ret = get_errno(); @@ -430,22 +430,22 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry, goto errout_with_lock; } - /* Wait for the proxy to complete its job */ + /* Wait for the proxy to complete its job */ #ifdef CONFIG_SCHED_WAITPID - ret = waitpid(proxy, &status, 0); - if (ret < 0) - { - sdbg("ERROR: waitpid() failed: %d\n", errno); - goto errout_with_lock; - } + ret = waitpid(proxy, &status, 0); + if (ret < 0) + { + sdbg("ERROR: waitpid() failed: %d\n", errno); + goto errout_with_lock; + } #else - spawn_semtake(&g_spawn_execsem); + spawn_semtake(&g_spawn_execsem); #endif - /* Get the result and relinquish our access to the parameter structure */ + /* Get the result and relinquish our access to the parameter structure */ - ret = g_spawn_parms.result; + ret = g_spawn_parms.result; errout_with_lock: #ifdef CONFIG_SCHED_WAITPID diff --git a/sched/task/task_start.c b/sched/task/task_start.c index 48ab75a3ad..6beeccff97 100644 --- a/sched/task/task_start.c +++ b/sched/task/task_start.c @@ -100,7 +100,7 @@ void task_start(void) { - FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s*)g_readytorun.head; + FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)g_readytorun.head; int exitcode; int argc; diff --git a/sched/task/task_terminate.c b/sched/task/task_terminate.c index b3f5678b90..684c09da8d 100644 --- a/sched/task/task_terminate.c +++ b/sched/task/task_terminate.c @@ -168,7 +168,8 @@ int task_terminate(pid_t pid, bool nonblocking) /* Remove the task from the OS's tasks lists. */ saved_state = irqsave(); - dq_rem((FAR dq_entry_t*)dtcb, (dq_queue_t*)g_tasklisttable[dtcb->task_state].list); + dq_rem((FAR dq_entry_t *)dtcb, + (FAR dq_queue_t *)g_tasklisttable[dtcb->task_state].list); dtcb->task_state = TSTATE_TASK_INVALID; irqrestore(saved_state); diff --git a/sched/task/task_vfork.c b/sched/task/task_vfork.c index 20e74179b1..65cdf481cf 100644 --- a/sched/task/task_vfork.c +++ b/sched/task/task_vfork.c @@ -458,7 +458,7 @@ void task_vforkabort(FAR struct task_tcb_s *child, int errcode) { /* The TCB was added to the active task list by task_schedsetup() */ - dq_rem((FAR dq_entry_t*)child, (dq_queue_t*)&g_inactivetasks); + dq_rem((FAR dq_entry_t *)child, (FAR dq_queue_t *)&g_inactivetasks); /* Release the TCB */ diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index fc8f9acd4a..a750a879b4 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -78,15 +78,15 @@ static struct posix_timer_s *timer_allocate(void) { - struct posix_timer_s *ret; - irqstate_t flags; - uint8_t pt_flags; + FAR struct posix_timer_s *ret; + irqstate_t flags; + uint8_t pt_flags; /* Try to get a preallocated timer from the free list */ #if CONFIG_PREALLOC_TIMERS > 0 flags = irqsave(); - ret = (struct posix_timer_s*)sq_remfirst((sq_queue_t*)&g_freetimers); + ret = (FAR struct posix_timer_s *)sq_remfirst((FAR sq_queue_t *)&g_freetimers); irqrestore(flags); /* Did we get one? */ @@ -100,7 +100,7 @@ static struct posix_timer_s *timer_allocate(void) { /* Allocate a new timer from the heap */ - ret = (struct posix_timer_s*)kmm_malloc(sizeof(struct posix_timer_s)); + ret = (FAR struct posix_timer_s *)kmm_malloc(sizeof(struct posix_timer_s)); pt_flags = 0; } @@ -116,7 +116,7 @@ static struct posix_timer_s *timer_allocate(void) /* And add it to the end of the list of allocated timers */ flags = irqsave(); - sq_addlast((sq_entry_t*)ret, (sq_queue_t*)&g_alloctimers); + sq_addlast((FAR sq_entry_t *)ret, (FAR sq_queue_t *)&g_alloctimers); irqrestore(flags); } diff --git a/sched/timer/timer_initialize.c b/sched/timer/timer_initialize.c index e28445d5e7..ab0c16d70c 100644 --- a/sched/timer/timer_initialize.c +++ b/sched/timer/timer_initialize.c @@ -113,18 +113,19 @@ void weak_function timer_initialize(void) /* Place all of the pre-allocated timers into the free timer list */ - sq_init((sq_queue_t*)&g_freetimers); + sq_init((FAR sq_queue_t *)&g_freetimers); for (i = 0; i < CONFIG_PREALLOC_TIMERS; i++) { g_prealloctimers[i].pt_flags = PT_FLAGS_PREALLOCATED; - sq_addlast((FAR sq_entry_t*)&g_prealloctimers[i], (FAR sq_queue_t*)&g_freetimers); + sq_addlast((FAR sq_entry_t *)&g_prealloctimers[i], + (FAR sq_queue_t *)&g_freetimers); } #endif /* Initialize the list of allocated timers */ - sq_init((sq_queue_t*)&g_alloctimers); + sq_init((FAR sq_queue_t *)&g_alloctimers); } /******************************************************************************** @@ -155,7 +156,7 @@ void weak_function timer_deleteall(pid_t pid) irqstate_t flags; flags = irqsave(); - for (timer = (FAR struct posix_timer_s*)g_alloctimers.head; timer; timer = next) + for (timer = (FAR struct posix_timer_s *)g_alloctimers.head; timer; timer = next) { next = timer->flink; if (timer->pt_owner == pid) diff --git a/sched/timer/timer_release.c b/sched/timer/timer_release.c index 2eb2a004bd..85e5b857c3 100644 --- a/sched/timer/timer_release.c +++ b/sched/timer/timer_release.c @@ -81,14 +81,14 @@ static inline void timer_free(struct posix_timer_s *timer) /* Remove the timer from the allocated list */ flags = irqsave(); - sq_rem((FAR sq_entry_t*)timer, (sq_queue_t*)&g_alloctimers); + sq_rem((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_alloctimers); /* Return it to the free list if it is one of the preallocated timers */ #if CONFIG_PREALLOC_TIMERS > 0 if ((timer->pt_flags & PT_FLAGS_PREALLOCATED) != 0) { - sq_addlast((FAR sq_entry_t*)timer, (FAR sq_queue_t*)&g_freetimers); + sq_addlast((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_freetimers); irqrestore(flags); } else diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 1145ff7783..01be3a28ae 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -170,7 +170,7 @@ static void timer_timeout(int argc, wdparm_t itimer) { #ifndef CONFIG_CAN_PASS_STRUCTS /* On many small machines, pointers are encoded and cannot be simply cast from - * wdparm_t to struct tcb_s*. The following union works around this (see wdogparm_t). + * wdparm_t to struct tcb_s *. The following union works around this (see wdogparm_t). */ union diff --git a/sched/wdog/wd_cancel.c b/sched/wdog/wd_cancel.c index 3a20cd611d..225e62a223 100644 --- a/sched/wdog/wd_cancel.c +++ b/sched/wdog/wd_cancel.c @@ -143,7 +143,7 @@ int wd_cancel(WDOG_ID wdog) { /* Remove the watchdog from mid- or end-of-queue */ - (void)sq_remafter((FAR sq_entry_t*)prev, &g_wdactivelist); + (void)sq_remafter((FAR sq_entry_t *)prev, &g_wdactivelist); } else { diff --git a/sched/wdog/wd_delete.c b/sched/wdog/wd_delete.c index 789f0b007f..14156418ad 100644 --- a/sched/wdog/wd_delete.c +++ b/sched/wdog/wd_delete.c @@ -142,7 +142,7 @@ int wd_delete(WDOG_ID wdog) * timers, all with interrupts disabled. */ - sq_addlast((FAR sq_entry_t*)wdog, &g_wdfreelist); + sq_addlast((FAR sq_entry_t *)wdog, &g_wdfreelist); g_wdnfree++; DEBUGASSERT(g_wdnfree <= CONFIG_PREALLOC_WDOGS); irqrestore(state); diff --git a/sched/wdog/wd_initialize.c b/sched/wdog/wd_initialize.c index b745c19b66..84894903cb 100644 --- a/sched/wdog/wd_initialize.c +++ b/sched/wdog/wd_initialize.c @@ -80,7 +80,7 @@ uint16_t g_wdnfree; ****************************************************************************/ /* g_wdpool is a list of pre-allocated watchdogs. The number of watchdogs -* in the pool is a configuration item. + * in the pool is a configuration item. */ static struct wdog_s g_wdpool[CONFIG_PREALLOC_WDOGS]; @@ -128,7 +128,7 @@ void wd_initialize(void) for (i = 0; i < CONFIG_PREALLOC_WDOGS; i++) { - sq_addlast((FAR sq_entry_t*)wdog++, &g_wdfreelist); + sq_addlast((FAR sq_entry_t *)wdog++, &g_wdfreelist); } /* All watchdogs are free */ diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index 90ce73c151..de3b05603e 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -180,7 +180,7 @@ static inline void wd_expiration(void) case 4: (*((wdentry4_t)(wdog->func)))(4, wdog->parm[0], wdog->parm[1], - wdog->parm[2] ,wdog->parm[3]); + wdog->parm[2], wdog->parm[3]); break; #endif } @@ -301,7 +301,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) { /* Add the watchdog to the head == tail of the queue. */ - sq_addlast((FAR sq_entry_t*)wdog, &g_wdactivelist); + sq_addlast((FAR sq_entry_t *)wdog, &g_wdactivelist); } /* There are other active watchdogs in the timer queue */ @@ -322,11 +322,11 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) /* Advance past shorter delays */ while (now <= delay && curr->next) - { - prev = curr; - curr = curr->next; - now += curr->lag; - } + { + prev = curr; + curr = curr->next; + now += curr->lag; + } /* Check if the new wdog must be inserted before the curr. */ @@ -368,13 +368,13 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) delay -= now; if (!curr->next) { - sq_addlast((FAR sq_entry_t*)wdog, &g_wdactivelist); + sq_addlast((FAR sq_entry_t *)wdog, &g_wdactivelist); } else { next = curr->next; next->lag -= delay; - sq_addafter((FAR sq_entry_t*)curr, (FAR sq_entry_t*)wdog, + sq_addafter((FAR sq_entry_t *)curr, (FAR sq_entry_t *)wdog, &g_wdactivelist); } } diff --git a/sched/wqueue/kwork_hpthread.c b/sched/wqueue/kwork_hpthread.c index 81ac4c24ff..5a6b387999 100644 --- a/sched/wqueue/kwork_hpthread.c +++ b/sched/wqueue/kwork_hpthread.c @@ -106,7 +106,7 @@ static int work_hpthread(int argc, char *argv[]) { /* Loop forever */ - for (;;) + for (; ; ) { #ifndef CONFIG_SCHED_LPWORK /* First, perform garbage collection. This cleans-up memory diff --git a/sched/wqueue/kwork_lpthread.c b/sched/wqueue/kwork_lpthread.c index c355596c09..eacbb6a265 100644 --- a/sched/wqueue/kwork_lpthread.c +++ b/sched/wqueue/kwork_lpthread.c @@ -127,7 +127,7 @@ static int work_lpthread(int argc, char *argv[]) /* Loop forever */ - for (;;) + for (; ; ) { #if CONFIG_SCHED_LPNTHREADS > 0 /* Thread 0 is special. Only thread 0 performs period garbage collection */ @@ -147,14 +147,14 @@ static int work_lpthread(int argc, char *argv[]) #endif { /* Perform garbage collection. This cleans-up memory de-allocations - * that were queued because they could not be freed in that execution - * context (for example, if the memory was freed from an interrupt handler). - * NOTE: If the work thread is disabled, this clean-up is performed by - * the IDLE thread (at a very, very low priority). - * - * In the event of multiple low priority threads, on index == 0 will do - * the garbage collection. - */ + * that were queued because they could not be freed in that execution + * context (for example, if the memory was freed from an interrupt handler). + * NOTE: If the work thread is disabled, this clean-up is performed by + * the IDLE thread (at a very, very low priority). + * + * In the event of multiple low priority threads, on index == 0 will do + * the garbage collection. + */ sched_garbagecollection(); diff --git a/sched/wqueue/kwork_process.c b/sched/wqueue/kwork_process.c index 6333a6c219..ff854fe83a 100644 --- a/sched/wqueue/kwork_process.c +++ b/sched/wqueue/kwork_process.c @@ -239,20 +239,20 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx) * period will be non-zero and equal to wqueue->delay. */ - if (period == 0) - { - sigset_t set; + if (period == 0) + { + sigset_t set; - /* Wait indefinitely until signalled with SIGWORK */ + /* Wait indefinitely until signalled with SIGWORK */ - sigemptyset(&set); - sigaddset(&set, SIGWORK); + sigemptyset(&set); + sigaddset(&set, SIGWORK); - wqueue->worker[wndx].busy = false; - DEBUGVERIFY(sigwaitinfo(&set, NULL)); + wqueue->worker[wndx].busy = false; + DEBUGVERIFY(sigwaitinfo(&set, NULL)); wqueue->worker[wndx].busy = true; - } - else + } + else #endif { /* Get the delay (in clock ticks) since we started the sampling */ -- GitLab From 78ae661223b6524af22dcf1edbaf1ee49114c463 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 7 Oct 2015 20:13:49 -0600 Subject: [PATCH 195/858] One more trivial spacing issue --- sched/pthread/pthread_getschedparam.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index eaf9931a68..24b18c1535 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -89,7 +89,7 @@ * (SCHED_OTHER and SCHED_SPORADIC, in particular, are not supported). * The SCHED_FIFO and SCHED_RR policies will have a single scheduling * parameter, sched_priority. -* + * * Parameters: * thread - The ID of thread whose scheduling parameters will be queried. * policy - The location to store the thread's scheduling policy. -- GitLab From 06cd5b2fcc03c2fd84c1d17a76c49f8452eb1e73 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 09:10:22 -0600 Subject: [PATCH 196/858] mm, audio, crypto, graphics: Fix various spacing/alignment issues --- arch | 2 +- audio/audio.c | 12 ++++---- audio/pcm_decode.c | 34 +++++++++++----------- crypto/cryptodev.c | 8 ++--- crypto/testmngr.c | 2 +- graphics/nxbe/nxbe_colormap.c | 14 +++++---- graphics/nxglib/fb/nxglib_copyrectangle.c | 6 ++-- graphics/nxglib/fb/nxglib_fillrectangle.c | 2 +- graphics/nxglib/fb/nxglib_filltrapezoid.c | 2 +- graphics/nxglib/fb/nxglib_getrectangle.c | 2 +- graphics/nxglib/fb/nxglib_setpixel.c | 2 +- graphics/nxglib/lcd/nxglib_copyrectangle.c | 6 ++-- graphics/nxglib/lcd/nxglib_fillrectangle.c | 4 +-- graphics/nxglib/lcd/nxglib_filltrapezoid.c | 4 +-- graphics/nxglib/lcd/nxglib_getrectangle.c | 2 +- graphics/nxglib/lcd/nxglib_moverectangle.c | 2 +- graphics/nxglib/lcd/nxglib_setpixel.c | 2 +- graphics/nxmu/nxmu_server.c | 6 ++-- graphics/nxterm/nxterm_font.c | 2 +- graphics/nxterm/nxterm_register.c | 2 +- graphics/nxterm/nxterm_scroll.c | 2 +- mm/mm_gran/mm_graninit.c | 2 +- mm/mm_gran/mm_granmark.c | 2 +- mm/mm_gran/mm_pgalloc.c | 4 +-- mm/mm_heap/mm_free.c | 8 ++--- mm/mm_heap/mm_mallinfo.c | 4 +-- mm/mm_heap/mm_malloc.c | 8 ++--- mm/mm_heap/mm_memalign.c | 10 +++---- mm/mm_heap/mm_realloc.c | 16 +++++----- mm/mm_heap/mm_sbrk.c | 2 +- mm/mm_heap/mm_shrinkchunk.c | 8 ++--- 31 files changed, 92 insertions(+), 90 deletions(-) diff --git a/arch b/arch index ecb6712035..8faab42f9a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ecb67120352a5acc46c6ea06fe882ddfb597824f +Subproject commit 8faab42f9a4c9170b35bfb68ef40b2e54ba83320 diff --git a/audio/audio.c b/audio/audio.c index f09fe631f0..a1f0db3834 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -379,7 +379,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case AUDIOIOC_GETCAPS: { - FAR struct audio_caps_s *caps = (FAR struct audio_caps_s*)((uintptr_t)arg); + FAR struct audio_caps_s *caps = (FAR struct audio_caps_s *)((uintptr_t)arg); DEBUGASSERT(lower->ops->getcaps != NULL); audvdbg("AUDIOIOC_GETCAPS: Device=%d\n", caps->ac_type); @@ -393,7 +393,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case AUDIOIOC_CONFIGURE: { FAR const struct audio_caps_desc_s *caps = - (FAR const struct audio_caps_desc_s*)((uintptr_t)arg); + (FAR const struct audio_caps_desc_s *)((uintptr_t)arg); DEBUGASSERT(lower->ops->configure != NULL); audvdbg("AUDIOIOC_INITIALIZE: Device=%d\n", caps->caps.ac_type); @@ -873,11 +873,11 @@ int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev) char path[AUDIO_MAX_DEVICE_PATH]; static bool dev_audio_created = false; #ifndef CONFIG_AUDIO_CUSTOM_DEV_PATH - const char* devname = "/dev/audio"; + FAR const char *devname = "/dev/audio"; #elif !defined(CONFIG_AUDIO_DEV_ROOT) - const char* devname = CONFIG_AUDIO_DEV_PATH; - const char* ptr; - char* pathptr; + FAR const char *devname = CONFIG_AUDIO_DEV_PATH; + FAR const char *ptr; + FAR char *pathptr; #endif /* Allocate the upper-half data structure */ diff --git a/audio/pcm_decode.c b/audio/pcm_decode.c index b8808a2cb7..d57d5dbb9b 100644 --- a/audio/pcm_decode.c +++ b/audio/pcm_decode.c @@ -259,23 +259,23 @@ static void pcm_callback(FAR void *arg, uint16_t reason, #ifdef CONFIG_PCM_DEBUG static void pcm_dump(FAR const struct wav_header_s *wav) { - dbg( "Wave file header\n"); - dbg( " Header Chunk:\n"); - dbg( " Chunk ID: 0x%08x\n", wav->hdr.chunkid); - dbg( " Chunk Size: %u\n", wav->hdr.chunklen); - dbg( " Format: 0x%08x\n", wav->hdr.format); - dbg( " Format Chunk:\n"); - dbg( " Chunk ID: 0x%08x\n", wav->fmt.chunkid); - dbg( " Chunk Size: %u\n", wav->fmt.chunklen); - dbg( " Audio Format: 0x%04x\n", wav->fmt.format); - dbg( " Num. Channels: %d\n", wav->fmt.nchannels); - dbg( " Sample Rate: %u\n", wav->fmt.samprate); - dbg( " Byte Rate: %u\n", wav->fmt.byterate); - dbg( " Block Align: %d\n", wav->fmt.align); - dbg( " Bits Per Sample: %d\n", wav->fmt.bpsamp); - dbg( " Data Chunk:\n"); - dbg( " Chunk ID: 0x%08x\n", wav->data.chunkid); - dbg( " Chunk Size: %u\n", wav->data.chunklen); + dbg("Wave file header\n"); + dbg(" Header Chunk:\n"); + dbg(" Chunk ID: 0x%08x\n", wav->hdr.chunkid); + dbg(" Chunk Size: %u\n", wav->hdr.chunklen); + dbg(" Format: 0x%08x\n", wav->hdr.format); + dbg(" Format Chunk:\n"); + dbg(" Chunk ID: 0x%08x\n", wav->fmt.chunkid); + dbg(" Chunk Size: %u\n", wav->fmt.chunklen); + dbg(" Audio Format: 0x%04x\n", wav->fmt.format); + dbg(" Num. Channels: %d\n", wav->fmt.nchannels); + dbg(" Sample Rate: %u\n", wav->fmt.samprate); + dbg(" Byte Rate: %u\n", wav->fmt.byterate); + dbg(" Block Align: %d\n", wav->fmt.align); + dbg(" Bits Per Sample: %d\n", wav->fmt.bpsamp); + dbg(" Data Chunk:\n"); + dbg(" Chunk ID: 0x%08x\n", wav->data.chunkid); + dbg(" Chunk Size: %u\n", wav->data.chunklen); } #endif diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index f6753effb5..c81585c329 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -96,11 +96,11 @@ static ssize_t cryptodev_write(FAR struct file *filep, FAR const char *buffer, static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { - switch(cmd) + switch (cmd) { case CIOCGSESSION: { - struct session_op *ses = (struct session_op*)arg; + FAR struct session_op *ses = (FAR struct session_op *)arg; ses->ses = (uint32_t)ses; return OK; } @@ -112,8 +112,8 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case CIOCCRYPT: { - FAR struct crypt_op *op = (struct crypt_op*)arg; - FAR struct session_op *ses = (struct session_op*)op->ses; + FAR struct crypt_op *op = (FAR struct crypt_op *)arg; + FAR struct session_op *ses = (FAR struct session_op *)op->ses; int encrypt; switch (op->op) diff --git a/crypto/testmngr.c b/crypto/testmngr.c index 2dacdd0c42..c7fe86e78a 100644 --- a/crypto/testmngr.c +++ b/crypto/testmngr.c @@ -68,7 +68,7 @@ * Private Functions ****************************************************************************/ -static int do_test_aes(FAR struct cipher_testvec* test, int mode, int encrypt) +static int do_test_aes(FAR struct cipher_testvec *test, int mode, int encrypt) { FAR void *out = kmm_zalloc(test->rlen); diff --git a/graphics/nxbe/nxbe_colormap.c b/graphics/nxbe/nxbe_colormap.c index d5d84e238c..1443206068 100644 --- a/graphics/nxbe/nxbe_colormap.c +++ b/graphics/nxbe/nxbe_colormap.c @@ -85,16 +85,18 @@ int nxbe_colormap(FAR NX_DRIVERTYPE *dev) { struct fb_cmap_s cmap; - uint8_t *alloc; - uint8_t *red; - uint8_t *green; - uint8_t *blue; + FAR uint8_t *alloc; + FAR uint8_t *red; + FAR uint8_t *green; + FAR uint8_t *blue; uint8_t rval; uint8_t gval; int size; int ndx; int ret; - int i, j, k; + int i; + int j; + int k; /* Allocate the color map tables in one allocation: * @@ -102,7 +104,7 @@ int nxbe_colormap(FAR NX_DRIVERTYPE *dev) */ size = 3 * CONFIG_NX_NCOLORS * sizeof(uint8_t); - alloc = (uint8_t*)kmm_malloc(size); + alloc = (FAR uint8_t *)kmm_malloc(size); if (alloc == NULL) { return -ENOMEM; diff --git a/graphics/nxglib/fb/nxglib_copyrectangle.c b/graphics/nxglib/fb/nxglib_copyrectangle.c index 0a6c12d414..ea0d1ad2e7 100644 --- a/graphics/nxglib/fb/nxglib_copyrectangle.c +++ b/graphics/nxglib/fb/nxglib_copyrectangle.c @@ -79,7 +79,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_copyrectangle, NXGLIB_SUFFIX) (FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *dest, FAR const void *src, FAR const struct nxgl_point_s *origin, unsigned int srcstride) @@ -131,7 +131,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) /* Then copy the image */ - sline = (const uint8_t*)src + NXGL_SCALEX(dest->pt1.x - origin->x) + (dest->pt1.y - origin->y) * srcstride; + sline = (FAR const uint8_t *)src + NXGL_SCALEX(dest->pt1.x - origin->x) + (dest->pt1.y - origin->y) * srcstride; dline = pinfo->fbmem + dest->pt1.y * deststride + NXGL_SCALEX(dest->pt1.x); while (rows--) @@ -171,7 +171,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) #else /* Copy the whole line */ - NXGL_MEMCPY((NXGL_PIXEL_T*)dline, (NXGL_PIXEL_T*)sline, width); + NXGL_MEMCPY((NXGL_PIXEL_T *)dline, (NXGL_PIXEL_T *)sline, width); #endif dline += deststride; sline += srcstride; diff --git a/graphics/nxglib/fb/nxglib_fillrectangle.c b/graphics/nxglib/fb/nxglib_fillrectangle.c index 3125004c9d..baaad84697 100644 --- a/graphics/nxglib/fb/nxglib_fillrectangle.c +++ b/graphics/nxglib/fb/nxglib_fillrectangle.c @@ -82,7 +82,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_fillrectangle, NXGLIB_SUFFIX) (FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, NXGL_PIXEL_T color) diff --git a/graphics/nxglib/fb/nxglib_filltrapezoid.c b/graphics/nxglib/fb/nxglib_filltrapezoid.c index 789ae7cee1..dcf29faad4 100644 --- a/graphics/nxglib/fb/nxglib_filltrapezoid.c +++ b/graphics/nxglib/fb/nxglib_filltrapezoid.c @@ -70,7 +70,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)( +void NXGL_FUNCNAME(nxgl_filltrapezoid, NXGLIB_SUFFIX)( FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_trapezoid_s *trap, FAR const struct nxgl_rect_s *bounds, diff --git a/graphics/nxglib/fb/nxglib_getrectangle.c b/graphics/nxglib/fb/nxglib_getrectangle.c index c1a9e1ee2d..39386b4cbd 100644 --- a/graphics/nxglib/fb/nxglib_getrectangle.c +++ b/graphics/nxglib/fb/nxglib_getrectangle.c @@ -127,7 +127,7 @@ static inline void nxgl_lowresmemcpy(FAR uint8_t *dline, FAR const uint8_t *slin * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_getrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_getrectangle, NXGLIB_SUFFIX) (FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, FAR void *dest, unsigned int deststride) { diff --git a/graphics/nxglib/fb/nxglib_setpixel.c b/graphics/nxglib/fb/nxglib_setpixel.c index 29f83bbaa3..c1c764f716 100644 --- a/graphics/nxglib/fb/nxglib_setpixel.c +++ b/graphics/nxglib/fb/nxglib_setpixel.c @@ -84,7 +84,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_setpixel,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_setpixel, NXGLIB_SUFFIX) (FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_point_s *pos, NXGL_PIXEL_T color) diff --git a/graphics/nxglib/lcd/nxglib_copyrectangle.c b/graphics/nxglib/lcd/nxglib_copyrectangle.c index 1194ff8e1b..0c5e266c62 100644 --- a/graphics/nxglib/lcd/nxglib_copyrectangle.c +++ b/graphics/nxglib/lcd/nxglib_copyrectangle.c @@ -81,7 +81,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_copyrectangle, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *dest, FAR const void *src, FAR const struct nxgl_point_s *origin, unsigned int srcstride) @@ -103,7 +103,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) /* Set up to copy the image */ xoffset = dest->pt1.x - origin->x; - sline = (const uint8_t*)src + NXGL_SCALEX(xoffset) + (dest->pt1.y - origin->y) * srcstride; + sline = (FAR const uint8_t *)src + NXGL_SCALEX(xoffset) + (dest->pt1.y - origin->y) * srcstride; #if NXGLIB_BITSPERPIXEL < 8 remainder = NXGL_REMAINDERX(xoffset); #endif @@ -119,7 +119,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) if (remainder != 0) { - NXGL_FUNCNAME(nxgl_copyrun,NXGLIB_SUFFIX)(sline, pinfo->buffer, remainder, ncols); + NXGL_FUNCNAME(nxgl_copyrun, NXGLIB_SUFFIX)(sline, pinfo->buffer, remainder, ncols); (void)pinfo->putrun(row, dest->pt1.x, pinfo->buffer, ncols); } else diff --git a/graphics/nxglib/lcd/nxglib_fillrectangle.c b/graphics/nxglib/lcd/nxglib_fillrectangle.c index 6e0911713d..6bc9a04fcb 100644 --- a/graphics/nxglib/lcd/nxglib_fillrectangle.c +++ b/graphics/nxglib/lcd/nxglib_fillrectangle.c @@ -84,7 +84,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_fillrectangle, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, NXGL_PIXEL_T color) @@ -98,7 +98,7 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX) /* Fill the run buffer with the selected color */ - NXGL_FUNCNAME(nxgl_fillrun,NXGLIB_SUFFIX)((NXGLIB_RUNTYPE*)pinfo->buffer, color, ncols); + NXGL_FUNCNAME(nxgl_fillrun, NXGLIB_SUFFIX)((NXGLIB_RUNTYPE *)pinfo->buffer, color, ncols); /* Then fill the rectangle line-by-line */ diff --git a/graphics/nxglib/lcd/nxglib_filltrapezoid.c b/graphics/nxglib/lcd/nxglib_filltrapezoid.c index df81971fb9..c88cae9542 100644 --- a/graphics/nxglib/lcd/nxglib_filltrapezoid.c +++ b/graphics/nxglib/lcd/nxglib_filltrapezoid.c @@ -86,7 +86,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_filltrapezoid, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_trapezoid_s *trap, FAR const struct nxgl_rect_s *bounds, @@ -215,7 +215,7 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX) ncols = botw; } - NXGL_FUNCNAME(nxgl_fillrun,NXGLIB_SUFFIX)((NXGLIB_RUNTYPE*)pinfo->buffer, color, ncols); + NXGL_FUNCNAME(nxgl_fillrun, NXGLIB_SUFFIX)((NXGLIB_RUNTYPE *)pinfo->buffer, color, ncols); /* Then fill the trapezoid row-by-row */ diff --git a/graphics/nxglib/lcd/nxglib_getrectangle.c b/graphics/nxglib/lcd/nxglib_getrectangle.c index 05bf78d666..1d6ecb5e60 100644 --- a/graphics/nxglib/lcd/nxglib_getrectangle.c +++ b/graphics/nxglib/lcd/nxglib_getrectangle.c @@ -79,7 +79,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_getrectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_getrectangle, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, FAR void *dest, unsigned int deststride) { diff --git a/graphics/nxglib/lcd/nxglib_moverectangle.c b/graphics/nxglib/lcd/nxglib_moverectangle.c index d634f2141c..02a84df098 100644 --- a/graphics/nxglib/lcd/nxglib_moverectangle.c +++ b/graphics/nxglib/lcd/nxglib_moverectangle.c @@ -81,7 +81,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_moverectangle,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_moverectangle, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, FAR struct nxgl_point_s *offset) { diff --git a/graphics/nxglib/lcd/nxglib_setpixel.c b/graphics/nxglib/lcd/nxglib_setpixel.c index 46b637575b..2af2c77a14 100644 --- a/graphics/nxglib/lcd/nxglib_setpixel.c +++ b/graphics/nxglib/lcd/nxglib_setpixel.c @@ -85,7 +85,7 @@ * ****************************************************************************/ -void NXGL_FUNCNAME(nxgl_setpixel,NXGLIB_SUFFIX) +void NXGL_FUNCNAME(nxgl_setpixel, NXGLIB_SUFFIX) (FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_point_s *pos, NXGL_PIXEL_T color) diff --git a/graphics/nxmu/nxmu_server.c b/graphics/nxmu/nxmu_server.c index 1f13dba908..a5dad6ec40 100644 --- a/graphics/nxmu/nxmu_server.c +++ b/graphics/nxmu/nxmu_server.c @@ -214,7 +214,7 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, attr.mq_msgsize = NX_MXSVRMSGLEN; attr.mq_flags = 0; - fe->conn.crdmq = mq_open(mqname, O_RDONLY|O_CREAT, 0666, &attr); + fe->conn.crdmq = mq_open(mqname, O_RDONLY | O_CREAT, 0666, &attr); if (fe->conn.crdmq == (mqd_t)-1) { gdbg("mq_open(%s) failed: %d\n", mqname, errno); @@ -245,7 +245,7 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, /* Initialize the non-NULL elements of the background window */ fe->be.bkgd.conn = &fe->conn; - fe->be.bkgd.be = (FAR struct nxbe_state_s*)fe; + fe->be.bkgd.be = (FAR struct nxbe_state_s *)fe; fe->be.bkgd.bounds.pt2.x = fe->be.vinfo.xres - 1; fe->be.bkgd.bounds.pt2.y = fe->be.vinfo.yres - 1; @@ -325,7 +325,7 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev) /* Then loop forever processing incoming messages */ - for (;;) + for (; ; ) { /* Receive the next server message */ diff --git a/graphics/nxterm/nxterm_font.c b/graphics/nxterm/nxterm_font.c index 013deab581..fec6d5a443 100644 --- a/graphics/nxterm/nxterm_font.c +++ b/graphics/nxterm/nxterm_font.c @@ -311,7 +311,7 @@ nxterm_renderglyph(FAR struct nxterm_state_s *priv, /* Then render the glyph into the allocated memory */ - ret = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap, + ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap, glyph->height, glyph->width, glyph->stride, fbm, priv->wndo.fcolor[0]); if (ret < 0) diff --git a/graphics/nxterm/nxterm_register.c b/graphics/nxterm/nxterm_register.c index 6a49e641cf..a0751773d7 100644 --- a/graphics/nxterm/nxterm_register.c +++ b/graphics/nxterm/nxterm_register.c @@ -96,7 +96,7 @@ FAR struct nxterm_state_s * priv->ops = ops; priv->handle = handle; priv->minor = minor; - memcpy(&priv->wndo, wndo, sizeof( struct nxterm_window_s)); + memcpy(&priv->wndo, wndo, sizeof(struct nxterm_window_s)); sem_init(&priv->exclsem, 0, 1); #ifdef CONFIG_DEBUG diff --git a/graphics/nxterm/nxterm_scroll.c b/graphics/nxterm/nxterm_scroll.c index 9d1827606f..38e9f5cb6b 100644 --- a/graphics/nxterm/nxterm_scroll.c +++ b/graphics/nxterm/nxterm_scroll.c @@ -136,7 +136,7 @@ static inline void nxterm_movedisplay(FAR struct nxterm_state_s *priv, /* Finally, clear the vacated part of the display */ rect.pt1.y = bottom; - rect.pt2.y = priv->wndo.wsize.h- 1; + rect.pt2.y = priv->wndo.wsize.h - 1; ret = priv->ops->fill(priv, &rect, priv->wndo.wcolor); if (ret < 0) diff --git a/mm/mm_gran/mm_graninit.c b/mm/mm_gran/mm_graninit.c index 0d4bf18b7f..9da0de1fc8 100644 --- a/mm/mm_gran/mm_graninit.c +++ b/mm/mm_gran/mm_graninit.c @@ -127,7 +127,7 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, * correct size. */ - priv = ( FAR struct gran_s *)kmm_zalloc(SIZEOF_GRAN_S(ngranules)); + priv = (FAR struct gran_s *)kmm_zalloc(SIZEOF_GRAN_S(ngranules)); if (priv) { /* Initialize non-zero elements of the granules heap info structure */ diff --git a/mm/mm_gran/mm_granmark.c b/mm/mm_gran/mm_granmark.c index 91bfdb0971..d9dfcb9ec6 100644 --- a/mm/mm_gran/mm_granmark.c +++ b/mm/mm_gran/mm_granmark.c @@ -100,7 +100,7 @@ void gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, { /* Mark bits in the first GAT entry */ - gatmask =0xffffffff << gatbit; + gatmask = 0xffffffff << gatbit; DEBUGASSERT((priv->gat[gatidx] & gatmask) == 0); priv->gat[gatidx] |= gatmask; diff --git a/mm/mm_gran/mm_pgalloc.c b/mm/mm_gran/mm_pgalloc.c index c4bda32d32..474d9e0f4e 100644 --- a/mm/mm_gran/mm_pgalloc.c +++ b/mm/mm_gran/mm_pgalloc.c @@ -208,9 +208,9 @@ uintptr_t mm_pgalloc(unsigned int npages) void mm_pgfree(uintptr_t paddr, unsigned int npages) { #ifdef CONFIG_GRAN_SINGLE - gran_free((FAR void*)paddr, (size_t)npages << MM_PGSHIFT); + gran_free((FAR void *)paddr, (size_t)npages << MM_PGSHIFT); #else - gran_free(g_pgalloc, (FAR void*)paddr, (size_t)npages << MM_PGSHIFT); + gran_free(g_pgalloc, (FAR void *)paddr, (size_t)npages << MM_PGSHIFT); #endif } diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c index ae0f50d3c7..a08682676d 100644 --- a/mm/mm_heap/mm_free.c +++ b/mm/mm_heap/mm_free.c @@ -88,12 +88,12 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) /* Map the memory chunk into a free node */ - node = (FAR struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE); + node = (FAR struct mm_freenode_s *)((FAR char *)mem - SIZEOF_MM_ALLOCNODE); node->preceding &= ~MM_ALLOC_BIT; /* Check if the following node is free and, if so, merge it */ - next = (FAR struct mm_freenode_s *)((char*)node + node->size); + next = (FAR struct mm_freenode_s *)((FAR char *)node + node->size); if ((next->preceding & MM_ALLOC_BIT) == 0) { FAR struct mm_allocnode_s *andbeyond; @@ -103,7 +103,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) * index past the tail chunk because it is always allocated. */ - andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size); + andbeyond = (FAR struct mm_allocnode_s *)((FAR char *)next + next->size); /* Remove the next node. There must be a predecessor, * but there may not be a successor node. @@ -127,7 +127,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) * it with this node */ - prev = (FAR struct mm_freenode_s *)((char*)node - node->preceding); + prev = (FAR struct mm_freenode_s *)((FAR char *)node - node->preceding); if ((prev->preceding & MM_ALLOC_BIT) == 0) { /* Remove the node. There must be a predecessor, but there may diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c index 9b97760dd8..5aa720e7a9 100644 --- a/mm/mm_heap/mm_mallinfo.c +++ b/mm/mm_heap/mm_mallinfo.c @@ -71,7 +71,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info) { - struct mm_allocnode_s *node; + FAR struct mm_allocnode_s *node; size_t mxordblk = 0; int ordblks = 0; /* Number of non-inuse chunks */ size_t uordblks = 0; /* Total allocated space */ @@ -98,7 +98,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info) for (node = heap->mm_heapstart[region]; node < heap->mm_heapend[region]; - node = (struct mm_allocnode_s *)((char*)node + node->size)) + node = (FAR struct mm_allocnode_s *)((FAR char *)node + node->size)) { mvdbg("region=%d node=%p size=%p preceding=%p (%c)\n", region, node, node->size, (node->preceding & ~MM_ALLOC_BIT), diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index 9890e5712c..e1ed4b8c15 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -49,7 +49,7 @@ ****************************************************************************/ #ifndef NULL -# define NULL ((void*)0) +# define NULL ((void *)0) #endif /**************************************************************************** @@ -164,11 +164,11 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) { /* Get a pointer to the next node in physical memory */ - next = (FAR struct mm_freenode_s*)(((char*)node) + node->size); + next = (FAR struct mm_freenode_s *)(((FAR char *)node) + node->size); /* Create the remainder node */ - remainder = (FAR struct mm_freenode_s*)(((char*)node) + size); + remainder = (FAR struct mm_freenode_s *)(((FAR char *)node) + size); remainder->size = remaining; remainder->preceding = size; @@ -190,7 +190,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) /* Handle the case of an exact size match */ node->preceding |= MM_ALLOC_BIT; - ret = (void*)((char*)node + SIZEOF_MM_ALLOCNODE); + ret = (void *)((FAR char *)node + SIZEOF_MM_ALLOCNODE); } mm_givesemaphore(heap); diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index aa7971c0cb..0609885653 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -119,7 +119,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, * the allocation. */ - node = (FAR struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE); + node = (FAR struct mm_allocnode_s *)(rawchunk - SIZEOF_MM_ALLOCNODE); /* Find the aligned subregion */ @@ -135,7 +135,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, /* Get the node the next node after the allocation. */ - next = (FAR struct mm_allocnode_s*)((char*)node + node->size); + next = (FAR struct mm_allocnode_s *)((FAR char *)node + node->size); /* Make sure that there is space to convert the preceding mm_allocnode_s * into an mm_freenode_s. I think that this should always be true @@ -143,7 +143,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, DEBUGASSERT(alignedchunk >= rawchunk + 8); - newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE); + newnode = (FAR struct mm_allocnode_s *)(alignedchunk - SIZEOF_MM_ALLOCNODE); /* Preceding size is full size of the new 'node,' including * SIZEOF_MM_ALLOCNODE @@ -162,7 +162,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, if (precedingsize < SIZEOF_MM_FREENODE) { alignedchunk += alignment; - newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE); + newnode = (FAR struct mm_allocnode_s *)(alignedchunk - SIZEOF_MM_ALLOCNODE); precedingsize = (size_t)newnode - (size_t)node; } @@ -210,5 +210,5 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, } mm_givesemaphore(heap); - return (FAR void*)alignedchunk; + return (FAR void *)alignedchunk; } diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index ef592b7cf4..7b6e75f298 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -115,7 +115,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Map the memory chunk into an allocated node structure */ - oldnode = (FAR struct mm_allocnode_s *)((FAR char*)oldmem - SIZEOF_MM_ALLOCNODE); + oldnode = (FAR struct mm_allocnode_s *)((FAR char *)oldmem - SIZEOF_MM_ALLOCNODE); /* We need to hold the MM semaphore while we muck with the nodelist. */ @@ -146,13 +146,13 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, * best decision */ - next = (FAR struct mm_freenode_s *)((FAR char*)oldnode + oldnode->size); + next = (FAR struct mm_freenode_s *)((FAR char *)oldnode + oldnode->size); if ((next->preceding & MM_ALLOC_BIT) == 0) { nextsize = next->size; } - prev = (FAR struct mm_freenode_s *)((FAR char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT)); + prev = (FAR struct mm_freenode_s *)((FAR char *)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT)); if ((prev->preceding & MM_ALLOC_BIT) == 0) { prevsize = prev->size; @@ -240,7 +240,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Extend the node into the previous free chunk */ - newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev); + newnode = (FAR struct mm_allocnode_s *)((FAR char *)oldnode - takeprev); /* Did we consume the entire preceding chunk? */ @@ -277,7 +277,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, * should be save for this. */ - newmem = (FAR void*)((FAR char*)newnode + SIZEOF_MM_ALLOCNODE); + newmem = (FAR void *)((FAR char *)newnode + SIZEOF_MM_ALLOCNODE); memcpy(newmem, oldmem, oldsize - SIZEOF_MM_ALLOCNODE); } @@ -292,7 +292,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, * chunk) */ - andbeyond = (FAR struct mm_allocnode_s*)((char*)next + nextsize); + andbeyond = (FAR struct mm_allocnode_s *)((FAR char *)next + nextsize); /* Remove the next node. There must be a predecessor, but there * may not be a successor node. @@ -308,7 +308,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Extend the node into the next chunk */ oldnode->size = oldsize + takenext; - newnode = (FAR struct mm_freenode_s *)((char*)oldnode + oldnode->size); + newnode = (FAR struct mm_freenode_s *)((FAR char *)oldnode + oldnode->size); /* Did we consume the entire preceding chunk? */ @@ -347,7 +347,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, */ mm_givesemaphore(heap); - newmem = (FAR void*)mm_malloc(heap, size); + newmem = (FAR void *)mm_malloc(heap, size); if (newmem) { memcpy(newmem, oldmem, oldsize); diff --git a/mm/mm_heap/mm_sbrk.c b/mm/mm_heap/mm_sbrk.c index a0f868012e..19a91cc3dd 100644 --- a/mm/mm_heap/mm_sbrk.c +++ b/mm/mm_heap/mm_sbrk.c @@ -75,7 +75,7 @@ * heap - A reference to the data structure that defines this heap. * incr - Specifies the number of bytes to add or to remove from the * space allocated for the process. - maxbreak - The maximum permissible break address. + * maxbreak - The maximum permissible break address. * * Returned Value: * Upon successful completion, sbrk() returns the prior break value. diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index ab6c39c20a..c829876079 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -73,7 +73,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, /* Get a reference to the next node */ - next = (FAR struct mm_freenode_s*)((char*)node + node->size); + next = (FAR struct mm_freenode_s *)((FAR char *)node + node->size); /* Check if it is free */ @@ -84,7 +84,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, /* Get the chunk next the next node (which could be the tail chunk) */ - andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size); + andbeyond = (FAR struct mm_allocnode_s *)((FAR char *)next + next->size); /* Remove the next node. There must be a predecessor, but there may * not be a successor node. @@ -101,7 +101,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, * tailing memory from the aligned chunk. */ - newnode = (FAR struct mm_freenode_s*)((char*)node + size); + newnode = (FAR struct mm_freenode_s *)((FAR char *)node + size); /* Set up the size of the new node */ @@ -127,7 +127,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, * tailing memory from the aligned chunk. */ - newnode = (FAR struct mm_freenode_s*)((char*)node + size); + newnode = (FAR struct mm_freenode_s *)((FAR char *)node + size); /* Set up the size of the new node */ -- GitLab From e947ea587d01fdf6538f8b26d9fad97ce29a45f1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 10:54:41 -0600 Subject: [PATCH 197/858] Add fs/tmpfs. Nothing much there yet --- ChangeLog | 2 + fs/romfs/fs_romfs.h | 53 +++++++------- fs/tmpfs/Kconfig | 51 +++++++++++++ fs/tmpfs/Make.defs | 47 ++++++++++++ fs/tmpfs/fs_tmpfs.h | 169 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 26 deletions(-) create mode 100644 fs/tmpfs/Kconfig create mode 100644 fs/tmpfs/Make.defs create mode 100644 fs/tmpfs/fs_tmpfs.h diff --git a/ChangeLog b/ChangeLog index 6aa0e2b1ef..ce7bf0b658 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11013,4 +11013,6 @@ parameters to match names used on OpenGroup.org (2015-10-02). * drivers/lcd/st7565.c: Extend to include support for the ERC12864-3. From Pierre-noel Bouteville (2015-10-07). + * fs/tmpfs: Created a directory that will eventually hold a trivial + temporary RAM file file system (2015-10-0i8). diff --git a/fs/romfs/fs_romfs.h b/fs/romfs/fs_romfs.h index 8b1d5fc5b1..12ab8d8823 100644 --- a/fs/romfs/fs_romfs.h +++ b/fs/romfs/fs_romfs.h @@ -188,39 +188,40 @@ struct romfs_dirinfo_s * Public Data ****************************************************************************/ -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif -EXTERN void romfs_semtake(struct romfs_mountpt_s *rm); -EXTERN void romfs_semgive(struct romfs_mountpt_s *rm); -EXTERN int romfs_hwread(struct romfs_mountpt_s *rm, uint8_t *buffer, - uint32_t sector, unsigned int nsectors); -EXTERN int romfs_filecacheread(struct romfs_mountpt_s *rm, - struct romfs_file_s *rf, uint32_t sector); -EXTERN int romfs_hwconfigure(struct romfs_mountpt_s *rm); -EXTERN int romfs_fsconfigure(struct romfs_mountpt_s *rm); -EXTERN int romfs_fileconfigure(struct romfs_mountpt_s *rm, - struct romfs_file_s *rf); -EXTERN int romfs_checkmount(struct romfs_mountpt_s *rm); -EXTERN int romfs_finddirentry(struct romfs_mountpt_s *rm, - struct romfs_dirinfo_s *dirinfo, - const char *path); -EXTERN int romfs_parsedirentry(struct romfs_mountpt_s *rm, - uint32_t offset, uint32_t *poffset, uint32_t *pnext, - uint32_t *pinfo, uint32_t *psize); -EXTERN int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32_t offset, - char *pname); -EXTERN int romfs_datastart(struct romfs_mountpt_s *rm, uint32_t offset, - uint32_t *start); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void romfs_semtake(FAR struct romfs_mountpt_s *rm); +void romfs_semgive(FAR struct romfs_mountpt_s *rm); +int romfs_hwread(FAR struct romfs_mountpt_s *rm, FAR uint8_t *buffer, + uint32_t sector, unsigned int nsectors); +int romfs_filecacheread(FAR struct romfs_mountpt_s *rm, + FAR struct romfs_file_s *rf, uint32_t sector); +int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm); +int romfs_fsconfigure(FAR struct romfs_mountpt_s *rm); +int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm, + FAR struct romfs_file_s *rf); +int romfs_checkmount(FAR struct romfs_mountpt_s *rm); +int romfs_finddirentry(FAR struct romfs_mountpt_s *rm, + FAR struct romfs_dirinfo_s *dirinfo, + FAR const char *path); +int romfs_parsedirentry(FAR struct romfs_mountpt_s *rm, + uint32_t offset, FAR uint32_t *poffset, FAR uint32_t *pnext, + FAR uint32_t *pinfo, FAR uint32_t *psize); +int romfs_parsefilename(FAR struct romfs_mountpt_s *rm, uint32_t offset, + FAR char *pname); +int romfs_datastart(FAR struct romfs_mountpt_s *rm, uint32_t offset, + FAR uint32_t *start); #undef EXTERN #if defined(__cplusplus) diff --git a/fs/tmpfs/Kconfig b/fs/tmpfs/Kconfig new file mode 100644 index 0000000000..c1f1220703 --- /dev/null +++ b/fs/tmpfs/Kconfig @@ -0,0 +1,51 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config FS_TMPFS + bool "TMPFS file system" + default n + depends on !DISABLE_MOUNTPOINT && EXPERIMENTAL + select FS_READABLE + select FS_WRITABLE + ---help--- + Enable TMPFS filesystem support + +if FS_TMPFS + +config FS_TMPFS_DIRECTORY_ALLOCGUARD + int "Directory object over-allocation" + default 64 + ---help--- + In order to avoid frequent reallocations, a little more memory than + needed is always allocated. This permits the directory to grow + without so many realloctions. + +config FS_TMPFS_DIRECTORY_FREEGUARD + int "Directory under free" + default 128 + ---help--- + In order to avoid frequent reallocations, a lot of free memory has + to be available before a directory entry shrinks (via reallocation) + little more memory than needed is always allocated. This permits + the directory to shrink without so many realloctions. + +config FS_TMPFS_FILE_ALLOCGUARD + int "Directory object over-allocation" + default 512 + ---help--- + In order to avoid frequent reallocations, a little more memory than + needed is always allocated. This permits the file to grow without + so many realloctions. + +config FS_TMPFS_FILE_FREEGUARD + int "Directory under free" + default 1024 + ---help--- + In order to avoid frequent reallocations, a lot of free memory has + to be available before a directory entry shrinks (via reallocation) + little more memory than needed is always allocated. This permits + the file to shrink without so many realloctions. + +endif diff --git a/fs/tmpfs/Make.defs b/fs/tmpfs/Make.defs new file mode 100644 index 0000000000..b4c6ebca82 --- /dev/null +++ b/fs/tmpfs/Make.defs @@ -0,0 +1,47 @@ +############################################################################ +# fs/romfs/Make.defs +# +# Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name Nuttx nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_FS_ROMFS),y) +# Files required for ROMFS file system support + +ASRCS += +CSRCS += fs_romfs.c fs_romfsutil.c + +# Include ROMFS build support + +DEPPATH += --dep-path romfs +VPATH += :romfs + +endif diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h new file mode 100644 index 0000000000..d2ff049d1b --- /dev/null +++ b/fs/tmpfs/fs_tmpfs.h @@ -0,0 +1,169 @@ +/**************************************************************************** + * fs/tmpfs/fs_tmpfs.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __FS_TMPFS_FS_TMPFS_H +#define __FS_TMPFS_FS_TMPFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#ifndef CONFIG_DISABLE_MOUNTPOINT + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TFO_FLAG_UNLINKED (1 << 0) /* Bit 0: File is unlinked */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* TMPFS memory object types */ + +enum tmpfs_objtype_e +{ + TMPFS_DIRECTORY = 0, /* Directory */ + TMPFS_REGULAR /* Regular file */ +}; + +/* The generic form of a TMPFS memory object */ + +struct tmpfs_object_s +{ + size_t to_alloc; /* Allocated size of the memory object */ + uint8_t to_type; /* See enum tmpfs_objtype_e */ + uint8_t to_refs; /* Reference count */ + sem_t to_exclsem; /* Supports exclusive access to the object */ +}; + +/* The form of one directory entry */ + +struct tmpfs_dirent_s +{ + FAR struct tmpfs_object_s *rde_object; + FAR char *rde_name; +}; + +/* The form of a directory memory object */ + +struct tmpfs_directory_s +{ + /* First fields must match common TMPFS object layout */ + + size_t tdo_alloc; /* Allocated size of the directory object */ + uint8_t tdo_type; /* See enum tmpfs_objtype_e */ + uint8_t tdo_refs; /* Reference count */ + sem_t tdo_exclsem; /* Supports exclusive access to the directory */ + + /* Remaining fields are unique to a directory object */ + + uint16_t tdo_nentries; /* Number of directory entries */ + struct tmpfs_dirent_s tdo_entry[1]; +}; + +#define SIZEOF_TMPFS_DIRECTORY(n) \ + (sizeof(struct tmpfs_directory_s) + ((n) - 1)*sizeof(struct tmpfs_dirent_s)) + +/* The form of a regular file memory object + * + * NOTE that in this very simplified implementation, there is no per-open + * state. The file memory object also serves as the open file object, + * saving an allocation. This has the negative side effect that no per- + * open state can be retained (such as open flags). + */ + +struct tmpfs_file_s +{ + /* First fields must match common TMPFS object layout */ + + size_t tfo_alloc; /* Allocated size of the file object */ + uint8_t tfo_type; /* See enum tmpfs_objtype_e */ + uint8_t tfo_refs; /* Reference count */ + sem_t tfo_exclsem; /* Supports exclusive access to the file */ + + /* Remaining fields are unique to a directory object */ + + uint8_t tfo_flags; /* See TFO_FLAG_* definitions */ + size_t tfo_size; /* Valid file size */ + uint8_t tfo_data[1]; /* File data starts here */ +}; + +#define SIZEOF_TMPFS_DIRECTORY(n) (sizeof(struct tmpfs_file_s) + (n) - 1) + +/* This structure represents one instance of a TMPFS file system */ + +struct tmpfs_s +{ + /* The root directory */ + + FAR struct tmpfs_directory_s *r_root; + + sem_t r_exclsem; /* Supports exclusive access to the file system */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +EXTERN const struct mountpt_operations tmpfs_operations; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __FS_TMPFS_FS_TMPFS_H */ -- GitLab From e91f82b0f897618fa7a27137a9c6305b20e23662 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 12:26:35 -0600 Subject: [PATCH 198/858] fs/tmpfs: Add an unfinished implementation of tmpfs --- fs/tmpfs/Make.defs | 16 +- fs/tmpfs/fs_tmpfs.c | 1284 +++++++++++++++++++++++++++++++++++++++++++ fs/tmpfs/fs_tmpfs.h | 2 +- 3 files changed, 1293 insertions(+), 9 deletions(-) create mode 100644 fs/tmpfs/fs_tmpfs.c diff --git a/fs/tmpfs/Make.defs b/fs/tmpfs/Make.defs index b4c6ebca82..f4f5d7b6ad 100644 --- a/fs/tmpfs/Make.defs +++ b/fs/tmpfs/Make.defs @@ -1,7 +1,7 @@ ############################################################################ -# fs/romfs/Make.defs +# fs/tmpfs/Make.defs # -# Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -33,15 +33,15 @@ # ############################################################################ -ifeq ($(CONFIG_FS_ROMFS),y) -# Files required for ROMFS file system support +ifeq ($(CONFIG_FS_TMPFS),y) +# Files required for TMPFS file system support ASRCS += -CSRCS += fs_romfs.c fs_romfsutil.c +CSRCS += fs_tmpfs.c -# Include ROMFS build support +# Include TMPFS build support -DEPPATH += --dep-path romfs -VPATH += :romfs +DEPPATH += --dep-path tmpfs +VPATH += :tmpfs endif diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c new file mode 100644 index 0000000000..fd365f05c5 --- /dev/null +++ b/fs/tmpfs/fs_tmpfs.c @@ -0,0 +1,1284 @@ +/**************************************************************************** + * fs/tmpfs/fs_tmpfs.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include + +#include +#include + +#include + +#include "fs_tmpfs.h" + +#ifndef CONFIG_DISABLE_MOUNTPOINT + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* TMPFS helpers */ + +static void tmpfs_lock(FAR struct tmpfs_s *fs); +#define tmpfs_unlock(fs) (sem_post(&fs->r_exclsem)) + +static void tmpfs_lock_object(FAR struct tmpfs_object_s *to); +#define tmpfs_unlock_object(to) (sem_post(&to->to_exclsem)) +#define tmpfs_unlock_file(tfo) (sem_post(&tfo->tfo_exclsem)) +#define tmpfs_unlock_directory(tdo) (sem_post(&tdo->tdo_exclsem)) + +static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, + unsigned int nentries); +static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, + size_t newsize); +static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, + FAR const char *name); +static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, + FAR const char *name); +static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, + FAR struct tmpfs_object_s *to, FAR const char *name); +static int tmpfs_create_file(FAR struct tmpfs_directory_s *tdo, + FAR struct tmpfs_file_s **tfo); +static int tmpfs_find_object(FAR struct tmpfs_s *fs, + FAR const char *relpath, FAR struct tmpfs_object_s **object, + FAR struct tmpfs_directory_s **parent); +static int tmpfs_find_file(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_file_s **tfo, + FAR struct tmpfs_directory_s **parent); +static int tmpfs_find_directory(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_directory_s **tdo, + FAR struct tmpfs_directory_s **parent); + +/* File system operations */ + +static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int tmpfs_close(FAR struct file *filep); +static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence); +static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp); +static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct fs_dirent_s *dir); +static int tmpfs_closedir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); +static int tmpfs_readdir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); +static int tmpfs_rewinddir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); +static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, + FAR void **handle); +static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, + unsigned int flags); +static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf); +static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath); +static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, + mode_t mode); +static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath); +static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, + FAR const char *newrelpath); +static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct stat *buf); + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +const struct mountpt_operations tmpfs_operations = +{ + tmpfs_open, /* open */ + tmpfs_close, /* close */ + tmpfs_read, /* read */ + tmpfs_write, /* write */ + tmpfs_seek, /* seek */ + tmpfs_ioctl, /* ioctl */ + NULL, /* sync */ + tmpfs_dup, /* dup */ + tmpfs_opendir, /* opendir */ + tmpfs_closedir, /* closedir */ + tmpfs_readdir, /* readdir */ + tmpfs_rewinddir, /* rewinddir */ + tmpfs_bind, /* bind */ + tmpfs_unbind, /* unbind */ + tmpfs_statfs, /* statfs */ + tmpfs_unlink, /* unlink */ + tmpfs_mkdir, /* mkdir */ + tmpfs_rmdir, /* rmdir */ + tmpfs_rename, /* rename */ + tmpfs_stat, /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * name: tmpfs_lock + ****************************************************************************/ + +static void tmpfs_lock(FAR struct tmpfs_s *fs) +{ + int ret; + + while ((ret = sem_wait(&fs->r_exclsem)) < 0) + { + DEBUGASSERT(errno == EINTR) + } +} + +/**************************************************************************** + * name: tmpfs_lock_object + ****************************************************************************/ + +static void tmpfs_lock_object(FAR struct tmpfs_object_s *to) +{ + int ret; + + while ((ret = sem_wait(&to->to_exclsem)) < 0) + { + DEBUGASSERT(errno == EINTR) + } +} + +/**************************************************************************** + * name: tmpfs_realloc_directory + ****************************************************************************/ + +static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, + unsigned int nentries) +{ + FAR struct tmpfs_directory_s *oldrdo = *tdo; + FAR struct tmpfs_directory_s *newrdo; + size_t objsize; + int ret = oldrdo->tdo_nentries; + + /* Get the new object size */ + + objsize = SIZEOF_TMPFS_DIRECTORY(nentries); + if (objsize <= oldrdo->tdo_alloc) + { + /* Already big enough */ + + *oldrdo->tdo_nentries = nentries; + return OK; + } + + /* Added some additional amount to the new size to account frequent + * reallocations. + */ + + objsize += CONFIG_FS_TMPFS_DIRECTORY_ALLOCGUARD; + + /* Realloc the directory object */ + + newrdo = (FAR struct tmpfs_directory_s *)kmm_realloc(oldrdo, objsize); + if (newrdo == NULL) + { + return -ENOMEM; + } + + /* Return the new address of the reallocating directory object */ + + newrdo->tdo_alloc = objsize; + *newrdo->tdo_nentries = nentries; + *tdo = newrdo; + + /* Return the index to the first, newly alloated directory entry */ + + return ret; +} + +/**************************************************************************** + * name: tmpfs_realloc_file + ****************************************************************************/ + +static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, + size_t newsize) +{ + FAR struct tmpfs_file_s *oldtfo = *tfo; + FAR struct tmpfs_file_s *newtfo; + size_t objsize; + size_t allocsize; + size_t delta; + + /* Check if the current allocation is sufficent */ + + objsize = SIZEOF_TMPFS_FILE(newsize); + + /* Added some additional amount to the new size to account frequent + * reallocations. + */ + + allocsize = objsize + CONFIG_FS_TMPFS_FILE_ALLOCGUARD; + + /* Are we growing or shrinking the object? */ + + if (allocsize <= oldtfo->tfo_alloc) + { + /* Shrinking ... Shrink unconditionally if the size is shrinking to + * zero. + */ + + if (newsize > 0) + { + /* Otherwise, don't realloc unless the object has shrunk by a + * lot. + */ + + delta = oldtfo->tfo_alloc - allocsize; + if (delta <= CONFIG_FS_TMPFS_FILE_ALLOCGUARD) + { + /* Hasn't shrunk enough.. Return doing nothing for now */ + + oldtfo->tfo_size = newsize; + return OK; + } + } + } + + /* Realloc the directory object */ + + newtfo = (FAR struct tmpfs_file_s *)kmm_realloc(oldtfo, objsize); + if (newtfo == NULL) + { + return -ENOMEM; + } + + /* Return the new address of the reallocating directory object */ + + newtfo->tfo_alloc = allocsize; + newtfo->tfo_size = objsize; + *tfo = newtfo; + return OK; +} + +/**************************************************************************** + * name: tmpfs_find_dirent + ****************************************************************************/ + +static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, + FAR const char *name) +{ + int i; + + /* Search the list of directory entries for a match */ + + for (i = 0; + i < tdo->tdo_nentries && + strcmp(tdo->tdo_entry[i].rde_name, name) != 0; + i++); + + /* Return what we found, if anything */ + + return i < tdo->tdo-nentries ? i : -ENOENT; +} + +/**************************************************************************** + * name: tmpfs_remove_dirent + ****************************************************************************/ + +static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, + FAR const char *name) +{ + int index; + int last; + + /* Search the list of directory entries for a match */ + + index = tmpfs_find_dirent(tdo, name); + if (index < 0) + { + return index; + } + + /* Free the object name */ + + if (tdo_entry[index].rde_name != NULL) + { + kmm_free(tdo_entry[index].rde_name); + } + + /* Remove be replace this entry with the final directory entry */ + + last = tdo->tdo_nentries - 1; + if (index != last) + { + tdo->tdo_entry[index].rde_object = tdo->tdo_entry[last].rde_object; + tdo->tdo_entry[index].rde_name = tdo->tdo_entry[last].rde_name; + } + + /* And decrement the count of directory entries */ + + tdo->tdo_entries = last; + return OK; +} + +/**************************************************************************** + * name: tmpfs_add_dirent + ****************************************************************************/ + +static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, + FAR struct tmpfs_object_s *to, + FAR const char *name) +{ + FAR struct tmpfs_directory_s *oldtdo; + FAR struct tmpfs_directory_s *newtdo; + FAR char newname; + unsigned int nentries; + int index; + + /* Copy the name string so that it will persist as long as the + * directory entry. + */ + + newname = strdup(name) + if (newname == NULL) + { + return -ENOMEM; + } + + /* Get the new number of entries */ + + oldtdo = *tdo; + nentries = oldtdo->tdo_nentries + 1; + + /* Reallocate the directory object (if necessary) */ + + index = tmpfs_realloc_directory(tdo, nentries); + if (index < 0) + { + kmm_free(newname) + return index; + } + + /* Save the new object info in the new directory entry */ + + newtdo = *tdo; + newtdo->tdo_entry[index].tdo_object = to; + newtdo->tdo_entry[index].tdo_name = newname; + return OK; +} + +/**************************************************************************** + * name: tmpfs_create_file + ****************************************************************************/ + +static int tmpfs_create_file(FAR struct tmpfs_directory_s *tdo, + FAR struct tmpfs_file_s **tfo) +{ + FAR struct tmpfs_file_s *newtfo; + size_t allocsize; + + /* Create a new zero length file object */ + + allocsize = SIZEOF_TMPFS_FILE(FS_TMPFS_FILE_ALLOCGUARD); + newtfo = (FAR struct tmpfs_file_s *)kmm_malloc(allocsize); + if (nenewtfowfile == NULL) + { + return -ENOMEM; + } + + /* Initialize the new file object */ + + newtfo->tfo_alloc = allocsize; + newtfo->tfo_type = TMPFS_REGULAR; + newtfo->tfo_refs = 1; + newtfo->tfo_flags = 0; + newtfo->tfo_size = 0; + sem_init(&newtfo->tfo_exclsem, 0, 0); + + *tfo = newtfo; + return OK; +} + +/**************************************************************************** + * name: tmpfs_find_object + ****************************************************************************/ + +static int tmpfs_find_object(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_object_s **object, + FAR struct tmpfs_directory_s **parent) +{ + FAR struct tmpfs_object_s *to; + FAR struct tmpfs_directory_s *tdo; + FAR struct tmpfs_directory_s *next_rdo; + FAR char *segment; + FAR char *next_segment; + FAR char *last; + FAR char *tkptr; + FAR char *copy; + int index; + + /* Make a copy of the path (so that we can modify it via strtok) */ + + copy = strdup(relpath); + if (copy == NULL) + { + return NULL; + } + + /* Traverse the file system for any object with the matching name */ + + to = (FAR struct tmpfs_object_s)fs->root; + next_rdo = fs->root; + + for (segment = strtok_r(copy, "/", &tkptr); + segment != NULL; + segment = next_segment) + { + /* Get the next segment after the one we are currently working on. + * This will be NULL is we are working on the final segment of the + * relpath. + */ + + next_segment = strtok_r(NULL, "/", &tkptr); + + /* Search the the next directory. */ + + tdo = next_rdo; + + /* Find the TMPFS object with the next segment name in the current + * directory. + */ + + index = tmpfs_find_dirent(tdo, segment); + if (index < 0) + { + /* No object with this name exists in the directory. */ + + return index; + } + + to = tdo->tdo_entry[index]; + + /* Is this object another directory? */ + + if (to->to_type != TMPFS_DIRECTORY) + { + /* No. Was this the final segment in the path? */ + + if (next_segment == NULL) + { + /* Then we can break out of the loop now */ + + break; + } + + /* No, this was not the final segement of the relpath. + * We cannot continue the search if any of the intermidate + * segements do no correspond to directories. + */ + + return -ENOTDIR; + } + + /* Search this directory for the next segement. If we + * exit the loop, tdo will still refer to the parent + * directory of to. + */ + + next_rdo = (FAR struct tmpfs_directory_s *)to; + } + + /* When we exit this loop (successfully), to will point to the TMPFS + * object associated with the terminal segment of the relpath. + * Increment the reference count on the located object. + */ + + /* Free the dup'ed string */ + + kmm_free(copy); + + /* Return what we found */ + + if (parent) + { + /* Get exclusive access to the parent and increment the reference + * count on the object. + */ + + tmpfs_lock_object(parent); + parent->tdo_refs++; + + *parent = tdo; + } + + if (object) + { + /* Get exclusive access to the object and increment the reference + * count on the object. + */ + + tmpfs_lock_object(to); + to->to_refs++; + + *object = to; + } + + return OK; +} + +/**************************************************************************** + * name: tmpfs_find_file + ****************************************************************************/ + +static int tmpfs_find_file(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_file_s **tfo, + FAR struct tmpfs_directory_s **parent) +{ + FAR struct tmpfs_object_s *to; + int ret; + + /* Find the object at this path */ + + ret = tmpfs_find_object(fs, relpath, &to, parent); + if (ret >= 0) + { + /* We found it... but is it a regular file? */ + + if (to->to_type != TMPFS_REGULAR) + { + /* No... unlock it and return an error */ + + to->to_refs++; +#warning Add check if the file system became unlinked + tmpfs_unlock_object(to); + ret = -EISDIR; + } + + /* Return the verified file object */ + + *tfo = (FAR struct tmpfs_file_s *)to; + } + + return ret; +} + +/**************************************************************************** + * name: tmpfs_find_directory + ****************************************************************************/ + +static int tmpfs_find_directory(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_directory_s **tdo, + FAR struct tmpfs_directory_s **parent) +{ + FAR struct tmpfs_object_s *to; + int ret; + + /* Find the object at this path */ + + ret = tmpfs_find_object(fs, relpath, &to, parent); + if (ret >= 0) + { + /* We found it... but is it a regular file? */ + + if (to->to_type != TMPFS_DIRECTORY) + { + /* No... unlock it and return an error */ + + to->to_refs++; +#warning Add check if the file system became unlinked + tmpfs_unlock_object(to); + ret = -ENOTDIR; + } + + /* Return the verified file object */ + + *tdo = (FAR struct tmpfs_file_s *)to; + } + + return ret; +} + +/**************************************************************************** + * name: tmpfs_open + ****************************************************************************/ + +static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_file_s *tfo; + int ret; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ + + tmpfs_lock(fs); + + /* Find the file allocation associated with this relative path. + * If successful, this action will lock both the parent directory and + * the file object, adding one to the reference count of both. + * In the event that -ENOENT, there will still be a reference and + * lock on the returned directory. + */ + + ret = tmpfs_find_file(fs, relpath, &tfo, NULL); + if (ret >= 0) + { + /* The file exists. We hold the lock and one reference count + * on the file object. + * + * It would be an error if we are asked to create it exclusively + */ + + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + { + /* Already exists -- can't create it exclusively */ + + ret = -EEXIST; + goto errout_with_filelock; + } + + /* Check if the caller has sufficient privileges to open the file */ + /* REVISIT: No file protection implemented */ + + /* If O_TRUNC is specified and the file is opened for writing, + * then truncate the file. This operation requires that the file is + * writeable, but we have already checked that. O_TRUNC without write + * access is ignored. + */ + + if ((oflags & (O_TRUNC|O_WRONLY)) == (O_TRUNC|O_WRONLY)) + { + /* Truncate the file to zero length (if it is not already + * zero length) + */ + + if (tfo->tfo_size > 0) + { + ret = tmpfs_realloc_file(tfo, 0); + if (ret < 0) + { + goto errout_with_filelock; + } + } + } + } + + /* ENOENT would be returned by tmpfs_find_file() if the full directory + * path was found, but the file was not found in the final directory. + */ + + else if (ret == -ENOENT) + { + /* The file does not exist. Were we asked to create it? */ + + if ((oflags & O_CREAT) == 0) + { + /* No.. then we fail with -ENOENT */ + + ret = -ENOENT; + goto errout_with_fslock; + } + + /* Yes.. create the file object. */ + + ret = tmpfs_create_file(&tfo); + if (ret < 0) + { + goto errout_with_fslock; + } + + /* Insert the file object into the directory structure */ +#warning Missing logic. + } + + /* Some other error occurred */ + + else + { + goto errout_with_fslock; + } + + /* Save the struct tmpfs_file_s instance as the file private data */ + + filep->f_priv = tfo; + + /* Unlock the file object, but retain the reference count */ + + tmpfs_unlock_file(tfo); + tmpfs_unlock(fs); + return OK; + + /* Error exits */ + +errout_with_filelock: + tfo->tfo_refs--; + tmpfs_unlock_file(tfo); + +errout_with_fslock: + tmpfs_unlock(fs); + return ret; +} + +/**************************************************************************** + * name: tmpfs_close + ****************************************************************************/ + +static int tmpfs_close(FAR struct file *filep) +{ + FAR struct tmpfs_file_s *tfo; + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = filep->f_priv; + + /* Get exclusive access to the file */ + + tmpfs_lock_file(tfo); + + /* Decrement the reference count on the file */ + + DEBUGASSERT(tfo->tfo_refs > 0); + if (tfo->tfo_refs > 0) + { + tfo->tfo_refs--; + } + + filep->f_priv = NULL; + + /* If the reference count decremented to zero and the file has been + * unlinked, then free the file allocation now. + */ + + if (tfo->tfo_refs == 0 && (tfo->flags & TFO_FLAG_UNLINKED) != 0) + { + /* Free the file object while we hold the lock? Weird but this + * should be safe because the object is unlinked and could not + * have any other references. + */ + + kmm_free(tfo); + return OK; + } + + /* Release the lock on the file */ + + tmpfs_unlock_file(tfo); + return OK; +} + +/**************************************************************************** + * name: tmpfs_read + ****************************************************************************/ + +static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + FAR struct tmpfs_file_s *tfo; + ssize_t nread; + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = filep->f_priv; + + /* Get exclusive access to the file */ +#warning Missing logic + /* Handle attempts to read beyond the end of the file */ +#warning Missing logic + /* Copy data from the memory object to the user buffer */ +#warning Missing logic + /* Release the lock on the file */ +#warning Missing logic + + return nread; +} + +/**************************************************************************** + * name: tmpfs_write + ****************************************************************************/ + +static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + FAR struct tmpfs_file_s *tfo; + ssize_t nwritten; + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = filep->f_priv; + + /* Get exclusive access to the file */ +#warning Missing logic + /* if the write would go past the end of the file, then extend the file + * by reallocating the in-memory file object + */ +#warning Missing logic + /* Copy data from the user buffer to the memory object */ +#warning Missing logic + /* Release the lock on the file */ +#warning Missing logic + + return nwritten; +} + +/**************************************************************************** + * name: tmpfs_seek + ****************************************************************************/ + +static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence) +{ + FAR struct tmpfs_file_s *tfo; + off_t position; + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = filep->f_priv; + + /* Map the offset according to the whence option */ + + switch (whence) + { + case SEEK_SET: /* The offset is set to offset bytes. */ + position = offset; + break; + + case SEEK_CUR: /* The offset is set to its current location plus + * offset bytes. */ + position = offset + filep->f_pos; + break; + + case SEEK_END: /* The offset is set to the size of the file plus + * offset bytes. */ + position = offset + tfo->tfo_size; + break; + + default: + return -EINVAL; + } + + /* Attempts to set the position beyound the end of file will + * work if the file is open for write access. + * + * REVISIT: This simple implementation has no per-open storage that + * would be needed to retain the open flags. + */ + +#if 0 + if (position > tfo->tfo_size && (tfo->tfo_oflags & O_WROK) == 0) + { + /* Otherwise, the position is limited to the file size */ + + position = tfo->tfo_size; + } +#endif + + /* Save the new file position */ + + filep->f_pos = position; + return position; +} + +/**************************************************************************** + * name: tmpfs_ioctl + ****************************************************************************/ + +static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct tmpfs_file_s *tfo; + FAR void **ppv = (FAR void**)arg; + + fvdbg("cmd: %d arg: %08lx\n", cmd, arg); + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = filep->f_inode->i_private; + + DEBUGASSERT(tfo != NULL); + + /* Only one ioctl command is supported */ + + if (cmd == FIOC_MMAP && tfo->rm_xipbase && ppv) + { + /* Return the address on the media corresponding to the start of + * the file. + */ + + *ppv = (FAR void *)tfo->tfo_data; + return OK; + } + + fdbg("Invalid cmd: %d \n", cmd); + return -ENOTTY; +} + +/**************************************************************************** + * name: tmpfs_dup + ****************************************************************************/ + +static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + FAR struct tmpfs_file_s *tfo; + + fvdbg("Dup %p->%p\n", oldp, newp); + DEBUGASSERT(oldp->f_priv != NULL && + oldp->f_inode != NULL != NULL && + newp->f_priv == NULL && + newp->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + tfo = oldp->f_inode->i_private; + DEBUGASSERT(tfo != NULL); + + /* Get exclusive access to the file */ +#warning Missing logic + /* Increment the reference count */ +#warning Missing logic + /* Unlock the file. */ +#warning Missing logic + + /* Save a copy of the file object as the dup'ed file */ + + oldp->f_inode->i_private = tfo; + return OK; +} + +/**************************************************************************** + * name: tmpfs_opendir + ****************************************************************************/ + +static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct fs_dirent_s *dir) +{ +} + +/**************************************************************************** + * name: tmpfs_closedir + ****************************************************************************/ + +static int tmpfs_closedir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir) +{ +} + +/**************************************************************************** + * name: tmpfs_readdir + ****************************************************************************/ + +static int tmpfs_readdir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir) +{ +} + +/**************************************************************************** + * name: tmpfs_rewinddir + ****************************************************************************/ + +static int tmpfs_rewinddir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir) +{ +} + +/**************************************************************************** + * name: tmpfs_bind + ****************************************************************************/ + +static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, + FAR void **handle) +{ +} + +/**************************************************************************** + * name: tmpfs_unbind + ****************************************************************************/ + +static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, + unsigned int flags) +{ +} + +/**************************************************************************** + * name: tmpfs_statfs + ****************************************************************************/ + +static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_file_s *tfo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Traverse the file system to accurmulate statistics */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * name: tmpfs_unlink + ****************************************************************************/ + +static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_directory_s *parent; + FAR struct tmpfs_file_s *tfo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Find the file allocation associated with this relative path */ +#warning Missing logic + /* If the reference count is not zero, then just mark the file as + * unlinked + */ +#warning Missing logic + /* Otherwise, remove the file from the parent directory entry */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + /* Free the file object allocation */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * name: tmpfs_mkdir + ****************************************************************************/ + +static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, + mode_t mode) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_directory_s *parent; + FAR struct tmpfs_directory_s *tdo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Find the parent directory allocation associated with this relative path */ +#warning Missing logic + /* Does the directory already exist? */ +#warning Missing logic + /* Create the new, empty directory entry */ +#warning Missing logic + /* Add the nre directory entry to the parent directory */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * name: tmpfs_rmdir + ****************************************************************************/ + +static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_directory_s *parent; + FAR struct tmpfs_directory_s *tdo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Find the directory allocation associated with this relative path */ +#warning Missing logic + /* Is the directory empty? */ +#warning Missing logic + /* Remove the directory entry from the parent structure */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + /* Free the directory object */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * name: tmpfs_rename + ****************************************************************************/ + +static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, + FAR const char *newrelpath) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_file_s *tfo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Find the file allocation associated with this relative path */ +#warning Missing logic + /* If the file was found, free its name allocation and repace the name + * with the new name. + */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * name: tmpfs_stat + ****************************************************************************/ + +static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct stat *buf) +{ + FAR struct inode *inode; + FAR struct tmpfs_s *fs; + FAR struct tmpfs_file_s *tfo; + + DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ +#warning Missing logic + /* Find the file/directory allocation associated with this relative path */ +#warning Missing logic + /* If found, generate the stat info */ +#warning Missing logic + /* Release the lock on the file system */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_DISABLE_MOUNTPOINT */ diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index d2ff049d1b..79cc8011c8 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -129,7 +129,7 @@ struct tmpfs_file_s uint8_t tfo_data[1]; /* File data starts here */ }; -#define SIZEOF_TMPFS_DIRECTORY(n) (sizeof(struct tmpfs_file_s) + (n) - 1) +#define SIZEOF_TMPFS_FILE(n) (sizeof(struct tmpfs_file_s) + (n) - 1) /* This structure represents one instance of a TMPFS file system */ -- GitLab From cc35c0c49d1f55b3bb2a23f5ceb3b52ae817a453 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 12:48:40 -0600 Subject: [PATCH 199/858] Add toosl/nxstyle.c --- ChangeLog | 2 + fs/tmpfs/fs_tmpfs.c | 1 + tools/Makefile.host | 16 +- tools/README.txt | 24 ++ tools/nxstyle.c | 987 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1027 insertions(+), 3 deletions(-) create mode 100644 tools/nxstyle.c diff --git a/ChangeLog b/ChangeLog index ce7bf0b658..b55967c223 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11015,4 +11015,6 @@ From Pierre-noel Bouteville (2015-10-07). * fs/tmpfs: Created a directory that will eventually hold a trivial temporary RAM file file system (2015-10-0i8). + * tools/: Add crappy style checking tool nxstyle.c. See thee tools/ + README file for more info (2015-10-08). diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index fd365f05c5..9a08621fe9 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -36,6 +36,7 @@ /**************************************************************************** * Included Files ****************************************************************************/ + #include #include diff --git a/tools/Makefile.host b/tools/Makefile.host index 1580ec8ed5..1f9f0027d0 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -1,7 +1,7 @@ ############################################################################ # Makefile.host # -# Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2008, 2011-2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -61,8 +61,9 @@ endif # Targets all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \ - configure$(HOSTEXEEXT) mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) mksymtab$(HOSTEXEEXT) \ - mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) + configure$(HOSTEXEEXT) mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \ + mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \ + nxstyle$(HOSTEXEEXT) default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) ifdef HOSTEXEEXT @@ -152,6 +153,15 @@ ifdef HOSTEXEEXT bdf-converter: bdf-converter$(HOSTEXEEXT) endif +# nxsytle - Check a file for compliance to NuttX coding style + +nxstyle$(HOSTEXEEXT): nxstyle.c + $(Q) $(HOSTCC) $(HOSTCFLAGS) -o nxstyle$(HOSTEXEEXT) nxstyle.c + +ifdef HOSTEXEEXT +nxstyle: nxstyle$(HOSTEXEEXT) +endif + # Create dependencies for a list of files mkdeps$(HOSTEXEEXT): mkdeps.c csvparser.c diff --git a/tools/README.txt b/tools/README.txt index 604a4c7055..5766a98458 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -210,6 +210,30 @@ mkctags.sh A script for creating ctags from Ken Pettit. See http://en.wikipedia.org/wiki/Ctags and http://ctags.sourceforge.net/ +nxstyle.c +--------- + + I am embarassed that this is here. This program is a complete hack + but, unfortunately, it has become so useful to me that I need to keep + it here. + + A little background: I have tinkered with pretty printers for some + time and have not been happy with the results. An alternative that + occurred to me would be just a standard checker that examines a C + file that gives warnings for violations of the coding standard. + + This turns out to be more difficult that you might think. A pretty + printer understands C syntax: They break the file up into its C + components then reassembles the output in the format. But parsing the + C loses the original file layout and so it not useful in this case. + + This program instead, uses a collection of heuristics (i.e., hacks and + bandaids) to examine the C file for obvious violations of the coding + standard. This program is completely ignorant of C syntax; it simply + performs crude pattern matching to check the file. + + Usage: nxstyle + pic32mx ------- diff --git a/tools/nxstyle.c b/tools/nxstyle.c new file mode 100644 index 0000000000..1eada32187 --- /dev/null +++ b/tools/nxstyle.c @@ -0,0 +1,987 @@ +/**************************************************************************** + * tools/nxstyle.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LINE_SIZE 512 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + FILE *instream; + char line[LINE_SIZE]; + bool btabs; + bool bfunctions; + bool bstatm; + bool bfor; + bool bswitch; + bool bstring; + bool bquote; + int lineno; + int indent; + int prevnest; + int ncomment; + int nnest; + int declnest; + int prevdeclnest; + int prevncomment; + int n; + int i; + + instream = fopen(argv[1], "r"); + if (!instream) + { + fprintf(stderr, "Failed to open %s\n", argv[1]); + return 1; + } + + btabs = false; + bfunctions = false; + bswitch = false; + bstring = false; + lineno = 0; + ncomment = 0; + nnest = 0; + declnest = 0; + prevdeclnest = 0; + prevncomment = 0; + + while (fgets(line, LINE_SIZE, instream)) + { + lineno++; + indent = 0; + prevnest = nnest; + prevdeclnest = declnest; + prevncomment = ncomment; + bstatm = false; + bfor = false; /* REVISIT: Implies for() is all on one line */ + + /* STEP 1: Find the indentation level and the start of real stuff on + * the line. + */ + + for (n = 0; line[n] != '\n' && isspace((int)line[n]); n++) + { + switch (line[n]) + { + case ' ': + { + indent++; + } + break; + + case '\t': + { + if (!btabs) + { + fprintf(stderr, "TABs found. First at line %d:%d\n", lineno, n); + btabs = true; + } + + indent = (indent + 4) & ~3; + } + break; + + default: + { + fprintf(stderr, "Unexpected white space character %02x found at line %d:%d\n", line[n], lineno, n); + } + break; + } + } + + /* STEP 2: Detect some certain start of line conditions */ + /* Skip over pre-processor lines */ + + if (line[indent] == '#') + { + continue; + } + + /* Check for the comment block indicating the beginning of functions. */ + + if (!bfunctions && ncomment > 0 && + (strcmp(line, " * Private Functions\n") == 0 || + strcmp(line, " * Public Functions\n") == 0)) + { + //fprintf(stderr, "Functions begin at line %d:%d\n", lineno, n); + bfunctions = true; + } + + /* Check for some kind of declaration. + * REVISIT: The following logic fails for any non-standard types. + * REVISIT: Terminator after keyword might not be a space. Might be + * a newline, for example. struct and unions are often unnamed, for + * example. + */ + + else if (strncmp(&line[indent], "auto ", 5) == 0 || + strncmp(&line[indent], "bool ", 5) == 0 || + strncmp(&line[indent], "char ", 5) == 0 || + strncmp(&line[indent], "CODE ", 5) == 0 || + strncmp(&line[indent], "const ", 6) == 0 || + strncmp(&line[indent], "double ", 7) == 0 || +// strncmp(&line[indent], "struct ", 7) == 0 || + strncmp(&line[indent], "struct", 6) == 0 || /* May be unnamed */ + strncmp(&line[indent], "enum ", 5) == 0 || + strncmp(&line[indent], "extern ", 7) == 0 || + strncmp(&line[indent], "EXTERN ", 7) == 0 || + strncmp(&line[indent], "FAR ", 4) == 0 || + strncmp(&line[indent], "float ", 6) == 0 || + strncmp(&line[indent], "int ", 4) == 0 || + strncmp(&line[indent], "int16_t ", 8) == 0 || + strncmp(&line[indent], "int32_t ", 8) == 0 || + strncmp(&line[indent], "long ", 5) == 0 || + strncmp(&line[indent], "off_t ", 6) == 0 || + strncmp(&line[indent], "register ", 9) == 0 || + strncmp(&line[indent], "short ", 6) == 0 || + strncmp(&line[indent], "signed ", 7) == 0 || + strncmp(&line[indent], "size_t ", 7) == 0 || + strncmp(&line[indent], "ssize_t ", 8) == 0 || + strncmp(&line[indent], "static ", 7) == 0 || + strncmp(&line[indent], "time_t ", 7) == 0 || + strncmp(&line[indent], "typedef ", 8) == 0 || + strncmp(&line[indent], "uint8_t ", 8) == 0 || + strncmp(&line[indent], "uint16_t ", 9) == 0 || + strncmp(&line[indent], "uint32_t ", 9) == 0 || +// strncmp(&line[indent], "union ", 6) == 0 || + strncmp(&line[indent], "union", 5) == 0 || /* May be unnamed */ + strncmp(&line[indent], "unsigned ", 9) == 0 || + strncmp(&line[indent], "void ", 5) == 0 || + strncmp(&line[indent], "volatile ", 9) == 0) + { + /* REVISIT: Also picks up function return types */ + /* REVISIT: Logic problem for nested data/function declarations */ + + if ((!bfunctions || nnest > 0) && declnest == 0) + { + declnest = 1; + } + } + + /* Check for a keyword indicating the beginning of a statement. + * REVISIT: This, obviously, will not detect statements that do not + * begin with a C keyword (such as assignement statements). + */ + + else if (strncmp(&line[indent], "break ", 6) == 0 || + strncmp(&line[indent], "case ", 5) == 0 || +// strncmp(&line[indent], "case ", 5) == 0 || /* Part of switch */ + strncmp(&line[indent], "continue ", 9) == 0 || +// strncmp(&line[indent], "default ", 8) == 0 || /* Part of switch */ + strncmp(&line[indent], "do ", 3) == 0 || + strncmp(&line[indent], "else ", 5) == 0 || + strncmp(&line[indent], "goto ", 5) == 0 || + strncmp(&line[indent], "if ", 3) == 0 || + strncmp(&line[indent], "return ", 7) == 0 || +// strncmp(&line[indent], "switch ", 7) == 0 || /* Doesn't follow pattern */ + strncmp(&line[indent], "while ", 6) == 0) + { + bstatm = true; + } + + /* Spacing works a little differently for and switch statements */ + + else if (strncmp(&line[indent], "for ", 4) == 0) + { + bfor = true; + bstatm = true; + } + else if (strncmp(&line[indent], "switch ", 7) == 0) + { + bswitch = true; + } + + /* Also check for C keywords with missing white space */ + + else if (strncmp(&line[indent], "do(", 3) == 0 || + strncmp(&line[indent], "if(", 3) == 0 || + strncmp(&line[indent], "while(", 6) == 0) + { + fprintf(stderr, "Missing whitespace after keyword at line %d:%d\n", lineno, n); + bstatm = true; + } + else if (strncmp(&line[indent], "for(", 4) == 0) + { + fprintf(stderr, "Missing whitespace after keyword at line %d:%d\n", lineno, n); + bfor = true; + bstatm = true; + } + else if (strncmp(&line[indent], "switch(", 7) == 0) + { + fprintf(stderr, "Missing whitespace after keyword at line %d:%d\n", lineno, n); + bswitch = true; + } + + /* STEP 3: Parse each character on the line */ + + bquote = false; + for (; line[n] != '\n' && line[n] != '\0'; n++) + { + if (line[n] == '/' && !bstring) + { + /* Check for start of a C comment */ + + if (line[n+1] == '*') + { + if (line[n+2] == '\n') + { + fprintf(stderr, "C comment on separate line at %d:%d\n", + lineno, n); + } + else if (line[n+2] != ' ' && line[n+2] != '*') + { + fprintf(stderr, + "Missing space after opening C comment at line %d:%d\n", + lineno, n); + } + + ncomment++; + n++; + continue; + } + + /* Check for end of a C comment */ + + else if (n > 0 && line[n-1] == '*') + { + if (n < 2) + { + fprintf(stderr, "Closing C comment not indented at line %d:%d\n", + lineno, n); + } + else if (line[n-2] != ' ' && line[n-2] != '*') + { + fprintf(stderr, + "Missing space before closing C comment at line %d:%d\n", + lineno, n); + } + +#if 0 + /* REVISIT: Generates false alarms when portions of an + * expression are commented out within the expression. + */ + + if (line[n+1] != '\n') + { + fprintf(stderr, + "Garbage on line after C comment at line %d:%d\n", + lineno, n); + } +#endif + + if (ncomment > 0) + { + ncomment--; + } + else + { + ncomment = 0; + fprintf(stderr, + "Closing without opening comment at line %d:%d\n", + lineno, n); + } + } + + /* Check for C++ style comments */ + + else if (line[n+1] == '/') + { + fprintf(stderr, "C++ style comment on at %d:%d\n", + lineno, n); + n++; + continue; + } + } + + /* Check for a string... ignore if we are in the middle of a + * comment. + */ + + if (ncomment == 0) + { + /* Backslash quoted charater */ + + if (line[n] == '\\') + { + bquote = true; + n++; + } + + /* Check for quoated characters: \" in string */ + + if (line[n] == '"' && !bquote) + { + bstring = !bstring; + } + + bquote = false; + } + + /* The reset of the line is only examined of we are in a comment + * or a string. + * + * REVISIT: Should still check for whitespace at the end of the + * line. + */ + + if (ncomment == 0 && !bstring) + { + switch (line[n]) + { + /* Handle logic nested with curly braces */ + + case '{': + { + if (n > indent) + { + if (declnest == 0) + { + fprintf(stderr, + "Left bracket not on separate line at %d:%d\n", + lineno, n); + } + } + else if (line[n+1] != '\n') + { + if (declnest == 0) + { + fprintf(stderr, + "Garbage follows left bracket at line %d:%d\n", + lineno, n); + } + } + + nnest++; + if (declnest > 0) + { + declnest++; + } + } + break; + + case '}': + { + if (nnest < 1) + { + fprintf(stderr, "Unmatched right brace at line %d:%d\n", lineno, n); + } + else + { + nnest--; + if (nnest < 1) + { + nnest = 0; + bswitch = false; + } + } + + if (declnest < 3) + { + declnest = 0; + } + else + { + declnest--; + } + + if (n > indent) + { + if (declnest == 0) + { + fprintf(stderr, + "Right bracket not on separate line at %d:%d\n", + lineno, n); + } + } + else if (line[n+1] != '\n' && + line[n+1] != ',' && + line[n+1] != ';') + { + /* One case where there may be garbage after the right + * bracket is, for example, when declaring a until or + * structure variable using an un-named union or + * structure. + */ + + if (prevdeclnest <= 0 || declnest > 0) + { + fprintf(stderr, + "Garbage follows right bracket at line %d:%d\n", + lineno, n); + } + } + } + break; + + /* Check for inappropriate space around parentheses */ + + case '(': + { + if (line[n+1] == ' ' /* && !bfor */) + { + fprintf(stderr, + "Space follows left parenthesis at line %d:%d\n", + lineno, n); + } + } + break; + + case ')': + { + /* Allow ')' as first thing on the line (n == indent) + * Allow "for (xx; xx; )" (bfor == true) + */ + + if (n > 0 && n != indent && line[n-1] == ' ' && !bfor) + { + fprintf(stderr, + "Space precedes right parenthesis at line %d:%d\n", + lineno, n); + } + } + break; + + /* Check for inappropriate space around square brackets */ + + case '[': + { + if (line[n+1] == ' ') + { + fprintf(stderr, + "Space follows left bracket at line %d:%d\n", + lineno, n); + } + } + break; + + case ']': + { + if (n > 0 && line[n-1] == ' ') + { + fprintf(stderr, + "Space precedes right bracket at line %d:%d\n", + lineno, n); + } + } + break; + + /* Semi-colon may terminate a declaration */ + + case ';': + { + if (!isspace((int)line[n+1])) + { + fprintf(stderr, "Missing whitespace after semicolon at line %d:%d\n", + lineno, n); + } + + /* Semicolon terminates a declaration/definition if there + * was no left curly brace (i.e., declnest is only 1). + */ + + if (declnest == 1) + { + declnest = 0; + } + } + break; + + /* Semi-colon may terminate a declaration */ + + case ',': + { + if (!isspace((int)line[n+1])) + { + fprintf(stderr, "Missing whitespace after comma at line %d:%d\n", + lineno, n); + } + } + break; + + case '\r': + { + fprintf(stderr, + "Carriage return detected at line %d:%d\n", + lineno, n); + } + break; + + /* Skip over character constants */ + + case '\'': + { + int endndx = n + 2; + + if (line[n+1] != '\n' && line[n+1] != '\0') + { + if (line[n+1] == '\\') + { + for (; + line[endndx] != '\n' && + line[endndx] != '\0' && + line[endndx] != '\''; + endndx++); + } + + n = endndx + 1; + } + } + break; + + /* Check for space at the end of the line */ + + case '\n': + { + if (n > 0 && isspace((int)line[n-1])) + { + fprintf(stderr, + "Dangling whitespace at the end of line %d:%d\n", + lineno, n); + } + } + break; + + /* Check for space around various operators */ + + case '-': + /* -> */ + + if (line[n+1] == '>') + { + n++; + break; + } + + case '+': + /* ++, -- */ + + if (line[n+1] == line[n]) + { + n++; + break; + } + + case '&': + /* && */ + + if (line[n] == '&' && line[n+1] == line[n]) + { + int curr; + int next; + + curr = n; + n++; + next = n + 1; + + if (line[curr-1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, curr); + } + + if (line[next] != ' ' && line[next] != '\n') + { + fprintf(stderr, + "Operator/assignment needs whitespace separation at line %d:%d\n", + lineno, curr); + } + + break; + } + + /* & OR &()*/ + + else if (isalpha((int)line[n+1]) || line[n+1] == '_' || line[n+1] == '(') + { + break; + } + + case '/': + { + if (line[n] == '/') + { + if (line[n-1] == '*') + { + n++; + break; + } + else if (line[n+1] == '/') + { + fprintf(stderr, "C++ style comment on at %d:%d\n", + lineno, n); + n++; + break; + } + } + } + + case '*': + { + /* *\/, ** */ + + if (line[n] == '*' && + (line[n+1] == '/' || + line[n+1] == '*')) + { + n++; + break; + } + + /* *, *() */ + + else if (isalpha((int)line[n+1]) || + line[n+1] == '_' || + line[n+1] == '(') + { + break; + } + + /* ( *) */ + + else if (line[n+1] == ')') + { + if (line[n-1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, n); + } + + break; + } + } + + case '%': + { + if (isalnum((int)line[n+1])) + { + break; + } + } + + case '<': + case '>': + case '|': + case '^': + case '=': + { + int curr; + int next; + + curr = n; + if (line[curr-1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, curr); + } + + next = n+1; + + /* <<, >>, <<=, >>= */ + + if (line[curr] == '>' || line[curr] == '<') + { + if (line[next] == line[curr]) + { + next++; + n++; + } + + if (line[next] == '=') + { + next++; + n++; + } + } + else if (line[next] == '=' || line[next] == line[n]) + { + next++; + n++; + } + + if (line[curr] != '-' && line[next] != ' ' && line[next] != '\n') + { + fprintf(stderr, + "Operator/assignment needs whitespace separation at line %d:%d\n", + lineno, curr); + } + } + break; + + case '~': + case '!': + { + int curr; + int next; + + curr = n; + next = n + 1; + if (line[next] == '=' || line[next] == line[n]) + { + next++; + n++; + + if (line[next] != ' ' && line[next] != '\n') + { + fprintf(stderr, + "Operator/assignment needs whitespace separation at line %d:%d\n", + lineno, curr); + } + } + + if (line[curr-1] != ' ' && line[curr-1] != '(') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, curr); + } + } + break; + + default: + break; + } + } + } + + /* STEP 4: Check alignment */ + + /* Within a comment block, we need only check on the alignment of the + * comment. + */ + + if ((ncomment > 0 || prevncomment > 0) && !bstring) + { + if (indent == 0 && line[0] != '/') + { + fprintf(stderr, "No indentation line %d:%d\n", + lineno, indent); + } + else if (indent == 1 && line[0] == ' ' && line[1] == '*') + { + /* Good indentation */ + } + else if (indent > 0 && line[indent] == '\n') + { + fprintf(stderr, "Whitespace on blank line at line %d:%d\n", + lineno, indent); + } + else if (indent > 0 && indent < 2) + { + fprintf(stderr, "Insufficient indentation line %d:%d\n", + lineno, indent); + } + else if (indent > 0 && !bswitch) + { + if (line[indent] == '/') + { + if ((indent & 3) != 2) + { + fprintf(stderr, + "Bad comment alignment at line %d:%d\n", + lineno, indent); + } + + /* REVISIT: This screws up in cases where there is C code, + * followed by a comment that continues on the next line. + */ + + else if (line[indent+1] != '*') + { + fprintf(stderr, + "Missing asterisk in comment at line %d:%d\n", + lineno, indent); + } + } + else if (line[indent] == '*') + { + /* REVISIT: Generates false alarms on comments at the end of + * the line if there is nothing preceding (such as the aligned + * comments with a structure field definition). So disabled for + * comments before beginning of function definitions. + */ + + if ((indent & 3) != 3 && bfunctions && declnest == 0) + { + fprintf(stderr, + "Bad comment block alignment at line %d:%d\n", + lineno, indent); + } + + if (line[indent+1] != ' ' && + line[indent+1] != '\n' && + line[indent+1] != '/') + { + fprintf(stderr, + "Invalid character after asterisk in comment block at line %d:%d\n", + lineno, indent); + } + } + + /* If this is not the line containing the comment start, then this + * line should begin with '*' + */ + + else if (prevncomment > 0) + { + fprintf(stderr, "Missing asterisk in comment block at line %d:%d\n", + lineno, indent); + } + } + } + + /* Check for various alignment outside of the comment block */ + + else if ((ncomment > 0 || prevncomment > 0) && !bstring) + { + if (indent == 0 && strchr("\n#{}", line[0]) == NULL) + { + /* Ignore if we are at global scope */ + + if (prevnest > 0) + { + bool blabel = false; + + if (isalpha((int)line[indent])) + { + for (i = indent + 1; isalnum((int)line[i]) || line[i] == '_'; i++); + blabel = (line[i] == ':'); + } + + if (!blabel) + { + fprintf(stderr, "No indentation line %d:%d\n", + lineno, indent); + } + } + } + else if (indent == 1 && line[0] == ' ' && line[1] == '*') + { + /* Good indentation */ + } + else if (indent > 0 && line[indent] == '\n') + { + fprintf(stderr, "Whitespace on blank line at line %d:%d\n", + lineno, indent); + } + else if (indent > 0 && indent < 2) + { + fprintf(stderr, "Insufficient indentation line %d:%d\n", + lineno, indent); + } + else if (line[indent] == '{') + { + /* REVISIT: False alarms in data initializers and switch statements */ + + if ((indent & 3) != 0 && !bswitch && declnest == 0) + { + fprintf(stderr, "Bad left brace alignment at line %d:%d\n", + lineno, indent); + } + } + else if (line[indent] == '}') + { + /* REVISIT: False alarms in data initializers and switch statements */ + + if ((indent & 3) != 0 && !bswitch && prevdeclnest == 0) + { + fprintf(stderr, "Bad right brace alignment at line %d:%d\n", + lineno, indent); + } + } + else if (indent > 0) + { + /* REVISIT: Generates false alarms when a statement continues on + * the next line. The bstatm check limits to lines beginnnig with + * C keywords. + * REVISIT: The bstatm check will not detect statements that + * do not begin with a C keyword (such as assignement statements). + * REVISIT: Generates false alarms on comments at the end of + * the line if there is nothing preceding (such as the aligned + * comments with a structure field definition). So disabled for + * comments before beginning of function definitions. + */ + + if ((bstatm || /* Begins with C keyword */ + (line[indent] == '/' && bfunctions)) && /* Comment in functions */ + !bswitch && /* Not in a switch */ + declnest == 0) /* Not a data definition */ + { + if ((indent & 3) != 2) + { + fprintf(stderr, "Bad alignment at line %d:%d\n", + lineno, indent); + } + } + + /* Crazy cases. There should be no small odd alignements + * outside of comment/string. Odd alignments are possible + * on continued lines, but not if they are small. + */ + + else if (indent == 1 || indent == 3) + { + fprintf(stderr, "Small odd alignment at line %d:%d\n", + lineno, indent); + } + } + } + } + + if (ncomment > 0 || bstring) + { + fprintf(stderr, "In a comment/string at end of file\n"); + } + + fclose(instream); + return 0; +} -- GitLab From 1e6ffe7677fbb96d8347091616a474fec6164a66 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 14:21:12 -0600 Subject: [PATCH 200/858] TMPFS update --- fs/tmpfs/fs_tmpfs.c | 326 +++++++++++++++++++++++++++++++------- fs/tmpfs/fs_tmpfs.h | 4 +- include/nuttx/fs/dirent.h | 16 ++ 3 files changed, 290 insertions(+), 56 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 9a08621fe9..dd491e996b 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -52,6 +52,17 @@ * Pre-processor Definitions ****************************************************************************/ +#define tmpfs_unlock(fs) (sem_post(&fs->tfs_exclsem)) + +#define tmpfs_lock_file(tfo) \ + (tmpfs_lock_object((FAR struct tmpfs_object_s *)tfo)) +#define tmpfs_lock_directory(tdo) \ + (tmpfs_lock_object((FAR struct tmpfs_object_s *)tdo)) + +#define tmpfs_unlock_object(to) (sem_post(&to->to_exclsem)) +#define tmpfs_unlock_file(tfo) (sem_post(&tfo->tfo_exclsem)) +#define tmpfs_unlock_directory(tdo) (sem_post(&tdo->tdo_exclsem)) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -62,13 +73,7 @@ /* TMPFS helpers */ static void tmpfs_lock(FAR struct tmpfs_s *fs); -#define tmpfs_unlock(fs) (sem_post(&fs->r_exclsem)) - static void tmpfs_lock_object(FAR struct tmpfs_object_s *to); -#define tmpfs_unlock_object(to) (sem_post(&to->to_exclsem)) -#define tmpfs_unlock_file(tfo) (sem_post(&tfo->tfo_exclsem)) -#define tmpfs_unlock_directory(tdo) (sem_post(&tdo->tdo_exclsem)) - static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, unsigned int nentries); static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, @@ -79,8 +84,9 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, FAR const char *name); static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, FAR struct tmpfs_object_s *to, FAR const char *name); -static int tmpfs_create_file(FAR struct tmpfs_directory_s *tdo, - FAR struct tmpfs_file_s **tfo); +static FAR struct tmpfs_file_s *tmpfs_alloc_file(void); +static int tmpfs_create_file(FAR struct tmpfs_s *fs, + FAR const char *relpath, FAR struct tmpfs_file_s **tfo); static int tmpfs_find_object(FAR struct tmpfs_s *fs, FAR const char *relpath, FAR struct tmpfs_object_s **object, FAR struct tmpfs_directory_s **parent); @@ -167,7 +173,7 @@ static void tmpfs_lock(FAR struct tmpfs_s *fs) { int ret; - while ((ret = sem_wait(&fs->r_exclsem)) < 0) + while ((ret = sem_wait(&fs->tfs_exclsem)) < 0) { DEBUGASSERT(errno == EINTR) } @@ -407,35 +413,129 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, } /**************************************************************************** - * name: tmpfs_create_file + * name: tmpfs_alloc_file ****************************************************************************/ -static int tmpfs_create_file(FAR struct tmpfs_directory_s *tdo, - FAR struct tmpfs_file_s **tfo) +static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) { - FAR struct tmpfs_file_s *newtfo; + FAR struct tmpfs_file_s *tfo; size_t allocsize; /* Create a new zero length file object */ allocsize = SIZEOF_TMPFS_FILE(FS_TMPFS_FILE_ALLOCGUARD); - newtfo = (FAR struct tmpfs_file_s *)kmm_malloc(allocsize); + tfo = (FAR struct tmpfs_file_s *)kmm_malloc(allocsize); if (nenewtfowfile == NULL) { - return -ENOMEM; + return NULL; } /* Initialize the new file object */ - newtfo->tfo_alloc = allocsize; - newtfo->tfo_type = TMPFS_REGULAR; - newtfo->tfo_refs = 1; - newtfo->tfo_flags = 0; - newtfo->tfo_size = 0; - sem_init(&newtfo->tfo_exclsem, 0, 0); + tfo->tfo_alloc = allocsize; + tfo->tfo_type = TMPFS_REGULAR; + tfo->tfo_refs = 1; + tfo->tfo_flags = 0; + tfo->tfo_size = 0; + sem_init(&tfo->tfo_exclsem, 0, 0); + + return tfo; +} + +/**************************************************************************** + * name: tmpfs_create_file + ****************************************************************************/ + +static int tmpfs_create_file(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_file_s **tfo) +{ + FAR struct tmpfs_directory_s *tdo; + FAR struct tmpfs_file_s *newtfo; + FAR char *copy; + FAR char *name; + + /* Duplicate the path variable so that we can modify it */ + + copy = strdup(relpath); + if (copy == NULL) + { + return -ENOMEM; + } + /* Separate the path into the file name and the path to the parent + * directory. + */ + + name = strrchr(copy, '/'); + if (name == NULL) + { + /* No subdirectories... the root directory */ + + name = copy; + tdo = fs->tfs_root; + } + else + { + /* Terminate the parent directly path */ + + *name++ = '\0'; + + /* Locate the parent directory that should contain this name */ + + ret = tmpfs_find_directory(fs, copy, &tdo, NULL); + if (ret < 0) + { + goto errout_with_copy; + } + } + + /* Verify that no object of this name already exists in the directory */ + + ret = tmpfs_find_dirent(tdo, name); + if (ret != -ENOENT) + { + /* Something with this name already exists n the directory */ + + if (ret >= 0) + { + ret = -EEXIST; + goto errout_with_copy; + } + } + + /* Allocate an empty file */ + + newtfo = tmpfs_alloc_file(); + if (newtfo == NULL) + { + ret = -ENOMEM: + goto errout_with_copy; + } + + /* Then add the new, empty file to the directory */ + + ret = tmpfs_add_dirent(tdo, ()FAR struct tmpfs_object_s *)newtfo, name); + if (ret < 0) + { + goto errout_with_file; + } + + /* Free the copy of the relpath and return success */ + + kmm_free(copy); *tfo = newtfo; return OK; + +/* Error exits */ + +errout_with_file: + sem_destroy(&tfo->tfo_exclsem); + kmm_free(tfo); + +errout_with_copy: + kmm_free(copy); + return ret; } /**************************************************************************** @@ -468,7 +568,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, /* Traverse the file system for any object with the matching name */ to = (FAR struct tmpfs_object_s)fs->root; - next_rdo = fs->root; + next_rdo = fs->tfs_root; for (segment = strtok_r(copy, "/", &tkptr); segment != NULL; @@ -652,6 +752,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, FAR struct tmpfs_file_s *tfo; int ret; + fvdbg("filep: %p", filep); DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); /* Get the mountpoint inode reference from the file structure and the @@ -667,7 +768,11 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, tmpfs_lock(fs); - /* Find the file allocation associated with this relative path. + /* Skip over any leading directory separators (shouldn't be any) */ + + for (; *relpath == '/'; relpath++); + + /* Find the file object associated with this relative path. * If successful, this action will lock both the parent directory and * the file object, adding one to the reference count of both. * In the event that -ENOENT, there will still be a reference and @@ -686,7 +791,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { /* Already exists -- can't create it exclusively */ - + ret = -EEXIST; goto errout_with_filelock; } @@ -724,25 +829,22 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, else if (ret == -ENOENT) { /* The file does not exist. Were we asked to create it? */ - + if ((oflags & O_CREAT) == 0) { /* No.. then we fail with -ENOENT */ - + ret = -ENOENT; goto errout_with_fslock; } - + /* Yes.. create the file object. */ - - ret = tmpfs_create_file(&tfo); + + ret = tmpfs_create_file(fs, relpath, &tfo); if (ret < 0) { goto errout_with_fslock; } - - /* Insert the file object into the directory structure */ -#warning Missing logic. } /* Some other error occurred */ @@ -781,6 +883,7 @@ static int tmpfs_close(FAR struct file *filep) { FAR struct tmpfs_file_s *tfo; + fvdbg("filep: %p", filep); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -831,7 +934,11 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, { FAR struct tmpfs_file_s *tfo; ssize_t nread; + off_t startpos; + off_t endpos; + fvdbg("filep: %p buffer: %p buflen: %lu", + filep, buffer, (unsigned long)buflen); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -839,13 +946,28 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, tfo = filep->f_priv; /* Get exclusive access to the file */ -#warning Missing logic - /* Handle attempts to read beyond the end of the file */ -#warning Missing logic + + tmpfs_lock_file(tfo); + + /* Handle attempts to read beyond the end of the file. */ + + startpos = filep->f_pos; + nread = buflen; + endpos = startpos + buflen; + + if (endpos > tfo->tfo_size) + { + endpos = tfo->tfo_size; + nread = endpos - startpos; + } + /* Copy data from the memory object to the user buffer */ -#warning Missing logic + + memcpy(buffer, &tfo->tfo_data, nread) + /* Release the lock on the file */ -#warning Missing logic + + tmpfs_file_unlock return nread; } @@ -859,7 +981,12 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, { FAR struct tmpfs_file_s *tfo; ssize_t nwritten; + off_t startpos; + off_t endpos; + int ret; + fvdbg("filep: %p buffer: %p buflen: %lu", + filep, buffer, (unsigned long)buflen); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -867,17 +994,38 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, tfo = filep->f_priv; /* Get exclusive access to the file */ -#warning Missing logic - /* if the write would go past the end of the file, then extend the file - * by reallocating the in-memory file object - */ -#warning Missing logic - /* Copy data from the user buffer to the memory object */ -#warning Missing logic + + tmpfs_lock_file(tfo); + + /* Handle attempts to read beyond the end of the file */ + + startpos = filep->f_pos; + nwritten = buflen; + endpos = startpos + buflen; + + if (endpos > tfo->tfo_size) + { + /* Reallocate the file to handle the write past the end of the file. */ + + ret = tmpfs_realloc_file(tfo, (size_t)endpos); + if (ret < 0) + { + goto errout_with_lock; + } + } + + /* Copy data from the memory object to the user buffer */ + + memcpy(&tfo->tfo_data, buffer, nwritten) + /* Release the lock on the file */ -#warning Missing logic + tmpfs_file_unlock(tfo); return nwritten; + +errout_with_lock: + tmpfs_file_unlock(tfo); + return (ssize_t)ret; } /**************************************************************************** @@ -889,6 +1037,7 @@ static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence) FAR struct tmpfs_file_s *tfo; off_t position; + fvdbg("filep: %p", filep); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -948,8 +1097,7 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) FAR struct tmpfs_file_s *tfo; FAR void **ppv = (FAR void**)arg; - fvdbg("cmd: %d arg: %08lx\n", cmd, arg); - + fvdbg("filep: %p cmd: %d arg: %08lx\n", filep, cmd, arg); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -981,7 +1129,7 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) { FAR struct tmpfs_file_s *tfo; - + fvdbg("Dup %p->%p\n", oldp, newp); DEBUGASSERT(oldp->f_priv != NULL && oldp->f_inode != NULL != NULL && @@ -993,14 +1141,16 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) tfo = oldp->f_inode->i_private; DEBUGASSERT(tfo != NULL); - /* Get exclusive access to the file */ -#warning Missing logic /* Increment the reference count */ -#warning Missing logic - /* Unlock the file. */ -#warning Missing logic - /* Save a copy of the file object as the dup'ed file */ + tmpfs_lock_file(tfo); + tfo->tfo_refs++; + tmpfs_lunock_file(tfo); + + /* Save a copy of the file object as the dup'ed file. This + * simple implementation does not many any per-open data + * structures so there is not really much to the dup operation. + */ oldp->f_inode->i_private = tfo; return OK; @@ -1013,6 +1163,45 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, FAR struct fs_dirent_s *dir) { + FAR struct tmpfs_s *fs; + FAR struct tmpfs_directory_s *tdo; + int ret; + + fvdbg("mountpt: %p relpath: %s dir: %p", + mountpt, relpath, dir); + DEBUGASSERT(mountpt != NULL && relpath != NULL && dir != NULL); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + DEBUGASSERT(fs != NULL); + + /* Get exclusive access to the file system */ + + tmpfs_lock(fs); + + /* Skip over any leading directory separators (shouldn't be any) */ + + for (; *relpath == '/'; relpath++); + + /* Find the directory object associated with this relative path. + * If successful, this action will lock both the parent directory and + * the file object, adding one to the reference count of both. + * In the event that -ENOENT, there will still be a reference and + * lock on the returned directory. + */ + + ret = tmpfs_find_directory(fs, relpath, &tdo, NULL); + if (ret >= 0) + { + dir->u.tmpfs.tf_tdo = tdo; + dir->u.tmpfs.tf_index = 0; + } + + /* Release the lock on the file system and return the result */ + + tmpfs_unlock(fs); + return ret; } /**************************************************************************** @@ -1022,6 +1211,22 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, static int tmpfs_closedir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { + FAR struct tmpfs_directory_s *tdo; + + fvdbg("mountpt: %p dir: %p", mountpt, dir); + DEBUGASSERT(mountpt != NULL && dir != NULL); + + /* Get the directory structure from the dir argument */ + + tdo = dir->u.tmpfs.tf_tdo; + DEBUGASSERT(tdo != NULL); + + /* Decrement the reference count on the directory object */ + + tmpfs_lock_directory(tdo); + tdo->tdo_refs--; + tmpfs_unlock_directory(tdo); + return OK; } /**************************************************************************** @@ -1031,6 +1236,7 @@ static int tmpfs_closedir(FAR struct inode *mountpt, static int tmpfs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { +#warning Missing Logic } /**************************************************************************** @@ -1040,6 +1246,16 @@ static int tmpfs_readdir(FAR struct inode *mountpt, static int tmpfs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { + FAR struct tmpfs_directory_s *tdo; + int ret; + + fvdbg("mountpt: %p dir: %p", mountpt, dir); + DEBUGASSERT(mountpt != NULL && dir != NULL); + + /* Set the readdir index to zero */ + + dir->u.tmpfs.tf_index = 0; + return OK; } /**************************************************************************** @@ -1049,6 +1265,7 @@ static int tmpfs_rewinddir(FAR struct inode *mountpt, static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, FAR void **handle) { +#warning Missing Logic } /**************************************************************************** @@ -1058,6 +1275,7 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { +#warning Missing Logic } /**************************************************************************** diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index 79cc8011c8..1359f50f6f 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -137,9 +137,9 @@ struct tmpfs_s { /* The root directory */ - FAR struct tmpfs_directory_s *r_root; + FAR struct tmpfs_directory_s *tfs_root; - sem_t r_exclsem; /* Supports exclusive access to the file system */ + sem_t tfs_exclsem; /* Supports exclusive access to the file system */ }; /**************************************************************************** diff --git a/include/nuttx/fs/dirent.h b/include/nuttx/fs/dirent.h index 645a2351f6..d7b91a80ec 100644 --- a/include/nuttx/fs/dirent.h +++ b/include/nuttx/fs/dirent.h @@ -102,6 +102,19 @@ struct fs_romfsdir_s }; #endif /* CONFIG_FS_ROMFS */ +#ifdef CONFIG_FS_TMPFS +/* For TMPFS, we need the directory object and an index into the directory + * entries. + */ + +struct tmpfs_directory_s; /* Forward reference */ +struct fs_tmpfsdir_s +{ + FAR struct tmpfs_directory_s *tf_tdo; /* Directory being enumerated */ + unsigned int tf_index; /* Directory index */ +}; +#endif /* CONFIG_FS_TMPFS */ + #ifdef CONFIG_FS_BINFS /* The apps/ pseudo bin/ directory. The state value is simply an index */ @@ -209,6 +222,9 @@ struct fs_dirent_s #ifdef CONFIG_FS_ROMFS struct fs_romfsdir_s romfs; #endif +#ifdef CONFIG_FS_TMPFS + struct fs_tmpfsdir_s tmpfs; +#endif #ifdef CONFIG_FS_BINFS struct fs_binfsdir_s binfs; #endif -- GitLab From 6209c512062a254575531e52b97c65cd53b8ae8d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 15:10:04 -0600 Subject: [PATCH 201/858] net/: More clean-up of spacing/alignment issues --- fs/tmpfs/fs_tmpfs.c | 2 +- net/arp/arp_arpin.c | 2 +- net/arp/arp_dump.c | 2 +- net/arp/arp_out.c | 19 +++- net/devif/ipv4_input.c | 192 +++++++++++++++++---------------- net/devif/ipv6_input.c | 10 +- net/icmp/icmp_ping.c | 2 +- net/icmpv6/icmpv6_autoconfig.c | 8 +- net/icmpv6/icmpv6_notify.c | 6 +- net/icmpv6/icmpv6_ping.c | 2 +- net/icmpv6/icmpv6_rnotify.c | 6 +- net/icmpv6/icmpv6_solicit.c | 2 +- net/igmp/igmp_group.c | 6 +- net/igmp/igmp_input.c | 4 +- net/igmp/igmp_send.c | 2 +- net/local/local_accept.c | 2 +- net/local/local_connect.c | 4 +- net/local/local_recvfrom.c | 6 +- net/local/local_sendto.c | 2 +- net/neighbor/neighbor_out.c | 11 +- net/netdev/netdev_findbyaddr.c | 20 ++-- net/netdev/netdev_ioctl.c | 8 +- net/netdev/netdev_register.c | 2 +- net/pkt/pkt_poll.c | 2 +- net/pkt/pkt_send.c | 2 +- net/route/net_delroute.c | 4 +- net/route/net_router.c | 4 +- net/route/netdev_router.c | 4 +- net/socket/bind.c | 10 +- net/socket/connect.c | 4 +- net/socket/getsockname.c | 16 +-- net/socket/getsockopt.c | 10 +- net/socket/net_close.c | 20 ++-- net/socket/net_monitor.c | 6 +- net/socket/net_sendfile.c | 6 +- net/socket/net_sockets.c | 2 +- net/socket/recvfrom.c | 23 ++-- net/socket/setsockopt.c | 2 +- net/tcp/tcp_accept.c | 4 +- net/tcp/tcp_backlog.c | 131 +++++++++++----------- net/tcp/tcp_input.c | 7 +- net/tcp/tcp_send_buffered.c | 16 +-- net/tcp/tcp_send_unbuffered.c | 16 +-- net/udp/udp_callback.c | 4 +- net/udp/udp_conn.c | 2 +- net/udp/udp_psock_sendto.c | 10 +- net/udp/udp_send.c | 8 +- net/utils/net_chksum.c | 2 +- 48 files changed, 334 insertions(+), 301 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index dd491e996b..eb7ed448b9 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -805,7 +805,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, * access is ignored. */ - if ((oflags & (O_TRUNC|O_WRONLY)) == (O_TRUNC|O_WRONLY)) + if ((oflags & (O_TRUNC | O_WRONLY)) == (O_TRUNC | O_WRONLY)) { /* Truncate the file to zero length (if it is not already * zero length) diff --git a/net/arp/arp_arpin.c b/net/arp/arp_arpin.c index a94bbb9fa0..feb2dc0a06 100644 --- a/net/arp/arp_arpin.c +++ b/net/arp/arp_arpin.c @@ -116,7 +116,7 @@ void arp_arpin(FAR struct net_driver_s *dev) dev->d_len = 0; ipaddr = net_ip4addr_conv32(arp->ah_dipaddr); - switch(arp->ah_opcode) + switch (arp->ah_opcode) { case HTONS(ARP_REQUEST): nllvdbg("ARP request for IP %04lx\n", (long)ipaddr); diff --git a/net/arp/arp_dump.c b/net/arp/arp_dump.c index 9c796863f7..739c280837 100644 --- a/net/arp/arp_dump.c +++ b/net/arp/arp_dump.c @@ -86,7 +86,7 @@ void arp_dump(FAR struct arp_hdr_s *arp) { nlldbg(" HW type: %04x Protocol: %04x\n", - arp->ah_hwtype, arp->ah_protocol);\ + arp->ah_hwtype, arp->ah_protocol); nlldbg(" HW len: %02x Proto len: %02x Operation: %04x\n", arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode); nlldbg(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", diff --git a/net/arp/arp_out.c b/net/arp/arp_out.c index a815715c63..daa71b2ac4 100644 --- a/net/arp/arp_out.c +++ b/net/arp/arp_out.c @@ -73,8 +73,16 @@ /* Support for broadcast address */ static const struct ether_addr g_broadcast_ethaddr = - {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static const uint16_t g_broadcast_ipaddr[2] = {0xffff, 0xffff}; +{ + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + } +}; + +static const uint16_t g_broadcast_ipaddr[2] = +{ + 0xffff, 0xffff +}; /* Support for IGMP multicast addresses. * @@ -93,7 +101,10 @@ static const uint16_t g_broadcast_ipaddr[2] = {0xffff, 0xffff}; */ #ifdef CONFIG_NET_IGMP -static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e}; +static const uint8_t g_multicast_ethaddr[3] = +{ + 0x01, 0x00, 0x5e +}; #endif /**************************************************************************** @@ -186,7 +197,7 @@ void arp_out(FAR struct net_driver_s *dev) * last three bytes of the IP address. */ - FAR const uint8_t *ip = ((uint8_t*)pip->eh_destipaddr) + 1; + FAR const uint8_t *ip = ((FAR uint8_t *)pip->eh_destipaddr) + 1; memcpy(peth->dest, g_multicast_ethaddr, 3); memcpy(&peth->dest[3], ip, 3); } diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index 919471a3e5..cb90e462e1 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -130,7 +130,9 @@ static uint8_t g_reassembly_buffer[TCP_REASS_BUFSIZE]; static uint8_t g_reassembly_bitmap[TCP_REASS_BUFSIZE / (8 * 8)]; static const uint8_t g_bitmap_bits[8] = - {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; +{ + 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 +}; static uint16_t g_reassembly_len; static uint8_t g_reassembly_flags; @@ -202,93 +204,97 @@ static uint8_t devif_reassembly(void) memcpy(&g_reassembly_buffer[IPv4_HDRLEN + offset], (char *)pbuf + (int)((pbuf->vhl & 0x0f) * 4), len); - /* Update the bitmap. */ - - if (offset / (8 * 8) == (offset + len) / (8 * 8)) - { - /* If the two endpoints are in the same byte, we only update that byte. */ - - g_reassembly_bitmap[offset / (8 * 8)] |= - g_bitmap_bits[(offset / 8 ) & 7] & ~g_bitmap_bits[((offset + len) / 8 ) & 7]; - - } - else - { - /* If the two endpoints are in different bytes, we update the bytes - * in the endpoints and fill the stuff inbetween with 0xff. - */ - - g_reassembly_bitmap[offset / (8 * 8)] |= g_bitmap_bits[(offset / 8 ) & 7]; - for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) - { - g_reassembly_bitmap[i] = 0xff; - } - - g_reassembly_bitmap[(offset + len) / (8 * 8)] |= - ~g_bitmap_bits[((offset + len) / 8 ) & 7]; - } - - /* If this fragment has the More Fragments flag set to zero, we know that - * this is the last fragment, so we can calculate the size of the entire - * packet. We also set the IP_REASS_FLAG_LASTFRAG flag to indicate that - * we have received the final fragment. - */ - - if ((pbuf->ipoffset[0] & IP_MF) == 0) - { - g_reassembly_flags |= TCP_REASS_LASTFRAG; - g_reassembly_len = offset + len; - } - - /* Finally, we check if we have a full packet in the buffer. We do this - * by checking if we have the last fragment and if all bits in the bitmap - * are set. - */ - - if (g_reassembly_flags & TCP_REASS_LASTFRAG) - { - /* Check all bytes up to and including all but the last byte in - * the bitmap. - */ - - for (i = 0; i < g_reassembly_len / (8 * 8) - 1; ++i) - { - if (g_reassembly_bitmap[i] != 0xff) - { - goto nullreturn; - } - } - - /* Check the last byte in the bitmap. It should contain just the - * right amount of bits. - */ - - if (g_reassembly_bitmap[g_reassembly_len / (8 * 8)] != (uint8_t)~g_bitmap_bits[g_reassembly_len / 8 & 7]) - { - goto nullreturn; - } - - /* If we have come this far, we have a full packet in the buffer, - * so we allocate a pbuf and copy the packet into it. We also reset - * the timer. - */ - - g_reassembly_timer = 0; - memcpy(pbuf, pfbuf, g_reassembly_len); - - /* Pretend to be a "normal" (i.e., not fragmented) IP packet from - * now on. - */ - - pbuf->ipoffset[0] = pbuf->ipoffset[1] = 0; - pbuf->len[0] = g_reassembly_len >> 8; - pbuf->len[1] = g_reassembly_len & 0xff; - pbuf->ipchksum = 0; - pbuf->ipchksum = ~(ipv4_chksum(dev)); - - return g_reassembly_len; - } - } + /* Update the bitmap. */ + + if (offset / (8 * 8) == (offset + len) / (8 * 8)) + { + /* If the two endpoints are in the same byte, we only update that byte. */ + + g_reassembly_bitmap[offset / (8 * 8)] |= + g_bitmap_bits[(offset / 8) & 7] & + ~g_bitmap_bits[((offset + len) / 8) & 7]; + + } + else + { + /* If the two endpoints are in different bytes, we update the bytes + * in the endpoints and fill the stuff inbetween with 0xff. + */ + + g_reassembly_bitmap[offset / (8 * 8)] |= + g_bitmap_bits[(offset / 8) & 7]; + + for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) + { + g_reassembly_bitmap[i] = 0xff; + } + + g_reassembly_bitmap[(offset + len) / (8 * 8)] |= + ~g_bitmap_bits[((offset + len) / 8) & 7]; + } + + /* If this fragment has the More Fragments flag set to zero, we know that + * this is the last fragment, so we can calculate the size of the entire + * packet. We also set the IP_REASS_FLAG_LASTFRAG flag to indicate that + * we have received the final fragment. + */ + + if ((pbuf->ipoffset[0] & IP_MF) == 0) + { + g_reassembly_flags |= TCP_REASS_LASTFRAG; + g_reassembly_len = offset + len; + } + + /* Finally, we check if we have a full packet in the buffer. We do this + * by checking if we have the last fragment and if all bits in the bitmap + * are set. + */ + + if (g_reassembly_flags & TCP_REASS_LASTFRAG) + { + /* Check all bytes up to and including all but the last byte in + * the bitmap. + */ + + for (i = 0; i < g_reassembly_len / (8 * 8) - 1; ++i) + { + if (g_reassembly_bitmap[i] != 0xff) + { + goto nullreturn; + } + } + + /* Check the last byte in the bitmap. It should contain just the + * right amount of bits. + */ + + if (g_reassembly_bitmap[g_reassembly_len / (8 * 8)] != + (uint8_t)~g_bitmap_bits[g_reassembly_len / 8 & 7]) + { + goto nullreturn; + } + + /* If we have come this far, we have a full packet in the buffer, + * so we allocate a pbuf and copy the packet into it. We also reset + * the timer. + */ + + g_reassembly_timer = 0; + memcpy(pbuf, pfbuf, g_reassembly_len); + + /* Pretend to be a "normal" (i.e., not fragmented) IP packet from + * now on. + */ + + pbuf->ipoffset[0] = pbuf->ipoffset[1] = 0; + pbuf->len[0] = g_reassembly_len >> 8; + pbuf->len[1] = g_reassembly_len & 0xff; + pbuf->ipchksum = 0; + pbuf->ipchksum = ~(ipv4_chksum(dev)); + + return g_reassembly_len; + } + } nullreturn: return 0; @@ -379,11 +385,11 @@ int ipv4_input(FAR struct net_driver_s *dev) } #if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) - /* If IP broadcast support is configured, we check for a broadcast - * UDP packet, which may be destined to us (even if there is no IP - * address yet assigned to the device as is the case when we are - * negotiating over DHCP for an address). - */ + /* If IP broadcast support is configured, we check for a broadcast + * UDP packet, which may be destined to us (even if there is no IP + * address yet assigned to the device as is the case when we are + * negotiating over DHCP for an address). + */ if (pbuf->proto == IP_PROTO_UDP && net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr), diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 7b878ac4ab..19fdea6482 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -191,11 +191,11 @@ int ipv6_input(FAR struct net_driver_s *dev) goto drop; } - /* If IP broadcast support is configured, we check for a broadcast - * UDP packet, which may be destined to us (even if there is no IP - * address yet assigned to the device as is the case when we are - * negotiating over DHCP for an address). - */ + /* If IP broadcast support is configured, we check for a broadcast + * UDP packet, which may be destined to us (even if there is no IP + * address yet assigned to the device as is the case when we are + * negotiating over DHCP for an address). + */ #if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) if (ipv6->proto == IP_PROTO_UDP && diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 41bc604dfd..767bceec16 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -390,7 +390,7 @@ int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen, if (state.png_cb) { state.png_cb->flags = (ICMP_POLL | ICMP_ECHOREPLY | NETDEV_DOWN); - state.png_cb->priv = (void*)&state; + state.png_cb->priv = (FAR void *)&state; state.png_cb->event = ping_interrupt; state.png_result = -EINTR; /* Assume sem-wait interrupted by signal */ diff --git a/net/icmpv6/icmpv6_autoconfig.c b/net/icmpv6/icmpv6_autoconfig.c index add6e328b5..7899f07451 100644 --- a/net/icmpv6/icmpv6_autoconfig.c +++ b/net/icmpv6/icmpv6_autoconfig.c @@ -398,7 +398,7 @@ int icmpv6_autoconfig(FAR struct net_driver_s *dev) */ lladdr[0] = HTONS(0xfe80); /* 10-bit address + 6 zeroes */ - memset(&lladdr[1], 0, 4* sizeof(uint16_t)); /* 64 more zeroes */ + memset(&lladdr[1], 0, 4 * sizeof(uint16_t)); /* 64 more zeroes */ memcpy(&lladdr[5], dev->d_mac.ether_addr_octet, sizeof(struct ether_addr)); /* 48-bit Ethernet address */ @@ -546,9 +546,9 @@ int icmpv6_autoconfig(FAR struct net_driver_s *dev) * first step. */ - /* On success, the new address was already set (in icmpv_rnotify()). We - * need only to bring the network back to the up state and return success. - */ + /* On success, the new address was already set (in icmpv_rnotify()). We + * need only to bring the network back to the up state and return success. + */ netdev_ifup(dev); net_unlock(save); diff --git a/net/icmpv6/icmpv6_notify.c b/net/icmpv6/icmpv6_notify.c index 2302b3b2a3..07191a5342 100644 --- a/net/icmpv6/icmpv6_notify.c +++ b/net/icmpv6/icmpv6_notify.c @@ -197,9 +197,9 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify, abstime.tv_nsec -= 1000000000; } - /* REVISIT: If net_timedwait() is awakened with signal, we will return - * the wrong error code. - */ + /* REVISIT: If net_timedwait() is awakened with signal, we will return + * the wrong error code. + */ (void)net_timedwait(¬ify->nt_sem, &abstime); ret = notify->nt_result; diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index 3cb74d3a48..956c18c656 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -456,7 +456,7 @@ int icmpv6_ping(net_ipv6addr_t addr, uint16_t id, uint16_t seqno, if (state.png_cb) { state.png_cb->flags = (ICMPv6_POLL | ICMPv6_ECHOREPLY); - state.png_cb->priv = (void*)&state; + state.png_cb->priv = (FAR void *)&state; state.png_cb->event = ping_interrupt; state.png_result = -EINTR; /* Assume sem-wait interrupted by signal */ diff --git a/net/icmpv6/icmpv6_rnotify.c b/net/icmpv6/icmpv6_rnotify.c index 9a17677197..d7c04976eb 100644 --- a/net/icmpv6/icmpv6_rnotify.c +++ b/net/icmpv6/icmpv6_rnotify.c @@ -293,9 +293,9 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, abstime.tv_nsec -= 1000000000; } - /* REVISIT: If net_timedwait() is awakened with signal, we will return - * the wrong error code. - */ + /* REVISIT: If net_timedwait() is awakened with signal, we will return + * the wrong error code. + */ (void)net_timedwait(¬ify->rn_sem, &abstime); ret = notify->rn_result; diff --git a/net/icmpv6/icmpv6_solicit.c b/net/icmpv6/icmpv6_solicit.c index cceac688da..7e84ccf7d5 100644 --- a/net/icmpv6/icmpv6_solicit.c +++ b/net/icmpv6/icmpv6_solicit.c @@ -174,7 +174,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev, * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map * to the Ethernet MAC address 33:33:00:01:00:03. - * + * * NOTES: This appears correct for the ICMPv6 Router Solicitation * Message, but the ICMPv6 Neighbor Solicitation message seems to * use 33:33:ff:01:00:03. diff --git a/net/igmp/igmp_group.c b/net/igmp/igmp_group.c index 3f33207f97..03f2613026 100644 --- a/net/igmp/igmp_group.c +++ b/net/igmp/igmp_group.c @@ -265,7 +265,7 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, /* Add the group structure to the list in the device structure */ - sq_addfirst((FAR sq_entry_t*)group, &dev->grplist); + sq_addfirst((FAR sq_entry_t *)group, &dev->grplist); net_unlock(flags); } @@ -363,7 +363,7 @@ void igmp_grpfree(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group) /* Remove the group structure from the group list in the device structure */ - sq_rem((FAR sq_entry_t*)group, &dev->grplist); + sq_rem((FAR sq_entry_t *)group, &dev->grplist); /* Destroy the wait semaphore */ @@ -381,7 +381,7 @@ void igmp_grpfree(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group) if (IS_PREALLOCATED(group->flags)) { grplldbg("Put back on free list\n"); - sq_addlast((FAR sq_entry_t*)group, &g_freelist); + sq_addlast((FAR sq_entry_t *)group, &g_freelist); net_unlock(flags); } else diff --git a/net/igmp/igmp_input.c b/net/igmp/igmp_input.c index f2f7363d7f..64a5aba912 100644 --- a/net/igmp/igmp_input.c +++ b/net/igmp/igmp_input.c @@ -134,14 +134,14 @@ void igmp_input(struct net_driver_s *dev) /* Calculate and check the IGMP checksum */ - if (net_chksum((uint16_t*)&IGMPBUF->type, IGMP_HDRLEN) != 0) + if (net_chksum((FAR uint16_t *)&IGMPBUF->type, IGMP_HDRLEN) != 0) { IGMP_STATINCR(g_netstats.igmp.chksum_errors); nlldbg("Checksum error\n"); return; } - /* Find the group (or create a new one) using the incoming IP address*/ + /* Find the group (or create a new one) using the incoming IP address */ destipaddr = net_ip4addr_conv32(IGMPBUF->destipaddr); group = igmp_grpallocfind(dev, &destipaddr); diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index f800503ff2..5a2526395d 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -92,7 +92,7 @@ static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen) { - uint16_t sum = net_chksum((FAR uint16_t*)buffer, buflen); + uint16_t sum = net_chksum((FAR uint16_t *)buffer, buflen); return sum ? sum : 0xffff; } diff --git a/net/local/local_accept.c b/net/local/local_accept.c index 0c393dcf21..d26fc74813 100644 --- a/net/local/local_accept.c +++ b/net/local/local_accept.c @@ -133,7 +133,7 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Loop as necessary if we have to wait for a connection */ - for (;;) + for (; ; ) { /* Are there pending connections. Remove the client from the * head of the waiting list. diff --git a/net/local/local_connect.c b/net/local/local_connect.c index 99ea989edf..f1176ad3c8 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -143,7 +143,7 @@ int inline local_stream_connect(FAR struct local_conn_s *client, return -ECONNREFUSED; } - /* Increment the number of pending server connection s*/ + /* Increment the number of pending server connection s */ server->u.server.lc_pending++; DEBUGASSERT(server->u.server.lc_pending != 0); @@ -271,7 +271,7 @@ int psock_local_connect(FAR struct socket *psock, /* Find the matching server connection */ state = net_lock(); - for(conn = (FAR struct local_conn_s *)g_local_listeners.head; + for (conn = (FAR struct local_conn_s *)g_local_listeners.head; conn; conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node)) { diff --git a/net/local/local_recvfrom.c b/net/local/local_recvfrom.c index 5ea052cd42..bf5dc45c16 100644 --- a/net/local/local_recvfrom.c +++ b/net/local/local_recvfrom.c @@ -94,7 +94,7 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf, * eventually be reported as ENOTCONN. */ - psock->s_flags &= ~(_SF_CONNECTED |_SF_CLOSED); + psock->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED); conn->lc_state = LOCAL_STATE_DISCONNECTED; /* Did we receive any data? */ @@ -351,7 +351,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, close(conn->lc_infd); conn->lc_infd = -1; - /* Release our reference to the half duplex FIFO*/ + /* Release our reference to the half duplex FIFO */ (void)local_release_halfduplex(conn); @@ -375,7 +375,7 @@ errout_with_infd: conn->lc_infd = -1; errout_with_halfduplex: - /* Release our reference to the half duplex FIFO*/ + /* Release our reference to the half duplex FIFO */ (void)local_release_halfduplex(conn); return ret; diff --git a/net/local/local_sendto.c b/net/local/local_sendto.c index a4761413ef..8142110c08 100644 --- a/net/local/local_sendto.c +++ b/net/local/local_sendto.c @@ -168,7 +168,7 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, conn->lc_outfd = -1; errout_with_halfduplex: - /* Release our reference to the half duplex FIFO*/ + /* Release our reference to the half duplex FIFO */ (void)local_release_halfduplex(conn); return nsent; diff --git a/net/neighbor/neighbor_out.c b/net/neighbor/neighbor_out.c index 3a6e471988..061a45518d 100644 --- a/net/neighbor/neighbor_out.c +++ b/net/neighbor/neighbor_out.c @@ -67,7 +67,11 @@ /* Support for broadcast address */ static const struct ether_addr g_broadcast_ethaddr = - {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +{ + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + } +}; /* Support for IGMP multicast addresses. * @@ -86,7 +90,10 @@ static const struct ether_addr g_broadcast_ethaddr = */ #ifdef CONFIG_NET_IGMP -static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e}; +static const uint8_t g_multicast_ethaddr[3] = +{ + 0x01, 0x00, 0x5e +}; #endif /**************************************************************************** diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index 041189842a..1f752a2c64 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -289,12 +289,12 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t ripaddr) */ #ifndef CONFIG_NETDEV_MULTINIC - /* If there is only a single, registered network interface, then the - * decision is pretty easy. Use that device and its default router - * address. - */ + /* If there is only a single, registered network interface, then the + * decision is pretty easy. Use that device and its default router + * address. + */ - dev = g_netdevices; + dev = g_netdevices; #endif /* If we will did not find the network device, then we might as well fail @@ -407,12 +407,12 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t ripaddr) */ #ifndef CONFIG_NETDEV_MULTINIC - /* If there is only a single, registered network interface, then the - * decision is pretty easy. Use that device and its default router - * address. - */ + /* If there is only a single, registered network interface, then the + * decision is pretty easy. Use that device and its default router + * address. + */ - dev = g_netdevices; + dev = g_netdevices; #endif /* If we will did not find the network device, then we might as well fail diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 627d8025c8..24578e9f85 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -713,7 +713,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, { ret = -ENOTTY; } - break;; + break; } return ret; @@ -964,18 +964,18 @@ int netdev_ioctl(int sockfd, int cmd, unsigned long arg) /* Execute the command */ - ret = netdev_ifrioctl(psock, cmd, (FAR struct ifreq*)((uintptr_t)arg)); + ret = netdev_ifrioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg)); #ifdef CONFIG_NET_IGMP if (ret == -ENOTTY) { - ret = netdev_imsfioctl(psock, cmd, (FAR struct ip_msfilter*)((uintptr_t)arg)); + ret = netdev_imsfioctl(psock, cmd, (FAR struct ip_msfilter *)((uintptr_t)arg)); } #endif #ifdef CONFIG_NET_ROUTE if (ret == -ENOTTY) { - ret = netdev_rtioctl(psock, cmd, (FAR struct rtentry*)((uintptr_t)arg)); + ret = netdev_rtioctl(psock, cmd, (FAR struct rtentry *)((uintptr_t)arg)); } #endif diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index de5fa6c8f4..fd6ce96985 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -294,7 +294,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) } #endif - snprintf(dev->d_ifname, IFNAMSIZ, devfmt, devnum ); + snprintf(dev->d_ifname, IFNAMSIZ, devfmt, devnum); /* Add the device to the list of known network devices */ diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index 14c536fbc1..561bb33fe5 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -114,7 +114,7 @@ void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn) if (dev->d_sndlen > 0) { -// devif_pkt_send(dev, conn); + //devif_pkt_send(dev, conn); return; } } diff --git a/net/pkt/pkt_send.c b/net/pkt/pkt_send.c index f7dbca8c67..b36e3cb8bb 100644 --- a/net/pkt/pkt_send.c +++ b/net/pkt/pkt_send.c @@ -266,7 +266,7 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf, /* Set up the callback in the connection */ state.snd_cb->flags = PKT_POLL; - state.snd_cb->priv = (void*)&state; + state.snd_cb->priv = (FAR void *)&state; state.snd_cb->event = psock_send_interrupt; /* Notify the device driver that new TX data is available. */ diff --git a/net/route/net_delroute.c b/net/route/net_delroute.c index 9e31768ff5..1efbb0e18e 100644 --- a/net/route/net_delroute.c +++ b/net/route/net_delroute.c @@ -93,7 +93,7 @@ struct route_match_ipv6_s #ifdef CONFIG_NET_IPv4 static int net_match(FAR struct net_route_s *route, FAR void *arg) { - FAR struct route_match_s *match = ( FAR struct route_match_s *)arg; + FAR struct route_match_s *match = (FAR struct route_match_s *)arg; /* To match, the masked target address must be the same, and the masks * must be the same. @@ -133,7 +133,7 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg) #ifdef CONFIG_NET_IPv6 static int net_match_ipv6(FAR struct net_route_ipv6_s *route, FAR void *arg) { - FAR struct route_match_ipv6_s *match = ( FAR struct route_match_ipv6_s *)arg; + FAR struct route_match_ipv6_s *match = (FAR struct route_match_ipv6_s *)arg; /* To match, the masked target address must be the same, and the masks * must be the same. diff --git a/net/route/net_router.c b/net/route/net_router.c index d0bd3eb0b2..a72990e37d 100644 --- a/net/route/net_router.c +++ b/net/route/net_router.c @@ -60,7 +60,7 @@ struct route_ipv4_match_s { in_addr_t target; /* Target IPv4 address on an external network to match */ - in_addr_t router; /* IPv4 address of the router on one of our networks*/ + in_addr_t router; /* IPv4 address of the router on one of our networks */ }; #endif @@ -68,7 +68,7 @@ struct route_ipv4_match_s struct route_ipv6_match_s { net_ipv6addr_t target; /* Target IPv6 address on an external network to match */ - net_ipv6addr_t router; /* IPv6 address of the router on one of our networks*/ + net_ipv6addr_t router; /* IPv6 address of the router on one of our networks */ }; #endif diff --git a/net/route/netdev_router.c b/net/route/netdev_router.c index fda212c664..d76a4e52b7 100644 --- a/net/route/netdev_router.c +++ b/net/route/netdev_router.c @@ -60,7 +60,7 @@ struct route_ipv4_devmatch_s { FAR struct net_driver_s *dev; /* The route must use this device */ in_addr_t target; /* Target IPv4 address on an external network to match */ - in_addr_t router; /* IPv6 address of the router on one of our networks*/ + in_addr_t router; /* IPv6 address of the router on one of our networks */ }; #endif @@ -69,7 +69,7 @@ struct route_ipv6_devmatch_s { FAR struct net_driver_s *dev; /* The route must use this device */ net_ipv6addr_t target; /* Target IPv4 address on an external network to match */ - net_ipv6addr_t router; /* IPv6 address of the router on one of our networks*/ + net_ipv6addr_t router; /* IPv6 address of the router on one of our networks */ }; #endif diff --git a/net/socket/bind.c b/net/socket/bind.c index c577dd8c26..fa39ed6f64 100644 --- a/net/socket/bind.c +++ b/net/socket/bind.c @@ -86,9 +86,15 @@ static int pkt_bind(FAR struct pkt_conn_s *conn, { int ifindex; #if 0 - char hwaddr[6] = {0x00, 0xa1, 0xb1, 0xc1, 0xd1, 0xe1}; /* our MAC for debugging */ + char hwaddr[6] = /* our MAC for debugging */ + { + 0x00, 0xa1, 0xb1, 0xc1, 0xd1, 0xe1 + }; #endif - char hwaddr[6] = {0x00, 0xe0, 0xde, 0xad, 0xbe, 0xef}; /* MAC from ifconfig */ + char hwaddr[6] = /* MAC from ifconfig */ + { + 0x00, 0xe0, 0xde, 0xad, 0xbe, 0xef + }; /* Look at the addr and identify network interface */ diff --git a/net/socket/connect.c b/net/socket/connect.c index 00e2db1e05..cbd19e1774 100644 --- a/net/socket/connect.c +++ b/net/socket/connect.c @@ -121,7 +121,7 @@ static inline int psock_setup_callbacks(FAR struct socket *psock, pstate->tc_cb->flags = (TCP_NEWDATA | TCP_CLOSE | TCP_ABORT | TCP_TIMEDOUT | TCP_CONNECTED | NETDEV_DOWN); - pstate->tc_cb->priv = (void*)pstate; + pstate->tc_cb->priv = (FAR void *)pstate; pstate->tc_cb->event = psock_connect_interrupt; ret = OK; } @@ -217,7 +217,7 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev, else if ((flags & TCP_TIMEDOUT) != 0) { - /* Indicate that the connection timedout?)*/ + /* Indicate that the connection timedout?) */ pstate->tc_result = -ETIMEDOUT; } diff --git a/net/socket/getsockname.c b/net/socket/getsockname.c index 2a9223f5ff..b6b8eebcee 100644 --- a/net/socket/getsockname.c +++ b/net/socket/getsockname.c @@ -228,14 +228,14 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, /* Check if enough space has been provided for the full address */ if (*addrlen < sizeof(struct sockaddr_in6)) - { - /* This function is supposed to return the partial address if - * a smaller buffer has been provided. This support has not - * been implemented. - */ - - return -ENOSYS; - } + { + /* This function is supposed to return the partial address if + * a smaller buffer has been provided. This support has not + * been implemented. + */ + + return -ENOSYS; + } /* Set the port number */ diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index 2af5dce60c..c2236e7591 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -141,9 +141,9 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option, * a macro will do. */ - optionset = psock->s_options; - *(int*)value = _SO_GETOPT(optionset, option); - *value_len = sizeof(int); + optionset = psock->s_options; + *(FAR int *)value = _SO_GETOPT(optionset, option); + *value_len = sizeof(int); } break; @@ -161,8 +161,8 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option, /* Return the socket type */ - *(int*)value = psock->s_type; - *value_len = sizeof(int); + *(FAR int *)value = psock->s_type; + *value_len = sizeof(int); } break; diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 499eee7c5d..c76baacaf2 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -117,17 +117,17 @@ static inline int close_timeout(FAR struct tcp_close_s *pstate) if (pstate) { - /* Yes Check for a timeout configured via setsockopts(SO_LINGER). - * If none... we well let the send wait forever. - */ + /* Yes Check for a timeout configured via setsockopts(SO_LINGER). + * If none... we well let the send wait forever. + */ - psock = pstate->cl_psock; - if (psock && psock->s_linger != 0) - { - /* Check if the configured timeout has elapsed */ + psock = pstate->cl_psock; + if (psock && psock->s_linger != 0) + { + /* Check if the configured timeout has elapsed */ - return net_timeo(pstate->cl_start, psock->s_linger); - } + return net_timeo(pstate->cl_start, psock->s_linger); + } } /* No timeout */ @@ -179,7 +179,7 @@ static uint16_t netclose_interrupt(FAR struct net_driver_s *dev, /* The disconnection is complete */ #ifdef CONFIG_NET_SOLINGER - /* pstate non-NULL means that we are performing a LINGERing close.*/ + /* pstate non-NULL means that we are performing a LINGERing close. */ if (pstate) { diff --git a/net/socket/net_monitor.c b/net/socket/net_monitor.c index ed2f0acc53..8c3f24f4a9 100644 --- a/net/socket/net_monitor.c +++ b/net/socket/net_monitor.c @@ -117,7 +117,7 @@ static void connection_closed(FAR struct socket *psock, uint16_t flags) * be reported as an ENOTCONN error. */ - psock->s_flags &= ~(_SF_CONNECTED |_SF_CLOSED); + psock->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED); } } @@ -262,7 +262,7 @@ int net_startmonitor(FAR struct socket *psock) if (cb != NULL) { cb->event = connection_event; - cb->priv = (void*)psock; + cb->priv = (FAR void *)psock; cb->flags = NETDEV_DOWN; } @@ -270,7 +270,7 @@ int net_startmonitor(FAR struct socket *psock) /* Set up to receive callbacks on connection-related events */ - conn->connection_private = (void*)psock; + conn->connection_private = (FAR void *)psock; conn->connection_event = connection_event; net_unlock(save); diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index d28ec93e9b..0769662ce5 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -320,7 +320,7 @@ static inline bool sendfile_addrcheck(FAR struct tcp_conn_s *conn) static uint16_t sendfile_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { - FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s*)pvconn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct sendfile_s *pstate = (FAR struct sendfile_s *)pvpriv; int ret; @@ -720,7 +720,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, /* Set up the ACK callback in the connection */ state.snd_ackcb->flags = (TCP_ACKDATA | TCP_REXMIT | TCP_DISCONN_EVENTS); - state.snd_ackcb->priv = (void*)&state; + state.snd_ackcb->priv = (FAR void *)&state; state.snd_ackcb->event = ack_interrupt; /* Perform the TCP send operation */ @@ -728,7 +728,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, do { state.snd_datacb->flags = TCP_POLL; - state.snd_datacb->priv = (void*)&state; + state.snd_datacb->priv = (FAR void *)&state; state.snd_datacb->event = sendfile_interrupt; /* Notify the device driver of the availability of TX data */ diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index 83ad061f6e..a327431b90 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -297,7 +297,7 @@ FAR struct socket *sockfd_socket(int sockfd) FAR struct socketlist *list; int ndx = sockfd - __SOCKFD_OFFSET; - if (ndx >=0 && ndx < CONFIG_NSOCKET_DESCRIPTORS) + if (ndx >= 0 && ndx < CONFIG_NSOCKET_DESCRIPTORS) { list = sched_getsockets(); if (list) diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 43ef798b6d..a14b673542 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -450,12 +450,12 @@ static inline void recvfrom_udpreadahead(struct recvfrom_s *pstate) goto out; } - if ( 0 + if (0 #ifdef CONFIG_NET_IPv6 - || src_addr_size == sizeof(struct sockaddr_in6) + || src_addr_size == sizeof(struct sockaddr_in6) #endif #ifdef CONFIG_NET_IPv4 - || src_addr_size == sizeof(struct sockaddr_in) + || src_addr_size == sizeof(struct sockaddr_in) #endif ) { @@ -845,11 +845,11 @@ static uint16_t recvfrom_tcpinterrupt(FAR struct net_driver_s *dev, } #ifdef CONFIG_NET_SOCKOPTS - /* Reset the timeout. We will want a short timeout to terminate - * the TCP receive. - */ + /* Reset the timeout. We will want a short timeout to terminate + * the TCP receive. + */ - pstate->rf_starttime = clock_systimer(); + pstate->rf_starttime = clock_systimer(); #endif } @@ -1017,7 +1017,8 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ if (infrom) { #ifdef CONFIG_NET_IPv6 - FAR struct udp_conn_s *conn = (FAR struct udp_conn_s*)pstate->rf_sock->s_conn; + FAR struct udp_conn_s *conn = + (FAR struct udp_conn_s *)pstate->rf_sock->s_conn; /* Hybrid dual-stack IPv6/IPv4 implementations recognize a special * class of addresses, the IPv4-mapped IPv6 addresses. @@ -1426,7 +1427,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (state.rf_cb) { state.rf_cb->flags = (PKT_NEWDATA | PKT_POLL); - state.rf_cb->priv = (void*)&state; + state.rf_cb->priv = (FAR void *)&state; state.rf_cb->event = recvfrom_pktinterrupt; /* Notify the device driver of the receive call */ @@ -1567,7 +1568,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, /* Set up the callback in the connection */ state.rf_cb->flags = (UDP_NEWDATA | UDP_POLL | NETDEV_DOWN); - state.rf_cb->priv = (void*)&state; + state.rf_cb->priv = (FAR void *)&state; state.rf_cb->event = recvfrom_udp_interrupt; /* Notify the device driver of the receive call */ @@ -1749,7 +1750,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (state.rf_cb) { state.rf_cb->flags = (TCP_NEWDATA | TCP_POLL | TCP_DISCONN_EVENTS); - state.rf_cb->priv = (void*)&state; + state.rf_cb->priv = (FAR void *)&state; state.rf_cb->event = recvfrom_tcpinterrupt; /* Wait for either the receive to complete or for an error/timeout diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index cc6d15dec9..99ec9378ed 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -147,7 +147,7 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option, /* Get the value. Is the option being set or cleared? */ - setting = *(int*)value; + setting = *(FAR int *)value; /* Disable interrupts so that there is no conflict with interrupt * level access to options. diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 0a92e3327e..102f8c2213 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -96,7 +96,7 @@ struct accept_s * * Assumptions: * Running at the interrupt level -* + * ****************************************************************************/ #ifdef CONFIG_NET_TCP @@ -291,7 +291,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Set up the callback in the connection */ - conn->accept_private = (void*)&state; + conn->accept_private = (FAR void *)&state; conn->accept = accept_interrupt; /* Wait for the send to complete or an error to occur: NOTES: (1) diff --git a/net/tcp/tcp_backlog.c b/net/tcp/tcp_backlog.c index 4d2ecbc2cb..bbd5c26353 100644 --- a/net/tcp/tcp_backlog.c +++ b/net/tcp/tcp_backlog.c @@ -123,7 +123,7 @@ int tcp_backlogcreate(FAR struct tcp_conn_s *conn, int nblg) /* Then add all of the pre-allocated containers to the free list */ - blc = (FAR struct tcp_blcontainer_s*)(((FAR uint8_t*)bls) + offset); + blc = (FAR struct tcp_blcontainer_s *)(((FAR uint8_t *)bls) + offset); for (i = 0; i < nblg; i++) { sq_addfirst(&blc->bc_node, &bls->bl_free); @@ -189,7 +189,7 @@ int tcp_backlogdestroy(FAR struct tcp_conn_s *conn) /* Handle any pending connections in the backlog */ - while ((blc = (FAR struct tcp_blcontainer_s*)sq_remfirst(&blg->bl_pending)) != NULL) + while ((blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&blg->bl_pending)) != NULL) { blconn = blc->bc_conn; if (blconn) @@ -242,25 +242,26 @@ int tcp_backlogadd(FAR struct tcp_conn_s *conn, FAR struct tcp_conn_s *blconn) bls = conn->backlog; if (bls && blconn) { - /* Allocate a container for the connection from the free list */ + /* Allocate a container for the connection from the free list */ - blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_free); - if (!blc) - { - nlldbg("Failed to allocate container\n"); - ret = -ENOMEM; - } - else - { - /* Save the connection reference in the container and put the - * container at the end of the pending connection list (FIFO). - */ + blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_free); + if (!blc) + { + nlldbg("Failed to allocate container\n"); + ret = -ENOMEM; + } + else + { + /* Save the connection reference in the container and put the + * container at the end of the pending connection list (FIFO). + */ - blc->bc_conn = blconn; - sq_addlast(&blc->bc_node, &bls->bl_pending); - ret = OK; - } + blc->bc_conn = blconn; + sq_addlast(&blc->bc_node, &bls->bl_pending); + ret = OK; + } } + return ret; } @@ -311,21 +312,21 @@ FAR struct tcp_conn_s *tcp_backlogremove(FAR struct tcp_conn_s *conn) bls = conn->backlog; if (bls) { - /* Remove the a container at the head of the pending connection list - * (FIFO) - */ + /* Remove the a container at the head of the pending connection list + * (FIFO) + */ - blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_pending); - if (blc) - { - /* Extract the connection reference from the container and put - * container in the free list - */ + blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_pending); + if (blc) + { + /* Extract the connection reference from the container and put + * container in the free list + */ - blconn = blc->bc_conn; - blc->bc_conn = NULL; - sq_addlast(&blc->bc_node, &bls->bl_free); - } + blconn = blc->bc_conn; + blc->bc_conn = NULL; + sq_addlast(&blc->bc_node, &bls->bl_free); + } } nllvdbg("conn=%p, returning %p\n", conn, blconn); @@ -364,41 +365,41 @@ int tcp_backlogdelete(FAR struct tcp_conn_s *conn, bls = conn->backlog; if (bls) { - /* Find the container hold the connection */ + /* Find the container hold the connection */ - for (blc = (FAR struct tcp_blcontainer_s *)sq_peek(&bls->bl_pending), prev = NULL; - blc; - prev = blc, blc = (FAR struct tcp_blcontainer_s *)sq_next(&blc->bc_node)) - { - if (blc->bc_conn == blconn) - { - if (prev) - { - /* Remove the a container from the middle of the list of - * pending connections - */ - - (void)sq_remafter(&prev->bc_node, &bls->bl_pending); - } - else - { - /* Remove the a container from the head of the list of - * pending connections - */ - - (void)sq_remfirst(&bls->bl_pending); - } - - /* Put container in the free list */ - - blc->bc_conn = NULL; - sq_addlast(&blc->bc_node, &bls->bl_free); - return OK; - } - } - - nlldbg("Failed to find pending connection\n"); - return -EINVAL; + for (blc = (FAR struct tcp_blcontainer_s *)sq_peek(&bls->bl_pending), prev = NULL; + blc; + prev = blc, blc = (FAR struct tcp_blcontainer_s *)sq_next(&blc->bc_node)) + { + if (blc->bc_conn == blconn) + { + if (prev) + { + /* Remove the a container from the middle of the list of + * pending connections + */ + + (void)sq_remafter(&prev->bc_node, &bls->bl_pending); + } + else + { + /* Remove the a container from the head of the list of + * pending connections + */ + + (void)sq_remfirst(&bls->bl_pending); + } + + /* Put container in the free list */ + + blc->bc_conn = NULL; + sq_addlast(&blc->bc_node, &bls->bl_free); + return OK; + } + } + + nlldbg("Failed to find pending connection\n"); + return -EINVAL; } return OK; diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index c63a08557c..109e27b763 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -228,7 +228,7 @@ static void tcp_input(FAR struct net_driver_s *dev, unsigned int iplen) if ((tcp->tcpoffset & 0xf0) > 0x50) { - for (i = 0; i < ((tcp->tcpoffset >> 4) - 5) << 2 ;) + for (i = 0; i < ((tcp->tcpoffset >> 4) - 5) << 2 ; ) { opt = dev->d_buf[hdrlen + i]; if (opt == TCP_OPT_END) @@ -520,7 +520,7 @@ found: if ((tcp->tcpoffset & 0xf0) > 0x50) { - for (i = 0; i < ((tcp->tcpoffset >> 4) - 5) << 2 ;) + for (i = 0; i < ((tcp->tcpoffset >> 4) - 5) << 2 ; ) { opt = dev->d_buf[hdrlen + i]; if (opt == TCP_OPT_END) @@ -682,7 +682,8 @@ found: { dev->d_urglen = 0; #else /* CONFIG_NET_TCPURGDATA */ - dev->d_appdata = ((uint8_t*)dev->d_appdata) + ((tcp->urgp[0] << 8) | tcp->urgp[1]); + dev->d_appdata = ((FAR uint8_t *)dev->d_appdata) + ((tcp->urgp[0] << 8) | + tcp->urgp[1]); dev->d_len -= (tcp->urgp[0] << 8) | tcp->urgp[1]; #endif /* CONFIG_NET_TCPURGDATA */ } diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 0a24144ccf..9b22630143 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -131,13 +131,13 @@ static void psock_insert_segment(FAR struct tcp_wrbuffer_s *wrb, FAR sq_queue_t *q) { - sq_entry_t *entry = (sq_entry_t*)wrb; - sq_entry_t *insert = NULL; + FAR sq_entry_t *entry = (FAR sq_entry_t *)wrb; + FAR sq_entry_t *insert = NULL; - sq_entry_t *itr; + FAR sq_entry_t *itr; for (itr = sq_peek(q); itr; itr = sq_next(itr)) { - FAR struct tcp_wrbuffer_s *wrb0 = (FAR struct tcp_wrbuffer_s*)itr; + FAR struct tcp_wrbuffer_s *wrb0 = (FAR struct tcp_wrbuffer_s *)itr; if (WRB_SEQNO(wrb0) < WRB_SEQNO(wrb)) { insert = itr; @@ -403,7 +403,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, /* Check of some or all of this write buffer has been ACKed. */ next = sq_next(entry); - wrb = (FAR struct tcp_wrbuffer_s*)entry; + wrb = (FAR struct tcp_wrbuffer_s *)entry; /* If the ACKed sequence number is greater than the start * sequence number of the write buffer, then some or all of @@ -469,7 +469,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, * before the entire write buffer has even been sent. */ - wrb = (FAR struct tcp_wrbuffer_s*)sq_peek(&conn->write_q); + wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q); if (wrb && WRB_SENT(wrb) > 0 && ackno > WRB_SEQNO(wrb)) { uint32_t nacked; @@ -597,7 +597,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, while ((entry = sq_remlast(&conn->unacked_q)) != NULL) { - wrb = (FAR struct tcp_wrbuffer_s*)entry; + wrb = (FAR struct tcp_wrbuffer_s *)entry; uint16_t sent; /* Reset the number of bytes sent sent from the write buffer */ @@ -1036,7 +1036,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, psock->s_sndcb->flags = (TCP_ACKDATA | TCP_REXMIT | TCP_POLL | TCP_DISCONN_EVENTS); - psock->s_sndcb->priv = (void*)psock; + psock->s_sndcb->priv = (FAR void *)psock; psock->s_sndcb->event = psock_send_interrupt; /* Initialize the write buffer */ diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index c8ee594fbd..559820b1dd 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -399,17 +399,17 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, goto end_wait; } - /* Check if the outgoing packet is available (it may have been claimed - * by a sendto interrupt serving a different thread). - */ + /* Check if the outgoing packet is available (it may have been claimed + * by a sendto interrupt serving a different thread). + */ #if 0 /* We can't really support multiple senders on the same TCP socket */ - else if (dev->d_sndlen > 0) - { - /* Another thread has beat us sending data, wait for the next poll */ + else if (dev->d_sndlen > 0) + { + /* Another thread has beat us sending data, wait for the next poll */ - return flags; - } + return flags; + } #endif /* We get here if (1) not all of the data has been ACKed, (2) we have been diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 1f09ede313..0492fb5bb8 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -174,7 +174,7 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con * any failure to allocated, the entire I/O buffer chain will be discarded. */ - ret = iob_trycopyin(iob, (FAR const uint8_t*)&src_addr_size, + ret = iob_trycopyin(iob, (FAR const uint8_t *)&src_addr_size, sizeof(uint8_t), 0, true); if (ret < 0) { @@ -187,7 +187,7 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con return 0; } - ret = iob_trycopyin(iob, (FAR const uint8_t*)src_addr, src_addr_size, + ret = iob_trycopyin(iob, (FAR const uint8_t *)src_addr, src_addr_size, sizeof(uint8_t), true); if (ret < 0) { diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index fbc8c8c9c8..7a0ce2e60c 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -141,7 +141,7 @@ static FAR struct udp_conn_s *udp_find_conn(uint16_t portno) FAR struct udp_conn_s *conn; int i; - /* Now search each connection structure.*/ + /* Now search each connection structure. */ for (i = 0; i < CONFIG_NET_UDP_CONNS; i++) { diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 36ba573f25..7714db60c6 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -247,10 +247,10 @@ static uint16_t sendto_interrupt(FAR struct net_driver_s *dev, FAR void *conn, else if (dev->d_sndlen > 0 || (flags & UDP_NEWDATA) != 0) { - /* Another thread has beat us sending data or the buffer is busy, - * Check for a timeout. If not timed out, wait for the next - * polling cycle and check again. - */ + /* Another thread has beat us sending data or the buffer is busy, + * Check for a timeout. If not timed out, wait for the next + * polling cycle and check again. + */ #ifdef CONFIG_NET_SENDTO_TIMEOUT if (send_timeout(pstate)) @@ -441,7 +441,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, if (state.st_cb) { state.st_cb->flags = (UDP_POLL | NETDEV_DOWN); - state.st_cb->priv = (void*)&state; + state.st_cb->priv = (FAR void *)&state; state.st_cb->event = sendto_interrupt; /* Notify the device driver of the availability of TX data */ diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index b505a5953f..021ea576e8 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -122,7 +122,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || (conn->domain == PF_INET6 && - ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr))) + ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { /* Get pointers to the IPv4 header and the offset TCP header */ @@ -148,9 +148,9 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET6 && - ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr)) + ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr)) { - in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr); + in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr); net_ipv4addr_hdrcopy(ipv4->destipaddr, &raddr); } else @@ -242,7 +242,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || (conn->domain == PF_INET6 && - ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr))) + ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { udp->udpchksum = ~udp_ipv4_chksum(dev); diff --git a/net/utils/net_chksum.c b/net/utils/net_chksum.c index 526ebf9e88..776438b607 100644 --- a/net/utils/net_chksum.c +++ b/net/utils/net_chksum.c @@ -413,7 +413,7 @@ uint16_t udp_ipv6_chksum(FAR struct net_driver_s *dev) uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len) { FAR struct icmp_iphdr_s *icmp = ICMPBUF; - return net_chksum((uint16_t*)&icmp->type, len); + return net_chksum((FAR uint16_t *)&icmp->type, len); } #endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */ -- GitLab From fe4cf00ad3bd274dab3cea8dbd6feb21a29f1b11 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 16:48:49 -0600 Subject: [PATCH 202/858] TMPFS: A little more logic. Still incomplete --- fs/tmpfs/fs_tmpfs.c | 296 +++++++++++++++++++++++++++++++++++++++----- fs/tmpfs/fs_tmpfs.h | 5 + 2 files changed, 267 insertions(+), 34 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index eb7ed448b9..196bf26359 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -409,6 +409,8 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, newtdo = *tdo; newtdo->tdo_entry[index].tdo_object = to; newtdo->tdo_entry[index].tdo_name = newname; + + kmm_free(newname); return OK; } @@ -678,7 +680,10 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs, FAR struct tmpfs_object_s *to; int ret; - /* Find the object at this path */ + /* Find the object at this path. If successful, tmpfs_find_object() will + * lock both the object and the parent directory and will increment the + * reference count on both. + */ ret = tmpfs_find_object(fs, relpath, &to, parent); if (ret >= 0) @@ -687,11 +692,19 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs, if (to->to_type != TMPFS_REGULAR) { - /* No... unlock it and return an error */ + /* No... unlock the object and its parent and return an error */ to->to_refs++; #warning Add check if the file system became unlinked tmpfs_unlock_object(to); + + if (parent) + { + tdo = *parent; + tdo->tdo_refs--; + tmpfs_unlock_object(to); + } + ret = -EISDIR; } @@ -729,6 +742,14 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, to->to_refs++; #warning Add check if the file system became unlinked tmpfs_unlock_object(to); + + if (parent) + { + tdo = *parent; + tdo->tdo_refs--; + tmpfs_unlock_object(to); + } + ret = -ENOTDIR; } @@ -1236,7 +1257,61 @@ static int tmpfs_closedir(FAR struct inode *mountpt, static int tmpfs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { -#warning Missing Logic + FAR struct tmpfs_directory_s *tdo; + unsigned int index; + int ret; + + fvdbg("mountpt: %p dir: %p", mountpt, dir); + DEBUGASSERT(mountpt != NULL && dir != NULL); + + /* Get the directory structure from the dir argument and lock it */ + + tdo = dir->u.tmpfs.tf_tdo; + DEBUGASSERT(tdo != NULL); + + tmpfs_lock_directory(tdo); + + /* Have we reached the end of the directory? */ + + index = dir->u.tmpfs.tf_index; + if (index > = tdo->tdo_nentries) + { + /* We signal the end of the directory by returning the special error: + * -ENOENT + */ + + fvdbg("End of directory\n"); + ret = -ENOENT; + } + else + { + /* Does this entry refer to a file or a directory object? */ + + if (tdo->tdo_entry[index].to_type == TMPFS_DIRECTORY) + { + /* A directory */ + + dir->fd_dir.d_type = DTYPE_DIRECTORY; + } + else /* tdo->tdo_entry[index].to_type == TMPFS_REGULAR) */ + { + /* A regular file */ + + dir->fd_dir.d_type = DTYPE_FILE; + } + + /* Copy the entry name */ + + strncpy(d_name, tdo->tdo_entry[index].to_name, NAME_MAX + 1); + + /* Increment the index for next time */ + + dir->u.tmpfs.tf_index = index + 1; + ret = OK; + } + + tmpfs_unlock_directory(tdo); + return ret; } /**************************************************************************** @@ -1265,7 +1340,26 @@ static int tmpfs_rewinddir(FAR struct inode *mountpt, static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, FAR void **handle) { -#warning Missing Logic + FAR struct tmpfs_s *fs; + + DEBUGSSERT(blkdriver == NULL && handle != NULL); + + /* Create an instance of the tmpfs file system */ + + fs = (FAR struct tmpfs_s *)kmm_zalloc(sizeof(struct tmpfs_s)); + if (fs == NULL) + { + return -ENOMEM; + } + + /* Initialize the file system state */ + + sem_init(&fs->tfs_exclsem, 0, 1); + + /* Return the new file system handle */ + + *handle = (FAR void *)fs; + return OK; } /**************************************************************************** @@ -1275,7 +1369,22 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { -#warning Missing Logic + FAR struct tmpfs_s *fs = (FAR struct tmpfs_s *fs)handle; + + DEBUGSSERT(blkdriver == NULL && handle != NULL); + + /* Lock the file system */ + + tmpfs_lock(fs); + + /* Traverse all directory entries (recursively), freeing all resource */ +#warning Missing logic + + /* Now we can destroy the filesystem itself. */ + + sem_destroy(&fs->tfs_exclsem); + kmm_free(fs); + return OK; } /**************************************************************************** @@ -1315,38 +1424,105 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) { - FAR struct inode *inode; FAR struct tmpfs_s *fs; - FAR struct tmpfs_directory_s *parent; + FAR struct tmpfs_directory_s *tdo; FAR struct tmpfs_file_s *tfo; + FAR const char *name; + int ret; - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + DEBUGASSERT(mountpt != NULL && relpath != NULL); /* Get the mountpoint inode reference from the file structure and the * mountpoint private data from the inode structure */ inode = filep->f_inode; - fs = inode->i_private; + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ -#warning Missing logic - /* Find the file allocation associated with this relative path */ -#warning Missing logic - /* If the reference count is not zero, then just mark the file as + + tmpfs_lock(fs); + + /* Find the file object and parent directory associated with this relative + * path. If successful, tmpfs_find_file will lock both the file object + * and the parent directory and take one reference count on each. + */ + + ret = tmpfs_find_file(fs, relpath, &tfo, &tdo); + if (ret < 0) + { + goto errout_with_lock; + } + + /* Get the file name from the relative path */ + + name = strrchr(relpath, '/'); + if (name != NULL) + { + /* Skip over the file '/' character */ + + name++; + } + else + { + /* The name must lie in the root directory */ + + name = relpath; + } + + /* Remove the file from parent directory */ + + ret = tmpfs_remove_dirent(tdo, name); + if (ret < 0) + { + goto errout_with_objects; + } + + /* If the reference count is not one, then just mark the file as * unlinked */ -#warning Missing logic - /* Otherwise, remove the file from the parent directory entry */ -#warning Missing logic - /* Release the lock on the file system */ -#warning Missing logic - /* Free the file object allocation */ -#warning Missing logic + + if (tfo->tfo_refx > 1) + { + /* Make the file object as unlinked */ + + tfo->tfo_flags |= TFO_FLAG_UNLINKED; + + /* Release the reference count on the file object */ + + tfo->tfo_refs--; + tmpfs_unlock_object(tfo); + } + + /* Otherwise we can free the object now */ + + else + { + sem_destroy(&tfo->tfo_exclsem); + kmm_free(tfo); + } + + /* Release the reference and lock on the parent directory */ + + tdo->tdo_refs--; + tmpfs_unlock_object(tdo); + tmpfs_unlock(fs); return OK; + +errout_with_objects: + tfo->tfo_refs--; +#warning Add check if the file system became unlinked + tmpfs_unlock_object(tfo); + + tdo->tdo_refs--; + tmpfs_unlock_object(tdo); + +errout_with_lock: + tmpfs_unlock(fs); + return ret; } /**************************************************************************** @@ -1469,31 +1645,83 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf) { - FAR struct inode *inode; FAR struct tmpfs_s *fs; - FAR struct tmpfs_file_s *tfo; + FAR struct tmpfs_object_s *to; + size_t objsize; + int ret; - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + DEBUGASSERT(mountpt != NULL && relpath != NULL && buf != NULL); /* Get the mountpoint inode reference from the file structure and the * mountpoint private data from the inode structure */ - inode = filep->f_inode; - fs = inode->i_private; - + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ -#warning Missing logic - /* Find the file/directory allocation associated with this relative path */ -#warning Missing logic - /* If found, generate the stat info */ -#warning Missing logic - /* Release the lock on the file system */ -#warning Missing logic - return OK; + tmpfs_lock(fs); + + /* Find the tmpfs object at the relpath. If successful, + * tmpfs_find_object() will lock the object and increment the + * reference count on the object. + */ + + ret = tmpfs_find_object(fs, relpath, &to, NULL); + if (ret < 0) + { + goto errout_with_fslock; + } + + /* We found it... Is the object a regular file? */ + + memset(buf, 0, sizeof(struct stat)); + + if (to->to_type == TMPFS_REGULAR) + { + FAR struct tmpfs_file_s *tfo = + (FAR struct tmpfs_file_s *)to; + + /* -rwxrwxrwx */ + + buf->st_mode = S_IRWXO | S_IRWXG | S_IRWXU | S_IFREG; + + /* Get the size of the object */ + + objsize = tfo->tfo_size; + } + else /* if (to->to_type == TMPFS_DIRECTORY) */ + { + FAR struct tmpfs_directory_s *tdo = + (FAR struct tmpfs_directory_s *)to; + + /* drwxrwxrwx */ + + buf->st_mode = S_IRWXO | S_IRWXG | S_IRWXU | S_IFDIR; + + /* Get the size of the object */ + + objsize = SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); + } + + /* Fake the rest of the information */ + + buf->st_size = objsize; + buf->st_blksize = TMPFS_BLOCKSIZE; + buf->st_blocks = (objsize + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; + + /* No... unlock the object and return and return success */ + + ret = OK; + + to->to_refs--; +#warning Add check if the file system became unlinked + tmpfs_unlock_object(to); + +errout_with_fslock: + tmpfs_unlock(fs); + return ret; } /**************************************************************************** diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index 1359f50f6f..dec7729b76 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -52,6 +52,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* This is the block size reported by stat() */ + +#define TMPFS_BLOCKSIZE 512 + +/* Bit definitions for file object flags */ #define TFO_FLAG_UNLINKED (1 << 0) /* Bit 0: File is unlinked */ -- GitLab From fcb55102f940d1a0ce37412c337436d28ee55eeb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 18:27:20 -0600 Subject: [PATCH 203/858] TMPFS: Add statfs and unbind methods --- fs/tmpfs/fs_tmpfs.c | 262 +++++++++++++++++++++++++++++++++++++++++--- fs/tmpfs/fs_tmpfs.h | 25 +++++ 2 files changed, 271 insertions(+), 16 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 196bf26359..864c2ae62e 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -39,6 +39,8 @@ #include +#include +#include #include #include @@ -98,6 +100,12 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, FAR const char *relpath, FAR struct tmpfs_directory_s **tdo, FAR struct tmpfs_directory_s **parent); +static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, + unsigned int index, FAR void *arg); +static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, + unsigned int index, FAR void *arg); +static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, + tmpfs_foreach_t callout); /* File system operations */ @@ -346,12 +354,12 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, /* Free the object name */ - if (tdo_entry[index].rde_name != NULL) + if (tdo->tdo_entry[index].rde_name != NULL) { - kmm_free(tdo_entry[index].rde_name); + kmm_free(tdo->tdo_entry[index].rde_name); } - /* Remove be replace this entry with the final directory entry */ + /* Remove by replacing this entry with the final directory entry */ last = tdo->tdo_nentries - 1; if (index != last) @@ -761,6 +769,192 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, return ret; } +/**************************************************************************** + * name: tmpfs_statfs_callout + ****************************************************************************/ + +static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, + unsigned int index, FAR void *arg) +{ + FAR struct tmpfs_object_s *to; + FAR struct tmpfs_statfs_s *tmpbuf; + + DEBUASSERT(tdo != NULL && arg != NULL); + + to = &tdo->tdo_entry[index]; + tmpbuf = (FAR struct tmpfs_statfs_s *)arg; + + /* Accumulate statistics. Save the total memory allocted for this object. */ + + tmpbuf.tsf_alloc += to->to_alloc; + + /* Is this directory entry a file object? */ + + if (to->to_type = TMPFS_REGULAR) + { + FAR struct tmpfs_object_s *tmptfo; + + /* It is a file object. Increment the number of files and update the + * amount of memory in use. + */ + + tmptfo = (FAR struct tmpfs_file_s *)to; + tmpbuf.tsf_inuse += tmptfo->tfo_size; + tmpbuf.tsf_files++; + } + else /* if (to->to_type = TMPFS_DIRECTORY) */ + { + FAR struct tmpfs_object_s *tmptdo; + size_t inuse; + size_t avail; + + /* It is a directory object. Update the amount of memory in use + * for the directory and estimate the number of free directory nodes. + */ + + tmptdo = (FAR struct tmpfs_directory_s *)to; + inuse = SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); + avail = tdo->tdo_alloc - inuse; + + tmpbuf.tsf_inuse += inuse; + tmpbuf.tsf_ffree += avail / sizeof(struct tmpfs_dirent_s); + } + + return TMPFS_CONTINUE; +} + +/**************************************************************************** + * name: tmpfs_free_callout + ****************************************************************************/ + +static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, + unsigned int index, FAR void *arg) +{ + FAR struct tmpfs_object_s *to; + FAR struct tmpfs_object_s *tmp; + FAR struct tmpfs_file_s *tfo; + unsigned int last; + + /* Free the object name */ + + if (tdo->tdo_entry[index].rde_name != NULL) + { + kmm_free(tdo->tdo_entry[index].rde_name); + } + + /* Remove by replacing this entry with the final directory entry */ + + to = &tdo->tdo_entry[index]; + last = tdo->tdo_nentries - 1; + + if (index != last) + { + tmp = &tdo->tdo_entry[last]; + to->rde_object = tmp->rde_object; + to->rde_name = tmp->rde_name; + } + + /* And decrement the count of directory entries */ + + tdo->tdo_entries = last; + + /* Is this directory entry a file object? */ + + if (to->to_type = TMPFS_REGULAR) + { + tfo = (FAR struct tmpfs_file_s *)to; + + /* Are there references to the file? */ + + if (tfo->tfo_refs > 0) + { + /* Yes.. We cannot delete the file now. Just mark it as unlinked. */ + + tfo->tfo_flags |= TFO_FLAG_UNLINKED; + return TMPFS_UNLINKED; + } + } + + /* Free the object now */ + + sem_destroy(&to->to_excsem); + kmm_free(to); + return TMPFS_DELETED; +} + +/**************************************************************************** + * name: tmpfs_foreach + ****************************************************************************/ + +static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, + tmpfs_foreach_t callout) +{ + FAR struct tmpfs_object_s *to; + unsigned int index; + int ret; + + /* Visit each directory entry */ + + for (index = 0; ; index < tdo->tdo_nentries) + { + /* Lock the object and take a reference */ + + tmpfs_lock_object(to); + to->to_refs++; + + /* Is the next entry a directory? */ + + to = tdo->tdo_entry[index].tde_object; + if (to->to_type == TMPFS_DIRECTORY) + { + FAR struct tmpfs_directory_s *next = + (FAR struct tmpfs_directory_s *)to; + + /* Yes.. traverse its children first in the case the the final + * action will be to delete the directory. + */ + + ret = tmpfs_foreach(next, tmpfs_free_callout, NULL); + if (ret < 0) + { + return -ECANCELED; + } + } + + /* Perform the callout */ + + ret = callout(tdo, index); + switch (ret) + { + case TMPFS_CONTINUE: /* Continue enumeration */ + /* Release the object and index to the next entry */ + + to->to_refs--; + tmpfs_unlock_object(to); + index++; + break; + + case TMPFS_HALT: /* Stop enumeration */ + /* Release the object and cancel the traversal */ + + to->to_refs--; + tmpfs_unlock_object(to); + return -ECANCELED; + + case TTMPFS_UNLINKED: /* Only the directory entry was deleted */ + /* Release the object and continue with the same index */ + + to->to_refs--; + tmpfs_unlock_object(to); + + case TMPFS_DELETED: /* Object and directory entry deleted */ + break; /* Continue with the same index */ + } + } + + return OK; +} + /**************************************************************************** * name: tmpfs_open ****************************************************************************/ @@ -1370,6 +1564,7 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { FAR struct tmpfs_s *fs = (FAR struct tmpfs_s *fs)handle; + int ret; DEBUGSSERT(blkdriver == NULL && handle != NULL); @@ -1377,14 +1572,15 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, tmpfs_lock(fs); - /* Traverse all directory entries (recursively), freeing all resource */ -#warning Missing logic + /* Traverse all directory entries (recursively), freeing all resources. */ + + ret = tmpfs_foreach(fs->tfs_root, tmpfs_free_callout); /* Now we can destroy the filesystem itself. */ sem_destroy(&fs->tfs_exclsem); kmm_free(fs); - return OK; + return ret; } /**************************************************************************** @@ -1393,28 +1589,62 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) { - FAR struct inode *inode; FAR struct tmpfs_s *fs; - FAR struct tmpfs_file_s *tfo; + FAR struct tmpfs_directory_s *tdo; + struct tmpfs_statfs_s tmpbuf; + size_t inuse; + size_t avail; + off_t blkalloc; + off_t blkused; - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + DEBUGASSERT(mountpt != NULL && buf != NULL); /* Get the mountpoint inode reference from the file structure and the * mountpoint private data from the inode structure */ - inode = filep->f_inode; - fs = inode->i_private; - - DEBUGASSERT(fs != NULL); + fs = mountpt->i_private; + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ -#warning Missing logic + + tmpfs_lock(fs); + /* Traverse the file system to accurmulate statistics */ -#warning Missing logic + + tdo = fs->tfs_root; + inuse = SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); + avail = tdo->tdo_alloc - inuse; + + tmpbuf.tsf_alloc = tdo->tdo_alloc; + tmpbuf.tsf_inuse = inuse; + tmpbuf.tsf_files = 0; + tmpbuf.tsf_ffree = avail / sizeof(struct tmpfs_dirent_s); + + ret = tmpfs_foreach(fs->tfs_root, tmpfs_statfs_callout, + (FAR void *)&tmpbuf); + if (ret < 0) + { + return -ECANCELED; + } + + /* Return something for the file system description */ + + blkalloc = (tmpbuf.tsf_alloc + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; + blkused = (tmpbuf.tsf_inuse + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; + + buf->f_type = TMPFS_MAGIC; + buf->f_namelen = NAME_MAX; + buf->f_bsize = TMPFS_BLOCKSIZE; + buf->f_blocks = blkalloc; + buf->f_bfree = blkalloc - blkused; + buf->f_bavail = blkalloc - blkused; + buf->f_files = tmpbuf.tsf_files; + buf->f_ffree = tmpbuf.tsf_free; + /* Release the lock on the file system */ -#warning Missing logic + tmpfs_unlock(fs); return OK; } diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index dec7729b76..77035465e7 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -72,6 +72,16 @@ enum tmpfs_objtype_e TMPFS_REGULAR /* Regular file */ }; +/* Values returned by tmpfs_foreach() */ + +enum tmpfs_foreach_e +{ + TMPFS_CONTINUE = 0, /* Continue enumeration */ + TMPFS_HALT, /* Stop enumeration */ + TMPFS_DELETED, /* Object and directory entry deleted */ + TMPFS_UNLINKED /* Only the directory entry was deleted */ +}; + /* The generic form of a TMPFS memory object */ struct tmpfs_object_s @@ -147,6 +157,21 @@ struct tmpfs_s sem_t tfs_exclsem; /* Supports exclusive access to the file system */ }; +/* This is the type used the tmpfs_statfs_callout to accumulate memory usage */ + +struct tmpfs_statfs_s +{ + size_t tsf_alloc; /* Total memory allocated */ + size_t tsf_inuse; /* Total memory in use */ + off_t tsf_files; /* Total file nodes in the file system */ + off_t tsf_ffree; /* Free directory nodes in the file system */ +}; + +/* This is the type of the for tmpfs_foreach callback */ + +typedef int (*tmpfs_foreach_t)(FAR struct tmpfs_directory_s *tdo, + unsigned int index, FAR void *arg); + /**************************************************************************** * Public Data ****************************************************************************/ -- GitLab From 45eebacbb4d1be26df70977e56e2bc0bd7662bc1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 19:20:17 -0600 Subject: [PATCH 204/858] binfmt/: More spacing/alignment fixes --- binfmt/binfmt_execmodule.c | 4 ++-- binfmt/binfmt_exepath.c | 4 ++-- binfmt/binfmt_schedunload.c | 2 +- binfmt/elf.c | 2 +- binfmt/libelf/libelf_bind.c | 2 +- binfmt/libelf/libelf_ctors.c | 6 +++--- binfmt/libelf/libelf_dtors.c | 6 +++--- binfmt/libelf/libelf_init.c | 6 +++--- binfmt/libelf/libelf_load.c | 4 ++-- binfmt/libelf/libelf_read.c | 4 ++-- binfmt/libelf/libelf_sections.c | 10 ++++++---- binfmt/libelf/libelf_symbols.c | 4 ++-- binfmt/libelf/libelf_verify.c | 5 ++++- binfmt/libnxflat/libnxflat_bind.c | 28 ++++++++++++++-------------- binfmt/libnxflat/libnxflat_init.c | 5 +++-- binfmt/libnxflat/libnxflat_load.c | 5 +++-- binfmt/libnxflat/libnxflat_read.c | 4 ++-- binfmt/libnxflat/libnxflat_unload.c | 4 ++-- binfmt/nxflat.c | 6 +++--- binfmt/pcode.c | 2 +- binfmt/symtab_findorderedbyvalue.c | 2 +- 21 files changed, 61 insertions(+), 54 deletions(-) diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index ccc20063cb..f8701be8ce 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -159,7 +159,7 @@ int exec_module(FAR const struct binary_s *binp) /* Allocate a TCB for the new task. */ - tcb = (FAR struct task_tcb_s*)kmm_zalloc(sizeof(struct task_tcb_s)); + tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct task_tcb_s)); if (!tcb) { err = ENOMEM; @@ -189,7 +189,7 @@ int exec_module(FAR const struct binary_s *binp) * will need to change if/when we want to support dynamic stack allocation. */ - stack = (FAR uint32_t*)kumm_malloc(binp->stacksize); + stack = (FAR uint32_t *)kumm_malloc(binp->stacksize); if (!stack) { err = ENOMEM; diff --git a/binfmt/binfmt_exepath.c b/binfmt/binfmt_exepath.c index 3caf02e40d..c99ae8706a 100644 --- a/binfmt/binfmt_exepath.c +++ b/binfmt/binfmt_exepath.c @@ -190,7 +190,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath) * in the PATH variable have been considered. */ - for (;;) + for (; ; ) { /* Make sure that exepath->next points to the beginning of a string */ @@ -244,7 +244,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath) /* Verify that a regular file exists at this path */ - ret = stat(fullpath, &buf);; + ret = stat(fullpath, &buf); if (ret == OK && S_ISREG(buf.st_mode)) { return fullpath; diff --git a/binfmt/binfmt_schedunload.c b/binfmt/binfmt_schedunload.c index 3d897953df..89d5815918 100644 --- a/binfmt/binfmt_schedunload.c +++ b/binfmt/binfmt_schedunload.c @@ -84,7 +84,7 @@ FAR struct binary_s *g_unloadhead; * pid - The task ID of the child task * bin - This structure must have been allocated with kmm_malloc() and must * persist until the task unloads - + * * * Returned Value: * None diff --git a/binfmt/elf.c b/binfmt/elf.c index 2cb18fe919..7291389eba 100644 --- a/binfmt/elf.c +++ b/binfmt/elf.c @@ -198,7 +198,7 @@ static void elf_dumpentrypt(FAR struct binary_s *binp, } #endif - elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt, + elf_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); #ifdef CONFIG_ARCH_ADDRENV diff --git a/binfmt/libelf/libelf_bind.c b/binfmt/libelf/libelf_bind.c index 59782bb1ca..a4fd589613 100644 --- a/binfmt/libelf/libelf_bind.c +++ b/binfmt/libelf/libelf_bind.c @@ -113,7 +113,7 @@ static inline int elf_readrel(FAR struct elf_loadinfo_s *loadinfo, /* And, finally, read the symbol table entry into memory */ - return elf_read(loadinfo, (FAR uint8_t*)rel, sizeof(Elf32_Rel), offset); + return elf_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); } /**************************************************************************** diff --git a/binfmt/libelf/libelf_ctors.c b/binfmt/libelf/libelf_ctors.c index 11d6b8810b..95f3884135 100644 --- a/binfmt/libelf/libelf_ctors.c +++ b/binfmt/libelf/libelf_ctors.c @@ -163,7 +163,7 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo) { /* Allocate memory to hold a copy of the .ctor section */ - loadinfo->ctoralloc = (binfmt_ctor_t*)kumm_malloc(ctorsize); + loadinfo->ctoralloc = (binfmt_ctor_t *)kumm_malloc(ctorsize); if (!loadinfo->ctoralloc) { bdbg("Failed to allocate memory for .ctors\n"); @@ -174,7 +174,7 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->ctors, ctorsize, + ret = elf_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, shdr->sh_offset); if (ret < 0) { @@ -206,7 +206,7 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo) * will be relocated via the normal mechanism. */ - loadinfo->ctors = (binfmt_ctor_t*)shdr->sh_addr; + loadinfo->ctors = (binfmt_ctor_t *)shdr->sh_addr; } } diff --git a/binfmt/libelf/libelf_dtors.c b/binfmt/libelf/libelf_dtors.c index d268ab1e26..1f4cdab7e3 100644 --- a/binfmt/libelf/libelf_dtors.c +++ b/binfmt/libelf/libelf_dtors.c @@ -163,7 +163,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo) { /* Allocate memory to hold a copy of the .dtor section */ - loadinfo->ctoralloc = (binfmt_dtor_t*)kumm_malloc(dtorsize); + loadinfo->ctoralloc = (binfmt_dtor_t *)kumm_malloc(dtorsize); if (!loadinfo->ctoralloc) { bdbg("Failed to allocate memory for .dtors\n"); @@ -174,7 +174,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->dtors, dtorsize, + ret = elf_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, shdr->sh_offset); if (ret < 0) { @@ -206,7 +206,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo) * will be relocated via the normal mechanism. */ - loadinfo->dtors = (binfmt_dtor_t*)shdr->sh_addr; + loadinfo->dtors = (binfmt_dtor_t *)shdr->sh_addr; } } diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 2ba84bfefd..35414fca18 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -172,19 +172,19 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) /* Read the ELF ehdr from offset 0 */ - ret = elf_read(loadinfo, (FAR uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); + ret = elf_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); if (ret < 0) { bdbg("Failed to read ELF header: %d\n", ret); return ret; } - elf_dumpbuffer("ELF header", (FAR const uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); + elf_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); /* Verify the ELF header */ ret = elf_verifyheader(&loadinfo->ehdr); - if (ret <0) + if (ret < 0) { /* This may not be an error because we will be called to attempt loading * EVERY binary. If elf_verifyheader() does not recognize the ELF header, diff --git a/binfmt/libelf/libelf_load.c b/binfmt/libelf/libelf_load.c index c81be5c196..b5cef6c6e9 100644 --- a/binfmt/libelf/libelf_load.c +++ b/binfmt/libelf/libelf_load.c @@ -157,8 +157,8 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo) /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */ bvdbg("Loaded sections:\n"); - text = (FAR uint8_t*)loadinfo->textalloc; - data = (FAR uint8_t*)loadinfo->dataalloc; + text = (FAR uint8_t *)loadinfo->textalloc; + data = (FAR uint8_t *)loadinfo->dataalloc; for (i = 0; i < loadinfo->ehdr.e_shnum; i++) { diff --git a/binfmt/libelf/libelf_read.c b/binfmt/libelf/libelf_read.c index dacd52347b..420c8f1808 100644 --- a/binfmt/libelf/libelf_read.c +++ b/binfmt/libelf/libelf_read.c @@ -68,9 +68,9 @@ ****************************************************************************/ #if defined(ELF_DUMP_READDATA) -static inline void elf_dumpreaddata(char *buffer, int buflen) +static inline void elf_dumpreaddata(FAR char *buffer, int buflen) { - uint32_t *buf32 = (uint32_t*)buffer; + FAR uint32_t *buf32 = (FAR uint32_t *)buffer; int i; int j; diff --git a/binfmt/libelf/libelf_sections.c b/binfmt/libelf/libelf_sections.c index 7aeff5a9e9..26189d7247 100644 --- a/binfmt/libelf/libelf_sections.c +++ b/binfmt/libelf/libelf_sections.c @@ -117,7 +117,7 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo, buffer = loadinfo->iobuffer; bytesread = 0; - for (;;) + for (; ; ) { /* Get the number of bytes to read */ @@ -211,16 +211,18 @@ int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo) /* Allocate memory to hold a working copy of the sector header table */ - loadinfo->shdr = (FAR Elf32_Shdr*)kmm_malloc(shdrsize); + loadinfo->shdr = (FAR FAR Elf32_Shdr *)kmm_malloc(shdrsize); if (!loadinfo->shdr) { - bdbg("Failed to allocate the section header table. Size: %ld\n", (long)shdrsize); + bdbg("Failed to allocate the section header table. Size: %ld\n", + (long)shdrsize); return -ENOMEM; } /* Read the section header table into memory */ - ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff); + ret = elf_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + loadinfo->ehdr.e_shoff); if (ret < 0) { bdbg("Failed to read section header table: %d\n", ret); diff --git a/binfmt/libelf/libelf_symbols.c b/binfmt/libelf/libelf_symbols.c index c2be4d193d..1769481558 100644 --- a/binfmt/libelf/libelf_symbols.c +++ b/binfmt/libelf/libelf_symbols.c @@ -107,7 +107,7 @@ static int elf_symname(FAR struct elf_loadinfo_s *loadinfo, bytesread = 0; - for (;;) + for (; ; ) { /* Get the number of bytes to read */ @@ -239,7 +239,7 @@ int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index, /* And, finally, read the symbol table entry into memory */ - return elf_read(loadinfo, (FAR uint8_t*)sym, sizeof(Elf32_Sym), offset); + return elf_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); } /**************************************************************************** diff --git a/binfmt/libelf/libelf_verify.c b/binfmt/libelf/libelf_verify.c index ee6c880f67..015d9d39fe 100644 --- a/binfmt/libelf/libelf_verify.c +++ b/binfmt/libelf/libelf_verify.c @@ -53,7 +53,10 @@ * Private Constant Data ****************************************************************************/ -static const char g_elfmagic[EI_MAGIC_SIZE] = { 0x7f, 'E', 'L', 'F' }; +static const char g_elfmagic[EI_MAGIC_SIZE] = +{ + 0x7f, 'E', 'L', 'F' +}; /**************************************************************************** * Private Functions diff --git a/binfmt/libnxflat/libnxflat_bind.c b/binfmt/libnxflat/libnxflat_bind.c index dfb1e911cc..3c1709b2a5 100644 --- a/binfmt/libnxflat/libnxflat_bind.c +++ b/binfmt/libnxflat/libnxflat_bind.c @@ -102,14 +102,14 @@ static inline int nxflat_bindrel32i(FAR struct nxflat_loadinfo_s *loadinfo, uint32_t offset) { - uint32_t *addr; + FAR uint32_t *addr; bvdbg("NXFLAT_RELOC_TYPE_REL32I Offset: %08x I-Space: %p\n", offset, loadinfo->ispace + sizeof(struct nxflat_hdr_s)); if (offset < loadinfo->dsize) { - addr = (uint32_t*)(offset + loadinfo->dspace->region); + addr = (FAR uint32_t *)(offset + loadinfo->dspace->region); bvdbg(" Before: %08x\n", *addr); *addr += (uint32_t)(loadinfo->ispace + sizeof(struct nxflat_hdr_s)); bvdbg(" After: %08x\n", *addr); @@ -141,14 +141,14 @@ static inline int nxflat_bindrel32i(FAR struct nxflat_loadinfo_s *loadinfo, static inline int nxflat_bindrel32d(FAR struct nxflat_loadinfo_s *loadinfo, uint32_t offset) { - uint32_t *addr; + FAR uint32_t *addr; bvdbg("NXFLAT_RELOC_TYPE_REL32D Offset: %08x D-Space: %p\n", offset, loadinfo->dspace->region); if (offset < loadinfo->dsize) { - addr = (uint32_t*)(offset + loadinfo->dspace->region); + addr = (FAR uint32_t *)(offset + loadinfo->dspace->region); bvdbg(" Before: %08x\n", *addr); *addr += (uint32_t)(loadinfo->dspace->region); bvdbg(" After: %08x\n", *addr); @@ -183,14 +183,14 @@ static inline int nxflat_bindrel32d(FAR struct nxflat_loadinfo_s *loadinfo, static inline int nxflat_bindrel32id(FAR struct nxflat_loadinfo_s *loadinfo, uint32_t offset) { - uint32_t *addr; + FAR uint32_t *addr; bvdbg("NXFLAT_RELOC_TYPE_REL32D Offset: %08x D-Space: %p\n", offset, loadinfo->dspace->region); if (offset < loadinfo->dsize) { - addr = (uint32_t*)(offset + loadinfo->dspace->region); + addr = (FAR uint32_t *)(offset + loadinfo->dspace->region); bvdbg(" Before: %08x\n", *addr); *addr += ((uint32_t)loadinfo->ispace - (uint32_t)(loadinfo->dspace->region)); bvdbg(" After: %08x\n", *addr); @@ -231,7 +231,7 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo) /* The NXFLAT header is the first thing at the beginning of the ISpace. */ - hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace; + hdr = (FAR struct nxflat_hdr_s *)loadinfo->ispace; /* From this, we can get the offset to the list of relocation entries */ @@ -348,8 +348,8 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo) #ifdef CONFIG_NXFLAT_DUMPBUFFER if (ret == OK && nrelocs > 0) { - relocs = (FAR struct nxflat_reloc_s*)(offset - loadinfo->isize + loadinfo->dspace->region); - nxflat_dumpbuffer("GOT", (FAR const uint8_t*)relocs, nrelocs * sizeof(struct nxflat_reloc_s)); + relocs = (FAR struct nxflat_reloc_s *)(offset - loadinfo->isize + loadinfo->dspace->region); + nxflat_dumpbuffer("GOT", (FAR const uint8_t *)relocs, nrelocs * sizeof(struct nxflat_reloc_s)); } #endif @@ -397,7 +397,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo, /* The NXFLAT header is the first thing at the beginning of the ISpace. */ - hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace; + hdr = (FAR struct nxflat_hdr_s *)loadinfo->ispace; /* From this, we can get the offset to the list of symbols imported by * this module and the number of symbols imported by this module. @@ -440,7 +440,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo, DEBUGASSERT(offset >= loadinfo->isize && offset < loadinfo->isize + loadinfo->dsize); - imports = (struct nxflat_import_s*) + imports = (FAR struct nxflat_import_s *) (offset - loadinfo->isize + loadinfo->dspace->region); /* Now, traverse the list of imported symbols and attempt to bind @@ -462,7 +462,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo, offset = imports[i].i_funcname; DEBUGASSERT(offset < loadinfo->isize); - symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s)); + symname = (FAR char *)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s)); /* Find the exported symbol value for this this symbol name. */ @@ -494,7 +494,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo, #ifdef CONFIG_NXFLAT_DUMPBUFFER if (nimports > 0) { - nxflat_dumpbuffer("Imports", (FAR const uint8_t*)imports, nimports * sizeof(struct nxflat_import_s)); + nxflat_dumpbuffer("Imports", (FAR const uint8_t *)imports, nimports * sizeof(struct nxflat_import_s)); } #endif @@ -549,7 +549,7 @@ static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo) /* Zero the BSS area */ - memset((void*)(loadinfo->dspace->region + loadinfo->datasize), 0, + memset((FAR void *)(loadinfo->dspace->region + loadinfo->datasize), 0, loadinfo->bsssize); /* Restore the original address environment */ diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c index 2057a18358..52159c5f03 100644 --- a/binfmt/libnxflat/libnxflat_init.c +++ b/binfmt/libnxflat/libnxflat_init.c @@ -118,14 +118,15 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) /* Read the NXFLAT header from offset 0 */ - ret = nxflat_read(loadinfo, (char*)&loadinfo->header, + ret = nxflat_read(loadinfo, (FAR char *)&loadinfo->header, sizeof(struct nxflat_hdr_s), 0); if (ret < 0) { bdbg("Failed to read NXFLAT header: %d\n", ret); return ret; } - nxflat_dumpbuffer("NXFLAT header", (FAR const uint8_t*)&loadinfo->header, + + nxflat_dumpbuffer("NXFLAT header", (FAR const uint8_t *)&loadinfo->header, sizeof(struct nxflat_hdr_s)); /* Verify the NXFLAT header */ diff --git a/binfmt/libnxflat/libnxflat_load.c b/binfmt/libnxflat/libnxflat_load.c index 663953ea27..a3e49d3ce1 100644 --- a/binfmt/libnxflat/libnxflat_load.c +++ b/binfmt/libnxflat/libnxflat_load.c @@ -147,7 +147,7 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo) */ loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ, - MAP_SHARED|MAP_FILE, loadinfo->filfd, 0); + MAP_SHARED | MAP_FILE, loadinfo->filfd, 0); if (loadinfo->ispace == (uint32_t)MAP_FAILED) { bdbg("Failed to map NXFLAT ISpace: %d\n", errno); @@ -189,7 +189,8 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo) * DSpace memory. */ - ret = nxflat_read(loadinfo, (char*)loadinfo->dspace->region, dreadsize, doffset); + ret = nxflat_read(loadinfo, (FAR char *)loadinfo->dspace->region, + dreadsize, doffset); if (ret < 0) { bdbg("Failed to read .data section: %d\n", ret); diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c index 3257945bed..023b7c07e4 100644 --- a/binfmt/libnxflat/libnxflat_read.c +++ b/binfmt/libnxflat/libnxflat_read.c @@ -69,9 +69,9 @@ ****************************************************************************/ #if defined(NXFLAT_DUMP_READDATA) -static inline void nxflat_dumpreaddata(char *buffer, int buflen) +static inline void nxflat_dumpreaddata(FAR char *buffer, int buflen) { - uint32_t *buf32 = (uint32_t*)buffer; + FAR uint32_t *buf32 = (FAR uint32_t *)buffer; int i; int j; diff --git a/binfmt/libnxflat/libnxflat_unload.c b/binfmt/libnxflat/libnxflat_unload.c index 08b1f44f35..7cca6f25f3 100644 --- a/binfmt/libnxflat/libnxflat_unload.c +++ b/binfmt/libnxflat/libnxflat_unload.c @@ -79,14 +79,14 @@ * ****************************************************************************/ -int nxflat_unload(struct nxflat_loadinfo_s *loadinfo) +int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo) { /* Release the memory segments */ /* Release the I-Space mmap'ed file */ if (loadinfo->ispace) { - munmap((void*)loadinfo->ispace, loadinfo->isize); + munmap((FAR void *)loadinfo->ispace, loadinfo->isize); loadinfo->ispace = 0; } diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c index f308de73b0..1c4b454ff9 100644 --- a/binfmt/nxflat.c +++ b/binfmt/nxflat.c @@ -187,7 +187,7 @@ static int nxflat_loadbinary(struct binary_s *binp) */ binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entryoffs); - binp->mapped = (void*)loadinfo.ispace; + binp->mapped = (FAR void *)loadinfo.ispace; binp->mapsize = loadinfo.isize; binp->stacksize = loadinfo.stacksize; @@ -202,7 +202,7 @@ static int nxflat_loadbinary(struct binary_s *binp) #ifdef CONFIG_ARCH_ADDRENV # warning "REVISIT" #else - binp->alloc[0] = (void*)loadinfo.dspace; + binp->alloc[0] = (FAR void *)loadinfo.dspace; #endif #ifdef CONFIG_ARCH_ADDRENV @@ -213,7 +213,7 @@ static int nxflat_loadbinary(struct binary_s *binp) up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv); #endif - nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt, + nxflat_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, MIN(loadinfo.isize - loadinfo.entryoffs, 512)); nxflat_uninit(&loadinfo); diff --git a/binfmt/pcode.c b/binfmt/pcode.c index a4423c6900..6023622440 100644 --- a/binfmt/pcode.c +++ b/binfmt/pcode.c @@ -352,7 +352,7 @@ static int pcode_load(struct binary_s *binp) { /* Set up for the next gulp */ - DEBUGASSERT(nread > 0 && nread <=remaining); + DEBUGASSERT(nread > 0 && nread <= remaining); remaining -= nread; ptr += nread; } diff --git a/binfmt/symtab_findorderedbyvalue.c b/binfmt/symtab_findorderedbyvalue.c index 7b2c76e748..ba731be965 100644 --- a/binfmt/symtab_findorderedbyvalue.c +++ b/binfmt/symtab_findorderedbyvalue.c @@ -100,7 +100,7 @@ symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, */ mid = (low + high) >> 1; - if ( value < symtab[mid].sym_value) + if (value < symtab[mid].sym_value) { high = mid - 1; } -- GitLab From 11a8a014628cbf3c515fc8f96562e61de1becc6f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Oct 2015 20:35:41 -0600 Subject: [PATCH 205/858] TMPFS: Add mkdir and rmdir logic --- arch | 2 +- fs/tmpfs/fs_tmpfs.c | 413 +++++++++++++++++++++++++++++++++----------- fs/tmpfs/fs_tmpfs.h | 2 +- 3 files changed, 310 insertions(+), 107 deletions(-) diff --git a/arch b/arch index 8faab42f9a..0b7bf8249b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8faab42f9a4c9170b35bfb68ef40b2e54ba83320 +Subproject commit 0b7bf8249b1b96f5e31597b5242db222a2c29f73 diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 864c2ae62e..1d2b202bcb 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -89,6 +89,9 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, static FAR struct tmpfs_file_s *tmpfs_alloc_file(void); static int tmpfs_create_file(FAR struct tmpfs_s *fs, FAR const char *relpath, FAR struct tmpfs_file_s **tfo); +static FAR struct tmpfs_directory_s *tmpfs_alloc_directory(void); +static int tmpfs_create_directory(FAR struct tmpfs_s *fs, + FAR const char *relpath, FAR struct tmpfs_directory_s **tdo); static int tmpfs_find_object(FAR struct tmpfs_s *fs, FAR const char *relpath, FAR struct tmpfs_object_s **object, FAR struct tmpfs_directory_s **parent); @@ -174,7 +177,7 @@ const struct mountpt_operations tmpfs_operations = ****************************************************************************/ /**************************************************************************** - * name: tmpfs_lock + * Name: tmpfs_lock ****************************************************************************/ static void tmpfs_lock(FAR struct tmpfs_s *fs) @@ -188,7 +191,7 @@ static void tmpfs_lock(FAR struct tmpfs_s *fs) } /**************************************************************************** - * name: tmpfs_lock_object + * Name: tmpfs_lock_object ****************************************************************************/ static void tmpfs_lock_object(FAR struct tmpfs_object_s *to) @@ -202,7 +205,7 @@ static void tmpfs_lock_object(FAR struct tmpfs_object_s *to) } /**************************************************************************** - * name: tmpfs_realloc_directory + * Name: tmpfs_realloc_directory ****************************************************************************/ static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, @@ -250,7 +253,7 @@ static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, } /**************************************************************************** - * name: tmpfs_realloc_file + * Name: tmpfs_realloc_file ****************************************************************************/ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, @@ -314,7 +317,7 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, } /**************************************************************************** - * name: tmpfs_find_dirent + * Name: tmpfs_find_dirent ****************************************************************************/ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, @@ -335,7 +338,7 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, } /**************************************************************************** - * name: tmpfs_remove_dirent + * Name: tmpfs_remove_dirent ****************************************************************************/ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, @@ -375,7 +378,7 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, } /**************************************************************************** - * name: tmpfs_add_dirent + * Name: tmpfs_add_dirent ****************************************************************************/ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, @@ -423,7 +426,7 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, } /**************************************************************************** - * name: tmpfs_alloc_file + * Name: tmpfs_alloc_file ****************************************************************************/ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) @@ -435,7 +438,7 @@ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) allocsize = SIZEOF_TMPFS_FILE(FS_TMPFS_FILE_ALLOCGUARD); tfo = (FAR struct tmpfs_file_s *)kmm_malloc(allocsize); - if (nenewtfowfile == NULL) + if (tfo == NULL) { return NULL; } @@ -453,14 +456,14 @@ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) } /**************************************************************************** - * name: tmpfs_create_file + * Name: tmpfs_create_file ****************************************************************************/ static int tmpfs_create_file(FAR struct tmpfs_s *fs, FAR const char *relpath, FAR struct tmpfs_file_s **tfo) { - FAR struct tmpfs_directory_s *tdo; + FAR struct tmpfs_directory_s *parent; FAR struct tmpfs_file_s *newtfo; FAR char *copy; FAR char *name; @@ -480,20 +483,26 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, name = strrchr(copy, '/'); if (name == NULL) { - /* No subdirectories... the root directory */ + /* No subdirectories... use the root directory */ - name = copy; - tdo = fs->tfs_root; + name = copy; + parent = fs->tfs_root; + + tmpfs_lock_directory(parent); + parent->tdo_refs++; } else { - /* Terminate the parent directly path */ + /* Terminate the parent directory path */ *name++ = '\0'; - /* Locate the parent directory that should contain this name */ + /* Locate the parent directory that should contain this name. + * On success, tmpfs_find_directory() will lockthe parent + * directory and increment the reference count. + */ - ret = tmpfs_find_directory(fs, copy, &tdo, NULL); + ret = tmpfs_find_directory(fs, copy, &parent, NULL); if (ret < 0) { goto errout_with_copy; @@ -502,16 +511,19 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, /* Verify that no object of this name already exists in the directory */ - ret = tmpfs_find_dirent(tdo, name); + ret = tmpfs_find_dirent(parent, name); if (ret != -ENOENT) { - /* Something with this name already exists n the directory */ + /* Something with this name already exists in the directory. + * OR perhaps some fatal error occurred. + */ if (ret >= 0) { ret = -EEXIST; - goto errout_with_copy; } + + goto errout_with_parent; } /* Allocate an empty file */ @@ -520,12 +532,12 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, if (newtfo == NULL) { ret = -ENOMEM: - goto errout_with_copy; + goto errout_with_parent; } /* Then add the new, empty file to the directory */ - ret = tmpfs_add_dirent(tdo, ()FAR struct tmpfs_object_s *)newtfo, name); + ret = tmpfs_add_dirent(parent, (FAR struct tmpfs_object_s *)newtfo, name); if (ret < 0) { goto errout_with_file; @@ -543,13 +555,167 @@ errout_with_file: sem_destroy(&tfo->tfo_exclsem); kmm_free(tfo); +errout_with_parent: + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + errout_with_copy: kmm_free(copy); return ret; } /**************************************************************************** - * name: tmpfs_find_object + * Name: tmpfs_alloc_directory + ****************************************************************************/ + +static FAR struct tmpfs_directory_s *tmpfs_alloc_directory(void) +{ + FAR struct tmpfs_directory_s *tdo; + size_t allocsize; + unsigned int nentries; + + /* Convert the pre-allocated memory to a number of directory entries */ + + nentries = (FS_TMPFS_DIRECTORY_ALLOCGUARD + + sizeof(struct tmpfs_dirent_s) - 1) / + sizeof(struct tmpfs_dirent_s); + + /* Create a new zero length directory object */ + + allocsize = SIZEOF_TMPFS_DIRECTORY(nentries); + tdo = (FAR struct tmpfs_directory_s *)kmm_malloc(allocsize); + if (tdo == NULL) + { + return NULL; + } + + /* Initialize the new directory object */ + + tdo->tdo_alloc = allocsize; + tdo->tdo_type = TMPFS_DIRECTORY; + tdo->tdo_refs = 1; + tdo->tdo_nentries = 0; + sem_init(&tdo->tdo_exclsem, 0, 0); + + return tdo; +} + +/**************************************************************************** + * Name: tmpfs_create_directory + ****************************************************************************/ + +static int tmpfs_create_directory(FAR struct tmpfs_s *fs, + FAR const char *relpath, + FAR struct tmpfs_directory_s **tdo) +{ + FAR struct tmpfs_directory_s *parent; + FAR struct tmpfs_directory_s *newtdo; + FAR char *copy; + FAR char *name; + + /* Duplicate the path variable so that we can modify it */ + + copy = strdup(relpath); + if (copy == NULL) + { + return -ENOMEM; + } + + /* Separate the path into the file name and the path to the parent + * directory. + */ + + name = strrchr(copy, '/'); + if (name == NULL) + { + /* No subdirectories... use the root directory */ + + name = copy; + parent = fs->tfs_root; + + tmpfs_lock_directory(parent); + parent->tdo_refs++; + } + else + { + /* Terminate the parent directory path */ + + *name++ = '\0'; + + /* Locate the parent directory that should contain this name. + * On success, tmpfs_find_directory() will lockthe parent + * directory and increment the reference count. + */ + + ret = tmpfs_find_directory(fs, copy, &parent, NULL); + if (ret < 0) + { + goto errout_with_copy; + } + } + + /* Verify that no object of this name already exists in the directory */ + + ret = tmpfs_find_dirent(parent, name); + if (ret != -ENOENT) + { + /* Something with this name already exists in the directory. + * OR perhaps some fatal error occurred. + */ + + if (ret >= 0) + { + ret = -EEXIST; + } + + goto errout_with_parent; + } + + /* Allocate an empty directory */ + + newtdo = tmpfs_alloc_directory(); + if (newtdo == NULL) + { + ret = -ENOMEM: + goto errout_with_parent; + } + + /* Then add the new, empty file to the directory */ + + ret = tmpfs_add_dirent(parent, (FAR struct tmpfs_object_s *)newtdo, name); + if (ret < 0) + { + goto errout_with_directory; + } + + /* Free the copy of the relpath, release our reference to the parent directory, + * and return success + */ + + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + kmm_free(copy); + + *tfo = newtdo; + return OK; + +/* Error exits */ + +errout_with_directory: + sem_destroy(&tfo->tfo_exclsem); + kmm_free(tfo); + +errout_with_parent: + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + +errout_with_copy: + kmm_free(copy); + return ret; +} + +/**************************************************************************** + * Name: tmpfs_find_object ****************************************************************************/ static int tmpfs_find_object(FAR struct tmpfs_s *fs, @@ -677,7 +843,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, } /**************************************************************************** - * name: tmpfs_find_file + * Name: tmpfs_find_file ****************************************************************************/ static int tmpfs_find_file(FAR struct tmpfs_s *fs, @@ -725,7 +891,7 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs, } /**************************************************************************** - * name: tmpfs_find_directory + * Name: tmpfs_find_directory ****************************************************************************/ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, @@ -770,7 +936,7 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, } /**************************************************************************** - * name: tmpfs_statfs_callout + * Name: tmpfs_statfs_callout ****************************************************************************/ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, @@ -824,7 +990,7 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, } /**************************************************************************** - * name: tmpfs_free_callout + * Name: tmpfs_free_callout ****************************************************************************/ static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, @@ -883,7 +1049,7 @@ static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, } /**************************************************************************** - * name: tmpfs_foreach + * Name: tmpfs_foreach ****************************************************************************/ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, @@ -956,7 +1122,7 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, } /**************************************************************************** - * name: tmpfs_open + * Name: tmpfs_open ****************************************************************************/ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, @@ -1091,7 +1257,7 @@ errout_with_fslock: } /**************************************************************************** - * name: tmpfs_close + * Name: tmpfs_close ****************************************************************************/ static int tmpfs_close(FAR struct file *filep) @@ -1141,7 +1307,7 @@ static int tmpfs_close(FAR struct file *filep) } /**************************************************************************** - * name: tmpfs_read + * Name: tmpfs_read ****************************************************************************/ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, @@ -1188,7 +1354,7 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, } /**************************************************************************** - * name: tmpfs_write + * Name: tmpfs_write ****************************************************************************/ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, @@ -1244,7 +1410,7 @@ errout_with_lock: } /**************************************************************************** - * name: tmpfs_seek + * Name: tmpfs_seek ****************************************************************************/ static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence) @@ -1304,7 +1470,7 @@ static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence) } /**************************************************************************** - * name: tmpfs_ioctl + * Name: tmpfs_ioctl ****************************************************************************/ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) @@ -1338,7 +1504,7 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } /**************************************************************************** - * name: tmpfs_dup + * Name: tmpfs_dup ****************************************************************************/ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) @@ -1372,7 +1538,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) } /**************************************************************************** - * name: tmpfs_opendir + * Name: tmpfs_opendir ****************************************************************************/ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, @@ -1420,7 +1586,7 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, } /**************************************************************************** - * name: tmpfs_closedir + * Name: tmpfs_closedir ****************************************************************************/ static int tmpfs_closedir(FAR struct inode *mountpt, @@ -1445,7 +1611,7 @@ static int tmpfs_closedir(FAR struct inode *mountpt, } /**************************************************************************** - * name: tmpfs_readdir + * Name: tmpfs_readdir ****************************************************************************/ static int tmpfs_readdir(FAR struct inode *mountpt, @@ -1509,7 +1675,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt, } /**************************************************************************** - * name: tmpfs_rewinddir + * Name: tmpfs_rewinddir ****************************************************************************/ static int tmpfs_rewinddir(FAR struct inode *mountpt, @@ -1528,7 +1694,7 @@ static int tmpfs_rewinddir(FAR struct inode *mountpt, } /**************************************************************************** - * name: tmpfs_bind + * Name: tmpfs_bind ****************************************************************************/ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, @@ -1557,7 +1723,7 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, } /**************************************************************************** - * name: tmpfs_unbind + * Name: tmpfs_unbind ****************************************************************************/ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, @@ -1584,7 +1750,7 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, } /**************************************************************************** - * name: tmpfs_statfs + * Name: tmpfs_statfs ****************************************************************************/ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) @@ -1599,9 +1765,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) DEBUGASSERT(mountpt != NULL && buf != NULL); - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ + /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); @@ -1649,7 +1813,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) } /**************************************************************************** - * name: tmpfs_unlink + * Name: tmpfs_unlink ****************************************************************************/ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) @@ -1662,13 +1826,9 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) DEBUGASSERT(mountpt != NULL && relpath != NULL); - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ - - inode = filep->f_inode; - fs = mountpt->i_private; + /* Get the file system structure from the inode reference. */ + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ @@ -1756,84 +1916,133 @@ errout_with_lock: } /**************************************************************************** - * name: tmpfs_mkdir + * Name: tmpfs_mkdir ****************************************************************************/ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode) { - FAR struct inode *inode; FAR struct tmpfs_s *fs; - FAR struct tmpfs_directory_s *parent; - FAR struct tmpfs_directory_s *tdo; - - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + int ret; - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ + DEBUGASSERT(mountpt != NULL && relpath != NULL); - inode = filep->f_inode; - fs = inode->i_private; + /* Get the file system structure from the inode reference. */ + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ -#warning Missing logic - /* Find the parent directory allocation associated with this relative path */ -#warning Missing logic - /* Does the directory already exist? */ -#warning Missing logic - /* Create the new, empty directory entry */ -#warning Missing logic - /* Add the nre directory entry to the parent directory */ -#warning Missing logic - /* Release the lock on the file system */ -#warning Missing logic - return OK; + tmpfs_lock(fs); + + /* Create the directory. This will lock the newly directory with a + * a reference count of one. + */ + + ret = tmpfs_create_directory(fs, relpath, NULL); + tmpfs_unlock(fs); + return ret; } /**************************************************************************** - * name: tmpfs_rmdir + * Name: tmpfs_rmdir ****************************************************************************/ static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) { - FAR struct inode *inode; FAR struct tmpfs_s *fs; FAR struct tmpfs_directory_s *parent; FAR struct tmpfs_directory_s *tdo; + FAR const char *name; + int ret; - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); - - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ + DEBUGASSERT(mountpt != NULL && relpath != NULL); - inode = filep->f_inode; - fs = inode->i_private; + /* Get the file system structure from the inode reference. */ + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ -#warning Missing logic - /* Find the directory allocation associated with this relative path */ -#warning Missing logic - /* Is the directory empty? */ -#warning Missing logic - /* Remove the directory entry from the parent structure */ -#warning Missing logic - /* Release the lock on the file system */ -#warning Missing logic + + tmpfs_lock(fs); + + /* Find the directory object and parent directory associated with this + * relative path. If successful, tmpfs_find_file will lock both the + * directory object and the parent directory and take one reference count + * on each. + */ + + ret = tmpfs_find_directory(fs, relpath, &tdo, &parent); + if (ret < 0) + { + goto errout_with_lock; + } + + /* Is the directory empty? We cannot remove directories that still + * contain references to file system objects. No can we remove the + * directory if there are outstanding references on it (other than + * our reference). + */ + + if (tdo->tdo_nentries > 0 || tdo->tdo_refs > 1) + { + ret = -EBUSY; + goto errout_with_objects; + } + + /* Get the directory name from the relative path */ + + name = strrchr(relpath, '/'); + if (name != NULL) + { + /* Skip over the fidirectoryle '/' character */ + + name++; + } + else + { + /* The name must lie in the root directory */ + + name = relpath; + } + + /* Remove the directory from parent directory */ + + ret = tmpfs_remove_dirent(parent, name); + if (ret < 0) + { + goto errout_with_objects; + } + /* Free the directory object */ -#warning Missing logic + + sem_destroy(&tfo->tdo_exclsem); + kmm_free(tdo); + + /* Release the reference and lock on the parent directory */ + + parent->tdo_refs--; + tmpfs_unlock_object(parent); + tmpfs_unlock(fs); return OK; + +errout_with_objects: + tdo->tdo_refs--; + tmpfs_unlock_directory(tdo); + + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + +errout_with_lock: + tmpfs_unlock(fs); + return ret; } /**************************************************************************** - * name: tmpfs_rename + * Name: tmpfs_rename ****************************************************************************/ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, @@ -1845,13 +2054,9 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ - - inode = filep->f_inode; - fs = inode->i_private; + /* Get the file system structure from the inode reference. */ + fs = mountpt->i_private; DEBUGASSERT(fs != NULL); /* Get exclusive access to the file system */ @@ -1869,7 +2074,7 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, } /**************************************************************************** - * name: tmpfs_stat + * Name: tmpfs_stat ****************************************************************************/ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, @@ -1882,9 +2087,7 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, DEBUGASSERT(mountpt != NULL && relpath != NULL && buf != NULL); - /* Get the mountpoint inode reference from the file structure and the - * mountpoint private data from the inode structure - */ + /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; DEBUGASSERT(fs != NULL); diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index 77035465e7..a668ce562a 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -118,7 +118,7 @@ struct tmpfs_directory_s }; #define SIZEOF_TMPFS_DIRECTORY(n) \ - (sizeof(struct tmpfs_directory_s) + ((n) - 1)*sizeof(struct tmpfs_dirent_s)) + (sizeof(struct tmpfs_directory_s) + ((n) - 1) * sizeof(struct tmpfs_dirent_s)) /* The form of a regular file memory object * -- GitLab From d359a5be132a7cdbf28e34233748d80877a4f0c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 11:02:59 -0600 Subject: [PATCH 206/858] TMPFS: Code complete, but not yet functional --- ChangeLog | 5 +- arch | 2 +- fs/Kconfig | 1 + fs/Makefile | 1 + fs/mount/fs_mount.c | 11 +- fs/tmpfs/fs_tmpfs.c | 665 +++++++++++++++++++++++++++++++------------- fs/tmpfs/fs_tmpfs.h | 44 ++- 7 files changed, 519 insertions(+), 210 deletions(-) diff --git a/ChangeLog b/ChangeLog index b55967c223..93e17112f5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11017,4 +11017,7 @@ temporary RAM file file system (2015-10-0i8). * tools/: Add crappy style checking tool nxstyle.c. See thee tools/ README file for more info (2015-10-08). - + * stm32 F4: Fix some TIM12 pin mappings. From Max Kriegleder + (2015-10-9). + * fs/tmpfs: TMPFS file system is code complete, but not yet functional + (2015-10-9). diff --git a/arch b/arch index 0b7bf8249b..00acafcbb1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0b7bf8249b1b96f5e31597b5242db222a2c29f73 +Subproject commit 00acafcbb154a076f60413eb75249c5b68c6c316 diff --git a/fs/Kconfig b/fs/Kconfig index a03a7445a4..91f4d10fad 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -57,6 +57,7 @@ source fs/fat/Kconfig source fs/nfs/Kconfig source fs/nxffs/Kconfig source fs/romfs/Kconfig +source fs/tmpfs/Kconfig source fs/smartfs/Kconfig source fs/binfs/Kconfig source fs/procfs/Kconfig diff --git a/fs/Makefile b/fs/Makefile index 9c30b61a97..58d9c2fb0e 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -64,6 +64,7 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) include mount/Make.defs include fat/Make.defs include romfs/Make.defs +include tmpfs/Make.defs include nxffs/Make.defs include nfs/Make.defs include smartfs/Make.defs diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 2aa5fc6faf..e2f116aa22 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/mount/fs_mount.c * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -77,7 +77,8 @@ /* These file systems do not require block drivers */ #if defined(CONFIG_FS_NXFFS) || defined(CONFIG_FS_BINFS) || \ - defined(CONFIG_FS_PROCFS) || defined(CONFIG_NFS) + defined(CONFIG_FS_PROCFS) || defined(CONFIG_NFS) || \ + defined(CONFIG_FS_TMPFS) # define NONBDFS_SUPPORT #endif @@ -102,6 +103,9 @@ extern const struct mountpt_operations fat_operations; #ifdef CONFIG_FS_ROMFS extern const struct mountpt_operations romfs_operations; #endif +#ifdef CONFIG_FS_TMPFS +extern const struct mountpt_operations tmpfs_operations; +#endif #ifdef CONFIG_FS_SMARTFS extern const struct mountpt_operations smartfs_operations; #endif @@ -140,6 +144,9 @@ static const struct fsmap_t g_nonbdfsmap[] = #ifdef CONFIG_FS_NXFFS { "nxffs", &nxffs_operations }, #endif +#ifdef CONFIG_FS_TMPFS + { "tmpfs", &tmpfs_operations }, +#endif #ifdef CONFIG_NFS { "nfs", &nfs_operations }, #endif diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 1d2b202bcb..90734e917f 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -42,9 +42,18 @@ #include #include #include +#include +#include +#include #include +#include +#include +#include +#include #include +#include +#include #include "fs_tmpfs.h" @@ -54,16 +63,14 @@ * Pre-processor Definitions ****************************************************************************/ -#define tmpfs_unlock(fs) (sem_post(&fs->tfs_exclsem)) - #define tmpfs_lock_file(tfo) \ (tmpfs_lock_object((FAR struct tmpfs_object_s *)tfo)) #define tmpfs_lock_directory(tdo) \ (tmpfs_lock_object((FAR struct tmpfs_object_s *)tdo)) - -#define tmpfs_unlock_object(to) (sem_post(&to->to_exclsem)) -#define tmpfs_unlock_file(tfo) (sem_post(&tfo->tfo_exclsem)) -#define tmpfs_unlock_directory(tdo) (sem_post(&tdo->tdo_exclsem)) +#define tmpfs_unlock_file(tfo) \ + (tmpfs_unlock_object((FAR struct tmpfs_object_s *)tfo)) +#define tmpfs_unlock_directory(tdo) \ + (tmpfs_unlock_object((FAR struct tmpfs_object_s *)tdo)) /**************************************************************************** * Private Types @@ -74,12 +81,18 @@ ****************************************************************************/ /* TMPFS helpers */ +static void tmpfs_lock_reentrant(FAR struct tmpfs_sem_s *sem); static void tmpfs_lock(FAR struct tmpfs_s *fs); +static void tmpfs_unlock_reentrant(FAR struct tmpfs_sem_s *sem); +static void tmpfs_unlock(FAR struct tmpfs_s *fs); static void tmpfs_lock_object(FAR struct tmpfs_object_s *to); +static void tmpfs_unlock_object(FAR struct tmpfs_object_s *to); static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, unsigned int nentries); static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, size_t newsize); +static void tmpfs_release_lockedobject(FAR struct tmpfs_object_s *to); +static void tmpfs_release_lockedfile(FAR struct tmpfs_file_s *tfo); static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, FAR const char *name); static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, @@ -108,7 +121,7 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, unsigned int index, FAR void *arg); static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, - tmpfs_foreach_t callout); + tmpfs_foreach_t callout, FAR void *arg); /* File system operations */ @@ -177,17 +190,51 @@ const struct mountpt_operations tmpfs_operations = ****************************************************************************/ /**************************************************************************** - * Name: tmpfs_lock + * Name: tmpfs_lock_reentrant ****************************************************************************/ -static void tmpfs_lock(FAR struct tmpfs_s *fs) +static void tmpfs_lock_reentrant(FAR struct tmpfs_sem_s *sem) { - int ret; + pid_t me; + + /* Do we already hold the semaphore? */ - while ((ret = sem_wait(&fs->tfs_exclsem)) < 0) + me = getpid(); + if (me == sem->ts_holder) { - DEBUGASSERT(errno == EINTR) + /* Yes... just increment the count */ + + sem->ts_count++; + DEBUGASSERT(sem->ts_count > 0); } + + /* Take the semaphore (perhaps waiting) */ + + else + { + while (sem_wait(&sem->ts_sem) != 0) + { + /* The only case that an error should occr here is if + * the wait was awakened by a signal. + */ + + DEBUGASSERT(get_errno() == EINTR); + } + + /* No we hold the semaphore */ + + sem->ts_holder = me; + sem->ts_count = 1; + } +} + +/**************************************************************************** + * Name: tmpfs_lock + ****************************************************************************/ + +static void tmpfs_lock(FAR struct tmpfs_s *fs) +{ + tmpfs_lock_reentrant(&fs->tfs_exclsem); } /**************************************************************************** @@ -196,14 +243,54 @@ static void tmpfs_lock(FAR struct tmpfs_s *fs) static void tmpfs_lock_object(FAR struct tmpfs_object_s *to) { - int ret; + tmpfs_lock_reentrant(&to->to_exclsem); +} - while ((ret = sem_wait(&to->to_exclsem)) < 0) +/**************************************************************************** + * Name: tmpfs_unlock_reentrant + ****************************************************************************/ + +static void tmpfs_unlock_reentrant(FAR struct tmpfs_sem_s *sem) +{ + DEBUGASSERT(sem->ts_holder == getpid()); + + /* Is this our last count on the semaphore? */ + + if (sem->ts_count > 1) + { + /* No.. just decrement the count */ + + sem->ts_count--; + } + + /* Yes.. then we can really release the semaphore */ + + else { - DEBUGASSERT(errno == EINTR) + sem->ts_holder = TMPFS_NO_HOLDER; + sem->ts_count = 0; + sem_post(&sem->ts_sem); } } +/**************************************************************************** + * Name: tmpfs_unlock + ****************************************************************************/ + +static void tmpfs_unlock(FAR struct tmpfs_s *fs) +{ + tmpfs_unlock_reentrant(&fs->tfs_exclsem); +} + +/**************************************************************************** + * Name: tmpfs_unlock_object + ****************************************************************************/ + +static void tmpfs_unlock_object(FAR struct tmpfs_object_s *to) +{ + tmpfs_unlock_reentrant(&to->to_exclsem); +} + /**************************************************************************** * Name: tmpfs_realloc_directory ****************************************************************************/ @@ -211,19 +298,19 @@ static void tmpfs_lock_object(FAR struct tmpfs_object_s *to) static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, unsigned int nentries) { - FAR struct tmpfs_directory_s *oldrdo = *tdo; - FAR struct tmpfs_directory_s *newrdo; + FAR struct tmpfs_directory_s *oldtdo = *tdo; + FAR struct tmpfs_directory_s *newtdo; size_t objsize; - int ret = oldrdo->tdo_nentries; + int ret = oldtdo->tdo_nentries; /* Get the new object size */ objsize = SIZEOF_TMPFS_DIRECTORY(nentries); - if (objsize <= oldrdo->tdo_alloc) + if (objsize <= oldtdo->tdo_alloc) { /* Already big enough */ - *oldrdo->tdo_nentries = nentries; + oldtdo->tdo_nentries = nentries; return OK; } @@ -235,19 +322,24 @@ static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, /* Realloc the directory object */ - newrdo = (FAR struct tmpfs_directory_s *)kmm_realloc(oldrdo, objsize); - if (newrdo == NULL) + newtdo = (FAR struct tmpfs_directory_s *)kmm_realloc(oldtdo, objsize); + if (newtdo == NULL) { return -ENOMEM; } - /* Return the new address of the reallocating directory object */ + /* Adjust the reference in the parent directory entry */ - newrdo->tdo_alloc = objsize; - *newrdo->tdo_nentries = nentries; - *tdo = newrdo; + DEBUGASSERT(newtdo->tdo_dirent); + newtdo->tdo_dirent->tde_object = (FAR struct tmpfs_object_s *)newtdo; - /* Return the index to the first, newly alloated directory entry */ + /* Return the new address of the reallocated directory object */ + + newtdo->tdo_alloc = objsize; + newtdo->tdo_nentries = nentries; + *tdo = newtdo; + + /* Return the index to the first, newly allocated directory entry */ return ret; } @@ -300,7 +392,7 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, } } - /* Realloc the directory object */ + /* Realloc the file object */ newtfo = (FAR struct tmpfs_file_s *)kmm_realloc(oldtfo, objsize); if (newtfo == NULL) @@ -308,7 +400,12 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, return -ENOMEM; } - /* Return the new address of the reallocating directory object */ + /* Adjust the reference in the parent directory entry */ + + DEBUGASSERT(newtfo->tfo_dirent); + newtfo->tfo_dirent->tde_object = (FAR struct tmpfs_object_s *)tfo; + + /* Return the new address of the reallocated file object */ newtfo->tfo_alloc = allocsize; newtfo->tfo_size = objsize; @@ -316,6 +413,54 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, return OK; } +/**************************************************************************** + * Name: tmpfs_release_lockedobject + ****************************************************************************/ + +static void tmpfs_release_lockedobject(FAR struct tmpfs_object_s *to) +{ + DEBUGASSERT(to && to->to_refs > 0); + + /* Is this a file object? */ + + if (to->to_type == TMPFS_REGULAR) + { + tmpfs_release_lockedfile((FAR struct tmpfs_file_s *)to); + } + else + { + to->to_refs--; + tmpfs_unlock_object(to); + } +} + +/**************************************************************************** + * Name: tmpfs_release_lockedfile + ****************************************************************************/ + +static void tmpfs_release_lockedfile(FAR struct tmpfs_file_s *tfo) +{ + DEBUGASSERT(tfo && tfo->tfo_refs > 0); + + /* If there are no longer any references to the file and the file has been + * unlinked from its parent directory, then free the file object now. + */ + + if (tfo->tfo_refs == 1 && (tfo->tfo_flags & TFO_FLAG_UNLINKED) != 0) + { + sem_destroy(&tfo->tfo_exclsem.ts_sem); + kmm_free(tfo); + } + + /* Otherwise, just decrement the reference count on the file object */ + + else + { + tfo->tfo_refs--; + tmpfs_unlock_file(tfo); + } +} + /**************************************************************************** * Name: tmpfs_find_dirent ****************************************************************************/ @@ -329,12 +474,12 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo, for (i = 0; i < tdo->tdo_nentries && - strcmp(tdo->tdo_entry[i].rde_name, name) != 0; + strcmp(tdo->tdo_entry[i].tde_name, name) != 0; i++); /* Return what we found, if anything */ - return i < tdo->tdo-nentries ? i : -ENOENT; + return i < tdo->tdo_nentries ? i : -ENOENT; } /**************************************************************************** @@ -357,9 +502,9 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, /* Free the object name */ - if (tdo->tdo_entry[index].rde_name != NULL) + if (tdo->tdo_entry[index].tde_name != NULL) { - kmm_free(tdo->tdo_entry[index].rde_name); + kmm_free(tdo->tdo_entry[index].tde_name); } /* Remove by replacing this entry with the final directory entry */ @@ -367,13 +512,13 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, last = tdo->tdo_nentries - 1; if (index != last) { - tdo->tdo_entry[index].rde_object = tdo->tdo_entry[last].rde_object; - tdo->tdo_entry[index].rde_name = tdo->tdo_entry[last].rde_name; + tdo->tdo_entry[index].tde_object = tdo->tdo_entry[last].tde_object; + tdo->tdo_entry[index].tde_name = tdo->tdo_entry[last].tde_name; } /* And decrement the count of directory entries */ - tdo->tdo_entries = last; + tdo->tdo_nentries = last; return OK; } @@ -387,7 +532,7 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, { FAR struct tmpfs_directory_s *oldtdo; FAR struct tmpfs_directory_s *newtdo; - FAR char newname; + FAR char *newname; unsigned int nentries; int index; @@ -395,7 +540,7 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, * directory entry. */ - newname = strdup(name) + newname = strdup(name); if (newname == NULL) { return -ENOMEM; @@ -411,17 +556,19 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, index = tmpfs_realloc_directory(tdo, nentries); if (index < 0) { - kmm_free(newname) + kmm_free(newname); return index; } /* Save the new object info in the new directory entry */ newtdo = *tdo; - newtdo->tdo_entry[index].tdo_object = to; - newtdo->tdo_entry[index].tdo_name = newname; + newtdo->tdo_entry[index].tde_object = to; + newtdo->tdo_entry[index].tde_name = newname; + + /* Add backward link to the directory entry to the object */ - kmm_free(newname); + to->to_dirent = &newtdo->tdo_entry[index]; return OK; } @@ -436,7 +583,7 @@ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) /* Create a new zero length file object */ - allocsize = SIZEOF_TMPFS_FILE(FS_TMPFS_FILE_ALLOCGUARD); + allocsize = SIZEOF_TMPFS_FILE(CONFIG_FS_TMPFS_FILE_ALLOCGUARD); tfo = (FAR struct tmpfs_file_s *)kmm_malloc(allocsize); if (tfo == NULL) { @@ -447,10 +594,13 @@ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) tfo->tfo_alloc = allocsize; tfo->tfo_type = TMPFS_REGULAR; - tfo->tfo_refs = 1; + tfo->tfo_refs = 0; tfo->tfo_flags = 0; tfo->tfo_size = 0; - sem_init(&tfo->tfo_exclsem, 0, 0); + + tfo->tfo_exclsem.ts_holder = TMPFS_NO_HOLDER; + tfo->tfo_exclsem.ts_count = 0; + sem_init(&tfo->tfo_exclsem.ts_sem, 0, 1); return tfo; } @@ -467,6 +617,7 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, FAR struct tmpfs_file_s *newtfo; FAR char *copy; FAR char *name; + int ret; /* Duplicate the path variable so that we can modify it */ @@ -531,13 +682,13 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, newtfo = tmpfs_alloc_file(); if (newtfo == NULL) { - ret = -ENOMEM: + ret = -ENOMEM; goto errout_with_parent; } /* Then add the new, empty file to the directory */ - ret = tmpfs_add_dirent(parent, (FAR struct tmpfs_object_s *)newtfo, name); + ret = tmpfs_add_dirent(&parent, (FAR struct tmpfs_object_s *)newtfo, name); if (ret < 0) { goto errout_with_file; @@ -552,8 +703,8 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, /* Error exits */ errout_with_file: - sem_destroy(&tfo->tfo_exclsem); - kmm_free(tfo); + sem_destroy(&newtfo->tfo_exclsem.ts_sem); + kmm_free(newtfo); errout_with_parent: parent->tdo_refs--; @@ -576,7 +727,7 @@ static FAR struct tmpfs_directory_s *tmpfs_alloc_directory(void) /* Convert the pre-allocated memory to a number of directory entries */ - nentries = (FS_TMPFS_DIRECTORY_ALLOCGUARD + + nentries = (CONFIG_FS_TMPFS_DIRECTORY_ALLOCGUARD + sizeof(struct tmpfs_dirent_s) - 1) / sizeof(struct tmpfs_dirent_s); @@ -591,11 +742,14 @@ static FAR struct tmpfs_directory_s *tmpfs_alloc_directory(void) /* Initialize the new directory object */ - tdo->tdo_alloc = allocsize; - tdo->tdo_type = TMPFS_DIRECTORY; - tdo->tdo_refs = 1; + tdo->tdo_alloc = allocsize; + tdo->tdo_type = TMPFS_DIRECTORY; + tdo->tdo_refs = 0; tdo->tdo_nentries = 0; - sem_init(&tdo->tdo_exclsem, 0, 0); + + tdo->tdo_exclsem.ts_holder = TMPFS_NO_HOLDER; + tdo->tdo_exclsem.ts_count = 0; + sem_init(&tdo->tdo_exclsem.ts_sem, 0, 1); return tdo; } @@ -612,6 +766,7 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, FAR struct tmpfs_directory_s *newtdo; FAR char *copy; FAR char *name; + int ret; /* Duplicate the path variable so that we can modify it */ @@ -676,13 +831,13 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, newtdo = tmpfs_alloc_directory(); if (newtdo == NULL) { - ret = -ENOMEM: + ret = -ENOMEM; goto errout_with_parent; } /* Then add the new, empty file to the directory */ - ret = tmpfs_add_dirent(parent, (FAR struct tmpfs_object_s *)newtdo, name); + ret = tmpfs_add_dirent(&parent, (FAR struct tmpfs_object_s *)newtdo, name); if (ret < 0) { goto errout_with_directory; @@ -696,14 +851,14 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, tmpfs_unlock_directory(parent); kmm_free(copy); - *tfo = newtdo; + *tdo = newtdo; return OK; /* Error exits */ errout_with_directory: - sem_destroy(&tfo->tfo_exclsem); - kmm_free(tfo); + sem_destroy(&newtdo->tdo_exclsem.ts_sem); + kmm_free(newtdo); errout_with_parent: parent->tdo_refs--; @@ -725,10 +880,9 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, { FAR struct tmpfs_object_s *to; FAR struct tmpfs_directory_s *tdo; - FAR struct tmpfs_directory_s *next_rdo; + FAR struct tmpfs_directory_s *next_tdo; FAR char *segment; FAR char *next_segment; - FAR char *last; FAR char *tkptr; FAR char *copy; int index; @@ -738,13 +892,13 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, copy = strdup(relpath); if (copy == NULL) { - return NULL; + return -ENOMEM; } /* Traverse the file system for any object with the matching name */ - to = (FAR struct tmpfs_object_s)fs->root; - next_rdo = fs->tfs_root; + to = (FAR struct tmpfs_object_s *)fs->tfs_root; + next_tdo = fs->tfs_root; for (segment = strtok_r(copy, "/", &tkptr); segment != NULL; @@ -759,7 +913,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, /* Search the the next directory. */ - tdo = next_rdo; + tdo = next_tdo; /* Find the TMPFS object with the next segment name in the current * directory. @@ -773,7 +927,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, return index; } - to = tdo->tdo_entry[index]; + to = tdo->tdo_entry[index].tde_object; /* Is this object another directory? */ @@ -801,7 +955,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, * directory of to. */ - next_rdo = (FAR struct tmpfs_directory_s *)to; + next_tdo = (FAR struct tmpfs_directory_s *)to; } /* When we exit this loop (successfully), to will point to the TMPFS @@ -821,8 +975,8 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, * count on the object. */ - tmpfs_lock_object(parent); - parent->tdo_refs++; + tmpfs_lock_directory(tdo); + tdo->tdo_refs++; *parent = tdo; } @@ -868,15 +1022,14 @@ static int tmpfs_find_file(FAR struct tmpfs_s *fs, { /* No... unlock the object and its parent and return an error */ - to->to_refs++; -#warning Add check if the file system became unlinked - tmpfs_unlock_object(to); + tmpfs_release_lockedobject(to); if (parent) { - tdo = *parent; + FAR struct tmpfs_directory_s *tdo = *parent; + tdo->tdo_refs--; - tmpfs_unlock_object(to); + tmpfs_unlock_directory(tdo); } ret = -EISDIR; @@ -911,17 +1064,16 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, if (to->to_type != TMPFS_DIRECTORY) { - /* No... unlock it and return an error */ + /* No... unlock the object and its parent and return an error */ - to->to_refs++; -#warning Add check if the file system became unlinked - tmpfs_unlock_object(to); + tmpfs_release_lockedobject(to); if (parent) { - tdo = *parent; - tdo->tdo_refs--; - tmpfs_unlock_object(to); + FAR struct tmpfs_directory_s *tmptdo = *parent; + + tmptdo->tdo_refs--; + tmpfs_unlock_directory(tmptdo); } ret = -ENOTDIR; @@ -929,7 +1081,7 @@ static int tmpfs_find_directory(FAR struct tmpfs_s *fs, /* Return the verified file object */ - *tdo = (FAR struct tmpfs_file_s *)to; + *tdo = (FAR struct tmpfs_directory_s *)to; } return ret; @@ -945,32 +1097,34 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, FAR struct tmpfs_object_s *to; FAR struct tmpfs_statfs_s *tmpbuf; - DEBUASSERT(tdo != NULL && arg != NULL); + DEBUGASSERT(tdo != NULL && arg != NULL && index < tdo->tdo_nentries); - to = &tdo->tdo_entry[index]; + to = tdo->tdo_entry[index].tde_object; tmpbuf = (FAR struct tmpfs_statfs_s *)arg; + DEBUGASSERT(to != NULL); + /* Accumulate statistics. Save the total memory allocted for this object. */ - tmpbuf.tsf_alloc += to->to_alloc; + tmpbuf->tsf_alloc += to->to_alloc; /* Is this directory entry a file object? */ - if (to->to_type = TMPFS_REGULAR) + if (to->to_type == TMPFS_REGULAR) { - FAR struct tmpfs_object_s *tmptfo; + FAR struct tmpfs_file_s *tmptfo; /* It is a file object. Increment the number of files and update the * amount of memory in use. */ - tmptfo = (FAR struct tmpfs_file_s *)to; - tmpbuf.tsf_inuse += tmptfo->tfo_size; - tmpbuf.tsf_files++; + tmptfo = (FAR struct tmpfs_file_s *)to; + tmpbuf->tsf_inuse += tmptfo->tfo_size; + tmpbuf->tsf_files++; } - else /* if (to->to_type = TMPFS_DIRECTORY) */ + else /* if (to->to_type == TMPFS_DIRECTORY) */ { - FAR struct tmpfs_object_s *tmptdo; + FAR struct tmpfs_directory_s *tmptdo; size_t inuse; size_t avail; @@ -979,11 +1133,11 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, */ tmptdo = (FAR struct tmpfs_directory_s *)to; - inuse = SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); - avail = tdo->tdo_alloc - inuse; + inuse = SIZEOF_TMPFS_DIRECTORY(tmptdo->tdo_nentries); + avail = tmptdo->tdo_alloc - inuse; - tmpbuf.tsf_inuse += inuse; - tmpbuf.tsf_ffree += avail / sizeof(struct tmpfs_dirent_s); + tmpbuf->tsf_inuse += inuse; + tmpbuf->tsf_ffree += avail / sizeof(struct tmpfs_dirent_s); } return TMPFS_CONTINUE; @@ -996,37 +1150,40 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo, static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, unsigned int index, FAR void *arg) { + FAR struct tmpfs_dirent_s *tde; FAR struct tmpfs_object_s *to; - FAR struct tmpfs_object_s *tmp; FAR struct tmpfs_file_s *tfo; unsigned int last; /* Free the object name */ - if (tdo->tdo_entry[index].rde_name != NULL) + if (tdo->tdo_entry[index].tde_name != NULL) { - kmm_free(tdo->tdo_entry[index].rde_name); + kmm_free(tdo->tdo_entry[index].tde_name); } /* Remove by replacing this entry with the final directory entry */ - to = &tdo->tdo_entry[index]; + tde = &tdo->tdo_entry[index]; + to = tde->tde_object; last = tdo->tdo_nentries - 1; if (index != last) { - tmp = &tdo->tdo_entry[last]; - to->rde_object = tmp->rde_object; - to->rde_name = tmp->rde_name; + FAR struct tmpfs_dirent_s *tmp; + + tmp = &tdo->tdo_entry[last]; + tde->tde_object = tmp->tde_object; + tde->tde_name = tmp->tde_name; } /* And decrement the count of directory entries */ - tdo->tdo_entries = last; + tdo->tdo_nentries = last; /* Is this directory entry a file object? */ - if (to->to_type = TMPFS_REGULAR) + if (to->to_type == TMPFS_REGULAR) { tfo = (FAR struct tmpfs_file_s *)to; @@ -1043,7 +1200,7 @@ static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, /* Free the object now */ - sem_destroy(&to->to_excsem); + sem_destroy(&to->to_exclsem.ts_sem); kmm_free(to); return TMPFS_DELETED; } @@ -1053,7 +1210,7 @@ static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, ****************************************************************************/ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, - tmpfs_foreach_t callout) + tmpfs_foreach_t callout, FAR void *arg) { FAR struct tmpfs_object_s *to; unsigned int index; @@ -1061,7 +1218,7 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, /* Visit each directory entry */ - for (index = 0; ; index < tdo->tdo_nentries) + for (index = 0; index < tdo->tdo_nentries; ) { /* Lock the object and take a reference */ @@ -1089,29 +1246,26 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, /* Perform the callout */ - ret = callout(tdo, index); + ret = callout(tdo, index, arg); switch (ret) { case TMPFS_CONTINUE: /* Continue enumeration */ /* Release the object and index to the next entry */ - to->to_refs--; - tmpfs_unlock_object(to); + tmpfs_release_lockedobject(to); index++; break; case TMPFS_HALT: /* Stop enumeration */ /* Release the object and cancel the traversal */ - to->to_refs--; - tmpfs_unlock_object(to); + tmpfs_release_lockedobject(to); return -ECANCELED; - case TTMPFS_UNLINKED: /* Only the directory entry was deleted */ + case TMPFS_UNLINKED: /* Only the directory entry was deleted */ /* Release the object and continue with the same index */ - to->to_refs--; - tmpfs_unlock_object(to); + tmpfs_release_lockedobject(to); case TMPFS_DELETED: /* Object and directory entry deleted */ break; /* Continue with the same index */ @@ -1133,7 +1287,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, FAR struct tmpfs_file_s *tfo; int ret; - fvdbg("filep: %p", filep); + fvdbg("filep: %p\n", filep); DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); /* Get the mountpoint inode reference from the file structure and the @@ -1143,7 +1297,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, inode = filep->f_inode; fs = inode->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -1194,7 +1348,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, if (tfo->tfo_size > 0) { - ret = tmpfs_realloc_file(tfo, 0); + ret = tmpfs_realloc_file(&tfo, 0); if (ret < 0) { goto errout_with_filelock; @@ -1248,8 +1402,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, /* Error exits */ errout_with_filelock: - tfo->tfo_refs--; - tmpfs_unlock_file(tfo); + tmpfs_release_lockedfile(tfo); errout_with_fslock: tmpfs_unlock(fs); @@ -1264,7 +1417,7 @@ static int tmpfs_close(FAR struct file *filep) { FAR struct tmpfs_file_s *tfo; - fvdbg("filep: %p", filep); + fvdbg("filep: %p\n", filep); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -1289,7 +1442,7 @@ static int tmpfs_close(FAR struct file *filep) * unlinked, then free the file allocation now. */ - if (tfo->tfo_refs == 0 && (tfo->flags & TFO_FLAG_UNLINKED) != 0) + if (tfo->tfo_refs == 0 && (tfo->tfo_flags & TFO_FLAG_UNLINKED) != 0) { /* Free the file object while we hold the lock? Weird but this * should be safe because the object is unlinked and could not @@ -1318,7 +1471,7 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, off_t startpos; off_t endpos; - fvdbg("filep: %p buffer: %p buflen: %lu", + fvdbg("filep: %p buffer: %p buflen: %lu\n", filep, buffer, (unsigned long)buflen); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); @@ -1344,12 +1497,11 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, /* Copy data from the memory object to the user buffer */ - memcpy(buffer, &tfo->tfo_data, nread) + memcpy(buffer, &tfo->tfo_data, nread); /* Release the lock on the file */ - tmpfs_file_unlock - + tmpfs_unlock_file(tfo); return nread; } @@ -1366,7 +1518,7 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, off_t endpos; int ret; - fvdbg("filep: %p buffer: %p buflen: %lu", + fvdbg("filep: %p buffer: %p buflen: %lu\n", filep, buffer, (unsigned long)buflen); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); @@ -1388,24 +1540,26 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, { /* Reallocate the file to handle the write past the end of the file. */ - ret = tmpfs_realloc_file(tfo, (size_t)endpos); + ret = tmpfs_realloc_file(&tfo, (size_t)endpos); if (ret < 0) { goto errout_with_lock; } + + filep->f_priv = tfo; } /* Copy data from the memory object to the user buffer */ - memcpy(&tfo->tfo_data, buffer, nwritten) + memcpy(&tfo->tfo_data, buffer, nwritten); /* Release the lock on the file */ - tmpfs_file_unlock(tfo); + tmpfs_unlock_file(tfo); return nwritten; errout_with_lock: - tmpfs_file_unlock(tfo); + tmpfs_unlock_file(tfo); return (ssize_t)ret; } @@ -1418,7 +1572,7 @@ static off_t tmpfs_seek(FAR struct file *filep, off_t offset, int whence) FAR struct tmpfs_file_s *tfo; off_t position; - fvdbg("filep: %p", filep); + fvdbg("filep: %p\n", filep); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -1489,7 +1643,7 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Only one ioctl command is supported */ - if (cmd == FIOC_MMAP && tfo->rm_xipbase && ppv) + if (cmd == FIOC_MMAP && ppv != NULL) { /* Return the address on the media corresponding to the start of * the file. @@ -1499,7 +1653,7 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return OK; } - fdbg("Invalid cmd: %d \n", cmd); + fdbg("Invalid cmd: %d\n", cmd); return -ENOTTY; } @@ -1512,10 +1666,8 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) FAR struct tmpfs_file_s *tfo; fvdbg("Dup %p->%p\n", oldp, newp); - DEBUGASSERT(oldp->f_priv != NULL && - oldp->f_inode != NULL != NULL && - newp->f_priv == NULL && - newp->f_inode != NULL); + DEBUGASSERT(oldp->f_priv != NULL && oldp->f_inode != NULL && + newp->f_priv == NULL && newp->f_inode != NULL); /* Recover our private data from the struct file instance */ @@ -1526,7 +1678,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) tmpfs_lock_file(tfo); tfo->tfo_refs++; - tmpfs_lunock_file(tfo); + tmpfs_unlock_file(tfo); /* Save a copy of the file object as the dup'ed file. This * simple implementation does not many any per-open data @@ -1548,14 +1700,14 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, FAR struct tmpfs_directory_s *tdo; int ret; - fvdbg("mountpt: %p relpath: %s dir: %p", + fvdbg("mountpt: %p relpath: %s dir: %p\n", mountpt, relpath, dir); DEBUGASSERT(mountpt != NULL && relpath != NULL && dir != NULL); /* Get the mountpoint private data from the inode structure */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -1594,7 +1746,7 @@ static int tmpfs_closedir(FAR struct inode *mountpt, { FAR struct tmpfs_directory_s *tdo; - fvdbg("mountpt: %p dir: %p", mountpt, dir); + fvdbg("mountpt: %p dir: %p\n", mountpt, dir); DEBUGASSERT(mountpt != NULL && dir != NULL); /* Get the directory structure from the dir argument */ @@ -1621,7 +1773,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt, unsigned int index; int ret; - fvdbg("mountpt: %p dir: %p", mountpt, dir); + fvdbg("mountpt: %p dir: %p\n", mountpt, dir); DEBUGASSERT(mountpt != NULL && dir != NULL); /* Get the directory structure from the dir argument and lock it */ @@ -1634,7 +1786,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt, /* Have we reached the end of the directory? */ index = dir->u.tmpfs.tf_index; - if (index > = tdo->tdo_nentries) + if (index >= tdo->tdo_nentries) { /* We signal the end of the directory by returning the special error: * -ENOENT @@ -1645,15 +1797,22 @@ static int tmpfs_readdir(FAR struct inode *mountpt, } else { + FAR struct tmpfs_dirent_s *tde; + FAR struct tmpfs_object_s *to; + /* Does this entry refer to a file or a directory object? */ - if (tdo->tdo_entry[index].to_type == TMPFS_DIRECTORY) + tde = &tdo->tdo_entry[index]; + to = tde->tde_object; + DEBUGASSERT(to != NULL); + + if (to->to_type == TMPFS_DIRECTORY) { /* A directory */ dir->fd_dir.d_type = DTYPE_DIRECTORY; } - else /* tdo->tdo_entry[index].to_type == TMPFS_REGULAR) */ + else /* to->to_type == TMPFS_REGULAR) */ { /* A regular file */ @@ -1662,7 +1821,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt, /* Copy the entry name */ - strncpy(d_name, tdo->tdo_entry[index].to_name, NAME_MAX + 1); + strncpy(dir->fd_dir.d_name, tde->tde_name, NAME_MAX + 1); /* Increment the index for next time */ @@ -1681,10 +1840,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt, static int tmpfs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { - FAR struct tmpfs_directory_s *tdo; - int ret; - - fvdbg("mountpt: %p dir: %p", mountpt, dir); + fvdbg("mountpt: %p dir: %p\n", mountpt, dir); DEBUGASSERT(mountpt != NULL && dir != NULL); /* Set the readdir index to zero */ @@ -1702,7 +1858,8 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, { FAR struct tmpfs_s *fs; - DEBUGSSERT(blkdriver == NULL && handle != NULL); + fvdbg("blkdriver: %p data: %p handle: %p\n", blkdriver, data, handle); + DEBUGASSERT(blkdriver == NULL && handle != NULL); /* Create an instance of the tmpfs file system */ @@ -1712,9 +1869,20 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, return -ENOMEM; } + /* Create a root file system */ + + fs->tfs_root = tmpfs_alloc_directory(); + if (fs->tfs_root == NULL) + { + kmm_free(fs); + return -ENOMEM; + } + /* Initialize the file system state */ - sem_init(&fs->tfs_exclsem, 0, 1); + fs->tfs_exclsem.ts_holder = TMPFS_NO_HOLDER; + fs->tfs_exclsem.ts_count = 0; + sem_init(&fs->tfs_exclsem.ts_sem, 0, 1); /* Return the new file system handle */ @@ -1729,10 +1897,14 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { - FAR struct tmpfs_s *fs = (FAR struct tmpfs_s *fs)handle; + FAR struct tmpfs_s *fs = (FAR struct tmpfs_s *)handle; + FAR struct tmpfs_directory_s *tdo; int ret; - DEBUGSSERT(blkdriver == NULL && handle != NULL); + fvdbg("handle: %p blkdriver: %p flags: %02x\n", + handle, blkdriver, flags); + DEBUGASSERT(blkdriver == NULL && handle != NULL); + DEBUGASSERT(fs == NULL && fs->tfs_root != NULL); /* Lock the file system */ @@ -1740,11 +1912,15 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, /* Traverse all directory entries (recursively), freeing all resources. */ - ret = tmpfs_foreach(fs->tfs_root, tmpfs_free_callout); + tdo = fs->tfs_root; + ret = tmpfs_foreach(tdo, tmpfs_free_callout, NULL); + + /* Now we can destroy the root file system and the file system itself. */ - /* Now we can destroy the filesystem itself. */ + sem_destroy(&tdo->tdo_exclsem.ts_sem); + kmm_free(tdo); - sem_destroy(&fs->tfs_exclsem); + sem_destroy(&fs->tfs_exclsem.ts_sem); kmm_free(fs); return ret; } @@ -1762,6 +1938,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) size_t avail; off_t blkalloc; off_t blkused; + int ret; DEBUGASSERT(mountpt != NULL && buf != NULL); @@ -1804,7 +1981,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) buf->f_bfree = blkalloc - blkused; buf->f_bavail = blkalloc - blkused; buf->f_files = tmpbuf.tsf_files; - buf->f_ffree = tmpbuf.tsf_free; + buf->f_ffree = tmpbuf.tsf_ffree; /* Release the lock on the file system */ @@ -1829,7 +2006,7 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -1874,7 +2051,7 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) * unlinked */ - if (tfo->tfo_refx > 1) + if (tfo->tfo_refs > 1) { /* Make the file object as unlinked */ @@ -1883,32 +2060,30 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) /* Release the reference count on the file object */ tfo->tfo_refs--; - tmpfs_unlock_object(tfo); + tmpfs_unlock_file(tfo); } /* Otherwise we can free the object now */ else { - sem_destroy(&tfo->tfo_exclsem); + sem_destroy(&tfo->tfo_exclsem.ts_sem); kmm_free(tfo); } /* Release the reference and lock on the parent directory */ tdo->tdo_refs--; - tmpfs_unlock_object(tdo); + tmpfs_unlock_directory(tdo); tmpfs_unlock(fs); return OK; errout_with_objects: - tfo->tfo_refs--; -#warning Add check if the file system became unlinked - tmpfs_unlock_object(tfo); + tmpfs_release_lockedfile(tfo); tdo->tdo_refs--; - tmpfs_unlock_object(tdo); + tmpfs_unlock_directory(tdo); errout_with_lock: tmpfs_unlock(fs); @@ -1930,7 +2105,7 @@ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -1962,7 +2137,7 @@ static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -2018,13 +2193,13 @@ static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) /* Free the directory object */ - sem_destroy(&tfo->tdo_exclsem); + sem_destroy(&tdo->tdo_exclsem.ts_sem); kmm_free(tdo); /* Release the reference and lock on the parent directory */ parent->tdo_refs--; - tmpfs_unlock_object(parent); + tmpfs_unlock_directory(parent); tmpfs_unlock(fs); return OK; @@ -2048,29 +2223,138 @@ errout_with_lock: static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, FAR const char *newrelpath) { - FAR struct inode *inode; + FAR struct tmpfs_directory_s *oldparent; + FAR struct tmpfs_directory_s *newparent; + FAR struct tmpfs_object_s *to; FAR struct tmpfs_s *fs; - FAR struct tmpfs_file_s *tfo; + FAR const char *oldname; + FAR char *newname; + FAR char *copy; + int ret; - DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); + DEBUGASSERT(mountpt != NULL && oldrelpath != NULL && newrelpath != NULL); /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + + /* Duplicate the newpath variable so that we can modify it */ + + copy = strdup(newrelpath); + if (copy == NULL) + { + return -ENOMEM; + } /* Get exclusive access to the file system */ -#warning Missing logic - /* Find the file allocation associated with this relative path */ -#warning Missing logic - /* If the file was found, free its name allocation and repace the name - * with the new name. + + tmpfs_lock(fs); + + /* Separate the new path into the new file name and the path to the new + * parent directory. */ -#warning Missing logic - /* Release the lock on the file system */ -#warning Missing logic - return OK; + newname = strrchr(copy, '/'); + if (newname == NULL) + { + /* No subdirectories... use the root directory */ + + newname = copy; + newparent = fs->tfs_root; + + tmpfs_lock_directory(newparent); + newparent->tdo_refs++; + } + else + { + /* Terminate the parent directory path */ + + *newname++ = '\0'; + + /* Locate the parent directory that should contain this name. + * On success, tmpfs_find_directory() will lockthe parent + * directory and increment the reference count. + */ + + ret = tmpfs_find_directory(fs, copy, &newparent, NULL); + if (ret < 0) + { + goto errout_with_lock; + } + } + + /* Verify that no object of this name already exists in the destination + * directory. + */ + + ret = tmpfs_find_dirent(newparent, newname); + if (ret != -ENOENT) + { + /* Something with this name already exists in the directory. + * OR perhaps some fatal error occurred. + */ + + if (ret >= 0) + { + ret = -EEXIST; + } + + goto errout_with_newparent; + } + + /* Find the old object at oldpath. If successful, tmpfs_find_object() + * will lock both the object and the parent directory and will increment + * the reference count on both. + */ + + ret = tmpfs_find_object(fs, oldrelpath, &to, &oldparent); + if (ret < 0) + { + goto errout_with_newparent; + } + + /* Get the old file name from the relative path */ + + oldname = strrchr(oldrelpath, '/'); + if (oldname != NULL) + { + /* Skip over the file '/' character */ + + oldname++; + } + else + { + /* The name must lie in the root directory */ + + oldname = oldrelpath; + } + + /* Remove the entry from the parent directory */ + + ret = tmpfs_remove_dirent(oldparent, oldname); + if (ret < 0) + { + goto errout_with_oldparent; + } + + /* Add an entry to the new parent directory. */ + + ret = tmpfs_add_dirent(&newparent, to, newname); + +errout_with_oldparent: + oldparent->tdo_refs--; + tmpfs_unlock_directory(oldparent); + + tmpfs_release_lockedobject(to); + +errout_with_newparent: + newparent->tdo_refs--; + tmpfs_unlock_directory(newparent); + +errout_with_lock: + tmpfs_unlock(fs); + return ret; } /**************************************************************************** @@ -2090,7 +2374,7 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Get exclusive access to the file system */ @@ -2144,14 +2428,11 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, buf->st_blksize = TMPFS_BLOCKSIZE; buf->st_blocks = (objsize + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; - /* No... unlock the object and return and return success */ + /* No... unlock the object and return success */ + tmpfs_release_lockedobject(to); ret = OK; - to->to_refs--; -#warning Add check if the file system became unlinked - tmpfs_unlock_object(to); - errout_with_fslock: tmpfs_unlock(fs); return ret; diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index a668ce562a..18233b0340 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -47,8 +47,6 @@ #include -#ifndef CONFIG_DISABLE_MOUNTPOINT - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -56,6 +54,10 @@ #define TMPFS_BLOCKSIZE 512 +/* Indicates that there is no holder of the re-entrant semaphore */ + +#define TMPFS_NO_HOLDER -1 + /* Bit definitions for file object flags */ #define TFO_FLAG_UNLINKED (1 << 0) /* Bit 0: File is unlinked */ @@ -82,22 +84,33 @@ enum tmpfs_foreach_e TMPFS_UNLINKED /* Only the directory entry was deleted */ }; -/* The generic form of a TMPFS memory object */ +/* Re-entrant semaphore */ -struct tmpfs_object_s +struct tmpfs_sem_s { - size_t to_alloc; /* Allocated size of the memory object */ - uint8_t to_type; /* See enum tmpfs_objtype_e */ - uint8_t to_refs; /* Reference count */ - sem_t to_exclsem; /* Supports exclusive access to the object */ + sem_t ts_sem; /* The actual semaphore */ + pid_t ts_holder; /* Current older (-1 if not held) */ + uint16_t ts_count; /* Number of counts held */ }; /* The form of one directory entry */ struct tmpfs_dirent_s { - FAR struct tmpfs_object_s *rde_object; - FAR char *rde_name; + FAR struct tmpfs_object_s *tde_object; + FAR char *tde_name; +}; + +/* The generic form of a TMPFS memory object */ + +struct tmpfs_object_s +{ + FAR struct tmpfs_dirent_s *to_dirent; + struct tmpfs_sem_s to_exclsem; + + size_t to_alloc; /* Allocated size of the memory object */ + uint8_t to_type; /* See enum tmpfs_objtype_e */ + uint8_t to_refs; /* Reference count */ }; /* The form of a directory memory object */ @@ -106,10 +119,12 @@ struct tmpfs_directory_s { /* First fields must match common TMPFS object layout */ + FAR struct tmpfs_dirent_s *tdo_dirent; + struct tmpfs_sem_s tdo_exclsem; + size_t tdo_alloc; /* Allocated size of the directory object */ uint8_t tdo_type; /* See enum tmpfs_objtype_e */ uint8_t tdo_refs; /* Reference count */ - sem_t tdo_exclsem; /* Supports exclusive access to the directory */ /* Remaining fields are unique to a directory object */ @@ -132,10 +147,12 @@ struct tmpfs_file_s { /* First fields must match common TMPFS object layout */ + FAR struct tmpfs_dirent_s *tfo_dirent; + struct tmpfs_sem_s tfo_exclsem; + size_t tfo_alloc; /* Allocated size of the file object */ uint8_t tfo_type; /* See enum tmpfs_objtype_e */ uint8_t tfo_refs; /* Reference count */ - sem_t tfo_exclsem; /* Supports exclusive access to the file */ /* Remaining fields are unique to a directory object */ @@ -153,8 +170,7 @@ struct tmpfs_s /* The root directory */ FAR struct tmpfs_directory_s *tfs_root; - - sem_t tfs_exclsem; /* Supports exclusive access to the file system */ + struct tmpfs_sem_s tfs_exclsem; }; /* This is the type used the tmpfs_statfs_callout to accumulate memory usage */ -- GitLab From 9eb92268b7f64103a122db940a1a2f4bff188f6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 12:13:57 -0600 Subject: [PATCH 207/858] TMPFS: Fixes a few bugs. Still not fully functional --- fs/tmpfs/fs_tmpfs.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 90734e917f..9582d7336d 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -590,17 +590,19 @@ static FAR struct tmpfs_file_s *tmpfs_alloc_file(void) return NULL; } - /* Initialize the new file object */ + /* Initialize the new file object. NOTE that the initial state is + * locked with one reference count. + */ tfo->tfo_alloc = allocsize; tfo->tfo_type = TMPFS_REGULAR; - tfo->tfo_refs = 0; + tfo->tfo_refs = 1; tfo->tfo_flags = 0; tfo->tfo_size = 0; - tfo->tfo_exclsem.ts_holder = TMPFS_NO_HOLDER; - tfo->tfo_exclsem.ts_count = 0; - sem_init(&tfo->tfo_exclsem.ts_sem, 0, 1); + tfo->tfo_exclsem.ts_holder = getpid(); + tfo->tfo_exclsem.ts_count = 1; + sem_init(&tfo->tfo_exclsem.ts_sem, 0, 0); return tfo; } @@ -677,7 +679,9 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, goto errout_with_parent; } - /* Allocate an empty file */ + /* Allocate an empty file. The initial state of the file is locked with one + * reference count. + */ newtfo = tmpfs_alloc_file(); if (newtfo == NULL) @@ -826,7 +830,9 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, goto errout_with_parent; } - /* Allocate an empty directory */ + /* Allocate an empty directory object. There is no reference on the new + * directory and the object is not locked. + */ newtdo = tmpfs_alloc_directory(); if (newtdo == NULL) @@ -1373,7 +1379,9 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, goto errout_with_fslock; } - /* Yes.. create the file object. */ + /* Yes.. create the file object. There will be a reference and a lock + * on the new file object. + */ ret = tmpfs_create_file(fs, relpath, &tfo); if (ret < 0) @@ -1393,7 +1401,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, filep->f_priv = tfo; - /* Unlock the file object, but retain the reference count */ + /* Unlock the file file object, but retain the reference count */ tmpfs_unlock_file(tfo); tmpfs_unlock(fs); @@ -1674,7 +1682,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) tfo = oldp->f_inode->i_private; DEBUGASSERT(tfo != NULL); - /* Increment the reference count */ + /* Increment the reference count (atomically)*/ tmpfs_lock_file(tfo); tfo->tfo_refs++; @@ -1685,7 +1693,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) * structures so there is not really much to the dup operation. */ - oldp->f_inode->i_private = tfo; + newp->f_inode->i_private = tfo; return OK; } @@ -1940,6 +1948,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) off_t blkused; int ret; + fvdbg("mountpt: %p buf: %p\n", mountpt, buf); DEBUGASSERT(mountpt != NULL && buf != NULL); /* Get the file system structure from the inode reference. */ @@ -2001,6 +2010,7 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) FAR const char *name; int ret; + fvdbg("mountpt: %p relpath: %s\n", mountpt, relpath); DEBUGASSERT(mountpt != NULL && relpath != NULL); /* Get the file system structure from the inode reference. */ @@ -2100,6 +2110,7 @@ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, FAR struct tmpfs_s *fs; int ret; + fvdbg("mountpt: %p relpath: %s mode: %04x\n", mountpt, relpath, mode); DEBUGASSERT(mountpt != NULL && relpath != NULL); /* Get the file system structure from the inode reference. */ @@ -2132,6 +2143,7 @@ static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) FAR const char *name; int ret; + fvdbg("mountpt: %p relpath: %s\n", mountpt, relpath); DEBUGASSERT(mountpt != NULL && relpath != NULL); /* Get the file system structure from the inode reference. */ @@ -2232,6 +2244,8 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, FAR char *copy; int ret; + fvdbg("mountpt: %p oldrelpath: %s newrelpath: %s\n", + mountpt, oldrelpath, newrelpath); DEBUGASSERT(mountpt != NULL && oldrelpath != NULL && newrelpath != NULL); /* Get the file system structure from the inode reference. */ @@ -2369,6 +2383,7 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, size_t objsize; int ret; + fvdbg("mountpt=%p relpath=%s buf=%p\n", mountpt, relpath, buf); DEBUGASSERT(mountpt != NULL && relpath != NULL && buf != NULL); /* Get the file system structure from the inode reference. */ -- GitLab From c25adcb74c0258c09d3600cef5d6732cd9bf7beb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 13:33:28 -0600 Subject: [PATCH 208/858] TMPFS: More fixes --- fs/tmpfs/fs_tmpfs.c | 79 +++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 9582d7336d..639177936c 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -63,6 +63,14 @@ * Pre-processor Definitions ****************************************************************************/ +#if CONFIG_FS_TMPFS_DIRECTORY_FREEGUARD <= CONFIG_FS_TMPFS_DIRECTORY_ALLOCGUARD +# warning CONFIG_FS_TMPFS_DIRECTORY_FREEGUARD needs to be > ALLOCGUARD +#endif + +#if CONFIG_FS_TMPFS_FILE_FREEGUARD <= CONFIG_FS_TMPFS_FILE_ALLOCGUARD +# warning CONFIG_FS_TMPFS_FILE_FREEGUARD needs to be > ALLOCGUARD +#endif + #define tmpfs_lock_file(tfo) \ (tmpfs_lock_object((FAR struct tmpfs_object_s *)tfo)) #define tmpfs_lock_directory(tdo) \ @@ -308,10 +316,12 @@ static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, objsize = SIZEOF_TMPFS_DIRECTORY(nentries); if (objsize <= oldtdo->tdo_alloc) { - /* Already big enough */ + /* Already big enough. + * REVISIT: Missing logic to shrink directory objects. + */ oldtdo->tdo_nentries = nentries; - return OK; + return ret; } /* Added some additional amount to the new size to account frequent @@ -361,15 +371,9 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, objsize = SIZEOF_TMPFS_FILE(newsize); - /* Added some additional amount to the new size to account frequent - * reallocations. - */ - - allocsize = objsize + CONFIG_FS_TMPFS_FILE_ALLOCGUARD; - /* Are we growing or shrinking the object? */ - if (allocsize <= oldtfo->tfo_alloc) + if (objsize <= oldtfo->tfo_alloc) { /* Shrinking ... Shrink unconditionally if the size is shrinking to * zero. @@ -381,8 +385,8 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, * lot. */ - delta = oldtfo->tfo_alloc - allocsize; - if (delta <= CONFIG_FS_TMPFS_FILE_ALLOCGUARD) + delta = oldtfo->tfo_alloc - objsize; + if (delta <= CONFIG_FS_TMPFS_FILE_FREEGUARD) { /* Hasn't shrunk enough.. Return doing nothing for now */ @@ -392,6 +396,12 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, } } + /* Added some additional amount to the new size to account frequent + * reallocations. + */ + + allocsize = objsize + CONFIG_FS_TMPFS_FILE_ALLOCGUARD; + /* Realloc the file object */ newtfo = (FAR struct tmpfs_file_s *)kmm_realloc(oldtfo, objsize); @@ -512,8 +522,22 @@ static int tmpfs_remove_dirent(FAR struct tmpfs_directory_s *tdo, last = tdo->tdo_nentries - 1; if (index != last) { - tdo->tdo_entry[index].tde_object = tdo->tdo_entry[last].tde_object; - tdo->tdo_entry[index].tde_name = tdo->tdo_entry[last].tde_name; + FAR struct tmpfs_dirent_s *newtde; + FAR struct tmpfs_dirent_s *oldtde; + FAR struct tmpfs_object_s *to; + + /* Move the directory entry */ + + newtde = &tdo->tdo_entry[index]; + oldtde = &tdo->tdo_entry[last]; + to = oldtde->tde_object; + + newtde->tde_object = to; + newtde->tde_name = oldtde->tde_name; + + /* Reset the backward link to the directory entry */ + + to->to_dirent = newtde; } /* And decrement the count of directory entries */ @@ -532,6 +556,7 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, { FAR struct tmpfs_directory_s *oldtdo; FAR struct tmpfs_directory_s *newtdo; + FAR struct tmpfs_dirent_s *tde; FAR char *newname; unsigned int nentries; int index; @@ -562,13 +587,14 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s **tdo, /* Save the new object info in the new directory entry */ - newtdo = *tdo; - newtdo->tdo_entry[index].tde_object = to; - newtdo->tdo_entry[index].tde_name = newname; + newtdo = *tdo; + tde = &newtdo->tdo_entry[index]; + tde->tde_object = to; + tde->tde_name = newname; /* Add backward link to the directory entry to the object */ - to->to_dirent = &newtdo->tdo_entry[index]; + to->to_dirent = tde; return OK; } @@ -1176,11 +1202,20 @@ static int tmpfs_free_callout(FAR struct tmpfs_directory_s *tdo, if (index != last) { - FAR struct tmpfs_dirent_s *tmp; + FAR struct tmpfs_dirent_s *oldtde; + FAR struct tmpfs_object_s *oldto; + + /* Move the directory entry */ + + oldtde = &tdo->tdo_entry[last]; + oldto = oldtde->tde_object; + + tde->tde_object = oldto; + tde->tde_name = oldtde->tde_name; + + /* Reset the backward link to the directory entry */ - tmp = &tdo->tdo_entry[last]; - tde->tde_object = tmp->tde_object; - tde->tde_name = tmp->tde_name; + oldto->to_dirent = tde; } /* And decrement the count of directory entries */ @@ -1506,6 +1541,7 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, /* Copy data from the memory object to the user buffer */ memcpy(buffer, &tfo->tfo_data, nread); + filep->f_pos += nread; /* Release the lock on the file */ @@ -1560,6 +1596,7 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, /* Copy data from the memory object to the user buffer */ memcpy(&tfo->tfo_data, buffer, nwritten); + filep->f_pos += nwritten; /* Release the lock on the file */ -- GitLab From b489cd9610f953c13d75eb79d1c3b46df565aca2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 15:17:32 -0600 Subject: [PATCH 209/858] TMFPS: Now basically functional although not heavily tested --- ChangeLog | 4 ++-- Documentation | 2 +- fs/tmpfs/Kconfig | 2 +- fs/tmpfs/fs_tmpfs.c | 27 +++++++++++++++++++-------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93e17112f5..887081c9b4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11019,5 +11019,5 @@ README file for more info (2015-10-08). * stm32 F4: Fix some TIM12 pin mappings. From Max Kriegleder (2015-10-9). - * fs/tmpfs: TMPFS file system is code complete, but not yet functional - (2015-10-9). + * fs/tmpfs: TMPFS file system is code complete and bascially functional + although it has not been heavilay tested (2015-10-9). diff --git a/Documentation b/Documentation index b705a3fefb..7a768453c1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit b705a3fefb00ce13be249f47a17d80cdfa7bf71c +Subproject commit 7a768453c1ca9602d668c79d45db141b74d5c215 diff --git a/fs/tmpfs/Kconfig b/fs/tmpfs/Kconfig index c1f1220703..2d75fd11e6 100644 --- a/fs/tmpfs/Kconfig +++ b/fs/tmpfs/Kconfig @@ -6,7 +6,7 @@ config FS_TMPFS bool "TMPFS file system" default n - depends on !DISABLE_MOUNTPOINT && EXPERIMENTAL + depends on !DISABLE_MOUNTPOINT select FS_READABLE select FS_WRITABLE ---help--- diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 639177936c..2d28fa293d 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -667,6 +667,8 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, name = copy; parent = fs->tfs_root; + /* Lock the root directory to emulate the behavior of tmpfs_find_directory() */ + tmpfs_lock_directory(parent); parent->tdo_refs++; } @@ -677,7 +679,7 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, *name++ = '\0'; /* Locate the parent directory that should contain this name. - * On success, tmpfs_find_directory() will lockthe parent + * On success, tmpfs_find_directory() will lock the parent * directory and increment the reference count. */ @@ -724,6 +726,11 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, goto errout_with_file; } + /* Release the reference and lock on the parent directory */ + + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + /* Free the copy of the relpath and return success */ kmm_free(copy); @@ -856,8 +863,8 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, goto errout_with_parent; } - /* Allocate an empty directory object. There is no reference on the new - * directory and the object is not locked. + /* Allocate an empty directory object. NOTE that there is no reference on + * the new directory and the object is not locked. */ newtdo = tmpfs_alloc_directory(); @@ -883,7 +890,13 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, tmpfs_unlock_directory(parent); kmm_free(copy); - *tdo = newtdo; + /* Return the (unlocked, unreferenced) directory object to the caller */ + + if (tdo != NULL) + { + *tdo = newtdo; + } + return OK; /* Error exits */ @@ -1263,12 +1276,12 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, { /* Lock the object and take a reference */ + to = tdo->tdo_entry[index].tde_object; tmpfs_lock_object(to); to->to_refs++; /* Is the next entry a directory? */ - to = tdo->tdo_entry[index].tde_object; if (to->to_type == TMPFS_DIRECTORY) { FAR struct tmpfs_directory_s *next = @@ -2159,9 +2172,7 @@ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, tmpfs_lock(fs); - /* Create the directory. This will lock the newly directory with a - * a reference count of one. - */ + /* Create the directory. */ ret = tmpfs_create_directory(fs, relpath, NULL); tmpfs_unlock(fs); -- GitLab From d80bea326f4d8fd84359584a3597f2bf94fd6e9b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 15:56:16 -0600 Subject: [PATCH 210/858] TMPFS: Fix a misbehaving assertion --- fs/tmpfs/fs_tmpfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 2d28fa293d..54ac92fa87 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1961,8 +1961,7 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, fvdbg("handle: %p blkdriver: %p flags: %02x\n", handle, blkdriver, flags); - DEBUGASSERT(blkdriver == NULL && handle != NULL); - DEBUGASSERT(fs == NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); /* Lock the file system */ -- GitLab From e675ddb81376b92ee6d60164e4ae2d51c613f50b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 16:57:48 -0600 Subject: [PATCH 211/858] TMPFS: Reported block size is now configurable --- arch | 2 +- fs/tmpfs/Kconfig | 13 +++++++++++++ fs/tmpfs/fs_tmpfs.c | 23 +++++++++++++++-------- fs/tmpfs/fs_tmpfs.h | 4 ---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/arch b/arch index 00acafcbb1..07f1151a80 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 00acafcbb154a076f60413eb75249c5b68c6c316 +Subproject commit 07f1151a8039a32ff09fe479869b268dd11ed514 diff --git a/fs/tmpfs/Kconfig b/fs/tmpfs/Kconfig index 2d75fd11e6..9eebf3b964 100644 --- a/fs/tmpfs/Kconfig +++ b/fs/tmpfs/Kconfig @@ -14,6 +14,16 @@ config FS_TMPFS if FS_TMPFS +config FS_TMPFS_BLOCKSIZE + int "Reported block size" + default 512 + ---help--- + Various queries expect the file system to report resources in units + of blocks. There are, of course, no blocks with the TMPFS. This + options is available to control how sizes are reported. For very + small TMPFS systems, you might want to set this to something smaller + the the usual 512 bytes. + config FS_TMPFS_DIRECTORY_ALLOCGUARD int "Directory object over-allocation" default 64 @@ -39,6 +49,9 @@ config FS_TMPFS_FILE_ALLOCGUARD needed is always allocated. This permits the file to grow without so many realloctions. + You will probably want to use smaller value than the default on tiny + TMFPS systems. + config FS_TMPFS_FILE_FREEGUARD int "Directory under free" default 1024 diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 54ac92fa87..be8e01e02d 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -2009,17 +2009,21 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) tmpfs_lock(fs); - /* Traverse the file system to accurmulate statistics */ + /* Set up the memory use for the file system and root directory object */ tdo = fs->tfs_root; - inuse = SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); - avail = tdo->tdo_alloc - inuse; + inuse = sizeof(struct tmpfs_s) + + SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); + avail = sizeof(struct tmpfs_s) + + tdo->tdo_alloc - inuse; tmpbuf.tsf_alloc = tdo->tdo_alloc; tmpbuf.tsf_inuse = inuse; tmpbuf.tsf_files = 0; tmpbuf.tsf_ffree = avail / sizeof(struct tmpfs_dirent_s); + /* Traverse the file system to accurmulate statistics */ + ret = tmpfs_foreach(fs->tfs_root, tmpfs_statfs_callout, (FAR void *)&tmpbuf); if (ret < 0) @@ -2029,12 +2033,14 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) /* Return something for the file system description */ - blkalloc = (tmpbuf.tsf_alloc + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; - blkused = (tmpbuf.tsf_inuse + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; + blkalloc = (tmpbuf.tsf_alloc + CONFIG_FS_TMPFS_BLOCKSIZE - 1) / + CONFIG_FS_TMPFS_BLOCKSIZE; + blkused = (tmpbuf.tsf_inuse + CONFIG_FS_TMPFS_BLOCKSIZE - 1) / + CONFIG_FS_TMPFS_BLOCKSIZE; buf->f_type = TMPFS_MAGIC; buf->f_namelen = NAME_MAX; - buf->f_bsize = TMPFS_BLOCKSIZE; + buf->f_bsize = CONFIG_FS_TMPFS_BLOCKSIZE; buf->f_blocks = blkalloc; buf->f_bfree = blkalloc - blkused; buf->f_bavail = blkalloc - blkused; @@ -2487,8 +2493,9 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, /* Fake the rest of the information */ buf->st_size = objsize; - buf->st_blksize = TMPFS_BLOCKSIZE; - buf->st_blocks = (objsize + TMPFS_BLOCKSIZE - 1) / TMPFS_BLOCKSIZE; + buf->st_blksize = CONFIG_FS_TMPFS_BLOCKSIZE; + buf->st_blocks = (objsize + CONFIG_FS_TMPFS_BLOCKSIZE - 1) / + CONFIG_FS_TMPFS_BLOCKSIZE; /* No... unlock the object and return success */ diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index 18233b0340..5654136490 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -50,10 +50,6 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* This is the block size reported by stat() */ - -#define TMPFS_BLOCKSIZE 512 - /* Indicates that there is no holder of the re-entrant semaphore */ #define TMPFS_NO_HOLDER -1 -- GitLab From cf14f8d1b5eafff501cb58a56b19e1bb48068a28 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 10:41:00 -0600 Subject: [PATCH 212/858] drivers/: Fixes to spacing and alignement --- drivers/analog/ad5410.c | 18 +-- drivers/analog/adc.c | 5 +- drivers/analog/ads1255.c | 62 ++++----- drivers/analog/dac.c | 36 +++--- drivers/audio/audio_null.c | 14 +-- drivers/audio/vs1053.c | 57 +++++---- drivers/audio/wm8904.c | 19 +-- drivers/audio/wm8904_debug.c | 2 +- drivers/bch/bchdev_driver.c | 2 +- drivers/bch/bchlib_cache.c | 7 +- drivers/bch/bchlib_read.c | 2 +- drivers/bch/bchlib_setup.c | 2 +- drivers/bch/bchlib_write.c | 2 +- drivers/can.c | 2 +- drivers/dev_null.c | 10 +- drivers/dev_zero.c | 10 +- drivers/eeprom/spi_xx25xx.c | 50 ++++---- drivers/input/ads7843e.c | 12 +- drivers/input/ajoystick.c | 3 +- drivers/input/djoystick.c | 5 +- drivers/input/max11802.c | 12 +- drivers/input/mxt.c | 6 +- drivers/input/stmpe811_base.c | 7 +- drivers/input/stmpe811_temp.c | 6 +- drivers/input/stmpe811_tsc.c | 10 +- drivers/input/tsc2007.c | 14 +-- drivers/ioexpander/pca9555.c | 18 +-- drivers/lcd/ili9341.c | 33 ++--- drivers/lcd/memlcd.c | 11 +- drivers/lcd/mio283qt2.c | 12 +- drivers/lcd/mio283qt9a.c | 35 +++--- drivers/lcd/nokia6100.c | 64 +++++----- drivers/lcd/p14201.c | 54 ++++---- drivers/lcd/ra8875.c | 23 ++-- drivers/lcd/skeleton.c | 8 +- drivers/lcd/ssd1289.c | 12 +- drivers/lcd/ssd1306_base.c | 56 ++++----- drivers/lcd/st7565.c | 8 +- drivers/lcd/st7567.c | 10 +- drivers/lcd/ug-2864ambag01.c | 12 +- drivers/lcd/ug-9664hswag01.c | 10 +- drivers/mmcsd/mmcsd_sdio.c | 54 ++++---- drivers/mmcsd/mmcsd_spi.c | 18 +-- drivers/mtd/at45db.c | 12 +- drivers/mtd/flash_eraseall.c | 2 +- drivers/mtd/mtd_config.c | 19 ++- drivers/mtd/mtd_nand.c | 6 +- drivers/mtd/mtd_nandscheme.c | 10 +- drivers/mtd/mtd_onfi.c | 20 +-- drivers/mtd/mtd_partition.c | 2 +- drivers/mtd/mtd_procfs.c | 3 +- drivers/mtd/mtd_rwbuffer.c | 2 +- drivers/mtd/rammtd.c | 2 +- drivers/mtd/sector512.c | 12 +- drivers/mtd/smart.c | 110 ++++++++-------- drivers/mtd/sst25.c | 18 +-- drivers/mtd/st25fl1.c | 2 +- drivers/mtd/w25.c | 4 +- drivers/net/cs89x0.c | 60 ++++----- drivers/net/dm90x0.c | 82 ++++++------ drivers/net/e1000.c | 193 +++++++++++++++++------------ drivers/net/enc28j60.c | 28 ++--- drivers/net/encx24j600.c | 76 ++++++------ drivers/net/ftmac100.c | 42 +++---- drivers/net/loopback.c | 2 +- drivers/net/skeleton.c | 6 +- drivers/net/slip.c | 8 +- drivers/net/tun.c | 17 +-- drivers/net/vnet.c | 59 ++++----- drivers/pipes/fifo.c | 4 +- drivers/pipes/pipe.c | 2 +- drivers/pipes/pipe_common.c | 18 +-- drivers/power/battery_charger.c | 4 +- drivers/power/battery_gauge.c | 3 +- drivers/power/pm_checkstate.c | 27 ++-- drivers/power/pm_update.c | 3 +- drivers/pwm.c | 4 +- drivers/rwbuffer.c | 6 +- drivers/sensors/bmp180.c | 5 +- drivers/sensors/lis331dl.c | 2 +- drivers/sensors/lm75.c | 10 +- drivers/sensors/lm92.c | 2 +- drivers/sensors/max31855.c | 5 +- drivers/sensors/mpl115a.c | 9 +- drivers/sensors/qencoder.c | 5 +- drivers/sercomm/console.c | 37 ++++-- drivers/sercomm/uart.c | 10 +- drivers/serial/lowconsole.c | 2 +- drivers/serial/serial.c | 18 +-- drivers/serial/uart_16550.c | 57 +++++---- drivers/syslog/ramlog.c | 8 +- drivers/syslog/syslog_console.c | 2 +- drivers/timers/cs2100-cp.c | 2 +- drivers/timers/rtc.c | 3 +- drivers/timers/timer.c | 49 +------- drivers/usbdev/cdcacm.c | 87 ++++++------- drivers/usbdev/cdcacm_desc.c | 2 +- drivers/usbdev/composite.c | 16 +-- drivers/usbdev/pl2303.c | 74 +++++------ drivers/usbdev/usbmsc.c | 31 ++--- drivers/usbdev/usbmsc_scsi.c | 32 ++--- drivers/usbhost/usbhost_cdcacm.c | 20 +-- drivers/usbhost/usbhost_devaddr.c | 2 +- drivers/usbhost/usbhost_hidkbd.c | 12 +- drivers/usbhost/usbhost_hidmouse.c | 10 +- drivers/usbhost/usbhost_hub.c | 2 +- drivers/usbhost/usbhost_skeleton.c | 6 +- drivers/usbhost/usbhost_storage.c | 27 ++-- 108 files changed, 1131 insertions(+), 1097 deletions(-) diff --git a/drivers/analog/ad5410.c b/drivers/analog/ad5410.c index 9caf675ab4..33da3c7661 100644 --- a/drivers/analog/ad5410.c +++ b/drivers/analog/ad5410.c @@ -141,9 +141,9 @@ static int dac_setup(FAR struct dac_dev_s *dev) FAR struct spi_dev_s *spi = priv->spi; SPI_SELECT(spi, priv->devno, true); - SPI_SEND(spi,AD5410_REG_CMD); - SPI_SEND(spi,(AD5410_CMD_OUTEN|AD5410_CMD_420MA)>>8); - SPI_SEND(spi,AD5410_CMD_OUTEN|AD5410_CMD_420MA); + SPI_SEND(spi, AD5410_REG_CMD); + SPI_SEND(spi, (AD5410_CMD_OUTEN | AD5410_CMD_420MA) >> 8); + SPI_SEND(spi, AD5410_CMD_OUTEN | AD5410_CMD_420MA); SPI_SELECT(spi, priv->devno, false); return OK; } @@ -167,10 +167,10 @@ static int dac_send(FAR struct dac_dev_s *dev, FAR struct dac_msg_s *msg) FAR struct up_dev_s *priv = (FAR struct up_dev_s *)dev->ad_priv; FAR struct spi_dev_s *spi = priv->spi; - SPI_SELECT(spi, priv->devno, true); - SPI_SEND(spi,AD5410_REG_WR); - SPI_SEND(spi,(uint8_t)(msg->am_data>>24)); - SPI_SEND(spi,(uint8_t)(msg->am_data>>16)); + SPI_SELECT(spi, priv->devno, true); + SPI_SEND(spi, AD5410_REG_WR); + SPI_SEND(spi, (uint8_t)(msg->am_data >> 24)); + SPI_SEND(spi, (uint8_t)(msg->am_data >> 16)); SPI_SELECT(spi, priv->devno, false); dac_txdone(&g_dacdev); return 0; @@ -207,8 +207,8 @@ FAR struct dac_dev_s *up_ad5410initialize(FAR struct spi_dev_s *spi, { FAR struct up_dev_s *priv = (FAR struct up_dev_s *)g_dacdev.ad_priv; - priv->spi=spi; - priv->devno=devno; + priv->spi = spi; + priv->devno = devno; return &g_dacdev; } #endif diff --git a/drivers/analog/adc.c b/drivers/analog/adc.c index 9b5bb6e42d..b856d39589 100644 --- a/drivers/analog/adc.c +++ b/drivers/analog/adc.c @@ -67,8 +67,9 @@ static int adc_open(FAR struct file *filep); static int adc_close(FAR struct file *filep); -static ssize_t adc_read(FAR struct file *, FAR char *, size_t); -static int adc_ioctl(FAR struct file *filep,int cmd,unsigned long arg); +static ssize_t adc_read(FAR struct file *fielp, FAR char *buffer, + size_t buflen); +static int adc_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** * Private Data diff --git a/drivers/analog/ads1255.c b/drivers/analog/ads1255.c index 0fbf63c196..93bed6d2f6 100644 --- a/drivers/analog/ads1255.c +++ b/drivers/analog/ads1255.c @@ -147,17 +147,17 @@ static struct up_dev_s g_adcpriv = { .mux = (const uint8_t []) { - CONFIG_ADS1255_MUX,0 + CONFIG_ADS1255_MUX, 0 }, - .sps = CONFIG_ADS1255_SPS, + .sps = CONFIG_ADS1255_SPS, .channel = 0, - .irq = CONFIG_ADS1255_IRQ, + .irq = CONFIG_ADS1255_IRQ, }; static struct adc_dev_s g_adcdev = { - .ad_ops = &g_adcops, - .ad_priv= &g_adcpriv, + .ad_ops = &g_adcops, + .ad_priv = &g_adcpriv, }; /**************************************************************************** @@ -166,12 +166,12 @@ static struct adc_dev_s g_adcdev = static uint8_t getspsreg(uint16_t sps) { - static const unsigned short sps_tab[]= + static const unsigned short sps_tab[] = { 3, 7, 12, 20, 27, 40, 55, 80, 300, 750, 1500, 3000, 5000, 10000, 20000, 65535, }; - static const unsigned char sps_reg[]= + static const unsigned char sps_reg[] = { 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x72, 0x82, 0x92, 0xa1, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, @@ -206,9 +206,9 @@ static void adc_reset(FAR struct adc_dev_s *dev) SPI_SETFREQUENCY(spi, CONFIG_ADS1255_FREQUENCY); usleep(1000); SPI_SELECT(spi, priv->devno, true); - SPI_SEND(spi,ADS125X_WREG+0x03); /* WRITE SPS REG */ - SPI_SEND(spi,0x00); /* count=1 */ - SPI_SEND(spi,0x63); + SPI_SEND(spi, ADS125X_WREG + 0x03); /* WRITE SPS REG */ + SPI_SEND(spi, 0x00); /* count=1 */ + SPI_SEND(spi, 0x63); SPI_SELECT(spi, priv->devno, false); } @@ -227,22 +227,22 @@ static int adc_setup(FAR struct adc_dev_s *dev) if (ret == OK) { SPI_SELECT(spi, priv->devno, true); - SPI_SEND(spi,ADS125X_WREG); /* WRITE REG from 0 */ - SPI_SEND(spi,0x03); /* count=4+1 */ + SPI_SEND(spi, ADS125X_WREG); /* WRITE REG from 0 */ + SPI_SEND(spi, 0x03); /* count=4+1 */ if (priv->buf) { - SPI_SEND(spi,ADS125X_BUFON); /* REG0 STATUS BUFFER ON */ + SPI_SEND(spi, ADS125X_BUFON); /* REG0 STATUS BUFFER ON */ } else { - SPI_SEND(spi,ADS125X_BUFOFF); + SPI_SEND(spi, ADS125X_BUFOFF); } - SPI_SEND(spi,priv->mux[0]); - SPI_SEND(spi,priv->pga); /* REG2 ADCON PGA=2 */ - SPI_SEND(spi,getspsreg(priv->sps)); + SPI_SEND(spi, priv->mux[0]); + SPI_SEND(spi, priv->pga); /* REG2 ADCON PGA=2 */ + SPI_SEND(spi, getspsreg(priv->sps)); usleep(1000); - SPI_SEND(spi,ADS125X_SELFCAL); + SPI_SEND(spi, ADS125X_SELFCAL); SPI_SELECT(spi, priv->devno, false); up_enable_irq(priv->irq); } @@ -292,30 +292,30 @@ static int adc_interrupt(int irq, void *context) unsigned char ch; SPI_SELECT(spi, priv->devno, true); - SPI_SEND(spi,ADS125X_RDATA); + SPI_SEND(spi, ADS125X_RDATA); up_udelay(10); - buf[3]=SPI_SEND(spi,0xff); - buf[2]=SPI_SEND(spi,0xff); - buf[1]=SPI_SEND(spi,0xff); - buf[0]=0; + buf[3] = SPI_SEND(spi, 0xff); + buf[2] = SPI_SEND(spi, 0xff); + buf[1] = SPI_SEND(spi, 0xff); + buf[0] = 0; priv->channel++; ch = priv->mux[priv->channel]; - if ( ch == 0 ) + if (ch == 0) { - priv->channel=0; + priv->channel = 0; ch = priv->mux[0]; } - SPI_SEND(spi,ADS125X_WREG+0x01); - SPI_SEND(spi,0x00); - SPI_SEND(spi,ch); - SPI_SEND(spi,ADS125X_SYNC); + SPI_SEND(spi, ADS125X_WREG + 0x01); + SPI_SEND(spi, 0x00); + SPI_SEND(spi, ch); + SPI_SEND(spi, ADS125X_SYNC); up_udelay(2); - SPI_SEND(spi,ADS125X_WAKEUP); + SPI_SEND(spi, ADS125X_WAKEUP); SPI_SELECT(spi, priv->devno, false); - adc_receive(&g_adcdev,priv->channel,*(int32_t *)buf); + adc_receive(&g_adcdev, priv->channel, *(int32_t *)buf); return OK; } diff --git a/drivers/analog/dac.c b/drivers/analog/dac.c index c4cd10a6af..12be8837b5 100644 --- a/drivers/analog/dac.c +++ b/drivers/analog/dac.c @@ -74,9 +74,11 @@ static int dac_open(FAR struct file *filep); static int dac_close(FAR struct file *filep); -static ssize_t dac_read(FAR struct file *, FAR char *, size_t); -static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int dac_ioctl(FAR struct file *filep,int cmd,unsigned long arg); +static ssize_t dac_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int dac_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** * Private Data @@ -299,7 +301,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t * shorter than the minimum. */ - if (buflen % 5 == 0 ) + if (buflen % 5 == 0) { msglen = 5; } @@ -324,7 +326,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t msglen = 5; } - while ((buflen - nsent) >= msglen ) + while ((buflen - nsent) >= msglen) { /* Check if adding this new message would over-run the drivers ability to enqueue * xmit data. @@ -394,27 +396,27 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t } else if (msglen == 4) { - fifo->af_buffer[fifo->af_tail].am_channel=buffer[nsent]; - fifo->af_buffer[fifo->af_tail].am_data=*(uint32_t *)&buffer[nsent]; - fifo->af_buffer[fifo->af_tail].am_data&=0xffffff00; + fifo->af_buffer[fifo->af_tail].am_channel = buffer[nsent]; + fifo->af_buffer[fifo->af_tail].am_data = *(uint32_t *)&buffer[nsent]; + fifo->af_buffer[fifo->af_tail].am_data &= 0xffffff00; } else if (msglen == 3) { - fifo->af_buffer[fifo->af_tail].am_channel=buffer[nsent]; - fifo->af_buffer[fifo->af_tail].am_data=(*(uint16_t *)&buffer[nsent+1]); - fifo->af_buffer[fifo->af_tail].am_data<<=16; + fifo->af_buffer[fifo->af_tail].am_channel = buffer[nsent]; + fifo->af_buffer[fifo->af_tail].am_data = (*(uint16_t *)&buffer[nsent+1]); + fifo->af_buffer[fifo->af_tail].am_data <<= 16; } else if (msglen == 2) { - fifo->af_buffer[fifo->af_tail].am_channel=0; - fifo->af_buffer[fifo->af_tail].am_data=(*(uint16_t *)&buffer[nsent]); - fifo->af_buffer[fifo->af_tail].am_data<<=16; + fifo->af_buffer[fifo->af_tail].am_channel = 0; + fifo->af_buffer[fifo->af_tail].am_data = (*(uint16_t *)&buffer[nsent]); + fifo->af_buffer[fifo->af_tail].am_data <<= 16; } else if (msglen == 1) { - fifo->af_buffer[fifo->af_tail].am_channel=0; - fifo->af_buffer[fifo->af_tail].am_data=buffer[nsent]; - fifo->af_buffer[fifo->af_tail].am_data<<=24; + fifo->af_buffer[fifo->af_tail].am_channel = 0; + fifo->af_buffer[fifo->af_tail].am_data = buffer[nsent]; + fifo->af_buffer[fifo->af_tail].am_data <<= 24; } /* Increment the tail of the circular buffer */ diff --git a/drivers/audio/audio_null.c b/drivers/audio/audio_null.c index 7e0f366a78..f5a1337f5c 100644 --- a/drivers/audio/audio_null.c +++ b/drivers/audio/audio_null.c @@ -101,7 +101,7 @@ static int null_start(FAR struct audio_lowerhalf_s *dev); #ifndef CONFIG_AUDIO_EXCLUDE_STOP #ifdef CONFIG_AUDIO_MULTI_SESSION static int null_stop(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); #else static int null_stop(FAR struct audio_lowerhalf_s *dev); #endif @@ -109,9 +109,9 @@ static int null_stop(FAR struct audio_lowerhalf_s *dev); #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION static int null_pause(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); static int null_resume(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); #else static int null_pause(FAR struct audio_lowerhalf_s *dev); static int null_resume(FAR struct audio_lowerhalf_s *dev); @@ -432,7 +432,7 @@ static void *null_workerthread(pthread_addr_t pvarg) #ifndef CONFIG_AUDIO_EXCLUDE_STOP while (!priv->terminate) #else - for (;;) + for (; ; ) #endif { /* Wait for messages from our message queue */ @@ -573,7 +573,7 @@ static int null_start(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_STOP #ifdef CONFIG_AUDIO_MULTI_SESSION -static int null_stop(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int null_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int null_stop(FAR struct audio_lowerhalf_s *dev) #endif @@ -611,7 +611,7 @@ static int null_stop(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int null_pause(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int null_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int null_pause(FAR struct audio_lowerhalf_s *dev) #endif @@ -630,7 +630,7 @@ static int null_pause(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int null_resume(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int null_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int null_resume(FAR struct audio_lowerhalf_s *dev) #endif diff --git a/drivers/audio/vs1053.c b/drivers/audio/vs1053.c index dfc4220edb..35b0a95647 100644 --- a/drivers/audio/vs1053.c +++ b/drivers/audio/vs1053.c @@ -111,35 +111,35 @@ struct vs1053_struct_s /* Our specific driver data goes here */ - const FAR struct vs1053_lower_s *hw_lower;/* Pointer to the hardware lower functions */ - FAR struct spi_dev_s *spi; /* Pointer to the SPI bus */ - FAR struct ap_buffer_s *apb; /* Pointer to the buffer we are processing */ - struct dq_queue_s apbq; /* Our queue for enqueued buffers */ - unsigned long spi_freq; /* Frequency to run the SPI bus at. */ - unsigned long chip_freq; /* Current chip frequency */ - mqd_t mq; /* Message queue for receiving messages */ - char mqname[16]; /* Our message queue name */ - pthread_t threadid; /* ID of our thread */ - sem_t apbq_sem; /* Audio Pipeline Buffer Queue sem access */ + const FAR struct vs1053_lower_s *hw_lower; /* Pointer to the hardware lower functions */ + FAR struct spi_dev_s *spi; /* Pointer to the SPI bus */ + FAR struct ap_buffer_s *apb; /* Pointer to the buffer we are processing */ + struct dq_queue_s apbq; /* Our queue for enqueued buffers */ + unsigned long spi_freq; /* Frequency to run the SPI bus at. */ + unsigned long chip_freq; /* Current chip frequency */ + mqd_t mq; /* Message queue for receiving messages */ + char mqname[16]; /* Our message queue name */ + pthread_t threadid; /* ID of our thread */ + sem_t apbq_sem; /* Audio Pipeline Buffer Queue sem access */ #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME - int16_t volume; /* Current volume level */ + int16_t volume; /* Current volume level */ #ifndef CONFIG_AUDIO_EXCLUDE_BALANCE - int16_t balance; /* Current balance level */ + int16_t balance; /* Current balance level */ #endif /* CONFIG_AUDIO_EXCLUDE_BALANCE */ #endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */ #ifndef CONFIG_AUDIO_EXCLUDE_TONE - uint8_t bass; /* Bass level */ - uint8_t treble; /* Bass level */ + uint8_t bass; /* Bass level */ + uint8_t treble; /* Bass level */ #endif uint16_t endfillbytes; - uint8_t endfillchar; /* Fill char to send when no more data */ + uint8_t endfillchar; /* Fill char to send when no more data */ bool running; bool paused; bool endmode; #ifndef CONFIG_AUDIO_EXCLUDE_STOP bool cancelmode; #endif - bool busy; /* Set true when device reserved */ + bool busy; /* Set true when device reserved */ }; /**************************************************************************** @@ -167,7 +167,7 @@ static int vs1053_resume(FAR struct audio_lowerhalf_s *lower, static int vs1053_reserve(FAR struct audio_lowerhalf_s *lower, FAR void** ppContext); static int vs1053_release(FAR struct audio_lowerhalf_s *lower, - FAR void* pContext); + FAR void *pContext); #else static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, FAR const struct audio_caps_s *pCaps); @@ -219,7 +219,10 @@ static const struct audio_ops_s g_audioops = /* ISR context pointers */ -static struct vs1053_struct_s* g_isrdata[CONFIG_VS1053_DEVICE_COUNT] = { NULL, }; +static struct vs1053_struct_s *g_isrdata[CONFIG_VS1053_DEVICE_COUNT] = +{ + NULL, +}; /* Volume control log table. This table is in increments of 2% of * requested volume level and is the register value that should be @@ -1518,14 +1521,14 @@ static int vs1053_start(FAR struct audio_lowerhalf_s *lower) #ifndef CONFIG_AUDIO_EXCLUDE_STOP #ifdef CONFIG_AUDIO_MULTI_SESSION -static int vs1053_stop(FAR struct audio_lowerhalf_s *lower, FAR void* session) +static int vs1053_stop(FAR struct audio_lowerhalf_s *lower, FAR void *session) #else static int vs1053_stop(FAR struct audio_lowerhalf_s *lower) #endif { FAR struct vs1053_struct_s *dev = (struct vs1053_struct_s *) lower; - struct audio_msg_s term_msg; - FAR void* value; + struct audio_msg_s term_msg; + FAR void *value; /* Send a message to stop all audio streaming */ @@ -1562,7 +1565,7 @@ static int vs1053_stop(FAR struct audio_lowerhalf_s *lower) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int vs1053_pause(FAR struct audio_lowerhalf_s *lower, FAR void* session) +static int vs1053_pause(FAR struct audio_lowerhalf_s *lower, FAR void *session) #else static int vs1053_pause(FAR struct audio_lowerhalf_s *lower) #endif @@ -1591,7 +1594,7 @@ static int vs1053_pause(FAR struct audio_lowerhalf_s *lower) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int vs1053_resume(FAR struct audio_lowerhalf_s *lower, FAR void* session) +static int vs1053_resume(FAR struct audio_lowerhalf_s *lower, FAR void *session) #else static int vs1053_resume(FAR struct audio_lowerhalf_s *lower) #endif @@ -1620,9 +1623,9 @@ static int vs1053_resume(FAR struct audio_lowerhalf_s *lower) ****************************************************************************/ static int vs1053_enqueuebuffer(FAR struct audio_lowerhalf_s *lower, - FAR struct ap_buffer_s *apb ) + FAR struct ap_buffer_s *apb) { - FAR struct vs1053_struct_s *dev = (struct vs1053_struct_s *) lower; + FAR struct vs1053_struct_s *dev = (struct vs1053_struct_s *)lower; struct audio_msg_s term_msg; int ret; @@ -1661,7 +1664,7 @@ static int vs1053_enqueuebuffer(FAR struct audio_lowerhalf_s *lower, ****************************************************************************/ static int vs1053_cancelbuffer(FAR struct audio_lowerhalf_s *lower, - FAR struct ap_buffer_s *apb ) + FAR struct ap_buffer_s *apb) { return OK; } @@ -1871,7 +1874,7 @@ struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi, * for the DREQ to be active indicating the device is ready */ - retry = 200;; + retry = 200; while (!lower->read_dreq(lower) && retry) { up_udelay(10); diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index c90c834f65..ac3bdf3668 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -133,7 +133,7 @@ static int wm8904_start(FAR struct audio_lowerhalf_s *dev); #ifndef CONFIG_AUDIO_EXCLUDE_STOP #ifdef CONFIG_AUDIO_MULTI_SESSION static int wm8904_stop(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); #else static int wm8904_stop(FAR struct audio_lowerhalf_s *dev); #endif @@ -141,9 +141,9 @@ static int wm8904_stop(FAR struct audio_lowerhalf_s *dev); #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION static int wm8904_pause(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); static int wm8904_resume(FAR struct audio_lowerhalf_s *dev, - FAR void* session); + FAR void *session); #else static int wm8904_pause(FAR struct audio_lowerhalf_s *dev); static int wm8904_resume(FAR struct audio_lowerhalf_s *dev); @@ -232,7 +232,10 @@ const uint8_t g_sysclk_scaleb1[WM8904_BCLK_MAXDIV+1] = #ifndef CONFIG_WM8904_CLKDEBUG static #endif -const uint8_t g_fllratio[WM8904_NFLLRATIO] = {1, 2, 4, 8, 16}; +const uint8_t g_fllratio[WM8904_NFLLRATIO] = +{ + 1, 2, 4, 8, 16 +}; /**************************************************************************** * Private Functions @@ -726,7 +729,7 @@ static void wm8904_setbitrate(FAR struct wm8904_dev_s *priv) minfout = WM8904_FVCO_MAX / WM8904_MAXOUTDIV; divndx = 0; - for (;;) + for (; ; ) { /* Calculate the new value of Fout that we would need to provide * with this SYSCLK divider in place. @@ -1585,7 +1588,7 @@ static int wm8904_start(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_STOP #ifdef CONFIG_AUDIO_MULTI_SESSION -static int wm8904_stop(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int wm8904_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int wm8904_stop(FAR struct audio_lowerhalf_s *dev) #endif @@ -1622,7 +1625,7 @@ static int wm8904_stop(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int wm8904_pause(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int wm8904_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int wm8904_pause(FAR struct audio_lowerhalf_s *dev) #endif @@ -1651,7 +1654,7 @@ static int wm8904_pause(FAR struct audio_lowerhalf_s *dev) #ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME #ifdef CONFIG_AUDIO_MULTI_SESSION -static int wm8904_resume(FAR struct audio_lowerhalf_s *dev, FAR void* session) +static int wm8904_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session) #else static int wm8904_resume(FAR struct audio_lowerhalf_s *dev) #endif diff --git a/drivers/audio/wm8904_debug.c b/drivers/audio/wm8904_debug.c index a45573ee27..d94eb2c4fb 100644 --- a/drivers/audio/wm8904_debug.c +++ b/drivers/audio/wm8904_debug.c @@ -394,7 +394,7 @@ void wm8904_clock_analysis(FAR struct audio_lowerhalf_s *dev, else { syslog(LOG_INFO, " MCLK_DIV: 2\n"); - sysclk >>=1; + sysclk >>= 1; } syslog(LOG_INFO, " SYSCLK: %lu (after divider)\n", (unsigned long)sysclk); diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 9382b4d58a..7bf5f54ed9 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -322,7 +322,7 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) #if defined(CONFIG_BCH_ENCRYPTION) else if (cmd == DIOC_SETKEY) { - memcpy(bch->key, (void*)arg, CONFIG_BCH_ENCRYPTION_KEY_SIZE); + memcpy(bch->key, (FAR void *)arg, CONFIG_BCH_ENCRYPTION_KEY_SIZE); ret = OK; } #endif diff --git a/drivers/bch/bchlib_cache.c b/drivers/bch/bchlib_cache.c index 3e46c24057..009a3eb631 100644 --- a/drivers/bch/bchlib_cache.c +++ b/drivers/bch/bchlib_cache.c @@ -91,13 +91,16 @@ static void bch_xor(uint32_t *R, uint32_t *A, uint32_t *B) static int bch_cypher(FAR struct bchlib_s *bch, int encrypt) { int blocks = bch->sectsize / 16; - uint32_t *buffer = (uint32_t*)bch->buffer; + FAR uint32_t *buffer = (FAR uint32_t *)bch->buffer; int i; for (i = 0; i < blocks; i++, buffer += 16 / sizeof(uint32_t) ) { uint32_t T[4]; - uint32_t X[4] = {bch->sector, 0, 0, i}; + uint32_t X[4] = + { + bch->sector, 0, 0, i + }; aes_cypher(X, X, 16, NULL, bch->key, CONFIG_BCH_ENCRYPTION_KEY_SIZE, AES_MODE_ECB, CYPHER_ENCRYPT); diff --git a/drivers/bch/bchlib_read.c b/drivers/bch/bchlib_read.c index 93210fcaeb..e275d5943b 100644 --- a/drivers/bch/bchlib_read.c +++ b/drivers/bch/bchlib_read.c @@ -148,7 +148,7 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t le * into the user buffer. */ - if (len >= bch->sectsize ) + if (len >= bch->sectsize) { nsectors = len / bch->sectsize; if (sector + nsectors > bch->nsectors) diff --git a/drivers/bch/bchlib_setup.c b/drivers/bch/bchlib_setup.c index e0c956a739..8dfcbbbf5b 100644 --- a/drivers/bch/bchlib_setup.c +++ b/drivers/bch/bchlib_setup.c @@ -93,7 +93,7 @@ int bchlib_setup(const char *blkdev, bool readonly, FAR void **handle) /* Allocate the BCH state structure */ - bch = (FAR struct bchlib_s*)kmm_zalloc(sizeof(struct bchlib_s)); + bch = (FAR struct bchlib_s *)kmm_zalloc(sizeof(struct bchlib_s)); if (!bch) { fdbg("Failed to allocate BCH structure\n"); diff --git a/drivers/bch/bchlib_write.c b/drivers/bch/bchlib_write.c index 07d77ce8a7..2336b11dda 100644 --- a/drivers/bch/bchlib_write.c +++ b/drivers/bch/bchlib_write.c @@ -148,7 +148,7 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, si * directly from the user buffer. */ - if (len >= bch->sectsize ) + if (len >= bch->sectsize) { nsectors = len / bch->sectsize; if (sector + nsectors > bch->nsectors) diff --git a/drivers/can.c b/drivers/can.c index 3e836ff5c5..66ba2b467e 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -795,7 +795,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, unsigned long arg) */ case CANIOC_RTR: - ret = can_rtrread(dev, (struct canioc_rtr_s*)((uintptr_t)arg)); + ret = can_rtrread(dev, (FAR struct canioc_rtr_s *)((uintptr_t)arg)); break; /* Not a "built-in" ioctl command.. perhaps it is unique to this diff --git a/drivers/dev_null.c b/drivers/dev_null.c index 1a405d7cfc..eca30dd8e1 100644 --- a/drivers/dev_null.c +++ b/drivers/dev_null.c @@ -50,11 +50,13 @@ * Private Function Prototypes ****************************************************************************/ -static ssize_t devnull_read(FAR struct file *, FAR char *, size_t); -static ssize_t devnull_write(FAR struct file *, FAR const char *, size_t); +static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); #ifndef CONFIG_DISABLE_POLL static int devnull_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup); + bool setup); #endif /**************************************************************************** @@ -106,7 +108,7 @@ static int devnull_poll(FAR struct file *filep, FAR struct pollfd *fds, { if (setup) { - fds->revents |= (fds->events & (POLLIN|POLLOUT)); + fds->revents |= (fds->events & (POLLIN | POLLOUT)); if (fds->revents != 0) { sem_post(fds->sem); diff --git a/drivers/dev_zero.c b/drivers/dev_zero.c index a1374101ad..0bb31688be 100644 --- a/drivers/dev_zero.c +++ b/drivers/dev_zero.c @@ -50,11 +50,13 @@ * Private Function Prototypes ****************************************************************************/ -static ssize_t devzero_read(FAR struct file *, FAR char *, size_t); -static ssize_t devzero_write(FAR struct file *, FAR const char *, size_t); +static ssize_t devzero_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t devzero_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); #ifndef CONFIG_DISABLE_POLL static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup); + bool setup); #endif /**************************************************************************** @@ -109,7 +111,7 @@ static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds, { if (setup) { - fds->revents |= (fds->events & (POLLIN|POLLOUT)); + fds->revents |= (fds->events & (POLLIN | POLLOUT)); if (fds->revents != 0) { sem_post(fds->sem); diff --git a/drivers/eeprom/spi_xx25xx.c b/drivers/eeprom/spi_xx25xx.c index e8c520d907..6fdc39458b 100644 --- a/drivers/eeprom/spi_xx25xx.c +++ b/drivers/eeprom/spi_xx25xx.c @@ -173,10 +173,10 @@ struct ee25xx_geom_s { - uint8_t bytes : 4; /*power of two of 128 bytes (0:128 1:256 2:512 etc) */ - uint8_t pagesize : 4; /*power of two of 8 bytes (0:8 1:16 2:32 3:64 etc)*/ - uint8_t addrlen : 4; /*number of bytes in command address field */ - uint8_t flags : 4; /*special address management for 25xx040, 1=A8 in inst*/ + uint8_t bytes : 4; /* Power of two of 128 bytes (0:128 1:256 2:512 etc) */ + uint8_t pagesize : 4; /* Power of two of 8 bytes (0:8 1:16 2:32 3:64 etc) */ + uint8_t addrlen : 4; /* Number of bytes in command address field */ + uint8_t flags : 4; /* Special address management for 25xx040, 1=A8 in inst */ }; /* Private data attached to the inode */ @@ -219,29 +219,29 @@ static const struct ee25xx_geom_s g_ee25xx_devices[] = { /* Microchip devices */ - { 0, 1, 1, 0}, /* 25xx010A 128 16 1*/ - { 1, 1, 1, 0}, /* 25xx020A 256 16 1*/ - { 2, 1, 1, 1}, /* 25xx040 512 16 1+bit*/ - { 3, 1, 1, 0}, /* 25xx080 1024 16 1*/ - { 3, 2, 2, 0}, /* 25xx080B 1024 32 2*/ - { 4, 1, 2, 0}, /* 25xx160 2048 16 2*/ - { 4, 2, 2, 0}, /* 25xx160B/D 2048 32 2*/ - { 5, 2, 2, 0}, /* 25xx320 4096 32 2*/ - { 6, 2, 2, 0}, /* 25xx640 8192 32 2*/ - { 7, 3, 2, 0}, /* 25xx128 16384 64 2*/ - { 8, 3, 2, 0}, /* 25xx256 32768 64 2*/ - { 9, 4, 2, 0}, /* 25xx512 65536 128 2*/ - {10, 5, 3, 0}, /* 25xx1024 131072 256 3*/ + { 0, 1, 1, 0}, /* 25xx010A 128 16 1 */ + { 1, 1, 1, 0}, /* 25xx020A 256 16 1 */ + { 2, 1, 1, 1}, /* 25xx040 512 16 1+bit */ + { 3, 1, 1, 0}, /* 25xx080 1024 16 1 */ + { 3, 2, 2, 0}, /* 25xx080B 1024 32 2 */ + { 4, 1, 2, 0}, /* 25xx160 2048 16 2 */ + { 4, 2, 2, 0}, /* 25xx160B/D 2048 32 2 */ + { 5, 2, 2, 0}, /* 25xx320 4096 32 2 */ + { 6, 2, 2, 0}, /* 25xx640 8192 32 2 */ + { 7, 3, 2, 0}, /* 25xx128 16384 64 2 */ + { 8, 3, 2, 0}, /* 25xx256 32768 64 2 */ + { 9, 4, 2, 0}, /* 25xx512 65536 128 2 */ + {10, 5, 3, 0}, /* 25xx1024 131072 256 3 */ /* Atmel devices */ - { 0, 0, 1, 0}, /* AT25010B 128 8 1*/ - { 1, 0, 1, 0}, /* AT25020B 256 8 1*/ - { 2, 0, 1, 1}, /* AT25040B 512 8 1+bit*/ + { 0, 0, 1, 0}, /* AT25010B 128 8 1 */ + { 1, 0, 1, 0}, /* AT25020B 256 8 1 */ + { 2, 0, 1, 1}, /* AT25040B 512 8 1+bit */ /* STM devices */ - {11, 5, 3, 0}, /* M95M02 262144 256 3*/ + {11, 5, 3, 0}, /* M95M02 262144 256 3 */ }; /* Driver operations */ @@ -337,7 +337,7 @@ static void ee25xx_sendcmd(FAR struct spi_dev_s *spi, uint8_t cmd, buf[cmdlen++] = addr & 0xff; - SPI_SNDBLOCK(spi,buf,cmdlen); + SPI_SNDBLOCK(spi, buf, cmdlen); } /**************************************************************************** @@ -488,7 +488,7 @@ static int ee25xx_open(FAR struct file *filep) /* Increment the reference count */ - if ( (eedev->refs + 1) == 0) + if ((eedev->refs + 1) == 0) { ret = -EMFILE; } @@ -678,7 +678,7 @@ static ssize_t ee25xx_write(FAR struct file *filep, FAR const char *buffer, /* Clamp len to avoid crossing the end of the memory */ - if ( (len + filep->f_pos) > eedev->size) + if ((len + filep->f_pos) > eedev->size) { len = eedev->size - filep->f_pos; } @@ -807,7 +807,7 @@ int ee25xx_initialize(FAR struct spi_dev_s *dev, FAR char *devname, eedev->size = 128 << g_ee25xx_devices[devtype].bytes; eedev->pgsize = 8 << g_ee25xx_devices[devtype].pagesize; eedev->addrlen = g_ee25xx_devices[devtype].addrlen << 3; - if ( (g_ee25xx_devices[devtype].flags & 1)) + if ((g_ee25xx_devices[devtype].flags & 1)) { eedev->addrlen = 9; } diff --git a/drivers/input/ads7843e.c b/drivers/input/ads7843e.c index f23fc7d5db..c0500229b5 100644 --- a/drivers/input/ads7843e.c +++ b/drivers/input/ads7843e.c @@ -395,7 +395,7 @@ static int ads7843e_sample(FAR struct ads7843e_dev_s *priv, * sampled data. */ - memcpy(sample, &priv->sample, sizeof(struct ads7843e_sample_s )); + memcpy(sample, &priv->sample, sizeof(struct ads7843e_sample_s)); /* Now manage state transitions */ @@ -480,7 +480,7 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv, ivdbg("Sampled\n"); - /* Re-acquire the semaphore that manages mutually exclusive access to + /* Re-acquire the semaphore that manages mutually exclusive access to * the device structure. We may have to wait here. But we have our sample. * Interrupts and pre-emption will be re-enabled while we wait. */ @@ -974,10 +974,10 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer, size_t le if (sample.contact == CONTACT_UP) { - /* Pen is now up. Is the positional data valid? This is important to - * know because the release will be sent to the window based on its - * last positional data. - */ + /* Pen is now up. Is the positional data valid? This is important to + * know because the release will be sent to the window based on its + * last positional data. + */ if (sample.valid) { diff --git a/drivers/input/ajoystick.c b/drivers/input/ajoystick.c index de4d52f404..0e00b907ed 100644 --- a/drivers/input/ajoystick.c +++ b/drivers/input/ajoystick.c @@ -143,7 +143,8 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv); static int ajoy_open(FAR struct file *filep); static int ajoy_close(FAR struct file *filep); -static ssize_t ajoy_read(FAR struct file *, FAR char *, size_t); +static ssize_t ajoy_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static int ajoy_ioctl(FAR struct file *filep, int cmd, unsigned long arg); #ifndef CONFIG_DISABLE_POLL diff --git a/drivers/input/djoystick.c b/drivers/input/djoystick.c index 0e746634f2..93a448d2ae 100644 --- a/drivers/input/djoystick.c +++ b/drivers/input/djoystick.c @@ -143,7 +143,8 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv); static int djoy_open(FAR struct file *filep); static int djoy_close(FAR struct file *filep); -static ssize_t djoy_read(FAR struct file *, FAR char *, size_t); +static ssize_t djoy_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static int djoy_ioctl(FAR struct file *filep, int cmd, unsigned long arg); #ifndef CONFIG_DISABLE_POLL @@ -585,7 +586,7 @@ static ssize_t djoy_read(FAR struct file *filep, FAR char *buffer, lower = priv->du_lower; DEBUGASSERT(lower && lower->dl_sample); priv->du_sample = lower->dl_sample(lower); - *(djoy_buttonset_t*)buffer = priv->du_sample; + *(FAR djoy_buttonset_t *)buffer = priv->du_sample; ret = sizeof(djoy_buttonset_t); djoy_givesem(&priv->du_exclsem); diff --git a/drivers/input/max11802.c b/drivers/input/max11802.c index c61b48188d..fe87fc32fe 100644 --- a/drivers/input/max11802.c +++ b/drivers/input/max11802.c @@ -285,7 +285,7 @@ static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1]; *tags = result & 0xF; - result >>= 4; // Get rid of tags + result >>= 4; /* Get rid of tags */ ivdbg("cmd:%02x response:%04x\n", cmd, result); return result; @@ -359,7 +359,7 @@ static int max11802_sample(FAR struct max11802_dev_s *priv, * sampled data. */ - memcpy(sample, &priv->sample, sizeof(struct max11802_sample_s )); + memcpy(sample, &priv->sample, sizeof(struct max11802_sample_s)); /* Now manage state transitions */ @@ -980,10 +980,10 @@ static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer, if (sample.contact == CONTACT_UP) { - /* Pen is now up. Is the positional data valid? This is important to - * know because the release will be sent to the window based on its - * last positional data. - */ + /* Pen is now up. Is the positional data valid? This is important to + * know because the release will be sent to the window based on its + * last positional data. + */ if (sample.valid) { diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index ca28f936e0..6a1ebeceb6 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -92,8 +92,8 @@ */ #define MXT_GETUINT16(p) \ - (((uint16_t)(((FAR uint8_t*)(p))[1]) << 8) | \ - (uint16_t)(((FAR uint8_t*)(p))[0])) + (((uint16_t)(((FAR uint8_t *)(p))[1]) << 8) | \ + (uint16_t)(((FAR uint8_t *)(p))[0])) /**************************************************************************** * Private Types @@ -1368,7 +1368,7 @@ static ssize_t mxt_read(FAR struct file *filep, FAR char *buffer, size_t len) memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(ncontacts)); report->npoints = ncontacts; - for (i = 0, j= 0; i < priv->nslots && j < ncontacts; i++) + for (i = 0, j = 0; i < priv->nslots && j < ncontacts; i++) { FAR struct mxt_sample_s *sample = &priv->sample[i]; diff --git a/drivers/input/stmpe811_base.c b/drivers/input/stmpe811_base.c index f2bdf8bca8..d10462e8fb 100644 --- a/drivers/input/stmpe811_base.c +++ b/drivers/input/stmpe811_base.c @@ -101,7 +101,7 @@ static void stmpe811_worker(FAR void *arg) /* Check for a touchscreen interrupt */ #ifndef CONFIG_STMPE811_TSC_DISABLE - if ((regval & (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)) != 0) + if ((regval & (INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW)) != 0) { /* Dispatch the touchscreen interrupt if it was brought into the link */ @@ -112,8 +112,9 @@ static void stmpe811_worker(FAR void *arg) stmpe811_tscworker(priv, regval); } - stmpe811_putreg8(priv, STMPE811_INT_STA, (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)); - regval &= ~(INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW); + stmpe811_putreg8(priv, STMPE811_INT_STA, + (INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW)); + regval &= ~(INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW); } #endif diff --git a/drivers/input/stmpe811_temp.c b/drivers/input/stmpe811_temp.c index 9b5e7e150f..0cb5c686c7 100644 --- a/drivers/input/stmpe811_temp.c +++ b/drivers/input/stmpe811_temp.c @@ -101,7 +101,8 @@ int stmpe811_tempinitialize(STMPE811_HANDLE handle) /* Aquire data enable */ - stmpe811_putreg8(priv, STMPE811_TEMP_CTRL, (TEMP_CTRL_ACQ|TEMP_CTRL_ENABLE)); + stmpe811_putreg8(priv, STMPE811_TEMP_CTRL, + (TEMP_CTRL_ACQ | TEMP_CTRL_ENABLE)); return OK; } @@ -130,7 +131,8 @@ uint16_t stmpe811_tempread(STMPE811_HANDLE handle) /* Acquire data enable */ - stmpe811_putreg8(priv, STMPE811_TEMP_CTRL, (TEMP_CTRL_ACQ|TEMP_CTRL_ENABLE)); + stmpe811_putreg8(priv, STMPE811_TEMP_CTRL, + (TEMP_CTRL_ACQ | TEMP_CTRL_ENABLE)); /* Read the temperature */ diff --git a/drivers/input/stmpe811_tsc.c b/drivers/input/stmpe811_tsc.c index 783e9f3dc4..723d12c92f 100644 --- a/drivers/input/stmpe811_tsc.c +++ b/drivers/input/stmpe811_tsc.c @@ -307,7 +307,7 @@ static inline int stmpe811_waitsample(FAR struct stmpe811_dev_s *priv, if (ret < 0) { #ifdef CONFIG_DEBUG - // Sample the errno (debug output could change it) + /* Sample the errno (debug output could change it) */ int errval = errno; @@ -577,11 +577,11 @@ errout: /**************************************************************************** * Name: stmpe811_ioctl - * + * * Description: * Standard character driver ioctl method. * -****************************************************************************/ + ****************************************************************************/ static int stmpe811_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { @@ -860,7 +860,7 @@ static inline void stmpe811_tscinitialize(FAR struct stmpe811_dev_s *priv) stmpe811_putreg8(priv, STMPE811_TSC_IDRIVE, TSC_IDRIVE_50MA); /* Enable the TSC. Use no tracking index, touch-screen controller - * operation mode (XYZ). + * operation mode (XYZ). */ stmpe811_putreg8(priv, STMPE811_TSC_CTRL, TSC_CTRL_EN); @@ -1019,7 +1019,7 @@ void stmpe811_tscworker(FAR struct stmpe811_dev_s *priv, uint8_t intsta) /* The pen is down... check for data in the FIFO */ - else if ((intsta & (INT_FIFO_TH|INT_FIFO_OFLOW)) != 0) + else if ((intsta & (INT_FIFO_TH | INT_FIFO_OFLOW)) != 0) { /* Read the next x and y positions from the FIFO. */ diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index c4ad245942..8f6a6930af 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -309,7 +309,7 @@ static int tsc2007_sample(FAR struct tsc2007_dev_s *priv, * sampled data. */ - memcpy(sample, &priv->sample, sizeof(struct tsc2007_sample_s )); + memcpy(sample, &priv->sample, sizeof(struct tsc2007_sample_s)); /* Now manage state transitions */ @@ -539,10 +539,10 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd) return ret; } - /* Get the MS 8 bits from the first byte and the remaining LS 4 bits from - * the second byte. The valid range of data is then from 0 to 4095 with - * the LSB unit corresponding to Vref/4096. - */ + /* Get the MS 8 bits from the first byte and the remaining LS 4 bits from + * the second byte. The valid range of data is then from 0 to 4095 with + * the LSB unit corresponding to Vref/4096. + */ ret = (unsigned int)data12[0] << 4 | (unsigned int)data12[1] >> 4; ivdbg("data: 0x%04x\n", ret); @@ -971,8 +971,8 @@ static ssize_t tsc2007_read(FAR struct file *filep, FAR char *buffer, size_t len if (sample.contact == CONTACT_UP) { - /* Pen is now up. Is the positional data valid? This is important to - * know because the release will be sent to the window based on its + /* Pen is now up. Is the positional data valid? This is important to + * know because the release will be sent to the window based on its * last positional data. */ diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index f2f06fed6e..3bf2cf1923 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -215,7 +215,7 @@ static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, int direction) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_setbit(pca->i2c, PCA9555_REG_CONFIG, pin, (direction == IOEXPANDER_DIRECTION_IN)); } @@ -231,7 +231,7 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, int opt, void *val) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; int ival = (int)val; if (opt == IOEXPANDER_OPTION_INVERT) @@ -253,7 +253,7 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_write(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_setbit(pca->i2c, PCA9555_REG_OUTPUT, pin, value); } @@ -268,7 +268,7 @@ static int pca9555_write(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_getbit(pca->i2c, PCA9555_REG_INPUT, pin, value); } @@ -283,7 +283,7 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_getbit(pca->i2c, PCA9555_REG_OUTPUT, pin, value); } @@ -348,7 +348,7 @@ static int pca9555_multiwrite(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t addr = PCA9555_REG_OUTPUT; uint8_t buf[3]; int ret; @@ -410,7 +410,7 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_getmultibits(pca->i2c, PCA9555_REG_INPUT, pins, values, count); } @@ -427,7 +427,7 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_getmultibits(pca->i2c, PCA9555_REG_OUTPUT, pins, values, count); } @@ -447,7 +447,7 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, static int pca9555_attach(FAR struct ioexpander_dev_s *dev, uint8_t pin, ioexpander_handler_t handler) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)dev; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return 0; } diff --git a/drivers/lcd/ili9341.c b/drivers/lcd/ili9341.c index c5f58aae9b..7fb8612db7 100644 --- a/drivers/lcd/ili9341.c +++ b/drivers/lcd/ili9341.c @@ -62,8 +62,7 @@ * Pre-processor Definitions ****************************************************************************/ -/* - * This is the generic lcd driver interface for the ili9341 Single Chip LCD +/* This is the generic lcd driver interface for the ili9341 Single Chip LCD * driver. The driver supports multiple displays, each connected with an own * ili9341 Single Chip LCD driver. The communication with the LCD single chip * driver must be provide by a subdriver accessable trough the ili9341_dev_s @@ -157,8 +156,7 @@ /* Memory access control (MADCTL) */ -/* - * Landscape: 00100000 / 00101000 / h28 +/* Landscape: 00100000 / 00101000 / h28 * * MY: 0 * MX: 0 @@ -186,8 +184,7 @@ ILI9341_MADCTL_LANDSCAPE_BGR | \ ILI9341_MADCTL_LANDSCAPE_MH) -/* - * Portrait: 00000000 / 00001000 / h08 +/* Portrait: 00000000 / 00001000 / h08 * * MY: 0 * MX: 0 @@ -214,8 +211,7 @@ ILI9341_MADCTL_PORTRAIT_ML | \ ILI9341_MADCTL_PORTRAIT_BGR | \ ILI9341_MADCTL_PORTRAIT_MH) -/* - * RLandscape: 01100000 / 01101000 / h68 +/* RLandscape: 01100000 / 01101000 / h68 * * MY: 0 * MX: 1 @@ -244,8 +240,7 @@ ILI9341_MADCTL_RLANDSCAPE_BGR | \ ILI9341_MADCTL_RLANDSCAPE_MH) -/* - * RPortrait: 11000000 / 11001000 / hc8 +/* RPortrait: 11000000 / 11001000 / hc8 * * MY: 1 * MX: 1 @@ -292,8 +287,7 @@ #define ILI9341_PIXSET_16BITMCU_PARAM1 (ILI9341_PIXSET_16BITDPI | \ ILI9341_PIXSET_16BITDBI) -/* - * 18-bit MCU: 01100110 / h66 (not supported by nuttx until now) +/* 18-bit MCU: 01100110 / h66 (not supported by nuttx until now) * * DPI: 6 (RGB18-666 RGB interface) * DBI: 6 (RGB18-666 MCU interface) @@ -387,8 +381,7 @@ * Private Type Definition ****************************************************************************/ -/* - * Each single connected ili9341 LCD driver needs an own driver instance +/* Each single connected ili9341 LCD driver needs an own driver instance * to provide a unique getrun and putrun method. Also store fundamental * parameter in driver internal structure. This minimal overhead should be * acceptable. @@ -453,14 +446,14 @@ static int ili9341_putrun(int devno, fb_coord_t row, fb_coord_t col, static int ili9341_getrun(int devno, fb_coord_t row, fb_coord_t col, FAR uint8_t * buffer, size_t npixels); #endif -/* - * Definition of the public visible getrun / putrun methods + +/* Definition of the public visible getrun / putrun methods * each for a single LCD driver */ #ifdef CONFIG_LCD_ILI9341_IFACE0 static int ili9341_putrun0(fb_coord_t row, fb_coord_t col, - FAR const uint8_t * buffer, size_t npixsels); + FAR const uint8_t *buffer, size_t npixsels); #endif #ifdef CONFIG_LCD_ILI9341_IFACE1 static int ili9341_putrun1(fb_coord_t row, fb_coord_t col, @@ -659,7 +652,7 @@ static int ili9341_putrun(int devno, fb_coord_t row, fb_coord_t col, { FAR struct ili9341_dev_s *dev = &g_lcddev[devno]; FAR struct ili9341_lcd_s *lcd = dev->lcd; - FAR const uint16_t *src = (const uint16_t*)buffer; + FAR const uint16_t *src = (FAR const uint16_t *)buffer; DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); @@ -720,7 +713,7 @@ static int ili9341_getrun(int devno, fb_coord_t row, fb_coord_t col, { FAR struct ili9341_dev_s *dev = &g_lcddev[devno]; FAR struct ili9341_lcd_s *lcd = dev->lcd; - FAR uint16_t *dest = (uint16_t*)buffer; + FAR uint16_t *dest = (FAR uint16_t *)buffer; DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); @@ -994,7 +987,7 @@ static int ili9341_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, pinfo->getrun = priv->getrun; #endif pinfo->bpp = priv->bpp; - pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */ + pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */ lcdvdbg("planeno: %d bpp: %d\n", planeno, pinfo->bpp); diff --git a/drivers/lcd/memlcd.c b/drivers/lcd/memlcd.c index 4046f882b5..06683ba0c9 100644 --- a/drivers/lcd/memlcd.c +++ b/drivers/lcd/memlcd.c @@ -333,15 +333,13 @@ static inline void memlcd_select(FAR struct spi_dev_s *spi) #else static void memlcd_select(FAR struct spi_dev_s *spi) { - /* - * Select memlcd (locking the SPI bus in case there are multiple + /* Select memlcd (locking the SPI bus in case there are multiple * devices competing for the SPI bus */ SPI_LOCK(spi, true); SPI_SELECT(spi, SPIDEV_DISPLAY, true); - /* - * Now make sure that the SPI bus is configured for the memlcd (it + /* Now make sure that the SPI bus is configured for the memlcd (it * might have gotten configured for a different device while unlocked) */ SPI_SETMODE(spi, MEMLCD_SPI_MODE); @@ -435,9 +433,8 @@ static int memlcd_extcominisr(int irq, FAR void *context) struct memlcd_dev_s *mlcd = &g_memlcddev; #ifdef CONFIG_MEMLCD_EXTCOMIN_MODE_HW # error "CONFIG_MEMLCD_EXTCOMIN_MODE_HW unsupported yet!" - /* - * start a worker thread, do it in bottom half? - */ + /* Start a worker thread, do it in bottom half? */ + #else pol = !pol; mlcd->priv->setpolarity(pol); diff --git a/drivers/lcd/mio283qt2.c b/drivers/lcd/mio283qt2.c index 5e68c953ef..2d078e1ff0 100644 --- a/drivers/lcd/mio283qt2.c +++ b/drivers/lcd/mio283qt2.c @@ -529,7 +529,7 @@ static int mio283qt2_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *b { FAR struct mio283qt2_dev_s *priv = &g_lcddev; FAR struct mio283qt2_lcd_s *lcd = priv->lcd; - FAR const uint16_t *src = (FAR const uint16_t*)buffer; + FAR const uint16_t *src = (FAR const uint16_t *)buffer; int i; /* Buffer must be provided and aligned to a 16-bit address boundary */ @@ -578,7 +578,7 @@ static int mio283qt2_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, #ifndef CONFIG_LCD_NOGETRUN FAR struct mio283qt2_dev_s *priv = &g_lcddev; FAR struct mio283qt2_lcd_s *lcd = priv->lcd; - FAR uint16_t *dest = (FAR uint16_t*)buffer; + FAR uint16_t *dest = (FAR uint16_t *)buffer; uint16_t accum; int i; @@ -658,10 +658,10 @@ static int mio283qt2_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planen DEBUGASSERT(dev && pinfo && planeno == 0); lcdvdbg("planeno: %d bpp: %d\n", planeno, MIO283QT2_BPP); - pinfo->putrun = mio283qt2_putrun; /* Put a run into LCD memory */ - pinfo->getrun = mio283qt2_getrun; /* Get a run from LCD memory */ - pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */ - pinfo->bpp = MIO283QT2_BPP; /* Bits-per-pixel */ + pinfo->putrun = mio283qt2_putrun; /* Put a run into LCD memory */ + pinfo->getrun = mio283qt2_getrun; /* Get a run from LCD memory */ + pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */ + pinfo->bpp = MIO283QT2_BPP; /* Bits-per-pixel */ return OK; } diff --git a/drivers/lcd/mio283qt9a.c b/drivers/lcd/mio283qt9a.c index 2a17fe763e..d98935f84f 100644 --- a/drivers/lcd/mio283qt9a.c +++ b/drivers/lcd/mio283qt9a.c @@ -382,16 +382,15 @@ static inline uint16_t mio283qt9a_gramread(FAR struct mio283qt9a_lcd_s *lcd, static void mio283qt9a_setarea(FAR struct mio283qt9a_lcd_s *lcd, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - //lcddbg("setarea x0=%d, y0=%d, x1=%d, y1=%d\n", x0, y0, x1, y1); - - mio283qt9a_putreg(lcd, 0x2a, (x0 >> 8)); /* set column address x0 */ - lcd->write(lcd, (x0 & 0xff)); /* set x0 */ - lcd->write(lcd, (x1 >> 8)); /* set x1 */ - lcd->write(lcd, (x1 & 0xff)); /* set x1 */ - mio283qt9a_putreg(lcd, 0x2b, (y0 >> 8)); /* set page address y0 */ - lcd->write(lcd, (y0 & 0xff)); /* set y0 */ - lcd->write(lcd, (y1 >> 8)); /* set y1 */ - lcd->write(lcd, (y1 & 0xff)); /* set y1 */ + mio283qt9a_putreg(lcd, 0x2a, (x0 >> 8)); /* Set column address x0 */ + lcd->write(lcd, (x0 & 0xff)); /* Set x0 */ + lcd->write(lcd, (x1 >> 8)); /* Set x1 */ + lcd->write(lcd, (x1 & 0xff)); /* Set x1 */ + + mio283qt9a_putreg(lcd, 0x2b, (y0 >> 8)); /* Set page address y0 */ + lcd->write(lcd, (y0 & 0xff)); /* Set y0 */ + lcd->write(lcd, (y1 >> 8)); /* Set y1 */ + lcd->write(lcd, (y1 & 0xff)); /* Set y1 */ } /************************************************************************************** @@ -445,12 +444,11 @@ static int mio283qt9a_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t * { FAR struct mio283qt9a_dev_s *priv = &g_lcddev; FAR struct mio283qt9a_lcd_s *lcd = priv->lcd; - FAR const uint16_t *src = (FAR const uint16_t*)buffer; + FAR const uint16_t *src = (FAR const uint16_t *)buffer; int i; /* Buffer must be provided and aligned to a 16-bit address boundary */ - //lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels); DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); /* Select the LCD */ @@ -494,7 +492,7 @@ static int mio283qt9a_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer #ifndef CONFIG_LCD_NOGETRUN FAR struct mio283qt9a_dev_s *priv = &g_lcddev; FAR struct mio283qt9a_lcd_s *lcd = priv->lcd; - FAR uint16_t *dest = (FAR uint16_t*)buffer; + FAR uint16_t *dest = (FAR uint16_t *)buffer; uint16_t accum, test; int i; @@ -520,8 +518,7 @@ static int mio283qt9a_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer for (i = 0; i < npixels; i++) { - test= mio283qt9a_gramread(lcd, &accum); - // lcddbg("read 0x%04x\n", test); + test = mio283qt9a_gramread(lcd, &accum); *dest++ = test; } @@ -572,10 +569,10 @@ static int mio283qt9a_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int plane DEBUGASSERT(dev && pinfo && planeno == 0); lcdvdbg("planeno: %d bpp: %d\n", planeno, MIO283QT9A_BPP); - pinfo->putrun = mio283qt9a_putrun; /* Put a run into LCD memory */ - pinfo->getrun = mio283qt9a_getrun; /* Get a run from LCD memory */ - pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */ - pinfo->bpp = MIO283QT9A_BPP; /* Bits-per-pixel */ + pinfo->putrun = mio283qt9a_putrun; /* Put a run into LCD memory */ + pinfo->getrun = mio283qt9a_getrun; /* Get a run from LCD memory */ + pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */ + pinfo->bpp = MIO283QT9A_BPP; /* Bits-per-pixel */ return OK; } diff --git a/drivers/lcd/nokia6100.c b/drivers/lcd/nokia6100.c index 3677d8bfe3..735ae3c628 100644 --- a/drivers/lcd/nokia6100.c +++ b/drivers/lcd/nokia6100.c @@ -435,10 +435,10 @@ static const struct fb_videoinfo_s g_videoinfo = static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = nokia_putrun, /* Put a run into LCD memory */ - .getrun = nokia_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = NOKIA_BPP, /* Bits-per-pixel */ + .putrun = nokia_putrun, /* Put a run into LCD memory */ + .getrun = nokia_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = NOKIA_BPP, /* Bits-per-pixel */ }; /* This is the standard, NuttX LCD driver object */ @@ -477,21 +477,21 @@ static struct nokia_dev_s g_lcddev = #if 1 // CONFIG_NOKIA6100_BPP == 12 static const uint8_t g_disctl[] = { - S1D15G10_DISCTL, /* Display control */ - DISCTL_CLDIV_2|DISCTL_PERIOD_8, /* P1: Divide clock by 2; switching period = 8 */ -//DISCTL_CLDIV_NONE|DISCTL_PERIOD_8, /* P1: No clock division; switching period = 8 */ - 32, /* P2: nlines/4 - 1 = 132/4 - 1 = 32 */ - 0, /* P3: No inversely highlighted lines */ - 0 /* P4: No disperion */ + S1D15G10_DISCTL, /* Display control */ + DISCTL_CLDIV_2 | DISCTL_PERIOD_8, /* P1: Divide clock by 2; switching period = 8 */ +//DISCTL_CLDIV_NONE | DISCTL_PERIOD_8, /* P1: No clock division; switching period = 8 */ + 32, /* P2: nlines/4 - 1 = 132/4 - 1 = 32 */ + 0, /* P3: No inversely highlighted lines */ + 0 /* P4: No disperion */ }; #else /* CONFIG_NOKIA6100_BPP == 8 */ static const uint8_t g_disctl[] = { - S1D15G10_DISCTL, /* Display control */ - DISCTL_CLDIV_2|DISCTL_PERIOD_FLD, /* P1: Divide clock by 2; switching period = field */ - 32, /* P2: nlines/4 - 1 = 132/4 - 1 = 32 */ - 0, /* P3: No inversely highlighted lines */ - 0 /* P4: No disperion */ + S1D15G10_DISCTL, /* Display control */ + DISCTL_CLDIV_2 | DISCTL_PERIOD_FLD, /* P1: Divide clock by 2; switching period = field */ + 32, /* P2: nlines/4 - 1 = 132/4 - 1 = 32 */ + 0, /* P3: No inversely highlighted lines */ + 0 /* P4: No disperion */ }; #endif @@ -501,8 +501,8 @@ static const uint8_t g_disctl[] = static const uint8_t g_comscn[] = { - S1D15G10_COMSCN, /* Common scan direction */ - 1 /* 0x01 = Scan 1->68, 132<-69 */ + S1D15G10_COMSCN, /* Common scan direction */ + 1 /* 0x01 = Scan 1->68, 132<-69 */ }; /* Power control: @@ -513,7 +513,7 @@ static const uint8_t g_comscn[] = static const uint8_t g_pwrctr[] = { S1D15G10_PWRCTR, /* Power control */ - PWCTR_REFVOLTAGE|PWCTR_REGULATOR|PWCTR_BOOSTER2|PWCTR_BOOSTER1 + PWCTR_REFVOLTAGE | PWCTR_REGULATOR | PWCTR_BOOSTER2 | PWCTR_BOOSTER1 }; /* Data control: @@ -528,13 +528,13 @@ static const uint8_t g_datctl[] = S1D15G10_DATCTL, /* Data control */ 0 #if CONFIG_NOKIA6100_MY != 0 /* Display row direction */ - |DATCTL_PGADDR_INV /* Page address inverted */ + | DATCTL_PGADDR_INV /* Page address inverted */ #endif #if CONFIG_NOKIA6100_MX != 0 /* Display column direction */ - |DATCTL_COLADDR_REV /* Column address reversed */ + | DATCTL_COLADDR_REV /* Column address reversed */ #endif #if CONFIG_NOKIA6100_V != 0 /* Display address direction */ - |DATCTL_ADDR_PGDIR /* Address scan in page direction */ + | DATCTL_ADDR_PGDIR /* Address scan in page direction */ #endif , #if CONFIG_NOKIA6100_RGBORD != 0 @@ -617,22 +617,22 @@ static const uint8_t g_colmod[] = static const uint8_t g_madctl[] = { - PCF8833_MADCTL, /* Memory data access control*/ + PCF8833_MADCTL, /* Memory data access control */ 0 #ifdef CONFIG_NOKIA6100_RGBORD != 0 - |MADCTL_RGB /* RGB->BGR */ + | MADCTL_RGB /* RGB->BGR */ #endif -#ifdef CONFIG_NOKIA6100_MY != 0 /* Display row direction */ - |MADCTL_MY /* Mirror Y */ +#ifdef CONFIG_NOKIA6100_MY != 0 /* Display row direction */ + | MADCTL_MY /* Mirror Y */ #endif -#ifdef CONFIG_NOKIA6100_MX != 0 /* Display column direction */ - |MADCTL_MX /* Mirror X */ +#ifdef CONFIG_NOKIA6100_MX != 0 /* Display column direction */ + | MADCTL_MX /* Mirror X */ #endif -#ifdef CONFIG_NOKIA6100_V != 0 /* Display address direction */ - |MADCTL_V /* ertical RAM write; in Y direction */ +#ifdef CONFIG_NOKIA6100_V != 0 /* Display address direction */ + | MADCTL_V /* ertical RAM write; in Y direction */ #endif -#ifdef CONFIG_NOKIA6100_ML != 0 /* Display scan direction */ - |MADCTL_LAO /* Line address order bottom to top */ +#ifdef CONFIG_NOKIA6100_ML != 0 /* Display scan direction */ + | MADCTL_LAO /* Line address order bottom to top */ #endif }; @@ -931,7 +931,7 @@ static int nokia_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffe #if NOKIA_YBIAS > 0 row += NOKIA_YBIAS; #endif - DEBUGASSERT(buffer && col >=0 && (col + npixels) <= NOKIA_XRES && row >= 0 && row < NOKIA_YRES); + DEBUGASSERT(buffer && col >= 0 && (col + npixels) <= NOKIA_XRES && row >= 0 && row < NOKIA_YRES); /* Set up to write the run. */ diff --git a/drivers/lcd/p14201.c b/drivers/lcd/p14201.c index 26ded62a28..a97a608e32 100644 --- a/drivers/lcd/p14201.c +++ b/drivers/lcd/p14201.c @@ -283,20 +283,20 @@ static uint8_t g_framebuffer[RIT_YRES * RIT_XRES / 2]; static const struct fb_videoinfo_s g_videoinfo = { - .fmt = RIT_COLORFMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */ - .xres = RIT_XRES, /* Horizontal resolution in pixel columns */ - .yres = RIT_YRES, /* Vertical resolution in pixel rows */ - .nplanes = 1, /* Number of color planes supported */ + .fmt = RIT_COLORFMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */ + .xres = RIT_XRES, /* Horizontal resolution in pixel columns */ + .yres = RIT_YRES, /* Vertical resolution in pixel rows */ + .nplanes = 1, /* Number of color planes supported */ }; /* This is the standard, NuttX Plane information object */ static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = rit_putrun, /* Put a run into LCD memory */ - .getrun = rit_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = RIT_BPP, /* Bits-per-pixel */ + .putrun = rit_putrun, /* Put a run into LCD memory */ + .getrun = rit_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = RIT_BPP, /* Bits-per-pixel */ }; /* This is the OLED driver instance (only a single device is supported for now) */ @@ -347,8 +347,8 @@ static const uint8_t g_initcmds[] = (31 << 1) | SSD1329_PRECHRG2_DBL, /* Pre-charge speed == 32, doubled */ SSD1329_NOOP, 3, SSD1329_GDDRAM_REMAP, /* Set GDDRAM re-map */ - (SSD1329_COM_SPLIT| /* Enable COM slip even/odd */ - SSD1329_COM_REMAP| /* Enable COM re-map */ + (SSD1329_COM_SPLIT | /* Enable COM slip even/odd */ + SSD1329_COM_REMAP | /* Enable COM re-map */ SSD1329_NIBBLE_REMAP), /* Enable nibble re-map */ SSD1329_NOOP, 3, SSD1329_VERT_START, /* Set Display Start Line */ @@ -405,7 +405,7 @@ static const uint8_t g_sleepon[] = static const uint8_t g_horzinc[] = { SSD1329_GDDRAM_REMAP, - (SSD1329_COM_SPLIT|SSD1329_COM_REMAP|SSD1329_NIBBLE_REMAP), + (SSD1329_COM_SPLIT | SSD1329_COM_REMAP | SSD1329_NIBBLE_REMAP), }; /* The following set a window that covers the entire display */ @@ -570,7 +570,7 @@ static void rit_sndbytes(FAR struct rit_dev_s *priv, FAR const uint8_t *buffer, uint8_t tmp; ritdbg("buflen: %d cmd: %s [%02x %02x %02x]\n", - buflen, cmd ? "YES" : "NO", buffer[0], buffer[1], buffer[2] ); + buflen, cmd ? "YES" : "NO", buffer[0], buffer[1], buffer[2]); DEBUGASSERT(spi); /* Clear/set the D/Cn bit to enable command or data mode */ @@ -769,19 +769,19 @@ static int rit_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer, memcpy(&run[start], buffer, aend - start); } - /* An even number of byte-aligned pixel pairs have been written (where - * zero counts as an even number). If npixels was was odd (including - * npixels == 1), then handle the final, byte aligned pixel. - */ + /* An even number of byte-aligned pixel pairs have been written (where + * zero counts as an even number). If npixels was was odd (including + * npixels == 1), then handle the final, byte aligned pixel. + */ - if (aend != end) - { - /* The leftmost column is contained in source bits 7:4 and in - * destination bits 7:4 - */ + if (aend != end) + { + /* The leftmost column is contained in source bits 7:4 and in + * destination bits 7:4 + */ - run[aend] = (run[aend] & 0x0f) | (buffer[aend - start] & 0xf0); - } + run[aend] = (run[aend] & 0x0f) | (buffer[aend - start] & 0xf0); + } } /* CASE 2: First pixel X position is byte aligned @@ -825,10 +825,10 @@ static int rit_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer, run[i] = (last << 4) | (curr >> 4); } - /* An odd number of unaligned pixel have been written (where npixels - * may have been as small as one). If npixels was was even, then handle - * the final, unaligned pixel. - */ + /* An odd number of unaligned pixel have been written (where npixels + * may have been as small as one). If npixels was was even, then handle + * the final, unaligned pixel. + */ if (aend != end) { diff --git a/drivers/lcd/ra8875.c b/drivers/lcd/ra8875.c index cef1157a79..aa8758ab64 100644 --- a/drivers/lcd/ra8875.c +++ b/drivers/lcd/ra8875.c @@ -391,9 +391,10 @@ static void ra8875_waitreg(FAR struct ra8875_lcd_s *lcd, uint8_t regaddr, uint8_ { int i = 20000/100; - while (i-- && ra8875_readreg(lcd, regaddr) & mask) { - up_udelay(100); - } + while (i-- && ra8875_readreg(lcd, regaddr) & mask) + { + up_udelay(100); + } } #endif @@ -624,9 +625,9 @@ static int ra8875_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buff #if RA8875_BPP == 16 DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); - FAR const uint16_t *src = (FAR const uint16_t*)buffer; + FAR const uint16_t *src = (FAR const uint16_t *)buffer; #else - FAR const uint8_t *src = (FAR const uint8_t*)buffer; + FAR const uint8_t *src = (FAR const uint8_t *)buffer; #endif int i; @@ -733,7 +734,7 @@ static int ra8875_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, #ifndef CONFIG_LCD_NOGETRUN FAR struct ra8875_dev_s *priv = &g_lcddev; FAR struct ra8875_lcd_s *lcd = priv->lcd; - FAR uint16_t *dest = (FAR uint16_t*)buffer; + FAR uint16_t *dest = (FAR uint16_t *)buffer; int i; /* Buffer must be provided and aligned to a 16-bit address boundary */ @@ -854,10 +855,10 @@ static int ra8875_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, DEBUGASSERT(dev && pinfo && planeno == 0); lcdvdbg("planeno: %d bpp: %d\n", planeno, RA8875_BPP); - pinfo->putrun = ra8875_putrun; /* Put a run into LCD memory */ - pinfo->getrun = ra8875_getrun; /* Get a run from LCD memory */ - pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */ - pinfo->bpp = RA8875_BPP; /* Bits-per-pixel */ + pinfo->putrun = ra8875_putrun; /* Put a run into LCD memory */ + pinfo->getrun = ra8875_getrun; /* Get a run from LCD memory */ + pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */ + pinfo->bpp = RA8875_BPP; /* Bits-per-pixel */ return OK; } @@ -990,7 +991,7 @@ static inline int ra8875_hwinitialize(FAR struct ra8875_dev_s *priv) uint8_t rv; FAR struct ra8875_lcd_s *lcd = priv->lcd; - /*@@TODO: Maybe some of these values needs to be configurable?? */ + /* REVISIT: Maybe some of these values needs to be configurable?? */ lcdvdbg("hwinitialize\n"); diff --git a/drivers/lcd/skeleton.c b/drivers/lcd/skeleton.c index 1c02c40b24..454fdcc41a 100644 --- a/drivers/lcd/skeleton.c +++ b/drivers/lcd/skeleton.c @@ -178,10 +178,10 @@ static const struct fb_videoinfo_s g_videoinfo = static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = skel_putrun, /* Put a run into LCD memory */ - .getrun = skel_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = SKEL_BPP, /* Bits-per-pixel */ + .putrun = skel_putrun, /* Put a run into LCD memory */ + .getrun = skel_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = SKEL_BPP, /* Bits-per-pixel */ }; /* This is the standard, NuttX LCD driver object */ diff --git a/drivers/lcd/ssd1289.c b/drivers/lcd/ssd1289.c index 8385101191..f5cef7996c 100644 --- a/drivers/lcd/ssd1289.c +++ b/drivers/lcd/ssd1289.c @@ -588,7 +588,7 @@ static int ssd1289_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buf { FAR struct ssd1289_dev_s *priv = &g_lcddev; FAR struct ssd1289_lcd_s *lcd = priv->lcd; - FAR const uint16_t *src = (FAR const uint16_t*)buffer; + FAR const uint16_t *src = (FAR const uint16_t *)buffer; int i; /* Buffer must be provided and aligned to a 16-bit address boundary */ @@ -718,7 +718,7 @@ static int ssd1289_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, #ifndef CONFIG_LCD_NOGETRUN FAR struct ssd1289_dev_s *priv = &g_lcddev; FAR struct ssd1289_lcd_s *lcd = priv->lcd; - FAR uint16_t *dest = (FAR uint16_t*)buffer; + FAR uint16_t *dest = (FAR uint16_t *)buffer; uint16_t accum; int i; @@ -872,10 +872,10 @@ static int ssd1289_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, DEBUGASSERT(dev && pinfo && planeno == 0); lcdvdbg("planeno: %d bpp: %d\n", planeno, SSD1289_BPP); - pinfo->putrun = ssd1289_putrun; /* Put a run into LCD memory */ - pinfo->getrun = ssd1289_getrun; /* Get a run from LCD memory */ - pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */ - pinfo->bpp = SSD1289_BPP; /* Bits-per-pixel */ + pinfo->putrun = ssd1289_putrun; /* Put a run into LCD memory */ + pinfo->getrun = ssd1289_getrun; /* Get a run from LCD memory */ + pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */ + pinfo->bpp = SSD1289_BPP; /* Bits-per-pixel */ return OK; } diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index 5186850d89..a47fb590bc 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -208,10 +208,10 @@ static const struct fb_videoinfo_s g_videoinfo = static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = ssd1306_putrun, /* Put a run into LCD memory */ - .getrun = ssd1306_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = SSD1306_DEV_BPP, /* Bits-per-pixel */ + .putrun = ssd1306_putrun, /* Put a run into LCD memory */ + .getrun = ssd1306_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = SSD1306_DEV_BPP, /* Bits-per-pixel */ }; /* This is the OLED driver instance (only a single device is supported for now) */ @@ -864,40 +864,40 @@ FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_dev_s *dev, unsigned int /* Configure the device */ - ssd1306_sendbyte(priv, SSD1306_DISPOFF); /* Display off 0xae */ - ssd1306_sendbyte(priv, SSD1306_SETCOLL(0)); /* Set lower column address 0x00 */ - ssd1306_sendbyte(priv, SSD1306_SETCOLH(0)); /* Set higher column address 0x10 */ - ssd1306_sendbyte(priv, SSD1306_STARTLINE(0)); /* Set display start line 0x40 */ - /* ssd1306_sendbyte(priv, SSD1306_PAGEADDR(0));*//* Set page address (Can ignore)*/ - ssd1306_sendbyte(priv, SSD1306_CONTRAST_MODE); /* Contrast control 0x81 */ - ssd1306_sendbyte(priv,SSD1306_CONTRAST(SSD1306_DEV_CONTRAST)); /* Default contrast 0xCF */ - ssd1306_sendbyte(priv, SSD1306_REMAPPLEFT); /* Set segment remap left 95 to 0 | 0xa1 */ - /* ssd1306_sendbyte(priv, SSD1306_EDISPOFF); */ /* Normal display off 0xa4 (Can ignore)*/ - ssd1306_sendbyte(priv, SSD1306_NORMAL); /* Normal (un-reversed) display mode 0xa6 */ - ssd1306_sendbyte(priv, SSD1306_MRATIO_MODE); /* Multiplex ratio 0xa8 */ + ssd1306_sendbyte(priv, SSD1306_DISPOFF); /* Display off 0xae */ + ssd1306_sendbyte(priv, SSD1306_SETCOLL(0)); /* Set lower column address 0x00 */ + ssd1306_sendbyte(priv, SSD1306_SETCOLH(0)); /* Set higher column address 0x10 */ + ssd1306_sendbyte(priv, SSD1306_STARTLINE(0)); /* Set display start line 0x40 */ + //ssd1306_sendbyte(priv, SSD1306_PAGEADDR(0)); /* Set page address (Can ignore) */ + ssd1306_sendbyte(priv, SSD1306_CONTRAST_MODE); /* Contrast control 0x81 */ + ssd1306_sendbyte(priv, SSD1306_CONTRAST(SSD1306_DEV_CONTRAST)); /* Default contrast 0xCF */ + ssd1306_sendbyte(priv, SSD1306_REMAPPLEFT); /* Set segment remap left 95 to 0 | 0xa1 */ + //ssd1306_sendbyte(priv, SSD1306_EDISPOFF); /* Normal display off 0xa4 (Can ignore) */ + ssd1306_sendbyte(priv, SSD1306_NORMAL); /* Normal (un-reversed) display mode 0xa6 */ + ssd1306_sendbyte(priv, SSD1306_MRATIO_MODE); /* Multiplex ratio 0xa8 */ ssd1306_sendbyte(priv, SSD1306_MRATIO(SSD1306_DEV_DUTY)); /* Duty = 1/64 or 1/32 */ - /* ssd1306_sendbyte(priv, SSD1306_SCANTOCOM0);*/ /* Com scan direction: Scan from COM[n-1] to COM[0] (Can ignore)*/ - ssd1306_sendbyte(priv, SSD1306_DISPOFFS_MODE); /* Set display offset 0xd3 */ + //ssd1306_sendbyte(priv, SSD1306_SCANTOCOM0); /* Com scan direction: Scan from COM[n-1] to COM[0] (Can ignore) */ + ssd1306_sendbyte(priv, SSD1306_DISPOFFS_MODE); /* Set display offset 0xd3 */ ssd1306_sendbyte(priv, SSD1306_DISPOFFS(0)); - ssd1306_sendbyte(priv, SSD1306_CLKDIV_SET); /* Set clock divider 0xd5*/ - ssd1306_sendbyte(priv, SSD1306_CLKDIV(8,0)); /* 0x80*/ + ssd1306_sendbyte(priv, SSD1306_CLKDIV_SET); /* Set clock divider 0xd5 */ + ssd1306_sendbyte(priv, SSD1306_CLKDIV(8, 0)); /* 0x80 */ - ssd1306_sendbyte(priv, SSD1306_CHRGPER_SET); /* Set pre-charge period 0xd9 */ - ssd1306_sendbyte(priv, SSD1306_CHRGPER(0x0f,1)); /* 0xf1 or 0x22 Enhanced mode */ + ssd1306_sendbyte(priv, SSD1306_CHRGPER_SET); /* Set pre-charge period 0xd9 */ + ssd1306_sendbyte(priv, SSD1306_CHRGPER(0x0f, 1)); /* 0xf1 or 0x22 Enhanced mode */ - ssd1306_sendbyte(priv, SSD1306_CMNPAD_CONFIG); /* Set common pads / set com pins hardware configuration 0xda */ + ssd1306_sendbyte(priv, SSD1306_CMNPAD_CONFIG); /* Set common pads / set com pins hardware configuration 0xda */ ssd1306_sendbyte(priv, SSD1306_CMNPAD(SSD1306_DEV_CMNPAD)); /* 0x12 or 0x02 */ - ssd1306_sendbyte(priv, SSD1306_VCOM_SET); /* set vcomh 0xdb*/ + ssd1306_sendbyte(priv, SSD1306_VCOM_SET); /* set vcomh 0xdb */ ssd1306_sendbyte(priv, SSD1306_VCOM(0x40)); - ssd1306_sendbyte(priv, SSD1306_CHRPUMP_SET); /* Set Charge Pump enable/disable 0x8d ssd1306 */ - ssd1306_sendbyte(priv, SSD1306_CHRPUMP_ON); /* 0x14 close 0x10 */ + ssd1306_sendbyte(priv, SSD1306_CHRPUMP_SET); /* Set Charge Pump enable/disable 0x8d ssd1306 */ + ssd1306_sendbyte(priv, SSD1306_CHRPUMP_ON); /* 0x14 close 0x10 */ - /* ssd1306_sendbyte(priv, SSD1306_DCDC_MODE); */ /* DC/DC control mode: on (SSD1306 Not supported) */ - /* ssd1306_sendbyte(priv, SSD1306_DCDC_ON); */ + //ssd1306_sendbyte(priv, SSD1306_DCDC_MODE); /* DC/DC control mode: on (SSD1306 Not supported) */ + //ssd1306_sendbyte(priv, SSD1306_DCDC_ON); - ssd1306_sendbyte(priv, SSD1306_DISPON); /* Display ON 0xaf */ + ssd1306_sendbyte(priv, SSD1306_DISPON); /* Display ON 0xaf */ /* De-select and unlock the device */ diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c index fb42531d2a..6b4a1c0288 100644 --- a/drivers/lcd/st7565.c +++ b/drivers/lcd/st7565.c @@ -990,14 +990,16 @@ FAR struct lcd_dev_s *st7565_initialize(FAR struct st7565_lcd_s *lcd, st7565_reset(priv, true); /* it seems too long but written in NHDâ€C12864KGZ DISPLAY - * INITIALIZATION... */ + * INITIALIZATION... + */ up_mdelay(150); st7565_reset(priv, false); /* it seems too long but written in NHDâ€C12864KGZ DISPLAY - * INITIALIZATION... */ + * INITIALIZATION... + */ up_mdelay(150); @@ -1009,7 +1011,7 @@ FAR struct lcd_dev_s *st7565_initialize(FAR struct st7565_lcd_s *lcd, st7565_cmddata(priv, true); - /* reset by command in case of st7565_reset not implemeted */ + /* Reset by command in case of st7565_reset not implemeted */ (void)st7565_send_one_data(priv, ST7565_EXIT_SOFTRST); diff --git a/drivers/lcd/st7567.c b/drivers/lcd/st7567.c index 9e8405c64b..33d4a773ef 100644 --- a/drivers/lcd/st7567.c +++ b/drivers/lcd/st7567.c @@ -315,17 +315,17 @@ static const struct fb_videoinfo_s g_videoinfo = .fmt = ST7567_COLORFMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */ .xres = ST7567_XRES, /* Horizontal resolution in pixel columns */ .yres = ST7567_YRES, /* Vertical resolution in pixel rows */ - .nplanes = 1, /* Number of color planes supported */ + .nplanes = 1, /* Number of color planes supported */ }; /* This is the standard, NuttX Plane information object */ static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = st7567_putrun, /* Put a run into LCD memory */ - .getrun = st7567_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = ST7567_BPP, /* Bits-per-pixel */ + .putrun = st7567_putrun, /* Put a run into LCD memory */ + .getrun = st7567_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = ST7567_BPP, /* Bits-per-pixel */ }; /* This is the standard, NuttX LCD driver object */ diff --git a/drivers/lcd/ug-2864ambag01.c b/drivers/lcd/ug-2864ambag01.c index 7987c3b7c8..ffc3a8a8b1 100644 --- a/drivers/lcd/ug-2864ambag01.c +++ b/drivers/lcd/ug-2864ambag01.c @@ -375,10 +375,10 @@ static const struct fb_videoinfo_s g_videoinfo = static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = ug2864ambag01_putrun, /* Put a run into LCD memory */ - .getrun = ug2864ambag01_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = UG2864AMBAG01_BPP, /* Bits-per-pixel */ + .putrun = ug2864ambag01_putrun, /* Put a run into LCD memory */ + .getrun = ug2864ambag01_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = UG2864AMBAG01_BPP, /* Bits-per-pixel */ }; /* This is the OLED driver instance (only a single device is supported for now) */ @@ -1099,7 +1099,7 @@ FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi, unsign SPI_SEND(spi, SH1101A_STARTLINE(0)); /* Set display start line */ SPI_SEND(spi, SH1101A_PAGEADDR(0)); /* Set page address */ SPI_SEND(spi, SH1101A_CONTRAST_MODE); /* Contrast control */ - SPI_SEND(spi ,UG2864AMBAG01_CONTRAST); /* Default contrast */ + SPI_SEND(spi, UG2864AMBAG01_CONTRAST); /* Default contrast */ SPI_SEND(spi, SH1101A_REMAPPLEFT); /* Set segment remap left */ SPI_SEND(spi, SH1101A_EDISPOFF); /* Normal display */ SPI_SEND(spi, SH1101A_NORMAL); /* Normal (un-reversed) display mode */ @@ -1109,7 +1109,7 @@ FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi, unsign SPI_SEND(spi, SH1101A_DISPOFFS_MODE); /* Set display offset */ SPI_SEND(spi, SH1101A_DISPOFFS(0)); SPI_SEND(spi, SH1101A_CLKDIV_SET); /* Set clock divider */ - SPI_SEND(spi, SH1101A_CLKDIV(0,0)); + SPI_SEND(spi, SH1101A_CLKDIV(0, 0)); SPI_SEND(spi, SH1101A_CMNPAD_CONFIG); /* Set common pads */ SPI_SEND(spi, SH1101A_CMNPAD(0x10)); SPI_SEND(spi, SH1101A_VCOM_SET); diff --git a/drivers/lcd/ug-9664hswag01.c b/drivers/lcd/ug-9664hswag01.c index 107703a53a..5a567688ac 100644 --- a/drivers/lcd/ug-9664hswag01.c +++ b/drivers/lcd/ug-9664hswag01.c @@ -337,10 +337,10 @@ static const struct fb_videoinfo_s g_videoinfo = static const struct lcd_planeinfo_s g_planeinfo = { - .putrun = ug_putrun, /* Put a run into LCD memory */ - .getrun = ug_getrun, /* Get a run from LCD memory */ - .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ - .bpp = UG_BPP, /* Bits-per-pixel */ + .putrun = ug_putrun, /* Put a run into LCD memory */ + .getrun = ug_getrun, /* Get a run from LCD memory */ + .buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */ + .bpp = UG_BPP, /* Bits-per-pixel */ }; /* This is the standard, NuttX LCD driver object */ @@ -1109,7 +1109,7 @@ FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devn (void)SPI_SEND(spi, 0x80); /* Data 1: Set 1 of 256 contrast steps */ (void)SPI_SEND(spi, SSD1305_MAPCOL131); /* Set segment re-map */ (void)SPI_SEND(spi, SSD1305_DISPNORMAL); /* Set normal display */ -/*(void)SPI_SEND(spi, SSD1305_DISPINVERTED); Set inverse display */ +//(void)SPI_SEND(spi, SSD1305_DISPINVERTED); /* Set inverse display */ (void)SPI_SEND(spi, SSD1305_SETMUX); /* Set multiplex ratio */ (void)SPI_SEND(spi, 0x3f); /* Data 1: MUX ratio -1: 15-63 */ (void)SPI_SEND(spi, SSD1305_SETOFFSET); /* Set display offset */ diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 2ff3fd717d..2a1be9595d 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -498,9 +498,11 @@ static int mmcsd_getSCR(FAR struct mmcsd_state_s *priv, uint32_t scr[2]) /* Setup up to receive data with interrupt mode */ SDIO_BLOCKSETUP(priv->dev, 8, 1); - SDIO_RECVSETUP(priv->dev, (FAR uint8_t*)scr, 8); + SDIO_RECVSETUP(priv->dev, (FAR uint8_t *)scr, 8); - (void)SDIO_WAITENABLE(priv->dev, SDIOWAIT_TRANSFERDONE|SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR); + (void)SDIO_WAITENABLE(priv->dev, + SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT | + SDIOWAIT_ERROR); /* Send CMD55 APP_CMD with argument as card's RCA */ @@ -525,7 +527,8 @@ static int mmcsd_getSCR(FAR struct mmcsd_state_s *priv, uint32_t scr[2]) /* Wait for data to be transferred */ - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, MMCSD_SCR_DATADELAY); + ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, + MMCSD_SCR_DATADELAY); if (ret != OK) { fdbg("ERROR: mmcsd_eventwait for READ DATA failed: %d\n", ret); @@ -954,7 +957,7 @@ struct mmcsd_scr_s decoded; fvdbg("SCR:\n"); fvdbg(" SCR_STRUCTURE: %d SD_VERSION: %d\n", - decoded.scrversion,decoded.sdversion); + decoded.scrversion, decoded.sdversion); fvdbg(" DATA_STATE_AFTER_ERASE: %d SD_SECURITY: %d SD_BUS_WIDTHS: %x\n", decoded.erasestate, decoded.security, decoded.buswidth); fvdbg(" Manufacturing data: %08x\n", @@ -1151,7 +1154,7 @@ static int mmcsd_transferready(FAR struct mmcsd_state_s *priv) */ #if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE) - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, + ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, MMCSD_BLOCK_WDATADELAY); if (ret != OK) { @@ -1353,7 +1356,8 @@ static ssize_t mmcsd_readsingle(FAR struct mmcsd_state_s *priv, /* Configure SDIO controller hardware for the read transfer */ SDIO_BLOCKSETUP(priv->dev, priv->blocksize, 1); - SDIO_WAITENABLE(priv->dev, SDIOWAIT_TRANSFERDONE|SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR); + SDIO_WAITENABLE(priv->dev, + SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR); #ifdef CONFIG_SDIO_DMA if (priv->dma) @@ -1388,7 +1392,8 @@ static ssize_t mmcsd_readsingle(FAR struct mmcsd_state_s *priv, /* Then wait for the data transfer to complete */ - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, MMCSD_BLOCK_RDATADELAY); + ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, + MMCSD_BLOCK_RDATADELAY); if (ret != OK) { fdbg("ERROR: CMD17 transfer failed: %d\n", ret); @@ -1485,7 +1490,8 @@ static ssize_t mmcsd_readmultiple(FAR struct mmcsd_state_s *priv, /* Configure SDIO controller hardware for the read transfer */ SDIO_BLOCKSETUP(priv->dev, priv->blocksize, nblocks); - SDIO_WAITENABLE(priv->dev, SDIOWAIT_TRANSFERDONE|SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR); + SDIO_WAITENABLE(priv->dev, + SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR); #ifdef CONFIG_SDIO_DMA if (priv->dma) @@ -1518,7 +1524,8 @@ static ssize_t mmcsd_readmultiple(FAR struct mmcsd_state_s *priv, /* Wait for the transfer to complete */ - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, nblocks * MMCSD_BLOCK_RDATADELAY); + ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, + nblocks * MMCSD_BLOCK_RDATADELAY); if (ret != OK) { fdbg("ERROR: CMD18 transfer failed: %d\n", ret); @@ -1698,7 +1705,8 @@ static ssize_t mmcsd_writesingle(FAR struct mmcsd_state_s *priv, /* Configure SDIO controller hardware for the write transfer */ SDIO_BLOCKSETUP(priv->dev, priv->blocksize, 1); - SDIO_WAITENABLE(priv->dev, SDIOWAIT_TRANSFERDONE|SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR); + SDIO_WAITENABLE(priv->dev, + SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR); #ifdef CONFIG_SDIO_DMA if (priv->dma) { @@ -1723,7 +1731,8 @@ static ssize_t mmcsd_writesingle(FAR struct mmcsd_state_s *priv, /* Wait for the transfer to complete */ - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, MMCSD_BLOCK_WDATADELAY); + ret = mmcsd_eventwait(priv, + SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, MMCSD_BLOCK_WDATADELAY); if (ret != OK) { fdbg("ERROR: CMD24 transfer failed: %d\n", ret); @@ -1733,7 +1742,7 @@ static ssize_t mmcsd_writesingle(FAR struct mmcsd_state_s *priv, #if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE) /* Arm the write complete detection with timeout */ - SDIO_WAITENABLE(priv->dev, SDIOWAIT_WRCOMPLETE|SDIOWAIT_TIMEOUT); + SDIO_WAITENABLE(priv->dev, SDIOWAIT_WRCOMPLETE | SDIOWAIT_TIMEOUT); #endif /* On success, return the number of blocks written */ @@ -1859,7 +1868,8 @@ static ssize_t mmcsd_writemultiple(FAR struct mmcsd_state_s *priv, /* Configure SDIO controller hardware for the write transfer */ SDIO_BLOCKSETUP(priv->dev, priv->blocksize, nblocks); - SDIO_WAITENABLE(priv->dev, SDIOWAIT_TRANSFERDONE|SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR); + SDIO_WAITENABLE(priv->dev, + SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR); #ifdef CONFIG_SDIO_DMA if (priv->dma) { @@ -1896,7 +1906,7 @@ static ssize_t mmcsd_writemultiple(FAR struct mmcsd_state_s *priv, /* Wait for the transfer to complete */ - ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT|SDIOWAIT_ERROR, nblocks * MMCSD_BLOCK_WDATADELAY); + ret = mmcsd_eventwait(priv, SDIOWAIT_TIMEOUT | SDIOWAIT_ERROR, nblocks * MMCSD_BLOCK_WDATADELAY); if (ret != OK) { fdbg("ERROR: CMD18 transfer failed: %d\n", ret); @@ -2749,7 +2759,8 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv) * CMD8 Response: R7 */ - ret = mmcsd_sendcmdpoll(priv, SD_CMD8, MMCSD_CMD8CHECKPATTERN|MMCSD_CMD8VOLTAGE_27); + ret = mmcsd_sendcmdpoll(priv, SD_CMD8, + MMCSD_CMD8CHECKPATTERN | MMCSD_CMD8VOLTAGE_27); if (ret == OK) { /* CMD8 was sent successfully... Get the R7 response */ @@ -2815,7 +2826,8 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv) { /* Send ACMD41 */ - mmcsd_sendcmdpoll(priv, SD_ACMD41, MMCSD_ACMD41_VOLTAGEWINDOW_33_32|sdcapacity); + mmcsd_sendcmdpoll(priv, SD_ACMD41, + MMCSD_ACMD41_VOLTAGEWINDOW_33_32 | sdcapacity); ret = SDIO_RECVR3(priv->dev, SD_ACMD41, &response); if (ret != OK) { @@ -3009,18 +3021,18 @@ static int mmcsd_probe(FAR struct mmcsd_state_s *priv) switch (priv->type) { - case MMCSD_CARDTYPE_SDV1: /* Bit 1: SD version 1.x */ - case MMCSD_CARDTYPE_SDV2: /* SD version 2.x with byte addressing */ - case MMCSD_CARDTYPE_SDV2|MMCSD_CARDTYPE_BLOCK: /* SD version 2.x with block addressing */ + case MMCSD_CARDTYPE_SDV1: /* Bit 1: SD version 1.x */ + case MMCSD_CARDTYPE_SDV2: /* SD version 2.x with byte addressing */ + case MMCSD_CARDTYPE_SDV2 | MMCSD_CARDTYPE_BLOCK: /* SD version 2.x with block addressing */ ret = mmcsd_sdinitialize(priv); break; - case MMCSD_CARDTYPE_MMC: /* MMC card */ + case MMCSD_CARDTYPE_MMC: /* MMC card */ #ifdef CONFIG_MMCSD_MMCSUPPORT ret = mmcsd_mmcinitialize(priv); break; #endif - case MMCSD_CARDTYPE_UNKNOWN: /* Unknown card type */ + case MMCSD_CARDTYPE_UNKNOWN: /* Unknown card type */ default: fdbg("ERROR: Internal confusion: %d\n", priv->type); ret = -EPERM; diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index 16fc31089f..64f67a797d 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -274,7 +274,7 @@ static const uint32_t g_transpeedru[8] = 10000, /* 0: 10 Kbit/sec / 10 */ 100000, /* 1: 1 Mbit/sec / 10 */ 1000000, /* 2: 10 Mbit/sec / 10 */ - 10000000, /* 3: 100 Mbit/sec / 10*/ + 10000000, /* 3: 100 Mbit/sec / 10 */ 0, 0, 0, 0 /* 4-7: Reserved values */ }; @@ -316,7 +316,7 @@ static const uint16_t g_taactu[8] = 1, /* 3: 1 us 1,000 ns */ 10, /* 4: 10 us 10,000 ns */ 100, /* 5: 100 us 100,000 ns */ - 1000, /* 6: 1 ms 1,000,000 ns*/ + 1000, /* 6: 1 ms 1,000,000 ns */ 10000, /* 7: 10 ms 10,000,000 ns */ }; @@ -677,7 +677,7 @@ static uint32_t mmcsd_taac(FAR struct mmcsd_slot_s *slot, uint8_t *csd) { int tundx; - /*The TAAC consists of a 3-bit time unit (TU) and a 4-bit time value (TV). + /* The TAAC consists of a 3-bit time unit (TU) and a 4-bit time value (TV). * TAAC is in units of time; NSAC is in units of SPI clocks. * The access time we need is then given by: * @@ -1532,7 +1532,7 @@ static int mmcsd_geometry(FAR struct inode *inode, struct geometry *geometry) /* Then return the card geometry */ geometry->geo_available = - ((slot->state & (MMCSD_SLOTSTATUS_NOTREADY|MMCSD_SLOTSTATUS_NODISK)) == 0); + ((slot->state & (MMCSD_SLOTSTATUS_NOTREADY | MMCSD_SLOTSTATUS_NODISK)) == 0); geometry->geo_mediachanged = ((slot->state & MMCSD_SLOTSTATUS_MEDIACHGD) != 0); #if defined(CONFIG_FS_WRITABLE) && !defined(CONFIG_MMCSD_READONLY) @@ -1713,7 +1713,7 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) if ((slot->ocr & MMCSD_OCR_CCS) != 0) { fdbg("Identified SD ver2 card/with block access\n"); - slot->type = MMCSD_CARDTYPE_SDV2|MMCSD_CARDTYPE_BLOCK; + slot->type = MMCSD_CARDTYPE_SDV2 | MMCSD_CARDTYPE_BLOCK; } else { @@ -1862,7 +1862,7 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) static void mmcsd_mediachanged(void *arg) { - struct mmcsd_slot_s *slot = (struct mmcsd_slot_s*)arg; + FAR struct mmcsd_slot_s *slot = (FAR struct mmcsd_slot_s *)arg; FAR struct spi_dev_s *spi; uint8_t oldstate; int ret; @@ -1892,7 +1892,7 @@ static void mmcsd_mediachanged(void *arg) /* Media is not present */ fdbg("No card present\n"); - slot->state |= (MMCSD_SLOTSTATUS_NODISK|MMCSD_SLOTSTATUS_NOTREADY); + slot->state |= (MMCSD_SLOTSTATUS_NODISK | MMCSD_SLOTSTATUS_NOTREADY); /* Was media removed? */ @@ -1906,7 +1906,7 @@ static void mmcsd_mediachanged(void *arg) * ready, then try re-initializing it */ - else if ((oldstate & (MMCSD_SLOTSTATUS_NODISK|MMCSD_SLOTSTATUS_NOTREADY)) != 0) + else if ((oldstate & (MMCSD_SLOTSTATUS_NODISK | MMCSD_SLOTSTATUS_NOTREADY)) != 0) { /* (Re-)initialize for the media in the slot */ @@ -2014,7 +2014,7 @@ int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi) * removal of cards. */ - (void)SPI_REGISTERCALLBACK(spi, mmcsd_mediachanged, (void*)slot); + (void)SPI_REGISTERCALLBACK(spi, mmcsd_mediachanged, (FAR void *)slot); return OK; } diff --git a/drivers/mtd/at45db.c b/drivers/mtd/at45db.c index 2c8689ab21..0fb7d8018d 100644 --- a/drivers/mtd/at45db.c +++ b/drivers/mtd/at45db.c @@ -251,12 +251,18 @@ static int at45db_ioctl(FAR struct mtd_dev_s *mtd, int cmd, unsigned long arg); /* Chip erase sequence */ #define CHIP_ERASE_SIZE 4 -static const uint8_t g_chiperase[CHIP_ERASE_SIZE] = {0xc7, 0x94, 0x80, 0x9a}; +static const uint8_t g_chiperase[CHIP_ERASE_SIZE] = +{ + 0xc7, 0x94, 0x80, 0x9a +}; /* Sequence to program the device to binary page sizes{256, 512, 1024} */ #define BINPGSIZE_SIZE 4 -static const uint8_t g_binpgsize[BINPGSIZE_SIZE] = {0x3d, 0x2a, 0x80, 0xa6}; +static const uint8_t g_binpgsize[BINPGSIZE_SIZE] = +{ + 0x3d, 0x2a, 0x80, 0xa6 +}; /************************************************************************************ * Private Functions @@ -270,7 +276,7 @@ static void at45db_lock(FAR struct at45db_dev_s *priv) { /* On SPI buses where there are multiple devices, it will be necessary to lock SPI * to have exclusive access to the buses for a sequence of transfers. The bus - & should be locked before the chip is selected. + * should be locked before the chip is selected. * * This is a blocking call and will not return until we have exclusive access to * the SPI bus. We will retain that exclusive access until the bus is unlocked. diff --git a/drivers/mtd/flash_eraseall.c b/drivers/mtd/flash_eraseall.c index e09f3cfacb..185da7695c 100644 --- a/drivers/mtd/flash_eraseall.c +++ b/drivers/mtd/flash_eraseall.c @@ -87,7 +87,7 @@ int flash_eraseall(FAR const char *driver) /* Open the block driver */ - ret = open_blockdriver(driver ,0, &inode); + ret = open_blockdriver(driver, 0, &inode); if (ret < 0) { fdbg("ERROR: Failed to open '%s': %d\n", driver, ret); diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c index c9162eae6f..674fd6ed56 100644 --- a/drivers/mtd/mtd_config.c +++ b/drivers/mtd/mtd_config.c @@ -115,11 +115,13 @@ struct mtdconfig_header_s static int mtdconfig_open(FAR struct file *filep); static int mtdconfig_close(FAR struct file *filep); -static ssize_t mtdconfig_read(FAR struct file *, FAR char *, size_t); -static ssize_t mtdconfig_ioctl(FAR struct file *, int, unsigned long); +static ssize_t mtdconfig_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t mtdconfig_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); #ifndef CONFIG_DISABLE_POLL static int mtdconfig_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup); + bool setup); #endif /**************************************************************************** @@ -645,8 +647,6 @@ static off_t mtdconfig_ramconsolidate(FAR struct mtdconfig_struct_s *dev) /* Now Write the item to the current dst_offset location */ - //printf("REL HDR: ID=%04X,%02X Len=%4d Off=%5d Src off=%4d\n", - // phdr->id, phdr->instance, phdr->len, dst_offset, src_offset); ret = mtdconfig_writebytes(dev, dst_offset, (uint8_t *) phdr, sizeof(hdr)); if (ret < 0) @@ -815,8 +815,6 @@ retry_relocate: /* Copy this entry to the destination */ - //printf("REL HDR: ID=%04X,%02X Len=%4d Off=%5d Src off=%4d\n", - // hdr.id, hdr.instance, hdr.len, dst_offset, src_offset); mtdconfig_writebytes(dev, dst_offset, (uint8_t *) &hdr, sizeof(hdr)); src_offset += sizeof(hdr); dst_offset += sizeof(hdr); @@ -850,7 +848,7 @@ retry_relocate: src_offset += sizeof(hdr) + hdr.len; if (src_offset + sizeof(hdr) >= (src_block + 1) * dev->erasesize || - src_offset == (src_block +1 ) * dev->erasesize) + src_offset == (src_block + 1) * dev->erasesize) { /* No room left at end of source block */ @@ -1181,8 +1179,7 @@ retry_find: hdr.instance = pdata->instance; hdr.len = pdata->len; hdr.flags = MTD_ERASED_FLAGS; - //printf("SAV HDR: ID=%04X,%02X Len=%4d Off=%5d\n", - // hdr.id, hdr.instance, hdr.len, offset); + mtdconfig_writebytes(dev, offset, (uint8_t *)&hdr, sizeof(hdr)); bytes = mtdconfig_writebytes(dev, offset + sizeof(hdr), pdata->configdata, pdata->len); @@ -1311,7 +1308,7 @@ static int mtdconfig_poll(FAR struct file *filep, FAR struct pollfd *fds, { if (setup) { - fds->revents |= (fds->events & (POLLIN|POLLOUT)); + fds->revents |= (fds->events & (POLLIN | POLLOUT)); if (fds->revents != 0) { sem_post(fds->sem); diff --git a/drivers/mtd/mtd_nand.c b/drivers/mtd/mtd_nand.c index 2261725d26..da4327b50b 100644 --- a/drivers/mtd/mtd_nand.c +++ b/drivers/mtd/mtd_nand.c @@ -250,8 +250,8 @@ static int nand_checkblock(FAR struct nand_dev_s *nand, off_t block) * ****************************************************************************/ -//#ifdef CONFIG_MTD_NAND_BLOCKCHECK -#if defined(CONFIG_MTD_NAND_BLOCKCHECK) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_FS) +#if defined(CONFIG_MTD_NAND_BLOCKCHECK) && defined(CONFIG_DEBUG_VERBOSE) && \ + defined(CONFIG_DEBUG_FS) static int nand_devscan(FAR struct nand_dev_s *nand) { FAR struct nand_raw_s *raw; @@ -329,7 +329,7 @@ static int nand_devscan(FAR struct nand_dev_s *nand) return OK; } -#endif /* CONFIG_MTD_NAND_BLOCKCHECK */ +#endif /* CONFIG_MTD_NAND_BLOCKCHECK && CONFIG_DEBUG_VERBOSE && CONFIG_DEBUG_FS */ /**************************************************************************** * Name: nand_chipid diff --git a/drivers/mtd/mtd_nandscheme.c b/drivers/mtd/mtd_nandscheme.c index 600e588836..367dcc18d6 100644 --- a/drivers/mtd/mtd_nandscheme.c +++ b/drivers/mtd/mtd_nandscheme.c @@ -327,12 +327,12 @@ void nandscheme_writeextra(FAR const struct nand_scheme_s *scheme, FAR uint8_t *spare, FAR const void *extra, unsigned int size, unsigned int offset) { - DEBUGASSERT((size + offset) < scheme->nxbytes); - - uint32_t i; - for (i = 0; i < size; i++) { + DEBUGASSERT((size + offset) < scheme->nxbytes); - spare[scheme->xbytepos[i+offset]] = ((uint8_t *) extra)[i]; + uint32_t i; + for (i = 0; i < size; i++) + { + spare[scheme->xbytepos[i+offset]] = ((uint8_t *) extra)[i]; } } diff --git a/drivers/mtd/mtd_onfi.c b/drivers/mtd/mtd_onfi.c index 62b955a81c..9a6f6c312a 100644 --- a/drivers/mtd/mtd_onfi.c +++ b/drivers/mtd/mtd_onfi.c @@ -328,39 +328,39 @@ int onfi_read(uintptr_t cmdaddr, uintptr_t addraddr, uintptr_t dataaddr, /* JEDEC manufacturer ID */ - onfi->manufacturer = *(uint8_t *)(parmtab + 64); + onfi->manufacturer = *(FAR uint8_t *)(parmtab + 64); /* Bus width */ - onfi->buswidth = (*(uint8_t *)(parmtab + 6)) & 0x01; + onfi->buswidth = (*(FAR uint8_t *)(parmtab + 6)) & 0x01; /* Get number of data bytes per page (bytes 80-83 in the param table) */ - onfi->pagesize = *(uint32_t *)(void*)(parmtab + 80); + onfi->pagesize = *(FAR uint32_t *)(FAR void *)(parmtab + 80); /* Get number of spare bytes per page (bytes 84-85 in the param table) */ - onfi->sparesize = *(uint16_t *)(void*)(parmtab + 84); + onfi->sparesize = *(FAR uint16_t *)(FAR voidFAR *)(parmtab + 84); /* Number of pages per block. */ - onfi->pagesperblock = *(uint32_t *)(void*)(parmtab + 92); + onfi->pagesperblock = *(FAR uint32_t *)(FAR void *)(parmtab + 92); /* Number of blocks per logical unit (LUN). */ - onfi->blocksperlun = *(uint32_t *)(void*)(parmtab + 96); + onfi->blocksperlun = *(FAR uint32_t *)(FAR void *)(parmtab + 96); /* Number of logical units. */ - onfi->luns = *(uint8_t *)(parmtab + 100); + onfi->luns = *(FAR uint8_t *)(parmtab + 100); /* Number of bits of ECC correction */ - onfi->eccsize = *(uint8_t *)(parmtab + 112); + onfi->eccsize = *(FAR uint8_t *)(parmtab + 112); /* Device model */ - onfi->model= *(uint8_t *)(parmtab + 49); + onfi->model = *(FAR uint8_t *)(parmtab + 49); fvdbg("Returning:\n"); fvdbg(" manufacturer: 0x%02x\n", onfi->manufacturer); @@ -483,7 +483,7 @@ bool onfi_ebidetect(uintptr_t cmdaddr, uintptr_t addraddr, ids[2] = READ_NAND(dataaddr); ids[3] = READ_NAND(dataaddr); - for (i = 0; i< NAND_NMODELS ; i++) + for (i = 0; i < NAND_NMODELS ; i++) { if (g_nandmodels[i].devid == ids[1]) { diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c index 4b7931e780..f6a148c753 100644 --- a/drivers/mtd/mtd_partition.c +++ b/drivers/mtd/mtd_partition.c @@ -739,7 +739,7 @@ static int part_procfs_stat(const char *relpath, struct stat *buf) { /* File/directory size, access block size */ - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; buf->st_size = 0; buf->st_blksize = 0; buf->st_blocks = 0; diff --git a/drivers/mtd/mtd_procfs.c b/drivers/mtd/mtd_procfs.c index 2a2137a098..2f640b1a3f 100644 --- a/drivers/mtd/mtd_procfs.c +++ b/drivers/mtd/mtd_procfs.c @@ -40,7 +40,6 @@ #include #include -//#include #include #include @@ -304,7 +303,7 @@ static int mtd_stat(const char *relpath, struct stat *buf) { /* File/directory size, access block size */ - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; buf->st_size = 0; buf->st_blksize = 0; buf->st_blocks = 0; diff --git a/drivers/mtd/mtd_rwbuffer.c b/drivers/mtd/mtd_rwbuffer.c index 4b9e39ea4f..0e05a7c92b 100644 --- a/drivers/mtd/mtd_rwbuffer.c +++ b/drivers/mtd/mtd_rwbuffer.c @@ -295,7 +295,7 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) /* Then invalidate in cached data */ - ret = rwb_invalidate(&priv->rwb,0, priv->rwb.nblocks); + ret = rwb_invalidate(&priv->rwb, 0, priv->rwb.nblocks); if (ret < 0) { fdbg("ERROR: rwb_invalidate failed: %d\n", ret); diff --git a/drivers/mtd/rammtd.c b/drivers/mtd/rammtd.c index 06497e13f8..af63097723 100644 --- a/drivers/mtd/rammtd.c +++ b/drivers/mtd/rammtd.c @@ -395,7 +395,7 @@ static int ram_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { /* Return (void*) base address of device memory */ - *ppv = (FAR void*)priv->start; + *ppv = (FAR void *)priv->start; ret = OK; } } diff --git a/drivers/mtd/sector512.c b/drivers/mtd/sector512.c index 3b61e8210a..3705efb769 100644 --- a/drivers/mtd/sector512.c +++ b/drivers/mtd/sector512.c @@ -107,7 +107,7 @@ struct s512_dev_s size_t sectperblock; /* Number of read/write sectors per erase block */ uint16_t stdperblock; /* Number of 512 byte sectors in one erase block */ uint8_t flags; /* Buffered sector flags */ - uint32_t eblockno; /* Erase sector number in the cache*/ + uint32_t eblockno; /* Erase sector number in the cache */ FAR uint8_t *eblock; /* Allocated erase block */ }; @@ -269,9 +269,9 @@ static int s512_erase(FAR struct mtd_dev_s *dev, off_t sector512, size_t nsector } /* Erase the block containing this sector if it is not already erased. - * The erased indicator will be cleared when the data from the erase sector - * is read into the cache and set here when we erase the block. - */ + * The erased indicator will be cleared when the data from the erase sector + * is read into the cache and set here when we erase the block. + */ if (!IS_ERASED(priv)) { @@ -538,7 +538,7 @@ static int s512_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) if (ret >= 0) { priv->flags = 0; /* Buffered sector flags */ - priv->eblockno = 0; /* Erase sector number in the cache*/ + priv->eblockno = 0; /* Erase sector number in the cache */ priv->eblock = NULL; /* Allocated erase block */ } } @@ -588,7 +588,7 @@ FAR struct mtd_dev_s *s512_initialize(FAR struct mtd_dev_s *mtd) /* We expect that the block size will be >512 and an even multiple of 512 */ if (ret < 0 || geo.erasesize <= SECTOR_512 || - (geo.erasesize & ~MASK_512) != geo.erasesize ) + (geo.erasesize & ~MASK_512) != geo.erasesize) { fdbg("ERROR: MTDIOC_GEOMETRY ioctl returned %d, eraseize=%d\n", ret, geo.erasesize); diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index b8ac874fc9..a565fee9c5 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -277,8 +277,8 @@ struct smart_struct_s #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS struct smart_multiroot_device_s { - FAR struct smart_struct_s* dev; - uint8_t rootdirnum; + FAR struct smart_struct_s *dev; + uint8_t rootdirnum; }; #endif @@ -440,10 +440,10 @@ static int smart_close(FAR struct inode *inode) ****************************************************************************/ #ifdef CONFIG_MTD_SMART_ALLOC_DEBUG -FAR static void* smart_malloc(FAR struct smart_struct_s *dev, +FAR static void *smart_malloc(FAR struct smart_struct_s *dev, size_t bytes, const char *name) { - void* ret = kmm_malloc(bytes); + FAR void *ret = kmm_malloc(bytes); uint8_t x; /* Keep track of the total allocation */ @@ -479,7 +479,7 @@ FAR static void* smart_malloc(FAR struct smart_struct_s *dev, ****************************************************************************/ #ifdef CONFIG_MTD_SMART_ALLOC_DEBUG -static void smart_free(FAR struct smart_struct_s *dev, FAR void* ptr) +static void smart_free(FAR struct smart_struct_s *dev, FAR void *ptr) { uint8_t x; @@ -505,7 +505,7 @@ static void smart_free(FAR struct smart_struct_s *dev, FAR void* ptr) ****************************************************************************/ #ifdef CONFIG_MTD_SMART_PACK_COUNTS -static void smart_set_count(FAR struct smart_struct_s *dev, FAR uint8_t* pCount, +static void smart_set_count(FAR struct smart_struct_s *dev, FAR uint8_t *pCount, uint16_t block, uint8_t count) { if (dev->sectorsPerBlk > 16) @@ -533,11 +533,11 @@ static void smart_set_count(FAR struct smart_struct_s *dev, FAR uint8_t* pCount, { if (count == 16) { - pCount[(dev->geo.neraseblocks >> 1) + (block>>3)] |= 1 << (block & 0x07); + pCount[(dev->geo.neraseblocks >> 1) + (block >> 3)] |= 1 << (block & 0x07); } else { - pCount[(dev->geo.neraseblocks >> 1) + (block>>3)] &= ~(1 << (block & 0x07)); + pCount[(dev->geo.neraseblocks >> 1) + (block >> 3)] &= ~(1 << (block & 0x07)); } } } @@ -554,7 +554,7 @@ static void smart_set_count(FAR struct smart_struct_s *dev, FAR uint8_t* pCount, #ifdef CONFIG_MTD_SMART_PACK_COUNTS static uint8_t smart_get_count(FAR struct smart_struct_s *dev, - FAR uint8_t* pCount, uint16_t block) + FAR uint8_t *pCount, uint16_t block) { uint8_t count; @@ -581,7 +581,7 @@ static uint8_t smart_get_count(FAR struct smart_struct_s *dev, if (dev->sectorsPerBlk == 16) { - if (pCount[(dev->geo.neraseblocks >> 1) + (block>>3)] & (1 << (block & 0x07))) + if (pCount[(dev->geo.neraseblocks >> 1) + (block >> 3)] & (1 << (block & 0x07))) { count |= 0x10; } @@ -600,7 +600,7 @@ static uint8_t smart_get_count(FAR struct smart_struct_s *dev, ****************************************************************************/ #ifdef CONFIG_MTD_SMART_PACK_COUNTS -static void smart_add_count(struct smart_struct_s *dev, uint8_t* pCount, +static void smart_add_count(struct smart_struct_s *dev, uint8_t *pCount, uint16_t block, int adder) { int16_t value; @@ -675,7 +675,7 @@ int smart_checkfree(FAR struct smart_struct_s *dev, int lineno) } /* Modifiy the freesector count to reflect the actual calculated freecount - to get us back in line. + * to get us back in line. */ dev->freesectors = freecount; @@ -761,13 +761,13 @@ static ssize_t smart_reload(struct smart_struct_s *dev, FAR uint8_t *buffer, static ssize_t smart_read(FAR struct inode *inode, unsigned char *buffer, size_t start_sector, unsigned int nsectors) { - struct smart_struct_s *dev; + FAR struct smart_struct_s *dev; fvdbg("SMART: sector: %d nsectors: %d\n", start_sector, nsectors); DEBUGASSERT(inode && inode->i_private); #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - dev = ((struct smart_multiroot_device_s*) inode->i_private)->dev; + dev = ((FAR struct smart_multiroot_device_s *)inode->i_private)->dev; #else dev = (struct smart_struct_s *)inode->i_private; #endif @@ -803,7 +803,7 @@ static ssize_t smart_write(FAR struct inode *inode, DEBUGASSERT(inode && inode->i_private); #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - dev = ((FAR struct smart_multiroot_device_s*) inode->i_private)->dev; + dev = ((FAR struct smart_multiroot_device_s *)inode->i_private)->dev; #else dev = (FAR struct smart_struct_s *)inode->i_private; #endif @@ -912,7 +912,7 @@ static int smart_geometry(FAR struct inode *inode, struct geometry *geometry) if (geometry) { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - dev = ((FAR struct smart_multiroot_device_s*) inode->i_private)->dev; + dev = ((FAR struct smart_multiroot_device_s *)inode->i_private)->dev; #else dev = (FAR struct smart_struct_s *)inode->i_private; #endif @@ -1500,7 +1500,7 @@ static uint16_t smart_cache_lookup(FAR struct smart_struct_s *dev, uint16_t logi /* This is the sector we are looking for! Add it to the cache */ physical = block * dev->sectorsPerBlk + sector; - smart_add_sector_to_cache(dev, logical, physical, __LINE__ ); + smart_add_sector_to_cache(dev, logical, physical, __LINE__); break; } } @@ -1543,7 +1543,7 @@ static void smart_update_cache(FAR struct smart_struct_s *dev, uint16_t dev->sCache[x].physical = physical; /* If we are freeing a sector, then remove the logical entry from - the cache. + * the cache. */ if (physical == 0xFFFF) @@ -1739,7 +1739,8 @@ static int smart_set_wear_level(FAR struct smart_struct_s *dev, uint16_t block, } /* Test if this was the min level. If it was, then - we need to rescan for min. */ + * we need to rescan for min. + */ if (oldlevel == dev->minwearlevel) { @@ -1973,7 +1974,7 @@ static int smart_scan(FAR struct smart_struct_s *dev) /* Read the sector data */ ret = MTD_READ(dev->mtd, readaddress, 32, - (FAR uint8_t*) dev->rwbuffer); + (FAR uint8_t *)dev->rwbuffer); if (ret != 32) { fdbg("Error reading physical sector %d.\n", sector); @@ -1986,12 +1987,13 @@ static int smart_scan(FAR struct smart_struct_s *dev) dev->rwbuffer[SMART_FMT_POS2] != SMART_FMT_SIG2 || dev->rwbuffer[SMART_FMT_POS3] != SMART_FMT_SIG3 || dev->rwbuffer[SMART_FMT_POS4] != SMART_FMT_SIG4) - { - /* Invalid signature on a sector claiming to be sector 0! - * What should we do? Release it?*/ + { + /* Invalid signature on a sector claiming to be sector 0! + * What should we do? Release it? + */ - continue; - } + continue; + } /* Mark the volume as formatted and set the sector size */ @@ -2023,8 +2025,8 @@ static int smart_scan(FAR struct smart_struct_s *dev) * the SMART device structure and the root directory number. */ - rootdirdev = (struct smart_multiroot_device_s*) smart_malloc(dev, - sizeof(*rootdirdev), "Root Dir"); + rootdirdev = (struct smart_multiroot_device_s *) + smart_malloc(dev, sizeof(*rootdirdev), "Root Dir"); if (rootdirdev == NULL) { fdbg("Memory alloc failed\n"); @@ -2210,7 +2212,7 @@ static int smart_scan(FAR struct smart_struct_s *dev) if (logicalsector < SMART_FIRST_ALLOC_SECTOR) { - smart_add_sector_to_cache(dev, logicalsector, sector, __LINE__ ); + smart_add_sector_to_cache(dev, logicalsector, sector, __LINE__); } #endif } @@ -2927,7 +2929,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a for (x = 0; x < dev->neraseblocks; x++) { /* Test for a geometry with 65536 sectors. We allow this, though - we never use the last two sectors in this mode. + * we never use the last two sectors in this mode. */ if (x == dev->neraseblocks && dev->totalsectors == 65534) @@ -3304,7 +3306,7 @@ static int smart_relocate_block(FAR struct smart_struct_s *dev, uint16_t block) if (x == dev->neraseblocks && dev->totalsectors == 65534) { /* We can't use the last two sectors on a 65536 sector device, - so "pre-release" them so they never get allocated. + * so "pre-release" them so they never get allocated. */ prerelease = 2; @@ -3531,7 +3533,7 @@ retry: #ifdef CONFIG_MTD_SMART_ENABLE_CRC /* First check if there is a temporary alloc in place */ - FAR struct smart_allocsector_s* allocsect; + FAR struct smart_allocsector_s *allocsect; allocsect = dev->allocsector; while (allocsect) @@ -3758,7 +3760,7 @@ static int smart_write_wearstatus(struct smart_struct_s *dev) } /* Test if we need to write either total block erase count or - uneven wearcount (or both) + * uneven wearcount (or both) */ if (write_buffer) @@ -4223,9 +4225,9 @@ static int smart_writesector(FAR struct smart_struct_s *dev, #endif /* CONFIG_MTD_SMART_ENABLE_CRC */ /* If we are not using CRC and on a device that supports re-writing - bits from 1 to 0 without neededing a block erase, such as NOR - FLASH, then we can simply update the data in place and don't need - to relocate the sector. Test if we need to relocate or not. + * bits from 1 to 0 without neededing a block erase, such as NOR + * FLASH, then we can simply update the data in place and don't need + * to relocate the sector. Test if we need to relocate or not. */ if (needsrelocate) @@ -4532,20 +4534,20 @@ static int smart_readsector(FAR struct smart_struct_s *dev, #ifdef CONFIG_MTD_SMART_ENABLE_CRC - /* When CRC is enabled, we read the entire sector into RAM so we can - * validate the CRC. - */ + /* When CRC is enabled, we read the entire sector into RAM so we can + * validate the CRC. + */ - ret = MTD_BREAD(dev->mtd, physsector * dev->mtdBlksPerSector, - dev->mtdBlksPerSector, (FAR uint8_t *) dev->rwbuffer); - if (ret != dev->mtdBlksPerSector) - { - /* TODO: Mark the block bad */ + ret = MTD_BREAD(dev->mtd, physsector * dev->mtdBlksPerSector, + dev->mtdBlksPerSector, (FAR uint8_t *) dev->rwbuffer); + if (ret != dev->mtdBlksPerSector) + { + /* TODO: Mark the block bad */ - fdbg("Error reading phys sector %d\n", physsector); - ret = -EIO; - goto errout; - } + fdbg("Error reading phys sector %d\n", physsector); + ret = -EIO; + goto errout; + } #if SMART_STATUS_VERSION == 1 /* Test if this sector has CRC enabled or not */ @@ -4610,7 +4612,7 @@ static int smart_readsector(FAR struct smart_struct_s *dev, /* Read the sector data into the buffer */ readaddr = (uint32_t) physsector * dev->mtdBlksPerSector * dev->geo.blocksize + - req->offset + sizeof(struct smart_sect_header_s);; + req->offset + sizeof(struct smart_sect_header_s); ret = MTD_READ(dev->mtd, readaddr, req->count, (FAR uint8_t *) req->buffer); @@ -4844,7 +4846,7 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, dev->sMap[logsector] = physicalsector; #else dev->sBitMap[logsector >> 3] |= (1 << (logsector & 0x07)); - smart_add_sector_to_cache(dev, logsector, physicalsector, __LINE__ ); + smart_add_sector_to_cache(dev, logsector, physicalsector, __LINE__); #endif #ifdef CONFIG_MTD_SMART_PACK_COUNTS @@ -4991,7 +4993,7 @@ static int smart_ioctl(FAR struct inode *inode, int cmd, unsigned long arg) DEBUGASSERT(inode && inode->i_private); #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - dev = ((FAR struct smart_multiroot_device_s*) inode->i_private)->dev; + dev = ((FAR struct smart_multiroot_device_s *)inode->i_private)->dev; #else dev = (FAR struct smart_struct_s *)inode->i_private; #endif @@ -5027,7 +5029,7 @@ static int smart_ioctl(FAR struct inode *inode, int cmd, unsigned long arg) #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS ret = smart_getformat(dev, (FAR struct smart_format_s *) arg, - ((FAR struct smart_multiroot_device_s*) inode->i_private)->rootdirnum); + ((FAR struct smart_multiroot_device_s *)inode->i_private)->rootdirnum); #else ret = smart_getformat(dev, (FAR struct smart_format_s *) arg); #endif @@ -5292,8 +5294,8 @@ int smart_initialize(int minor, FAR struct mtd_dev_s *mtd, FAR const char *partn * the SMART device structure and the root directory number. */ - rootdirdev = (FAR struct smart_multiroot_device_s*) smart_malloc(dev, - sizeof(*rootdirdev), "Root Dir"); + rootdirdev = (FAR struct smart_multiroot_device_s *) + smart_malloc(dev, sizeof(*rootdirdev), "Root Dir"); if (rootdirdev == NULL) { fdbg("register_blockdriver failed: %d\n", -ret); @@ -5352,7 +5354,7 @@ errout: #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS if (rootdirdev) { - smart_free(dev,rootdirdev); + smart_free(dev, rootdirdev); } #endif diff --git a/drivers/mtd/sst25.c b/drivers/mtd/sst25.c index c4c49c7ee7..3a3db16e19 100644 --- a/drivers/mtd/sst25.c +++ b/drivers/mtd/sst25.c @@ -139,8 +139,8 @@ #define SST25_DUMMY 0xa5 /* Chip Geometries ******************************************************************/ -/* SST25VF512 capacity is 512Kbit (64Kbit x 8) = 64Kb (8Kb x 8)*/ -/* SST25VF010 capacity is 1Mbit (128Kbit x 8) = 128Kb (16Kb x 8*/ +/* SST25VF512 capacity is 512Kbit (64Kbit x 8) = 64Kb (8Kb x 8) */ +/* SST25VF010 capacity is 1Mbit (128Kbit x 8) = 128Kb (16Kb x 8 */ /* SST25VF520 capacity is 2Mbit (256Kbit x 8) = 256Kb (32Kb x 8) */ /* SST25VF540 capacity is 4Mbit (512Kbit x 8) = 512Kb (64Kb x 8) */ /* SST25VF080 capacity is 8Mbit (1024Kbit x 8) = 1Mb (128Kb x 8) */ @@ -199,7 +199,7 @@ struct sst25_dev_s #if defined(CONFIG_SST25_SECTOR512) && !defined(CONFIG_SST25_READONLY) uint8_t flags; /* Buffered sector flags */ - uint16_t esectno; /* Erase sector number in the cache*/ + uint16_t esectno; /* Erase sector number in the cache */ FAR uint8_t *sector; /* Allocated sector data */ #endif }; @@ -583,7 +583,7 @@ static void sst25_byteread(FAR struct sst25_dev_s *priv, FAR uint8_t *buffer, /* Wait for any preceding write or erase operation to complete. */ status = sst25_waitwritecomplete(priv); - DEBUGASSERT((status & (SST25_SR_WEL|SST25_SR_BP_MASK|SST25_SR_AAI)) == 0); + DEBUGASSERT((status & (SST25_SR_WEL | SST25_SR_BP_MASK | SST25_SR_AAI)) == 0); UNUSED(status); /* Select this FLASH part */ @@ -643,7 +643,7 @@ static void sst25_bytewrite(struct sst25_dev_s *priv, FAR const uint8_t *buffer, /* Wait for any preceding write or erase operation to complete. */ status = sst25_waitwritecomplete(priv); - DEBUGASSERT((status & (SST25_SR_WEL|SST25_SR_BP_MASK|SST25_SR_AAI)) == 0); + DEBUGASSERT((status & (SST25_SR_WEL | SST25_SR_BP_MASK | SST25_SR_AAI)) == 0); /* Enable write access to the FLASH */ @@ -723,7 +723,7 @@ static void sst25_wordwrite(struct sst25_dev_s *priv, FAR const uint8_t *buffer, /* Wait for any preceding write or erase operation to complete. */ status = sst25_waitwritecomplete(priv); - DEBUGASSERT((status & (SST25_SR_WEL|SST25_SR_BP_MASK|SST25_SR_AAI)) == 0); + DEBUGASSERT((status & (SST25_SR_WEL | SST25_SR_BP_MASK | SST25_SR_AAI)) == 0); UNUSED(status); /* Enable write access to the FLASH */ @@ -755,7 +755,8 @@ static void sst25_wordwrite(struct sst25_dev_s *priv, FAR const uint8_t *buffer, /* Wait for the preceding write to complete. */ status = sst25_waitwritecomplete(priv); - DEBUGASSERT((status & (SST25_SR_WEL|SST25_SR_BP_MASK|SST25_SR_AAI)) == (SST25_SR_WEL|SST25_SR_AAI)); + DEBUGASSERT((status & (SST25_SR_WEL | SST25_SR_BP_MASK | SST25_SR_AAI)) == + (SST25_SR_WEL | SST25_SR_AAI)); UNUSED(status); /* Decrement the word count and advance the write position */ @@ -793,7 +794,8 @@ static void sst25_wordwrite(struct sst25_dev_s *priv, FAR const uint8_t *buffer, /* Wait for the preceding write to complete. */ status = sst25_waitwritecomplete(priv); - DEBUGASSERT((status & (SST25_SR_WEL|SST25_SR_BP_MASK|SST25_SR_AAI)) == (SST25_SR_WEL|SST25_SR_AAI)); + DEBUGASSERT((status & (SST25_SR_WEL | SST25_SR_BP_MASK | SST25_SR_AAI)) == + (SST25_SR_WEL | SST25_SR_AAI)); UNUSED(status); /* Decrement the word count and advance the write position */ diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 2eaf4221d1..07228c4e29 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -322,7 +322,7 @@ struct st25fl1_dev_s #ifdef CONFIG_ST25FL1_SECTOR512 uint8_t flags; /* Buffered sector flags */ - uint16_t esectno; /* Erase sector number in the cache*/ + uint16_t esectno; /* Erase sector number in the cache */ FAR uint8_t *sector; /* Allocated sector data */ #endif }; diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index f84643d037..cb9c2980fa 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -657,7 +657,7 @@ static void w25_byteread(FAR struct w25_dev_s *priv, FAR uint8_t *buffer, /* Wait for any preceding write or erase operation to complete. */ status = w25_waitwritecomplete(priv); - DEBUGASSERT((status & (W25_SR_WEL|W25_SR_BP_MASK)) == 0); + DEBUGASSERT((status & (W25_SR_WEL | W25_SR_BP_MASK)) == 0); /* Make sure that writing is disabled */ @@ -715,7 +715,7 @@ static void w25_pagewrite(struct w25_dev_s *priv, FAR const uint8_t *buffer, /* Wait for any preceding write or erase operation to complete. */ status = w25_waitwritecomplete(priv); - DEBUGASSERT((status & (W25_SR_WEL|W25_SR_BP_MASK)) == 0); + DEBUGASSERT((status & (W25_SR_WEL | W25_SR_BP_MASK)) == 0); /* Enable write access to the FLASH */ diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index 1b27882912..8a9f181436 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -219,9 +219,9 @@ static uint16_t cs89x0_getppreg(struct cs89x0_driver_s *cs89x0, int addr) #endif } - /* When configured in I/O mode, the CS89x0 is accessed through eight, 16-bit - * I/O ports that in the host system's I/O space. - */ + /* When configured in I/O mode, the CS89x0 is accessed through eight, 16-bit + * I/O ports that in the host system's I/O space. + */ else #endif @@ -253,9 +253,9 @@ static void cs89x0_putppreg(struct cs89x0_driver_s *cs89x0, int addr, uint16_t v #endif } - /* When configured in I/O mode, the CS89x0 is accessed through eight, 16-bit - * I/O ports that in the host system's I/O space. - */ + /* When configured in I/O mode, the CS89x0 is accessed through eight, 16-bit + * I/O ports that in the host system's I/O space. + */ else #endif @@ -397,9 +397,9 @@ static int cs89x0_txpoll(struct net_driver_s *dev) * ****************************************************************************/ -static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) +static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) { - uint16_t *dest; + FAR uint16_t *dest; uint16_t rxlength; int nbytes; @@ -422,7 +422,7 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) if (isq & RX_CRC_ERROR) != 0) { - if (!(isq & (RX_EXTRA_DATA|RX_RUNT))) + if (!(isq & (RX_EXTRA_DATA | RX_RUNT))) { cd89x0->cs_stats.rx_crcerrors++; } @@ -451,7 +451,7 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) * amount of data in cs89x0->cs_dev.d_len */ - dest = (uint16_t*)cs89x0->cs_dev.d_buf; + dest = (FAR uint16_t *)cs89x0->cs_dev.d_buf; for (nbytes = 0; nbytes < rxlength; nbytes += sizeof(uint16_t)) { *dest++ = cs89x0_getreg(PPR_RXFRAMELOCATION); @@ -549,16 +549,16 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { - arp_arpin(&cs89x0->cs_dev); + arp_arpin(&cs89x0->cs_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ - if (cs89x0->cs_dev.d_len > 0) - { - cs89x0_transmit(cs89x0); - } + if (cs89x0->cs_dev.d_len > 0) + { + cs89x0_transmit(cs89x0); + } } else #endif @@ -720,13 +720,13 @@ static int cs89x0_interrupt(int irq, FAR void *context) case ISQ_RXMISSEVENT: #ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.rx_missederrors += (isq >>6); + cd89x0->cs_stats.rx_missederrors += (isq >> 6); #endif break; case ISQ_TXCOLEVENT: #ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.collisions += (isq >>6); + cd89x0->cs_stats.collisions += (isq >> 6); #endif break; } @@ -823,7 +823,7 @@ static int cs89x0_ifup(struct net_driver_s *dev) ndbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Initialize the Ethernet interface */ #warning "Missing logic" @@ -1033,20 +1033,20 @@ int cs89x0_initialize(FAR const cs89x0_driver_s *cs89x0, int devno) /* Initialize the driver structure */ - g_cs89x[devno] = cs89x0; /* Used to map IRQ back to instance */ - cs89x0->cs_dev.d_ifup = cs89x0_ifup; /* I/F down callback */ - cs89x0->cs_dev.d_ifdown = cs89x0_ifdown; /* I/F up (new IP address) callback */ - cs89x0->cs_dev.d_txavail = cs89x0_txavail; /* New TX data callback */ + g_cs89x[devno] = cs89x0; /* Used to map IRQ back to instance */ + cs89x0->cs_dev.d_ifup = cs89x0_ifup; /* I/F down callback */ + cs89x0->cs_dev.d_ifdown = cs89x0_ifdown; /* I/F up (new IP address) callback */ + cs89x0->cs_dev.d_txavail = cs89x0_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - cs89x0->cs_dev.d_addmac = cs89x0_addmac; /* Add multicast MAC address */ - cs89x0->cs_dev.d_rmmac = cs89x0_rmmac; /* Remove multicast MAC address */ + cs89x0->cs_dev.d_addmac = cs89x0_addmac; /* Add multicast MAC address */ + cs89x0->cs_dev.d_rmmac = cs89x0_rmmac; /* Remove multicast MAC address */ #endif - cs89x0->cs_dev.d_private = (void*)cs89x0; /* Used to recover private state from dev */ + cs89x0->cs_dev.d_private = (FAR void *)cs89x0; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - cs89x0->cs_txpoll = wd_create(); /* Create periodic poll timer */ - cs89x0->cs_txtimeout = wd_create(); /* Create TX timeout timer */ + cs89x0->cs_txpoll = wd_create(); /* Create periodic poll timer */ + cs89x0->cs_txtimeout = wd_create(); /* Create TX timeout timer */ /* Read the MAC address from the hardware into cs89x0->cs_dev.d_mac.ether_addr_octet */ diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index ae2884ed98..0f22470bae 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -194,8 +194,8 @@ #define DM9X_ISR_IOMODE16 (0 << 6) /* IO mode = 16 bit */ #define DM9X_ISR_IOMODE32 (1 << 6) /* IO mode = 32 bit */ -#define DM9X_IMRENABLE (DM9X_INT_PR|DM9X_INT_PT|DM9X_INT_LNKCHG|DM9X_IMR_PAR) -#define DM9X_IMRRXDISABLE (DM9X_INT_PT|DM9X_INT_LNKCHG|DM9X_IMR_PAR) +#define DM9X_IMRENABLE (DM9X_INT_PR | DM9X_INT_PT | DM9X_INT_LNKCHG | DM9X_IMR_PAR) +#define DM9X_IMRRXDISABLE (DM9X_INT_PT | DM9X_INT_LNKCHG | DM9X_IMR_PAR) #define DM9X_IMRDISABLE (DM9X_IMR_PAR) /* EEPROM/PHY control regiser bits */ @@ -224,7 +224,7 @@ #define DM9X_RXC_WTDIS (1 << 6) /* Disable watchdog timer */ #define DM9X_RXC_HASHALL (1 << 7) /* Filter all addresses in hash table */ -#define DM9X_RXCSETUP (DM9X_RXC_DISCRC|DM9X_RXC_DISLONG) +#define DM9X_RXCSETUP (DM9X_RXC_DISCRC | DM9X_RXC_DISLONG) /* EEPHY bit settings */ @@ -458,7 +458,7 @@ static void putreg(int reg, uint8_t value) * ****************************************************************************/ -static void read8(uint8_t *ptr, int len) +static void read8(FAR uint8_t *ptr, int len) { nvdbg("Read %d bytes (8-bit mode)\n", len); for (; len > 0; len--) @@ -467,9 +467,10 @@ static void read8(uint8_t *ptr, int len) } } -static void read16(uint8_t *ptr, int len) +static void read16(FAR uint8_t *ptr, int len) { - register uint16_t *ptr16 = (uint16_t*)ptr; + FAR uint16_t *ptr16 = (FAR uint16_t *)ptr; + nvdbg("Read %d bytes (16-bit mode)\n", len); for (; len > 0; len -= sizeof(uint16_t)) { @@ -477,9 +478,10 @@ static void read16(uint8_t *ptr, int len) } } -static void read32(uint8_t *ptr, int len) +static void read32(FARuint8_t *ptr, int len) { - register uint32_t *ptr32 = (uint32_t*)ptr; + FAR uint32_t *ptr32 = (FAR uint32_t *)ptr; + nvdbg("Read %d bytes (32-bit mode)\n", len); for (; len > 0; len -= sizeof(uint32_t)) { @@ -548,9 +550,10 @@ static void discard32(int len) * ****************************************************************************/ -static void write8(const uint8_t *ptr, int len) +static void write8(FAR const uint8_t *ptr, int len) { nvdbg("Write %d bytes (8-bit mode)\n", len); + for (; len > 0; len--) { DM9X_DATA = (*ptr++ & 0xff); @@ -559,7 +562,8 @@ static void write8(const uint8_t *ptr, int len) static void write16(const uint8_t *ptr, int len) { - register uint16_t *ptr16 = (uint16_t*)ptr; + FAR uint16_t *ptr16 = (FAR uint16_t *)ptr; + nvdbg("Write %d bytes (16-bit mode)\n", len); for (; len > 0; len -= sizeof(uint16_t)) @@ -568,10 +572,12 @@ static void write16(const uint8_t *ptr, int len) } } -static void write32(const uint8_t *ptr, int len) +static void write32(FAR const uint8_t *ptr, int len) { - register uint32_t *ptr32 = (uint32_t*)ptr; + FAR uint32_t *ptr32 = (FAR uint32_t *)ptr; + nvdbg("Write %d bytes (32-bit mode)\n", len); + for (; len > 0; len -= sizeof(uint32_t)) { DM9X_DATA = *ptr32++; @@ -602,7 +608,7 @@ static uint16_t dm9x_readsrom(struct dm9x_driver_s *dm9x, int offset) putreg(DM9X_EEPHYC, DM9X_EEPHYC_ERPRR); up_udelay(200); putreg(DM9X_EEPHYC, 0x00); - return (getreg(DM9X_EEPHYDL) + (getreg(DM9X_EEPHYDH) << 8) ); + return (getreg(DM9X_EEPHYDL) + (getreg(DM9X_EEPHYDH) << 8)); } #endif @@ -632,7 +638,7 @@ static uint16_t dm9x_phyread(struct dm9x_driver_s *dm9x, int reg) /* Issue PHY read command pulse in the EEPROM/PHY control register */ - putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRR|DM9X_EEPHYC_EPOS)); + putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRR | DM9X_EEPHYC_EPOS)); up_udelay(100); putreg(DM9X_EEPHYC, 0x00); @@ -654,7 +660,7 @@ static void dm9x_phywrite(struct dm9x_driver_s *dm9x, int reg, uint16_t value) /* Issue PHY write command pulse in the EEPROM/PHY control register */ - putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRW|DM9X_EEPHYC_EPOS)); + putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRW | DM9X_EEPHYC_EPOS)); up_udelay(500); putreg(DM9X_EEPHYC, 0x0); } @@ -803,7 +809,7 @@ static int dm9x_transmit(struct dm9x_driver_s *dm9x) #if !defined(CONFIG_DM9X_ETRANS) /* Issue TX polling command */ - putreg(DM9X_TXC, 0x1); /* Cleared after TX complete*/ + putreg(DM9X_TXC, 0x1); /* Cleared after TX complete */ #endif /* Clear count of back-to-back RX packet transfers */ @@ -914,7 +920,7 @@ static int dm9x_txpoll(struct net_driver_s *dev) * ****************************************************************************/ -static void dm9x_receive(struct dm9x_driver_s *dm9x) +static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) { union rx_desc_u rx; bool bchecksumready; @@ -946,7 +952,7 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) /* Read packet status & length */ - dm9x->dm_read((uint8_t*)&rx, 4); + dm9x->dm_read((FAR uint8_t *)&rx, 4); /* Check if any errors were reported by the hardware */ @@ -1025,9 +1031,9 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) arp_ipin(&dm9x->dm_dev); ipv4_input(&dm9x->dm_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ if (dm9x->dm_dev.d_len > 0) { @@ -1062,9 +1068,9 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) ipv6_input(&dm9x->dm_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ if (dm9x->dm_dev.d_len > 0) { @@ -1095,9 +1101,9 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) { arp_arpin(&dm9x->dm_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ if (dm9x->dm_dev.d_len > 0) { @@ -1230,8 +1236,8 @@ static int dm9x_interrupt(int irq, FAR void *context) for (i = 0; i < 500; i++) { - dm9x_phyread(dm9x,0x1); - if (dm9x_phyread(dm9x,0x1) & 0x4) /*Link OK*/ + dm9x_phyread(dm9x, 0x1); + if (dm9x_phyread(dm9x, 0x1) & 0x4) /* Link OK */ { /* Wait to get detected speed */ @@ -1413,7 +1419,7 @@ static inline void dm9x_phymode(struct dm9x_driver_s *dm9x) #ifdef CONFIG_DM9X_MODE_AUTO phyreg0 = 0x1200; /* Auto-negotiation & Restart Auto-negotiation */ - phyreg4 = 0x01e1; /* Default flow control disable*/ + phyreg4 = 0x01e1; /* Default flow control disable */ #elif defined(CONFIG_DM9X_MODE_10MHD) phyreg4 = 0x21; phyreg0 = 0x1000; @@ -1459,7 +1465,7 @@ static int dm9x_ifup(struct net_driver_s *dev) ndbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Initilize DM90x0 chip */ @@ -1688,9 +1694,9 @@ static void dm9x_bringup(struct dm9x_driver_s *dm9x) * in 10us; 20us guarantees completion of the reset */ - putreg(DM9X_NETC, (DM9X_NETC_RST|DM9X_NETC_LBK1)); + putreg(DM9X_NETC, (DM9X_NETC_RST | DM9X_NETC_LBK1)); up_udelay(20); - putreg(DM9X_NETC, (DM9X_NETC_RST|DM9X_NETC_LBK1)); + putreg(DM9X_NETC, (DM9X_NETC_RST | DM9X_NETC_LBK1)); up_udelay(20); /* Configure I/O mode */ @@ -1729,7 +1735,7 @@ static void dm9x_bringup(struct dm9x_driver_s *dm9x) putreg(DM9X_TXC, 0x00); /* Clear TX Polling */ putreg(DM9X_BPTHRES, 0x3f); /* Less 3kb, 600us */ putreg(DM9X_SMODEC, 0x00); /* Special mode */ - putreg(DM9X_NETS, (DM9X_NETS_WAKEST|DM9X_NETS_TX1END|DM9X_NETS_TX2END)); /* Clear TX status */ + putreg(DM9X_NETS, (DM9X_NETS_WAKEST | DM9X_NETS_TX1END | DM9X_NETS_TX2END)); /* Clear TX status */ putreg(DM9X_ISR, DM9X_INT_ALL); /* Clear interrupt status */ #if defined(CONFIG_DM9X_CHECKSUM) @@ -1794,7 +1800,7 @@ static void dm9x_reset(struct dm9x_driver_s *dm9x) dm9x->dm_b100M = false; for (i = 0; i < 1000; i++) { - if (dm9x_phyread(dm9x,0x1) & 0x4) + if (dm9x_phyread(dm9x, 0x1) & 0x4) { if (dm9x_phyread(dm9x, 0) &0x2000) { @@ -1874,12 +1880,12 @@ int dm9x_initialize(void) g_dm9x[0].dm_dev.d_addmac = dm9x_addmac; /* Add multicast MAC address */ g_dm9x[0].dm_dev.d_rmmac = dm9x_rmmac; /* Remove multicast MAC address */ #endif - g_dm9x[0].dm_dev.d_private = (void*)g_dm9x; /* Used to recover private state from dev */ + g_dm9x[0].dm_dev.d_private = (FAR void *)g_dm9x; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - g_dm9x[0].dm_txpoll = wd_create(); /* Create periodic poll timer */ - g_dm9x[0].dm_txtimeout = wd_create(); /* Create TX timeout timer */ + g_dm9x[0].dm_txpoll = wd_create(); /* Create periodic poll timer */ + g_dm9x[0].dm_txtimeout = wd_create(); /* Create TX timeout timer */ /* Read the MAC address */ diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 38b0f15ee2..e707ff63cf 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -142,7 +142,10 @@ struct e1000_dev_head * Private Data ****************************************************************************/ -static struct e1000_dev_head e1000_list = {0}; +static struct e1000_dev_head e1000_list = +{ + 0 +}; /**************************************************************************** * Private Function Prototypes @@ -195,24 +198,24 @@ void e1000_reset(struct e1000_dev *dev) /* Reset the network controller hardware */ dev_control = 0; - dev_control |= (1<<0); /* FD-bit (Full Duplex) */ - dev_control |= (0<<2); /* GIOMD-bit (GIO Master Disable) */ - dev_control |= (1<<3); /* LRST-bit (Link Reset) */ - dev_control |= (1<<6); /* SLU-bit (Set Link Up) */ - dev_control |= (2<<8); /* SPEED=2 (1000Mbps) */ - dev_control |= (0<<11); /* FRCSPD-bit (Force Speed) */ - dev_control |= (0<<12); /* FRCDPLX-bit (Force Duplex) */ - dev_control |= (0<<20); /* ADVD3WUC-bit (Advertise D3 Wake Up Cap) */ - dev_control |= (1<<26); /* RST-bit (Device Reset) */ - dev_control |= (1<<27); /* RFCE-bit (Receive Flow Control Enable) */ - dev_control |= (1<<28); /* TFCE-bit (Transmit Flow Control Enable) */ - dev_control |= (0<<30); /* VME-bit (VLAN Mode Enable) */ - dev_control |= (0<<31); /* PHY_RST-bit (PHY Reset) */ + dev_control |= (1 << 0); /* FD-bit (Full Duplex) */ + dev_control |= (0 << 2); /* GIOMD-bit (GIO Master Disable) */ + dev_control |= (1 << 3); /* LRST-bit (Link Reset) */ + dev_control |= (1 << 6); /* SLU-bit (Set Link Up) */ + dev_control |= (2 << 8); /* SPEED=2 (1000Mbps) */ + dev_control |= (0 << 11); /* FRCSPD-bit (Force Speed) */ + dev_control |= (0 << 12); /* FRCDPLX-bit (Force Duplex) */ + dev_control |= (0 << 20); /* ADVD3WUC-bit (Advertise D3 Wake Up Cap) */ + dev_control |= (1 << 26); /* RST-bit (Device Reset) */ + dev_control |= (1 << 27); /* RFCE-bit (Receive Flow Control Enable) */ + dev_control |= (1 << 28); /* TFCE-bit (Transmit Flow Control Enable) */ + dev_control |= (0 << 30); /* VME-bit (VLAN Mode Enable) */ + dev_control |= (0 << 31); /* PHY_RST-bit (PHY Reset) */ e1000_outl(dev, E1000_IMC, 0xFFFFFFFF); e1000_outl(dev, E1000_STATUS, 0x00000000); e1000_outl(dev, E1000_CTRL, dev_control); - dev_control &= ~(1<<26); /* clear RST-bit (Device Reset) */ + dev_control &= ~(1 << 26); /* clear RST-bit (Device Reset) */ e1000_outl(dev, E1000_CTRL, dev_control); up_mdelay(10); e1000_outl(dev, E1000_CTRL_EXT, 0x001401C0); @@ -228,13 +231,13 @@ void e1000_turn_on(struct e1000_dev *dev) /* turn on the controller's receive engine */ rx_control = e1000_inl(dev, E1000_RCTL); - rx_control |= (1<<1); + rx_control |= (1 << 1); e1000_outl(dev, E1000_RCTL, rx_control); /* turn on the controller's transmit engine */ tx_control = e1000_inl(dev, E1000_TCTL); - tx_control |= (1<<1); + tx_control |= (1 << 1); e1000_outl(dev, E1000_TCTL, tx_control); /* enable the controller's interrupts */ @@ -242,11 +245,11 @@ void e1000_turn_on(struct e1000_dev *dev) e1000_outl(dev, E1000_ICR, 0xFFFFFFFF); e1000_outl(dev, E1000_IMC, 0xFFFFFFFF); - ims |= 1<<0; /* TXDW */ - ims |= 1<<1; /* TXQE */ - ims |= 1<<2; /* LSC */ - ims |= 1<<4; /* RXDMT0 */ - ims |= 1<<7; /* RXT0 */ + ims |= 1 << 0; /* TXDW */ + ims |= 1 << 1; /* TXQE */ + ims |= 1 << 2; /* LSC */ + ims |= 1 << 4; /* RXDMT0 */ + ims |= 1 << 7; /* RXT0 */ e1000_outl(dev, E1000_IMS, ims); } @@ -258,13 +261,13 @@ void e1000_turn_off(struct e1000_dev *dev) /* turn off the controller's receive engine */ rx_control = e1000_inl(dev, E1000_RCTL); - rx_control &= ~(1<<1); + rx_control &= ~(1 << 1); e1000_outl(dev, E1000_RCTL, rx_control); /* turn off the controller's transmit engine */ tx_control = e1000_inl(dev, E1000_TCTL); - tx_control &= ~(1<<1); + tx_control &= ~(1 << 1); e1000_outl(dev, E1000_TCTL, tx_control); /* turn off the controller's interrupts */ @@ -287,39 +290,39 @@ void e1000_init(struct e1000_dev *dev) /* configure the controller's 'receive' engine */ rx_control = 0; - rx_control |= (0<<1); /* EN-bit (Enable) */ - rx_control |= (0<<2); /* SPB-bit (Store Bad Packets) */ - rx_control |= (0<<3); /* UPE-bit (Unicast Promiscuous Mode) */ - rx_control |= (1<<4); /* MPE-bit (Multicast Promiscuous Mode) */ - rx_control |= (0<<5); /* LPE-bit (Long Packet Enable) */ - rx_control |= (0<<6); /* LBM=0 (Loop-Back Mode) */ - rx_control |= (0<<8); /* RDMTS=0 (Rx Descriptor Min Threshold Size) */ - rx_control |= (0<<10); /* DTYPE=0 (Descriptor Type) */ - rx_control |= (0<<12); /* MO=0 (Multicast Offset) */ - rx_control |= (1<<15); /* BAM-bit (Broadcast Address Mode) */ - rx_control |= (0<<16); /* BSIZE=0 (Buffer Size = 2048) */ - rx_control |= (0<<18); /* VLE-bit (VLAN filter Enable) */ - rx_control |= (0<<19); /* CFIEN-bit (Canonical Form Indicator Enable) */ - rx_control |= (0<<20); /* CFI-bit (Canonical Form Indicator) */ - rx_control |= (1<<22); /* DPF-bit (Discard Pause Frames) */ - rx_control |= (0<<23); /* PMCF-bit (Pass MAC Control Frames) */ - rx_control |= (0<<25); /* BSEX=0 (Buffer Size EXtension) */ - rx_control |= (1<<26); /* SECRC-bit (Strip Ethernet CRC) */ - rx_control |= (0<<27); /* FLEXBUF=0 (Flexible Buffer size) */ + rx_control |= (0 << 1); /* EN-bit (Enable) */ + rx_control |= (0 << 2); /* SPB-bit (Store Bad Packets) */ + rx_control |= (0 << 3); /* UPE-bit (Unicast Promiscuous Mode) */ + rx_control |= (1 << 4); /* MPE-bit (Multicast Promiscuous Mode) */ + rx_control |= (0 << 5); /* LPE-bit (Long Packet Enable) */ + rx_control |= (0 << 6); /* LBM=0 (Loop-Back Mode) */ + rx_control |= (0 << 8); /* RDMTS=0 (Rx Descriptor Min Threshold Size) */ + rx_control |= (0 << 10); /* DTYPE=0 (Descriptor Type) */ + rx_control |= (0 << 12); /* MO=0 (Multicast Offset) */ + rx_control |= (1 << 15); /* BAM-bit (Broadcast Address Mode) */ + rx_control |= (0 << 16); /* BSIZE=0 (Buffer Size = 2048) */ + rx_control |= (0 << 18); /* VLE-bit (VLAN filter Enable) */ + rx_control |= (0 << 19); /* CFIEN-bit (Canonical Form Indicator Enable) */ + rx_control |= (0 << 20); /* CFI-bit (Canonical Form Indicator) */ + rx_control |= (1 << 22); /* DPF-bit (Discard Pause Frames) */ + rx_control |= (0 << 23); /* PMCF-bit (Pass MAC Control Frames) */ + rx_control |= (0 << 25); /* BSEX=0 (Buffer Size EXtension) */ + rx_control |= (1 << 26); /* SECRC-bit (Strip Ethernet CRC) */ + rx_control |= (0 << 27); /* FLEXBUF=0 (Flexible Buffer size) */ e1000_outl(dev, E1000_RCTL, rx_control); /* configure the controller's 'transmit' engine */ tx_control = 0; - tx_control |= (0<<1); /* EN-bit (Enable) */ - tx_control |= (1<<3); /* PSP-bit (Pad Short Packets) */ - tx_control |= (15<<4); /* CT=15 (Collision Threshold) */ - tx_control |= (63<<12); /* COLD=63 (Collision Distance) */ - tx_control |= (0<<22); /* SWXOFF-bit (Software XOFF) */ - tx_control |= (1<<24); /* RTLC-bit (Re-Transmit on Late Collision) */ - tx_control |= (0<<25); /* UNORTX-bit (Underrun No Re-Transmit) */ - tx_control |= (0<<26); /* TXCSCMT=0 (TxDesc Mininum Threshold) */ - tx_control |= (0<<28); /* MULR-bit (Multiple Request Support) */ + tx_control |= (0 << 1); /* EN-bit (Enable) */ + tx_control |= (1 << 3); /* PSP-bit (Pad Short Packets) */ + tx_control |= (15 << 4); /* CT=15 (Collision Threshold) */ + tx_control |= (63 << 12); /* COLD=63 (Collision Distance) */ + tx_control |= (0 << 22); /* SWXOFF-bit (Software XOFF) */ + tx_control |= (1 << 24); /* RTLC-bit (Re-Transmit on Late Collision) */ + tx_control |= (0 << 25); /* UNORTX-bit (Underrun No Re-Transmit) */ + tx_control |= (0 << 26); /* TXCSCMT=0 (TxDesc Mininum Threshold) */ + tx_control |= (0 << 28); /* MULR-bit (Multiple Request Support) */ e1000_outl(dev, E1000_TCTL, tx_control); /* hardware flow control */ @@ -328,27 +331,27 @@ void e1000_init(struct e1000_dev *dev) /* get receive FIFO size */ - pba = (pba & 0x000000ff)<<10; + pba = (pba & 0x000000ff) << 10; e1000_outl(dev, E1000_FCAL, 0x00C28001); e1000_outl(dev, E1000_FCAH, 0x00000100); e1000_outl(dev, E1000_FCT, 0x00008808); e1000_outl(dev, E1000_FCTTV, 0x00000680); - e1000_outl(dev, E1000_FCRTL, (pba*8/10)|0x80000000); - e1000_outl(dev, E1000_FCRTH, pba*9/10); + e1000_outl(dev, E1000_FCRTL, (pba * 8 / 10) | 0x80000000); + e1000_outl(dev, E1000_FCRTH, pba * 9 / 10); /* setup tx rings */ txd_phys = PADDR((uintptr_t)dev->tx_ring.desc); kmem_phys = PADDR((uintptr_t)dev->tx_ring.buf); - for (i=0; itx_ring.desc[i].base_address = kmem_phys; + dev->tx_ring.desc[i].base_address = kmem_phys; dev->tx_ring.desc[i].packet_length = 0; - dev->tx_ring.desc[i].cksum_offset = 0; - dev->tx_ring.desc[i].cksum_origin = 0; - dev->tx_ring.desc[i].desc_status = 1; - dev->tx_ring.desc[i].desc_command = (1<<0)|(1<<1)|(1<<3); - dev->tx_ring.desc[i].special_info = 0; + dev->tx_ring.desc[i].cksum_offset = 0; + dev->tx_ring.desc[i].cksum_origin = 0; + dev->tx_ring.desc[i].desc_status = 1; + dev->tx_ring.desc[i].desc_command = (1 << 0) | (1 << 1) | (1 << 3); + dev->tx_ring.desc[i].special_info = 0; } dev->tx_ring.tail = 0; @@ -359,14 +362,14 @@ void e1000_init(struct e1000_dev *dev) e1000_outl(dev, E1000_TDBAL, txd_phys); e1000_outl(dev, E1000_TDBAH, 0x00000000); - e1000_outl(dev, E1000_TDLEN, CONFIG_E1000_N_TX_DESC*16); + e1000_outl(dev, E1000_TDLEN, CONFIG_E1000_N_TX_DESC * 16); e1000_outl(dev, E1000_TXDCTL, 0x01010000); /* setup rx rings */ rxd_phys = PADDR((uintptr_t)dev->rx_ring.desc); kmem_phys = PADDR((uintptr_t)dev->rx_ring.buf); - for (i=0; irx_ring.desc[i].base_address = kmem_phys; dev->rx_ring.desc[i].packet_length = 0; @@ -440,7 +443,7 @@ static int e1000_transmit(struct e1000_dev *e1000) /* prepare the transmit-descriptor */ - e1000->tx_ring.desc[tail].packet_length = count<60 ? 60:count; + e1000->tx_ring.desc[tail].packet_length = count < 60 ? 60 : count; e1000->tx_ring.desc[tail].desc_status = 0; /* give ownership of this descriptor to the network controller */ @@ -803,7 +806,7 @@ static int e1000_ifup(struct net_driver_s *dev) ndbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ @@ -993,7 +996,7 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) /* Link status change */ - if (intr_cause & (1<<2)) + if (intr_cause & (1 << 2)) { if (e1000_inl(e1000, E1000_STATUS) & 2) { @@ -1009,14 +1012,14 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) /* Rx-descriptor Timer expired */ - if (intr_cause & (1<<7)) + if (intr_cause & (1 << 7)) { e1000_receive(e1000); } /* Tx queue empty */ - if (intr_cause & (1<<1)) + if (intr_cause & (1 << 1)) { wd_cancel(e1000->txtimeout); } @@ -1028,7 +1031,7 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) /* Tx-descriptor Written back */ - if (intr_cause & (1<<0)) + if (intr_cause & (1 << 0)) { devif_poll(&e1000->netdev, e1000_txpoll); } @@ -1036,7 +1039,7 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) /* Rx-Descriptors Low */ - if (intr_cause & (1<<4)) + if (intr_cause & (1 << 4)) { int tail; @@ -1054,12 +1057,42 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) static pci_id_t e1000_id_table[] = { - {.sep = {INTEL_VENDERID, E1000_82573L}}, - {.sep = {INTEL_VENDERID, E1000_82540EM}}, - {.sep = {INTEL_VENDERID, E1000_82574L}}, - {.sep = {INTEL_VENDERID, E1000_82567LM}}, - {.sep = {INTEL_VENDERID, E1000_82541PI}}, - {.sep = {0,0}} + { + .sep = + { + INTEL_VENDERID, E1000_82573L + } + }, + { + .sep = + { + INTEL_VENDERID, E1000_82540EM + } + }, + { + .sep = + { + INTEL_VENDERID, E1000_82574L + } + }, + { + .sep = + { + INTEL_VENDERID, E1000_82567LM + } + }, + { + .sep = + { + INTEL_VENDERID, E1000_82541PI + } + }, + { + .sep = + { + 0, 0 + } + } }; static int e1000_probe(uint16_t addr, pci_id_t id) @@ -1149,14 +1182,14 @@ static int e1000_probe(uint16_t addr, pci_id_t id) /* alloc memory for tx ring */ - dev->tx_ring.desc = (struct tx_desc*)kmem; + dev->tx_ring.desc = (FAR struct tx_desc *)kmem; kmem += CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc); dev->tx_ring.buf = kmem; kmem += CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE; /* alloc memory for rx rings */ - dev->rx_ring.desc = (struct rx_desc*)kmem; + dev->rx_ring.desc = (FAR struct rx_desc *)kmem; kmem += CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc); dev->rx_ring.buf = kmem; @@ -1235,7 +1268,7 @@ void e1000_mod_exit(void) CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; size = ROUNDUP(size, PGSIZE); - for (dev=e1000_list.next; dev!=NULL; dev=dev->next) + for (dev = e1000_list.next; dev != NULL; dev = dev->next) { netdev_unregister(&dev->netdev); e1000_reset(dev); diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 3d0c43e94d..8c90f4c8e9 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -203,7 +203,7 @@ # define enc_cmddump(c) \ lowsyslog(LOG_DEBUG, "ENC28J60: CMD: %02x\n", c); # define enc_bmdump(c,b,s) \ - lowsyslog(LOG_DEBUG, "ENC28J60: CMD: %02x buffer: %p length: %d\n", c,b,s); + lowsyslog(LOG_DEBUG, "ENC28J60: CMD: %02x buffer: %p length: %d\n", c, b, s); #else # define enc_wrdump(a,v) # define enc_rddump(a,v) @@ -478,7 +478,7 @@ static uint8_t enc_rdgreg2(FAR struct enc_driver_s *priv, uint8_t cmd) /* Select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the read command and collect the data. The sequence requires * 16-clocks: 8 to clock out the cmd + 8 to clock in the data. @@ -521,7 +521,7 @@ static void enc_wrgreg2(FAR struct enc_driver_s *priv, uint8_t cmd, /* Select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the write command and data. The sequence requires 16-clocks: * 8 to clock out the cmd + 8 to clock out the data. @@ -565,7 +565,7 @@ static inline void enc_src(FAR struct enc_driver_s *priv) /* Select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the system reset command. */ @@ -612,7 +612,7 @@ static inline void enc_src(FAR struct enc_driver_s *priv) static void enc_setbank(FAR struct enc_driver_s *priv, uint8_t bank) { - /* Check if the bank setting has changed*/ + /* Check if the bank setting has changed */ if (bank != priv->bank) { @@ -662,7 +662,7 @@ static uint8_t enc_rdbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg) /* Re-select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the RCR command and collect the data. How we collect the data * depends on if this is a PHY/CAN or not. The normal sequence requires @@ -719,7 +719,7 @@ static void enc_wrbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, /* Re-select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the WCR command and data. The sequence requires 16-clocks: * 8 to clock out the cmd + 8 to clock out the data. @@ -823,8 +823,8 @@ static void enc_rxdump(FAR struct enc_driver_s *priv) static void enc_txdump(FAR struct enc_driver_s *priv) { lowsyslog(LOG_DEBUG, "Tx Registers:\n"); - lowsyslog(LOG_DEBUG, " EIE: %02x EIR: %02x ESTAT: %02x\n", - enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR),); + lowsyslog(LOG_DEBUG, " EIE: %02x EIR: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR)); lowsyslog(LOG_DEBUG, " ESTAT: %02x ECON1: %02x\n", enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1)); lowsyslog(LOG_DEBUG, " ETXST: %02x %02x\n", @@ -873,7 +873,7 @@ static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer, /* Select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the read buffer memory command (ignoring the response) */ @@ -918,7 +918,7 @@ static inline void enc_wrbuffer(FAR struct enc_driver_s *priv, * "The WBM command is started by lowering the CS pin. ..." */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the write buffer memory command (ignoring the response) * @@ -1591,7 +1591,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) else { - /* Save the packet length (without the 4 byte CRC) in priv->dev.d_len*/ + /* Save the packet length (without the 4 byte CRC) in priv->dev.d_len */ priv->dev.d_len = pktlen - 4; @@ -2100,7 +2100,7 @@ static int enc_ifup(struct net_driver_s *dev) nlldbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Lock the SPI bus so that we have exclusive access */ @@ -2171,7 +2171,7 @@ static int enc_ifdown(struct net_driver_s *dev) nlldbg("Taking down: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Lock the SPI bus so that we have exclusive access */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index ca47a01730..18057f325f 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -199,7 +199,7 @@ # define enc_cmddump(c) \ lowsyslog(LOG_DEBUG, "ENCX24J600: CMD: %02x\n", c); # define enc_bmdump(c,b,s) \ - lowsyslog(LOG_DEBUG, "ENCX24J600: CMD: %02x buffer: %p length: %d\n", c,b,s); + lowsyslog(LOG_DEBUG, "ENCX24J600: CMD: %02x buffer: %p length: %d\n", c, b, s); #else # define enc_wrdump(a,v) # define enc_rddump(a,v) @@ -344,8 +344,8 @@ static int enc_txpoll(struct net_driver_s *dev); /* Common RX logic */ static struct enc_descr_s *enc_rxgetdescr(FAR struct enc_driver_s *priv); -static void enc_rxldpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr); -static void enc_rxrmpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr); +static void enc_rxldpkt(FAR struct enc_driver_s *priv, FAR struct enc_descr_s *descr); +static void enc_rxrmpkt(FAR struct enc_driver_s *priv, FAR struct enc_descr_s *descr); static void enc_rxdispatch(FAR struct enc_driver_s *priv); /* Interrupt handling */ @@ -499,7 +499,7 @@ static void enc_cmd(FAR struct enc_driver_s *priv, uint8_t cmd, uint16_t arg) /* Select ENCX24J600 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); (void)SPI_SEND(priv->spi, cmd); /* Clock out the command */ (void)SPI_SEND(priv->spi, arg & 0xff); /* Clock out the low byte */ @@ -533,7 +533,7 @@ static inline void enc_setethrst(FAR struct enc_driver_s *priv) /* Select ENC28J60 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Send the system reset command. */ @@ -651,7 +651,7 @@ static void enc_wrreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg, DEBUGASSERT(priv && priv->spi); DEBUGASSERT((ctrlreg & 0xe0) == 0); /* banked regeitsers only */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); enc_setbank(priv, GETBANK(ctrlreg)); @@ -729,7 +729,7 @@ static void enc_bfs(FAR struct enc_driver_s *priv, uint16_t ctrlreg, /* Select ENCX24J600 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Set the bank */ @@ -774,7 +774,7 @@ static void enc_bfc(FAR struct enc_driver_s *priv, uint16_t ctrlreg, /* Select ENCX24J600 chip */ - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); /* Set the bank */ @@ -842,8 +842,8 @@ static void enc_rxdump(FAR struct enc_driver_s *priv) static void enc_txdump(FAR struct enc_driver_s *priv) { lowsyslog(LOG_DEBUG, "Tx Registers:\n"); - lowsyslog(LOG_DEBUG, " EIE: %02x EIR: %02x ESTAT: %02x\n", - enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR),); + lowsyslog(LOG_DEBUG, " EIE: %02x EIR: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR)); lowsyslog(LOG_DEBUG, " ESTAT: %02x ECON1: %02x\n", enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1)); lowsyslog(LOG_DEBUG, " ETXST: %02x %02x\n", @@ -932,7 +932,7 @@ static inline void enc_wrbuffer(FAR struct enc_driver_s *priv, { DEBUGASSERT(priv && priv->spi); - SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true); SPI_SEND(priv->spi, ENC_WGPDATA); SPI_SNDBLOCK(priv->spi, buffer, buflen); @@ -1071,11 +1071,11 @@ static void enc_wrphy(FAR struct enc_driver_s *priv, uint8_t phyaddr, static int enc_transmit(FAR struct enc_driver_s *priv) { - struct enc_descr_s *descr; + FAR struct enc_descr_s *descr; /* dequeue next packet to transmit */ - descr = (struct enc_descr_s*)sq_remfirst(&priv->txqueue); + descr = (FAR struct enc_descr_s *)sq_remfirst(&priv->txqueue); DEBUGASSERT(descr != NULL); @@ -1110,7 +1110,7 @@ static int enc_transmit(FAR struct enc_driver_s *priv) /* free the descriptor */ - sq_addlast((sq_entry_t*)descr, &priv->txfreedescr); + sq_addlast((FAR sq_entry_t *)descr, &priv->txfreedescr); return OK; } @@ -1137,7 +1137,7 @@ static int enc_transmit(FAR struct enc_driver_s *priv) static int enc_txenqueue(FAR struct enc_driver_s *priv) { int ret = OK; - struct enc_descr_s *descr; + FAR struct enc_descr_s *descr; DEBUGASSERT(priv->dev.d_len > 0); @@ -1147,7 +1147,7 @@ static int enc_txenqueue(FAR struct enc_driver_s *priv) priv->stats.txrequests++; #endif - descr = (struct enc_descr_s*)sq_remfirst(&priv->txfreedescr); + descr = (FAR struct enc_descr_s *)sq_remfirst(&priv->txfreedescr); if (descr != NULL) { @@ -1167,7 +1167,7 @@ static int enc_txenqueue(FAR struct enc_driver_s *priv) /* enqueue packet */ - sq_addlast((sq_entry_t*)descr, &priv->txqueue); + sq_addlast((FAR sq_entry_t *)descr, &priv->txqueue); /* if currently no transmission is active, trigger the transmission */ @@ -1367,7 +1367,7 @@ static void enc_txif(FAR struct enc_driver_s *priv) ****************************************************************************/ static void enc_rxldpkt(FAR struct enc_driver_s *priv, - struct enc_descr_s *descr) + FAR struct enc_descr_s *descr) { DEBUGASSERT(priv != NULL && descr != NULL); @@ -1414,10 +1414,10 @@ static struct enc_descr_s *enc_rxgetdescr(FAR struct enc_driver_s *priv) /* Packets are held in the enc's SRAM until the space is needed */ - enc_rxrmpkt(priv, (struct enc_descr_s*)sq_peek(&priv->rxqueue)); + enc_rxrmpkt(priv, (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue)); } - return (struct enc_descr_s*)sq_remfirst(&priv->rxfreedescr); + return (FAR struct enc_descr_s *)sq_remfirst(&priv->rxfreedescr); } /**************************************************************************** @@ -1439,7 +1439,7 @@ static struct enc_descr_s *enc_rxgetdescr(FAR struct enc_driver_s *priv) * ****************************************************************************/ -static void enc_rxrmpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr) +static void enc_rxrmpkt(FAR struct enc_driver_s *priv, FAR struct enc_descr_s *descr) { uint16_t addr; @@ -1452,7 +1452,7 @@ static void enc_rxrmpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr if (descr != NULL) { - if (descr == (struct enc_descr_s*)sq_peek(&priv->rxqueue)) + if (descr == (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue)) { /* Wrap address properly around */ addr = (descr->addr - PKTMEM_RX_START + descr->len - 2 + PKTMEM_RX_SIZE) @@ -1472,10 +1472,10 @@ static void enc_rxrmpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr { /* Remove packet from RX queue */ - sq_rem((sq_entry_t*)descr, &priv->rxqueue); + sq_rem((FAR sq_entry_t *)descr, &priv->rxqueue); } - sq_addlast((sq_entry_t*)descr, &priv->rxfreedescr); + sq_addlast((FAR sq_entry_t *)descr, &priv->rxfreedescr); } } @@ -1498,14 +1498,14 @@ static void enc_rxrmpkt(FAR struct enc_driver_s *priv, struct enc_descr_s *descr static void enc_rxdispatch(FAR struct enc_driver_s *priv) { - struct enc_descr_s *descr; + FAR struct enc_descr_s *descr; struct enc_descr_s *next; int ret = ERROR; /* Process the RX queue */ - descr = (struct enc_descr_s*)sq_peek(&priv->rxqueue); + descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue); while (descr != NULL) { @@ -1513,7 +1513,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) * flink to NULL */ - next = (struct enc_descr_s*)sq_next(descr); + next = (FAR struct enc_descr_s *)sq_next(descr); /* Load the packet from the enc's SRAM */ @@ -1674,7 +1674,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) static void enc_pktif(FAR struct enc_driver_s *priv) { - struct enc_descr_s *descr; + FAR struct enc_descr_s *descr; uint8_t rsv[8]; uint16_t pktlen; uint32_t rxstat; @@ -1736,7 +1736,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) descr->addr = curpkt + 8; descr->len = pktlen; - sq_addlast((sq_entry_t*)descr, &priv->rxqueue); + sq_addlast((FAR sq_entry_t *)descr, &priv->rxqueue); /* Check if the packet was received OK */ @@ -1810,7 +1810,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) static void enc_rxabtif(FAR struct enc_driver_s *priv) { - struct enc_descr_s *descr; + FAR struct enc_descr_s *descr; #if 0 /* Free the last received packet from the RX queue */ @@ -1821,18 +1821,18 @@ static void enc_rxabtif(FAR struct enc_driver_s *priv) nlldbg("ERXTAIL: %04x\n", enc_rdreg(priv, ENC_ERXTAIL)); nlldbg("ERXHAED: %04x\n", enc_rdreg(priv, ENC_ERXHEAD)); - descr = (struct enc_descr_s*)sq_peek(&priv->rxqueue); + descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue); while (descr != NULL) { nlldbg("addr: %04x len: %d\n", descr->addr, descr->len); - descr = (struct enc_descr_s*)sq_next(descr); + descr = (FAR struct enc_descr_s *)sq_next(descr); } DEBUGASSERT(false); #endif - descr = (struct enc_descr_s*)sq_peek(&priv->rxqueue); + descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue); if (descr != NULL) { @@ -2278,7 +2278,7 @@ static int enc_ifup(struct net_driver_s *dev) nlldbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Lock the SPI bus so that we have exclusive access */ @@ -2300,7 +2300,7 @@ static int enc_ifup(struct net_driver_s *dev) enc_bfc(priv, ENC_EIR, EIR_ALLINTS); enc_bfs(priv, ENC_EIE, EIE_INTIE | EIE_LINKIE | EIE_PKTIE | EIE_RXABTIE | - EIE_TXIE ); + EIE_TXIE); #ifdef CONFIG_ENCX24J600_STATS enc_bfs(priv, ENC_EIE, EIE_TXABTIE); @@ -2353,7 +2353,7 @@ static int enc_ifdown(struct net_driver_s *dev) nlldbg("Taking down: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Lock the SPI bus so that we have exclusive access */ @@ -2739,14 +2739,14 @@ static void enc_resetbuffers(FAR struct enc_driver_s *priv) for (i = 0; i < ENC_NTXDESCR; i++) { priv->txdescralloc[i].addr = PKTMEM_START + PKTMEM_ALIGNED_BUFSIZE * i; - sq_addlast((sq_entry_t*)&priv->txdescralloc[i], &priv->txfreedescr); + sq_addlast((FAR sq_entry_t *)&priv->txdescralloc[i], &priv->txfreedescr); } /* Receive descriptors addresses are set on reception */ for (i = 0; i < CONFIG_ENCX24J600_NRXDESCR; i++) { - sq_addlast((sq_entry_t*)&priv->rxdescralloc[i], &priv->rxfreedescr); + sq_addlast((FAR sq_entry_t *)&priv->rxdescralloc[i], &priv->rxfreedescr); } } diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 2a7b236ab4..2a980ed5cc 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -283,9 +283,9 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) FAR struct ftmac100_register_s *iobase = (FAR struct ftmac100_register_s *)priv->iobase; FAR struct ftmac100_txdes_s *txdes; int len = priv->ft_dev.d_len; -// irqstate_t flags; -// flags = irqsave(); -// nvdbg("flags=%08x\n", flags); +//irqstate_t flags; +//flags = irqsave(); +//nvdbg("flags=%08x\n", flags); txdes = ftmac100_current_txdes(priv); @@ -300,7 +300,7 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) /* Send the packet: address=priv->ft_dev.d_buf, length=priv->ft_dev.d_len */ -// memcpy((void *)txdes->txdes2, priv->ft_dev.d_buf, len); +//memcpy((void *)txdes->txdes2, priv->ft_dev.d_buf, len); txdes->txdes2 = (unsigned int)priv->ft_dev.d_buf; txdes->txdes1 &= FTMAC100_TXDES1_EDOTR; txdes->txdes1 |= (FTMAC100_TXDES1_FTS | @@ -316,7 +316,8 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) priv->tx_pending++; /* Enable Tx polling */ - // FIXME: enable interrupts + /* FIXME: enable interrupts */ + putreg32(1, &iobase->txpd); /* Setup the TX timeout watchdog (perhaps restarting the timer) */ @@ -324,7 +325,7 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) (void)wd_start(priv->ft_txtimeout, FTMAC100_TXTIMEOUT, ftmac100_txtimeout_expiry, 1, (uint32_t)priv); -// irqrestore(flags); +//irqrestore(flags); return OK; } @@ -482,10 +483,10 @@ static void ftmac100_init(FAR struct ftmac100_driver_s *priv) rxdes[i].rxdes0 = FTMAC100_RXDES0_RXDMA_OWN; rxdes[i].rxdes1 |= FTMAC100_RXDES1_RXBUF_SIZE(RX_BUF_SIZE); rxdes[i].rxdes2 = (unsigned int)(kmem + i * RX_BUF_SIZE); - rxdes[i].rxdes3 = (unsigned int)(rxdes + i + 1); // next ring + rxdes[i].rxdes3 = (unsigned int)(rxdes + i + 1); /* Next ring */ } - rxdes[CONFIG_FTMAC100_RX_DESC - 1].rxdes3 = (unsigned int)rxdes; // next ring + rxdes[CONFIG_FTMAC100_RX_DESC - 1].rxdes3 = (unsigned int)rxdes; /* Next ring */ for (i = 0; i < CONFIG_FTMAC100_TX_DESC; i++) { @@ -495,11 +496,11 @@ static void ftmac100_init(FAR struct ftmac100_driver_s *priv) txdes[i].txdes1 = 0; txdes[i].txdes2 = 0; txdes[i].txdes3 = 0; -// txdes[i].txdes3 = (unsigned int)(txdes + i + 1); // next ring +// txdes[i].txdes3 = (unsigned int)(txdes + i + 1); /* Next ring */ } txdes[CONFIG_FTMAC100_TX_DESC - 1].txdes1 = FTMAC100_TXDES1_EDOTR; -// txdes[CONFIG_FTMAC100_TX_DESC - 1].txdes3 = (unsigned int)txdes; // next ring +//txdes[CONFIG_FTMAC100_TX_DESC - 1].txdes3 = (unsigned int)txdes; /* Next ring */ /* transmit ring */ @@ -513,7 +514,7 @@ static void ftmac100_init(FAR struct ftmac100_driver_s *priv) /* set RXINT_THR and TXINT_THR */ -// putreg32 (FTMAC100_ITC_RXINT_THR(1) | FTMAC100_ITC_TXINT_THR(1), &iobase->itc); +//putreg32 (FTMAC100_ITC_RXINT_THR(1) | FTMAC100_ITC_TXINT_THR(1), &iobase->itc); /* poll receive descriptor automatically */ @@ -526,8 +527,8 @@ static void ftmac100_init(FAR struct ftmac100_driver_s *priv) FTMAC100_DBLAC_RXFIFO_HTHR(6) | FTMAC100_DBLAC_RX_THR_EN, &iobase->dblac); -// putreg32 (getreg32(&iobase->fcr) | 0x1, &iobase->fcr); -// putreg32 (getreg32(&iobase->bpr) | 0x1, &iobase->bpr); +//putreg32 (getreg32(&iobase->fcr) | 0x1, &iobase->fcr); +//putreg32 (getreg32(&iobase->bpr) | 0x1, &iobase->bpr); #endif /* enable transmitter, receiver */ @@ -971,16 +972,16 @@ static void ftmac100_interrupt_work(FAR void *arg) { FAR struct ftmac100_driver_s *priv = (FAR struct ftmac100_driver_s *)arg; net_lock_t state; -// irqstate_t flags; +//irqstate_t flags; /* Process pending Ethernet interrupts */ state = net_lock(); -// flags = irqsave(); +//flags = irqsave(); ftmac100_interrupt_process(priv); -// irqrestore(flags); +//irqrestore(flags); net_unlock(state); /* Re-enable Ethernet interrupts */ @@ -1536,8 +1537,7 @@ static int ftmac100_addmac(struct net_driver_s *dev, FAR const uint8_t *mac) hash_value = crc32part(mac, 6, ~0L); - /* - * The HASH Table is a register array of 2 32-bit registers. + /* The HASH Table is a register array of 2 32-bit registers. * It is treated like an array of 64 bits. We want to set * bit BitArray[hash_value]. So we figure out what register * the bit is in, read it, OR in the new bit, then write @@ -1728,12 +1728,12 @@ int ftmac100_initialize(int intf) priv->ft_dev.d_addmac = ftmac100_addmac; /* Add multicast MAC address */ priv->ft_dev.d_rmmac = ftmac100_rmmac; /* Remove multicast MAC address */ #endif - priv->ft_dev.d_private = (void*)g_ftmac100; /* Used to recover private state from dev */ + priv->ft_dev.d_private = (FAR void *)g_ftmac100; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->ft_txpoll = wd_create(); /* Create periodic poll timer */ - priv->ft_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->ft_txpoll = wd_create(); /* Create periodic poll timer */ + priv->ft_txtimeout = wd_create(); /* Create TX timeout timer */ priv->iobase = CONFIG_FTMAC100_BASE; diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 7e50890208..79b8bfc5bf 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -540,7 +540,7 @@ int localhost_initialize(void) #ifdef CONFIG_NET_MULTIBUFFER priv->lo_dev.d_buf = g_iobuffer; /* Attach the IO buffer */ #endif - priv->lo_dev.d_private = (void*)priv; /* Used to recover private state from dev */ + priv->lo_dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmissions */ diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 949ace1938..c59498e6bd 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -1204,12 +1204,12 @@ int skel_initialize(int intf) priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */ #endif - priv->sk_dev.d_private = (void*)g_skel; /* Used to recover private state from dev */ + priv->sk_dev.d_private = (FAR void *)g_skel; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ - priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ + priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling skel_ifdown(). diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 203f9f7090..a7db1780ce 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -474,7 +474,7 @@ static void slip_txtask(int argc, FAR char *argv[]) /* Loop forever */ msec_start = clock_systimer() * MSEC_PER_TICK; - for (;;) + for (; ; ) { /* Wait for the timeout to expire (or until we are signaled by by */ @@ -579,7 +579,7 @@ static inline void slip_receive(FAR struct slip_driver_s *priv) */ nvdbg("Receiving packet\n"); - for (;;) + for (; ; ) { /* Get the next character in the stream. */ @@ -696,7 +696,7 @@ static int slip_rxtask(int argc, FAR char *argv[]) /* Loop forever */ - for (;;) + for (; ; ) { /* Wait for the next character to be available on the input stream. */ @@ -802,7 +802,7 @@ static int slip_ifup(FAR struct net_driver_s *dev) ndbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Mark the interface up */ diff --git a/drivers/net/tun.c b/drivers/net/tun.c index b8c5ca09d3..39f5266568 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -182,7 +182,7 @@ static void tun_ipv6multicast(FAR struct tun_device_s *priv); #endif static int tun_dev_init(FAR struct tun_device_s *priv, - FAR struct file *filep, FAR const char* devfmt); + FAR struct file *filep, FAR const char *devfmt); static int tun_dev_uninit(FAR struct tun_device_s *priv); /* File interface */ @@ -296,7 +296,6 @@ static void tun_pollnotify(FAR struct tun_device_s *priv, pollevent_t eventset) if (eventset != 0) { fds->revents |= eventset; - //fvdbg("Report events: %02x\n", fds->revents); sem_post(fds->sem); } } @@ -458,8 +457,8 @@ static void tun_receive(FAR struct tun_device_s *priv) ipv6_input(&priv->dev); /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + * sent out on the network, the field d_len will set to a value > 0. + */ if (priv->dev.d_len > 0) { @@ -789,8 +788,6 @@ static int tun_txavail(struct net_driver_s *dev) #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) static int tun_addmac(struct net_driver_s *dev, FAR const uint8_t *mac) { - //FAR struct tun_device_s *priv = (FAR struct tun_device_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ return OK; @@ -818,8 +815,6 @@ static int tun_addmac(struct net_driver_s *dev, FAR const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int tun_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac) { - //FAR struct tun_device_s *priv = (FAR struct tun_device_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ return OK; @@ -864,7 +859,7 @@ static void tun_ipv6multicast(FAR struct tun_device_s *priv) ****************************************************************************/ static int tun_dev_init(FAR struct tun_device_s *priv, FAR struct file *filep, - FAR const char* devfmt) + FAR const char *devfmt) { int ret; @@ -878,7 +873,7 @@ static int tun_dev_init(FAR struct tun_device_s *priv, FAR struct file *filep, priv->dev.d_addmac = tun_addmac; /* Add multicast MAC address */ priv->dev.d_rmmac = tun_rmmac; /* Remove multicast MAC address */ #endif - priv->dev.d_private = (void*)priv; /* Used to recover private state from dev */ + priv->dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Initialize the wait semaphore */ @@ -1187,7 +1182,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { uint8_t free_tuns; int intf; - FAR struct ifreq *ifr = (FAR struct ifreq*)arg; + FAR struct ifreq *ifr = (FAR struct ifreq *)arg; if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN) { diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index cba5f5aa63..abd08a3cae 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -103,12 +103,11 @@ struct vnet_driver_s { bool sk_bifup; /* true:ifup false:ifdown */ WDOG_ID sk_txpoll; /* TX poll timer */ - //WDOG_ID sk_txtimeout; /* TX timeout timer */ + struct rgmp_vnet *vnet; - /* This holds the information visible to uIP/NuttX */ + /* This holds the information visible to the NuttX */ - struct rgmp_vnet *vnet; - struct net_driver_s sk_dev; /* Interface understood by uIP */ + struct net_driver_s sk_dev; /* Interface understood by the network */ }; /**************************************************************************** @@ -185,10 +184,6 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet) err = vnet_xmit(vnet->vnet, (char *)vnet->sk_dev.d_buf, vnet->sk_dev.d_len); if (err) { - /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - - //(void)wd_start(vnet->sk_txtimeout, VNET_TXTIMEOUT, vnet_txtimeout, 1, (uint32_t)vnet); - /* When vnet_xmit fail, it means TX buffer is full. Watchdog * is of no use here because no TX done INT will happen. So * we reset the TX buffer directly. @@ -213,8 +208,9 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet) * Function: vnet_txpoll * * Description: - * The transmitter is available, check if uIP has any outgoing packets ready - * to send. This is a callback from devif_poll(). devif_poll() may be called: + * The transmitter is available, check if the network has any outgoing + * packets ready to send. This is a callback from devif_poll(). + * devif_poll() may be called: * * 1. When the preceding TX packet send is complete, * 2. When the preceding TX packet send timesout and the interface is reset @@ -309,9 +305,9 @@ void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) do { - /* Check for errors and update statistics */ - - /* Check if the packet is a valid size for the uIP buffer configuration */ + /* Check if the packet is a valid size for the network buffer + * configuration. + */ if (len > CONFIG_NET_ETH_MTU || len < 14) { @@ -418,8 +414,9 @@ void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) { arp_arpin(&vnet->sk_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. + /* If the above function invocation resulted in data that should + * be sent out on the network, the field d_len will set to a + * value > 0. */ if (vnet->sk_dev.d_len > 0) @@ -451,15 +448,7 @@ void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) static void vnet_txdone(FAR struct vnet_driver_s *vnet) { - /* Check for errors and update statistics */ - - /* If no further xmits are pending, then cancel the TX timeout and - * disable further Tx interrupts. - */ - - //wd_cancel(vnet->sk_txtimeout); - - /* Then poll uIP for new XMIT data */ + /* Poll the network for new XMIT data */ (void)devif_poll(&vnet->sk_dev, vnet_txpoll); } @@ -491,7 +480,7 @@ static void vnet_txtimeout(int argc, uint32_t arg, ...) /* Then reset the hardware */ - /* Then poll uIP for new XMIT data */ + /* Then poll the network for new XMIT data */ (void)devif_poll(&vnet->sk_dev, vnet_txpoll); } @@ -530,9 +519,9 @@ static void vnet_polltimer(int argc, uint32_t arg, ...) return; } - /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. - * might be bug here. Does this mean if there is a transmit in progress, - * we will missing TCP time state updates? + /* If so, update TCP timing states and poll the network for new XMIT data. + * Hmmm.. might be bug here. Does this mean if there is a transmit in + * progress, we will missing TCP time state updates? */ (void)devif_timer(&vnet->sk_dev, vnet_txpoll, VNET_POLLHSEC); @@ -565,7 +554,7 @@ static int vnet_ifup(struct net_driver_s *dev) ndbg("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ @@ -605,7 +594,6 @@ static int vnet_ifdown(struct net_driver_s *dev) /* Cancel the TX poll timer and TX timeout timers */ wd_cancel(vnet->sk_txpoll); - //wd_cancel(vnet->sk_txtimeout); /* Put the EMAC is its reset, non-operational state. This should be * a known configuration that will guarantee the vnet_ifup() always @@ -663,7 +651,7 @@ static int vnet_txavail(struct net_driver_s *dev) goto out; } - /* If so, then poll uIP for new XMIT data */ + /* If so, then poll the network for new XMIT data */ (void)devif_poll(&vnet->sk_dev, vnet_txpoll); } @@ -774,15 +762,14 @@ int vnet_init(struct rgmp_vnet *vnet) priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */ #endif - priv->sk_dev.d_private = (void*)priv; /* Used to recover private state from dev */ + priv->sk_dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ - //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ - priv->vnet = vnet; - vnet->priv = priv; + priv->vnet = vnet; + vnet->priv = priv; /* Register the device with the OS */ diff --git a/drivers/pipes/fifo.c b/drivers/pipes/fifo.c index 7148edc3cc..85905cb111 100644 --- a/drivers/pipes/fifo.c +++ b/drivers/pipes/fifo.c @@ -121,7 +121,7 @@ static const struct file_operations fifo_fops = int mkfifo(FAR const char *pathname, mode_t mode) { - struct pipe_dev_s *dev; + FAR struct pipe_dev_s *dev; int ret; /* Allocate and initialize a new device structure instance */ @@ -132,7 +132,7 @@ int mkfifo(FAR const char *pathname, mode_t mode) return -ENOMEM; } - ret = register_driver(pathname, &fifo_fops, mode, (void*)dev); + ret = register_driver(pathname, &fifo_fops, mode, (FAR void *)dev); if (ret != 0) { pipecommon_freedev(dev); diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c index 530c9871a2..b4c6acd72c 100644 --- a/drivers/pipes/pipe.c +++ b/drivers/pipes/pipe.c @@ -234,7 +234,7 @@ int pipe(int fd[2]) /* Register the pipe device */ - ret = register_driver(devname, &pipe_fops, 0666, (void*)dev); + ret = register_driver(devname, &pipe_fops, 0666, (FAR void *)dev); if (ret != 0) { (void)sem_post(&g_pipesem); diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index bfe043ebf4..37e1fc18cd 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -197,12 +197,12 @@ void pipecommon_freedev(FAR struct pipe_dev_s *dev) int pipecommon_open(FAR struct file *filep) { - struct inode *inode = filep->f_inode; - struct pipe_dev_s *dev = inode->i_private; - int sval; - int ret; + FAR struct inode *inode = filep->f_inode; + FAR struct pipe_dev_s *dev = inode->i_private; + int sval; + int ret; - DEBUGASSERT(dev); + DEBUGASSERT(dev != NULL); /* Make sure that we have exclusive access to the device structure. The * sem_wait() call should fail only if we are awakened by a signal. @@ -223,7 +223,7 @@ int pipecommon_open(FAR struct file *filep) if (dev->d_refs == 0 && dev->d_buffer == NULL) { - dev->d_buffer = (uint8_t*)kmm_malloc(CONFIG_DEV_PIPE_SIZE); + dev->d_buffer = (FAR uint8_t *)kmm_malloc(CONFIG_DEV_PIPE_SIZE); if (!dev->d_buffer) { (void)sem_post(&dev->d_bfsem); @@ -418,7 +418,7 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len) struct inode *inode = filep->f_inode; struct pipe_dev_s *dev = inode->i_private; #ifdef CONFIG_DEV_PIPEDUMP - FAR uint8_t *start = (uint8_t*)buffer; + FAR uint8_t *start = (FAR uint8_t *)buffer; #endif ssize_t nread = 0; int sval; @@ -514,7 +514,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t int sval; DEBUGASSERT(dev); - pipe_dumpbuffer("To PIPE:", (uint8_t*)buffer, len); + pipe_dumpbuffer("To PIPE:", (FAR uint8_t *)buffer, len); if (len == 0) { @@ -545,7 +545,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t /* Loop until all of the bytes have been written */ last = 0; - for (;;) + for (; ; ) { /* Calculate the write index AFTER the next byte is written */ diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c index fd6bcc8f6c..056e16e98c 100644 --- a/drivers/power/battery_charger.c +++ b/drivers/power/battery_charger.c @@ -72,8 +72,8 @@ static int bat_charger_open(FAR struct file *filep); static int bat_charger_close(FAR struct file *filep); -static ssize_t bat_charger_read(FAR struct file *, FAR char *, - size_t nbytes); +static ssize_t bat_charger_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static ssize_t bat_charger_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int bat_charger_ioctl(FAR struct file *filep, int cmd, diff --git a/drivers/power/battery_gauge.c b/drivers/power/battery_gauge.c index 032b6b1158..cf6a962e2b 100644 --- a/drivers/power/battery_gauge.c +++ b/drivers/power/battery_gauge.c @@ -72,7 +72,8 @@ static int bat_gauge_open(FAR struct file *filep); static int bat_gauge_close(FAR struct file *filep); -static ssize_t bat_gauge_read(FAR struct file *, FAR char *, size_t nbytes); +static ssize_t bat_gauge_read(FAR struct file *filep, FAR char *buflen, + size_t buflen); static ssize_t bat_gauge_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int bat_gauge_ioctl(FAR struct file *filep, int cmd, diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index 9b0e1045e7..13adc5d5ce 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -129,24 +129,25 @@ enum pm_state_e pm_checkstate(void) now = clock_systimer(); if (now - g_pmglobals.stime >= TIME_SLICE_TICKS) { - int16_t accum; + int16_t accum; - /* Sample the count, reset the time and count, and assess the PM - * state. This is an atomic operation because interrupts are - * still disabled. - */ + /* Sample the count, reset the time and count, and assess the PM + * state. This is an atomic operation because interrupts are + * still disabled. + */ - accum = g_pmglobals.accum; - g_pmglobals.stime = now; - g_pmglobals.accum = 0; + accum = g_pmglobals.accum; + g_pmglobals.stime = now; + g_pmglobals.accum = 0; - /* Reassessing the PM state may require some computation. However, - * the work will actually be performed on a worker thread at a user- - * controlled priority. - */ + /* Reassessing the PM state may require some computation. However, + * the work will actually be performed on a worker thread at a user- + * controlled priority. + */ - (void)pm_update(accum); + (void)pm_update(accum); } + irqrestore(flags); /* Return the recommended state. Assuming that we are called from the diff --git a/drivers/power/pm_update.c b/drivers/power/pm_update.c index e705883f5b..7392029935 100644 --- a/drivers/power/pm_update.c +++ b/drivers/power/pm_update.c @@ -328,7 +328,8 @@ void pm_update(int16_t accum) /* The work will be performed on the worker thread */ DEBUGASSERT(g_pmglobals.work.worker == NULL); - (void)work_queue(HPWORK, &g_pmglobals.work, pm_worker, (FAR void*)((intptr_t)accum), 0); + (void)work_queue(HPWORK, &g_pmglobals.work, pm_worker, + (FAR void *)((intptr_t)accum), 0); } #endif /* CONFIG_PM */ diff --git a/drivers/pwm.c b/drivers/pwm.c index 3151a57862..9071ab0543 100644 --- a/drivers/pwm.c +++ b/drivers/pwm.c @@ -438,7 +438,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_SETCHARACTERISTICS: { - FAR const struct pwm_info_s *info = (FAR const struct pwm_info_s*)((uintptr_t)arg); + FAR const struct pwm_info_s *info = (FAR const struct pwm_info_s *)((uintptr_t)arg); DEBUGASSERT(info != NULL && lower->ops->start != NULL); #ifdef CONFIG_PWM_PULSECOUNT @@ -475,7 +475,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_GETCHARACTERISTICS: { - FAR struct pwm_info_s *info = (FAR struct pwm_info_s*)((uintptr_t)arg); + FAR struct pwm_info_s *info = (FAR struct pwm_info_s *)((uintptr_t)arg); DEBUGASSERT(info != NULL); memcpy(info, &upper->info, sizeof(struct pwm_info_s)); diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index 584b25b091..9cd2a6d60d 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -561,7 +561,7 @@ int rwb_invalidate_readahead(FAR struct rwbuffer_s *rwb, rhbend = rwb->rhblockstart + rwb->rhnblocks; invend = startblock + blockcount; - if (rhbend <= startblock || rwb->rhblockstart >= invend ) + if (rhbend <= startblock || rwb->rhblockstart >= invend) { ret = OK; } @@ -640,7 +640,7 @@ int rwb_initialize(FAR struct rwbuffer_s *rwb) /* Setup so that rwb_uninitialize can handle a failure */ #ifdef CONFIG_DRVR_WRITEBUFFER - DEBUGASSERT(rwb->wrflush!= NULL); + DEBUGASSERT(rwb->wrflush != NULL); rwb->wrbuffer = NULL; #endif #ifdef CONFIG_DRVR_READAHEAD @@ -785,7 +785,7 @@ int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32_t nblocks, /* Loop until we have read all of the requested blocks */ rwb_semtake(&rwb->rhsem); - for (remaining = nblocks; remaining > 0;) + for (remaining = nblocks; remaining > 0; ) { /* Is there anything in the read-ahead buffer? */ diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index 32b1d4bc5e..c379b5707a 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -144,7 +144,8 @@ static int bmp180_getpressure(FAR struct bmp180_dev_s *priv); static int bmp180_open(FAR struct file *filep); static int bmp180_close(FAR struct file *filep); -static ssize_t bmp180_read(FAR struct file *, FAR char *, size_t); +static ssize_t bmp180_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static ssize_t bmp180_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); @@ -523,7 +524,7 @@ static ssize_t bmp180_read(FAR struct file *filep, FAR char *buffer, return -1; } - if ( buflen != 4) + if (buflen != 4) { sndbg("You can't read something other than 32 bits (4 bytes)\n"); return -1; diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index 10cf8d360a..aad762c8ec 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -249,7 +249,7 @@ FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_dev_s *i2c, { /* Copy LIS331DL registers to our private structure and power-up device */ - if (lis331dl_readregs(dev)==OK && lis331dl_powerup(dev) == OK) + if (lis331dl_readregs(dev) == OK && lis331dl_powerup(dev) == OK) { /* Normal exit point */ diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 7c47f86710..e1a43539e8 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -89,8 +89,10 @@ static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf); static int lm75_open(FAR struct file *filep); static int lm75_close(FAR struct file *filep); -static ssize_t lm75_read(FAR struct file *, FAR char *, size_t); -static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); +static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); static int lm75_ioctl(FAR struct file *filep,int cmd,unsigned long arg); /**************************************************************************** @@ -338,7 +340,7 @@ static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer, size_t buflen ret = lm75_readtemp(priv, &temp); if (ret < 0) { - sndbg("lm75_readtemp failed: %d\n",ret); + sndbg("lm75_readtemp failed: %d\n", ret); return (ssize_t)ret; } @@ -387,7 +389,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_WRITECONF: ret = lm75_writeconf(priv, (uint8_t)arg); - sndbg("conf: %02x ret: %d\n", *(uint8_t*)arg, ret); + sndbg("conf: %02x ret: %d\n", *(FAR uint8_t *)arg, ret); break; /* Shutdown the LM75, Arg: None */ diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index f2fa27f65b..02ed18196b 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -384,7 +384,7 @@ static ssize_t lm92_read(FAR struct file *filep, FAR char *buffer, ret = lm92_readtemp(priv, &temp); if (ret < 0) { - sndbg("lm92_readtemp failed: %d\n",ret); + sndbg("lm92_readtemp failed: %d\n", ret); return (ssize_t)ret; } diff --git a/drivers/sensors/max31855.c b/drivers/sensors/max31855.c index bbc0b341fa..fae6d8783e 100644 --- a/drivers/sensors/max31855.c +++ b/drivers/sensors/max31855.c @@ -37,7 +37,7 @@ /* NOTE: Some Maxim MAX31855 chips have an issue it report value 25% lower * of real temperature, for more info read this thread: * http://www.eevblog.com/forum/projects/max31855-temperature-error/ -*/ + */ /**************************************************************************** * Included Files @@ -87,7 +87,8 @@ struct max31855_dev_s static int max31855_open(FAR struct file *filep); static int max31855_close(FAR struct file *filep); -static ssize_t max31855_read(FAR struct file *, FAR char *, size_t); +static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static ssize_t max31855_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); diff --git a/drivers/sensors/mpl115a.c b/drivers/sensors/mpl115a.c index f3d1bff907..86a92dfe25 100644 --- a/drivers/sensors/mpl115a.c +++ b/drivers/sensors/mpl115a.c @@ -86,7 +86,8 @@ static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv); static int mpl115a_open(FAR struct file *filep); static int mpl115a_close(FAR struct file *filep); -static ssize_t mpl115a_read(FAR struct file *, FAR char *, size_t); +static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); /**************************************************************************** @@ -249,8 +250,8 @@ static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv) /* Check if coefficient data were read correctly */ - if ( (priv->mpl115a_cal_a0 == 0) || (priv->mpl115a_cal_b1 == 0) || - (priv->mpl115a_cal_b2 == 0) || (priv->mpl115a_cal_c12 == 0) ) + if ((priv->mpl115a_cal_a0 == 0) || (priv->mpl115a_cal_b1 == 0) || + (priv->mpl115a_cal_b2 == 0) || (priv->mpl115a_cal_c12 == 0)) { mpl115a_updatecaldata(priv); } @@ -324,7 +325,7 @@ static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer, size_t buf return -1; } - if ( buflen != 2) + if (buflen != 2) { sndbg("You can't read something other than 16 bits (2 bytes)\n"); return -1; diff --git a/drivers/sensors/qencoder.c b/drivers/sensors/qencoder.c index f550beeeae..34cb029d4c 100644 --- a/drivers/sensors/qencoder.c +++ b/drivers/sensors/qencoder.c @@ -231,10 +231,9 @@ static int qe_close(FAR struct file *filep) lower->ops->shutdown(lower); } - ret = OK; -//errout_with_sem: sem_post(&upper->exclsem); + ret = OK; errout: return ret; @@ -243,7 +242,7 @@ errout: /************************************************************************************ * Name: qe_read * - * Description: + * Description:O * A dummy read method. This is provided only to satsify the VFS layer. * ************************************************************************************/ diff --git a/drivers/sercomm/console.c b/drivers/sercomm/console.c index 9b9a9063e7..53b321964f 100644 --- a/drivers/sercomm/console.c +++ b/drivers/sercomm/console.c @@ -49,16 +49,6 @@ #include "uart.h" #include -/* stubs to make serial driver happy */ - -void sercomm_recvchars(void *a) { } -void sercomm_xmitchars(void *a) { } - -/* Stubs to make memory allocator happy */ - -void cons_puts(void *foo){} -void delay_ms(int ms){} - /************************************************************************************ * Fileops Prototypes and Structures ************************************************************************************/ @@ -102,7 +92,8 @@ static void recv_cb(uint8_t dlci, struct msgb *msg) * Fileops ****************************************************************************/ -/* XXX: recvmsg is overwritten when multiple msg arrive! */ +/* REVISIT: recvmsg is overwritten when multiple msg arrive! */ + static ssize_t sc_console_read(file_t *filep, FAR char *buffer, size_t buflen) { size_t len; @@ -130,7 +121,7 @@ static ssize_t sc_console_read(file_t *filep, FAR char *buffer, size_t buflen) return len; } -/* XXX: redirect to old Osmocom-BB comm/sercomm_cons.c -> 2 buffers */ +/* REVISIT: redirect to old Osmocom-BB comm/sercomm_cons.c -> 2 buffers */ extern int sercomm_puts(const char *s); @@ -180,7 +171,7 @@ static int sc_console_ioctl(struct file *filep, int cmd, unsigned long arg) int sercomm_register(FAR const char *path, FAR uart_dev_t *dev) { - /* XXX: initialize MODEMUART to be used for sercomm*/ + /* REVISIT: initialize MODEMUART to be used for sercomm */ uart_init(SERCOMM_UART_NR, 1); uart_baudrate(SERCOMM_UART_NR, UART_115200); @@ -199,3 +190,23 @@ int sercomm_register(FAR const char *path, FAR uart_dev_t *dev) dbg("Registering %s\n", path); return register_driver(path, &g_sercom_console_ops, 0666, NULL); } + +/* Stubs to make serial driver happy */ + +void sercomm_recvchars(void *a) +{ +} + +void sercomm_xmitchars(void *a) +{ +} + +/* Stubs to make memory allocator happy */ + +void cons_puts(void *foo) +{ +} + +void delay_ms(int ms) +{ +} diff --git a/drivers/sercomm/uart.c b/drivers/sercomm/uart.c index 234f600dd8..9e257455a8 100644 --- a/drivers/sercomm/uart.c +++ b/drivers/sercomm/uart.c @@ -46,7 +46,6 @@ #include #include -//#include #include #include "uart.h" @@ -269,8 +268,6 @@ static void uart_irq_handler_cons(__unused enum irq_nr irqnr) const uint8_t uart = CONS_UART_NR; uint8_t iir; - //uart_putchar_nb(uart, 'U'); - iir = uart_reg_read(uart, IIR); if (iir & IIR_INT_PENDING) { @@ -313,8 +310,6 @@ static void uart_irq_handler_sercomm(__unused enum irq_nr irqnr, __unused void * const uint8_t uart = SERCOMM_UART_NR; uint8_t iir, ch; - //uart_putchar_nb(uart, 'U'); - iir = uart_reg_read(uart, IIR); if (iir & IIR_INT_PENDING) { @@ -422,7 +417,7 @@ void uart_init(uint8_t uart, uint8_t interrupts) #if 0 if (uart == 1) { - /* assign UART to MCU and unmask interrupts*/ + /* assign UART to MCU and unmask interrupts */ writeb(UART_REG_UIR, 0x00); } @@ -454,7 +449,7 @@ void uart_init(uint8_t uart, uint8_t interrupts) /* THR interrupt only when TX FIFO and TX shift register are empty */ - uart_reg_write(uart, SCR, (1 << 0));// | (1 << 3)); + uart_reg_write(uart, SCR, (1 << 0)); /* | (1 << 3)); */ /* 8 bit, 1 stop bit, no parity, no break */ @@ -570,7 +565,6 @@ int uart_getchar_nb(uint8_t uart, uint8_t *ch) } *ch = readb(UART_REG(uart, RHR)); - //printf("getchar_nb(%u) = %02x\n", uart, *ch); return 1; } diff --git a/drivers/serial/lowconsole.c b/drivers/serial/lowconsole.c index ada5b518d1..00cb7ebdf6 100644 --- a/drivers/serial/lowconsole.c +++ b/drivers/serial/lowconsole.c @@ -125,7 +125,7 @@ static ssize_t lowconsole_write(struct file *filep, const char *buffer, size_t b /**************************************************************************** * Name: lowconsole_init -****************************************************************************/ + ****************************************************************************/ void lowconsole_init(void) { diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 560aa7af22..9930810fc7 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -169,7 +169,7 @@ static void uart_pollnotify(FAR uart_dev_t *dev, pollevent_t eventset) if (fds) { #ifdef CONFIG_SERIAL_REMOVABLE - fds->revents |= ((fds->events | (POLLERR|POLLHUP)) & eventset); + fds->revents |= ((fds->events | (POLLERR | POLLHUP)) & eventset); #else fds->revents |= (fds->events & eventset); #endif @@ -207,7 +207,7 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) /* Loop until we are able to add the character to the TX buffer */ - for (;;) + for (; ; ) { if (nexthead != dev->xmit.tail) { @@ -270,9 +270,9 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) if (ret < 0) { - /* A signal received while waiting for the xmit buffer to become - * non-full will abort the transfer. - */ + /* A signal received while waiting for the xmit buffer to become + * non-full will abort the transfer. + */ return -EINTR; } @@ -898,7 +898,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { case TCGETS: { - FAR struct termios *termiosp = (struct termios*)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -916,7 +916,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case TCSETS: { - FAR struct termios *termiosp = (struct termios*)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -1044,7 +1044,7 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) if (dev->disconnected) { - eventset |= (POLLERR|POLLHUP); + eventset |= (POLLERR | POLLHUP); } #endif @@ -1437,7 +1437,7 @@ void uart_connected(FAR uart_dev_t *dev, bool connected) /* Notify all poll/select waiters that a hangup occurred */ - uart_pollnotify(dev, (POLLERR|POLLHUP)); + uart_pollnotify(dev, (POLLERR | POLLHUP)); } irqrestore(flags); diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index adc193deeb..7db5291701 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -464,7 +464,7 @@ static uart_dev_t g_uart3port = * Name: u16550_serialin ****************************************************************************/ -static inline uart_datawidth_t u16550_serialin(struct u16550_s *priv, int offset) +static inline uart_datawidth_t u16550_serialin(FAR struct u16550_s *priv, int offset) { return uart_getreg(priv->uartbase, offset); } @@ -473,7 +473,8 @@ static inline uart_datawidth_t u16550_serialin(struct u16550_s *priv, int offset * Name: u16550_serialout ****************************************************************************/ -static inline void u16550_serialout(struct u16550_s *priv, int offset, uart_datawidth_t value) +static inline void u16550_serialout(FAR struct u16550_s *priv, int offset, + uart_datawidth_t value) { uart_putreg(priv->uartbase, offset, value); } @@ -483,7 +484,8 @@ static inline void u16550_serialout(struct u16550_s *priv, int offset, uart_data ****************************************************************************/ #ifndef CONFIG_SUPPRESS_SERIAL_INTS -static inline void u16550_disableuartint(struct u16550_s *priv, uart_datawidth_t *ier) +static inline void u16550_disableuartint(FAR struct u16550_s *priv, + FAR uart_datawidth_t *ier) { if (ier) { @@ -502,7 +504,7 @@ static inline void u16550_disableuartint(struct u16550_s *priv, uart_datawidth_t ****************************************************************************/ #ifndef CONFIG_SUPPRESS_SERIAL_INTS -static inline void u16550_restoreuartint(struct u16550_s *priv, uint32_t ier) +static inline void u16550_restoreuartint(FAR struct u16550_s *priv, uint32_t ier) { priv->ier |= ier & UART_IER_ALLIE; u16550_serialout(priv, UART_IER_OFFSET, priv->ier); @@ -515,7 +517,7 @@ static inline void u16550_restoreuartint(struct u16550_s *priv, uint32_t ier) * Name: u16550_enablebreaks ****************************************************************************/ -static inline void u16550_enablebreaks(struct u16550_s *priv, bool enable) +static inline void u16550_enablebreaks(FAR struct u16550_s *priv, bool enable) { uint32_t lcr = u16550_serialin(priv, UART_LCR_OFFSET); if (enable) @@ -543,7 +545,7 @@ static inline void u16550_enablebreaks(struct u16550_s *priv, bool enable) ************************************************************************************/ #ifndef CONFIG_16550_SUPRESS_CONFIG -static inline uint32_t u16550_divisor(struct u16550_s *priv) +static inline uint32_t u16550_divisor(FAR struct u16550_s *priv) { return (priv->uartclk + (priv->baud << 3)) / (priv->baud << 4); } @@ -566,17 +568,19 @@ static inline uint32_t u16550_divisor(struct u16550_s *priv) static int u16550_setup(struct uart_dev_s *dev) { #ifndef CONFIG_16550_SUPRESS_CONFIG - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; uint16_t div; uint32_t lcr; /* Clear fifos */ - u16550_serialout(priv, UART_FCR_OFFSET, (UART_FCR_RXRST|UART_FCR_TXRST)); + u16550_serialout(priv, UART_FCR_OFFSET, + (UART_FCR_RXRST | UART_FCR_TXRST)); /* Set trigger */ - u16550_serialout(priv, UART_FCR_OFFSET, (UART_FCR_FIFOEN|UART_FCR_RXTRIGGER_8)); + u16550_serialout(priv, UART_FCR_OFFSET, + (UART_FCR_FIFOEN | UART_FCR_RXTRIGGER_8)); /* Set up the IER */ @@ -618,7 +622,7 @@ static int u16550_setup(struct uart_dev_s *dev) } else if (priv->parity == 2) { - lcr |= (UART_LCR_PEN|UART_LCR_EPS); + lcr |= (UART_LCR_PEN | UART_LCR_EPS); } /* Enter DLAB=1 */ @@ -638,7 +642,8 @@ static int u16550_setup(struct uart_dev_s *dev) /* Configure the FIFOs */ u16550_serialout(priv, UART_FCR_OFFSET, - (UART_FCR_RXTRIGGER_8|UART_FCR_TXRST|UART_FCR_RXRST|UART_FCR_FIFOEN)); + (UART_FCR_RXTRIGGER_8 | UART_FCR_TXRST | UART_FCR_RXRST | + UART_FCR_FIFOEN)); #endif return OK; } @@ -654,7 +659,7 @@ static int u16550_setup(struct uart_dev_s *dev) static void u16550_shutdown(struct uart_dev_s *dev) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; u16550_disableuartint(priv, NULL); } @@ -676,7 +681,7 @@ static void u16550_shutdown(struct uart_dev_s *dev) static int u16550_attach(struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_SERIAL_INTS - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; int ret; /* Attach and enable the IRQ */ @@ -711,7 +716,7 @@ static int u16550_attach(struct uart_dev_s *dev) static void u16550_detach(FAR struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_SERIAL_INTS - FAR struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; #ifndef CONFIG_ARCH_NOINTC up_disable_irq(priv->irq); #endif @@ -767,7 +772,7 @@ static int u16550_interrupt(int irq, void *context) } #endif ASSERT(dev != NULL); - priv = (struct u16550_s*)dev->priv; + priv = (FAR struct u16550_s *)dev->priv; /* Loop until there are no characters to be transferred or, * until we have been looping for a long time. @@ -863,7 +868,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg) { struct inode *inode = filep->f_inode; struct uart_dev_s *dev = inode->i_private; - struct u16550_s *priv = (struct u16550_s*)dev->priv; + struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; #ifdef CONFIG_SERIAL_UART_ARCH_IOCTL int ret = uart_ioctl(filep, cmd, arg); @@ -879,7 +884,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg) #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT case TIOCSERGSTRUCT: { - struct u16550_s *user = (struct u16550_s*)arg; + FAR struct u16550_s *user = (FAR struct u16550_s *)arg; if (!user) { set_errno(EINVAL); @@ -931,7 +936,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg) static int u16550_receive(struct uart_dev_s *dev, uint32_t *status) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; uint32_t rbr; *status = u16550_serialin(priv, UART_LSR_OFFSET); @@ -950,7 +955,7 @@ static int u16550_receive(struct uart_dev_s *dev, uint32_t *status) static void u16550_rxint(struct uart_dev_s *dev, bool enable) { #ifndef CONFIG_SUPPRESS_SERIAL_INTS - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; if (enable) { priv->ier |= UART_IER_ERBFI; @@ -973,7 +978,7 @@ static void u16550_rxint(struct uart_dev_s *dev, bool enable) static bool u16550_rxavailable(struct uart_dev_s *dev) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; return ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_DR) != 0); } @@ -987,7 +992,7 @@ static bool u16550_rxavailable(struct uart_dev_s *dev) static void u16550_send(struct uart_dev_s *dev, int ch) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; u16550_serialout(priv, UART_THR_OFFSET, (uart_datawidth_t)ch); } @@ -1002,7 +1007,7 @@ static void u16550_send(struct uart_dev_s *dev, int ch) static void u16550_txint(struct uart_dev_s *dev, bool enable) { #ifndef CONFIG_SUPPRESS_SERIAL_INTS - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; irqstate_t flags; flags = irqsave(); @@ -1037,7 +1042,7 @@ static void u16550_txint(struct uart_dev_s *dev, bool enable) static bool u16550_txready(struct uart_dev_s *dev) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; return ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_THRE) != 0); } @@ -1051,7 +1056,7 @@ static bool u16550_txready(struct uart_dev_s *dev) static bool u16550_txempty(struct uart_dev_s *dev) { - struct u16550_s *priv = (struct u16550_s*)dev->priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; return ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_THRE) != 0); } @@ -1063,7 +1068,7 @@ static bool u16550_txempty(struct uart_dev_s *dev) * ****************************************************************************/ -static void u16550_putc(struct u16550_s *priv, int ch) +static void u16550_putc(FAR struct u16550_s *priv, int ch) { while ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_THRE) == 0); u16550_serialout(priv, UART_THR_OFFSET, (uart_datawidth_t)ch); @@ -1150,7 +1155,7 @@ void up_serialinit(void) #ifdef HAVE_16550_CONSOLE int up_putc(int ch) { - struct u16550_s *priv = (struct u16550_s*)CONSOLE_DEV.priv; + FAR struct u16550_s *priv = (FAR struct u16550_s *)CONSOLE_DEV.priv; #ifndef CONFIG_SUPPRESS_SERIAL_INTS uart_datawidth_t ier; diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index a06bdcbdd3..299ca4f9e9 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -108,8 +108,10 @@ static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch); /* Character driver methods */ -static ssize_t ramlog_read(FAR struct file *, FAR char *, size_t); -static ssize_t ramlog_write(FAR struct file *, FAR const char *, size_t); +static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); #ifndef CONFIG_DISABLE_POLL static int ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup); @@ -468,7 +470,7 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size /* Then output the character */ - ret = ramlog_addchar(priv,ch); + ret = ramlog_addchar(priv, ch); if (ret < 0) { /* The buffer is full and nothing was saved. Break out of the diff --git a/drivers/syslog/syslog_console.c b/drivers/syslog/syslog_console.c index 6e21231bd6..6d3bb406cf 100644 --- a/drivers/syslog/syslog_console.c +++ b/drivers/syslog/syslog_console.c @@ -130,7 +130,7 @@ static ssize_t syslog_console_write(FAR struct file *filep, /**************************************************************************** * Name: syslog_console_init -****************************************************************************/ + ****************************************************************************/ void syslog_console_init(void) { diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index 76ec3232aa..f8064db33f 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -368,7 +368,7 @@ static int cs2100_refclk(FAR const struct cs2100_config_s *config) /* Set the minimum loop bandwidth */ - DEBUGASSERT(config->loopbw >=1 && config->loopbw <= 128); + DEBUGASSERT(config->loopbw >= 1 && config->loopbw <= 128); if (config->loopbw < 2) { diff --git a/drivers/timers/rtc.c b/drivers/timers/rtc.c index 6d39b6c99a..6c76e449b8 100644 --- a/drivers/timers/rtc.c +++ b/drivers/timers/rtc.c @@ -79,7 +79,8 @@ static int rtc_open(FAR struct file *filep); static int rtc_close(FAR struct file *filep); #endif -static ssize_t rtc_read(FAR struct file *filep, FAR char *, size_t); +static ssize_t rtc_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); static ssize_t rtc_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg); diff --git a/drivers/timers/timer.c b/drivers/timers/timer.c index c1c8a9ee42..4e4e4d94f8 100644 --- a/drivers/timers/timer.c +++ b/drivers/timers/timer.c @@ -84,7 +84,6 @@ struct timer_upperhalf_s { uint8_t crefs; /* The number of times the device has been opened */ -//sem_t exclsem; /* Supports mutual exclusion */ FAR char *path; /* Registration path */ /* The contained lower-half driver */ @@ -143,15 +142,6 @@ static int timer_open(FAR struct file *filep) tmrvdbg("crefs: %d\n", upper->crefs); - /* Get exclusive access to the device structures */ - - ret = 1; //sem_wait(&upper->exclsem); - if (ret < 0) - { - ret = -get_errno(); - goto errout; - } - /* Increment the count of references to the device. If this the first * time that the driver has been opened for this device, then initialize * the device. @@ -163,7 +153,7 @@ static int timer_open(FAR struct file *filep) /* More than 255 opens; uint8_t overflows to zero */ ret = -EMFILE; - goto errout_with_sem; + goto errout; } /* Save the new open count */ @@ -171,9 +161,6 @@ static int timer_open(FAR struct file *filep) upper->crefs = tmp; ret = OK; -errout_with_sem: -// sem_post(&upper->exclsem); - errout: return ret; } @@ -188,21 +175,11 @@ errout: static int timer_close(FAR struct file *filep) { - FAR struct inode *inode = filep->f_inode; + FAR struct inode *inode = filep->f_inode; FAR struct timer_upperhalf_s *upper = inode->i_private; - int ret; tmrvdbg("crefs: %d\n", upper->crefs); - /* Get exclusive access to the device structures */ - - ret = 1; //sem_wait(&upper->exclsem); - if (ret < 0) - { - ret = -get_errno(); - goto errout; - } - /* Decrement the references to the driver. If the reference count will * decrement to 0, then uninitialize the driver. */ @@ -212,11 +189,7 @@ static int timer_close(FAR struct file *filep) upper->crefs--; } - //sem_post(&upper->exclsem); - ret = OK; - -errout: - return ret; + return OK; } /************************************************************************************ @@ -267,14 +240,6 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) tmrvdbg("cmd: %d arg: %ld\n", cmd, arg); DEBUGASSERT(upper && lower); - /* Get exclusive access to the device structures */ - - ret = 1; //sem_wait(&upper->exclsem); - if (ret < 0) - { - return ret; - } - /* Handle built-in ioctl commands */ switch (cmd) @@ -288,7 +253,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { /* Start the timer, resetting the time to the current timeout */ - if(lower->ops->start) + if (lower->ops->start) { ret = lower->ops->start(lower); } @@ -308,7 +273,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { /* Stop the timer */ - if(lower->ops->start) + if (lower->ops->start) { ret = lower->ops->stop(lower); } @@ -435,7 +400,6 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; } - //sem_post(&upper->exclsem); return ret; } @@ -492,7 +456,6 @@ FAR void *timer_register(FAR const char *path, * by kmm_zalloc()). */ - //sem_init(&upper->exclsem, 0, 1); upper->lower = lower; /* Copy the registration path */ @@ -519,7 +482,6 @@ errout_with_path: kmm_free(upper->path); errout_with_upper: - //sem_destroy(&upper->exclsem); kmm_free(upper); errout: @@ -566,7 +528,6 @@ void timer_unregister(FAR void *handle) /* Then free all of the driver resources */ kmm_free(upper->path); - //sem_destroy(&upper->exclsem); kmm_free(upper); } diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index 43cc465815..c5f874ed7d 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -92,7 +92,7 @@ struct cdcacm_dev_s FAR struct usbdev_s *usbdev; /* usbdev driver pointer */ uint8_t config; /* Configuration number */ - uint8_t nwrq; /* Number of queue write requests (in reqlist)*/ + uint8_t nwrq; /* Number of queue write requests (in reqlist) */ uint8_t nrdq; /* Number of queue read requests (in epbulkout) */ uint8_t minor; /* The device minor number */ bool rxenabled; /* true: UART RX "interrupts" enabled */ @@ -201,7 +201,8 @@ static int cdcuart_setup(FAR struct uart_dev_s *dev); static void cdcuart_shutdown(FAR struct uart_dev_s *dev); static int cdcuart_attach(FAR struct uart_dev_s *dev); static void cdcuart_detach(FAR struct uart_dev_s *dev); -static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg); +static int cdcuart_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable); #ifdef CONFIG_SERIAL_IFLOWCONTROL static bool cdcuart_rxflowcontrol(FAR struct uart_dev_s *dev, @@ -829,7 +830,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep, /* Extract references to private data */ - priv = (FAR struct cdcacm_dev_s*)ep->priv; + priv = (FAR struct cdcacm_dev_s *)ep->priv; /* Process the received data unless this is some unusual condition */ @@ -898,7 +899,7 @@ static void cdcacm_wrcomplete(FAR struct usbdev_ep_s *ep, /* Return the write request to the free list */ flags = irqsave(); - sq_addlast((sq_entry_t*)reqcontainer, &priv->reqlist); + sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; irqrestore(flags); @@ -944,7 +945,7 @@ static void cdcacm_wrcomplete(FAR struct usbdev_ep_s *ep, static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) { - FAR struct cdcacm_dev_s *priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + FAR struct cdcacm_dev_s *priv = ((FAR struct cdcacm_driver_s *)driver)->dev; FAR struct cdcacm_req_s *reqcontainer; irqstate_t flags; uint16_t reqlen; @@ -1079,7 +1080,7 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->callback = cdcacm_wrcomplete; flags = irqsave(); - sq_addlast((sq_entry_t*)reqcontainer, &priv->reqlist); + sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; /* Count of write requests available */ irqrestore(flags); } @@ -1132,7 +1133,7 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + priv = ((FAR struct cdcacm_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -1261,7 +1262,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ usbtrace(TRACE_CLASSSETUP, ctrl->req); - priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + priv = ((FAR struct cdcacm_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv || !priv->ctrlreq) @@ -1387,7 +1388,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, { if (ctrl->type == USB_DIR_IN) { - *(uint8_t*)ctrlreq->buf = priv->config; + *(FAR uint8_t *)ctrlreq->buf = priv->config; ret = 1; } } @@ -1412,13 +1413,13 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_GETINTERFACE: { - if (ctrl->type == (USB_DIR_IN|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && priv->config == CDCACM_CONFIGIDNONE) { if ((index == CDCACM_NOTIFID && value == CDCACM_NOTALTIFID) || (index == CDCACM_DATAIFID && value == CDCACM_DATAALTIFID)) { - *(uint8_t*) ctrlreq->buf = value; + *(FAR uint8_t *) ctrlreq->buf = value; ret = 1; } else @@ -1449,7 +1450,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, case ACM_GET_LINE_CODING: { - if (ctrl->type == (USB_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE) && index == CDCACM_NOTIFID) { /* Return the current line status from the private data structure */ @@ -1470,7 +1471,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, case ACM_SET_LINE_CODING: { - if (ctrl->type == (USB_DIR_OUT|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE) && len == SIZEOF_CDC_LINECODING && /* dataout && len == outlen && */ index == CDCACM_NOTIFID) { @@ -1511,7 +1512,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, case ACM_SET_CTRL_LINE_STATE: { - if (ctrl->type == (USB_DIR_OUT|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE) && index == CDCACM_NOTIFID) { /* Save the control line state in the private data structure. Only bits @@ -1537,11 +1538,11 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, } break; - /* Sends special carrier*/ + /* Sends special carrier */ case ACM_SEND_BREAK: { - if (ctrl->type == (USB_DIR_OUT|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE) && index == CDCACM_NOTIFID) { /* If there is a registered callback to handle the SendBreak request, @@ -1633,7 +1634,7 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + priv = ((FAR struct cdcacm_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -1698,7 +1699,7 @@ static void cdcacm_suspend(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + priv = ((FAR struct cdcacm_driver_s *)driver)->dev; /* And let the "upper half" driver now that we are suspended */ @@ -1732,7 +1733,7 @@ static void cdcacm_resume(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + priv = ((FAR struct cdcacm_driver_s *)driver)->dev; /* Are we still configured? */ @@ -1775,7 +1776,7 @@ static int cdcuart_setup(FAR struct uart_dev_s *dev) /* Extract reference to private data */ - priv = (FAR struct cdcacm_dev_s*)dev->priv; + priv = (FAR struct cdcacm_dev_s *)dev->priv; /* Check if we have been configured */ @@ -1832,8 +1833,8 @@ static int cdcuart_attach(FAR struct uart_dev_s *dev) * Name: cdcuart_detach * * Description: -* Does not apply to the USB serial class device - * + * Does not apply to the USB serial class device + * ****************************************************************************/ static void cdcuart_detach(FAR struct uart_dev_s *dev) @@ -1849,7 +1850,7 @@ static void cdcuart_detach(FAR struct uart_dev_s *dev) * ****************************************************************************/ -static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg) +static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { struct inode *inode = filep->f_inode; struct cdcacm_dev_s *priv = inode->i_private; @@ -1933,7 +1934,7 @@ static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg) * 1. Format and send a request header with: * * bmRequestType: - * USB_REQ_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE + * USB_REQ_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE * bRequest: ACM_SERIAL_STATE * wValue: 0 * wIndex: 0 @@ -1949,7 +1950,7 @@ static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg) #ifdef CONFIG_SERIAL_TERMIOS case TCGETS: { - struct termios *termiosp = (struct termios*)arg; + struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -1967,7 +1968,7 @@ static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg) case TCSETS: { - struct termios *termiosp = (struct termios*)arg; + struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -2075,7 +2076,7 @@ static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable) /* Extract reference to private data */ - priv = (FAR struct cdcacm_dev_s*)dev->priv; + priv = (FAR struct cdcacm_dev_s *)dev->priv; serdev = &priv->serdev; /* We need exclusive access to the RX buffer and private structure @@ -2085,19 +2086,19 @@ static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable) flags = irqsave(); if (enable) { - /* RX "interrupts" are enabled. Is this a transition from disabled - * to enabled state? - */ + /* RX "interrupts" are enabled. Is this a transition from disabled + * to enabled state? + */ - if (!priv->rxenabled) - { - /* Yes. During the time that RX interrupts are disabled, the - * the serial driver will be extracting data from the circular - * buffer and modifying recv.tail. During this time, we - * should avoid modifying recv.head; When interrupts are restored, - * we can update the head pointer for all of the data that we - * put into circular buffer while "interrupts" were disabled. - */ + if (!priv->rxenabled) + { + /* Yes. During the time that RX interrupts are disabled, the + * the serial driver will be extracting data from the circular + * buffer and modifying recv.tail. During this time, we + * should avoid modifying recv.head; When interrupts are restored, + * we can update the head pointer for all of the data that we + * put into circular buffer while "interrupts" were disabled. + */ if (priv->rxhead != serdev->recv.head) { @@ -2204,7 +2205,7 @@ static void cdcuart_txint(FAR struct uart_dev_s *dev, bool enable) /* Extract references to private data */ - priv = (FAR struct cdcacm_dev_s*)dev->priv; + priv = (FAR struct cdcacm_dev_s *)dev->priv; /* If the new state is enabled and if there is data in the XMIT buffer, * send the next packet now. @@ -2233,7 +2234,7 @@ static void cdcuart_txint(FAR struct uart_dev_s *dev, bool enable) static bool cdcuart_txempty(FAR struct uart_dev_s *dev) { - FAR struct cdcacm_dev_s *priv = (FAR struct cdcacm_dev_s*)dev->priv; + FAR struct cdcacm_dev_s *priv = (FAR struct cdcacm_dev_s *)dev->priv; usbtrace(CDCACM_CLASSAPI_TXEMPTY, 0); @@ -2287,7 +2288,7 @@ int cdcacm_classobject(int minor, FAR struct usbdevclass_driver_s **classdev) /* Allocate the structures needed */ - alloc = (FAR struct cdcacm_alloc_s*)kmm_malloc(sizeof(struct cdcacm_alloc_s)); + alloc = (FAR struct cdcacm_alloc_s *)kmm_malloc(sizeof(struct cdcacm_alloc_s)); if (!alloc) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCDEVSTRUCT), 0); @@ -2414,7 +2415,7 @@ int cdcacm_initialize(int minor, FAR void **handle) if (handle) { - *handle = (FAR void*)drvr; + *handle = (FAR void *)drvr; } return ret; diff --git a/drivers/usbdev/cdcacm_desc.c b/drivers/usbdev/cdcacm_desc.c index a2d2446ad4..221734a71e 100644 --- a/drivers/usbdev/cdcacm_desc.c +++ b/drivers/usbdev/cdcacm_desc.c @@ -602,7 +602,7 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf) { cdcacm_cpepdesc((FAR const struct usb_epdesc_s *)group->desc, group->hsepsize, - (FAR struct usb_epdesc_s*)dest); + (FAR struct usb_epdesc_s *)dest); } else #endif diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index e23f3c20f6..1cc35aab89 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -267,7 +267,7 @@ static void composite_freereq(FAR struct usbdev_ep_s *ep, static int composite_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) { - FAR struct composite_dev_s *priv = ((FAR struct composite_driver_s*)driver)->dev; + FAR struct composite_dev_s *priv = ((FAR struct composite_driver_s *)driver)->dev; int ret; usbtrace(TRACE_CLASSBIND, 0); @@ -352,7 +352,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct composite_driver_s*)driver)->dev; + priv = ((FAR struct composite_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -417,7 +417,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, /* Extract a reference to private data */ usbtrace(TRACE_CLASSSETUP, ctrl->req); - priv = ((FAR struct composite_driver_s*)driver)->dev; + priv = ((FAR struct composite_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -562,7 +562,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_GETINTERFACE: { - if (ctrl->type == (USB_DIR_IN|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && priv->config == COMPOSITE_CONFIGIDNONE) { ret = composite_classsetup(priv, dev, ctrl, dataout, outlen); @@ -651,7 +651,7 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct composite_driver_s*)driver)->dev; + priv = ((FAR struct composite_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -704,7 +704,7 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct composite_driver_s*)driver)->dev; + priv = ((FAR struct composite_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -746,7 +746,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct composite_driver_s*)driver)->dev; + priv = ((FAR struct composite_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -798,7 +798,7 @@ FAR void *composite_initialize(void) /* Allocate the structures needed */ - alloc = (FAR struct composite_alloc_s*)kmm_malloc(sizeof(struct composite_alloc_s)); + alloc = (FAR struct composite_alloc_s *)kmm_malloc(sizeof(struct composite_alloc_s)); if (!alloc) { usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCDEVSTRUCT), 0); diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index b978dfb349..8848905487 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -256,7 +256,7 @@ struct pl2303_dev_s FAR struct usbdev_s *usbdev; /* usbdev driver pointer */ uint8_t config; /* Configuration number */ - uint8_t nwrq; /* Number of queue write requests (in reqlist)*/ + uint8_t nwrq; /* Number of queue write requests (in reqlist) */ uint8_t nrdq; /* Number of queue read requests (in epbulkout) */ bool rxenabled; /* true: UART RX "interrupts" enabled */ uint8_t linest[7]; /* Fake line status */ @@ -926,7 +926,7 @@ static int16_t usbclass_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type) static int16_t usbclass_mkcfgdesc(uint8_t *buf) #endif { - FAR struct usb_cfgdesc_s *cfgdesc = (struct usb_cfgdesc_s*)buf; + FAR struct usb_cfgdesc_s *cfgdesc = (FAR struct usb_cfgdesc_s *)buf; #ifdef CONFIG_USBDEV_DUALSPEED bool hispeed = (speed == USB_SPEED_HIGH); uint16_t bulkmxpacket; @@ -975,9 +975,9 @@ static int16_t usbclass_mkcfgdesc(uint8_t *buf) bulkmxpacket = 64; } - usbclass_mkepbulkdesc(&g_epbulkoutdesc, bulkmxpacket, (struct usb_epdesc_s*)buf); + usbclass_mkepbulkdesc(&g_epbulkoutdesc, bulkmxpacket, (FAR struct usb_epdesc_s *)buf); buf += USB_SIZEOF_EPDESC; - usbclass_mkepbulkdesc(&g_epbulkindesc, bulkmxpacket, (struct usb_epdesc_s*)buf); + usbclass_mkepbulkdesc(&g_epbulkindesc, bulkmxpacket, (FAR struct usb_epdesc_s *)buf); #else memcpy(buf, &g_epbulkoutdesc, USB_SIZEOF_EPDESC); buf += USB_SIZEOF_EPDESC; @@ -1212,7 +1212,7 @@ static void usbclass_rdcomplete(FAR struct usbdev_ep_s *ep, /* Extract references to private data */ - priv = (FAR struct pl2303_dev_s*)ep->priv; + priv = (FAR struct pl2303_dev_s *)ep->priv; /* Process the received data unless this is some unusual condition */ @@ -1280,7 +1280,7 @@ static void usbclass_wrcomplete(FAR struct usbdev_ep_s *ep, /* Return the write request to the free list */ flags = irqsave(); - sq_addlast((sq_entry_t*)reqcontainer, &priv->reqlist); + sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; irqrestore(flags); @@ -1320,7 +1320,7 @@ static void usbclass_wrcomplete(FAR struct usbdev_ep_s *ep, static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) { - FAR struct pl2303_dev_s *priv = ((FAR struct pl2303_driver_s*)driver)->dev; + FAR struct pl2303_dev_s *priv = ((FAR struct pl2303_driver_s *)driver)->dev; FAR struct pl2303_req_s *reqcontainer; irqstate_t flags; uint16_t reqlen; @@ -1449,7 +1449,7 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->callback = usbclass_wrcomplete; flags = irqsave(); - sq_addlast((sq_entry_t*)reqcontainer, &priv->reqlist); + sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; /* Count of write requests available */ irqrestore(flags); } @@ -1498,7 +1498,7 @@ static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct pl2303_driver_s*)driver)->dev; + priv = ((FAR struct pl2303_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -1626,7 +1626,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ usbtrace(TRACE_CLASSSETUP, ctrl->req); - priv = ((FAR struct pl2303_driver_s*)driver)->dev; + priv = ((FAR struct pl2303_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv || !priv->ctrlreq) @@ -1722,7 +1722,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, { if (ctrl->type == USB_DIR_IN) { - *(uint8_t*)ctrlreq->buf = priv->config; + *(FAR uint8_t *)ctrlreq->buf = priv->config; ret = 1; } } @@ -1746,7 +1746,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_GETINTERFACE: { - if (ctrl->type == (USB_DIR_IN|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && priv->config == PL2303_CONFIGIDNONE) { if (index != PL2303_INTERFACEID) @@ -1755,7 +1755,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, } else { - *(uint8_t*) ctrlreq->buf = PL2303_ALTINTERFACEID; + *(FAR uint8_t *) ctrlreq->buf = PL2303_ALTINTERFACEID; ret = 1; } } @@ -1817,7 +1817,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, { if ((ctrl->type & USB_DIR_IN) != 0) { - *(uint32_t*)ctrlreq->buf = 0xdeadbeef; + *(FAR uint32_t *)ctrlreq->buf = 0xdeadbeef; ret = 4; } else @@ -1886,7 +1886,7 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct pl2303_driver_s*)driver)->dev; + priv = ((FAR struct pl2303_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -1949,7 +1949,7 @@ static void usbclass_suspend(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct pl2303_driver_s*)driver)->dev; + priv = ((FAR struct pl2303_driver_s *)driver)->dev; /* And let the "upper half" driver now that we are suspended */ @@ -1983,7 +1983,7 @@ static void usbclass_resume(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct pl2303_driver_s*)driver)->dev; + priv = ((FAR struct pl2303_driver_s *)driver)->dev; /* Are we still configured? */ @@ -2026,7 +2026,7 @@ static int usbser_setup(FAR struct uart_dev_s *dev) /* Extract reference to private data */ - priv = (FAR struct pl2303_dev_s*)dev->priv; + priv = (FAR struct pl2303_dev_s *)dev->priv; /* Check if we have been configured */ @@ -2083,8 +2083,8 @@ static int usbser_attach(FAR struct uart_dev_s *dev) * Name: usbser_detach * * Description: -* Does not apply to the USB serial class device - * + * Does not apply to the USB serial class device + * ****************************************************************************/ static void usbser_detach(FAR struct uart_dev_s *dev) @@ -2129,7 +2129,7 @@ static void usbser_rxint(FAR struct uart_dev_s *dev, bool enable) /* Extract reference to private data */ - priv = (FAR struct pl2303_dev_s*)dev->priv; + priv = (FAR struct pl2303_dev_s *)dev->priv; serdev = &priv->serdev; /* We need exclusive access to the RX buffer and private structure @@ -2139,19 +2139,19 @@ static void usbser_rxint(FAR struct uart_dev_s *dev, bool enable) flags = irqsave(); if (enable) { - /* RX "interrupts" are enabled. Is this a transition from disabled - * to enabled state? - */ + /* RX "interrupts" are enabled. Is this a transition from disabled + * to enabled state? + */ - if (!priv->rxenabled) - { - /* Yes. During the time that RX interrupts are disabled, the - * the serial driver will be extracting data from the circular - * buffer and modifying recv.tail. During this time, we - * should avoid modifying recv.head; When interrupts are restored, - * we can update the head pointer for all of the data that we - * put into cicular buffer while "interrupts" were disabled. - */ + if (!priv->rxenabled) + { + /* Yes. During the time that RX interrupts are disabled, the + * the serial driver will be extracting data from the circular + * buffer and modifying recv.tail. During this time, we + * should avoid modifying recv.head; When interrupts are restored, + * we can update the head pointer for all of the data that we + * put into cicular buffer while "interrupts" were disabled. + */ if (priv->rxhead != serdev->recv.head) { @@ -2220,7 +2220,7 @@ static void usbser_txint(FAR struct uart_dev_s *dev, bool enable) /* Extract references to private data */ - priv = (FAR struct pl2303_dev_s*)dev->priv; + priv = (FAR struct pl2303_dev_s *)dev->priv; /* If the new state is enabled and if there is data in the XMIT buffer, * send the next packet now. @@ -2249,7 +2249,7 @@ static void usbser_txint(FAR struct uart_dev_s *dev, bool enable) static bool usbser_txempty(FAR struct uart_dev_s *dev) { - FAR struct pl2303_dev_s *priv = (FAR struct pl2303_dev_s*)dev->priv; + FAR struct pl2303_dev_s *priv = (FAR struct pl2303_dev_s *)dev->priv; usbtrace(PL2303_CLASSAPI_TXEMPTY, 0); @@ -2290,7 +2290,7 @@ int usbdev_serialinitialize(int minor) /* Allocate the structures needed */ - alloc = (FAR struct pl2303_alloc_s*)kmm_malloc(sizeof(struct pl2303_alloc_s)); + alloc = (FAR struct pl2303_alloc_s *)kmm_malloc(sizeof(struct pl2303_alloc_s)); if (!alloc) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCDEVSTRUCT), 0); @@ -2315,7 +2315,7 @@ int usbdev_serialinitialize(int minor) priv->linest[3] = (115200 >> 24) & 0xff; priv->linest[4] = 0; /* One stop bit */ priv->linest[5] = 0; /* No parity */ - priv->linest[6] = 8; /*8 data bits */ + priv->linest[6] = 8; /* 8 data bits */ /* Initialize the serial driver sub-structure */ diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 6a6d425b04..9e502e4e10 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -255,7 +255,7 @@ static void usbmsc_freereq(FAR struct usbdev_ep_s *ep, struct usbdev_req_s *req) static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) { - FAR struct usbmsc_dev_s *priv = ((FAR struct usbmsc_driver_s*)driver)->dev; + FAR struct usbmsc_dev_s *priv = ((FAR struct usbmsc_driver_s *)driver)->dev; FAR struct usbmsc_req_s *reqcontainer; irqstate_t flags; int ret = OK; @@ -361,7 +361,7 @@ static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->callback = usbmsc_wrcomplete; flags = irqsave(); - sq_addlast((sq_entry_t*)reqcontainer, &priv->wrreqlist); + sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->wrreqlist); irqrestore(flags); } @@ -413,7 +413,7 @@ static void usbmsc_unbind(FAR struct usbdevclass_driver_s *driver, /* Extract reference to private data */ - priv = ((FAR struct usbmsc_driver_s*)driver)->dev; + priv = ((FAR struct usbmsc_driver_s *)driver)->dev; #ifdef CONFIG_DEBUG if (!priv) @@ -699,7 +699,7 @@ static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_GETINTERFACE: { - if (ctrl->type == (USB_DIR_IN|USB_REQ_RECIPIENT_INTERFACE) && + if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && priv->config == USBMSC_CONFIGIDNONE) { if (index != USBMSC_INTERFACEID) @@ -1083,13 +1083,13 @@ void usbmsc_wrcomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) /* Extract references to private data */ - priv = (FAR struct usbmsc_dev_s*)ep->priv; + priv = (FAR struct usbmsc_dev_s *)ep->priv; privreq = (FAR struct usbmsc_req_s *)req->priv; /* Return the write request to the free list */ flags = irqsave(); - sq_addlast((sq_entry_t*)privreq, &priv->wrreqlist); + sq_addlast((FAR sq_entry_t *)privreq, &priv->wrreqlist); irqrestore(flags); /* Process the received data unless this is some unusual condition */ @@ -1144,7 +1144,7 @@ void usbmsc_rdcomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) /* Extract references to private data */ - priv = (FAR struct usbmsc_dev_s*)ep->priv; + priv = (FAR struct usbmsc_dev_s *)ep->priv; privreq = (FAR struct usbmsc_req_s *)req->priv; /* Process the received data unless this is some unusual condition */ @@ -1158,7 +1158,7 @@ void usbmsc_rdcomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) /* Add the filled read request from the rdreqlist */ flags = irqsave(); - sq_addlast((sq_entry_t*)privreq, &priv->rdreqlist); + sq_addlast((FAR sq_entry_t *)privreq, &priv->rdreqlist); irqrestore(flags); /* Signal the worker thread that there is received data to be processed */ @@ -1326,7 +1326,7 @@ int usbmsc_configure(unsigned int nluns, void **handle) /* Allocate the structures needed */ - alloc = (FAR struct usbmsc_alloc_s*)kmm_malloc(sizeof(struct usbmsc_alloc_s)); + alloc = (FAR struct usbmsc_alloc_s *)kmm_malloc(sizeof(struct usbmsc_alloc_s)); if (!alloc) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCDEVSTRUCT), 0); @@ -1347,7 +1347,9 @@ int usbmsc_configure(unsigned int nluns, void **handle) /* Allocate the LUN table */ - priv->luntab = (struct usbmsc_lun_s*)kmm_malloc(priv->nluns*sizeof(struct usbmsc_lun_s)); + priv->luntab = (FAR struct usbmsc_lun_s *) + kmm_malloc(priv->nluns*sizeof(struct usbmsc_lun_s)); + if (!priv->luntab) { ret = -ENOMEM; @@ -1369,7 +1371,7 @@ int usbmsc_configure(unsigned int nluns, void **handle) /* Return the handle and success */ - *handle = (FAR void*)alloc; + *handle = (FAR void *)alloc; return OK; errout: @@ -1489,7 +1491,7 @@ int usbmsc_bindlun(FAR void *handle, FAR const char *drvrpath, if (!priv->iobuffer) { - priv->iobuffer = (uint8_t*)kmm_malloc(geo.geo_sectorsize); + priv->iobuffer = (FAR uint8_t *)kmm_malloc(geo.geo_sectorsize); if (!priv->iobuffer) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCIOBUFFER), geo.geo_sectorsize); @@ -1501,14 +1503,14 @@ int usbmsc_bindlun(FAR void *handle, FAR const char *drvrpath, else if (priv->iosize < geo.geo_sectorsize) { void *tmp; - tmp = (uint8_t*)kmm_realloc(priv->iobuffer, geo.geo_sectorsize); + tmp = (FAR uint8_t *)kmm_realloc(priv->iobuffer, geo.geo_sectorsize); if (!tmp) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_REALLOCIOBUFFER), geo.geo_sectorsize); return -ENOMEM; } - priv->iobuffer = (uint8_t*)tmp; + priv->iobuffer = (FAR uint8_t *)tmp; priv->iosize = geo.geo_sectorsize; } @@ -1701,7 +1703,6 @@ errout_with_lock: * * Returned Value: * 0 on success; a negated errno on failure - * ****************************************************************************/ diff --git a/drivers/usbdev/usbmsc_scsi.c b/drivers/usbdev/usbmsc_scsi.c index 97b489b523..75e958cebe 100644 --- a/drivers/usbdev/usbmsc_scsi.c +++ b/drivers/usbdev/usbmsc_scsi.c @@ -482,7 +482,7 @@ static inline int usbmsc_cmdrequestsense(FAR struct usbmsc_dev_s *priv, memset(response, 0, SCSIRESP_FIXEDSENSEDATA_SIZEOF); - response->code = SCSIRESP_SENSEDATA_RESPVALID|SCSIRESP_SENSEDATA_CURRENTFIXED; + response->code = SCSIRESP_SENSEDATA_RESPVALID | SCSIRESP_SENSEDATA_CURRENTFIXED; response->flags = (uint8_t)(sd >> 16); usbmsc_putbe32(response->info, sdinfo); response->len = SCSIRESP_FIXEDSENSEDATA_SIZEOF - 7; @@ -506,7 +506,7 @@ static inline int usbmsc_cmdrequestsense(FAR struct usbmsc_dev_s *priv, static inline int usbmsc_cmdread6(FAR struct usbmsc_dev_s *priv) { - FAR struct scsicmd_read6_s *read6 = (FAR struct scsicmd_read6_s*)priv->cdb; + FAR struct scsicmd_read6_s *read6 = (FAR struct scsicmd_read6_s *)priv->cdb; FAR struct usbmsc_lun_s *lun = priv->lun; int ret; @@ -647,7 +647,7 @@ static inline int usbmsc_cmdinquiry(FAR struct usbmsc_dev_s *priv, { if (!priv->lun) { - response->qualtype = SCSIRESP_INQUIRYPQ_NOTCAPABLE|SCSIRESP_INQUIRYPD_UNKNOWN; + response->qualtype = SCSIRESP_INQUIRYPQ_NOTCAPABLE | SCSIRESP_INQUIRYPD_UNKNOWN; } else if ((inquiry->flags != 0) || (inquiry->pagecode != 0)) { @@ -994,7 +994,7 @@ static int inline usbmsc_cmdreadcapacity10(FAR struct usbmsc_dev_s *priv, static inline int usbmsc_cmdread10(FAR struct usbmsc_dev_s *priv) { - struct scsicmd_read10_s *read10 = (struct scsicmd_read10_s*)priv->cdb; + struct scsicmd_read10_s *read10 = (struct scsicmd_read10_s *)priv->cdb; FAR struct usbmsc_lun_s *lun = priv->lun; int ret; @@ -1009,7 +1009,7 @@ static inline int usbmsc_cmdread10(FAR struct usbmsc_dev_s *priv) /* Verify that we can support this read command */ - if ((read10->flags & ~(SCSICMD_READ10FLAGS_DPO|SCSICMD_READ10FLAGS_FUA)) != 0) + if ((read10->flags & ~(SCSICMD_READ10FLAGS_DPO | SCSICMD_READ10FLAGS_FUA)) != 0) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_READ10FLAGS), 0); lun->sd = SCSI_KCQIR_INVALIDFIELDINCBA; @@ -1071,7 +1071,7 @@ static inline int usbmsc_cmdwrite10(FAR struct usbmsc_dev_s *priv) /* Verify that we can support this write command */ - if ((write10->flags & ~(SCSICMD_WRITE10FLAGS_DPO|SCSICMD_WRITE10FLAGS_FUA)) != 0) + if ((write10->flags & ~(SCSICMD_WRITE10FLAGS_DPO | SCSICMD_WRITE10FLAGS_FUA)) != 0) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRITE10FLAGS), 0); lun->sd = SCSI_KCQIR_INVALIDFIELDINCBA; @@ -1315,7 +1315,7 @@ static int inline usbmsc_cmdmodesense10(FAR struct usbmsc_dev_s *priv, static inline int usbmsc_cmdread12(FAR struct usbmsc_dev_s *priv) { - struct scsicmd_read12_s *read12 = (struct scsicmd_read12_s*)priv->cdb; + struct scsicmd_read12_s *read12 = (struct scsicmd_read12_s *)priv->cdb; FAR struct usbmsc_lun_s *lun = priv->lun; int ret; @@ -1330,7 +1330,7 @@ static inline int usbmsc_cmdread12(FAR struct usbmsc_dev_s *priv) /* Verify that we can support this read command */ - if ((read12->flags & ~(SCSICMD_READ12FLAGS_DPO|SCSICMD_READ12FLAGS_FUA)) != 0) + if ((read12->flags & ~(SCSICMD_READ12FLAGS_DPO | SCSICMD_READ12FLAGS_FUA)) != 0) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_READ12FLAGS), 0); lun->sd = SCSI_KCQIR_INVALIDFIELDINCBA; @@ -1392,7 +1392,7 @@ static inline int usbmsc_cmdwrite12(FAR struct usbmsc_dev_s *priv) /* Verify that we can support this write command */ - if ((write12->flags & ~(SCSICMD_WRITE12FLAGS_DPO|SCSICMD_WRITE12FLAGS_FUA)) != 0) + if ((write12->flags & ~(SCSICMD_WRITE12FLAGS_DPO | SCSICMD_WRITE12FLAGS_FUA)) != 0) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRITE12FLAGS), 0); lun->sd = SCSI_KCQIR_INVALIDFIELDINCBA; @@ -1652,7 +1652,7 @@ static int usbmsc_idlestate(FAR struct usbmsc_dev_s *priv) /* Handle the CBW */ - usbmsc_dumpdata("SCSCI CBW", (uint8_t*)cbw, USBMSC_CBW_SIZEOF - USBMSC_MAXCDBLEN); + usbmsc_dumpdata("SCSCI CBW", (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF - USBMSC_MAXCDBLEN); usbmsc_dumpdata(" CDB", cbw->cdb, MIN(cbw->cdblen, USBMSC_MAXCDBLEN)); /* Check for properly formatted CBW? */ @@ -2541,7 +2541,7 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv) } req = privreq->req; - csw = (struct usbmsc_csw_s*)req->buf; + csw = (FAR struct usbmsc_csw_s *)req->buf; /* Extract the sense data from the LUN structure */ @@ -2578,7 +2578,7 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv) usbmsc_putle32(csw->residue, priv->residue); csw->status = status; - usbmsc_dumpdata("SCSCI CSW", (uint8_t*)csw, USBMSC_CSW_SIZEOF); + usbmsc_dumpdata("SCSCI CSW", (FAR uint8_t *)csw, USBMSC_CSW_SIZEOF); req->len = USBMSC_CSW_SIZEOF; req->callback = usbmsc_wrcomplete; @@ -2590,7 +2590,7 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_SNDSTATUSSUBMIT), (uint16_t)-ret); flags = irqsave(); - (void)sq_addlast((sq_entry_t*)privreq, &priv->wrreqlist); + (void)sq_addlast((FAR sq_entry_t *)privreq, &priv->wrreqlist); irqrestore(flags); } @@ -2701,8 +2701,8 @@ int usbmsc_scsi_main(int argc, char *argv[]) * drive the state machine. */ - if ((eventset & (USBMSC_EVENT_DISCONNECT|USBMSC_EVENT_RESET|USBMSC_EVENT_CFGCHANGE| - USBMSC_EVENT_IFCHANGE|USBMSC_EVENT_ABORTBULKOUT)) != 0) + if ((eventset & (USBMSC_EVENT_DISCONNECT | USBMSC_EVENT_RESET | USBMSC_EVENT_CFGCHANGE | + USBMSC_EVENT_IFCHANGE | USBMSC_EVENT_ABORTBULKOUT)) != 0) { /* These events require that the current configuration be reset */ @@ -2720,7 +2720,7 @@ int usbmsc_scsi_main(int argc, char *argv[]) /* These events required that we send a deferred EP0 setup response */ - if ((eventset & (USBMSC_EVENT_RESET|USBMSC_EVENT_CFGCHANGE|USBMSC_EVENT_IFCHANGE)) != 0) + if ((eventset & (USBMSC_EVENT_RESET | USBMSC_EVENT_CFGCHANGE | USBMSC_EVENT_IFCHANGE)) != 0) { usbmsc_deferredresponse(priv, false); } diff --git a/drivers/usbhost/usbhost_cdcacm.c b/drivers/usbhost/usbhost_cdcacm.c index eb3fe49cd5..54b1c58042 100644 --- a/drivers/usbhost/usbhost_cdcacm.c +++ b/drivers/usbhost/usbhost_cdcacm.c @@ -511,7 +511,7 @@ static FAR struct usbhost_cdcacm_s *usbhost_allocclass(void) } irqrestore(flags); - uvdbg("Allocated: %p\n", entry);; + uvdbg("Allocated: %p\n", entry); return (FAR struct usbhost_cdcacm_s *)entry; } #else @@ -525,7 +525,7 @@ static FAR struct usbhost_cdcacm_s *usbhost_allocclass(void) DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_cdcacm_s *)kmm_malloc(sizeof(struct usbhost_cdcacm_s)); - uvdbg("Allocated: %p\n", priv);; + uvdbg("Allocated: %p\n", priv); return priv; } #endif @@ -569,7 +569,7 @@ static void usbhost_freeclass(FAR struct usbhost_cdcacm_s *usbclass) * from an interrupt handler. */ - uvdbg("Freeing: %p\n", usbclass);; + uvdbg("Freeing: %p\n", usbclass); sched_kfree(usbclass); } #endif @@ -850,8 +850,8 @@ static void usbhost_notification_callback(FAR void *arg, ssize_t nbytes) delay = USBHOST_CDCACM_NTDELAY; } - /* Make sure that the work structure available. There is a remote - * chance that this may collide with a device disconnection event. + /* Make sure that the work structure available. There is a remote + * chance that this may collide with a device disconnection event. */ if (work_available(&priv->ntwork)) @@ -1333,7 +1333,7 @@ static int usbhost_cfgdesc(FAR struct usbhost_cdcacm_s *priv, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); @@ -1723,11 +1723,11 @@ static int usbhost_alloc_buffers(FAR struct usbhost_cdcacm_s *priv) /* Allocate buffer for sending line coding data. */ ret = DRVR_IOALLOC(hport->drvr, &priv->linecode, - sizeof( struct cdc_linecoding_s)); + sizeof(struct cdc_linecoding_s)); if (ret < 0) { udbg("ERROR: DRVR_IOALLOC of line coding failed: %d (%d bytes)\n", - ret, sizeof( struct cdc_linecoding_s)); + ret, sizeof(struct cdc_linecoding_s)); goto errout; } @@ -2386,7 +2386,7 @@ static int usbhost_ioctl(FAR struct file *filep, int cmd, unsigned long arg) #ifdef CONFIG_SERIAL_TERMIOS case TCGETS: { - FAR struct termios *termiosp = (FAR struct termios*)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -2432,7 +2432,7 @@ static int usbhost_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case TCSETS: { - FAR struct termios *termiosp = (FAR struct termios*)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; #ifdef CONFIG_SERIAL_IFLOWCONTROL bool iflow; #endif diff --git a/drivers/usbhost/usbhost_devaddr.c b/drivers/usbhost/usbhost_devaddr.c index 83392d0ed4..e26513c540 100644 --- a/drivers/usbhost/usbhost_devaddr.c +++ b/drivers/usbhost/usbhost_devaddr.c @@ -101,7 +101,7 @@ static int usbhost_devaddr_allocate(FAR struct usbhost_devaddr_s *devgen) /* Loop until we find a valid device address */ - for (;;) + for (; ; ) { /* Try the next device address */ diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index d7a49fd671..5e820acb66 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -663,7 +663,7 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_state_s *)kmm_malloc(sizeof(struct usbhost_state_s)); - uvdbg("Allocated: %p\n", priv);; + uvdbg("Allocated: %p\n", priv); return priv; } @@ -687,7 +687,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) /* Free the class instance. */ - uvdbg("Freeing: %p\n", usbclass);; + uvdbg("Freeing: %p\n", usbclass); sched_kfree(usbclass); } @@ -921,7 +921,7 @@ static inline uint8_t usbhost_mapscancode(uint8_t scancode, uint8_t modifier) /* Is either shift key pressed? */ - if ((modifier & (USBHID_MODIFER_LSHIFT|USBHID_MODIFER_RSHIFT)) != 0) + if ((modifier & (USBHID_MODIFER_LSHIFT | USBHID_MODIFER_RSHIFT)) != 0) { return ucmap[scancode]; } @@ -1062,7 +1062,7 @@ static int usbhost_kbdpoll(int argc, char *argv[]) */ ctrlreq = (struct usb_ctrlreq_s *)priv->tbuffer; - ctrlreq->type = USB_REQ_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE; + ctrlreq->type = USB_REQ_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; ctrlreq->req = USBHID_REQUEST_GETREPORT; usbhost_putle16(ctrlreq->value, (USBHID_REPORTTYPE_INPUT << 8)); @@ -1155,7 +1155,7 @@ static int usbhost_kbdpoll(int argc, char *argv[]) * a valid, NUL character. */ - if ((rpt->modifier & (USBHID_MODIFER_LCTRL|USBHID_MODIFER_RCTRL)) != 0) + if ((rpt->modifier & (USBHID_MODIFER_LCTRL | USBHID_MODIFER_RCTRL)) != 0) { keycode &= 0x1f; } @@ -1363,7 +1363,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index 0befef80af..86a7bda2de 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -523,7 +523,7 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_state_s *)kmm_malloc(sizeof(struct usbhost_state_s)); - uvdbg("Allocated: %p\n", priv);; + uvdbg("Allocated: %p\n", priv); return priv; } @@ -547,7 +547,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) /* Free the class instance. */ - uvdbg("Freeing: %p\n", usbclass);; + uvdbg("Freeing: %p\n", usbclass); sched_kfree(usbclass); } @@ -1300,7 +1300,7 @@ static int usbhost_sample(FAR struct usbhost_state_s *priv, { /* Return a copy of the sampled data. */ - memcpy(sample, &priv->sample, sizeof(struct mouse_sample_s )); + memcpy(sample, &priv->sample, sizeof(struct mouse_sample_s)); #ifdef CONFIG_HIDMOUSE_TSCIF /* Now manage state transitions */ @@ -1405,7 +1405,7 @@ static int usbhost_waitsample(FAR struct usbhost_state_s *priv, ivdbg("Sampled\n"); - /* Re-acquire the semaphore that manages mutually exclusive access to + /* Re-acquire the semaphore that manages mutually exclusive access to * the device structure. We may have to wait here. But we have our sample. * Interrupts and pre-emption will be re-enabled while we wait. */ @@ -1484,7 +1484,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); diff --git a/drivers/usbhost/usbhost_hub.c b/drivers/usbhost/usbhost_hub.c index 7c98230c2e..170629987b 100644 --- a/drivers/usbhost/usbhost_hub.c +++ b/drivers/usbhost/usbhost_hub.c @@ -356,7 +356,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); diff --git a/drivers/usbhost/usbhost_skeleton.c b/drivers/usbhost/usbhost_skeleton.c index cb30aff9ec..7b39360458 100644 --- a/drivers/usbhost/usbhost_skeleton.c +++ b/drivers/usbhost/usbhost_skeleton.c @@ -250,7 +250,7 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_state_s *)kmm_malloc(sizeof(struct usbhost_state_s)); - uvdbg("Allocated: %p\n", priv);; + uvdbg("Allocated: %p\n", priv); return priv; } @@ -276,7 +276,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) * executing from an interrupt handler. */ - uvdbg("Freeing: %p\n", usbclass);; + uvdbg("Freeing: %p\n", usbclass); kmm_free(usbclass); } @@ -438,7 +438,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); diff --git a/drivers/usbhost/usbhost_storage.c b/drivers/usbhost/usbhost_storage.c index 288ad99e5e..b314bd7294 100644 --- a/drivers/usbhost/usbhost_storage.c +++ b/drivers/usbhost/usbhost_storage.c @@ -376,7 +376,7 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) } irqrestore(flags); - ullvdbg("Allocated: %p\n", entry);; + ullvdbg("Allocated: %p\n", entry); return (FAR struct usbhost_state_s *)entry; } #else @@ -390,7 +390,7 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_state_s *)kmm_malloc(sizeof(struct usbhost_state_s)); - uvdbg("Allocated: %p\n", priv);; + uvdbg("Allocated: %p\n", priv); return priv; } #endif @@ -434,7 +434,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) * from an interrupt handler. */ - uvdbg("Freeing: %p\n", usbclass);; + uvdbg("Freeing: %p\n", usbclass); sched_kfree(usbclass); } #endif @@ -687,7 +687,7 @@ static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv) uvdbg("Request maximum logical unit number\n"); memset(req, 0, sizeof(struct usb_ctrlreq_s)); - req->type = USB_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE; + req->type = USB_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; req->req = USBMSC_REQ_GETMAXLUN; usbhost_putle16(req->len, 1); @@ -729,7 +729,7 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv) usbhost_testunitreadycbw(cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Receive the CSW */ @@ -767,7 +767,7 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv) usbhost_requestsensecbw(cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Receive the sense data response */ @@ -813,7 +813,7 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv) usbhost_readcapacitycbw(cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Receive the read capacity CBW IN response */ @@ -864,7 +864,7 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv) usbhost_inquirycbw(cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Receive the CBW IN response */ @@ -1019,7 +1019,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, /* Get the total length of the configuration descriptor (little endian). * It might be a good check to get the number of interfaces here too. - */ + */ remaining = (int)usbhost_getle16(cfgdesc->totallen); @@ -2028,7 +2028,7 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer, usbhost_readcbw(startsector, priv->blocksize, nsectors, cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Receive the user data */ @@ -2056,7 +2056,8 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer, } } } - } while (nbytes == -EAGAIN); + } + while (nbytes == -EAGAIN); } usbhost_givesem(&priv->exclsem); @@ -2126,13 +2127,13 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe usbhost_writecbw(startsector, priv->blocksize, nsectors, cbw); nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); + (FAR uint8_t *)cbw, USBMSC_CBW_SIZEOF); if (nbytes >= 0) { /* Send the user data */ nbytes = DRVR_TRANSFER(hport->drvr, priv->bulkout, - (uint8_t*)buffer, priv->blocksize * nsectors); + (FAR uint8_t *)buffer, priv->blocksize * nsectors); if (nbytes >= 0) { /* Receive the CSW */ -- GitLab From 5f9c47a83f33d406f6ea7ac46b6cf4943d0ff545 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 11:51:32 -0600 Subject: [PATCH 213/858] drivers/wireless: Fixes to spacing and alignement --- drivers/wireless/ISM1_868MHzGFSK100kbps.c | 52 +- drivers/wireless/ISM2_905MHzGFSK250kbps.c | 52 +- drivers/wireless/cc1101.c | 26 +- drivers/wireless/cc3000/cc3000.c | 38 +- drivers/wireless/cc3000/cc3000_common.c | 4 +- drivers/wireless/cc3000/cc3000drv.c | 14 +- drivers/wireless/cc3000/evnt_handler.c | 68 +- drivers/wireless/cc3000/hci.c | 6 +- drivers/wireless/cc3000/netapp.c | 8 +- drivers/wireless/cc3000/nvmem.c | 14 +- drivers/wireless/cc3000/security.c | 773 ++++++++++++---------- drivers/wireless/cc3000/socket.c | 22 +- drivers/wireless/cc3000/socket_imp.c | 19 +- drivers/wireless/cc3000/wlan.c | 11 +- drivers/wireless/nrf24l01.c | 13 +- 15 files changed, 601 insertions(+), 519 deletions(-) diff --git a/drivers/wireless/ISM1_868MHzGFSK100kbps.c b/drivers/wireless/ISM1_868MHzGFSK100kbps.c index a02b2838af..88432196d5 100644 --- a/drivers/wireless/ISM1_868MHzGFSK100kbps.c +++ b/drivers/wireless/ISM1_868MHzGFSK100kbps.c @@ -84,40 +84,40 @@ const struct c1101_rfsettings_s cc1101_rfsettings_ISM1_868MHzGFSK100kbps = { - .FSCTRL1 = 0x08, /* FSCTRL1 Frequency Synthesizer Control */ - .FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */ + .FSCTRL1 = 0x08, /* FSCTRL1 Frequency Synthesizer Control */ + .FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */ - .FREQ2 = 0x20, /* FREQ2 Frequency Control Word, High Byte */ - .FREQ1 = 0x25, /* FREQ1 Frequency Control Word, Middle Byte */ - .FREQ0 = 0xED, /* FREQ0 Frequency Control Word, Low Byte */ + .FREQ2 = 0x20, /* FREQ2 Frequency Control Word, High Byte */ + .FREQ1 = 0x25, /* FREQ1 Frequency Control Word, Middle Byte */ + .FREQ0 = 0xED, /* FREQ0 Frequency Control Word, Low Byte */ - .MDMCFG4 = 0x8B, /* MDMCFG4 Modem Configuration */ - .MDMCFG3 = 0xE5, /* MDMCFG3 Modem Configuration */ - .MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */ - .MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */ - .MDMCFG0 = 0xE5, /* MDMCFG0 Modem Configuration */ + .MDMCFG4 = 0x8B, /* MDMCFG4 Modem Configuration */ + .MDMCFG3 = 0xE5, /* MDMCFG3 Modem Configuration */ + .MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */ + .MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */ + .MDMCFG0 = 0xE5, /* MDMCFG0 Modem Configuration */ - .DEVIATN = 0x46, /* DEVIATN Modem Deviation Setting */ + .DEVIATN = 0x46, /* DEVIATN Modem Deviation Setting */ - .FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */ + .FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */ - .BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */ + .BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */ - .AGCCTRL2= 0xC7, /* AGCCTRL2 AGC Control */ - .AGCCTRL1= 0x00, /* AGCCTRL1 AGC Control */ - .AGCCTRL0= 0xB2, /* AGCCTRL0 AGC Control */ + .AGCCTRL2 = 0xC7, /* AGCCTRL2 AGC Control */ + .AGCCTRL1 = 0x00, /* AGCCTRL1 AGC Control */ + .AGCCTRL0 = 0xB2, /* AGCCTRL0 AGC Control */ - .FREND1 = 0xB6, /* FREND1 Front End RX Configuration */ - .FREND0 = 0x10, /* FREND0 Front End TX Configuration */ + .FREND1 = 0xB6, /* FREND1 Front End RX Configuration */ + .FREND0 = 0x10, /* FREND0 Front End TX Configuration */ - .FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */ - .FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */ - .FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */ - .FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */ + .FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */ + .FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */ + .FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */ + .FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */ - .CHMIN = 0, /* Fix at 9th channel: 869.80 MHz +- 100 kHz RF Bandwidth */ - .CHMAX = 9, /* single channel */ + .CHMIN = 0, /* Fix at 9th channel: 869.80 MHz +- 100 kHz RF Bandwidth */ + .CHMAX = 9, /* single channel */ - .PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */ - .PA = {0x03, 0x0F, 0x1E, 0x27, 0x67, 0x50, 0x81, 0xC2} + .PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */ + .PA = {0x03, 0x0F, 0x1E, 0x27, 0x67, 0x50, 0x81, 0xC2} }; diff --git a/drivers/wireless/ISM2_905MHzGFSK250kbps.c b/drivers/wireless/ISM2_905MHzGFSK250kbps.c index c78cee5864..a416053b2c 100644 --- a/drivers/wireless/ISM2_905MHzGFSK250kbps.c +++ b/drivers/wireless/ISM2_905MHzGFSK250kbps.c @@ -82,40 +82,40 @@ const struct c1101_rfsettings_s cc1101_rfsettings_ISM2_905MHzGFSK250kbps = { - .FSCTRL1 = 0x0C, /* FSCTRL1 Frequency Synthesizer Control */ - .FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */ + .FSCTRL1 = 0x0C, /* FSCTRL1 Frequency Synthesizer Control */ + .FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */ - .FREQ2 = 0x22, /* FREQ2 Frequency Control Word, High Byte */ - .FREQ1 = 0xB1, /* FREQ1 Frequency Control Word, Middle Byte */ - .FREQ0 = 0x3B, /* FREQ0 Frequency Control Word, Low Byte */ + .FREQ2 = 0x22, /* FREQ2 Frequency Control Word, High Byte */ + .FREQ1 = 0xB1, /* FREQ1 Frequency Control Word, Middle Byte */ + .FREQ0 = 0x3B, /* FREQ0 Frequency Control Word, Low Byte */ - .MDMCFG4 = 0x2D, /* MDMCFG4 Modem Configuration */ - .MDMCFG3 = 0x3B, /* MDMCFG3 Modem Configuration */ - .MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */ - .MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */ - .MDMCFG0 = 0xF8, /* MDMCFG0 Modem Configuration */ + .MDMCFG4 = 0x2D, /* MDMCFG4 Modem Configuration */ + .MDMCFG3 = 0x3B, /* MDMCFG3 Modem Configuration */ + .MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */ + .MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */ + .MDMCFG0 = 0xF8, /* MDMCFG0 Modem Configuration */ - .DEVIATN = 0x62, /* DEVIATN Modem Deviation Setting */ + .DEVIATN = 0x62, /* DEVIATN Modem Deviation Setting */ - .FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */ + .FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */ - .BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */ + .BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */ - .AGCCTRL2= 0xC7, /* AGCCTRL2 AGC Control */ - .AGCCTRL1= 0x00, /* AGCCTRL1 AGC Control */ - .AGCCTRL0= 0xB0, /* AGCCTRL0 AGC Control */ + .AGCCTRL2 = 0xC7, /* AGCCTRL2 AGC Control */ + .AGCCTRL1 = 0x00, /* AGCCTRL1 AGC Control */ + .AGCCTRL0 = 0xB0, /* AGCCTRL0 AGC Control */ - .FREND1 = 0xB6, /* FREND1 Front End RX Configuration */ - .FREND0 = 0x10, /* FREND0 Front End TX Configuration */ + .FREND1 = 0xB6, /* FREND1 Front End RX Configuration */ + .FREND0 = 0x10, /* FREND0 Front End TX Configuration */ - .FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */ - .FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */ - .FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */ - .FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */ + .FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */ + .FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */ + .FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */ + .FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */ - .CHMIN = 0, /* VERIFY REGULATIONS! */ - .CHMAX = 0xFF, + .CHMIN = 0, /* VERIFY REGULATIONS! */ + .CHMAX = 0xFF, - .PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */ - .PA = {0x03, 0x0E, 0x1E, 0x27, 0x39, 0x8E, 0xCD, 0xC0} + .PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */ + .PA = {0x03, 0x0E, 0x1E, 0x27, 0x39, 0x8E, 0xCD, 0xC0} }; diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index 8289eef371..bd86776bbd 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -220,8 +220,7 @@ #define CC1101_MCSM0_XOSC_FORCE_ON 0x01 -/* - * Chip Status Byte +/* Chip Status Byte */ /* Bit fields in the chip status byte */ @@ -273,9 +272,7 @@ #define CC1101_PARTNUM_VALUE 0x00 #define CC1101_VERSION_VALUE 0x04 -/* - * Others ... - */ +/* Others ... */ #define CC1101_LQI_CRC_OK_BM 0x80 #define CC1101_LQI_EST_BM 0x7F @@ -357,7 +354,7 @@ int cc1101_access(FAR struct cc1101_dev_s * dev, uint8_t addr, cc1101_access_begin(dev); - if (length>1 || length < -1) + if (length > 1 || length < -1) { SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_BURST); } @@ -453,7 +450,11 @@ void cc1101_dumpregs(struct cc1101_dev_s * dev, uint8_t addr, uint8_t length) cc1101_access(dev, addr, (FAR uint8_t *)buf, length); printf("CC1101[%2x]: ", addr); - for (i=0; i RX, RX -> RX: 0x3F */ values[2] = CC1101_MCSM0_VALUE; /* Calibrate on IDLE -> RX/TX, OSC Timeout = ~500 us - TODO: has XOSC_FORCE_ON */ + * TODO: has XOSC_FORCE_ON */ cc1101_access(dev, CC1101_MCSM2, values, -3); /* Wake-On Radio Control */ + /* Not used yet. */ - // Not used yet. - - // WOREVT1:WOREVT0 - 16-bit timeout register + /* WOREVT1:WOREVT0 - 16-bit timeout register */ } /**************************************************************************** @@ -777,9 +777,9 @@ int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size) { ASSERT(dev); - if (buf==NULL) + if (buf == NULL) { - if (size==0) + if (size == 0) { return 64; } diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index b2265b33cb..0434cdbacd 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -350,7 +350,7 @@ static void cc3000_deselect_and_unlock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -static int cc3000_wait(FAR struct cc3000_dev_s *priv, sem_t* psem) +static int cc3000_wait(FAR struct cc3000_dev_s *priv, sem_t *psem) { int ret; @@ -404,7 +404,7 @@ static int cc3000_wait(FAR struct cc3000_dev_s *priv, sem_t* psem) static inline int cc3000_wait_irq(FAR struct cc3000_dev_s *priv) { - return cc3000_wait(priv,&priv->irqsem); + return cc3000_wait(priv, &priv->irqsem); } /**************************************************************************** @@ -426,7 +426,7 @@ static inline int cc3000_wait_irq(FAR struct cc3000_dev_s *priv) static inline int cc3000_wait_ready(FAR struct cc3000_dev_s *priv) { - return cc3000_wait(priv,&priv->readysem); + return cc3000_wait(priv, &priv->readysem); } /**************************************************************************** @@ -531,7 +531,7 @@ static void * select_thread_func(FAR void *arg) { /* Release the waiting threads */ - waitlldbg("Closed Signaled %d\n",count); + waitlldbg("Closed Signaled %d\n", count); sem_post(&priv->sockets[s].semwait); } } @@ -631,12 +631,12 @@ static void * cc3000_worker(FAR void *arg) ASSERT(priv != NULL && priv->config != NULL); - /* We have started release our creator*/ + /* We have started, release our creator */ sem_post(&priv->readysem); while (1) { - PROBE(0,1); + PROBE(0, 1); CHECK_GUARD(priv); cc3000_devtake(priv); @@ -644,8 +644,8 @@ static void * cc3000_worker(FAR void *arg) if ((cc3000_wait_irq(priv) != -EINTR) && (priv->workertid != -1)) { - PROBE(0,0); - nllvdbg("State%d\n",priv->state); + PROBE(0, 0); + nllvdbg("State%d\n", priv->state); switch (priv->state) { case eSPI_STATE_POWERUP: @@ -672,7 +672,7 @@ static void * cc3000_worker(FAR void *arg) cc3000_lock_and_select(priv->spi); /* Assert CS */ priv->state = eSPI_STATE_READ_PROCEED; - SPI_EXCHANGE(priv->spi,spi_readCommand, priv->rx_buffer.pbuffer, + SPI_EXCHANGE(priv->spi, spi_readCommand, priv->rx_buffer.pbuffer, ARRAY_SIZE(spi_readCommand)); /* Extract Length bytes from Rx Buffer. Here we need to convert @@ -738,7 +738,7 @@ static void * cc3000_worker(FAR void *arg) priv->state, priv->config->irq_read(priv->config)); sem_getvalue(&priv->irqsem, &count); - if (priv->config->irq_read(priv->config) && count==0) + if (priv->config->irq_read(priv->config) && count == 0) { sem_post(&priv->irqsem); } @@ -754,7 +754,7 @@ static void * cc3000_worker(FAR void *arg) break; default: - nllvdbg("default: State%d\n",priv->state); + nllvdbg("default: State%d\n", priv->state); break; } } @@ -787,9 +787,9 @@ static int cc3000_interrupt(int irq, FAR void *context) /* Run the worker thread */ - PROBE(1,0); + PROBE(1, 0); sem_post(&priv->irqsem); - PROBE(1,1); + PROBE(1, 1); /* Clear any pending interrupts and return success */ @@ -867,7 +867,7 @@ static int cc3000_open(FAR struct file *filep) } #endif - /* Ensure the power is off so we get the falling edge of IRQ*/ + /* Ensure the power is off so we get the falling edge of IRQ */ priv->config->power_enable(priv->config, false); @@ -887,7 +887,7 @@ static int cc3000_open(FAR struct file *filep) */ snprintf(queuename, QUEUE_NAMELEN, QUEUE_FORMAT, priv->minor); - priv->queue = mq_open(queuename, O_WRONLY|O_CREAT, 0666, &attr); + priv->queue = mq_open(queuename, O_WRONLY | O_CREAT, 0666, &attr); if (priv->queue < 0) { ret = -errno; @@ -1195,7 +1195,7 @@ static ssize_t cc3000_read(FAR struct file *filep, FAR char *buffer, size_t len) if (nread > 0) { - memcpy(buffer,priv->rx_buffer.pbuffer,priv->rx_buffer.len); + memcpy(buffer, priv->rx_buffer.pbuffer, priv->rx_buffer.len); priv->rx_buffer.len = 0; } @@ -1235,7 +1235,7 @@ static ssize_t cc3000_write(FAR struct file *filep, FAR const char *usrbuffer, s size_t tx_len = (len & 1) ? len : len +1; - nllvdbg("buffer:%p len:%d tx_len:%d\n", buffer, len, tx_len ); + nllvdbg("buffer:%p len:%d tx_len:%d\n", buffer, len, tx_len); DEBUGASSERT(filep); inode = filep->f_inode; @@ -1431,7 +1431,7 @@ static int cc3000_ioctl(FAR struct file *filep, int cmd, unsigned long arg) rv = priv->rx_buffer_max_len; flags = irqsave(); priv->rx_buffer_max_len = *psize; - priv->rx_buffer.pbuffer = kmm_realloc(priv->rx_buffer.pbuffer,*psize); + priv->rx_buffer.pbuffer = kmm_realloc(priv->rx_buffer.pbuffer, *psize); irqrestore(flags); DEBUGASSERT(priv->rx_buffer.pbuffer); *psize = rv; @@ -1606,7 +1606,7 @@ int cc3000_register(FAR struct spi_dev_s *spi, sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */ (void)snprintf(semname, SEM_NAMELEN, SEM_FORMAT, minor); - priv->wrkwaitsem = sem_open(semname,O_CREAT,0,0); /* Initialize Worker Wait semaphore */ + priv->wrkwaitsem = sem_open(semname, O_CREAT, 0, 0); /* Initialize Worker Wait semaphore */ #ifdef CONFIG_CC3000_MT pthread_mutex_init(&g_cc3000_mut, NULL); diff --git a/drivers/wireless/cc3000/cc3000_common.c b/drivers/wireless/cc3000/cc3000_common.c index bda6508308..cca794a079 100644 --- a/drivers/wireless/cc3000/cc3000_common.c +++ b/drivers/wireless/cc3000/cc3000_common.c @@ -117,7 +117,7 @@ uint8_t *UINT16_TO_STREAM_f(uint8_t *p, uint16_t u16) * ****************************************************************************/ -uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset) +uint16_t STREAM_TO_UINT16_f(FAR char *p, uint16_t offset) { return (uint16_t)((uint16_t)((uint16_t) (*(p + offset + 1)) << 8) + (uint16_t)(*(p + offset))); @@ -139,7 +139,7 @@ uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset) * ****************************************************************************/ -unsigned long STREAM_TO_UINT32_f(char* p, uint16_t offset) +unsigned long STREAM_TO_UINT32_f(FAR char *p, uint16_t offset) { return (unsigned long)((unsigned long)((unsigned long) (*(p + offset + 3)) << 24) + (unsigned long)((unsigned long) diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index d120162c99..e192dbf175 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -138,7 +138,7 @@ void cc3000_resume(void) long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) { DEBUGASSERT(spiconf.cc3000fd >= 0); - return write(spiconf.cc3000fd,pUserBuffer,usLength) == usLength ? 0 : -errno; + return write(spiconf.cc3000fd, pUserBuffer, usLength) == usLength ? 0 : -errno; } /**************************************************************************** @@ -159,7 +159,7 @@ long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) long cc3000_read(uint8_t *pUserBuffer, uint16_t usLength) { DEBUGASSERT(spiconf.cc3000fd >= 0); - return read(spiconf.cc3000fd,pUserBuffer,usLength); + return read(spiconf.cc3000fd, pUserBuffer, usLength); } /**************************************************************************** @@ -211,19 +211,19 @@ static void *unsoliced_thread_func(void *parameter) DEBUGASSERT(spiconf.queue != (mqd_t) -1); DEBUGASSERT(SEM_NAMELEN == QUEUE_NAMELEN); snprintf(buff, SEM_NAMELEN, SEM_FORMAT, minor); - spiconf.done = sem_open(buff,O_RDONLY); + spiconf.done = sem_open(buff, O_RDONLY); DEBUGASSERT(spiconf.done != (sem_t *)-1); sem_post(&spiconf.unsoliced_thread_wakesem); while (spiconf.run) { - memset(&spiconf.rx_buffer,0,sizeof(spiconf.rx_buffer)); + memset(&spiconf.rx_buffer, 0, sizeof(spiconf.rx_buffer)); nbytes = mq_receive(spiconf.queue, (FAR char *)&spiconf.rx_buffer, sizeof(spiconf.rx_buffer), 0); if (nbytes > 0) { - nlldbg("%d Processed\n",nbytes); + nlldbg("%d Processed\n", nbytes); spiconf.pfRxHandler(spiconf.rx_buffer.pbuffer); } } @@ -255,7 +255,7 @@ void cc3000_open(gcSpiHandleRx pfRxHandler) DEBUGASSERT(spiconf.cc3000fd == -1); - fd = open("/dev/wireless0",O_RDWR|O_BINARY); + fd = open("/dev/wireless0", O_RDWR | O_BINARY); if (fd >= 0) { spiconf.pfRxHandler = pfRxHandler; @@ -308,7 +308,7 @@ void cc3000_close(void) spiconf.run = false; pthread_cancel(spiconf.unsoliced_thread); - pthread_join(spiconf.unsoliced_thread, (pthread_addr_t*)&status); + pthread_join(spiconf.unsoliced_thread, (FAR pthread_addr_t *)&status); close(spiconf.cc3000fd); diff --git a/drivers/wireless/cc3000/evnt_handler.c b/drivers/wireless/cc3000/evnt_handler.c index ebda7af9ee..b890a9a9b7 100644 --- a/drivers/wireless/cc3000/evnt_handler.c +++ b/drivers/wireless/cc3000/evnt_handler.c @@ -237,7 +237,8 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) while (1) { - if (tSLInformation.usEventOrDataReceived != 0) { + if (tSLInformation.usEventOrDataReceived != 0) + { pucReceivedData = (tSLInformation.pucReceivedData); if (*pucReceivedData == HCI_TYPE_EVNT) @@ -258,7 +259,7 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) { STREAM_TO_UINT8(pucReceivedData, HCI_DATA_LENGTH_OFFSET, usLength); - switch(usReceivedEventOpcode) + switch (usReceivedEventOpcode) { case HCI_CMND_READ_BUFFER_SIZE: { @@ -449,37 +450,37 @@ uint8_t *hci_event_handler(void *pRetParams, uint8_t *from, uint8_t *fromlen) /* Read IP address */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_IP_LENGTH); RecvParams += 4; /* Read subnet */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_IP_LENGTH); RecvParams += 4; /* Read default GW */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_IP_LENGTH); RecvParams += 4; /* Read DHCP server */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_IP_LENGTH); RecvParams += 4; /* Read DNS server */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_IP_LENGTH); RecvParams += 4; /* Read Mac address */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_MAC_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_MAC_LENGTH); RecvParams += 6; /* Read SSID */ - STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH); + STREAM_TO_STREAM(RecvParams, RetParams, NETAPP_IPCONFIG_SSID_LENGTH); break; default: @@ -574,7 +575,7 @@ long hci_unsol_event_handler(char *event_hdr) unsigned long NumberOfReleasedPackets; unsigned long NumberOfSentPackets; - STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type); + STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET, event_type); if (event_type == HCI_EVNT_PATCHES_REQ) { @@ -583,7 +584,7 @@ long hci_unsol_event_handler(char *event_hdr) if (event_type & HCI_EVNT_UNSOL_BASE) { - switch(event_type) + switch (event_type) { case HCI_EVNT_DATA_UNSOL_FREE_BUFF: { @@ -607,7 +608,7 @@ long hci_unsol_event_handler(char *event_hdr) if (event_type & HCI_EVNT_WLAN_UNSOL_BASE) { - switch(event_type) + switch (event_type) { case HCI_EVNT_WLAN_KEEPALIVE: case HCI_EVNT_WLAN_UNSOL_CONNECT: @@ -623,34 +624,34 @@ long hci_unsol_event_handler(char *event_hdr) case HCI_EVNT_WLAN_UNSOL_DHCP: { - uint8_t params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; // extra byte is for the status + uint8_t params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; /* Extra byte is for the status */ uint8_t *recParams = params; - data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + data = (FAR char *)(event_hdr) + HCI_EVENT_HEADER_SIZE; /* Read IP address */ - STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(data, recParams, NETAPP_IPCONFIG_IP_LENGTH); data += 4; /* Read subnet */ - STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(data, recParams, NETAPP_IPCONFIG_IP_LENGTH); data += 4; /* Read default GW */ - STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(data, recParams, NETAPP_IPCONFIG_IP_LENGTH); data += 4; /* Read DHCP server */ - STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(data, recParams, NETAPP_IPCONFIG_IP_LENGTH); data += 4; /* Read DNS server */ - STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + STREAM_TO_STREAM(data, recParams, NETAPP_IPCONFIG_IP_LENGTH); /* Read the status */ @@ -666,7 +667,7 @@ long hci_unsol_event_handler(char *event_hdr) case HCI_EVNT_WLAN_ASYNC_PING_REPORT: { netapp_pingreport_args_t params; - data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + data = (FAR char *)(event_hdr) + HCI_EVENT_HEADER_SIZE; STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, params.packets_sent); STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_RCVD_OFFSET, params.packets_received); STREAM_TO_UINT32(data, NETAPP_PING_MIN_RTT_OFFSET, params.min_round_time); @@ -684,7 +685,7 @@ long hci_unsol_event_handler(char *event_hdr) { int sockfd; - data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + data = (FAR char *)(event_hdr) + HCI_EVENT_HEADER_SIZE; STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, sockfd); data += 4; @@ -713,7 +714,7 @@ long hci_unsol_event_handler(char *event_hdr) long status; pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr); - STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status); + STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET, status); if (ERROR_SOCKET_INACTIVE == status) { @@ -827,10 +828,10 @@ long hci_event_unsol_flowcontrol_handler(char *pEvent) { long temp, value; uint16_t i; - uint16_t pusNumberOfHandles=0; + uint16_t pusNumberOfHandles = 0; char *pReadPayload; - STREAM_TO_UINT16((char *)pEvent,HCI_EVENT_HEADER_SIZE,pusNumberOfHandles); + STREAM_TO_UINT16((char *)pEvent, HCI_EVENT_HEADER_SIZE, pusNumberOfHandles); pReadPayload = ((char *)pEvent + HCI_EVENT_HEADER_SIZE + sizeof(pusNumberOfHandles)); temp = 0; @@ -891,8 +892,8 @@ void update_socket_active_status(char *resp_params) { long status, sd; - STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET,sd); - STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET,status); + STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET, sd); + STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET, status); if (ERROR_SOCKET_INACTIVE == status) { @@ -923,7 +924,7 @@ void SimpleLinkWaitEvent(uint16_t opcode, void *pRetParams) */ tSLInformation.usRxEventOpcode = opcode; - nllvdbg("Looking for opcode 0x%x\n",opcode); + nllvdbg("Looking for opcode 0x%x\n", opcode); uint16_t event_type; do @@ -931,29 +932,30 @@ void SimpleLinkWaitEvent(uint16_t opcode, void *pRetParams) nllvdbg("cc3000_wait\n"); tSLInformation.pucReceivedData = cc3000_wait(); tSLInformation.usEventOrDataReceived = 1; - STREAM_TO_UINT16((char *)tSLInformation.pucReceivedData, HCI_EVENT_OPCODE_OFFSET,event_type); + STREAM_TO_UINT16((FAR char *)tSLInformation.pucReceivedData, + HCI_EVENT_OPCODE_OFFSET, event_type); if (*tSLInformation.pucReceivedData == HCI_TYPE_EVNT) { - nllvdbg("Evtn:0x%x\n",event_type); + nllvdbg("Evtn:0x%x\n", event_type); } if (event_type != opcode) { if (hci_unsolicited_event_handler() == 1) { - nllvdbg("Processed Event 0x%x want 0x%x\n",event_type, opcode); + nllvdbg("Processed Event 0x%x want 0x%x\n", event_type, opcode); } } else { - nllvdbg("Processing opcode 0x%x\n",opcode); + nllvdbg("Processing opcode 0x%x\n", opcode); hci_event_handler(pRetParams, 0, 0); } } while (tSLInformation.usRxEventOpcode != 0); - nllvdbg("Done for opcode 0x%x\n",opcode); + nllvdbg("Done for opcode 0x%x\n", opcode); } /**************************************************************************** @@ -1005,7 +1007,7 @@ void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen) } else { - nllvdbg("!!!!!opcode 0x%x\n",opcode); + nllvdbg("!!!!!opcode 0x%x\n", opcode); } UNUSED(event_type); diff --git a/drivers/wireless/cc3000/hci.c b/drivers/wireless/cc3000/hci.c index e51d45cbbc..6caf64c60d 100644 --- a/drivers/wireless/cc3000/hci.c +++ b/drivers/wireless/cc3000/hci.c @@ -79,7 +79,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, stream = (pucBuff + SPI_HEADER_SIZE); - nllvdbg("Send 0x%x\n",usOpcode); + nllvdbg("Send 0x%x\n", usOpcode); UINT8_TO_STREAM(stream, HCI_TYPE_CMND); stream = UINT16_TO_STREAM(stream, usOpcode); UINT8_TO_STREAM(stream, ucArgsLength); @@ -87,7 +87,7 @@ uint16_t hci_command_send(uint16_t usOpcode, uint8_t *pucBuff, /* Update the opcode of the event we will be waiting for */ cc3000_write(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE); - nllvdbg("Send of 0x%x Completed\n",usOpcode); + nllvdbg("Send of 0x%x Completed\n", usOpcode); return 0; } @@ -150,7 +150,7 @@ long hci_data_send(uint8_t ucOpcode, uint8_t *ucArgs, uint16_t usArgsLength, ****************************************************************************/ void hci_data_command_send(uint16_t usOpcode, uint8_t *pucBuff, - uint8_t ucArgsLength,uint16_t ucDataLength) + uint8_t ucArgsLength, uint16_t ucDataLength) { uint8_t *stream = (pucBuff + SPI_HEADER_SIZE); diff --git a/drivers/wireless/cc3000/netapp.c b/drivers/wireless/cc3000/netapp.c index 973f1e9ad8..f6ac0aa042 100644 --- a/drivers/wireless/cc3000/netapp.c +++ b/drivers/wireless/cc3000/netapp.c @@ -129,11 +129,11 @@ long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, /* Fill in temporary command buffer */ - ARRAY_TO_STREAM(args,aucIP,4); - ARRAY_TO_STREAM(args,aucSubnetMask,4); - ARRAY_TO_STREAM(args,aucDefaultGateway,4); + ARRAY_TO_STREAM(args, aucIP, 4); + ARRAY_TO_STREAM(args, aucSubnetMask, 4); + ARRAY_TO_STREAM(args, aucDefaultGateway, 4); args = UINT32_TO_STREAM(args, 0); - ARRAY_TO_STREAM(args,aucDNSServer,4); + ARRAY_TO_STREAM(args, aucDNSServer, 4); /* Initiate a HCI command */ diff --git a/drivers/wireless/cc3000/nvmem.c b/drivers/wireless/cc3000/nvmem.c index c8bd1b5be7..8009e48020 100644 --- a/drivers/wireless/cc3000/nvmem.c +++ b/drivers/wireless/cc3000/nvmem.c @@ -165,7 +165,7 @@ signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, args = UINT32_TO_STREAM(args, ulEntryOffset); memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE + - NVMEM_WRITE_PARAMS_LEN),buff,ulLength); + NVMEM_WRITE_PARAMS_LEN), buff, ulLength); /* Initiate a HCI command but it will come on data channel */ @@ -241,9 +241,9 @@ uint8_t nvmem_get_mac_address(uint8_t *mac) uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const uint8_t *spData) { - uint8_t status = 0; - uint16_t offset = 0; - uint8_t *spDataPtr = (uint8_t*)spData; + FAR uint8_t *spDataPtr = (FAR uint8_t *)spData; + uint8_t status = 0; + uint16_t offset = 0; while ((status == 0) && (spLength >= SP_PORTION_SIZE)) { @@ -253,7 +253,7 @@ uint8_t nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, spDataPtr += SP_PORTION_SIZE; } - if (status !=0) + if (status != 0) { /* NVMEM error occurred */ @@ -349,14 +349,14 @@ signed long nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen) ptr = tSLInformation.pucTxCommandBuffer; args = (ptr + HEADERS_SIZE_CMD); - /*( Fill in HCI packet structure */ + /* Fill in HCI packet structure */ args = UINT32_TO_STREAM(args, ulFileId); args = UINT32_TO_STREAM(args, ulNewLen); /* Initiate a HCI command */ - hci_command_send(HCI_CMND_NVMEM_CREATE_ENTRY,ptr, NVMEM_CREATE_PARAMS_LEN); + hci_command_send(HCI_CMND_NVMEM_CREATE_ENTRY, ptr, NVMEM_CREATE_PARAMS_LEN); SimpleLinkWaitEvent(HCI_CMND_NVMEM_CREATE_ENTRY, &retval); diff --git a/drivers/wireless/cc3000/security.c b/drivers/wireless/cc3000/security.c index 5d0c406faa..90152ac8fa 100644 --- a/drivers/wireless/cc3000/security.c +++ b/drivers/wireless/cc3000/security.c @@ -44,52 +44,52 @@ * Private Data ****************************************************************************/ -// foreward sbox +/* Forward sbox */ const uint8_t sbox[256] = { -//0 1 2 3 4 5 6 7 8 9 A B C D E F -0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, //0 -0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, //1 -0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, //2 -0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, //3 -0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, //4 -0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, //5 -0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, //6 -0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, //7 -0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, //8 -0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, //9 -0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, //A -0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, //B -0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, //C -0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, //D -0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, //E -0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 //F +/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, /* 0 */ + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, /* 1 */ + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, /* 2 */ + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, /* 3 */ + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, /* 4 */ + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, /* 5 */ + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, /* 6 */ + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, /* 7 */ + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, /* 8 */ + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, /* 9 */ + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, /* A */ + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, /* B */ + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, /* C */ + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, /* D */ + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, /* E */ + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 /* F */ }; -// inverse sbox +/* Inverse sbox */ const uint8_t rsbox[256] = { - 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb -, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb -, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e -, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25 -, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92 -, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84 -, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06 -, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b -, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73 -, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e -, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b -, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4 -, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f -, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef -, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61 -, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d + 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, + 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, + 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, + 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, + 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, + 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, + 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, + 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, + 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, + 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, + 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, + 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, + 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, + 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; -// round constant +/* Round constant */ const uint8_t Rcon[11] = { @@ -101,221 +101,253 @@ uint8_t aexpandedKey[176]; /**************************************************************************** * Public Functions ****************************************************************************/ -//***************************************************************************** -// -//! expandKey -//! -//! @param key AES128 key - 16 bytes -//! @param expandedKey expanded AES128 key -//! -//! @return none -//! -//! @brief expend a 16 bytes key for AES128 implementation -//! -//***************************************************************************** - -void expandKey(uint8_t *expandedKey, - uint8_t *key) +/**************************************************************************** + * Name: expandKey + * + * Description: + * Expend a 16 bytes key for AES128 implementation + * + * Input Parameters: + * key AES128 key - 16 bytes + * expandedKey expanded AES128 key + * + * Returned Value: + * None + * + ****************************************************************************/ + +void expandKey(uint8_t *expandedKey, uint8_t *key) { uint16_t ii, buf1; - for (ii=0;ii<16;ii++) - expandedKey[ii] = key[ii]; - - for (ii=1;ii<11;ii++) - { - buf1 = expandedKey[ii*16 - 4]; - expandedKey[ii*16 + 0] = sbox[expandedKey[ii*16 - 3]]^expandedKey[(ii-1)*16 + 0]^Rcon[ii]; - expandedKey[ii*16 + 1] = sbox[expandedKey[ii*16 - 2]]^expandedKey[(ii-1)*16 + 1]; - expandedKey[ii*16 + 2] = sbox[expandedKey[ii*16 - 1]]^expandedKey[(ii-1)*16 + 2]; - expandedKey[ii*16 + 3] = sbox[buf1 ]^expandedKey[(ii-1)*16 + 3]; - expandedKey[ii*16 + 4] = expandedKey[(ii-1)*16 + 4]^expandedKey[ii*16 + 0]; - expandedKey[ii*16 + 5] = expandedKey[(ii-1)*16 + 5]^expandedKey[ii*16 + 1]; - expandedKey[ii*16 + 6] = expandedKey[(ii-1)*16 + 6]^expandedKey[ii*16 + 2]; - expandedKey[ii*16 + 7] = expandedKey[(ii-1)*16 + 7]^expandedKey[ii*16 + 3]; - expandedKey[ii*16 + 8] = expandedKey[(ii-1)*16 + 8]^expandedKey[ii*16 + 4]; - expandedKey[ii*16 + 9] = expandedKey[(ii-1)*16 + 9]^expandedKey[ii*16 + 5]; - expandedKey[ii*16 +10] = expandedKey[(ii-1)*16 +10]^expandedKey[ii*16 + 6]; - expandedKey[ii*16 +11] = expandedKey[(ii-1)*16 +11]^expandedKey[ii*16 + 7]; - expandedKey[ii*16 +12] = expandedKey[(ii-1)*16 +12]^expandedKey[ii*16 + 8]; - expandedKey[ii*16 +13] = expandedKey[(ii-1)*16 +13]^expandedKey[ii*16 + 9]; - expandedKey[ii*16 +14] = expandedKey[(ii-1)*16 +14]^expandedKey[ii*16 +10]; - expandedKey[ii*16 +15] = expandedKey[(ii-1)*16 +15]^expandedKey[ii*16 +11]; - } + for (ii = 0; ii < 16; ii++) + { + expandedKey[ii] = key[ii]; + } + + for (ii = 1; ii < 11; ii++) + { + buf1 = expandedKey[ii*16 - 4]; + expandedKey[ii * 16 + 0] = sbox[expandedKey[ii *16 - 3]] ^ expandedKey[(ii - 1) * 16 + 0] ^ Rcon[ii]; + expandedKey[ii * 16 + 1] = sbox[expandedKey[ii *16 - 2]] ^ expandedKey[(ii - 1) * 16 + 1]; + expandedKey[ii * 16 + 2] = sbox[expandedKey[ii *16 - 1]] ^ expandedKey[(ii - 1) * 16 + 2]; + expandedKey[ii * 16 + 3] = sbox[buf1] ^ expandedKey[(ii - 1) *1 6 + 3]; + expandedKey[ii * 16 + 4] = expandedKey[(ii - 1) * 16 + 4] ^ expandedKey[ii * 16 + 0]; + expandedKey[ii * 16 + 5] = expandedKey[(ii - 1) * 16 + 5] ^ expandedKey[ii * 16 + 1]; + expandedKey[ii * 16 + 6] = expandedKey[(ii - 1) * 16 + 6] ^ expandedKey[ii * 16 + 2]; + expandedKey[ii * 16 + 7] = expandedKey[(ii - 1) * 16 + 7] ^ expandedKey[ii * 16 + 3]; + expandedKey[ii * 16 + 8] = expandedKey[(ii - 1) * 16 + 8] ^ expandedKey[ii * 16 + 4]; + expandedKey[ii * 16 + 9] = expandedKey[(ii - 1) * 16 + 9] ^ expandedKey[ii * 16 + 5]; + expandedKey[ii * 16 +10] = expandedKey[(ii - 1) * 16 +10] ^ expandedKey[ii * 16 + 6]; + expandedKey[ii * 16 +11] = expandedKey[(ii - 1) * 16 +11] ^ expandedKey[ii * 16 + 7]; + expandedKey[ii * 16 +12] = expandedKey[(ii - 1) * 16 +12] ^ expandedKey[ii * 16 + 8]; + expandedKey[ii * 16 +13] = expandedKey[(ii - 1) * 16 +13] ^ expandedKey[ii * 16 + 9]; + expandedKey[ii * 16 +14] = expandedKey[(ii - 1) * 16 +14] ^ expandedKey[ii * 16 +10]; + expandedKey[ii * 16 +15] = expandedKey[(ii - 1) * 16 +15] ^ expandedKey[ii * 16 +11]; + } } -//***************************************************************************** -// -//! galois_mul2 -//! -//! @param value argument to multiply -//! -//! @return multiplied argument -//! -//! @brief multiply by 2 in the galois field -//! -//***************************************************************************** +/****************************************************************************** + * Name: galois_mul2 + * + * Description: + * Multiply by 2 in the galois field + * + * Input Parameters: + * value argument to multiply + * + * Returned Value: + * Multiplied argument + * + ******************************************************************************/ uint8_t galois_mul2(uint8_t value) { - if (value>>7) - { - value = value << 1; - return (value^0x1b); - } else - return value<<1; + if (value >> 7) + { + value = value << 1; + return (value ^ 0x1b); + } + else + { + return value << 1; + } } -//***************************************************************************** -// -//! aes_encr -//! -//! @param[in] expandedKey expanded AES128 key -//! @param[in/out] state 16 bytes of plain text and cipher text -//! -//! @return none -//! -//! @brief internal implementation of AES128 encryption. -//! straight forward aes encryption implementation -//! first the group of operations -//! - addRoundKey -//! - subbytes -//! - shiftrows -//! - mixcolums -//! is executed 9 times, after this addroundkey to finish the 9th -//! round, after that the 10th round without mixcolums -//! no further subfunctions to save cycles for function calls -//! no structuring with "for (....)" to save cycles. -//! -//! -//***************************************************************************** +/****************************************************************************** + * Name: aes_encr + * + * Description: + * Internal implementation of AES128 encryption. + * Straight forward aes encryption implementation. First the group of operations + * - addRoundKey + * - subbytes + * - shiftrows + * - mixcolums + * is executed 9 times, after this addroundkey to finish the 9th round, after + * that the 10th round without mixcolums no further subfunctions to save + * cycles for function calls no structuring with "for (....)" to save cycles. + * + * Input Parameters: + * expandedKey expanded AES128 key + * state 16 bytes of plain text and cipher text + * + * Returned Value: + * None + * + ******************************************************************************/ void aes_encr(uint8_t *state, uint8_t *expandedKey) { uint8_t buf1, buf2, buf3, round; - for (round = 0; round < 9; round ++){ - // addroundkey, sbox and shiftrows - // row 0 - state[ 0] = sbox[(state[ 0] ^ expandedKey[(round*16) ])]; - state[ 4] = sbox[(state[ 4] ^ expandedKey[(round*16) + 4])]; - state[ 8] = sbox[(state[ 8] ^ expandedKey[(round*16) + 8])]; - state[12] = sbox[(state[12] ^ expandedKey[(round*16) + 12])]; - // row 1 - buf1 = state[1] ^ expandedKey[(round*16) + 1]; - state[ 1] = sbox[(state[ 5] ^ expandedKey[(round*16) + 5])]; - state[ 5] = sbox[(state[ 9] ^ expandedKey[(round*16) + 9])]; - state[ 9] = sbox[(state[13] ^ expandedKey[(round*16) + 13])]; - state[13] = sbox[buf1]; - // row 2 - buf1 = state[2] ^ expandedKey[(round*16) + 2]; - buf2 = state[6] ^ expandedKey[(round*16) + 6]; - state[ 2] = sbox[(state[10] ^ expandedKey[(round*16) + 10])]; - state[ 6] = sbox[(state[14] ^ expandedKey[(round*16) + 14])]; - state[10] = sbox[buf1]; - state[14] = sbox[buf2]; - // row 3 - buf1 = state[15] ^ expandedKey[(round*16) + 15]; - state[15] = sbox[(state[11] ^ expandedKey[(round*16) + 11])]; - state[11] = sbox[(state[ 7] ^ expandedKey[(round*16) + 7])]; - state[ 7] = sbox[(state[ 3] ^ expandedKey[(round*16) + 3])]; - state[ 3] = sbox[buf1]; - - // mixcolums ////////// - // col1 - buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; - buf2 = state[0]; - buf3 = state[0]^state[1]; buf3=galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; - buf3 = state[1]^state[2]; buf3=galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; - buf3 = state[2]^state[3]; buf3=galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; - buf3 = state[3]^buf2; buf3=galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; - // col2 - buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; - buf2 = state[4]; - buf3 = state[4]^state[5]; buf3=galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; - buf3 = state[5]^state[6]; buf3=galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; - buf3 = state[6]^state[7]; buf3=galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; - buf3 = state[7]^buf2; buf3=galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; - // col3 - buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; - buf2 = state[8]; - buf3 = state[8]^state[9]; buf3=galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; - buf3 = state[9]^state[10]; buf3=galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; - buf3 = state[10]^state[11]; buf3=galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; - buf3 = state[11]^buf2; buf3=galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; - // col4 - buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; - buf2 = state[12]; - buf3 = state[12]^state[13]; buf3=galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; - buf3 = state[13]^state[14]; buf3=galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; - buf3 = state[14]^state[15]; buf3=galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; - buf3 = state[15]^buf2; buf3=galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; - - } - // 10th round without mixcols - state[ 0] = sbox[(state[ 0] ^ expandedKey[(round*16) ])]; - state[ 4] = sbox[(state[ 4] ^ expandedKey[(round*16) + 4])]; - state[ 8] = sbox[(state[ 8] ^ expandedKey[(round*16) + 8])]; - state[12] = sbox[(state[12] ^ expandedKey[(round*16) + 12])]; - // row 1 - buf1 = state[1] ^ expandedKey[(round*16) + 1]; - state[ 1] = sbox[(state[ 5] ^ expandedKey[(round*16) + 5])]; - state[ 5] = sbox[(state[ 9] ^ expandedKey[(round*16) + 9])]; - state[ 9] = sbox[(state[13] ^ expandedKey[(round*16) + 13])]; + for (round = 0; round < 9; round ++) + { + /* addroundkey, sbox and shiftrows */ + /* Row 0 */ + + state[0] = sbox[(state[0] ^ expandedKey[(round * 16)])]; + state[4] = sbox[(state[4] ^ expandedKey[(round * 16) + 4])]; + state[8] = sbox[(state[8] ^ expandedKey[(round * 16) + 8])]; + state[12] = sbox[(state[12] ^ expandedKey[(round * 16) + 12])]; + + /* Row 1 */ + + buf1 = state[1] ^ expandedKey[(round * 16) + 1]; + state[1] = sbox[(state[5] ^ expandedKey[(round * 16) + 5])]; + state[5] = sbox[(state[9] ^ expandedKey[(round * 16) + 9])]; + state[9] = sbox[(state[13] ^ expandedKey[(round * 16) + 13])]; + state[13] = sbox[buf1]; + + /* Row 2 */ + + buf1 = state[2] ^ expandedKey[(round * 16) + 2]; + buf2 = state[6] ^ expandedKey[(round * 16) + 6]; + state[2] = sbox[(state[10] ^ expandedKey[(round * 16) + 10])]; + state[6] = sbox[(state[14] ^ expandedKey[(round * 16) + 14])]; + state[10] = sbox[buf1]; + state[14] = sbox[buf2]; + + /* Row 3 */ + + buf1 = state[15] ^ expandedKey[(round * 16) + 15]; + state[15] = sbox[(state[11] ^ expandedKey[(round * 16) + 11])]; + state[11] = sbox[(state[7] ^ expandedKey[(round * 16) + 7])]; + state[7] = sbox[(state[3] ^ expandedKey[(round * 16) + 3])]; + state[3] = sbox[buf1]; + + /* mixcolums */ + /* Col1 */ + + buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; + buf2 = state[0]; + buf3 = state[0] ^ state[1]; buf3 = galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; + buf3 = state[1] ^ state[2]; buf3 = galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; + buf3 = state[2] ^ state[3]; buf3 = galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; + buf3 = state[3] ^ buf2; buf3 = galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; + + /* Col2 */ + + buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; + buf2 = state[4]; + buf3 = state[4] ^ state[5]; buf3 = galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; + buf3 = state[5] ^ state[6]; buf3 = galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; + buf3 = state[6] ^ state[7]; buf3 = galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; + buf3 = state[7] ^ buf2; buf3 = galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; + + /* Col3 */ + + buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; + buf2 = state[8]; + buf3 = state[8] ^ state[9]; buf3 = galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; + buf3 = state[9] ^ state[10]; buf3 = galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; + buf3 = state[10] ^ state[11]; buf3 = galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; + buf3 = state[11] ^ buf2; buf3 = galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; + + /* Col4 */ + + buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; + buf2 = state[12]; + buf3 = state[12] ^ state[13]; buf3 = galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; + buf3 = state[13] ^ state[14]; buf3 = galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; + buf3 = state[14] ^ state[15]; buf3 = galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; + buf3 = state[15] ^ buf2; buf3 = galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; + } + + /* 10th round without mixcols */ + + state[0] = sbox[(state[0] ^ expandedKey[(round * 16)])]; + state[4] = sbox[(state[4] ^ expandedKey[(round * 16) + 4])]; + state[8] = sbox[(state[8] ^ expandedKey[(round * 16) + 8])]; + state[12] = sbox[(state[12] ^ expandedKey[(round * 16) + 12])]; + + /* Row 1 */ + + buf1 = state[1] ^ expandedKey[(round * 16) + 1]; + state[1] = sbox[(state[5] ^ expandedKey[(round * 16) + 5])]; + state[5] = sbox[(state[9] ^ expandedKey[(round * 16) + 9])]; + state[9] = sbox[(state[13] ^ expandedKey[(round * 16) + 13])]; state[13] = sbox[buf1]; - // row 2 - buf1 = state[2] ^ expandedKey[(round*16) + 2]; - buf2 = state[6] ^ expandedKey[(round*16) + 6]; - state[ 2] = sbox[(state[10] ^ expandedKey[(round*16) + 10])]; - state[ 6] = sbox[(state[14] ^ expandedKey[(round*16) + 14])]; + + /* Row 2 */ + + buf1 = state[2] ^ expandedKey[(round * 16) + 2]; + buf2 = state[6] ^ expandedKey[(round * 16) + 6]; + state[2] = sbox[(state[10] ^ expandedKey[(round * 16) + 10])]; + state[6] = sbox[(state[14] ^ expandedKey[(round * 16) + 14])]; state[10] = sbox[buf1]; state[14] = sbox[buf2]; - // row 3 - buf1 = state[15] ^ expandedKey[(round*16) + 15]; - state[15] = sbox[(state[11] ^ expandedKey[(round*16) + 11])]; - state[11] = sbox[(state[ 7] ^ expandedKey[(round*16) + 7])]; - state[ 7] = sbox[(state[ 3] ^ expandedKey[(round*16) + 3])]; - state[ 3] = sbox[buf1]; - // last addroundkey - state[ 0]^=expandedKey[160]; - state[ 1]^=expandedKey[161]; - state[ 2]^=expandedKey[162]; - state[ 3]^=expandedKey[163]; - state[ 4]^=expandedKey[164]; - state[ 5]^=expandedKey[165]; - state[ 6]^=expandedKey[166]; - state[ 7]^=expandedKey[167]; - state[ 8]^=expandedKey[168]; - state[ 9]^=expandedKey[169]; - state[10]^=expandedKey[170]; - state[11]^=expandedKey[171]; - state[12]^=expandedKey[172]; - state[13]^=expandedKey[173]; - state[14]^=expandedKey[174]; - state[15]^=expandedKey[175]; + + /* Row 3 */ + + buf1 = state[15] ^ expandedKey[(round * 16) + 15]; + state[15] = sbox[(state[11] ^ expandedKey[(round * 16) + 11])]; + state[11] = sbox[(state[7] ^ expandedKey[(round * 16) + 7])]; + state[7] = sbox[(state[3] ^ expandedKey[(round * 16) + 3])]; + state[3] = sbox[buf1]; + + /* Last addroundkey */ + + state[0] ^= expandedKey[160]; + state[1] ^= expandedKey[161]; + state[2] ^= expandedKey[162]; + state[3] ^= expandedKey[163]; + state[4] ^= expandedKey[164]; + state[5] ^= expandedKey[165]; + state[6] ^= expandedKey[166]; + state[7] ^= expandedKey[167]; + state[8] ^= expandedKey[168]; + state[9] ^= expandedKey[169]; + state[10] ^= expandedKey[170]; + state[11] ^= expandedKey[171]; + state[12] ^= expandedKey[172]; + state[13] ^= expandedKey[173]; + state[14] ^= expandedKey[174]; + state[15] ^= expandedKey[175]; } -//***************************************************************************** -// -//! aes_decr -//! -//! @param[in] expandedKey expanded AES128 key -//! @param[in\out] state 16 bytes of cipher text and plain text -//! -//! @return none -//! -//! @brief internal implementation of AES128 decryption. -//! straight forward aes decryption implementation -//! the order of substeps is the exact reverse of decryption -//! inverse functions: -//! - addRoundKey is its own inverse -//! - rsbox is inverse of sbox -//! - rightshift instead of leftshift -//! - invMixColumns = barreto + mixColumns -//! no further subfunctions to save cycles for function calls -//! no structuring with "for (....)" to save cycles -//! -//***************************************************************************** +/****************************************************************************** + * Name: aes_decr + * + * Description: + * Internal implementation of AES128 decryption. + * Straight forward aes decryption implementation. The order of substeps is + * the exact reverse of decryption inverse functions: + * - addRoundKey is its own inverse + * - rsbox is inverse of sbox + * - rightshift instead of leftshift + * - invMixColumns = barreto + mixColumns + * No further subfunctions to save cycles for function calls no structuring + * with "for (....)" to save cycles + * + * Input Parameters: + * expandedKey expanded AES128 key + * state 16 bytes of cipher text and plain text + * + * Returned Value: + * None + * + ******************************************************************************/ void aes_decr(uint8_t *state, uint8_t *expandedKey) { @@ -323,124 +355,166 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) int8_t round; round = 9; - // initial addroundkey - state[ 0]^=expandedKey[160]; - state[ 1]^=expandedKey[161]; - state[ 2]^=expandedKey[162]; - state[ 3]^=expandedKey[163]; - state[ 4]^=expandedKey[164]; - state[ 5]^=expandedKey[165]; - state[ 6]^=expandedKey[166]; - state[ 7]^=expandedKey[167]; - state[ 8]^=expandedKey[168]; - state[ 9]^=expandedKey[169]; - state[10]^=expandedKey[170]; - state[11]^=expandedKey[171]; - state[12]^=expandedKey[172]; - state[13]^=expandedKey[173]; - state[14]^=expandedKey[174]; - state[15]^=expandedKey[175]; - - // 10th round without mixcols - state[ 0] = rsbox[state[ 0]] ^ expandedKey[(round*16) ]; - state[ 4] = rsbox[state[ 4]] ^ expandedKey[(round*16) + 4]; - state[ 8] = rsbox[state[ 8]] ^ expandedKey[(round*16) + 8]; - state[12] = rsbox[state[12]] ^ expandedKey[(round*16) + 12]; - // row 1 - buf1 = rsbox[state[13]] ^ expandedKey[(round*16) + 1]; - state[13] = rsbox[state[ 9]] ^ expandedKey[(round*16) + 13]; - state[ 9] = rsbox[state[ 5]] ^ expandedKey[(round*16) + 9]; - state[ 5] = rsbox[state[ 1]] ^ expandedKey[(round*16) + 5]; - state[ 1] = buf1; - // row 2 - buf1 = rsbox[state[ 2]] ^ expandedKey[(round*16) + 10]; - buf2 = rsbox[state[ 6]] ^ expandedKey[(round*16) + 14]; - state[ 2] = rsbox[state[10]] ^ expandedKey[(round*16) + 2]; - state[ 6] = rsbox[state[14]] ^ expandedKey[(round*16) + 6]; + /* Initial addroundkey */ + + state[0] ^= expandedKey[160]; + state[1] ^= expandedKey[161]; + state[2] ^= expandedKey[162]; + state[3] ^= expandedKey[163]; + state[4] ^= expandedKey[164]; + state[5] ^= expandedKey[165]; + state[6] ^= expandedKey[166]; + state[7] ^= expandedKey[167]; + state[8] ^= expandedKey[168]; + state[9] ^= expandedKey[169]; + state[10] ^= expandedKey[170]; + state[11] ^= expandedKey[171]; + state[12] ^= expandedKey[172]; + state[13] ^= expandedKey[173]; + state[14] ^= expandedKey[174]; + state[15] ^= expandedKey[175]; + + /* 10th round without mixcols */ + + state[0] = rsbox[state[0]] ^ expandedKey[(round * 16)]; + state[4] = rsbox[state[4]] ^ expandedKey[(round * 16) + 4]; + state[8] = rsbox[state[8]] ^ expandedKey[(round * 16) + 8]; + state[12] = rsbox[state[12]] ^ expandedKey[(round * 16) + 12]; + + /* Row 1 */ + + buf1 = rsbox[state[13]] ^ expandedKey[(round * 16) + 1]; + state[13] = rsbox[state[9]] ^ expandedKey[(round * 16) + 13]; + state[9] = rsbox[state[5]] ^ expandedKey[(round * 16) + 9]; + state[5] = rsbox[state[1]] ^ expandedKey[(round * 16) + 5]; + state[1] = buf1; + + /* Row 2 */ + + buf1 = rsbox[state[2]] ^ expandedKey[(round * 16) + 10]; + buf2 = rsbox[state[6]] ^ expandedKey[(round * 16) + 14]; + state[2] = rsbox[state[10]] ^ expandedKey[(round * 16) + 2]; + state[6] = rsbox[state[14]] ^ expandedKey[(round * 16) + 6]; state[10] = buf1; state[14] = buf2; - // row 3 - buf1 = rsbox[state[ 3]] ^ expandedKey[(round*16) + 15]; - state[ 3] = rsbox[state[ 7]] ^ expandedKey[(round*16) + 3]; - state[ 7] = rsbox[state[11]] ^ expandedKey[(round*16) + 7]; - state[11] = rsbox[state[15]] ^ expandedKey[(round*16) + 11]; - state[15] = buf1; - for (round = 8; round >= 0; round--){ - // barreto - //col1 - buf1 = galois_mul2(galois_mul2(state[0]^state[2])); - buf2 = galois_mul2(galois_mul2(state[1]^state[3])); - state[0] ^= buf1; state[1] ^= buf2; state[2] ^= buf1; state[3] ^= buf2; - //col2 - buf1 = galois_mul2(galois_mul2(state[4]^state[6])); - buf2 = galois_mul2(galois_mul2(state[5]^state[7])); - state[4] ^= buf1; state[5] ^= buf2; state[6] ^= buf1; state[7] ^= buf2; - //col3 - buf1 = galois_mul2(galois_mul2(state[8]^state[10])); - buf2 = galois_mul2(galois_mul2(state[9]^state[11])); - state[8] ^= buf1; state[9] ^= buf2; state[10] ^= buf1; state[11] ^= buf2; - //col4 - buf1 = galois_mul2(galois_mul2(state[12]^state[14])); - buf2 = galois_mul2(galois_mul2(state[13]^state[15])); - state[12] ^= buf1; state[13] ^= buf2; state[14] ^= buf1; state[15] ^= buf2; - // mixcolums ////////// - // col1 - buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; - buf2 = state[0]; - buf3 = state[0]^state[1]; buf3=galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; - buf3 = state[1]^state[2]; buf3=galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; - buf3 = state[2]^state[3]; buf3=galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; - buf3 = state[3]^buf2; buf3=galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; - // col2 - buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; - buf2 = state[4]; - buf3 = state[4]^state[5]; buf3=galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; - buf3 = state[5]^state[6]; buf3=galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; - buf3 = state[6]^state[7]; buf3=galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; - buf3 = state[7]^buf2; buf3=galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; - // col3 - buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; - buf2 = state[8]; - buf3 = state[8]^state[9]; buf3=galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; - buf3 = state[9]^state[10]; buf3=galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; - buf3 = state[10]^state[11]; buf3=galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; - buf3 = state[11]^buf2; buf3=galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; - // col4 - buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; - buf2 = state[12]; - buf3 = state[12]^state[13]; buf3=galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; - buf3 = state[13]^state[14]; buf3=galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; - buf3 = state[14]^state[15]; buf3=galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; - buf3 = state[15]^buf2; buf3=galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; - - // addroundkey, rsbox and shiftrows - // row 0 - state[ 0] = rsbox[state[ 0]] ^ expandedKey[(round*16) ]; - state[ 4] = rsbox[state[ 4]] ^ expandedKey[(round*16) + 4]; - state[ 8] = rsbox[state[ 8]] ^ expandedKey[(round*16) + 8]; - state[12] = rsbox[state[12]] ^ expandedKey[(round*16) + 12]; - // row 1 - buf1 = rsbox[state[13]] ^ expandedKey[(round*16) + 1]; - state[13] = rsbox[state[ 9]] ^ expandedKey[(round*16) + 13]; - state[ 9] = rsbox[state[ 5]] ^ expandedKey[(round*16) + 9]; - state[ 5] = rsbox[state[ 1]] ^ expandedKey[(round*16) + 5]; - state[ 1] = buf1; - // row 2 - buf1 = rsbox[state[ 2]] ^ expandedKey[(round*16) + 10]; - buf2 = rsbox[state[ 6]] ^ expandedKey[(round*16) + 14]; - state[ 2] = rsbox[state[10]] ^ expandedKey[(round*16) + 2]; - state[ 6] = rsbox[state[14]] ^ expandedKey[(round*16) + 6]; - state[10] = buf1; - state[14] = buf2; - // row 3 - buf1 = rsbox[state[ 3]] ^ expandedKey[(round*16) + 15]; - state[ 3] = rsbox[state[ 7]] ^ expandedKey[(round*16) + 3]; - state[ 7] = rsbox[state[11]] ^ expandedKey[(round*16) + 7]; - state[11] = rsbox[state[15]] ^ expandedKey[(round*16) + 11]; - state[15] = buf1; - } + /* Row 3 */ + + buf1 = rsbox[state[3]] ^ expandedKey[(round * 16) + 15]; + state[3] = rsbox[state[7]] ^ expandedKey[(round * 16) + 3]; + state[7] = rsbox[state[11]] ^ expandedKey[(round * 16) + 7]; + state[11] = rsbox[state[15]] ^ expandedKey[(round * 16) + 11]; + state[15] = buf1; + for (round = 8; round >= 0; round--) + { + /* barreto */ + /* Col1 */ + + buf1 = galois_mul2(galois_mul2(state[0] ^ state[2])); + buf2 = galois_mul2(galois_mul2(state[1] ^ state[3])); + state[0] ^= buf1; + state[1] ^= buf2; + state[2] ^= buf1; + state[3] ^= buf2; + + /* Col2 */ + + buf1 = galois_mul2(galois_mul2(state[4] ^ state[6])); + buf2 = galois_mul2(galois_mul2(state[5] ^ state[7])); + state[4] ^= buf1; + state[5] ^= buf2; + state[6] ^= buf1; + state[7] ^= buf2; + + /* Col3 */ + + buf1 = galois_mul2(galois_mul2(state[8] ^ state[10])); + buf2 = galois_mul2(galois_mul2(state[9] ^ state[11])); + state[8] ^= buf1; + state[9] ^= buf2; + state[10] ^= buf1; + state[11] ^= buf2; + + /* Col4 */ + + buf1 = galois_mul2(galois_mul2(state[12] ^ state[14])); + buf2 = galois_mul2(galois_mul2(state[13] ^ state[15])); + state[12] ^= buf1; + state[13] ^= buf2; + state[14] ^= buf1; + state[15] ^= buf2; + + /* mixcolums */ + /* Col1 */ + + buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; + buf2 = state[0]; + buf3 = state[0] ^ state[1]; buf3 = galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; + buf3 = state[1] ^ state[2]; buf3 = galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; + buf3 = state[2] ^ state[3]; buf3 = galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; + buf3 = state[3] ^ buf2; buf3 = galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; + + /* Col2 */ + + buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; + buf2 = state[4]; + buf3 = state[4] ^ state[5]; buf3 = galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; + buf3 = state[5] ^ state[6]; buf3 = galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; + buf3 = state[6] ^ state[7]; buf3 = galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; + buf3 = state[7] ^ buf2; buf3 = galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; + + /* Col3 */ + + buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; + buf2 = state[8]; + buf3 = state[8] ^ state[9]; buf3 = galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; + buf3 = state[9] ^ state[10]; buf3 = galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; + buf3 = state[10] ^ state[11]; buf3 = galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; + buf3 = state[11] ^ buf2; buf3 = galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; + + /* Col4 */ + + buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; + buf2 = state[12]; + buf3 = state[12] ^ state[13]; buf3 = galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; + buf3 = state[13] ^ state[14]; buf3 = galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; + buf3 = state[14] ^ state[15]; buf3 = galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; + buf3 = state[15] ^ buf2; buf3 = galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; + + /* addroundkey, rsbox and shiftrows */ + /* Row 0 */ + + state[0] = rsbox[state[0]] ^ expandedKey[(round * 16)]; + state[4] = rsbox[state[4]] ^ expandedKey[(round * 16) + 4]; + state[8] = rsbox[state[8]] ^ expandedKey[(round * 16) + 8]; + state[12] = rsbox[state[12]] ^ expandedKey[(round * 16) + 12]; + + /* Row 1 */ + + buf1 = rsbox[state[13]] ^ expandedKey[(round * 16) + 1]; + state[13] = rsbox[state[9]] ^ expandedKey[(round * 16) + 13]; + state[9] = rsbox[state[5]] ^ expandedKey[(round * 16) + 9]; + state[5] = rsbox[state[1]] ^ expandedKey[(round * 16) + 5]; + state[1] = buf1; + + /* Row 2 */ + + buf1 = rsbox[state[2]] ^ expandedKey[(round * 16) + 10]; + buf2 = rsbox[state[6]] ^ expandedKey[(round * 16) + 14]; + state[2] = rsbox[state[10]] ^ expandedKey[(round * 16) + 2]; + state[6] = rsbox[state[14]] ^ expandedKey[(round * 16) + 6]; + state[10] = buf1; + state[14] = buf2; + + /* Row 3 */ + + buf1 = rsbox[state[3]] ^ expandedKey[(round * 16) + 15]; + state[3] = rsbox[state[7]] ^ expandedKey[(round * 16) + 3]; + state[7] = rsbox[state[11]] ^ expandedKey[(round * 16) + 7]; + state[11] = rsbox[state[15]] ^ expandedKey[(round * 16) + 11]; + state[15] = buf1; + } } /**************************************************************************** @@ -462,7 +536,8 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) void aes_encrypt(uint8_t *state, uint8_t *key) { - // expand the key into 176 bytes + /* Expand the key into 176 bytes */ + expandKey(aexpandedKey, key); aes_encr(state, aexpandedKey); } @@ -486,8 +561,8 @@ void aes_encrypt(uint8_t *state, uint8_t *key) void aes_decrypt(uint8_t *state, uint8_t *key) { - expandKey(aexpandedKey, key); // expand the key into 176 bytes - aes_decr(state, aexpandedKey); + expandKey(aexpandedKey, key); /* Expand the key into 176 bytes */ + aes_decr(state, aexpandedKey); } /**************************************************************************** @@ -538,4 +613,4 @@ signed long aes_write_key(uint8_t *key) return returnValue; } -#endif //CC3000_UNENCRYPTED_SMART_CONFIG +#endif /* CC3000_UNENCRYPTED_SMART_CONFIG */ diff --git a/drivers/wireless/cc3000/socket.c b/drivers/wireless/cc3000/socket.c index aa8b10af9a..9653d06ed7 100644 --- a/drivers/wireless/cc3000/socket.c +++ b/drivers/wireless/cc3000/socket.c @@ -167,7 +167,7 @@ int cc3000_socket(int domain, int type, int protocol) cc3000_lib_lock(); type = bsd2ti_types[type]; - sd = cc3000_socket_impl(domain,type,protocol); + sd = cc3000_socket_impl(domain, type, protocol); #ifdef CONFIG_CC3000_MT cc3000_add_socket(sd); #endif @@ -271,12 +271,12 @@ int cc3000_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return -errno; } - memset(addr,0,*addrlen); - return cc3000_accept_socket(sockfd,addr,addrlen); + memset(addr, 0, *addrlen); + return cc3000_accept_socket(sockfd, addr, addrlen); } #else { - cc3000_accept_socket(sockfd,0); + cc3000_accept_socket(sockfd, 0); short nonBlocking = CC3000_SOCK_OFF; if (setsockopt(sockfd, CC3000_SOL_SOCKET, CC3000_SOCKOPT_ACCEPT_NONBLOCK, @@ -286,7 +286,7 @@ int cc3000_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return -errno; } - return cc3000_do_accept(int sockfd, addr, addrlen);; + return cc3000_do_accept(sockfd, addr, addrlen); } #endif @@ -352,7 +352,7 @@ int cc3000_listen(int sockfd, int backlog) int ret; cc3000_lib_lock(); - ret = cc3000_listen_impl(sockfd,backlog); + ret = cc3000_listen_impl(sockfd, backlog); cc3000_lib_unlock(); return ret; } @@ -436,8 +436,8 @@ int cc3000_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrle * ****************************************************************************/ -int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, - struct timeval *timeout) +int cc3000_select(int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout) { int ret; @@ -765,8 +765,10 @@ ssize_t cc3000_sendto(int sockfd, FAR const void *buf, size_t len, int flags, ****************************************************************************/ #ifndef CC3000_TINY_DRIVER -// TODO: Standard is struct hostent *gethostbyname(const char *name); -int cc3000_gethostbyname(char * hostname, uint16_t usNameLen, unsigned long* out_ip_addr) +/* REVISIT: Standard is struct hostent *gethostbyname(const char *name); */ + +int cc3000_gethostbyname(char *hostname, uint16_t usNameLen, + unsigned long *out_ip_addr) { int ret; diff --git a/drivers/wireless/cc3000/socket_imp.c b/drivers/wireless/cc3000/socket_imp.c index 3e810757d7..780a085eb8 100644 --- a/drivers/wireless/cc3000/socket_imp.c +++ b/drivers/wireless/cc3000/socket_imp.c @@ -514,7 +514,8 @@ long cc3000_listen_impl(long sd, long backlog) ****************************************************************************/ #ifndef CC3000_TINY_DRIVER -int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long* out_ip_addr) +int cc3000_gethostbyname_impl(char *hostname, uint16_t usNameLen, + unsigned long *out_ip_addr) { tBsdGethostbynameParams ret; uint8_t *ptr, *args; @@ -546,7 +547,7 @@ int cc3000_gethostbyname_impl(char * hostname, uint16_t usNameLen, unsigned long set_errno(ret.retVal); - (*((long*)out_ip_addr)) = ret.outputAddress; + (*((FAR long *)out_ip_addr)) = ret.outputAddress; return ret.retVal; } @@ -680,9 +681,9 @@ int cc3000_select_impl(long nfds, TICC3000fd_set *readsds, TICC3000fd_set *write args = UINT32_TO_STREAM(args, 0x00000014); args = UINT32_TO_STREAM(args, 0x00000014); args = UINT32_TO_STREAM(args, is_blocking); - args = UINT32_TO_STREAM(args, ((readsds) ? *(unsigned long*)readsds : 0)); - args = UINT32_TO_STREAM(args, ((writesds) ? *(unsigned long*)writesds : 0)); - args = UINT32_TO_STREAM(args, ((exceptsds) ? *(unsigned long*)exceptsds : 0)); + args = UINT32_TO_STREAM(args, ((readsds) ? *(FAR unsigned long *)readsds : 0)); + args = UINT32_TO_STREAM(args, ((writesds) ? *(FAR unsigned long *)writesds : 0)); + args = UINT32_TO_STREAM(args, ((exceptsds) ? *(FAR unsigned long *)exceptsds : 0)); if (timeout) { @@ -1078,7 +1079,7 @@ int simple_link_send(long sd, const void *buf, long len, long flags, /* Update the offset of data and parameters according to the command */ - switch(opcode) + switch (opcode) { case HCI_CMND_SENDTO: { @@ -1119,18 +1120,18 @@ int simple_link_send(long sd, const void *buf, long len, long flags, /* Copy the data received from user into the TX Buffer */ - ARRAY_TO_STREAM(pDataPtr, ((uint8_t *)buf), len); + ARRAY_TO_STREAM(pDataPtr, ((FAR uint8_t *)buf), len); /* In case we are using SendTo, copy the to parameters */ if (opcode == HCI_CMND_SENDTO) { - ARRAY_TO_STREAM(pDataPtr, ((uint8_t *)to), tolen); + ARRAY_TO_STREAM(pDataPtr, ((FAR uint8_t *)to), tolen); } /* Initiate a HCI command */ - hci_data_send(opcode, ptr, uArgSize, len,(uint8_t*)to, tolen); + hci_data_send(opcode, ptr, uArgSize, len, (FAR uint8_t *)to, tolen); if (opcode == HCI_CMND_SENDTO) { diff --git a/drivers/wireless/cc3000/wlan.c b/drivers/wireless/cc3000/wlan.c index 227a633cb4..6d9ad12997 100644 --- a/drivers/wireless/cc3000/wlan.c +++ b/drivers/wireless/cc3000/wlan.c @@ -222,7 +222,7 @@ void wlan_init(size_t max_tx_len, /* Init I/O callback */ /* Init asynchronous events callback */ - tSLInformation.sWlanCB= sWlanCB; + tSLInformation.sWlanCB = sWlanCB; /* By default TX Complete events are routed to host too */ @@ -624,7 +624,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t *ucSsid, unsigned long ulPriority, unsigned long ulPairwiseCipher_Or_TxKeyLen, unsigned long ulGroupCipher_TxKeyIndex, - unsigned long ulKeyMgmt, uint8_t* ucPf_OrKey, + unsigned long ulKeyMgmt, uint8_t *ucPf_OrKey, unsigned long ulPassPhraseLen) { uint16_t arg_len = 0; @@ -702,7 +702,7 @@ long wlan_add_profile(unsigned long ulSecType, uint8_t *ucSsid, } break; - /*WPA, WPA2 */ + /* WPA, WPA2 */ case WLAN_SEC_WPA: case WLAN_SEC_WPA2: @@ -907,7 +907,8 @@ long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime, unsigned long uiMaxDwellTime, unsigned long uiNumOfProbeRequests, - unsigned long uiChannelMask,long iRSSIThreshold, + unsigned long uiChannelMask, + long iRSSIThreshold, unsigned long uiSNRThreshold, unsigned long uiDefaultTxPower, unsigned long *aiIntervalList) @@ -1163,7 +1164,7 @@ long wlan_smart_config_stop(void) * ****************************************************************************/ -long wlan_smart_config_set_prefix(char* cNewPrefix) +long wlan_smart_config_set_prefix(FAR char *cNewPrefix) { long ret; uint8_t *ptr; diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index ad5bdcc3b3..607a56a1aa 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -325,7 +325,7 @@ static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi) * As we own the SPI bus this method is called just once. */ - SPI_SELECT(spi, SPIDEV_WIRELESS, true); // Useful ? + SPI_SELECT(spi, SPIDEV_WIRELESS, true); /* Useful ? */ SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, 8); SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); @@ -663,7 +663,7 @@ static void nrf24l01_tostate(struct nrf24l01_dev_s *dev, nrf24l01_state_t state) /* Entering new state */ - switch(state) + switch (state) { case ST_UNKNOWN: /* Power down the module here... */ @@ -980,7 +980,7 @@ static int nrf24l01_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; case NRF24L01IOC_GETRETRCFG: /* Get retransmit params. arg: Pointer to nrf24l01_retrcfg_t */ - result = -ENOSYS; /* TODO !*/ + result = -ENOSYS; /* TODO */ break; case NRF24L01IOC_SETPIPESCFG: @@ -1053,7 +1053,7 @@ static int nrf24l01_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } case NRF24L01IOC_GETDATARATE: - result = -ENOSYS; /* TODO !*/ + result = -ENOSYS; /* TODO */ break; case NRF24L01IOC_SETADDRWIDTH: @@ -1351,7 +1351,8 @@ int nrf24l01_init(FAR struct nrf24l01_dev_s *dev) /* Clear interrupt sources (useful ?) */ - nrf24l01_writeregbyte(dev, NRF24L01_STATUS, NRF24L01_RX_DR|NRF24L01_TX_DS|NRF24L01_MAX_RT); + nrf24l01_writeregbyte(dev, NRF24L01_STATUS, + NRF24L01_RX_DR | NRF24L01_TX_DS | NRF24L01_MAX_RT); out: nrf24l01_unlock(dev->spi); @@ -1523,7 +1524,7 @@ int nrf24l01_settxpower(FAR struct nrf24l01_dev_s *dev, int outpower) * '11' – 0dBm */ - switch(outpower) + switch (outpower) { case 0: hwpow = 3 << NRF24L01_RF_PWR_SHIFT; -- GitLab From 796d52b3e106e640f2271463928dbe03b2e451c5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 12:24:31 -0600 Subject: [PATCH 214/858] Fix a typo introduced with last commits --- arch | 2 +- configs | 2 +- drivers/net/dm90x0.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 07f1151a80..8a9c89d35a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 07f1151a8039a32ff09fe479869b268dd11ed514 +Subproject commit 8a9c89d35a4babc8f45687e5293e01e56126ed8c diff --git a/configs b/configs index 20921ccad2..b16519ea24 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 20921ccad2cf456d6828d5d9f4ec8763a5f31f1f +Subproject commit b16519ea24e26d50c61202ea80802a0417daeb11 diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index 0f22470bae..fd785e9e77 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -478,7 +478,7 @@ static void read16(FAR uint8_t *ptr, int len) } } -static void read32(FARuint8_t *ptr, int len) +static void read32(FAR uint8_t *ptr, int len) { FAR uint32_t *ptr32 = (FAR uint32_t *)ptr; -- GitLab From cdc646ae68777c0938db21c112c8ab864ffa77da Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 12:31:31 -0600 Subject: [PATCH 215/858] Another typo introduced in previous commit --- drivers/wireless/cc3000/security.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/wireless/cc3000/security.c b/drivers/wireless/cc3000/security.c index 90152ac8fa..bd30a78121 100644 --- a/drivers/wireless/cc3000/security.c +++ b/drivers/wireless/cc3000/security.c @@ -131,7 +131,7 @@ void expandKey(uint8_t *expandedKey, uint8_t *key) expandedKey[ii * 16 + 0] = sbox[expandedKey[ii *16 - 3]] ^ expandedKey[(ii - 1) * 16 + 0] ^ Rcon[ii]; expandedKey[ii * 16 + 1] = sbox[expandedKey[ii *16 - 2]] ^ expandedKey[(ii - 1) * 16 + 1]; expandedKey[ii * 16 + 2] = sbox[expandedKey[ii *16 - 1]] ^ expandedKey[(ii - 1) * 16 + 2]; - expandedKey[ii * 16 + 3] = sbox[buf1] ^ expandedKey[(ii - 1) *1 6 + 3]; + expandedKey[ii * 16 + 3] = sbox[buf1] ^ expandedKey[(ii - 1) * 16 + 3]; expandedKey[ii * 16 + 4] = expandedKey[(ii - 1) * 16 + 4] ^ expandedKey[ii * 16 + 0]; expandedKey[ii * 16 + 5] = expandedKey[(ii - 1) * 16 + 5] ^ expandedKey[ii * 16 + 1]; expandedKey[ii * 16 + 6] = expandedKey[(ii - 1) * 16 + 6] ^ expandedKey[ii * 16 + 2]; -- GitLab From f0be2b7b098ae64010ffcd6b723d31853bd500c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 14:14:25 -0600 Subject: [PATCH 216/858] TMPFS: Fix error in reallocted directory --- fs/tmpfs/fs_tmpfs.c | 58 ++++++++++++++++++++++++++++----------------- fs/tmpfs/fs_tmpfs.h | 2 +- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index be8e01e02d..5e7641d0a5 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -349,6 +349,11 @@ static int tmpfs_realloc_directory(FAR struct tmpfs_directory_s **tdo, newtdo->tdo_nentries = nentries; *tdo = newtdo; + /* Adjust the reference in the parent directory entry */ + + DEBUGASSERT(newtdo->tdo_dirent); + newtdo->tdo_dirent->tde_object = (FAR struct tmpfs_object_s *)newtdo; + /* Return the index to the first, newly allocated directory entry */ return ret; @@ -413,7 +418,7 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, /* Adjust the reference in the parent directory entry */ DEBUGASSERT(newtfo->tfo_dirent); - newtfo->tfo_dirent->tde_object = (FAR struct tmpfs_object_s *)tfo; + newtfo->tfo_dirent->tde_object = (FAR struct tmpfs_object_s *)newtfo; /* Return the new address of the reallocated file object */ @@ -665,7 +670,7 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, /* No subdirectories... use the root directory */ name = copy; - parent = fs->tfs_root; + parent = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; /* Lock the root directory to emulate the behavior of tmpfs_find_directory() */ @@ -823,7 +828,7 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, /* No subdirectories... use the root directory */ name = copy; - parent = fs->tfs_root; + parent = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; tmpfs_lock_directory(parent); parent->tdo_refs++; @@ -942,8 +947,8 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, /* Traverse the file system for any object with the matching name */ - to = (FAR struct tmpfs_object_s *)fs->tfs_root; - next_tdo = fs->tfs_root; + to = fs->tfs_root.tde_object; + next_tdo = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; for (segment = strtok_r(copy, "/", &tkptr); segment != NULL; @@ -1351,7 +1356,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, inode = filep->f_inode; fs = inode->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -1765,7 +1770,7 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Get the mountpoint private data from the inode structure */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -1914,6 +1919,7 @@ static int tmpfs_rewinddir(FAR struct inode *mountpt, static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, FAR void **handle) { + FAR struct tmpfs_directory_s *tdo; FAR struct tmpfs_s *fs; fvdbg("blkdriver: %p data: %p handle: %p\n", blkdriver, data, handle); @@ -1927,15 +1933,24 @@ static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data, return -ENOMEM; } - /* Create a root file system */ + /* Create a root file system. This is like a single directory entry in + * the file system structure. + */ - fs->tfs_root = tmpfs_alloc_directory(); - if (fs->tfs_root == NULL) + tdo = tmpfs_alloc_directory(); + if (tdo == NULL) { kmm_free(fs); return -ENOMEM; } + fs->tfs_root.tde_object = (FAR struct tmpfs_object_s *)tdo; + fs->tfs_root.tde_name = ""; + + /* Set up the backward link (to support reallocation) */ + + tdo->tdo_dirent = &fs->tfs_root; + /* Initialize the file system state */ fs->tfs_exclsem.ts_holder = TMPFS_NO_HOLDER; @@ -1961,7 +1976,7 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, fvdbg("handle: %p blkdriver: %p flags: %02x\n", handle, blkdriver, flags); - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Lock the file system */ @@ -1969,7 +1984,7 @@ static int tmpfs_unbind(FAR void *handle, FAR struct inode **blkdriver, /* Traverse all directory entries (recursively), freeing all resources. */ - tdo = fs->tfs_root; + tdo = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; ret = tmpfs_foreach(tdo, tmpfs_free_callout, NULL); /* Now we can destroy the root file system and the file system itself. */ @@ -2003,7 +2018,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -2011,7 +2026,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) /* Set up the memory use for the file system and root directory object */ - tdo = fs->tfs_root; + tdo = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; inuse = sizeof(struct tmpfs_s) + SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries); avail = sizeof(struct tmpfs_s) + @@ -2024,8 +2039,7 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) /* Traverse the file system to accurmulate statistics */ - ret = tmpfs_foreach(fs->tfs_root, tmpfs_statfs_callout, - (FAR void *)&tmpbuf); + ret = tmpfs_foreach(tdo, tmpfs_statfs_callout, (FAR void *)&tmpbuf); if (ret < 0) { return -ECANCELED; @@ -2071,7 +2085,7 @@ static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -2171,7 +2185,7 @@ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -2202,7 +2216,7 @@ static int tmpfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ @@ -2304,7 +2318,7 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Duplicate the newpath variable so that we can modify it */ @@ -2328,7 +2342,7 @@ static int tmpfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, /* No subdirectories... use the root directory */ newname = copy; - newparent = fs->tfs_root; + newparent = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; tmpfs_lock_directory(newparent); newparent->tdo_refs++; @@ -2442,7 +2456,7 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR const char *relpath, /* Get the file system structure from the inode reference. */ fs = mountpt->i_private; - DEBUGASSERT(fs != NULL && fs->tfs_root != NULL); + DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL); /* Get exclusive access to the file system */ diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h index 5654136490..8e4b1a32f5 100644 --- a/fs/tmpfs/fs_tmpfs.h +++ b/fs/tmpfs/fs_tmpfs.h @@ -165,7 +165,7 @@ struct tmpfs_s { /* The root directory */ - FAR struct tmpfs_directory_s *tfs_root; + FAR struct tmpfs_dirent_s tfs_root; struct tmpfs_sem_s tfs_exclsem; }; -- GitLab From d6fa78a1b05a5e03ef51fbab321529c9a52e2ef6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 15:26:07 -0600 Subject: [PATCH 217/858] TMPFS: Fixes several bugs --- configs | 2 +- fs/tmpfs/fs_tmpfs.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs b/configs index b16519ea24..20921ccad2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b16519ea24e26d50c61202ea80802a0417daeb11 +Subproject commit 20921ccad2cf456d6828d5d9f4ec8763a5f31f1f diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 5e7641d0a5..9984cc5d65 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -409,7 +409,7 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, /* Realloc the file object */ - newtfo = (FAR struct tmpfs_file_s *)kmm_realloc(oldtfo, objsize); + newtfo = (FAR struct tmpfs_file_s *)kmm_realloc(oldtfo, allocsize); if (newtfo == NULL) { return -ENOMEM; @@ -423,7 +423,7 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s **tfo, /* Return the new address of the reallocated file object */ newtfo->tfo_alloc = allocsize; - newtfo->tfo_size = objsize; + newtfo->tfo_size = newsize; *tfo = newtfo; return OK; } @@ -1558,7 +1558,7 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer, /* Copy data from the memory object to the user buffer */ - memcpy(buffer, &tfo->tfo_data, nread); + memcpy(buffer, &tfo->tfo_data[startpos], nread); filep->f_pos += nread; /* Release the lock on the file */ @@ -1613,7 +1613,7 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer, /* Copy data from the memory object to the user buffer */ - memcpy(&tfo->tfo_data, buffer, nwritten); + memcpy(&tfo->tfo_data[startpos], buffer, nwritten); filep->f_pos += nwritten; /* Release the lock on the file */ -- GitLab From 838f9e5a1875fc35e91ec6de8f64c45b43b9fd4f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 17:04:38 -0600 Subject: [PATCH 218/858] TMPFS: Fix yet another bug --- configs | 2 +- fs/tmpfs/fs_tmpfs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configs b/configs index 20921ccad2..b16519ea24 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 20921ccad2cf456d6828d5d9f4ec8763a5f31f1f +Subproject commit b16519ea24e26d50c61202ea80802a0417daeb11 diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 9984cc5d65..4c2b78ef4b 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1734,7 +1734,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) /* Recover our private data from the struct file instance */ - tfo = oldp->f_inode->i_private; + tfo = oldp->f_priv; DEBUGASSERT(tfo != NULL); /* Increment the reference count (atomically)*/ @@ -1748,7 +1748,7 @@ static int tmpfs_dup(FAR const struct file *oldp, FAR struct file *newp) * structures so there is not really much to the dup operation. */ - newp->f_inode->i_private = tfo; + newp->f_priv = tfo; return OK; } -- GitLab From 6a2098d35c1380e75e911db62d548a16b2455dcd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 18:01:14 -0600 Subject: [PATCH 219/858] TMPFS: Fix a memory leak --- fs/tmpfs/fs_tmpfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 4c2b78ef4b..f1b62e6976 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -974,6 +974,7 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, { /* No object with this name exists in the directory. */ + kmm_free(copy); return index; } @@ -993,10 +994,11 @@ static int tmpfs_find_object(FAR struct tmpfs_s *fs, } /* No, this was not the final segement of the relpath. - * We cannot continue the search if any of the intermidate - * segements do no correspond to directories. + * We cannot continue the search if any of the intermediate + * segments do no correspond to directories. */ + kmm_free(copy); return -ENOTDIR; } -- GitLab From 2c385b81f8a910cabc069b55ad06d3a9730310b9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 18:39:43 -0600 Subject: [PATCH 220/858] TMPFS: Yet another memory leak --- fs/tmpfs/fs_tmpfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index f1b62e6976..947ea028f2 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -2437,6 +2437,7 @@ errout_with_newparent: errout_with_lock: tmpfs_unlock(fs); + kmm_free(copy); return ret; } -- GitLab From 185b941c2766b59b9e0e14fc0f0fc273f201b4d4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 11 Oct 2015 10:29:35 -0600 Subject: [PATCH 221/858] TMPFS: In open write/append mode, need to set the file position to the end of the file --- fs/tmpfs/fs_tmpfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 947ea028f2..529cdd5ee7 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1346,6 +1346,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, FAR struct inode *inode; FAR struct tmpfs_s *fs; FAR struct tmpfs_file_s *tfo; + off_t offset; int ret; fvdbg("filep: %p\n", filep); @@ -1456,6 +1457,18 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, filep->f_priv = tfo; + /* In write/append mode, we need to set the file pointer to the end of the + * file. + */ + + offset = 0; + if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + { + offset = tfo->tfo_size; + } + + filep->f_pos = offset; + /* Unlock the file file object, but retain the reference count */ tmpfs_unlock_file(tfo); -- GitLab From c70987e551ef3044809a54f8f09f34759fd0f88e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 11 Oct 2015 11:39:29 -0600 Subject: [PATCH 222/858] nuttx/fs: Fix some spacing and alignment issues --- fs/binfs/fs_binfs.c | 5 +- fs/dirent/fs_opendir.c | 6 +- fs/dirent/fs_seekdir.c | 4 +- fs/driver/fs_devsyslog.c | 5 +- fs/fat/fs_fat32.c | 33 ++-- fs/fat/fs_fat32attrib.c | 6 +- fs/fat/fs_fat32dirent.c | 206 ++++++++++----------- fs/fat/fs_fat32util.c | 77 ++++---- fs/fat/fs_mkfatfs.c | 4 +- fs/fat/fs_writefat.c | 8 +- fs/inode/fs_files.c | 2 +- fs/inode/fs_inode.c | 28 +-- fs/inode/fs_inodebasename.c | 2 +- fs/inode/fs_inodereserve.c | 18 +- fs/mmap/fs_mmap.c | 4 +- fs/mmap/fs_munmap.c | 2 +- fs/mmap/fs_rammap.c | 32 ++-- fs/mqueue/mq_close.c | 28 +-- fs/mqueue/mq_open.c | 12 +- fs/nfs/nfs_util.c | 10 +- fs/nfs/nfs_vfsops.c | 53 +++--- fs/nfs/rpc_clnt.c | 6 +- fs/nxffs/nxffs_blockstats.c | 4 +- fs/nxffs/nxffs_dump.c | 18 +- fs/nxffs/nxffs_initialize.c | 17 +- fs/nxffs/nxffs_inode.c | 4 +- fs/nxffs/nxffs_open.c | 18 +- fs/nxffs/nxffs_pack.c | 314 ++++++++++++++++----------------- fs/nxffs/nxffs_read.c | 2 +- fs/nxffs/nxffs_reformat.c | 4 +- fs/nxffs/nxffs_stat.c | 5 +- fs/nxffs/nxffs_write.c | 2 +- fs/procfs/fs_procfs.c | 56 +++--- fs/procfs/fs_procfscpuload.c | 2 +- fs/procfs/fs_procfsproc.c | 6 +- fs/procfs/fs_procfsuptime.c | 4 +- fs/procfs/fs_skeleton.c | 2 +- fs/romfs/fs_romfs.c | 22 +-- fs/romfs/fs_romfsutil.c | 20 +-- fs/semaphore/sem_close.c | 26 +-- fs/semaphore/sem_open.c | 12 +- fs/smartfs/smartfs_mksmartfs.c | 2 +- fs/smartfs/smartfs_procfs.c | 7 +- fs/smartfs/smartfs_smart.c | 11 +- fs/smartfs/smartfs_utils.c | 25 +-- fs/unionfs/fs_unionfs.c | 4 +- fs/vfs/fs_dup.c | 3 +- fs/vfs/fs_open.c | 2 +- fs/vfs/fs_read.c | 2 +- fs/vfs/fs_select.c | 2 +- fs/vfs/fs_stat.c | 12 +- 51 files changed, 594 insertions(+), 565 deletions(-) diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 5e5a09f576..8cd8b7e5c5 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -425,13 +425,14 @@ static int binfs_stat(struct inode *mountpt, const char *relpath, struct stat *b /* It's a execute-only file name */ - buf->st_mode = S_IFREG|S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR; } else { /* It's a read/execute-only directory name */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR | S_IXOTH | + S_IXGRP | S_IXUSR; } /* File/directory size, access block size */ diff --git a/fs/dirent/fs_opendir.c b/fs/dirent/fs_opendir.c index 00876012c6..5731ba632b 100644 --- a/fs/dirent/fs_opendir.c +++ b/fs/dirent/fs_opendir.c @@ -261,7 +261,7 @@ FAR DIR *opendir(FAR const char *path) if (!inode) { - /* 'path' is not a does not exist.*/ + /* 'path' is not a does not exist. */ ret = ENOTDIR; goto errout_with_semaphore; @@ -274,7 +274,7 @@ FAR DIR *opendir(FAR const char *path) dir = (FAR struct fs_dirent_s *)kumm_zalloc(sizeof(struct fs_dirent_s)); if (!dir) { - /* Insufficient memory to complete the operation.*/ + /* Insufficient memory to complete the operation. */ ret = ENOMEM; goto errout_with_semaphore; @@ -350,7 +350,7 @@ FAR DIR *opendir(FAR const char *path) } inode_semgive(); - return ((DIR*)dir); + return ((FAR DIR *)dir); /* Nasty goto's make error handling simpler */ diff --git a/fs/dirent/fs_seekdir.c b/fs/dirent/fs_seekdir.c index f58274f43a..761dba33cd 100644 --- a/fs/dirent/fs_seekdir.c +++ b/fs/dirent/fs_seekdir.c @@ -68,7 +68,7 @@ static inline void seekpseudodir(struct fs_dirent_s *idir, off_t offset) * "rewind" to the root dir. */ - if ( offset < idir->fd_position ) + if (offset < idir->fd_position) { pos = 0; curr = idir->fd_root; @@ -126,7 +126,7 @@ static inline void seekmountptdir(struct fs_dirent_s *idir, off_t offset) */ inode = idir->fd_root; - if ( offset < idir->fd_position ) + if (offset < idir->fd_position) { if (inode->u.i_mops && inode->u.i_mops->rewinddir) { diff --git a/fs/driver/fs_devsyslog.c b/fs/driver/fs_devsyslog.c index 991506fe0f..70b21a2c08 100644 --- a/fs/driver/fs_devsyslog.c +++ b/fs/driver/fs_devsyslog.c @@ -108,7 +108,10 @@ struct syslog_dev_s /* This is the device structure for the console or syslogging function. */ static struct syslog_dev_s g_sysdev; -static const uint8_t g_syscrlf[2] = { '\r', '\n' }; +static const uint8_t g_syscrlf[2] = +{ + '\r', '\n' +}; /**************************************************************************** * Private Functions diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index e4dfbe19b8..95a6ce04d5 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -229,7 +229,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, /* It would be an error if we are asked to create it exclusively */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { /* Already exists -- can't create it exclusively */ @@ -256,7 +256,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, * access is ignored. */ - if ((oflags & (O_TRUNC|O_WRONLY)) == (O_TRUNC|O_WRONLY)) + if ((oflags & (O_TRUNC | O_WRONLY)) == (O_TRUNC | O_WRONLY)) { /* Truncate the file to zero length */ @@ -314,7 +314,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, * file. */ - ff = (struct fat_file_s *)kmm_zalloc(sizeof(struct fat_file_s)); + ff = (FAR struct fat_file_s *)kmm_zalloc(sizeof(struct fat_file_s)); if (!ff) { ret = -ENOMEM; @@ -323,7 +323,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, /* Create a file buffer to support partial sector accesses */ - ff->ff_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize); + ff->ff_buffer = (FAR uint8_t *)fat_io_alloc(fs->fs_hwsectorsize); if (!ff->ff_buffer) { ret = -ENOMEM; @@ -366,7 +366,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, /* In write/append mode, we need to set the file pointer to the end of the file */ - if ((oflags & (O_APPEND|O_WRONLY)) == (O_APPEND|O_WRONLY)) + if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) { off_t offset = fat_seek(filep, ff->ff_size, SEEK_SET); if (offset < 0) @@ -482,7 +482,7 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer, unsigned int nsectors; size_t bytesleft; int32_t cluster; - FAR uint8_t *userbuffer = (uint8_t*)buffer; + FAR uint8_t *userbuffer = (FAR uint8_t *)buffer; int sectorindex; int ret; bool force_indirect = false; @@ -710,7 +710,7 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer, unsigned int byteswritten; unsigned int writesize; unsigned int nsectors; - FAR uint8_t *userbuffer = (uint8_t*)buffer; + FAR uint8_t *userbuffer = (FAR uint8_t *)buffer; int sectorindex; int ret; bool force_indirect = false; @@ -970,7 +970,7 @@ fat_write_restart: */ memcpy(&ff->ff_buffer[sectorindex], userbuffer, writesize); - ff->ff_bflags |= (FFBUFF_DIRTY|FFBUFF_VALID|FFBUFF_MODIFIED); + ff->ff_bflags |= (FFBUFF_DIRTY | FFBUFF_VALID | FFBUFF_MODIFIED); } /* Set up for the next write */ @@ -1119,7 +1119,7 @@ static off_t fat_seek(FAR struct file *filep, off_t offset, int whence) */ clustersize = fs->fs_fatsecperclus * fs->fs_hwsectorsize; - for (;;) + for (; ; ) { /* Skip over clusters prior to the one containing * the requested position. @@ -1436,7 +1436,7 @@ static int fat_dup(FAR const struct file *oldp, FAR struct file *newp) * dup'ed file. */ - newff = (struct fat_file_s *)kmm_malloc(sizeof(struct fat_file_s)); + newff = (FAR struct fat_file_s *)kmm_malloc(sizeof(struct fat_file_s)); if (!newff) { ret = -ENOMEM; @@ -1445,7 +1445,7 @@ static int fat_dup(FAR const struct file *oldp, FAR struct file *newp) /* Create a file buffer to support partial sector accesses */ - newff->ff_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize); + newff->ff_buffer = (FAR uint8_t *)fat_io_alloc(fs->fs_hwsectorsize); if (!newff->ff_buffer) { ret = -ENOMEM; @@ -1873,7 +1873,7 @@ static int fat_bind(FAR struct inode *blkdriver, FAR const void *data, return ret; } - *handle = (void*)fs; + *handle = (FAR void *)fs; fat_semgive(fs); return OK; } @@ -1889,7 +1889,7 @@ static int fat_bind(FAR struct inode *blkdriver, FAR const void *data, static int fat_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { - FAR struct fat_mountpt_s *fs = (FAR struct fat_mountpt_s*)handle; + FAR struct fat_mountpt_s *fs = (FAR struct fat_mountpt_s *)handle; if (!fs) { @@ -2525,7 +2525,8 @@ static int fat_stat(FAR struct inode *mountpt, FAR const char *relpath, { /* It's directory name of the mount point */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IWOTH|S_IWGRP|S_IWUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR | S_IWOTH | + S_IWGRP | S_IWUSR; ret = OK; goto errout_with_semaphore; } @@ -2544,10 +2545,10 @@ static int fat_stat(FAR struct inode *mountpt, FAR const char *relpath, * by everyone but may be writeable by no-one. */ - buf->st_mode = S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IROTH | S_IRGRP | S_IRUSR; if ((attribute & FATATTR_READONLY) == 0) { - buf->st_mode |= S_IWOTH|S_IWGRP|S_IWUSR; + buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR; } /* We will report only types file or directory */ diff --git a/fs/fat/fs_fat32attrib.c b/fs/fat/fs_fat32attrib.c index 1880dc6819..ef9b90b474 100644 --- a/fs/fat/fs_fat32attrib.c +++ b/fs/fat/fs_fat32attrib.c @@ -128,8 +128,10 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib, /* Set or clear any bits as requested */ - newattributes &= ~(clearbits & (FATATTR_READONLY|FATATTR_HIDDEN|FATATTR_SYSTEM|FATATTR_ARCHIVE)); - newattributes |= (setbits & (FATATTR_READONLY|FATATTR_HIDDEN|FATATTR_SYSTEM|FATATTR_ARCHIVE)); + newattributes &= ~(clearbits & (FATATTR_READONLY | FATATTR_HIDDEN | + FATATTR_SYSTEM | FATATTR_ARCHIVE)); + newattributes |= (setbits & (FATATTR_READONLY | FATATTR_HIDDEN | + FATATTR_SYSTEM | FATATTR_ARCHIVE)); /* Did any thingchange? */ diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c index 9d349c9495..586c60d8ee 100644 --- a/fs/fat/fs_fat32dirent.c +++ b/fs/fat/fs_fat32dirent.c @@ -271,7 +271,7 @@ static inline int fat_parsesfname(const char **path, /* Loop until the name is successfully parsed or an error occurs */ endndx = 8; - for (;;) + for (; ; ) { /* Get the next byte from the path */ @@ -279,7 +279,7 @@ static inline int fat_parsesfname(const char **path, /* Check if this the last byte in this node of the name */ - if ((ch == '\0' || ch == '/') && ndx != 0 ) + if ((ch == '\0' || ch == '/') && ndx != 0) { /* Return the accumulated NT flags and the terminating character */ @@ -348,12 +348,12 @@ static inline int fat_parsesfname(const char **path, goto errout; } - /* So far, only upper case in the name*/ + /* So far, only upper case in the name */ namecase = FATCASE_UPPER; #endif - /* Clear lower case name bit in mask*/ + /* Clear lower case name bit in mask */ ntlcenable &= ~FATNTRES_LCNAME; } @@ -369,7 +369,7 @@ static inline int fat_parsesfname(const char **path, goto errout; } - /* So far, only upper case in the extension*/ + /* So far, only upper case in the extension */ extcase = FATCASE_UPPER; #endif @@ -415,7 +415,7 @@ static inline int fat_parsesfname(const char **path, goto errout; } - /* So far, only lower case in the name*/ + /* So far, only lower case in the name */ namecase = FATCASE_LOWER; #endif @@ -436,7 +436,7 @@ static inline int fat_parsesfname(const char **path, goto errout; } - /* So far, only lower case in the extension*/ + /* So far, only lower case in the extension */ extcase = FATCASE_LOWER; #endif @@ -503,7 +503,7 @@ static inline int fat_parselfname(const char **path, /* Loop until the name is successfully parsed or an error occurs */ - for (;;) + for (; ; ) { /* Get the next byte from the path */ @@ -511,7 +511,7 @@ static inline int fat_parselfname(const char **path, /* Check if this the last byte in this node of the name */ - if ((ch == '\0' || ch == '/') && ndx != 0 ) + if ((ch == '\0' || ch == '/') && ndx != 0) { /* Null terminate the string */ @@ -594,8 +594,8 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) /* First, let's decide what is name and what is extension */ - len = strlen((char*)dirinfo->fd_lfname); - ext = strrchr((char*)dirinfo->fd_lfname, '.'); + len = strlen((FAR char *)dirinfo->fd_lfname); + ext = strrchr((FAR char *)dirinfo->fd_lfname, '.'); if (ext) { ptrdiff_t tmp; @@ -604,7 +604,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) * beginning of the string is then the name length. */ - tmp = ext - (char*)dirinfo->fd_lfname; + tmp = ext - (FAR char *)dirinfo->fd_lfname; namechars = tmp; /* And the rest, excluding the '.' is the extension. */ @@ -656,7 +656,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) } else { - src = (char*)dirinfo->fd_lfname; + src = (FAR char *)dirinfo->fd_lfname; } /* Then copy the name and extension, handling upper case conversions and @@ -666,7 +666,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) ndx = 0; /* Position to write the next name character */ endndx = 6; /* Maximum index before we write ~! and switch to the extension */ - for (;;) + for (; ; ) { /* Get the next byte from the path. Break out of the loop if we * encounter the end of null-terminated the long file name string. @@ -991,7 +991,7 @@ static int fat_findsfnentry(struct fat_mountpt_s *fs, * the matching short name */ - for (;;) + for (; ; ) { /* Read the next sector into memory */ @@ -1017,7 +1017,7 @@ static int fat_findsfnentry(struct fat_mountpt_s *fs, if (direntry[DIR_NAME] != DIR0_EMPTY && !(DIR_GETATTRIBUTES(direntry) & FATATTR_VOLUMEID) && - !memcmp(&direntry[DIR_NAME], dirinfo->fd_name, DIR_MAXFNAME) ) + !memcmp(&direntry[DIR_NAME], dirinfo->fd_name, DIR_MAXFNAME)) { /* Yes.. Return success */ @@ -1085,7 +1085,7 @@ static bool fat_cmplfnchunk(uint8_t *chunk, const uint8_t *substr, int nchunk) * should match the ASCII code. */ - wch = (wchar_t)fat_getuint16((uint8_t*)chunk); + wch = (wchar_t)fat_getuint16((FAR uint8_t *)chunk); if ((wch & 0xff) != (wchar_t)ch) { return false; @@ -1130,7 +1130,7 @@ static bool fat_cmplfname(const uint8_t *direntry, const uint8_t *substr) * terminator). */ - len = strlen((char*)substr) + 1; + len = strlen((FAR char *)substr) + 1; /* Check bytes 1-5 */ @@ -1186,7 +1186,7 @@ static inline int fat_findlfnentry(struct fat_mountpt_s *fs, * LDIR_MAXFNAME+1 we do not have to check the length of the string). */ - namelen = strlen((char*)dirinfo->fd_lfname); + namelen = strlen((FAR char *)dirinfo->fd_lfname); DEBUGASSERT(namelen <= LDIR_MAXFNAME+1); /* How many LFN directory entries are we expecting? */ @@ -1219,7 +1219,7 @@ static inline int fat_findlfnentry(struct fat_mountpt_s *fs, * the match shore name */ - for (;;) + for (; ; ) { /* Read the next sector into memory */ @@ -1406,7 +1406,7 @@ static inline int fat_allocatesfnentry(struct fat_mountpt_s *fs, /* Then search for a free short file name directory entry */ - for (;;) + for (; ; ) { /* Read the directory sector into fs_buffer */ @@ -1518,7 +1518,7 @@ static inline int fat_allocatelfnentry(struct fat_mountpt_s *fs, */ needed = nentries; - for (;;) + for (; ; ) { /* Read the directory sector into fs_buffer */ @@ -1613,111 +1613,111 @@ static inline int fat_getsfname(uint8_t *direntry, char *buffer, unsigned int buflen) { #ifdef CONFIG_FAT_LCNAMES - uint8_t ntflags; + uint8_t ntflags; #endif - int ch; - int ndx; + int ch; + int ndx; - /* Check if we will be doing upper to lower case conversions */ + /* Check if we will be doing upper to lower case conversions */ #ifdef CONFIG_FAT_LCNAMES - ntflags = DIR_GETNTRES(direntry); + ntflags = DIR_GETNTRES(direntry); #endif - /* Reserve a byte for the NUL terminator */ + /* Reserve a byte for the NUL terminator */ - buflen--; + buflen--; - /* Get the 8-byte filename */ + /* Get the 8-byte filename */ - for (ndx = 0; ndx < 8 && buflen > 0; ndx++) - { - /* Get the next filename character from the directory entry */ + for (ndx = 0; ndx < 8 && buflen > 0; ndx++) + { + /* Get the next filename character from the directory entry */ - ch = direntry[ndx]; + ch = direntry[ndx]; - /* Any space (or ndx==8) terminates the filename */ + /* Any space (or ndx==8) terminates the filename */ - if (ch == ' ') - { - break; - } + if (ch == ' ') + { + break; + } - /* In this version, we never write 0xe5 in the directory filenames - * (because we do not handle any character sets where 0xe5 is valid - * in a filaname), but we could encounted this in a filesystem - * written by some other system - */ + /* In this version, we never write 0xe5 in the directory filenames + * (because we do not handle any character sets where 0xe5 is valid + * in a filaname), but we could encounted this in a filesystem + * written by some other system + */ - if (ndx == 0 && ch == DIR0_E5) - { - ch = 0xe5; - } + if (ndx == 0 && ch == DIR0_E5) + { + ch = 0xe5; + } - /* Check if we should perform upper to lower case conversion - * of the (whole) filename. - */ + /* Check if we should perform upper to lower case conversion + * of the (whole) filename. + */ #ifdef CONFIG_FAT_LCNAMES - if (ntflags & FATNTRES_LCNAME && isupper(ch)) - { - ch = tolower(ch); - } + if (ntflags & FATNTRES_LCNAME && isupper(ch)) + { + ch = tolower(ch); + } #endif - /* Copy the next character into the filename */ + /* Copy the next character into the filename */ - *buffer++ = ch; - buflen--; - } + *buffer++ = ch; + buflen--; + } - /* Check if there is an extension */ + /* Check if there is an extension */ - if (direntry[8] != ' ' && buflen > 0) - { - /* Yes, output the dot before the extension */ + if (direntry[8] != ' ' && buflen > 0) + { + /* Yes, output the dot before the extension */ - *buffer++ = '.'; - buflen--; + *buffer++ = '.'; + buflen--; - /* Then output the (up to) 3 character extension */ + /* Then output the (up to) 3 character extension */ - for (ndx = 8; ndx < 11 && buflen > 0; ndx++) - { - /* Get the next extensions character from the directory entry */ + for (ndx = 8; ndx < 11 && buflen > 0; ndx++) + { + /* Get the next extensions character from the directory entry */ - ch = direntry[DIR_NAME + ndx]; + ch = direntry[DIR_NAME + ndx]; - /* Any space (or ndx==11) terminates the extension */ + /* Any space (or ndx==11) terminates the extension */ - if (ch == ' ') - { - break; - } + if (ch == ' ') + { + break; + } - /* Check if we should perform upper to lower case conversion - * of the (whole) filename. - */ + /* Check if we should perform upper to lower case conversion + * of the (whole) filename. + */ #ifdef CONFIG_FAT_LCNAMES - if (ntflags & FATNTRES_LCEXT && isupper(ch)) - { - ch = tolower(ch); - } + if (ntflags & FATNTRES_LCEXT && isupper(ch)) + { + ch = tolower(ch); + } #endif - /* Copy the next character into the filename */ + /* Copy the next character into the filename */ - *buffer++ = ch; - buflen--; - } - } + *buffer++ = ch; + buflen--; + } + } - /* Put a null terminator at the end of the filename. We don't have to - * check if there is room because we reserved a byte for the NUL - * terminator at the beginning of this function. - */ + /* Put a null terminator at the end of the filename. We don't have to + * check if there is room because we reserved a byte for the NUL + * terminator at the beginning of this function. + */ - *buffer = '\0'; - return OK; + *buffer = '\0'; + return OK; } /**************************************************************************** @@ -1798,7 +1798,7 @@ static inline int fat_getlfname(struct fat_mountpt_s *fs, struct fs_dirent_s *di /* Loop until the whole file name has been transferred */ - for (;;) + for (; ; ) { /* Get the string offset associated with the "last" entry. */ @@ -2028,7 +2028,7 @@ static int fat_putlfname(struct fat_mountpt_s *fs, * LDIR_MAXLFNCHARS (13). */ - namelen = strlen((char*)dirinfo->fd_lfname); + namelen = strlen((FAR char *)dirinfo->fd_lfname); DEBUGASSERT(namelen <= LDIR_MAXFNAME+1); /* How many LFN directory entries do we need to write? */ @@ -2093,7 +2093,7 @@ static int fat_putlfname(struct fat_mountpt_s *fs, /* Now loop, writing each long file name entry */ - for (;;) + for (; ; ) { /* Get the string offset associated with the directory entry. */ @@ -2314,7 +2314,7 @@ int fat_finddirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo, /* Now loop until the directory entry corresponding to the path is found */ - for (;;) + for (; ; ) { /* Convert the next the path segment name into the kind of name that * we would see in the directory entry. @@ -2441,7 +2441,7 @@ int fat_allocatedirentry(struct fat_mountpt_s *fs, * or until to fail to extend the directory cluster chain. */ - for (;;) + for (; ; ) { /* Can this cluster chain be extended */ @@ -2520,9 +2520,9 @@ int fat_allocatedirentry(struct fat_mountpt_s *fs, return cluster; } - /* Flush out any cached data in fs_buffer.. we are going to use - * it to initialize the new directory cluster. - */ + /* Flush out any cached data in fs_buffer.. we are going to use + * it to initialize the new directory cluster. + */ ret = fat_fscacheflush(fs); if (ret < 0) @@ -2591,7 +2591,7 @@ int fat_freedirentry(struct fat_mountpt_s *fs, struct fat_dirseq_s *seq) * and for the single short file name entry. */ - for (;;) + for (; ; ) { /* Read the directory sector into the sector cache */ @@ -2896,7 +2896,7 @@ int fat_remove(struct fat_mountpt_s *fs, const char *relpath, bool directory) * (2) the directory is found to be empty, or (3) some error occurs. */ - for (;;) + for (; ; ) { unsigned int subdirindex; uint8_t *subdirentry; diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c index 3d70032582..380facb313 100644 --- a/fs/fat/fs_fat32util.c +++ b/fs/fat/fs_fat32util.c @@ -322,9 +322,9 @@ uint32_t fat_getuint32(uint8_t *ptr) * Name: fat_putuint16 ****************************************************************************/ -void fat_putuint16(uint8_t *ptr, uint16_t value16) +void fat_putuint16(FAR uint8_t *ptr, uint16_t value16) { - uint8_t *val = (uint8_t*)&value16; + FAR uint8_t *val = (FAR uint8_t *)&value16; #ifdef CONFIG_ENDIAN_BIG /* If the target is big-endian then the bytes always have to be swapped so @@ -348,9 +348,9 @@ void fat_putuint16(uint8_t *ptr, uint16_t value16) * Name: fat_putuint32 ****************************************************************************/ -void fat_putuint32(uint8_t *ptr, uint32_t value32) +void fat_putuint32(FAR uint8_t *ptr, uint32_t value32) { - uint16_t *val = (uint16_t*)&value32; + FAR uint16_t *val = (FAR uint16_t *)&value32; #ifdef CONFIG_ENDIAN_BIG /* If the target is big-endian then the bytes always have to be swapped so @@ -554,7 +554,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) /* Allocate a buffer to hold one hardware sector */ - fs->fs_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize); + fs->fs_buffer = (FAR uint8_t *)fat_io_alloc(fs->fs_hwsectorsize); if (!fs->fs_buffer) { ret = -ENOMEM; @@ -585,12 +585,12 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) * indexed by 16x the partition number. */ - int i; - for (i = 0; i < 4; i++) - { - /* Check if the partition exists and, if so, get the bootsector for that - * partition and see if we can find the boot record there. - */ + int i; + for (i = 0; i < 4; i++) + { + /* Check if the partition exists and, if so, get the bootsector for that + * partition and see if we can find the boot record there. + */ uint8_t part = PART_GETTYPE(i, fs->fs_buffer); fvdbg("Partition %d, offset %d, type %d\n", i, PART_ENTRY(i), part); @@ -748,7 +748,7 @@ int fat_hwread(struct fat_mountpt_s *fs, uint8_t *buffer, off_t sector, unsigned int nsectors) { int ret = -ENODEV; - if (fs && fs->fs_blkdriver ) + if (fs && fs->fs_blkdriver) { struct inode *inode = fs->fs_blkdriver; if (inode && inode->u.i_bops && inode->u.i_bops->read) @@ -781,7 +781,7 @@ int fat_hwwrite(struct fat_mountpt_s *fs, uint8_t *buffer, off_t sector, unsigned int nsectors) { int ret = -ENODEV; - if (fs && fs->fs_blkdriver ) + if (fs && fs->fs_blkdriver) { struct inode *inode = fs->fs_blkdriver; if (inode && inode->u.i_bops && inode->u.i_bops->write) @@ -811,7 +811,7 @@ int fat_hwwrite(struct fat_mountpt_s *fs, uint8_t *buffer, off_t sector, * ****************************************************************************/ -off_t fat_cluster2sector(struct fat_mountpt_s *fs, uint32_t cluster ) +off_t fat_cluster2sector(FAR struct fat_mountpt_s *fs, uint32_t cluster) { cluster -= 2; if (cluster >= fs->fs_nclusters - 2) @@ -993,7 +993,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, /* Make sure that the sector at this offset is in the cache */ - if (fat_fscacheread(fs, fatsector)< 0) + if (fat_fscacheread(fs, fatsector) < 0) { /* Read error */ @@ -1239,7 +1239,7 @@ int32_t fat_extendchain(struct fat_mountpt_s *fs, uint32_t cluster) */ newcluster = startcluster; - for (;;) + for (; ; ) { /* Examine the next cluster in the FAT */ @@ -1303,7 +1303,7 @@ int32_t fat_extendchain(struct fat_mountpt_s *fs, uint32_t cluster) return ret; } - /* And link if to the start cluster (if any)*/ + /* And link if to the start cluster (if any) */ if (cluster) { @@ -1563,29 +1563,29 @@ int fat_fscacheread(struct fat_mountpt_s *fs, off_t sector) * we do nothing. Otherwise, we will have to read the new sector. */ - if (fs->fs_currentsector != sector) - { - /* We will need to read the new sector. First, flush the cached - * sector if it is dirty. - */ + if (fs->fs_currentsector != sector) + { + /* We will need to read the new sector. First, flush the cached + * sector if it is dirty. + */ - ret = fat_fscacheflush(fs); - if (ret < 0) - { - return ret; - } + ret = fat_fscacheflush(fs); + if (ret < 0) + { + return ret; + } - /* Then read the specified sector into the cache */ + /* Then read the specified sector into the cache */ - ret = fat_hwread(fs, fs->fs_buffer, sector, 1); - if (ret < 0) - { - return ret; - } + ret = fat_hwread(fs, fs->fs_buffer, sector, 1); + if (ret < 0) + { + return ret; + } - /* Update the cached sector number */ + /* Update the cached sector number */ - fs->fs_currentsector = sector; + fs->fs_currentsector = sector; } return OK; @@ -1608,7 +1608,8 @@ int fat_ffcacheflush(struct fat_mountpt_s *fs, struct fat_file_s *ff) */ if (ff->ff_cachesector && - (ff->ff_bflags & (FFBUFF_DIRTY|FFBUFF_VALID)) == (FFBUFF_DIRTY|FFBUFF_VALID)) + (ff->ff_bflags & (FFBUFF_DIRTY | FFBUFF_VALID)) == + (FFBUFF_DIRTY | FFBUFF_VALID)) { /* Write the dirty sector */ @@ -1875,7 +1876,7 @@ int fat_currentsector(struct fat_mountpt_s *fs, struct fat_file_s *ff, { int sectoroffset; - if (position <= ff->ff_size ) + if (position <= ff->ff_size) { /* sectoroffset is the sector number offset into the current cluster */ @@ -1883,7 +1884,7 @@ int fat_currentsector(struct fat_mountpt_s *fs, struct fat_file_s *ff, /* The current cluster is the first sector of the cluster plus * the sector offset - */ + */ ff->ff_currentsector = fat_cluster2sector(fs, ff->ff_currentcluster) + sectoroffset; diff --git a/fs/fat/fs_mkfatfs.c b/fs/fat/fs_mkfatfs.c index 08eb618c2b..a1f17d7374 100644 --- a/fs/fat/fs_mkfatfs.c +++ b/fs/fat/fs_mkfatfs.c @@ -299,9 +299,9 @@ int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt) /* Allocate a buffer that will be working sector memory */ #ifdef CONFIG_FAT_DMAMEMORY - var.fv_sect = (uint8_t*)fat_dma_alloc(var.fv_sectorsize); + var.fv_sect = (FAR uint8_t *)fat_dma_alloc(var.fv_sectorsize); #else - var.fv_sect = (uint8_t*)kmm_malloc(var.fv_sectorsize); + var.fv_sect = (FAR uint8_t *)kmm_malloc(var.fv_sectorsize); #endif if (!var.fv_sect) diff --git a/fs/fat/fs_writefat.c b/fs/fat/fs_writefat.c index 51e71e278d..a484cbac67 100644 --- a/fs/fat/fs_writefat.c +++ b/fs/fat/fs_writefat.c @@ -81,7 +81,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, /* 8@3: Usually "MSWIN4.1" */ - strcpy((char*)&var->fv_sect[BS_OEMNAME], "NUTTX "); + strcpy((FAR char *)&var->fv_sect[BS_OEMNAME], "NUTTX "); /* 2@11: Bytes per sector: 512, 1024, 2048, 4096 */ @@ -177,7 +177,7 @@ static inline void mkfatfs_initmbr(FAR struct fat_format_s *fmt, MBR_PUTFATSZ32(var->fv_sect, var->fv_nfatsects); - /* 2@40: 0-3:Active FAT, 7=0 both FATS, 7=1 one FAT -- left zero*/ + /* 2@40: 0-3:Active FAT, 7=0 both FATS, 7=1 one FAT -- left zero */ /* 2@42: MSB:Major LSB:Minor revision number (0.0) -- left zero */ /* 4@44: Cluster no. of 1st cluster of root dir */ @@ -357,7 +357,7 @@ static inline int mkfatfs_writembr(FAR struct fat_format_s *fmt, if (ret >= 0) { - /* Create an image of the fsinfo sector*/ + /* Create an image of the fsinfo sector */ mkfatfs_initfsinfo(fmt, var); @@ -408,7 +408,7 @@ static inline int mkfatfs_writefat(FAR struct fat_format_s *fmt, if (sectno == 0) { memset(var->fv_sect, 0, var->fv_sectorsize); - switch(fmt->ff_fattype) + switch (fmt->ff_fattype) { case 12: /* Mark the first two full FAT entries -- 24 bits, 3 bytes total */ diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 4f82b15126..a35526232d 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -385,7 +385,7 @@ void files_release(int fd) list = sched_getfiles(); DEBUGASSERT(list); - if (fd >=0 && fd < CONFIG_NFILE_DESCRIPTORS) + if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) { _files_semtake(list); list->fl_files[fd].f_oflags = 0; diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c index d5d58102ea..2e3edc4c1d 100644 --- a/fs/inode/fs_inode.c +++ b/fs/inode/fs_inode.c @@ -111,7 +111,7 @@ static int _inode_compare(FAR const char *fname, return -1; } - for (;;) + for (; ; ) { /* At end of node name? */ @@ -133,7 +133,7 @@ static int _inode_compare(FAR const char *fname, } } - /* At end of find name?*/ + /* At end of find name? */ else if (!*fname || *fname == '/') { @@ -421,19 +421,19 @@ FAR const char *inode_nextname(FAR const char *name) * path segment. */ - while (*name && *name != '/') - { - name++; - } + while (*name && *name != '/') + { + name++; + } - /* If we found the '/' delimiter, then the path segment we want begins at - * the next character (which might also be the NUL terminator). - */ + /* If we found the '/' delimiter, then the path segment we want begins at + * the next character (which might also be the NUL terminator). + */ - if (*name) - { - name++; - } + if (*name) + { + name++; + } - return name; + return name; } diff --git a/fs/inode/fs_inodebasename.c b/fs/inode/fs_inodebasename.c index afd1e56592..6398d9854c 100644 --- a/fs/inode/fs_inodebasename.c +++ b/fs/inode/fs_inodebasename.c @@ -74,7 +74,7 @@ FAR const char *inode_basename(FAR const char *name) { FAR const char *basename = NULL; - for (;;) + for (; ; ) { /* Get the name for the next path segment */ diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index a241cef0e4..5e674783df 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -70,7 +70,11 @@ static int inode_namelen(FAR const char *name) { const char *tmp = name; - while (*tmp && *tmp != '/') tmp++; + while (*tmp && *tmp != '/') + { + tmp++; + } + return tmp - name; } @@ -80,8 +84,12 @@ static int inode_namelen(FAR const char *name) static void inode_namecpy(char *dest, const char *src) { - while (*src && *src != '/') *dest++ = *src++; - *dest='\0'; + while (*src && *src != '/') + { + *dest++ = *src++; + } + + *dest = '\0'; } /**************************************************************************** @@ -91,7 +99,7 @@ static void inode_namecpy(char *dest, const char *src) static FAR struct inode *inode_alloc(FAR const char *name) { int namelen = inode_namelen(name); - FAR struct inode *node = (FAR struct inode*)kmm_zalloc(FSNODE_SIZE(namelen)); + FAR struct inode *node = (FAR struct inode *)kmm_zalloc(FSNODE_SIZE(namelen)); if (node) { inode_namecpy(node->i_name, name); @@ -194,7 +202,7 @@ int inode_reserve(FAR const char *path, FAR struct inode **inode) /* Now we now where to insert the subtree */ - for (;;) + for (; ; ) { FAR struct inode *node; diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index 0cb6f5db58..501db40282 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -133,7 +133,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, #ifdef CONFIG_DEBUG if (prot == PROT_NONE || - (flags & (MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_DENYWRITE)) != 0) + (flags & (MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS | MAP_DENYWRITE)) != 0) { fdbg("Unsupported options, prot=%x flags=%04x\n", prot, flags); set_errno(ENOSYS); @@ -170,5 +170,5 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, /* Return the offset address */ - return (void*)(((uint8_t*)addr) + offset); + return (FAR void *)(((FAR uint8_t *)addr) + offset); } diff --git a/fs/mmap/fs_munmap.c b/fs/mmap/fs_munmap.c index 04800d35ac..12b084d85b 100644 --- a/fs/mmap/fs_munmap.c +++ b/fs/mmap/fs_munmap.c @@ -196,7 +196,7 @@ int munmap(FAR void *start, size_t length) else { newaddr = kumm_realloc(curr->addr, sizeof(struct fs_rammap_s) + length); - DEBUGASSERT(newaddr == (FAR void*)(curr->addr)); + DEBUGASSERT(newaddr == (FAR void *)(curr->addr)); curr->length = length; } diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 2aaced1d0d..5f00032553 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -177,24 +177,24 @@ FAR void *rammap(int fd, size_t length, off_t offset) nread = read(fd, rdbuffer, length); if (nread < 0) { - /* Handle the special case where the read was interrupted by a - * signal. - */ - - err = get_errno(); - if (err != EINTR) - { - /* All other read errors are bad. errno is already set. - * (but maybe should be forced to EINVAL?). NOTE that if - * FS DEBUG is enabled, then the following fdbg() macro will - * destroy the errno value. - */ - - fdbg("Read failed: offset=%d errno=%d\n", (int)offset, err); + /* Handle the special case where the read was interrupted by a + * signal. + */ + + err = get_errno(); + if (err != EINTR) + { + /* All other read errors are bad. errno is already set. + * (but maybe should be forced to EINVAL?). NOTE that if + * FS DEBUG is enabled, then the following fdbg() macro will + * destroy the errno value. + */ + + fdbg("Read failed: offset=%d errno=%d\n", (int)offset, err); #ifdef CONFIG_DEBUG_FS - goto errout_with_region; + goto errout_with_region; #else - goto errout_with_errno; + goto errout_with_errno; #endif } } diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c index 5b6db2369e..d8527e7cf3 100644 --- a/fs/mqueue/mq_close.c +++ b/fs/mqueue/mq_close.c @@ -164,25 +164,25 @@ void mq_inode_release(FAR struct inode *inode) * the inode now. */ - if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0) - { - FAR struct mqueue_inode_s *msgq = inode->u.i_mqueue; - DEBUGASSERT(msgq); + if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0) + { + FAR struct mqueue_inode_s *msgq = inode->u.i_mqueue; + DEBUGASSERT(msgq); - /* Free the message queue (and any messages left in it) */ + /* Free the message queue (and any messages left in it) */ - mq_msgqfree(msgq); - inode->u.i_mqueue = NULL; + mq_msgqfree(msgq); + inode->u.i_mqueue = NULL; - /* Release and free the inode container. If it has been properly - * unlinked, then the peer pointer should be NULL. - */ + /* Release and free the inode container. If it has been properly + * unlinked, then the peer pointer should be NULL. + */ - inode_semgive(); + inode_semgive(); - DEBUGASSERT(inode->i_peer == NULL); - inode_free(inode); - return; + DEBUGASSERT(inode->i_peer == NULL); + inode_free(inode); + return; } inode_semgive(); diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index f20e69579f..3dbb2f9f8c 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -158,7 +158,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) * create a new mqueue with this name. */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { errcode = EEXIST; goto errout_with_inode; @@ -186,13 +186,13 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) goto errout_with_lock; } - /* Create the mqueue. First we have to extract the additional - * parameters from the variable argument list. - */ + /* Create the mqueue. First we have to extract the additional + * parameters from the variable argument list. + */ va_start(ap, oflags); mode = va_arg(ap, mode_t); - attr = va_arg(ap, FAR struct mq_attr*); + attr = va_arg(ap, FAR struct mq_attr *); va_end(ap); /* Create an inode in the pseudo-filesystem at this path */ @@ -211,7 +211,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) * be created with a reference count of zero. */ - msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr); + msgq = (FAR struct mqueue_inode_s *)mq_msgqalloc(mode, attr); if (!msgq) { errcode = ENOSPC; diff --git a/fs/nfs/nfs_util.c b/fs/nfs/nfs_util.c index 19e78ea650..dbe547bcd9 100644 --- a/fs/nfs/nfs_util.c +++ b/fs/nfs/nfs_util.c @@ -90,7 +90,7 @@ static inline int nfs_pathsegment(FAR const char **path, FAR char *buffer, /* Loop until the name is successfully parsed or an error occurs */ - for (;;) + for (; ; ) { /* Get the next byte from the path */ @@ -102,7 +102,7 @@ static inline int nfs_pathsegment(FAR const char **path, FAR char *buffer, { /* This logic just suppors "//" sequences in the path name */ - if (ch == '\0' || nbytes > 0 ) + if (ch == '\0' || nbytes > 0) { /* NULL terminate the parsed path segment */ @@ -433,7 +433,7 @@ int nfs_findnode(struct nfsmount *nmp, FAR const char *relpath, * to the path is found. */ - for (;;) + for (; ; ) { /* Extract the next path segment name. */ @@ -494,7 +494,7 @@ int nfs_findnode(struct nfsmount *nmp, FAR const char *relpath, * Desciption: * Given a path to something that may or may not be in the file system, * return the handle of the entry of the directory containing the requested -* object. + * object. * * Return Value: * Zero on success; a positive errno value on failure. @@ -527,7 +527,7 @@ int nfs_finddir(struct nfsmount *nmp, FAR const char *relpath, /* Loop until the directory entry containing the path is found. */ - for (;;) + for (; ; ) { /* Extract the next path segment name. */ diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c index 576ee589f7..934cea664b 100644 --- a/fs/nfs/nfs_vfsops.c +++ b/fs/nfs/nfs_vfsops.c @@ -495,7 +495,7 @@ static int nfs_fileopen(FAR struct nfsmount *nmp, struct nfsnode *np, */ tmp = fxdr_unsigned(uint32_t, fattr.fa_mode); - if ((tmp & (NFSMODE_IWOTH|NFSMODE_IWGRP|NFSMODE_IWUSR)) == 0) + if ((tmp & (NFSMODE_IWOTH | NFSMODE_IWGRP | NFSMODE_IWUSR)) == 0) { fdbg("ERROR: File is read-only: %08x\n", tmp); return EACCES; @@ -504,7 +504,7 @@ static int nfs_fileopen(FAR struct nfsmount *nmp, struct nfsnode *np, /* It would be an error if we are asked to create the file exclusively */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { /* Already exists -- can't create it exclusively */ @@ -528,7 +528,7 @@ static int nfs_fileopen(FAR struct nfsmount *nmp, struct nfsnode *np, * access is ignored. */ - if ((oflags & (O_TRUNC|O_WRONLY)) == (O_TRUNC|O_WRONLY)) + if ((oflags & (O_TRUNC | O_WRONLY)) == (O_TRUNC | O_WRONLY)) { /* Truncate the file to zero length. I think we can do this with * the SETATTR call by setting the length to zero. @@ -567,7 +567,7 @@ static int nfs_open(FAR struct file *filep, FAR const char *relpath, * mountpoint private data from the inode structure */ - nmp = (struct nfsmount*)filep->f_inode->i_private; + nmp = (FAR struct nfsmount *)filep->f_inode->i_private; DEBUGASSERT(nmp != NULL); /* Pre-allocate the file private data to describe the opened file. */ @@ -690,8 +690,8 @@ static int nfs_close(FAR struct file *filep) /* Recover our private data from the struct file instance */ - nmp = (struct nfsmount*) filep->f_inode->i_private; - np = (struct nfsnode*) filep->f_priv; + nmp = (FAR struct nfsmount *) filep->f_inode->i_private; + np = (FAR struct nfsnode *) filep->f_priv; DEBUGASSERT(nmp != NULL); @@ -787,8 +787,8 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen) /* Recover our private data from the struct file instance */ - nmp = (struct nfsmount*)filep->f_inode->i_private; - np = (struct nfsnode*)filep->f_priv; + nmp = (FAR struct nfsmount *)filep->f_inode->i_private; + np = (FAR struct nfsnode *)filep->f_priv; DEBUGASSERT(nmp != NULL); @@ -835,7 +835,7 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen) /* Initialize the request */ - ptr = (FAR uint32_t*)&nmp->nm_msgbuffer.read.read; + ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.read.read; reqlen = 0; /* Copy the variable length, file handle */ @@ -963,8 +963,8 @@ static ssize_t nfs_write(FAR struct file *filep, const char *buffer, /* Recover our private data from the struct file instance */ - nmp = (struct nfsmount*)filep->f_inode->i_private; - np = (struct nfsnode*)filep->f_priv; + nmp = (FAR struct nfsmount *)filep->f_inode->i_private; + np = (FAR struct nfsnode *)filep->f_priv; DEBUGASSERT(nmp != NULL); @@ -1143,8 +1143,8 @@ static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp) /* Recover our private data from the struct file instance */ - nmp = (struct nfsmount*)oldp->f_inode->i_private; - np = (struct nfsnode*)oldp->f_priv; + nmp = (FAR struct nfsmount *)oldp->f_inode->i_private; + np = (FAR struct nfsnode *)oldp->f_priv; DEBUGASSERT(nmp != NULL); @@ -1305,7 +1305,7 @@ static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) * the dirent structure. */ - ptr = (FAR uint32_t*)&nmp->nm_msgbuffer.readdir.readdir; + ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.readdir.readdir; reqlen = 0; /* Copy the variable length, directory file handle */ @@ -1421,7 +1421,7 @@ static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) tmp = *ptr++; length = fxdr_unsigned(uint32_t, tmp); - name = (uint8_t*)ptr; + name = (FAR uint8_t *)ptr; /* Increment the pointer past the name (allowing for padding). ptr * now points to the cookie. @@ -1702,8 +1702,9 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data, nfs_decode_args(&nprmt, argp); - /* Determine the size of a buffer that will hold one RPC data transfer. - * First, get the maximum size of a read and a write transfer */ + /* Determine the size of a buffer that will hold one RPC data transfer. + * First, get the maximum size of a read and a write transfer. + */ buflen = SIZEOF_rpc_call_write(nprmt.wsize); tmp = SIZEOF_rpc_reply_read(nprmt.rsize); @@ -1817,7 +1818,7 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data, error = nfs_request(nmp, NFSPROC_GETATTR, (FAR void *)&getattr, sizeof(struct FS3args), - (FAR void*)&resok, sizeof(struct rpc_reply_getattr)); + (FAR void *)&resok, sizeof(struct rpc_reply_getattr)); if (error) { fdbg("ERROR: nfs_request failed: %d\n", error); @@ -1830,7 +1831,7 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data, /* Mounted! */ - *handle = (void*)nmp; + *handle = (FAR void *)nmp; nfs_semgive(nmp); fvdbg("Successfully mounted\n"); @@ -2045,7 +2046,7 @@ static int nfs_statfs(FAR struct inode *mountpt, FAR struct statfs *sbp) /* Get the mountpoint private data from the inode structure */ - nmp = (struct nfsmount*)mountpt->i_private; + nmp = (FAR struct nfsmount *)mountpt->i_private; /* Check if the mount is still healthy */ @@ -2123,7 +2124,7 @@ static int nfs_remove(struct inode *mountpt, const char *relpath) /* Get the mountpoint private data from the inode structure */ - nmp = (struct nfsmount*)mountpt->i_private; + nmp = (FAR struct nfsmount *)mountpt->i_private; /* Check if the mount is still healthy */ @@ -2209,7 +2210,7 @@ static int nfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) /* Get the mountpoint private data from the inode structure */ - nmp = (struct nfsmount*) mountpt->i_private; + nmp = (FAR struct nfsmount *) mountpt->i_private; /* Check if the mount is still healthy */ @@ -2536,7 +2537,7 @@ static int nfs_stat(struct inode *mountpt, const char *relpath, /* Get the mountpoint private data from the inode structure */ - nmp = (struct nfsmount*)mountpt->i_private; + nmp = (FAR struct nfsmount *)mountpt->i_private; DEBUGASSERT(nmp && buf); /* Check if the mount is still healthy */ @@ -2568,9 +2569,9 @@ static int nfs_stat(struct inode *mountpt, const char *relpath, * as in the NFSv3 spec. */ - mode = tmp & (NFSMODE_IXOTH|NFSMODE_IWOTH|NFSMODE_IROTH| - NFSMODE_IXGRP|NFSMODE_IWGRP|NFSMODE_IRGRP| - NFSMODE_IXUSR|NFSMODE_IWUSR|NFSMODE_IRUSR); + mode = tmp & (NFSMODE_IXOTH | NFSMODE_IWOTH | NFSMODE_IROTH | + NFSMODE_IXGRP | NFSMODE_IWGRP | NFSMODE_IRGRP | + NFSMODE_IXUSR | NFSMODE_IWUSR | NFSMODE_IRUSR); /* Handle the cases that are not the same */ diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c index 7e7c96739a..030d9bafb2 100644 --- a/fs/nfs/rpc_clnt.c +++ b/fs/nfs/rpc_clnt.c @@ -415,9 +415,9 @@ int rpcclnt_connect(struct rpcclnt *rpc) so->s_crefs = 1; rpc->rc_so = so; - /* Always set receive timeout to detect server crash and reconnect. - * Otherwise, we can get stuck in psock_receive forever. - */ + /* Always set receive timeout to detect server crash and reconnect. + * Otherwise, we can get stuck in psock_receive forever. + */ tv.tv_sec = 1; tv.tv_usec = 0; diff --git a/fs/nxffs/nxffs_blockstats.c b/fs/nxffs/nxffs_blockstats.c index 859423ca48..4ff1bd8b3a 100644 --- a/fs/nxffs/nxffs_blockstats.c +++ b/fs/nxffs/nxffs_blockstats.c @@ -125,7 +125,7 @@ int nxffs_blockstats(FAR struct nxffs_volume_s *volume, * in the NXFFS data. */ - FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)bptr; + FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s *)bptr; /* Increment the total count of blocks examined */ @@ -203,7 +203,7 @@ int nxffs_blockstats(FAR struct nxffs_volume_s *volume, * in the NXFFS data. */ - FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)volume->pack; + FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s *)volume->pack; /* Collect statistics */ /* Check if this is a block that should be recognized by NXFFS */ diff --git a/fs/nxffs/nxffs_dump.c b/fs/nxffs/nxffs_dump.c index 19e4d4b5ce..1be0e294ac 100644 --- a/fs/nxffs/nxffs_dump.c +++ b/fs/nxffs/nxffs_dump.c @@ -149,16 +149,16 @@ static inline ssize_t nxffs_analyzeinode(FAR struct nxffs_blkinfo_s *blkinfo, return ERROR; } - spaceleft = (blkinfo->nblocks - blkinfo->block) * blkinfo->geo.blocksize; - spaceleft -= (offset + SIZEOF_NXFFS_BLOCK_HDR); - if (datlen > spaceleft) - { - /* The data length is greater than what would fit in the rest of FLASH - * (even ignoring block and data header sizes. - */ + spaceleft = (blkinfo->nblocks - blkinfo->block) * blkinfo->geo.blocksize; + spaceleft -= (offset + SIZEOF_NXFFS_BLOCK_HDR); + if (datlen > spaceleft) + { + /* The data length is greater than what would fit in the rest of FLASH + * (even ignoring block and data header sizes. + */ - return ERROR; - } + return ERROR; + } /* The name begins after the inode header. Does it begin in this block? */ diff --git a/fs/nxffs/nxffs_initialize.c b/fs/nxffs/nxffs_initialize.c index 66476f4874..745ca4560a 100644 --- a/fs/nxffs/nxffs_initialize.c +++ b/fs/nxffs/nxffs_initialize.c @@ -110,17 +110,26 @@ const struct mountpt_operations nxffs_operations = * block */ -const uint8_t g_blockmagic[NXFFS_MAGICSIZE] = { 'B', 'l', 'c', 'k' }; +const uint8_t g_blockmagic[NXFFS_MAGICSIZE] = +{ + 'B', 'l', 'c', 'k' +}; /* The magic number that appears that the beginning of each NXFFS inode */ -const uint8_t g_inodemagic[NXFFS_MAGICSIZE] = { 'I', 'n', 'o', 'd' }; +const uint8_t g_inodemagic[NXFFS_MAGICSIZE] = +{ + 'I', 'n', 'o', 'd' +}; /* The magic number that appears that the beginning of each NXFFS inode * data block. */ -const uint8_t g_datamagic[NXFFS_MAGICSIZE] = { 'D', 'a', 't', 'a' }; +const uint8_t g_datamagic[NXFFS_MAGICSIZE] = +{ + 'D', 'a', 't', 'a' +}; /* If CONFIG_NXFFS_PREALLOCATED is defined, then this is the single, pre- * allocated NXFFS volume instance. @@ -427,7 +436,7 @@ int nxffs_limits(FAR struct nxffs_volume_s *volume) nxffs_ioseek(volume, offset); nerased = 0; - for (;;) + for (; ; ) { int ch = nxffs_getc(volume, 1); if (ch < 0) diff --git a/fs/nxffs/nxffs_inode.c b/fs/nxffs/nxffs_inode.c index a8bf821861..63ba8cbb46 100644 --- a/fs/nxffs/nxffs_inode.c +++ b/fs/nxffs/nxffs_inode.c @@ -276,7 +276,7 @@ int nxffs_nextentry(FAR struct nxffs_volume_s *volume, off_t offset, nerased = 0; nmagic = 0; - for (;;) + for (; ; ) { /* Read the next character */ @@ -401,7 +401,7 @@ int nxffs_findinode(FAR struct nxffs_volume_s *volume, FAR const char *name, * media. */ - for (;;) + for (; ; ) { /* Get the next, valid NXFFS inode entry */ diff --git a/fs/nxffs/nxffs_open.c b/fs/nxffs/nxffs_open.c index 07e115a154..f665623a06 100644 --- a/fs/nxffs/nxffs_open.c +++ b/fs/nxffs/nxffs_open.c @@ -450,7 +450,7 @@ static inline int nxffs_wropen(FAR struct nxffs_volume_s *volume, * exclusively. */ - else if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + else if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { fdbg("ERROR: File exists, can't create O_EXCL\n"); ret = -EEXIST; @@ -462,7 +462,7 @@ static inline int nxffs_wropen(FAR struct nxffs_volume_s *volume, * we will not re-create the file unless O_CREAT is also specified. */ - else if ((oflags & (O_CREAT|O_TRUNC)) == (O_CREAT|O_TRUNC)) + else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) { /* Just schedule the removal the file and fall through to re-create it. * Note that the old file of the same name will not actually be removed @@ -546,7 +546,7 @@ static inline int nxffs_wropen(FAR struct nxffs_volume_s *volume, */ packed = false; - for (;;) + for (; ; ) { /* File a valid location to position the inode header. Start with the * first byte in the free FLASH region. @@ -600,7 +600,7 @@ static inline int nxffs_wropen(FAR struct nxffs_volume_s *volume, * Note that nothing is written to FLASH. */ - for (;;) + for (; ; ) { /* File a valid location to position the inode name. Start with the * first byte in the free FLASH region. @@ -853,7 +853,7 @@ static inline void nxffs_freeofile(FAR struct nxffs_volume_s *volume, */ #ifdef CONFIG_NXFFS_PREALLOCATED - if ((FAR struct nxffs_wrfile_s*)ofile != &g_wrfile) + if ((FAR struct nxffs_wrfile_s *)ofile != &g_wrfile) #endif { kmm_free(ofile); @@ -1022,7 +1022,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath, * file structure */ - volume = (FAR struct nxffs_volume_s*)filep->f_inode->i_private; + volume = (FAR struct nxffs_volume_s *)filep->f_inode->i_private; DEBUGASSERT(volume != NULL); #ifdef CONFIG_FILE_MODE @@ -1036,7 +1036,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath, * extension is supported. */ - switch (oflags & (O_WROK|O_RDOK)) + switch (oflags & (O_WROK | O_RDOK)) { case 0: default: @@ -1051,7 +1051,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath, ret = nxffs_rdopen(volume, relpath, &ofile); break; - case O_WROK|O_RDOK: + case O_WROK | O_RDOK: fdbg("ERROR: O_RDWR is not supported\n"); return -ENOSYS; } @@ -1092,7 +1092,7 @@ int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp) * file structure */ - volume = (FAR struct nxffs_volume_s*)oldp->f_inode->i_private; + volume = (FAR struct nxffs_volume_s *)oldp->f_inode->i_private; DEBUGASSERT(volume != NULL); #endif diff --git a/fs/nxffs/nxffs_pack.c b/fs/nxffs/nxffs_pack.c index 8706e8009a..14c9e8d8f1 100644 --- a/fs/nxffs/nxffs_pack.c +++ b/fs/nxffs/nxffs_pack.c @@ -286,7 +286,7 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume, * compacting. */ - for (;;) + for (; ; ) { /* Is there wasted space between the offset where the we could have * valid data and the offset to the beginning of the first valid @@ -358,12 +358,12 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume, ret = nxffs_validblock(volume, &volume->ioblock); if (ret < 0) { - /* No valid blocks? Then there is nothing we can do. Return - * the end-of-flash indication. - */ + /* No valid blocks? Then there is nothing we can do. Return + * the end-of-flash indication. + */ - *froffset = volume->froffset; - return -ENOSPC; + *froffset = volume->froffset; + return -ENOSPC; } volume->iooffset = SIZEOF_NXFFS_BLOCK_HDR; @@ -933,7 +933,7 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume, * block is full, or (3) an error occurs. */ - for (;;) + for (; ; ) { /* Transfer data from the source buffer to the destination buffer */ @@ -1186,39 +1186,39 @@ static inline int nxffs_packwriter(FAR struct nxffs_volume_s *volume, * block is full, or (3) an error occurs. */ - for (;;) + for (; ; ) { - /* Transfer data from the source buffer to the destination buffer */ + /* Transfer data from the source buffer to the destination buffer */ - nxffs_packtransfer(volume, pack); + nxffs_packtransfer(volume, pack); - /* Now, either the (1) src block has been fully transferred, (2) all - * of the source data has been transferred, or (3) the destination - * block is full, .. or all three. - * - * Check if all of the bytes in the source inode have been transferred. - */ + /* Now, either the (1) src block has been fully transferred, (2) all + * of the source data has been transferred, or (3) the destination + * block is full, .. or all three. + * + * Check if all of the bytes in the source inode have been transferred. + */ - if (pack->src.fpos >= pack->src.entry.datlen) - { - /* Write the final destination data block header and inode - * headers. - */ + if (pack->src.fpos >= pack->src.entry.datlen) + { + /* Write the final destination data block header and inode + * headers. + */ - nxffs_wrdathdr(volume, pack); + nxffs_wrdathdr(volume, pack); - /* Set the new offsets in the open file instance. */ + /* Set the new offsets in the open file instance. */ - wrfile->ofile.entry.hoffset = pack->dest.entry.hoffset; - wrfile->ofile.entry.noffset = pack->dest.entry.noffset; - wrfile->ofile.entry.doffset = pack->dest.entry.doffset; + wrfile->ofile.entry.hoffset = pack->dest.entry.hoffset; + wrfile->ofile.entry.noffset = pack->dest.entry.noffset; + wrfile->ofile.entry.doffset = pack->dest.entry.doffset; - /* Return an end-of-flash error to indicate that all of the write - * data has been transferred. - */ + /* Return an end-of-flash error to indicate that all of the write + * data has been transferred. + */ - return -ENOSPC; - } + return -ENOSPC; + } /* Not at the end of the source data stream. Check if we are at the * end of the current source data block. @@ -1312,7 +1312,7 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume) /* No, there is no write in progress. We just have an empty flash * full of deleted files. In this case, the media needs to be re- * formatted. - */ + */ ret = nxffs_reformat(volume); if (ret == OK) @@ -1359,19 +1359,19 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume) if (iooffset + CONFIG_NXFFS_TAILTHRESHOLD < volume->froffset) { - /* Setting 'packed' to true will supress normal inode packing - * operation. - */ + /* Setting 'packed' to true will supress normal inode packing + * operation. + */ - packed = true; + packed = true; - /* Writing is performed at the end of the free FLASH region. - * If we are not packing files, we could still need to pack - * the partially written file at the end of FLASH. - */ + /* Writing is performed at the end of the free FLASH region. + * If we are not packing files, we could still need to pack + * the partially written file at the end of FLASH. + */ - wrfile = nxffs_setupwriter(volume, &pack); - } + wrfile = nxffs_setupwriter(volume, &pack); + } /* Otherwise return OK.. meaning that there is nothing more we can * do to recover FLASH space. @@ -1422,7 +1422,7 @@ start_pack: ret = MTD_BREAD(volume->mtd, pack.block0, volume->blkper, volume->pack); if (ret < 0) { - fdbg("ERROR: Failed to read erase block %d: %d\n", eblock,-ret); + fdbg("ERROR: Failed to read erase block %d: %d\n", eblock, -ret); goto errout_with_pack; } @@ -1462,120 +1462,120 @@ start_pack: i < volume->blkper; i++, block++, pack.iobuffer += volume->geo.blocksize) { - /* The first time here, the ioblock may point to an offset into - * the erase block. We just need to skip over those cases. - */ - - if (block >= pack.ioblock) - { - /* Set the I/O position. Note on the first time we get - * pack.iooffset will hold the offset in the first I/O block - * to the first inode header. After that, it will always - * refer to the first byte after the block header. - */ - - pack.ioblock = block; - - /* If this is not a valid block or if we have already - * finished packing the valid inode entries, then just fall - * through, reset the FLASH memory to the erase state, and - * write the reset values to FLASH. (The first block that - * we want to process will always be valid -- we have - * already verified that). - */ - - if (nxffs_packvalid(&pack)) - { - /* Have we finished packing inodes? */ - - if (!packed) - { - DEBUGASSERT(wrfile == NULL); - - /* Pack inode data into this block */ - - ret = nxffs_packblock(volume, &pack); - if (ret < 0) - { - /* The error -ENOSPC is a special value that simply - * means that there is nothing further to be packed. - */ - - if (ret == -ENOSPC) - { - packed = true; - - /* Writing is performed at the end of the free - * FLASH region and this implemenation is restricted - * to a single writer. The new inode is not - * written to FLASH until the writer is closed - * and so will not be found by nxffs_packblock(). - */ - - wrfile = nxffs_setupwriter(volume, &pack); - } - else - { - /* Otherwise, something really bad happened */ - - fdbg("ERROR: Failed to pack into block %d: %d\n", - block, ret); - goto errout_with_pack; - } - } - } - - /* If all of the "normal" inodes have been packed, then check if - * we need to pack the current, in-progress write operation. - */ - - if (wrfile) - { - DEBUGASSERT(packed == true); - - /* Pack write data into this block */ - - ret = nxffs_packwriter(volume, &pack, wrfile); - if (ret < 0) - { - /* The error -ENOSPC is a special value that simply - * means that there is nothing further to be packed. - */ - - if (ret == -ENOSPC) - { - wrfile = NULL; - } - else - { - /* Otherwise, something really bad happened */ - - fdbg("ERROR: Failed to pack into block %d: %d\n", - block, ret); - goto errout_with_pack; - } - } - } - } - - /* Set any unused portion at the end of the block to the - * erased state. - */ - - if (pack.iooffset < volume->geo.blocksize) - { - memset(&pack.iobuffer[pack.iooffset], - CONFIG_NXFFS_ERASEDSTATE, - volume->geo.blocksize - pack.iooffset); - } - - /* Next time through the loop, pack.iooffset will point to the - * first byte after the block header. - */ - - pack.iooffset = SIZEOF_NXFFS_BLOCK_HDR; - } - } + /* The first time here, the ioblock may point to an offset into + * the erase block. We just need to skip over those cases. + */ + + if (block >= pack.ioblock) + { + /* Set the I/O position. Note on the first time we get + * pack.iooffset will hold the offset in the first I/O block + * to the first inode header. After that, it will always + * refer to the first byte after the block header. + */ + + pack.ioblock = block; + + /* If this is not a valid block or if we have already + * finished packing the valid inode entries, then just fall + * through, reset the FLASH memory to the erase state, and + * write the reset values to FLASH. (The first block that + * we want to process will always be valid -- we have + * already verified that). + */ + + if (nxffs_packvalid(&pack)) + { + /* Have we finished packing inodes? */ + + if (!packed) + { + DEBUGASSERT(wrfile == NULL); + + /* Pack inode data into this block */ + + ret = nxffs_packblock(volume, &pack); + if (ret < 0) + { + /* The error -ENOSPC is a special value that simply + * means that there is nothing further to be packed. + */ + + if (ret == -ENOSPC) + { + packed = true; + + /* Writing is performed at the end of the free + * FLASH region and this implemenation is restricted + * to a single writer. The new inode is not + * written to FLASH until the writer is closed + * and so will not be found by nxffs_packblock(). + */ + + wrfile = nxffs_setupwriter(volume, &pack); + } + else + { + /* Otherwise, something really bad happened */ + + fdbg("ERROR: Failed to pack into block %d: %d\n", + block, ret); + goto errout_with_pack; + } + } + } + + /* If all of the "normal" inodes have been packed, then check if + * we need to pack the current, in-progress write operation. + */ + + if (wrfile) + { + DEBUGASSERT(packed == true); + + /* Pack write data into this block */ + + ret = nxffs_packwriter(volume, &pack, wrfile); + if (ret < 0) + { + /* The error -ENOSPC is a special value that simply + * means that there is nothing further to be packed. + */ + + if (ret == -ENOSPC) + { + wrfile = NULL; + } + else + { + /* Otherwise, something really bad happened */ + + fdbg("ERROR: Failed to pack into block %d: %d\n", + block, ret); + goto errout_with_pack; + } + } + } + } + + /* Set any unused portion at the end of the block to the + * erased state. + */ + + if (pack.iooffset < volume->geo.blocksize) + { + memset(&pack.iobuffer[pack.iooffset], + CONFIG_NXFFS_ERASEDSTATE, + volume->geo.blocksize - pack.iooffset); + } + + /* Next time through the loop, pack.iooffset will point to the + * first byte after the block header. + */ + + pack.iooffset = SIZEOF_NXFFS_BLOCK_HDR; + } + } /* We now have an in-memory image of how we want this erase block to * appear. Now it is safe to erase the block. diff --git a/fs/nxffs/nxffs_read.c b/fs/nxffs/nxffs_read.c index 934a640bf6..6bd09374f9 100644 --- a/fs/nxffs/nxffs_read.c +++ b/fs/nxffs/nxffs_read.c @@ -294,7 +294,7 @@ int nxffs_nextblock(FAR struct nxffs_volume_s *volume, off_t offset, nerased = 0; nmagic = 0; - for (;;) + for (; ; ) { /* Read the next character */ diff --git a/fs/nxffs/nxffs_reformat.c b/fs/nxffs/nxffs_reformat.c index b969a398b3..ba151f4cc9 100644 --- a/fs/nxffs/nxffs_reformat.c +++ b/fs/nxffs/nxffs_reformat.c @@ -190,7 +190,7 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume) i++, block++, blkptr += volume->geo.blocksize) #endif { - FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)blkptr; + FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s *)blkptr; /* Assume that this is a good block until we learn otherwise */ @@ -330,7 +330,7 @@ int nxffs_reformat(FAR struct nxffs_volume_s *volume) void nxffs_blkinit(FAR struct nxffs_volume_s *volume, FAR uint8_t *blkptr, uint8_t state) { - FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)blkptr; + FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s *)blkptr; memset(blkptr, CONFIG_NXFFS_ERASEDSTATE, volume->geo.blocksize); memcpy(blkhdr->magic, g_blockmagic, NXFFS_MAGICSIZE); diff --git a/fs/nxffs/nxffs_stat.c b/fs/nxffs/nxffs_stat.c index 9f45b5a4b1..f4a16a2117 100644 --- a/fs/nxffs/nxffs_stat.c +++ b/fs/nxffs/nxffs_stat.c @@ -166,7 +166,7 @@ int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath, } buf->st_blocks = entry.datlen / (volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR); - buf->st_mode = S_IFREG|S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR; buf->st_size = entry.datlen; buf->st_atime = entry.utc; buf->st_mtime = entry.utc; @@ -180,7 +180,8 @@ int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath, { /* It's a read/execute-only directory name */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR | S_IXOTH | + S_IXGRP | S_IXUSR; } ret = OK; diff --git a/fs/nxffs/nxffs_write.c b/fs/nxffs/nxffs_write.c index 7f081b92d8..561fb58bea 100644 --- a/fs/nxffs/nxffs_write.c +++ b/fs/nxffs/nxffs_write.c @@ -227,7 +227,7 @@ static inline int nxffs_wralloc(FAR struct nxffs_volume_s *volume, */ packed = false; - for (;;) + for (; ; ) { size_t mindata = MIN(NXFFS_MINDATA, size); diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index d23ea195bd..5b6786b2e6 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -647,33 +647,33 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) /* Test if we skipped this entry */ if (name != NULL) - { - /* This entry is okay to report. Test if it has a duplicate - * first level name as the one we just reported. This could - * happen in the event of procfs_entry_s such as: - * - * fs/smartfs - * fs/nfs - * fs/nxffs - */ - - name = g_procfsentries[index - priv->nentries].pathpattern; - if (!level0->lastlen || (strncmp(name, level0->lastread, + { + /* This entry is okay to report. Test if it has a duplicate + * first level name as the one we just reported. This could + * happen in the event of procfs_entry_s such as: + * + * fs/smartfs + * fs/nfs + * fs/nxffs + */ + + name = g_procfsentries[index - priv->nentries].pathpattern; + if (!level0->lastlen || (strncmp(name, level0->lastread, level0->lastlen) != 0)) - { - /* Not a duplicate, return the first segment of this - * entry - */ - - break; - } - else - { - /* Skip this entry ... duplicate 1st level name found */ - - index++; - } - } + { + /* Not a duplicate, return the first segment of this + * entry + */ + + break; + } + else + { + /* Skip this entry ... duplicate 1st level name found */ + + index++; + } + } } /* Test if we are at the end of the directory */ @@ -915,7 +915,7 @@ static int procfs_stat(struct inode *mountpt, const char *relpath, /* The path refers to the top level directory */ /* It's a read-only directory */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; ret = OK; } else @@ -945,7 +945,7 @@ static int procfs_stat(struct inode *mountpt, const char *relpath, { /* It's an internal subdirectory */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; ret = OK; break; } diff --git a/fs/procfs/fs_procfscpuload.c b/fs/procfs/fs_procfscpuload.c index f60789a768..fd94c91870 100644 --- a/fs/procfs/fs_procfscpuload.c +++ b/fs/procfs/fs_procfscpuload.c @@ -337,7 +337,7 @@ static int cpuload_stat(const char *relpath, struct stat *buf) /* "cpuload" is the name for a read-only file */ - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; buf->st_size = 0; buf->st_blksize = 0; buf->st_blocks = 0; diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 80ea40583c..62284797df 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1455,7 +1455,7 @@ static int proc_stat(const char *relpath, struct stat *buf) { /* Yes ... It's a read-only directory */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; } /* Verify that the process ID is followed by valid path segment delimiter */ @@ -1492,11 +1492,11 @@ static int proc_stat(const char *relpath, struct stat *buf) if (node->dtype == DTYPE_FILE) { - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; } else { - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; } } diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index 7d924087c8..c5f8c719a5 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -351,7 +351,7 @@ static int uptime_dup(FAR const struct file *oldp, FAR struct file *newp) * ****************************************************************************/ -static int uptime_stat(const char *relpath, struct stat *buf) +static int uptime_stat(FAR const char *relpath, FAR struct stat *buf) { /* "uptime" is the only acceptable value for the relpath */ @@ -363,7 +363,7 @@ static int uptime_stat(const char *relpath, struct stat *buf) /* "uptime" is the name for a read-only file */ - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; buf->st_size = 0; buf->st_blksize = 0; buf->st_blocks = 0; diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c index 0dd573f562..99ba5b4f18 100644 --- a/fs/procfs/fs_skeleton.c +++ b/fs/procfs/fs_skeleton.c @@ -441,7 +441,7 @@ static int skel_stat(const char *relpath, struct stat *buf) * or a directory and set it's permissions. */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; ret = OK; /* File/directory size, access block size */ diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 8198b2b657..00f3f92886 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -167,7 +167,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath, * structure */ - rm = (FAR struct romfs_mountpt_s*)filep->f_inode->i_private; + rm = (FAR struct romfs_mountpt_s *)filep->f_inode->i_private; DEBUGASSERT(rm != NULL); @@ -344,7 +344,7 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer, uint32_t offset; size_t bytesleft; off_t sector; - FAR uint8_t *userbuffer = (FAR uint8_t*)buffer; + FAR uint8_t *userbuffer = (FAR uint8_t *)buffer; int sectorndx; int ret; @@ -586,7 +586,7 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * the file. */ - *ppv = (void*)(rm->rm_xipbase + rf->rf_startoffset); + *ppv = (FAR void *)(rm->rm_xipbase + rf->rf_startoffset); return OK; } @@ -617,7 +617,7 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp) * structure */ - rm = (FAR struct romfs_mountpt_s*)newp->f_inode->i_private; + rm = (FAR struct romfs_mountpt_s *)newp->f_inode->i_private; DEBUGASSERT(rm != NULL); /* Check if the mount is still healthy */ @@ -789,7 +789,7 @@ static int romfs_readdir(FAR struct inode *mountpt, /* Loop, skipping over unsupported items in the file system */ - for (;;) + for (; ; ) { /* Have we reached the end of the directory */ @@ -955,7 +955,7 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data, /* Mounted! */ - *handle = (void*)rm; + *handle = (FAR void *)rm; romfs_semgive(rm); return OK; @@ -982,7 +982,7 @@ errout_with_sem: static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { - FAR struct romfs_mountpt_s *rm = (FAR struct romfs_mountpt_s*)handle; + FAR struct romfs_mountpt_s *rm = (FAR struct romfs_mountpt_s *)handle; int ret; fvdbg("Entry\n"); @@ -1159,20 +1159,20 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath, { /* It's a read-only directory name */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; if (IS_EXECUTABLE(dirinfo.rd_next)) { - buf->st_mode |= S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode |= S_IXOTH | S_IXGRP | S_IXUSR; } } else if (IS_FILE(dirinfo.rd_next)) { /* It's a read-only file name */ - buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; if (IS_EXECUTABLE(dirinfo.rd_next)) { - buf->st_mode |= S_IXOTH|S_IXGRP|S_IXUSR; + buf->st_mode |= S_IXOTH | S_IXGRP | S_IXUSR; } } else diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 65528d1378..7269bf14bc 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -108,7 +108,7 @@ static uint32_t romfs_devread32(struct romfs_mountpt_s *rm, int ndx) { /* Extract the value */ - uint32_t value = *(uint32_t*)&rm->rm_buffer[ndx]; + uint32_t value = *(FAR uint32_t *)&rm->rm_buffer[ndx]; /* Value is begin endian -- return the native host endian-ness. */ #ifdef CONFIG_ENDIAN_BIG @@ -228,7 +228,7 @@ int16_t romfs_devcacheread(struct romfs_mountpt_s *rm, uint32_t offset) } else { - /* In non-XIP mode, we will have to read the new sector.*/ + /* In non-XIP mode, we will have to read the new sector. */ ret = romfs_hwread(rm, rm->rm_buffer, sector, 1); if (ret < 0) @@ -477,7 +477,7 @@ int romfs_filecacheread(struct romfs_mountpt_s *rm, struct romfs_file_s *rf, } else { - /* In non-XIP mode, we will have to read the new sector.*/ + /* In non-XIP mode, we will have to read the new sector. */ fvdbg("Calling romfs_hwread\n"); ret = romfs_hwread(rm, rf->rf_buffer, sector, 1); @@ -560,7 +560,7 @@ int romfs_hwconfigure(struct romfs_mountpt_s *rm) /* Allocate the device cache buffer for normal sector accesses */ - rm->rm_buffer = (uint8_t*)kmm_malloc(rm->rm_hwsectorsize); + rm->rm_buffer = (FAR uint8_t *)kmm_malloc(rm->rm_hwsectorsize); if (!rm->rm_buffer) { return -ENOMEM; @@ -608,7 +608,7 @@ int romfs_fsconfigure(struct romfs_mountpt_s *rm) /* The root directory entry begins right after the header */ - name = (const char*)&rm->rm_buffer[ROMFS_VHDR_VOLNAME]; + name = (FAR const char *)&rm->rm_buffer[ROMFS_VHDR_VOLNAME]; rm->rm_rootoffset = ROMFS_ALIGNUP(ROMFS_VHDR_VOLNAME + strlen(name) + 1); /* and return success */ @@ -648,7 +648,7 @@ int romfs_fileconfigure(struct romfs_mountpt_s *rm, struct romfs_file_s *rf) /* Create a file buffer to support partial sector accesses */ - rf->rf_buffer = (uint8_t*)kmm_malloc(rm->rm_hwsectorsize); + rf->rf_buffer = (FAR uint8_t *)kmm_malloc(rm->rm_hwsectorsize); if (!rf->rf_buffer) { return -ENOMEM; @@ -738,7 +738,7 @@ int romfs_finddirentry(struct romfs_mountpt_s *rm, entryname = path; terminator = NULL; - for (;;) + for (; ; ) { /* Find the start of the next path component */ @@ -876,7 +876,7 @@ int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32_t offset, */ offset += ROMFS_FHDR_NAME; - for (namelen = 0, done = false; namelen < NAME_MAX && !done;) + for (namelen = 0, done = false; namelen < NAME_MAX && !done; ) { /* Read the sector into memory */ @@ -892,7 +892,7 @@ int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32_t offset, { /* Yes.. then this chunk is less than 16 */ - chunklen = strlen((char*)&rm->rm_buffer[ndx]); + chunklen = strlen((FAR char *)&rm->rm_buffer[ndx]); done = true; } else @@ -948,7 +948,7 @@ int romfs_datastart(struct romfs_mountpt_s *rm, uint32_t offset, /* Loop until the header size is obtained. */ offset += ROMFS_FHDR_NAME; - for (;;) + for (; ; ) { /* Read the sector into memory */ diff --git a/fs/semaphore/sem_close.c b/fs/semaphore/sem_close.c index 3e9dfffa5c..97d2bf5886 100644 --- a/fs/semaphore/sem_close.c +++ b/fs/semaphore/sem_close.c @@ -127,23 +127,23 @@ int sem_close(FAR sem_t *sem) * now. */ - if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0) - { - /* Destroy the semaphore and free the container */ + if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0) + { + /* Destroy the semaphore and free the container */ - sem_destroy(&nsem->ns_sem); - group_free(NULL, nsem); + sem_destroy(&nsem->ns_sem); + group_free(NULL, nsem); - /* Release and free the inode container. If it has been properly - * unlinked, then the peer pointer should be NULL. - */ + /* Release and free the inode container. If it has been properly + * unlinked, then the peer pointer should be NULL. + */ - inode_semgive(); + inode_semgive(); - DEBUGASSERT(inode->i_peer == NULL); - inode_free(inode); - return OK; - } + DEBUGASSERT(inode->i_peer == NULL); + inode_free(inode); + return OK; + } inode_semgive(); return OK; diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index e5e46d9ba6..4bae07352c 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -125,7 +125,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) FAR const char *relpath = NULL; mode_t mode; FAR struct nsem_inode_s *nsem; - FAR sem_t *sem = (FAR sem_t*)ERROR; + FAR sem_t *sem = (FAR sem_t *)ERROR; char fullpath[MAX_SEMPATH]; unsigned value; int errcode; @@ -168,7 +168,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) * create a new semaphore with this name. */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { errcode = EEXIST; goto errout_with_inode; @@ -195,10 +195,10 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) goto errout_with_lock; } - /* Create the semaphore. First we have to extract the additional - * parameters from the variable argument list. - * REVISIT: Mode parameter is not currently used. - */ + /* Create the semaphore. First we have to extract the additional + * parameters from the variable argument list. + * REVISIT: Mode parameter is not currently used. + */ va_start(ap, oflags); mode = va_arg(ap, mode_t); diff --git a/fs/smartfs/smartfs_mksmartfs.c b/fs/smartfs/smartfs_mksmartfs.c index 620a6096fb..076915e169 100644 --- a/fs/smartfs/smartfs_mksmartfs.c +++ b/fs/smartfs/smartfs_mksmartfs.c @@ -93,7 +93,7 @@ int mksmartfs(FAR const char *pathname, uint8_t nrootdirs) int mksmartfs(FAR const char *pathname) #endif { - struct inode* inode; + FAR struct inode *inode; struct smart_format_s fmt; int ret; int x; diff --git a/fs/smartfs/smartfs_procfs.c b/fs/smartfs/smartfs_procfs.c index 960f37893a..c0f60c13e6 100644 --- a/fs/smartfs/smartfs_procfs.c +++ b/fs/smartfs/smartfs_procfs.c @@ -88,7 +88,7 @@ struct smartfs_level1_s * open / read / stat, etc. */ - struct smartfs_mountpt_s* mount; + FAR struct smartfs_mountpt_s *mount; uint8_t direntry; }; @@ -216,7 +216,7 @@ static int smartfs_find_dirref(FAR const char *relpath, FAR struct smartfs_level1_s *level1) { int ret = -ENOENT; - FAR struct smartfs_mountpt_s* mount; + FAR struct smartfs_mountpt_s *mount; uint16_t x; FAR char * str; @@ -715,7 +715,7 @@ static int smartfs_stat(const char *relpath, struct stat *buf) ret = smartfs_find_dirref(relpath, &level1); - buf->st_mode = S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IROTH | S_IRGRP | S_IRUSR; if (ret == OK) { if (level1.base.level < 3) @@ -982,7 +982,6 @@ static size_t smartfs_erasemap_read(FAR struct file *filep, FAR char *buffer, copylen = 0; for (y = 0; y < rows; y++) { - //for (x = 0; x < 128; x++) for (x = 0; x < cols; x++) { /* Copy data to the buffer */ diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index 55228b2a5d..fffba254b7 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -236,7 +236,7 @@ static int smartfs_open(FAR struct file *filep, const char *relpath, /* It would be an error if we are asked to create it exclusively */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { /* Already exists -- can't create it exclusively */ @@ -435,7 +435,7 @@ static int smartfs_close(FAR struct file *filep) /* Now free the pointer */ - filep->f_priv = NULL;; + filep->f_priv = NULL; if (sf->entry.name != NULL) { /* Free the space for the name too */ @@ -1532,7 +1532,7 @@ static int smartfs_bind(FAR struct inode *blkdriver, const void *data, return ret; } - *handle = (void*)fs; + *handle = (FAR void *)fs; smartfs_semgive(fs); return OK; } @@ -1548,7 +1548,7 @@ static int smartfs_bind(FAR struct inode *blkdriver, const void *data, static int smartfs_unbind(FAR void *handle, FAR struct inode **blkdriver, unsigned int flags) { - struct smartfs_mountpt_s *fs = (struct smartfs_mountpt_s*)handle; + FAR struct smartfs_mountpt_s *fs = (FAR struct smartfs_mountpt_s *)handle; int ret; if (!fs) @@ -2105,7 +2105,8 @@ static int smartfs_stat(struct inode *mountpt, const char *relpath, struct stat { /* It's directory name of the mount point */ - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IWOTH|S_IWGRP|S_IWUSR; + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR | S_IWOTH | + S_IWGRP | S_IWUSR; ret = OK; goto errout_with_semaphore; } diff --git a/fs/smartfs/smartfs_utils.c b/fs/smartfs/smartfs_utils.c index db0de34fa0..58dcde8e6b 100644 --- a/fs/smartfs/smartfs_utils.c +++ b/fs/smartfs/smartfs_utils.c @@ -74,7 +74,7 @@ #if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || \ (defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)) -static struct smartfs_mountpt_s* g_mounthead = NULL; +static struct smartfs_mountpt_s *g_mounthead = NULL; #endif /**************************************************************************** @@ -840,11 +840,11 @@ errout: * ****************************************************************************/ -int smartfs_createentry(struct smartfs_mountpt_s *fs, - uint16_t parentdirsector, const char* filename, - uint16_t type, - mode_t mode, struct smartfs_entry_s *direntry, - uint16_t sectorno, FAR struct smartfs_ofile_s *sf) +int smartfs_createentry(FAR struct smartfs_mountpt_s *fs, + uint16_t parentdirsector, FAR const char *filename, + uint16_t type, mode_t mode, + FAR struct smartfs_entry_s *direntry, + uint16_t sectorno, FAR struct smartfs_ofile_s *sf) { struct smart_read_write_s readwrite; int ret; @@ -908,9 +908,9 @@ int smartfs_createentry(struct smartfs_mountpt_s *fs, if ((entry->flags == SMARTFS_ERASEDSTATE_16BIT) || ((entry->flags & #endif - (SMARTFS_DIRENT_EMPTY | SMARTFS_DIRENT_ACTIVE) ) == + (SMARTFS_DIRENT_EMPTY | SMARTFS_DIRENT_ACTIVE)) == (~SMARTFS_ERASEDSTATE_16BIT & - (SMARTFS_DIRENT_EMPTY | SMARTFS_DIRENT_ACTIVE) ))) + (SMARTFS_DIRENT_EMPTY | SMARTFS_DIRENT_ACTIVE)))) { /* We found an empty entry. Use it. */ @@ -1034,7 +1034,8 @@ int smartfs_createentry(struct smartfs_mountpt_s *fs, ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long) &readwrite); if (ret < 0) { - fdbg("Error %d setting new sector type for sector %d\n",ret, nextsector); + fdbg("Error %d setting new sector type for sector %d\n", + ret, nextsector); goto errout; } } @@ -1122,7 +1123,7 @@ int smartfs_deleteentry(struct smartfs_mountpt_s *fs, struct smart_read_write_s readwrite; /* Okay, delete the file. Loop through each sector and release them - + * * TODO: We really should walk the list backward to avoid lost * sectors in the event we lose power. However this requires * allocating a buffer to build the sector list since we don't @@ -1493,7 +1494,7 @@ int smartfs_truncatefile(struct smartfs_mountpt_s *fs, } /* Now deal with the first sector in the event we are using a sector buffer - like we would be if CRC is enabled. + * like we would be if CRC is enabled. */ #ifdef CONFIG_SMARTFS_USE_SECTOR_BUFFER @@ -1531,7 +1532,7 @@ errout: ****************************************************************************/ #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS) -struct smartfs_mountpt_s* smartfs_get_first_mount(void) +FAR struct smartfs_mountpt_s *smartfs_get_first_mount(void) { return g_mounthead; } diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index f57d3dd2a7..491d71f74a 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -2085,7 +2085,8 @@ static int unionfs_unlink(FAR struct inode *mountpt, } /* Check if some exists at this path on file system 1. This might be - * a file or a directory*/ + * a file or a directory + */ um = &ui->ui_fs[0]; ret = unionfs_trystat(um->um_node, relpath, um->um_prefix, &buf); @@ -2612,7 +2613,6 @@ int unionfs_mount(FAR const char *fspath1, FAR const char *prefix1, errout_with_semaphore: inode_semgive(); -//errout_with_prefix2: if (ui->ui_fs[1].um_prefix != NULL) { kmm_free(ui->ui_fs[1].um_prefix); diff --git a/fs/vfs/fs_dup.c b/fs/vfs/fs_dup.c index 8e8edb86fa..03b8b751ab 100644 --- a/fs/vfs/fs_dup.c +++ b/fs/vfs/fs_dup.c @@ -77,7 +77,8 @@ int dup(int fd) if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS) { /* Its a valid file descriptor.. dup the file descriptor using any - * other file descriptor*/ + * other file descriptor + */ ret = fs_dupfd(fd, 0); } diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index ed44e47e21..ae903970fe 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -107,7 +107,7 @@ int open(const char *path, int oflags, ...) /* If the file is opened for creation, then get the mode bits */ - if ((oflags & (O_WRONLY|O_CREAT)) != 0) + if ((oflags & (O_WRONLY | O_CREAT)) != 0) { va_list ap; va_start(ap, oflags); diff --git a/fs/vfs/fs_read.c b/fs/vfs/fs_read.c index c5cdc701e6..f1d6097236 100644 --- a/fs/vfs/fs_read.c +++ b/fs/vfs/fs_read.c @@ -101,7 +101,7 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes) * signature and position in the operations vtable. */ - ret = (int)inode->u.i_ops->read(filep, (char*)buf, (size_t)nbytes); + ret = (int)inode->u.i_ops->read(filep, (FAR char *)buf, (size_t)nbytes); } /* If an error occurred, set errno and return -1 (ERROR) */ diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c index 60151232f2..d71d8e28a1 100644 --- a/fs/vfs/fs_select.c +++ b/fs/vfs/fs_select.c @@ -238,7 +238,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, if (readfds) { - if (pollset[ndx].revents & (POLLIN|POLLHUP)) + if (pollset[ndx].revents & (POLLIN | POLLHUP)) { FD_SET(pollset[ndx].fd, readfds); ret++; diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index 1bd9d05d8e..a96cf3be71 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -58,7 +58,7 @@ static inline int statpseudo(FAR struct inode *inode, FAR struct stat *buf) { /* Most of the stat entries just do not apply */ - memset(buf, 0, sizeof(struct stat) ); + memset(buf, 0, sizeof(struct stat)); if (INODE_IS_SPECIAL(inode)) { @@ -90,12 +90,12 @@ static inline int statpseudo(FAR struct inode *inode, FAR struct stat *buf) { if (inode->u.i_ops->read) { - buf->st_mode = S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode = S_IROTH | S_IRGRP | S_IRUSR; } if (inode->u.i_ops->write) { - buf->st_mode |= S_IWOTH|S_IWGRP|S_IWUSR; + buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR; } if (INODE_IS_MOUNTPT(inode)) @@ -123,7 +123,7 @@ static inline int statpseudo(FAR struct inode *inode, FAR struct stat *buf) * write-able. */ - buf->st_mode |= S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + buf->st_mode |= S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; } return OK; @@ -137,8 +137,8 @@ static inline int statroot(FAR struct stat *buf) { /* There is no inode associated with the fake root directory */ - memset(buf, 0, sizeof(struct stat) ); - buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR; + memset(buf, 0, sizeof(struct stat)); + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; return OK; } -- GitLab From e9bd8bceb468d9534698e1044a22c1a072244751 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 12 Oct 2015 07:45:02 -0600 Subject: [PATCH 223/858] nuttx/libc: Fix some spacing and alignment issues --- libc/aio/lio_listio.c | 4 +- libc/math/lib_rint.c | 4 +- libc/math/lib_rintf.c | 4 +- libc/math/lib_rintl.c | 4 +- libc/math/lib_trunc.c | 10 ++- libc/math/lib_truncf.c | 10 ++- libc/math/lib_truncl.c | 5 +- libc/misc/lib_crc32.c | 2 +- libc/misc/lib_match.c | 2 +- libc/net/lib_inetaddr.c | 2 +- libc/net/lib_inetntoa.c | 4 +- libc/net/lib_inetntop.c | 2 +- libc/net/lib_inetpton.c | 4 +- libc/net/lib_shutdown.c | 4 +- libc/netdb/lib_dnsclient.c | 14 ++-- libc/netdb/lib_gethostbyaddrr.c | 42 +++++----- libc/netdb/lib_parsehostfile.c | 2 +- libc/queue/sq_rem.c | 2 +- libc/stdio/lib_dtoa.c | 52 ++++++++---- libc/stdio/lib_fopen.c | 2 +- libc/stdio/lib_libfflush.c | 8 +- libc/stdio/lib_libfgets.c | 2 +- libc/stdio/lib_libflushall.c | 64 +++++++------- libc/stdio/lib_libfread.c | 8 +- libc/stdio/lib_libvsprintf.c | 6 +- libc/stdio/lib_sscanf.c | 18 ++-- libc/stdlib/lib_qsort.c | 6 +- libc/stdlib/lib_strtod.c | 2 +- libc/string/lib_memccpy.c | 4 +- libc/string/lib_memcpy.c | 4 +- libc/string/lib_memmove.c | 14 ++-- libc/string/lib_memset.c | 20 ++--- libc/string/lib_strcasecmp.c | 4 +- libc/string/lib_strcasestr.c | 30 +++---- libc/string/lib_strcmp.c | 4 +- libc/string/lib_strdup.c | 4 +- libc/string/lib_strndup.c | 2 +- libc/string/lib_strpbrk.c | 4 +- libc/string/lib_strrchr.c | 4 +- libc/string/lib_strstr.c | 16 ++-- libc/string/lib_vikmemcpy.c | 6 +- libc/time/lib_dayofweek.c | 3 +- libc/time/lib_gmtimer.c | 13 +-- libc/time/lib_localtime.c | 11 +-- libc/unistd/lib_getopt.c | 142 ++++++++++++++++---------------- libc/unistd/lib_usleep.c | 2 +- libc/wqueue/work_cancel.c | 2 +- libc/wqueue/work_usrthread.c | 2 +- 48 files changed, 312 insertions(+), 268 deletions(-) diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index e4e4a71a7e..0889fd9b14 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -305,7 +305,7 @@ static int lio_sigsetup(FAR struct aiocb * const *list, int nent, /* Attach our signal handler */ - printf("waiter_main: Registering signal handler\n" ); + printf("waiter_main: Registering signal handler\n"); act.sa_sigaction = lio_sighandler; act.sa_flags = SA_SIGINFO; @@ -352,7 +352,7 @@ static int lio_waitall(FAR struct aiocb * const *list, int nent) /* Loop until all I/O completes */ - for (;;) + for (; ; ) { /* Check if all I/O has completed */ diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index c424d05365..d180c2a251 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -111,7 +111,7 @@ double rint(double x) if (fremainder == -0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ double rint(double x) if (fremainder == 0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c index f0a329733f..d72cbad7fd 100644 --- a/libc/math/lib_rintf.c +++ b/libc/math/lib_rintf.c @@ -111,7 +111,7 @@ float rintf(float x) if (fremainder == -0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ float rintf(float x) if (fremainder == 0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c index 439c75566f..c6dc09a3b8 100644 --- a/libc/math/lib_rintl.c +++ b/libc/math/lib_rintl.c @@ -111,7 +111,7 @@ long double rintl(long double x) if (fremainder == -0.5) { - llinteger = ((llinteger+1)&~1); + llinteger = ((llinteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ long double rintl(long double x) if (fremainder == 0.5) { - llinteger = ((llinteger+1)&~1); + llinteger = ((llinteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_trunc.c b/libc/math/lib_trunc.c index b0a93f4575..3f32577402 100644 --- a/libc/math/lib_trunc.c +++ b/libc/math/lib_trunc.c @@ -43,7 +43,15 @@ #ifdef CONFIG_HAVE_DOUBLE double trunc(double x) { - union {double f; uint64_t i;} u = {x}; + union + { + double f; + uint64_t i; + } u = + { + x + }; + int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12; uint64_t m; volatile float __x; diff --git a/libc/math/lib_truncf.c b/libc/math/lib_truncf.c index 73ce7b0ad8..97b1f707bd 100644 --- a/libc/math/lib_truncf.c +++ b/libc/math/lib_truncf.c @@ -42,7 +42,15 @@ float truncf(float x) { - union {float f; uint32_t i;} u = {x}; + union + { + float f; + uint32_t i; + } u = + { + x + }; + int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9; uint32_t m; volatile float __x; diff --git a/libc/math/lib_truncl.c b/libc/math/lib_truncl.c index fce958557c..8fc87f8a55 100644 --- a/libc/math/lib_truncl.c +++ b/libc/math/lib_truncl.c @@ -58,7 +58,10 @@ union ldshape long double truncl(long double x) { - union ldshape u = {x}; + union ldshape u = + { + x + }; int e = u.i.se & 0x7fff; int s = u.i.se >> 15; long double y; diff --git a/libc/misc/lib_crc32.c b/libc/misc/lib_crc32.c index 0c111a8824..40e7c014a0 100644 --- a/libc/misc/lib_crc32.c +++ b/libc/misc/lib_crc32.c @@ -37,7 +37,7 @@ * - The values must be right-shifted by eight bits by the updcrc logic; the shift must * be u_(bring in zeroes). On some hardware you could probably optimize the shift in * assembler by using byte-swap instructions polynomial $edb88320 - ************************************************************************************************/ + ************************************************************************************************/ /************************************************************************************************ * Included Files diff --git a/libc/misc/lib_match.c b/libc/misc/lib_match.c index 3bebb1a946..690d111a5c 100644 --- a/libc/misc/lib_match.c +++ b/libc/misc/lib_match.c @@ -191,7 +191,7 @@ int match(const char *pattern, const char *string) { const char *or; - for (;;) + for (; ; ) { or = strchr(pattern, '|'); if (or == (char *)0) diff --git a/libc/net/lib_inetaddr.c b/libc/net/lib_inetaddr.c index c05b596974..5a2d9a97b2 100644 --- a/libc/net/lib_inetaddr.c +++ b/libc/net/lib_inetaddr.c @@ -55,7 +55,7 @@ * The inet_addr() function converts the string pointed to by cp, in the * standard IPv4 dotted decimal notation, to an integer value suitable for * use as an Internet address. - + * ****************************************************************************/ in_addr_t inet_addr(FAR const char *cp) diff --git a/libc/net/lib_inetntoa.c b/libc/net/lib_inetntoa.c index 60c5742871..4bd49db921 100644 --- a/libc/net/lib_inetntoa.c +++ b/libc/net/lib_inetntoa.c @@ -65,7 +65,7 @@ FAR char *inet_ntoa(struct in_addr in) { static char buffer[INET_ADDRSTRLEN+2]; - FAR unsigned char *ptr = (FAR unsigned char*)&in.s_addr; + FAR unsigned char *ptr = (FAR unsigned char *)&in.s_addr; sprintf(buffer, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]); return buffer; } @@ -73,7 +73,7 @@ FAR char *inet_ntoa(struct in_addr in) FAR char *_inet_ntoa(in_addr_t in) { static char buffer[INET_ADDRSTRLEN+2]; - FAR unsigned char *ptr = (FAR unsigned char*)∈ + FAR unsigned char *ptr = (FAR unsigned char *)∈ sprintf(buffer, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]); return buffer; } diff --git a/libc/net/lib_inetntop.c b/libc/net/lib_inetntop.c index 460ec31b10..2a6037f97c 100644 --- a/libc/net/lib_inetntop.c +++ b/libc/net/lib_inetntop.c @@ -107,7 +107,7 @@ static int inet_ipv4_ntop(FAR const void *src, FAR char *dest, socklen_t size) return -ENOSPC; } - ptr = (FAR char*)src; + ptr = (FAR char *)src; sprintf(dest, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); return OK; } diff --git a/libc/net/lib_inetpton.c b/libc/net/lib_inetpton.c index c69af48bc1..96338bde11 100644 --- a/libc/net/lib_inetpton.c +++ b/libc/net/lib_inetpton.c @@ -111,7 +111,7 @@ static int inet_ipv4_pton(FAR const char *src, FAR void *dest) numoffset = 0; ndots = 0; - for (;;) + for (; ; ) { ch = (uint8_t)src[srcoffset++]; @@ -225,7 +225,7 @@ static int inet_ipv6_pton(FAR const char *src, FAR void *dest) nrsep = 0; rtime = false; - for (;;) + for (; ; ) { ch = (uint8_t)src[srcoffset++]; diff --git a/libc/net/lib_shutdown.c b/libc/net/lib_shutdown.c index 6b71f847c3..028fb96eeb 100644 --- a/libc/net/lib_shutdown.c +++ b/libc/net/lib_shutdown.c @@ -59,7 +59,7 @@ * * The shutdown() function disables subsequent send and/or receive * operations on a socket, depending on the value of the how argument. - + * * Input Paramteers: * sockfd - Specifies the file descriptor of the socket. * how - Specifies the type of shutdown. The values are as follows: @@ -71,7 +71,7 @@ * Returned Value: * Upon successful completion, shutdown() will return 0; otherwise, -1 will * be returned and errno set to indicate the error. - + * * EBADF - The socket argument is not a valid file descriptor. * EINVAL - The how argument is invalid. * ENOTCONN - The socket is not connected. diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index a959005f53..c510f2f431 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -534,11 +534,11 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, int d = 64; nameptr = dns_parse_name((uint8_t *)buffer + 12) + 4; - for (;;) + for (; ; ) { ndbg("%02X %02X %02X %02X %02X %02X %02X %02X \n", - nameptr[0],nameptr[1],nameptr[2],nameptr[3], - nameptr[4],nameptr[5],nameptr[6],nameptr[7]); + nameptr[0], nameptr[1], nameptr[2], nameptr[3], + nameptr[4], nameptr[5], nameptr[6], nameptr[7]); nameptr += 8; d -= 8; @@ -589,10 +589,10 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, ans->u.ipv4.s_addr = *(FAR uint32_t *)(nameptr + 10); nvdbg("IPv4 address: %d.%d.%d.%d\n", - (ans->u.ipv4.s_addr ) & 0xff, - (ans->u.ipv4.s_addr >> 8 ) & 0xff, - (ans->u.ipv4.s_addr >> 16 ) & 0xff, - (ans->u.ipv4.s_addr >> 24 ) & 0xff); + (ans->u.ipv4.s_addr ) & 0xff, + (ans->u.ipv4.s_addr >> 8 ) & 0xff, + (ans->u.ipv4.s_addr >> 16) & 0xff, + (ans->u.ipv4.s_addr >> 24) & 0xff); if (*addrlen >= sizeof(struct sockaddr_in)) { diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index f32fdc1d29..812b1fedb9 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -191,36 +191,32 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, return -ERANGE; } + info = (FAR struct hostent_info_s *)buf; + dest = info->hi_data; + buflen -= (sizeof(struct hostent_info_s) - 1); - info = (FAR struct hostent_info_s *)buf; - dest = info->hi_data; - buflen -= (sizeof(struct hostent_info_s) - 1); + memset(host, 0, sizeof(struct hostent)); + memset(info, 0, sizeof(struct hostent_info_s)); + memcpy(dest, src, addrlen); - memset(host, 0, sizeof(struct hostent)); - memset(info, 0, sizeof(struct hostent_info_s)); - memcpy(dest, src, addrlen); + info->hi_addrlist[0] = dest; + host->h_addr_list = info->hi_addrlist; + host->h_length = addrlen; - info->hi_addrlist[0] = dest; - host->h_addr_list = info->hi_addrlist; - host->h_length = addrlen; + dest += addrlen; + buflen -= addrlen; - dest += addrlen; - buflen -= addrlen; + /* And copy localhost host name */ - /* And copy localhost host name */ - - namelen = strlen(g_lo_hostname); - if (addrlen + namelen + 1 > buflen) - { - herrnocode = ERANGE; - goto errorout_with_herrnocode; - } - - strncpy(dest, g_lo_hostname, buflen); - return 0; + namelen = strlen(g_lo_hostname); + if (addrlen + namelen + 1 > buflen) + { + herrnocode = ERANGE; + goto errorout_with_herrnocode; } - return 1; + strncpy(dest, g_lo_hostname, buflen); + return 0; errorout_with_herrnocode: if (h_errnop) diff --git a/libc/netdb/lib_parsehostfile.c b/libc/netdb/lib_parsehostfile.c index 8913a8a2b2..177c00a3f3 100644 --- a/libc/netdb/lib_parsehostfile.c +++ b/libc/netdb/lib_parsehostfile.c @@ -61,7 +61,7 @@ /* Check if character is any kind of white space (except for newline) */ #define lib_isspace(c) \ - ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\f' || c== '\v') + ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\f' || c == '\v') /**************************************************************************** * Private Type Definitions diff --git a/libc/queue/sq_rem.c b/libc/queue/sq_rem.c index 2abf6d34e3..dd51390859 100644 --- a/libc/queue/sq_rem.c +++ b/libc/queue/sq_rem.c @@ -66,7 +66,7 @@ void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue) else { FAR sq_entry_t *prev; - for (prev = (FAR sq_entry_t*)queue->head; + for (prev = (FAR sq_entry_t *)queue->head; prev && prev->flink != node; prev = prev->flink); diff --git a/libc/stdio/lib_dtoa.c b/libc/stdio/lib_dtoa.c index 6241a486b4..68ae7b2098 100644 --- a/libc/stdio/lib_dtoa.c +++ b/libc/stdio/lib_dtoa.c @@ -427,7 +427,10 @@ static Bigint *pow5mult(Bigint * b, int k) { Bigint *b1, *p5, *p51; int i; - static int p05[3] = { 5, 25, 125 }; + static int p05[3] = + { + 5, 25, 125 + }; if ((i = k & 3)) b = multadd(b, p05[i - 1], 0); @@ -444,7 +447,7 @@ static Bigint *pow5mult(Bigint * b, int k) p5->next = 0; } - for (;;) + for (; ; ) { if (k & 1) { @@ -574,7 +577,8 @@ static int cmp(Bigint * a, Bigint * b) xa = xa0 + j; xb0 = b->x; xb = xb0 + j; - for (;;) + + for (; ; ) { if (*--xa != *--xb) { @@ -807,13 +811,27 @@ static const double tens[] = }; #ifdef IEEE_Arith -static const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; +static const double bigtens[] = +{ + 1e16, 1e32, 1e64, 1e128, 1e256 +}; + +static const double tinytens[] = +{ + 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 +}; # define n_bigtens 5 #else -static const double bigtens[] = { 1e16, 1e32 }; -static const double tinytens[] = { 1e-16, 1e-32 }; +static const double bigtens[] = +{ + 1e16, 1e32 +}; + +static const double tinytens[] = +{ + 1e-16, 1e-32 +}; # define n_bigtens 2 #endif @@ -1284,7 +1302,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) /* Use Steele & White method of only generating digits needed. */ eps = 0.5 / tens[ilim - 1] - eps; - for (i = 0;;) + for (i = 0; ; ) { L = (int)d; d -= L; @@ -1314,7 +1332,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) /* Generate ilim digits, then fix them up. */ eps *= tens[ilim - 1]; - for (i = 1;; i++, d *= 10.) + for (i = 1; ; i++, d *= 10.) { L = (int)d; d -= L; @@ -1363,7 +1381,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) goto one_digit; } - for (i = 1;; i++) + for (i = 1; ; i++) { L = (int)(d / ds); d -= L * ds; @@ -1586,7 +1604,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) mhi = lshift(mhi, Log2P); } - for (i = 1;; i++) + for (i = 1; ; i++) { dig = quorem(b, S) + '0'; /* Do we yet have the shortest decimal string that will round to d? */ @@ -1634,8 +1652,10 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) if (j_1 > 0) { if (dig == '9') - { /* possible if i == 1 */ - round_9_up: + { + /* possible if i == 1 */ + + round_9_up: *s++ = '9'; goto roundoff; } @@ -1664,7 +1684,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) } else { - for (i = 1;; i++) + for (i = 1; ; i++) { *s++ = dig = quorem(b, S) + '0'; if (i >= ilim) @@ -1713,7 +1733,9 @@ ret: ret1: Bfree(b); if (s == s0) - { /* Don't return empty string */ + { + /* Don't return empty string */ + *s++ = '0'; k = 0; } diff --git a/libc/stdio/lib_fopen.c b/libc/stdio/lib_fopen.c index a29140ebae..fc0856ce5b 100644 --- a/libc/stdio/lib_fopen.c +++ b/libc/stdio/lib_fopen.c @@ -137,7 +137,7 @@ static int lib_mode2oflags(FAR const char *mode) { /* Write to the end of the file */ - oflags = O_WROK|O_CREAT|O_APPEND; + oflags = O_WROK | O_CREAT | O_APPEND; state = MODE_A; } else diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index 6c0dfabe83..ff9aaece4b 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -121,11 +121,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) if (stream->fs_bufpos != stream->fs_bufstart) { - /* Make sure that the buffer holds buffered write data. We do not - * support concurrent read/write buffer usage. - */ + /* Make sure that the buffer holds buffered write data. We do not + * support concurrent read/write buffer usage. + */ - if (stream->fs_bufread != stream->fs_bufstart) + if (stream->fs_bufread != stream->fs_bufstart) { /* The buffer holds read data... just return zero meaning "no bytes * remaining in the buffer." diff --git a/libc/stdio/lib_libfgets.c b/libc/stdio/lib_libfgets.c index 210d273bf3..884cc1f535 100644 --- a/libc/stdio/lib_libfgets.c +++ b/libc/stdio/lib_libfgets.c @@ -177,7 +177,7 @@ FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream, * the next character and one for the null terminator. */ - for (;;) + for (; ; ) { /* Get the next character */ diff --git a/libc/stdio/lib_libflushall.c b/libc/stdio/lib_libflushall.c index 7c7b8d9b66..85e807a9ea 100644 --- a/libc/stdio/lib_libflushall.c +++ b/libc/stdio/lib_libflushall.c @@ -97,38 +97,38 @@ int lib_flushall(FAR struct streamlist *list) if (list) { - int i; - - /* Process each stream in the thread's stream list */ - - stream_semtake(list); - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - FILE *stream = &list->sl_streams[i]; - - /* If the stream is open (i.e., assigned a non-negative file - * descriptor) and opened for writing, then flush all of the pending - * write data in the stream. - */ - - if (stream->fs_fd >= 0 && (stream->fs_oflags & O_WROK) != 0) - { - /* Flush the writable FILE */ - - ret = lib_fflush(stream, true); - if (ret < 0) - { - /* An error occurred during the flush AND/OR we were unable - * to flush all of the buffered write data. Remember the - * last errcode. - */ - - lasterrno = ret; - } - } - } - - stream_semgive(list); + int i; + + /* Process each stream in the thread's stream list */ + + stream_semtake(list); + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + FILE *stream = &list->sl_streams[i]; + + /* If the stream is open (i.e., assigned a non-negative file + * descriptor) and opened for writing, then flush all of the pending + * write data in the stream. + */ + + if (stream->fs_fd >= 0 && (stream->fs_oflags & O_WROK) != 0) + { + /* Flush the writable FILE */ + + ret = lib_fflush(stream, true); + if (ret < 0) + { + /* An error occurred during the flush AND/OR we were unable + * to flush all of the buffered write data. Remember the + * last errcode. + */ + + lasterrno = ret; + } + } + } + + stream_semgive(list); } /* If any flush failed, return the errorcode of the last failed flush */ diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index 27011738c9..48ab4ad4cf 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -86,10 +86,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { - unsigned char *dest = (unsigned char*)ptr; - ssize_t bytes_read; + FAR unsigned char *dest = (FAR unsigned char*)ptr; + ssize_t bytes_read; #if CONFIG_STDIO_BUFFER_SIZE > 0 - int ret; + int ret; #endif /* Make sure that reading from this stream is allowed */ @@ -288,7 +288,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) #if CONFIG_STDIO_BUFFER_SIZE > 0 shortread: #endif - bytes_read = dest - (unsigned char*)ptr; + bytes_read = dest - (FAR unsigned char *)ptr; /* Set or clear the EOF indicator. If we get here because of a * short read and the total number of* bytes read is zero, then diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index 61cac29283..634b172ad0 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -1291,7 +1291,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a /* Accumulate the field width integer. */ int n = ((int)(FMT_CHAR)) - (int)'0'; - for (;;) + for (; ; ) { FMT_NEXT; if (FMT_CHAR >= '0' && FMT_CHAR <= '9') @@ -1363,10 +1363,10 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a #endif /* Get the string to output */ - ptmp = va_arg(ap, char *); + ptmp = va_arg(ap, FAR char *); if (!ptmp) { - ptmp = (char*)g_nullstring; + ptmp = (FAR char *)g_nullstring; } /* Get the width of the string and perform right-justification diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c index c094cb1fb3..d4996dceef 100644 --- a/libc/stdio/lib_sscanf.c +++ b/libc/stdio/lib_sscanf.c @@ -168,7 +168,7 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...) int count; va_start(ap, fmt); - count = vsscanf((FAR const char*)buf, fmt, ap); + count = vsscanf((FAR const char *)buf, fmt, ap); va_end(ap); return count; } @@ -274,7 +274,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) tv = NULL; /* To avoid warnings about begin uninitialized */ if (!noassign) { - tv = va_arg(ap, char*); + tv = va_arg(ap, FAR char *); tv[0] = '\0'; } @@ -330,7 +330,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) tv = NULL; /* To avoid warnings about beign uninitialized */ if (!noassign) { - tv = va_arg(ap, char*); + tv = va_arg(ap, FAR char *); tv[0] = '\0'; } @@ -389,12 +389,12 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) if (lflag) { - plong = va_arg(ap, long*); + plong = va_arg(ap, FAR long *); *plong = 0; } else { - pint = va_arg(ap, int*); + pint = va_arg(ap, FAR int *); *pint = 0; } } @@ -540,13 +540,13 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) #ifdef CONFIG_HAVE_DOUBLE if (lflag) { - pd = va_arg(ap, double_t*); + pd = va_arg(ap, FAR double_t *); *pd = 0.0; } else #endif { - pf = va_arg(ap, float*); + pf = va_arg(ap, FAR float *); *pf = 0.0; } } @@ -644,12 +644,12 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) if (lflag) { - FAR long *plong = va_arg(ap, long*); + FAR long *plong = va_arg(ap, FAR long *); *plong = (long)nchars; } else { - FAR int *pint = va_arg(ap, int*); + FAR int *pint = va_arg(ap, FAR int *); *pint = (int)nchars; } } diff --git a/libc/stdlib/lib_qsort.c b/libc/stdlib/lib_qsort.c index 32f10c0469..8c0e2825b1 100644 --- a/libc/stdlib/lib_qsort.c +++ b/libc/stdlib/lib_qsort.c @@ -115,8 +115,8 @@ static inline FAR char *med3(FAR char *a, FAR char *b, FAR char *c, FAR const void *)) { return compar(a, b) < 0 ? - (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a )) - :(compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c )); + (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a)) : + (compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c)); } /**************************************************************************** @@ -218,7 +218,7 @@ loop: pa = pb = (FAR char *)base + width; pc = pd = (FAR char *)base + (nel - 1) * width; - for (;;) + for (; ; ) { while (pb <= pc && (r = compar(pb, base)) <= 0) { diff --git a/libc/stdlib/lib_strtod.c b/libc/stdlib/lib_strtod.c index 5b462b3527..2f7ed81f55 100644 --- a/libc/stdlib/lib_strtod.c +++ b/libc/stdlib/lib_strtod.c @@ -168,7 +168,7 @@ double_t strtod(const char *str, char **endptr) /* Handle optional sign */ negative = 0; - switch(*++p) + switch (*++p) { case '-': negative = 1; /* Fall through to increment pos */ diff --git a/libc/string/lib_memccpy.c b/libc/string/lib_memccpy.c index 525eb872c5..bbb307afc6 100644 --- a/libc/string/lib_memccpy.c +++ b/libc/string/lib_memccpy.c @@ -68,8 +68,8 @@ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) { - FAR unsigned char *pout = (FAR unsigned char*)s1; - FAR unsigned char *pin = (FAR unsigned char*)s2; + FAR unsigned char *pout = (FAR unsigned char *)s1; + FAR unsigned char *pin = (FAR unsigned char *)s2; /* Copy at most n bytes */ diff --git a/libc/string/lib_memcpy.c b/libc/string/lib_memcpy.c index aff9c34347..6a4b2bbe34 100644 --- a/libc/string/lib_memcpy.c +++ b/libc/string/lib_memcpy.c @@ -56,8 +56,8 @@ #ifndef CONFIG_ARCH_MEMCPY FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) { - FAR unsigned char *pout = (FAR unsigned char*)dest; - FAR unsigned char *pin = (FAR unsigned char*)src; + FAR unsigned char *pout = (FAR unsigned char *)dest; + FAR unsigned char *pin = (FAR unsigned char *)src; while (n-- > 0) *pout++ = *pin++; return dest; } diff --git a/libc/string/lib_memmove.c b/libc/string/lib_memmove.c index d4b28b4f05..fb672f54eb 100644 --- a/libc/string/lib_memmove.c +++ b/libc/string/lib_memmove.c @@ -52,11 +52,14 @@ #ifndef CONFIG_ARCH_MEMMOVE FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) { - char *tmp, *s; + FAR char *tmp; + FAR char *s; + if (dest <= src) { - tmp = (char*) dest; - s = (char*) src; + tmp = (FAR char *) dest; + s = (FAR char *) src; + while (count--) { *tmp++ = *s++; @@ -64,8 +67,9 @@ FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) } else { - tmp = (char*) dest + count; - s = (char*) src + count; + tmp = (FAR char *) dest + count; + s = (FAR char *) src + count; + while (count--) { *--tmp = *--s; diff --git a/libc/string/lib_memset.c b/libc/string/lib_memset.c index 67f45ab6a9..fc2f83b30b 100644 --- a/libc/string/lib_memset.c +++ b/libc/string/lib_memset.c @@ -64,7 +64,7 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_MEMSET -void *memset(void *s, int c, size_t n) +FAR void *memset(FAR void *s, int c, size_t n) { #ifdef CONFIG_MEMSET_OPTSPEED /* This version is optimized for speed (you could do better @@ -87,7 +87,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 1) != 0) { - *(uint8_t*)addr = (uint8_t)c; + *(FAR uint8_t *)addr = (uint8_t)c; addr += 1; n -= 1; } @@ -102,7 +102,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 3) != 0) { - *(uint16_t*)addr = val16; + *(FAR uint16_t *)addr = val16; addr += 2; n -= 2; } @@ -112,7 +112,7 @@ void *memset(void *s, int c, size_t n) while (n >= 4) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -127,7 +127,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 7) != 0) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -136,7 +136,7 @@ void *memset(void *s, int c, size_t n) while (n >= 8) { - *(uint64_t*)addr = val64; + *(FAR uint64_t *)addr = val64; addr += 8; n -= 8; } @@ -151,7 +151,7 @@ void *memset(void *s, int c, size_t n) if (n >= 4) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -167,20 +167,20 @@ void *memset(void *s, int c, size_t n) if (n >= 2) { - *(uint16_t*)addr = val16; + *(FAR uint16_t *)addr = val16; addr += 2; n -= 2; } if (n >= 1) { - *(uint8_t*)addr = (uint8_t)c; + *(FAR uint8_t *)addr = (uint8_t)c; } } #else /* This version is optimized for size */ - unsigned char *p = (unsigned char*)s; + FAR unsigned char *p = (FAR unsigned char*)s; while (n-- > 0) *p++ = c; #endif return s; diff --git a/libc/string/lib_strcasecmp.c b/libc/string/lib_strcasecmp.c index 4aec2826a5..9017625b2a 100644 --- a/libc/string/lib_strcasecmp.c +++ b/libc/string/lib_strcasecmp.c @@ -47,10 +47,10 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP -int strcasecmp(const char *cs, const char *ct) +int strcasecmp(FAR const char *cs, FAR const char *ct) { int result; - for (;;) + for (; ; ) { if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) { diff --git a/libc/string/lib_strcasestr.c b/libc/string/lib_strcasestr.c index 85cb9a043a..0a56c73180 100644 --- a/libc/string/lib_strcasestr.c +++ b/libc/string/lib_strcasestr.c @@ -57,7 +57,7 @@ static FAR char *strcasechr(FAR const char *s, int uc) ch = *s; if (toupper(ch) == uc) { - return (FAR char*)s; + return (FAR char *)s; } } } @@ -71,9 +71,9 @@ static FAR char *strcasechr(FAR const char *s, int uc) FAR char *strcasestr(FAR const char *str, FAR const char *substr) { - const char *candidate; /* Candidate in str with matching start character */ - char ch; /* First character of the substring */ - int len; /* The length of the substring */ + FAR const char *candidate; /* Candidate in str with matching start character */ + char ch; /* First character of the substring */ + int len; /* The length of the substring */ /* Special case the empty substring */ @@ -86,7 +86,7 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) * the string */ - return (char*)str; + return (FAR char *)str; } /* Search for the substring */ @@ -94,7 +94,7 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) candidate = str; ch = toupper(ch); - for (;;) + for (; ; ) { /* strcasechr() will return a pointer to the next occurrence of the * character ch in the string (ignoring case) @@ -103,23 +103,23 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) candidate = strcasechr(candidate, ch); if (!candidate || strlen(candidate) < len) { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ + /* First character of the substring does not appear in the string + * or the remainder of the string is not long enough to contain the + * substring. + */ - return NULL; + return NULL; } /* Check if this is the beginning of a matching substring (ignoring case) */ if (strncasecmp(candidate, substr, len) == 0) { - /* Yes.. return the pointer to the first occurrence of the matching - * substring. - */ + /* Yes.. return the pointer to the first occurrence of the matching + * substring. + */ - return (char*)candidate; + return (FAR char *)candidate; } /* No, find the next candidate after this one */ diff --git a/libc/string/lib_strcmp.c b/libc/string/lib_strcmp.c index 364caa7f5f..9839c4ee99 100644 --- a/libc/string/lib_strcmp.c +++ b/libc/string/lib_strcmp.c @@ -46,10 +46,10 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP -int strcmp(const char *cs, const char *ct) +int strcmp(FAR const char *cs, FAR const char *ct) { register signed char result; - for (;;) + for (; ; ) { if ((result = *cs - *ct++) != 0 || !*cs++) break; diff --git a/libc/string/lib_strdup.c b/libc/string/lib_strdup.c index 5ba87ae27b..ab5c620a12 100644 --- a/libc/string/lib_strdup.c +++ b/libc/string/lib_strdup.c @@ -47,12 +47,12 @@ * Public Functions ****************************************************************************/ -FAR char *strdup(const char *s) +FAR char *strdup(FAR const char *s) { FAR char *news = NULL; if (s) { - news = (FAR char*)lib_malloc(strlen(s) + 1); + news = (FAR char *)lib_malloc(strlen(s) + 1); if (news) { strcpy(news, s); diff --git a/libc/string/lib_strndup.c b/libc/string/lib_strndup.c index 1b9d868067..984b363944 100644 --- a/libc/string/lib_strndup.c +++ b/libc/string/lib_strndup.c @@ -74,7 +74,7 @@ FAR char *strndup(FAR const char *s, size_t size) /* Allocate the new string, adding 1 for the NUL terminator */ - news = (FAR char*)lib_malloc(allocsize + 1); + news = (FAR char *)lib_malloc(allocsize + 1); if (news) { /* Copy the string into the allocated memory and add a NUL diff --git a/libc/string/lib_strpbrk.c b/libc/string/lib_strpbrk.c index 78d54ba407..4170926bb6 100644 --- a/libc/string/lib_strpbrk.c +++ b/libc/string/lib_strpbrk.c @@ -45,7 +45,7 @@ * Public Functions ****************************************************************************/ -char *strpbrk(const char *str, const char *charset) +FAR char *strpbrk(FAR const char *str, FAR const char *charset) { /* Sanity checking */ @@ -66,7 +66,7 @@ char *strpbrk(const char *str, const char *charset) { /* Yes, then this position must be the first occurrence in string */ - return (char*)str; + return (FAR char *)str; } /* This character from the strings matches none of those in the charset. diff --git a/libc/string/lib_strrchr.c b/libc/string/lib_strrchr.c index 601f655b43..3b08598bb2 100644 --- a/libc/string/lib_strrchr.c +++ b/libc/string/lib_strrchr.c @@ -49,7 +49,7 @@ * occurrence of the character c in the string s. */ -char *strrchr(const char *s, int c) +FAR char *strrchr(FAR const char *s, int c) { if (s) { @@ -58,7 +58,7 @@ char *strrchr(const char *s, int c) { if (*p == c) { - return (char*)p; + return (FAR char *)p; } } } diff --git a/libc/string/lib_strstr.c b/libc/string/lib_strstr.c index eb629b709a..06404402a9 100644 --- a/libc/string/lib_strstr.c +++ b/libc/string/lib_strstr.c @@ -62,13 +62,13 @@ FAR char *strstr(FAR const char *str, FAR const char *substr) * the string */ - return (char*)str; + return (FAR char *)str; } /* Search for the substring */ candidate = str; - for (;;) + for (; ; ) { /* strchr() will return a pointer to the next occurrence of the * character ch in the string @@ -77,19 +77,19 @@ FAR char *strstr(FAR const char *str, FAR const char *substr) candidate = strchr(candidate, ch); if (!candidate || strlen(candidate) < len) { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ + /* First character of the substring does not appear in the string + * or the remainder of the string is not long enough to contain the + * substring. + */ - return NULL; + return NULL; } /* Check if this is the beginning of a matching substring */ if (strncmp(candidate, substr, len) == 0) { - return (char*)candidate; + return (FAR char *)candidate; } /* No, find the next candidate after this one */ diff --git a/libc/string/lib_vikmemcpy.c b/libc/string/lib_vikmemcpy.c index 7dbcd331b2..41ab3ecf37 100644 --- a/libc/string/lib_vikmemcpy.c +++ b/libc/string/lib_vikmemcpy.c @@ -310,10 +310,10 @@ typedef uint32_t UIntN; * ****************************************************************************/ -void *memcpy(void *dest, const void *src, size_t count) +FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count) { - uint8_t *dst8 = (uint8_t*)dest; - uint8_t *src8 = (uint8_t*)src; + FAR uint8_t *dst8 = (FAR uint8_t *)dest; + FAR uint8_t *src8 = (FAR uint8_t *)src; if (count < 8) { diff --git a/libc/time/lib_dayofweek.c b/libc/time/lib_dayofweek.c index b630c838cb..55fb3c4370 100644 --- a/libc/time/lib_dayofweek.c +++ b/libc/time/lib_dayofweek.c @@ -104,6 +104,7 @@ int clock_dayoftheweek(int mday, int month, int year) } month -= 2; - return (mday + year + year/4 - year/100 + year/400 + ( 31 * month) / 12) % 7; + return (mday + year + year / 4 - year / 100 + year / 400 + + (31 * month) / 12) % 7; } #endif /* CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_gmtimer.c b/libc/time/lib_gmtimer.c index b42d7a7c90..d3f1740189 100644 --- a/libc/time/lib_gmtimer.c +++ b/libc/time/lib_gmtimer.c @@ -169,7 +169,8 @@ static void clock_utc2julian(time_t jd, int *year, int *month, int *day) /* Only handles dates since Jan 1, 1970 */ -static void clock_utc2calendar(time_t days, int *year, int *month, int *day) +static void clock_utc2calendar(time_t days, FAR int *year, FAR int *month, + FAR int *day) { int value; int min; @@ -181,13 +182,13 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) * following: */ - value = days / (4*365 + 1); /* Number of 4-years periods since the epoch*/ - days -= value * (4*365 + 1); /* Remaining days */ - value <<= 2; /* Years since the epoch */ + value = days / (4 * 365 + 1); /* Number of 4-years periods since the epoch */ + days -= value * (4 * 365 + 1); /* Remaining days */ + value <<= 2; /* Years since the epoch */ /* Then we will brute force the next 0-3 years */ - for (;;) + for (; ; ) { /* Is this year a leap year (we'll need this later too) */ @@ -231,7 +232,7 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) /* Get the number of days that occurred before the beginning of the month * following the midpoint. - */ + */ tmp = clock_daysbeforemonth(value + 1, leapyear); diff --git a/libc/time/lib_localtime.c b/libc/time/lib_localtime.c index 6e587f9486..c091d3d50d 100644 --- a/libc/time/lib_localtime.c +++ b/libc/time/lib_localtime.c @@ -437,10 +437,10 @@ static void settzname(void) FAR struct state_s *const sp = lclptr; int i; - tzname[0] = tzname[1] = (FAR char*)g_wildabbr; + tzname[0] = tzname[1] = (FAR char *)g_wildabbr; if (sp == NULL) { - tzname[0] = tzname[1] = (FAR char*)GMT; + tzname[0] = tzname[1] = (FAR char *)GMT; return; } @@ -528,6 +528,7 @@ static int tzload(FAR const char *name, struct state_s st; } u; }; + char *fullname; u_t *up; int doaccess; @@ -1158,7 +1159,7 @@ static FAR const char *getrule(FAR const char *strp, return strp; } -/*Given a year, a rule, and the offset from UT at the time that rule takes +/* Given a year, a rule, and the offset from UT at the time that rule takes * effect, calculate the year-relative time that rule takes effect. */ @@ -2122,7 +2123,7 @@ static time_t time2sub(struct tm *const tmp, } } - for (;;) + for (; ; ) { i = g_mon_lengths[isleap(y)][yourtm.tm_mon]; if (yourtm.tm_mday <= i) @@ -2198,7 +2199,7 @@ static time_t time2sub(struct tm *const tmp, hi = -(lo + 1); } - for (;;) + for (; ; ) { t = lo / 2 + hi / 2; if (t < lo) diff --git a/libc/unistd/lib_getopt.c b/libc/unistd/lib_getopt.c index 0c939fc420..1c0450100c 100644 --- a/libc/unistd/lib_getopt.c +++ b/libc/unistd/lib_getopt.c @@ -187,82 +187,82 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring) g_optptr++; } - /* Special case handling of "-" and "-:" */ - - if (!*g_optptr) - { - optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ - return '?'; - } - - /* Handle the case of "-:" */ - - if (*g_optptr == ':') - { - optopt = ':'; - g_optptr++; - return '?'; - } - - /* g_optptr now points at the next option and it is not something crazy. - * check if the option is in the list of valid options. - */ - - optchar = strchr(optstring, *g_optptr); - if (!optchar) - { - /* No this character is not in the list of valid options */ - - optopt = *g_optptr; - g_optptr++; - return '?'; - } - - /* Yes, the character is in the list of valid options. Does it have an - * required argument? - */ - - if (optchar[1] != ':') - { - /* No, no arguments. Just return the character that we found */ - - g_optptr++; - return *optchar; - } - - /* Yes, it has a required argument. Is the required argument - * immediately after the command in this same argument? - */ - - if (g_optptr[1] != '\0') - { - /* Yes, return a pointer into the current argument */ - - optarg = &g_optptr[1]; - optind++; - g_optptr = NULL; - return *optchar; - } + /* Special case handling of "-" and "-:" */ + + if (!*g_optptr) + { + optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ + return '?'; + } + + /* Handle the case of "-:" */ + + if (*g_optptr == ':') + { + optopt = ':'; + g_optptr++; + return '?'; + } + + /* g_optptr now points at the next option and it is not something crazy. + * check if the option is in the list of valid options. + */ + + optchar = strchr(optstring, *g_optptr); + if (!optchar) + { + /* No this character is not in the list of valid options */ - /* No.. is the optional argument the next argument in argv[] ? */ + optopt = *g_optptr; + g_optptr++; + return '?'; + } - if (argv[optind+1] && *argv[optind+1] != '-') - { - /* Yes.. return that */ + /* Yes, the character is in the list of valid options. Does it have an + * required argument? + */ - optarg = argv[optind+1]; - optind += 2; - g_optptr = NULL; - return *optchar; - } + if (optchar[1] != ':') + { + /* No, no arguments. Just return the character that we found */ + + g_optptr++; + return *optchar; + } + + /* Yes, it has a required argument. Is the required argument + * immediately after the command in this same argument? + */ + + if (g_optptr[1] != '\0') + { + /* Yes, return a pointer into the current argument */ + + optarg = &g_optptr[1]; + optind++; + g_optptr = NULL; + return *optchar; + } + + /* No.. is the optional argument the next argument in argv[] ? */ + + if (argv[optind+1] && *argv[optind+1] != '-') + { + /* Yes.. return that */ + + optarg = argv[optind+1]; + optind += 2; + g_optptr = NULL; + return *optchar; + } - /* No argument was supplied */ + /* No argument was supplied */ - g_optptr = NULL; - optarg = NULL; - optopt = *optchar; - optind++; - return noarg_ret; + g_optptr = NULL; + optarg = NULL; + optopt = *optchar; + optind++; + return noarg_ret; } /* Restore the initial, uninitialized state */ diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c index 09a06feeeb..7f554b3ebc 100644 --- a/libc/unistd/lib_usleep.c +++ b/libc/unistd/lib_usleep.c @@ -114,7 +114,7 @@ * * nanosleep(), setitimer(), timer_create(), timer_delete(), timer_getoverrun(), * timer_gettime(), timer_settime(), ualarm(), sleep() - + * * Parameters: * usec - the number of microseconds to wait. * diff --git a/libc/wqueue/work_cancel.c b/libc/wqueue/work_cancel.c index 393c84359c..50d5e5239d 100644 --- a/libc/wqueue/work_cancel.c +++ b/libc/wqueue/work_cancel.c @@ -112,7 +112,7 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work DEBUGASSERT(work->dq.flink != NULL || (FAR dq_entry_t *)work == wqueue->q.tail); - DEBUGASSERT(work->dq.blink != NULL ||i + DEBUGASSERT(work->dq.blink != NULL || (FAR dq_entry_t *)work == wqueue->q.head); /* Remove the entry from the work queue and make sure that it is diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index d359712d83..21bd65916e 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -304,7 +304,7 @@ static pthread_addr_t work_usrthread(pthread_addr_t arg) { /* Loop forever */ - for (;;) + for (; ; ) { /* Then process queued work. We need to keep the work queue locked * while we process items in the work list. -- GitLab From 613798027e1384d0022674d7fd6b61c576bbeee5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 12 Oct 2015 14:29:43 -0600 Subject: [PATCH 224/858] Add a button upper/lower half driver --- ChangeLog | 3 + arch | 2 +- drivers/input/Kconfig | 16 + drivers/input/Make.defs | 4 + drivers/input/ajoystick.c | 12 +- drivers/input/buttons.c | 882 ++++++++++++++++++++++++++++++++ include/nuttx/fs/ioctl.h | 9 +- include/nuttx/input/ajoystick.h | 2 +- include/nuttx/input/buttons.h | 185 +++++++ tools/nxstyle.c | 4 + 10 files changed, 1110 insertions(+), 9 deletions(-) create mode 100644 drivers/input/buttons.c create mode 100644 include/nuttx/input/buttons.h diff --git a/ChangeLog b/ChangeLog index 887081c9b4..374e99b091 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11021,3 +11021,6 @@ (2015-10-9). * fs/tmpfs: TMPFS file system is code complete and bascially functional although it has not been heavilay tested (2015-10-9). + * drivers/input/buttons/c and include/nuttx/input/buttons.h: Add a + driver to support application access to board buttons (2015-10-12). + diff --git a/arch b/arch index 8a9c89d35a..9f6b9305b1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8a9c89d35a4babc8f45687e5293e01e56126ed8c +Subproject commit 9f6b9305b14423c28abeb6261b8ba7095073f316 diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index cd2a096a81..480403a534 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -322,6 +322,22 @@ config STMPE811_REGDEBUG endif # INPUT_STMPE811 +config BUTTONS + bool "Button Inputs" + default n + depends on ARCH_BUTTONS + ---help--- + Enable standard button upper half driver. + +if BUTTONS + +config BUTTONS_NPOLLWAITERS + int "Max Number of Poll Waiters" + default 2 + depends on !DISABLE_POLL + +endif # BUTTONS + config DJOYSTICK bool "Discrete Joystick" default n diff --git a/drivers/input/Make.defs b/drivers/input/Make.defs index dc01bda886..899f6cdacb 100644 --- a/drivers/input/Make.defs +++ b/drivers/input/Make.defs @@ -71,6 +71,10 @@ ifneq ($(CONFIG_INPUT_STMPE811_TEMP_DISABLE),y) endif endif +ifeq ($(CONFIG_BUTTONS),y) + CSRCS += buttons.c +endif + ifeq ($(CONFIG_DJOYSTICK),y) CSRCS += djoystick.c endif diff --git a/drivers/input/ajoystick.c b/drivers/input/ajoystick.c index 0e00b907ed..ea1fc7848c 100644 --- a/drivers/input/ajoystick.c +++ b/drivers/input/ajoystick.c @@ -67,11 +67,11 @@ * Private Types ****************************************************************************/ -/* This structure provides the state of one discrete joystick driver */ +/* This structure provides the state of one analog joystick driver */ struct ajoy_upperhalf_s { - /* Saved binding to the lower half discrete joystick driver */ + /* Saved binding to the lower half analog joystick driver */ FAR const struct ajoy_lowerhalf_s *au_lower; @@ -823,15 +823,15 @@ errout_with_dusem: * Name: ajoy_register * * Description: - * Bind the lower half discrete joystick driver to an instance of the - * upper half discrete joystick driver and register the composite character + * Bind the lower half analog joystick driver to an instance of the + * upper half analog joystick driver and register the composite character * driver as the specific device. * * Input Parameters: - * devname - The name of the discrete joystick device to be registers. + * devname - The name of the analog joystick device to be registers. * This should be a string of the form "/priv/ajoyN" where N is the the * minor device number. - * lower - An instance of the platform-specific discrete joystick lower + * lower - An instance of the platform-specific analog joystick lower * half driver. * * Returned Values: diff --git a/drivers/input/buttons.c b/drivers/input/buttons.c new file mode 100644 index 0000000000..b9b49e24cf --- /dev/null +++ b/drivers/input/buttons.c @@ -0,0 +1,882 @@ +/**************************************************************************** + * drivers/buttons.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* This file provides a driver for a button input devices. + * + * The buttons driver exports a standard character driver interface. By + * convention, the button driver is registered as an input device at + * /dev/btnN where N uniquely identifies the driver instance. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure provides the state of one button driver */ + +struct btn_upperhalf_s +{ + /* Saved binding to the lower half button driver */ + + FAR const struct btn_lowerhalf_s *bu_lower; + + btn_buttonset_t bu_enabled; /* Set of currently enabled button interrupts */ + btn_buttonset_t bu_sample; /* Last sampled button states */ + sem_t bu_exclsem; /* Supports exclusive access to the device */ + + /* The following is a singly linked list of open references to the + * button device. + */ + + FAR struct btn_open_s *bu_open; +}; + +/* This structure describes the state of one open button driver instance */ + +struct btn_open_s +{ + /* Supports a singly linked list */ + + FAR struct btn_open_s *bo_flink; + + /* The following will be true if we are closing */ + + volatile bool bo_closing; + +#ifndef CONFIG_DISABLE_SIGNALS + /* Button event notification information */ + + pid_t bo_pid; + struct btn_notify_s bo_notify; +#endif + +#ifndef CONFIG_DISABLE_POLL + /* Poll event information */ + + struct btn_pollevents_s bo_pollevents; + + /* The following is a list if poll structures of threads waiting for + * driver events. + */ + + FAR struct pollfd *bo_fds[CONFIG_BUTTONS_NPOLLWAITERS]; +#endif +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Semaphore helpers */ + +static inline int btn_takesem(sem_t *sem); +#define btn_givesem(s) sem_post(s); + +/* Sampling and Interrupt handling */ + +#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) +static void btn_enable(FAR struct btn_upperhalf_s *priv); +static void btn_interrupt(FAR const struct btn_lowerhalf_s *lower, + FAR void *arg); +#endif + +/* Sampling */ + +static void btn_sample(FAR struct btn_upperhalf_s *priv); + +/* Character driver methods */ + +static int btn_open(FAR struct file *filep); +static int btn_close(FAR struct file *filep); +static ssize_t btn_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static int btn_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); +#ifndef CONFIG_DISABLE_POLL +static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds, + bool setup); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations btn_fops = +{ + btn_open, /* open */ + btn_close, /* close */ + btn_read, /* read */ + 0, /* write */ + 0, /* seek */ + btn_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , btn_poll /* poll */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_takesem + ****************************************************************************/ + +static inline int btn_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + +/**************************************************************************** + * Name: btn_enable + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) +static void btn_enable(FAR struct btn_upperhalf_s *priv) +{ + FAR const struct btn_lowerhalf_s *lower = priv->bu_lower; + FAR struct btn_open_s *opriv; + btn_buttonset_t press; + btn_buttonset_t release; + irqstate_t flags; +#ifndef CONFIG_DISABLE_POLL + int i; +#endif + + DEBUGASSERT(priv && priv->bu_lower); + lower = priv->bu_lower; + + /* This routine is called both task level and interrupt level, so + * interrupts must be disabled. + */ + + flags = irqsave(); + + /* Visit each opened reference to the device */ + + press = 0; + release = 0; + + for (opriv = priv->bu_open; opriv; opriv = opriv->bo_flink) + { +#ifndef CONFIG_DISABLE_POLL + /* Are there any poll waiters? */ + + for (i = 0; i < CONFIG_BUTTONS_NPOLLWAITERS; i++) + { + if (opriv->bo_fds[i]) + { + /* Yes.. OR in the poll event buttons */ + + press |= opriv->bo_pollevents.ap_press; + release |= opriv->bo_pollevents.ap_release; + break; + } + } +#endif + +#ifndef CONFIG_DISABLE_SIGNALS + /* OR in the signal events */ + + press |= opriv->bo_notify.bn_press; + release |= opriv->bo_notify.bn_release; +#endif + } + + /* Enable/disable button interrupts */ + + DEBUGASSERT(lower->bl_enable); + if (press != 0 || release != 0) + { + /* Enable interrupts with the new button set */ + + lower->bl_enable(lower, press, release, + (btn_handler_t)btn_interrupt, priv); + } + else + { + /* Disable further interrupts */ + + lower->bl_enable(lower, 0, 0, NULL, NULL); + } + + irqrestore(flags); +} +#endif + +/**************************************************************************** + * Name: btn_interrupt + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) +static void btn_interrupt(FAR const struct btn_lowerhalf_s *lower, + FAR void *arg) +{ + FAR struct btn_upperhalf_s *priv = (FAR struct btn_upperhalf_s *)arg; + + DEBUGASSERT(priv); + + /* Process the next sample */ + + btn_sample(priv); +} +#endif + +/**************************************************************************** + * Name: btn_sample + ****************************************************************************/ + +static void btn_sample(FAR struct btn_upperhalf_s *priv) +{ + FAR const struct btn_lowerhalf_s *lower = priv->bu_lower; + FAR struct btn_open_s *opriv; + btn_buttonset_t sample; +#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) + btn_buttonset_t change; + btn_buttonset_t press; + btn_buttonset_t release; +#endif + irqstate_t flags; +#ifndef CONFIG_DISABLE_POLL + int i; +#endif + + DEBUGASSERT(priv && priv->bu_lower); + lower = priv->bu_lower; + + /* This routine is called both task level and interrupt level, so + * interrupts must be disabled. + */ + + flags = irqsave(); + + /* Sample the new button state */ + + DEBUGASSERT(lower->bl_buttons); + sample = lower->bl_buttons(lower); + +#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) + /* Determine which buttons have been newly pressed and which have been + * newly released. + */ + + change = sample ^ priv->bu_sample; + press = change & sample; + + DEBUGASSERT(lower->bl_supported); + release = change & (lower->bl_supported(lower) & ~sample); + + /* Visit each opened reference to the device */ + + for (opriv = priv->bu_open; opriv; opriv = opriv->bo_flink) + { +#ifndef CONFIG_DISABLE_POLL + /* Have any poll events occurred? */ + + if ((press & opriv->bo_pollevents.ap_press) != 0 || + (release & opriv->bo_pollevents.ap_release) != 0) + { + /* Yes.. Notify all waiters */ + + for (i = 0; i < CONFIG_BUTTONS_NPOLLWAITERS; i++) + { + FAR struct pollfd *fds = opriv->bo_fds[i]; + if (fds) + { + fds->revents |= (fds->events & POLLIN); + if (fds->revents != 0) + { + ivdbg("Report events: %02x\n", fds->revents); + sem_post(fds->sem); + } + } + } + } +#endif + +#ifndef CONFIG_DISABLE_SIGNALS + /* Have any signal events occurred? */ + + if ((press & opriv->bo_notify.bn_press) != 0 || + (release & opriv->bo_notify.bn_release) != 0) + { + /* Yes.. Signal the waiter */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + union sigval value; + value.sival_int = (int)sample; + (void)sigqueue(opriv->bo_pid, opriv->bo_notify.bn_signo, value); +#else + (void)sigqueue(opriv->bo_pid, opriv->bo_notify.dn.signo, + (FAR void *)sample); +#endif + } +#endif + } + + /* Enable/disable interrupt handling */ + + btn_enable(priv); +#endif + + priv->bu_sample = sample; + irqrestore(flags); +} + +/**************************************************************************** + * Name: btn_open + ****************************************************************************/ + +static int btn_open(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct btn_upperhalf_s *priv; + FAR struct btn_open_s *opriv; +#ifndef CONFIG_DISABLE_POLL + FAR const struct btn_lowerhalf_s *lower; + btn_buttonset_t supported; +#endif + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct btn_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = btn_takesem(&priv->bu_exclsem); + if (ret < 0) + { + ivdbg("ERROR: btn_takesem failed: %d\n", ret); + return ret; + } + + /* Allocate a new open structure */ + + opriv = (FAR struct btn_open_s *)kmm_zalloc(sizeof(struct btn_open_s)); + if (!opriv) + { + ivdbg("ERROR: Failled to allocate open structure\n"); + ret = -ENOMEM; + goto errout_with_sem; + } + + /* Initialize the open structure */ + +#ifndef CONFIG_DISABLE_POLL + lower = priv->bu_lower; + DEBUGASSERT(lower && lower->bl_supported); + supported = lower->bl_supported(lower); + + opriv->bo_pollevents.ap_press = supported; + opriv->bo_pollevents.ap_release = supported; +#endif + + /* Attach the open structure to the device */ + + opriv->bo_flink = priv->bu_open; + priv->bu_open = opriv; + + /* Attach the open structure to the file structure */ + + filep->f_priv = (FAR void *)opriv; + ret = OK; + +errout_with_sem: + btn_givesem(&priv->bu_exclsem); + return ret; +} + +/**************************************************************************** + * Name: btn_close + ****************************************************************************/ + +static int btn_close(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct btn_upperhalf_s *priv; + FAR struct btn_open_s *opriv; + FAR struct btn_open_s *curr; + FAR struct btn_open_s *prev; + irqstate_t flags; + bool closing; + int ret; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct btn_upperhalf_s *)inode->i_private; + + /* Handle an improbable race conditions with the following atomic test + * and set. + * + * This is actually a pretty feeble attempt to handle this. The + * improbable race condition occurs if two different threads try to + * close the button driver at the same time. The rule: don't do + * that! It is feeble because we do not really enforce stale pointer + * detection anyway. + */ + + flags = irqsave(); + closing = opriv->bo_closing; + opriv->bo_closing = true; + irqrestore(flags); + + if (closing) + { + /* Another thread is doing the close */ + + return OK; + } + + /* Get exclusive access to the driver structure */ + + ret = btn_takesem(&priv->bu_exclsem); + if (ret < 0) + { + ivdbg("ERROR: btn_takesem failed: %d\n", ret); + return ret; + } + + /* Find the open structure in the list of open structures for the device */ + + for (prev = NULL, curr = priv->bu_open; + curr && curr != opriv; + prev = curr, curr = curr->bo_flink); + + DEBUGASSERT(curr); + if (!curr) + { + ivdbg("ERROR: Failed to find open entry\n"); + ret = -ENOENT; + goto errout_with_exclsem; + } + + /* Remove the structure from the device */ + + if (prev) + { + prev->bo_flink = opriv->bo_flink; + } + else + { + priv->bu_open = opriv->bo_flink; + } + + /* And free the open structure */ + + kmm_free(opriv); + + /* Enable/disable interrupt handling */ + + btn_enable(priv); + ret = OK; + +errout_with_exclsem: + btn_givesem(&priv->bu_exclsem); + return ret; +} + +/**************************************************************************** + * Name: btn_read + ****************************************************************************/ + +static ssize_t btn_read(FAR struct file *filep, FAR char *buffer, + size_t len) +{ + FAR struct inode *inode; + FAR struct btn_upperhalf_s *priv; + FAR const struct btn_lowerhalf_s *lower; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct btn_upperhalf_s *)inode->i_private; + + /* Make sure that the buffer is sufficiently large to hold at least one + * complete sample. + * + * REVISIT: Should also check buffer alignment. + */ + + if (len < sizeof(btn_buttonset_t)) + { + ivdbg("ERROR: buffer too small: %lu\n", (unsigned long)len); + return -EINVAL; + } + + /* Get exclusive access to the driver structure */ + + ret = btn_takesem(&priv->bu_exclsem); + if (ret < 0) + { + ivdbg("ERROR: btn_takesem failed: %d\n", ret); + return ret; + } + + /* Read and return the current state of the buttons */ + + lower = priv->bu_lower; + DEBUGASSERT(lower && lower->bl_buttons); + *(FAR btn_buttonset_t *)buffer = lower->bl_buttons(lower); + + btn_givesem(&priv->bu_exclsem); + return (ssize_t)sizeof(btn_buttonset_t); +} + +/**************************************************************************** + * Name: btn_ioctl + ****************************************************************************/ + +static int btn_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct btn_upperhalf_s *priv; + FAR struct btn_open_s *opriv; + FAR const struct btn_lowerhalf_s *lower; + int ret; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct btn_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = btn_takesem(&priv->bu_exclsem); + if (ret < 0) + { + ivdbg("ERROR: btn_takesem failed: %d\n", ret); + return ret; + } + + /* Handle the ioctl command */ + + ret = -EINVAL; + switch (cmd) + { + /* Command: BTNIOC_SUPPORTED + * Description: Report the set of button events supported by the hardware; + * Argument: A pointer to writeable integer value in which to return the + * set of supported buttons. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + + case BTNIOC_SUPPORTED: + { + FAR btn_buttonset_t *supported = (FAR btn_buttonset_t *)((uintptr_t)arg); + + if (supported) + { + lower = priv->bu_lower; + DEBUGASSERT(lower && lower->bl_supported); + + *supported = lower->bl_supported(lower); + ret = OK; + } + } + break; + +#ifndef CONFIG_DISABLE_POLL + /* Command: BTNIOC_POLLEVENTS + * Description: Specify the set of button events that can cause a poll() + * to awaken. The default is all button depressions and + * all button releases (all supported buttons); + * Argument: A read-only pointer to an instance of struct + * btn_pollevents_s + * Return: Zero (OK) on success. Minus one will be returned on + * failure with the errno value set appropriately. + */ + + case BTNIOC_POLLEVENTS: + { + FAR struct btn_pollevents_s *pollevents = + (FAR struct btn_pollevents_s *)((uintptr_t)arg); + + if (pollevents) + { + /* Save the poll events */ + + opriv->bo_pollevents.ap_press = pollevents->ap_press; + opriv->bo_pollevents.ap_release = pollevents->ap_release; + + /* Enable/disable interrupt handling */ + + btn_enable(priv); + ret = OK; + } + } + break; +#endif + +#ifndef CONFIG_DISABLE_SIGNALS + /* Command: BTNIOC_REGISTER + * Description: Register to receive a signal whenever there is a change + * in any of the discrete buttone inputs. This feature, + * of course, depends upon interrupt GPIO support from the + * platform. + * Argument: A read-only pointer to an instance of struct + * btn_notify_s + * Return: Zero (OK) on success. Minus one will be returned on + * failure with the errno value set appropriately. + */ + + case BTNIOC_REGISTER: + { + FAR struct btn_notify_s *notify = + (FAR struct btn_notify_s *)((uintptr_t)arg); + + if (notify) + { + /* Save the notification events */ + + opriv->bo_notify.bn_press = notify->bn_press; + opriv->bo_notify.bn_release = notify->bn_release; + opriv->bo_notify.bn_signo = notify->bn_signo; + opriv->bo_pid = getpid(); + + /* Enable/disable interrupt handling */ + + btn_enable(priv); + ret = OK; + } + } + break; +#endif + + default: + ivdbg("ERROR: Unrecognized command: %ld\n", cmd); + ret = -ENOTTY; + break; + } + + btn_givesem(&priv->bu_exclsem); + return ret; +} + +/**************************************************************************** + * Name: btn_poll + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_POLL +static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds, + bool setup) +{ + FAR struct inode *inode; + FAR struct btn_upperhalf_s *priv; + FAR struct btn_open_s *opriv; + int ret; + int i; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct btn_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = btn_takesem(&priv->bu_exclsem); + if (ret < 0) + { + ivdbg("ERROR: btn_takesem failed: %d\n", ret); + return ret; + } + + /* Are we setting up the poll? Or tearing it down? */ + + if (setup) + { + /* This is a request to set up the poll. Find an available + * slot for the poll structure reference + */ + + for (i = 0; i < CONFIG_BUTTONS_NPOLLWAITERS; i++) + { + /* Find an available slot */ + + if (!opriv->bo_fds[i]) + { + /* Bind the poll structure and this slot */ + + opriv->bo_fds[i] = fds; + fds->priv = &opriv->bo_fds[i]; + break; + } + } + + if (i >= CONFIG_BUTTONS_NPOLLWAITERS) + { + ivdbg("ERROR: Too man poll waiters\n"); + fds->priv = NULL; + ret = -EBUSY; + goto errout_with_dusem; + } + } + else if (fds->priv) + { + /* This is a request to tear down the poll. */ + + FAR struct pollfd **slot = (FAR struct pollfd **)fds->priv; + +#ifdef CONFIG_DEBUG + if (!slot) + { + ivdbg("ERROR: Poll slot not found\n"); + ret = -EIO; + goto errout_with_dusem; + } +#endif + + /* Remove all memory of the poll setup */ + + *slot = NULL; + fds->priv = NULL; + } + +errout_with_dusem: + btn_givesem(&priv->bu_exclsem); + return ret; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_register + * + * Description: + * Bind the lower half button driver to an instance of the upper half + * button driver and register the composite character driver as the + * specified device. + * + * Input Parameters: + * devname - The name of the button device to be registered. + * This should be a string of the form "/dev/btnN" where N is the the + * minor device number. + * lower - An instance of the platform-specific button lower half driver. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int btn_register(FAR const char *devname, + FAR const struct btn_lowerhalf_s *lower) + +{ + FAR struct btn_upperhalf_s *priv; + int ret; + + DEBUGASSERT(devname && lower); + + /* Allocate a new button driver instance */ + + priv = (FAR struct btn_upperhalf_s *) + kmm_zalloc(sizeof(struct btn_upperhalf_s)); + + if (!priv) + { + ivdbg("ERROR: Failed to allocate device structure\n"); + return -ENOMEM; + } + + /* Make sure that all button interrupts are disabled */ + + DEBUGASSERT(lower->bl_enable); + lower->bl_enable(lower, 0, 0, NULL, NULL); + + /* Initialize the new button driver instance */ + + priv->bu_lower = lower; + sem_init(&priv->bu_exclsem, 0, 1); + + DEBUGASSERT(lower->bl_buttons); + priv->bu_sample = lower->bl_buttons(lower); + + /* And register the button driver */ + + ret = register_driver(devname, &btn_fops, 0666, priv); + if (ret < 0) + { + ivdbg("ERROR: register_driver failed: %d\n", ret); + goto errout_with_priv; + } + + return OK; + +errout_with_priv: + sem_destroy(&priv->bu_exclsem); + kmm_free(priv); + return ret; +} diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 827f62e4c5..7a5d17f702 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -77,7 +77,8 @@ #define _RTCBASE (0x1800) /* RTC ioctl commands */ #define _RELAYBASE (0x1900) /* Relay devices ioctl commands */ #define _CANBASE (0x1a00) /* CAN ioctl commands */ -#define _BOARDBASE (0x1b00) /* boardctl ioctl commands */ +#define _BTNBASE (0x1b00) /* Button ioctl commands */ +#define _BOARDBASE (0x1c00) /* boardctl ioctl commands */ /* Macros used to manage ioctl commands */ @@ -336,6 +337,12 @@ #define _CANIOCVALID(c) (_IOC_TYPE(c)==_CANBASE) #define _CANIOC(nr) _IOC(_CANBASE,nr) +/* Button driver ioctl definitions ******************************************/ +/* (see nuttx/can.h */ + +#define _BTNIOCVALID(c) (_IOC_TYPE(c)==_BTNBASE) +#define _BTNIOC(nr) _IOC(_BTNBASE,nr) + /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/input/ajoystick.h b/include/nuttx/input/ajoystick.h index b2f49c527d..b672ed57ed 100644 --- a/include/nuttx/input/ajoystick.h +++ b/include/nuttx/input/ajoystick.h @@ -275,7 +275,7 @@ extern "C" * driver as the specified device. * * Input Parameters: - * devname - The name of the analog joystick device to be registers. + * devname - The name of the analog joystick device to be registered. * This should be a string of the form "/dev/ajoyN" where N is the the * minor device number. * lower - An instance of the platform-specific analog joystick lower diff --git a/include/nuttx/input/buttons.h b/include/nuttx/input/buttons.h new file mode 100644 index 0000000000..f31a197a1e --- /dev/null +++ b/include/nuttx/input/buttons.h @@ -0,0 +1,185 @@ +/************************************************************************************ + * include/nuttx/input/buttons.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __INCLUDE_NUTTX_INPUT_BUTTONS_H +#define __INCLUDE_NUTTX_INPUT_BUTTONS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_BUTTONS_NPOLLWAITERS +# define CONFIG_BUTTONS_NPOLLWAITERS 2 +#endif + +/* ioctl commands */ + +/* Command: BTNIOC_SUPPORTED + * Description: Report the set of button events supported by the hardware; + * Argument: A pointer to writeable btn_buttonset_t value in which to + * return the set of supported buttons. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define BTNIOC_SUPPORTED _BTNIOC(0x0001) + +/* Command: BTNIOC_REGISTER + * Description: Register to receive a signal whenever there is a change in + * the state of button inputs. This feature, of course, depends + * upon interrupt GPIO support from the platform. + * Argument: A read-only pointer to an instance of struct btn_notify_s + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define BTNIOC_REGISTER _BTNIOC(0x0002) + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* This type is a bit set that contains the state of all buttons as defined + * in arch/board/board.h. This is the value that is returned when reading + * from the button driver. + */ + +typedef uint8_t btn_buttonset_t; + +/* A reference to this structure is provided with the BTNIOC_REGISTER IOCTL + * command and describes the conditions under which the client would like + * to receive notification. + */ + +struct btn_notify_s +{ + btn_buttonset_t bn_press; /* Set of button depressions to be notified */ + btn_buttonset_t bn_release; /* Set of button releases to be notified */ + uint8_t bn_signo; /* Signal number to use in the notification */ +}; + +/* This is the type of the button interrupt handler used with the struct + * btn_lowerhalf_s enable() method. + */ + +struct btn_lowerhalf_s; +typedef CODE void (*btn_handler_t) + (FAR const struct btn_lowerhalf_s *lower, FAR void *arg); + +/* The button driver is a two-part driver: + * + * 1) A common upper half driver that provides the common user interface to + * the buttons, + * 2) Platform-specific lower half drivers that provide the interface + * between the common upper half and the platform discrete button inputs. + * + * This structure defines the interface between an instance of the lower + * half driver and the common upper half driver. Such an instance is + * passed to the upper half driver when the driver is initialized, binding + * the upper and lower halves into one driver. + */ + +struct btn_lowerhalf_s +{ + /* Return the set of buttons supported by the board */ + + CODE btn_buttonset_t (*bl_supported)(FAR const struct btn_lowerhalf_s *lower); + + /* Return the current state of button data (only) */ + + CODE btn_buttonset_t (*bl_buttons)(FAR const struct btn_lowerhalf_s *lower); + + /* Enable interrupts on the selected set of buttons. An empty set will + * disable all interrupts. + */ + + CODE void (*bl_enable)(FAR const struct btn_lowerhalf_s *lower, + btn_buttonset_t press, btn_buttonset_t release, + btn_handler_t handler, FAR void *arg); +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_register + * + * Description: + * Bind the lower half button driver to an instance of the upper half + * button driver and register the composite character driver as the + * specified device. + * + * Input Parameters: + * devname - The name of the button device to be registered. + * This should be a string of the form "/dev/btnN" where N is the the + * minor device number. + * lower - An instance of the platform-specific button lower half driver. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int btn_register(FAR const char *devname, + FAR const struct btn_lowerhalf_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_INPUT_BUTTONS_H */ + diff --git a/tools/nxstyle.c b/tools/nxstyle.c index 1eada32187..4fa84eb523 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -688,6 +688,8 @@ int main(int argc, char **argv, char **envp) else if (line[n+1] == ')') { + /* REVISIT: This gives false alarms on syntax like *--ptr */ + if (line[n-1] != ' ') { fprintf(stderr, @@ -748,6 +750,8 @@ int main(int argc, char **argv, char **envp) n++; } + /* REVISIT: This gives false alarms on syntax like *--ptr */ + if (line[curr] != '-' && line[next] != ' ' && line[next] != '\n') { fprintf(stderr, -- GitLab From 75fcf4e8a12882c153138619b8bc23c82872f550 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 12 Oct 2015 14:53:47 -0600 Subject: [PATCH 225/858] Trivial fixes to spacing --- drivers/input/buttons.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/input/buttons.c b/drivers/input/buttons.c index b9b49e24cf..e185e83c58 100644 --- a/drivers/input/buttons.c +++ b/drivers/input/buttons.c @@ -73,7 +73,7 @@ struct btn_upperhalf_s btn_buttonset_t bu_enabled; /* Set of currently enabled button interrupts */ btn_buttonset_t bu_sample; /* Last sampled button states */ - sem_t bu_exclsem; /* Supports exclusive access to the device */ + sem_t bu_exclsem; /* Supports exclusive access to the device */ /* The following is a singly linked list of open references to the * button device. @@ -128,7 +128,7 @@ static inline int btn_takesem(sem_t *sem); #if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) static void btn_enable(FAR struct btn_upperhalf_s *priv); static void btn_interrupt(FAR const struct btn_lowerhalf_s *lower, - FAR void *arg); + FAR void *arg); #endif /* Sampling */ @@ -140,12 +140,12 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv); static int btn_open(FAR struct file *filep); static int btn_close(FAR struct file *filep); static ssize_t btn_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); + size_t buflen); static int btn_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); + unsigned long arg); #ifndef CONFIG_DISABLE_POLL static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup); + bool setup); #endif /**************************************************************************** @@ -272,7 +272,7 @@ static void btn_enable(FAR struct btn_upperhalf_s *priv) #if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS) static void btn_interrupt(FAR const struct btn_lowerhalf_s *lower, - FAR void *arg) + FAR void *arg) { FAR struct btn_upperhalf_s *priv = (FAR struct btn_upperhalf_s *)arg; @@ -546,7 +546,7 @@ errout_with_exclsem: ****************************************************************************/ static ssize_t btn_read(FAR struct file *filep, FAR char *buffer, - size_t len) + size_t len) { FAR struct inode *inode; FAR struct btn_upperhalf_s *priv; @@ -727,7 +727,7 @@ static int btn_ioctl(FAR struct file *filep, int cmd, unsigned long arg) #ifndef CONFIG_DISABLE_POLL static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup) + bool setup) { FAR struct inode *inode; FAR struct btn_upperhalf_s *priv; @@ -832,7 +832,7 @@ errout_with_dusem: ****************************************************************************/ int btn_register(FAR const char *devname, - FAR const struct btn_lowerhalf_s *lower) + FAR const struct btn_lowerhalf_s *lower) { FAR struct btn_upperhalf_s *priv; -- GitLab From f0b40ba96a9d62cdcb57e3f8fdda76d85f284efb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 13 Oct 2015 07:08:11 -0600 Subject: [PATCH 226/858] Add a a generic lower half button driver --- ChangeLog | 7 +- drivers/input/Kconfig | 27 ++- drivers/input/Make.defs | 8 +- drivers/input/button_lower.c | 235 ++++++++++++++++++++ drivers/input/{buttons.c => button_upper.c} | 2 +- 5 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 drivers/input/button_lower.c rename drivers/input/{buttons.c => button_upper.c} (99%) diff --git a/ChangeLog b/ChangeLog index 374e99b091..fb499c6313 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11021,6 +11021,9 @@ (2015-10-9). * fs/tmpfs: TMPFS file system is code complete and bascially functional although it has not been heavilay tested (2015-10-9). - * drivers/input/buttons/c and include/nuttx/input/buttons.h: Add a + * drivers/input/button_upper.c and include/nuttx/input/buttons.h: Add a driver to support application access to board buttons (2015-10-12). - + * drivers/input/button_lower.c: Add a generic lower half button driver. + This lower half driver is only usable in a limited number of + situations, but can still serve as a module for the lower half button + driver. (2015-10-13). diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 480403a534..88d1e07ad3 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -325,12 +325,37 @@ endif # INPUT_STMPE811 config BUTTONS bool "Button Inputs" default n - depends on ARCH_BUTTONS ---help--- Enable standard button upper half driver. if BUTTONS +config BUTTONS_LOWER + bool "Generic Lower Half Button Dirver" + default n + depends on ARCH_BUTTONS && ARCH_IRQBUTTONS + ---help--- + If the board supports the standard button interfaces as + defined in include/nuttx/board.h header file, then this + standard button lower half driver might be usable. + + In order for this generic driver to be usable: + + 1. The board implementation must provide the button + interfaces as defined in include/nuttx/board.h + 2. The board implementation must support interrupts for each + button. + 3. The board.h header file must provide the definition + NUM_BUTTONS, and + 4. The board.h header file must not include any other + header files that are not accessibble in this context + (such as those in arch//src/). + + If your board does not meet these requirements, then the + board_lower.c file can still be copied to your your + board src/ directory and modified for your specific board + requirements. + config BUTTONS_NPOLLWAITERS int "Max Number of Poll Waiters" default 2 diff --git a/drivers/input/Make.defs b/drivers/input/Make.defs index 899f6cdacb..8285bfda0f 100644 --- a/drivers/input/Make.defs +++ b/drivers/input/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # drivers/input/Make.defs # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -72,7 +72,11 @@ endif endif ifeq ($(CONFIG_BUTTONS),y) - CSRCS += buttons.c + CSRCS += button_upper.c +ifeq ($(CONFIG_BUTTONS_LOWER),y) + CSRCS += button_lower.c +endif + endif ifeq ($(CONFIG_DJOYSTICK),y) diff --git a/drivers/input/button_lower.c b/drivers/input/button_lower.c new file mode 100644 index 0000000000..dba0b94bfa --- /dev/null +++ b/drivers/input/button_lower.c @@ -0,0 +1,235 @@ +/**************************************************************************** + * drivers/input/button_lower.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#if CONFIG_BUTTONS_LOWER + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static btn_buttonset_t btn_supported(FAR const struct btn_lowerhalf_s *lower); +static btn_buttonset_t btn_buttons(FAR const struct btn_lowerhalf_s *lower); +static void btn_enable(FAR const struct btn_lowerhalf_s *lower, + btn_buttonset_t press, btn_buttonset_t release, + btn_handler_t handler, FAR void *arg); + +static void btn_disable(void); +static int btn_interrupt(int irq, FAR void *context); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This is the button button lower half driver interface */ + +static const struct btn_lowerhalf_s g_btnlower = +{ + .bl_supported = btn_supported, + .bl_buttons = btn_buttons, + .bl_enable = btn_enable, +}; + +/* Current interrupt handler and argument */ + +static btn_handler_t g_btnhandler; +static FAR void *g_btnarg; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_supported + * + * Description: + * Return the set of buttons supported + * + ****************************************************************************/ + +static btn_buttonset_t btn_supported(FAR const struct btn_lowerhalf_s *lower) +{ + ivdbg("NUM_BUTTONS: %02x\n", NUM_BUTTONS); + return (btn_buttonset_t)((1 << NUM_BUTTONS) - 1); +} + +/**************************************************************************** + * Name: btn_buttons + * + * Description: + * Return the current state of button data + * + ****************************************************************************/ + +static btn_buttonset_t btn_buttons(FAR const struct btn_lowerhalf_s *lower) +{ + return board_buttons(); +} + +/**************************************************************************** + * Name: btn_enable + * + * Description: + * Enable interrupts on the selected set of buttons. And empty set or + * a NULL handler will disable all interrupts. + * + ****************************************************************************/ + +static void btn_enable(FAR const struct btn_lowerhalf_s *lower, + btn_buttonset_t press, btn_buttonset_t release, + btn_handler_t handler, FAR void *arg) +{ + btn_buttonset_t mask; + btn_buttonset_t either = press | release; + irqstate_t flags; + int id; + + /* Start with all interrupts disabled */ + + flags = irqsave(); + btn_disable(); + + illvdbg("press: %02x release: %02x handler: %p arg: %p\n", + press, release, handler, arg); + + /* If no events are indicated or if no handler is provided, then this + * must really be a request to disable interrupts. + */ + + if (either && handler) + { + /* Save the new the handler and argument */ + + g_btnhandler = handler; + g_btnarg = arg; + + /* Attach and enable each button interrupt */ + + for (id = 0; id < NUM_BUTTONS; id++) + { + mask = (1 << id); + if ((either & mask) != 0) + { + (void)board_button_irq(id, btn_interrupt); + } + } + } + + irqrestore(flags); +} + +/**************************************************************************** + * Name: btn_disable + * + * Description: + * Disable all button interrupts + * + ****************************************************************************/ + +static void btn_disable(void) +{ + irqstate_t flags; + int id; + + /* Disable each button interrupt */ + + flags = irqsave(); + for (id = 0; id < NUM_BUTTONS; id++) + { + (void)board_button_irq(id, NULL); + } + + /* Nullify the handler and argument */ + + g_btnhandler = NULL; + g_btnarg = NULL; + irqrestore(flags); +} + +/**************************************************************************** + * Name: btn_interrupt + * + * Description: + * Discrete button interrupt handler (all buttons) + * + ****************************************************************************/ + +static int btn_interrupt(int irq, FAR void *context) +{ + DEBUGASSERT(g_btnhandler); + + if (g_btnhandler) + { + g_btnhandler(&g_btnlower, g_btnarg); + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: btn_lower_initialize + * + * Description: + * Initialize the generic button lower half driver, bind it and register + * it with the upper half button driver as devname. + * + ****************************************************************************/ + +int btn_lower_initialize(FAR const char *devname) +{ + board_button_initialize(); + return btn_register(devname, &g_btnlower); +} + +#endif /* CONFIG_BUTTONS_LOWER */ diff --git a/drivers/input/buttons.c b/drivers/input/button_upper.c similarity index 99% rename from drivers/input/buttons.c rename to drivers/input/button_upper.c index e185e83c58..deb9492fba 100644 --- a/drivers/input/buttons.c +++ b/drivers/input/button_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/buttons.c + * drivers/button_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt -- GitLab From 8f0c912fff4b944e54d03e04dcc64166b98d91b9 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Tue, 13 Oct 2015 07:27:16 -0600 Subject: [PATCH 227/858] Add Zero Cross device driver support --- ChangeLog | 3 + drivers/sensors/Kconfig | 4 + drivers/sensors/Make.defs | 6 + drivers/sensors/zerocross.c | 546 ++++++++++++++++++++++++++++++++++++ include/nuttx/fs/ioctl.h | 65 +++-- 5 files changed, 595 insertions(+), 29 deletions(-) create mode 100644 drivers/sensors/zerocross.c diff --git a/ChangeLog b/ChangeLog index fb499c6313..af0e99f236 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11027,3 +11027,6 @@ This lower half driver is only usable in a limited number of situations, but can still serve as a module for the lower half button driver. (2015-10-13). + * drivers/sensors/zerocross.c and include/nuttx/sensors/zerocross.h: + Add Zero Cross device driver support. From Alan Carvalho de Assis + (2015-10-13). diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 510696bce7..a9d0d3c364 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -123,3 +123,7 @@ config LM92 config QENCODER bool "Qencoder" default n + +config ZEROCROSS + bool "Zero Cross Sensor" + default n diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 9a00862dfa..89a10808e9 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -101,6 +101,12 @@ ifeq ($(CONFIG_QENCODER),y) CSRCS += qencoder.c endif +# Zero Cross upper half + +ifeq ($(CONFIG_ZEROCROSS),y) + CSRCS += zerocross.c +endif + # Include sensor driver build support DEPPATH += --dep-path sensors diff --git a/drivers/sensors/zerocross.c b/drivers/sensors/zerocross.c new file mode 100644 index 0000000000..22f2f499a9 --- /dev/null +++ b/drivers/sensors/zerocross.c @@ -0,0 +1,546 @@ +/**************************************************************************** + * drivers/sensors/zerocross.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef CONFIG_ZEROCROSS + +#ifdef CONFIG_DISABLE_SIGNALS +#error "This driver needs SIGNAL support, remove CONFIG_DISABLE_SIGNALS" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Debug ********************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/* This structure describes the state of the upper half driver */ + +struct zc_upperhalf_s +{ + FAR struct zc_lowerhalf_s *lower; /* lower-half state */ + sem_t exclsem; /* Supports mutual exclusion */ + + /* The following is a singly linked list of open references to the + * zero cross device. + */ + + FAR struct zc_open_s *zu_open; + +}; + +/* This structure describes the state of one open zero cross driver instance */ + +struct zc_open_s +{ + /* Supports a singly linked list */ + + FAR struct zc_open_s *do_flink; + + /* The following will be true if we are closing */ + + volatile bool do_closing; + + /* Zero cross event notification information */ + + pid_t do_pid; + struct zc_notify_s do_notify; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int zc_open(FAR struct file *filep); +static int zc_close(FAR struct file *filep); +static ssize_t zc_read(FAR struct file *filep, FAR char *buffer, size_t + buflen); +static ssize_t zc_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int zc_ioctl(FAR struct file *filep, int cmd, unsigned long arg); + +static void zerocross_enable(FAR struct zc_upperhalf_s *priv); +static void zerocross_interrupt(FAR const struct zc_lowerhalf_s *lower, + FAR void *arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_zcops = +{ + zc_open, /* open */ + zc_close, /* close */ + zc_read, /* read */ + zc_write, /* write */ + 0, /* seek */ + zc_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +volatile int sample = 0; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: zerocross_enable + ****************************************************************************/ + +static void zerocross_enable(FAR struct zc_upperhalf_s *priv) +{ + FAR const struct zc_lowerhalf_s *lower; + irqstate_t flags; + + DEBUGASSERT(priv && priv->lower); + lower = priv->lower; + + /* This routine is called both task level and interrupt level, so + * interrupts must be disabled. + */ + + flags = irqsave(); + + /* Enable interrupts */ + + DEBUGASSERT(lower->zc_enable); + + /* Enable interrupts with the new button set */ + + lower->zc_enable(lower, (zc_interrupt_t)zerocross_interrupt, priv); + + irqrestore(flags); +} + +/**************************************************************************** + * Name: zerocross_interrupt + ****************************************************************************/ + +static void zerocross_interrupt(FAR const struct zc_lowerhalf_s *lower, + FAR void *arg) +{ + FAR struct zc_upperhalf_s *priv = (FAR struct zc_upperhalf_s *)arg; + FAR struct zc_open_s *opriv; + irqstate_t flags; + + /* This routine is called both task level and interrupt level, so + * interrupts must be disabled. + */ + + flags = irqsave(); + + /* Update sample value */ + + sample++; + + /* Visit each opened reference and notify a zero cross event */ + + for (opriv = priv->zu_open; opriv; opriv = opriv->do_flink) + { + /* Signal the waiter */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + union sigval value; + value.sival_int = (int)sample; + (void)sigqueue(opriv->do_pid, opriv->do_notify.zc_signo, value); +#else + (void)sigqueue(opriv->do_pid, opriv->do_notify.zc_signo, + (FAR void *)sample); +#endif + } + + irqrestore(flags); +} + +/************************************************************************************ + * Name: zc_open + * + * Description: + * This function is called whenever the PWM device is opened. + * + ************************************************************************************/ + +static int zc_open(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct zc_upperhalf_s *priv; + FAR const struct zc_lowerhalf_s *lower; + FAR struct zc_open_s *opriv; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct zc_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + snvdbg("ERROR: sem_wait failed: %d\n", ret); + return ret; + } + + /* Allocate a new open structure */ + + opriv = (FAR struct zc_open_s *)kmm_zalloc(sizeof(struct zc_open_s)); + if (!opriv) + { + snvdbg("ERROR: Failled to allocate open structure\n"); + ret = -ENOMEM; + goto errout_with_sem; + } + + /* Attach the open structure to the device */ + + opriv->do_flink = priv->zu_open; + priv->zu_open = opriv; + + /* Attach the open structure to the file structure */ + + filep->f_priv = (FAR void *)opriv; + ret = OK; + +errout_with_sem: + sem_post(&priv->exclsem); + return ret; +} + +/************************************************************************************ + * Name: zc_close + * + * Description: + * This function is called when the PWM device is closed. + * + ************************************************************************************/ + +static int zc_close(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct zc_upperhalf_s *priv; + FAR struct zc_open_s *opriv; + FAR struct zc_open_s *curr; + FAR struct zc_open_s *prev; + irqstate_t flags; + bool closing; + int ret; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct zc_upperhalf_s *)inode->i_private; + + /* Handle an improbable race conditions with the following atomic test + * and set. + * + * This is actually a pretty feeble attempt to handle this. The + * improbable race condition occurs if two different threads try to + * close the zero cross driver at the same time. The rule: don't do + * that! It is feeble because we do not really enforce stale pointer + * detection anyway. + */ + + flags = irqsave(); + closing = opriv->do_closing; + opriv->do_closing = true; + irqrestore(flags); + + if (closing) + { + /* Another thread is doing the close */ + + return OK; + } + + /* Get exclusive access to the driver structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + snvdbg("ERROR: sem_wait failed: %d\n", ret); + return ret; + } + + /* Find the open structure in the list of open structures for the device */ + + for (prev = NULL, curr = priv->zu_open; + curr && curr != opriv; + prev = curr, curr = curr->do_flink); + + DEBUGASSERT(curr); + if (!curr) + { + snvdbg("ERROR: Failed to find open entry\n"); + ret = -ENOENT; + goto errout_with_exclsem; + } + + /* Remove the structure from the device */ + + if (prev) + { + prev->do_flink = opriv->do_flink; + } + else + { + priv->zu_open = opriv->do_flink; + } + + /* And free the open structure */ + + kmm_free(opriv); + + /* Enable/disable interrupt handling */ + + zerocross_enable(priv); + ret = OK; + +errout_with_exclsem: + sem_post(&priv->exclsem); + return ret; +} + +/************************************************************************************ + * Name: zc_read + * + * Description:O + * A dummy read method. This is provided only to satsify the VFS layer. + * + ************************************************************************************/ + +static ssize_t zc_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +{ + /* Return zero -- usually meaning end-of-file */ + + return 0; +} + +/************************************************************************************ + * Name: zc_write + * + * Description: + * A dummy write method. This is provided only to satsify the VFS layer. + * + ************************************************************************************/ + +static ssize_t zc_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) +{ + /* Return a failure */ + + return -EPERM; +} + +/************************************************************************************ + * Name: zc_ioctl + * + * Description: + * The standard ioctl method. This is where ALL of the PWM work is done. + * + ************************************************************************************/ + +static int zc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct zc_upperhalf_s *priv; + FAR struct zc_open_s *opriv; + FAR struct zc_lowerhalf_s *lower; + int ret; + + snvdbg("cmd: %d arg: %ld\n", cmd, arg); + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private) + priv = (FAR struct zc_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the device structures */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + return ret; + } + + /* Handle built-in ioctl commands */ + + ret = -EINVAL; + switch (cmd) + { +#ifndef CONFIG_DISABLE_SIGNALS + /* Command: ZCIOC_REGISTER + * Description: Register to receive a signal whenever there is zero + * cross detection interrupt. + * Argument: A read-only pointer to an instance of struct + * zc_notify_s + * Return: Zero (OK) on success. Minus one will be returned on + * failure with the errno value set appropriately. + */ + + case ZCIOC_REGISTER: + { + FAR struct zc_notify_s *notify = + (FAR struct zc_notify_s *)((uintptr_t)arg); + + if (notify) + { + /* Save the notification events */ + + opriv->do_notify.zc_signo = notify->zc_signo; + opriv->do_pid = getpid(); + + /* Enable/disable interrupt handling */ + + zerocross_enable(priv); + ret = OK; + } + } + break; +#endif + + default: + { + snvdbg("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg); + ret = -ENOTTY; + } + break; + } + + sem_post(&priv->exclsem); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: zc_register + * + * Description: + * Register the Zero Cross lower half device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/zc0" + * lower - An instance of the lower half interface + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. The following + * possible error values may be returned (most are returned by + * register_driver()): + * + * EINVAL - 'path' is invalid for this operation + * EEXIST - An inode already exists at 'path' + * ENOMEM - Failed to allocate in-memory resources for the operation + * + ****************************************************************************/ + +int zc_register(FAR const char *devname, FAR struct zc_lowerhalf_s *lower) +{ + FAR struct zc_upperhalf_s *priv; + int ret; + + DEBUGASSERT(devname && lower); + + /* Allocate a new zero cross driver instance */ + + priv = (FAR struct zc_upperhalf_s *) + kmm_zalloc(sizeof(struct zc_upperhalf_s)); + + if (!priv) + { + snvdbg("ERROR: Failed to allocate device structure\n"); + return -ENOMEM; + } + + /* Make sure that zero cross interrupt is disabled */ + + DEBUGASSERT(lower->zc_enable); + lower->zc_enable(lower, NULL, NULL); + + /* Initialize the new zero cross driver instance */ + + priv->lower = lower; + sem_init(&priv->exclsem, 0, 1); + + /* And register the zero cross driver */ + + ret = register_driver(devname, &g_zcops, 0666, priv); + if (ret < 0) + { + snvdbg("ERROR: register_driver failed: %d\n", ret); + sem_destroy(&priv->exclsem); + kmm_free(priv); + } + + return ret; +} + +#endif /* CONFIG_ZEROCROSS */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 7a5d17f702..6814787005 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -78,7 +78,8 @@ #define _RELAYBASE (0x1900) /* Relay devices ioctl commands */ #define _CANBASE (0x1a00) /* CAN ioctl commands */ #define _BTNBASE (0x1b00) /* Button ioctl commands */ -#define _BOARDBASE (0x1c00) /* boardctl ioctl commands */ +#define _ZCBASE (0x1c00) /* Zero Cross ioctl commands */ +#define _BOARDBASE (0x1d00) /* boardctl ioctl commands */ /* Macros used to manage ioctl commands */ @@ -268,56 +269,56 @@ /* NuttX Audio driver ioctl definitions *************************************/ /* (see nuttx/audio/audio.h) */ -#define _AUDIOIOCVALID(c) (_IOC_TYPE(c)==_AUDIOIOCBASE) -#define _AUDIOIOC(nr) _IOC(_AUDIOIOCBASE,nr) +#define _AUDIOIOCVALID(c) (_IOC_TYPE(c)==_AUDIOIOCBASE) +#define _AUDIOIOC(nr) _IOC(_AUDIOIOCBASE,nr) /* Segment LCD driver ioctl definitions *************************************/ /* (see nuttx/include/lcd/slcd_codec.h */ -#define _SLCDIOCVALID(c) (_IOC_TYPE(c)==_SLCDIOCBASE) -#define _SLCDIOC(nr) _IOC(_SLCDIOCBASE,nr) +#define _SLCDIOCVALID(c) (_IOC_TYPE(c)==_SLCDIOCBASE) +#define _SLCDIOC(nr) _IOC(_SLCDIOCBASE,nr) /* Wireless driver ioctl definitions ****************************************/ /* (see nuttx/include/wireless/wireless.h */ -#define _WLIOCVALID(c) (_IOC_TYPE(c)==_WLIOCBASE) -#define _WLIOC(nr) _IOC(_WLIOCBASE,nr) +#define _WLIOCVALID(c) (_IOC_TYPE(c)==_WLIOCBASE) +#define _WLIOC(nr) _IOC(_WLIOCBASE,nr) /* Application Config Data driver ioctl definitions *************************/ /* (see nuttx/include/configdata.h */ -#define _CFGDIOCVALID(c) (_IOC_TYPE(c)==_CFGDIOCBASE) -#define _CFGDIOC(nr) _IOC(_CFGDIOCBASE,nr) +#define _CFGDIOCVALID(c) (_IOC_TYPE(c)==_CFGDIOCBASE) +#define _CFGDIOC(nr) _IOC(_CFGDIOCBASE,nr) /* Timer driver ioctl commands **********************************************/ /* (see nuttx/include/timer.h */ -#define _TCIOCVALID(c) (_IOC_TYPE(c)==_TCIOCBASE) -#define _TCIOC(nr) _IOC(_TCIOCBASE,nr) +#define _TCIOCVALID(c) (_IOC_TYPE(c)==_TCIOCBASE) +#define _TCIOC(nr) _IOC(_TCIOCBASE,nr) /* Discrete joystick driver ioctl definitions *******************************/ /* (see nuttx/include/input/djoystick.h */ -#define _DJOYIOCVALID(c) (_IOC_TYPE(c)==_DJOYBASE) -#define _DJOYIOC(nr) _IOC(_DJOYBASE,nr) +#define _DJOYIOCVALID(c) (_IOC_TYPE(c)==_DJOYBASE) +#define _DJOYIOC(nr) _IOC(_DJOYBASE,nr) /* Analog joystick driver ioctl definitions *********************************/ /* (see nuttx/include/input/ajoystick.h */ -#define _AJOYIOCVALID(c) (_IOC_TYPE(c)==_AJOYBASE) -#define _AJOYIOC(nr) _IOC(_AJOYBASE,nr) +#define _AJOYIOCVALID(c) (_IOC_TYPE(c)==_AJOYBASE) +#define _AJOYIOC(nr) _IOC(_AJOYBASE,nr) /* FIFOs and pipe driver ioctl definitions **********************************/ -#define _PIPEIOCVALID(c) (_IOC_TYPE(c)==_PIPEBASE) -#define _PIPEIOC(nr) _IOC(_PIPEBASE,nr) +#define _PIPEIOCVALID(c) (_IOC_TYPE(c)==_PIPEBASE) +#define _PIPEIOC(nr) _IOC(_PIPEBASE,nr) -#define PIPEIOC_POLICY _PIPEIOC(0x0001) /* Set buffer policy - * IN: unsigned long integer - * 0=free on last close - * (default) - * 1=fre when empty - * OUT: None */ +#define PIPEIOC_POLICY _PIPEIOC(0x0001) /* Set buffer policy + * IN: unsigned long integer + * 0=free on last close + * (default) + * 1=fre when empty + * OUT: None */ /* RTC driver ioctl definitions *********************************************/ /* (see nuttx/include/rtc.h */ @@ -328,20 +329,26 @@ /* Relay driver ioctl definitions *******************************************/ /* (see nuttx/power/relay.h */ -#define _RELAYIOCVALID(c) (_IOC_TYPE(c)==_RELAYBASE) -#define _RELAYIOC(nr) _IOC(_RELAYBASE,nr) +#define _RELAYIOCVALID(c) (_IOC_TYPE(c)==_RELAYBASE) +#define _RELAYIOC(nr) _IOC(_RELAYBASE,nr) /* CAN driver ioctl definitions *********************************************/ /* (see nuttx/can.h */ -#define _CANIOCVALID(c) (_IOC_TYPE(c)==_CANBASE) -#define _CANIOC(nr) _IOC(_CANBASE,nr) +#define _CANIOCVALID(c) (_IOC_TYPE(c)==_CANBASE) +#define _CANIOC(nr) _IOC(_CANBASE,nr) /* Button driver ioctl definitions ******************************************/ /* (see nuttx/can.h */ -#define _BTNIOCVALID(c) (_IOC_TYPE(c)==_BTNBASE) -#define _BTNIOC(nr) _IOC(_BTNBASE,nr) +#define _BTNIOCVALID(c) (_IOC_TYPE(c)==_BTNBASE) +#define _BTNIOC(nr) _IOC(_BTNBASE,nr) + +/* Zero Cross driver ioctl definitions **************************************/ +/* (see nuttx/include/sensor/zerocross.h */ + +#define _ZCIOCVALID(c) (_IOC_TYPE(c)==_ZCBASE) +#define _ZCIOC(nr) _IOC(_ZCBASE,nr) /* boardctl() command definitions *******************************************/ -- GitLab From f5f69ef85df3919bc25fbae6af6ebd2fbb88fc69 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 13 Oct 2015 07:36:46 -0600 Subject: [PATCH 228/858] Add a file missed in the last commit --- ChangeLog | 3 + configs | 2 +- include/nuttx/sensors/zerocross.h | 151 ++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 include/nuttx/sensors/zerocross.h diff --git a/ChangeLog b/ChangeLog index af0e99f236..b5fcab5b83 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11030,3 +11030,6 @@ * drivers/sensors/zerocross.c and include/nuttx/sensors/zerocross.h: Add Zero Cross device driver support. From Alan Carvalho de Assis (2015-10-13). + * configs/stm32f4discovery/src/stm32_zerocross.c: Add low level support + for the Zero Cross driver for the STM32F4-Discovery. From Alan + Carvalho de Assis (2015-10-13). diff --git a/configs b/configs index b16519ea24..47c4c967a3 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b16519ea24e26d50c61202ea80802a0417daeb11 +Subproject commit 47c4c967a3dd1c9de5fa41ba587468f744f1ca36 diff --git a/include/nuttx/sensors/zerocross.h b/include/nuttx/sensors/zerocross.h new file mode 100644 index 0000000000..9b93c7c215 --- /dev/null +++ b/include/nuttx/sensors/zerocross.h @@ -0,0 +1,151 @@ +/**************************************************************************** + * include/nuttx/zerocross.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NUTTX_SENSORS_ZEROCROSS_H +#define __NUTTX_SENSORS_ZEROCROSS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#ifdef CONFIG_ZEROCROSS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************ + * CONFIG_ZEROCROSS - Enables support for the zero cross AC detection upper + * half + */ + +/* Command: ZCIOC_REGISTER + * Description: Register to receive a signal whenever there is zero cross + * interrupt event. + * Argument: A read-only pointer to an instance of struct zc_notify_s + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define ZCIOC_REGISTER _ZCIOC(0x0001) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This is the vtable that is used to by the upper half of the zero cross + * to call back into the lower half of the zero cross driver. + */ + +struct zc_lowerhalf_s; + +/* This is the type of the discrete zero cross interrupt handler used with + * the struct zc_lowerhalf_s enable() method. + */ + +typedef CODE void (*zc_interrupt_t) + (FAR const struct zc_lowerhalf_s *lower, FAR void *arg); + +/* This is the interface between the lower half zero cross detection driver + * and the upper half zero cross detection driver. A (device-specific) + * instance of this structure is passed to the upper-half driver when the + * zero cross driver is registered. + * + * Normally that lower half logic will have its own, custom state structure + * that is simply cast to struct zc_lowerhalf_s. In order to perform such + * casts, the initial fields of the custom state structure match the initial + * fields of the following generic lower half state structure. + */ + +/* A reference to this structure is provided with the ZCIOC_REGISTER IOCTL + * command and describes the conditions under which the client would like + * to receive notification. + */ + +struct zc_notify_s +{ + uint8_t zc_signo; /* Signal number to use in the notification */ +}; + +struct zc_lowerhalf_s +{ + /* Enable interrupt on the defined pin used to zero cross detection */ + + CODE void (*zc_enable)(FAR const struct zc_lowerhalf_s *lower, + zc_interrupt_t handler, FAR void *arg); +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: zc_register + * + * Description: + * Register the Zero Cross lower half device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/zc0" + * lower - An instance of the lower half interface + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int zc_register(FAR const char *devpath, FAR struct zc_lowerhalf_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_ZEROCROSS */ +#endif /* __NUTTX_SENSORS_ZEROCROSS_H */ -- GitLab From a5f44cd9fcbc3f3c313957e205d896f6ec96dc3b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 13 Oct 2015 09:29:23 -0600 Subject: [PATCH 229/858] Buttons lower half: Undefine __KERNEL__ before including board.h to suppress bad included; fix some configuratin issues --- drivers/input/Kconfig | 4 +++- drivers/input/button_lower.c | 2 ++ fs/nxffs/README.txt | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 88d1e07ad3..e132870fb9 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -349,7 +349,9 @@ config BUTTONS_LOWER NUM_BUTTONS, and 4. The board.h header file must not include any other header files that are not accessibble in this context - (such as those in arch//src/). + (such as those in arch//src/) UNLESS those + inclusions are conditioned on __KERNEL__. button_lower.c + will undefine __KERNEL__ before included board.h. If your board does not meet these requirements, then the board_lower.c file can still be copied to your your diff --git a/drivers/input/button_lower.c b/drivers/input/button_lower.c index dba0b94bfa..fefab10b8c 100644 --- a/drivers/input/button_lower.c +++ b/drivers/input/button_lower.c @@ -47,6 +47,8 @@ #include #include + +#undef __KERNEL__ #include #if CONFIG_BUTTONS_LOWER diff --git a/fs/nxffs/README.txt b/fs/nxffs/README.txt index af631a94b0..e7d38e4e63 100644 --- a/fs/nxffs/README.txt +++ b/fs/nxffs/README.txt @@ -175,6 +175,6 @@ Things to Do done. That garbarge collection should search for valid blocks that no longer contain valid data. It should pre-erase them, put them in a good but empty state... all ready for file system re-organization. - - +- And worse, when NXFSS reorganization the FLASH a power cycle can + damage the file system content if it happens at the wrong time. -- GitLab From bf99b4e207117bdaac8438c8b4ac29599b6d45f6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 14 Oct 2015 07:15:00 -0600 Subject: [PATCH 230/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 9f6b9305b1..235452bd4e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9f6b9305b14423c28abeb6261b8ba7095073f316 +Subproject commit 235452bd4e71740fc5902bcad1016444d0e5e686 -- GitLab From 0ba6f21532621773e8dca5dc946c3337787ff16f Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 18 Oct 2015 07:52:47 +0800 Subject: [PATCH 231/858] Add support to Thermocouple-to-Digital converter MAX6675 --- drivers/sensors/Kconfig | 7 +++++++ drivers/sensors/Make.defs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index a9d0d3c364..80cdfcec0c 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -99,6 +99,13 @@ config MAX31855 ---help--- Enables support for the MAX31855 driver +config MAX6675 + bool "Maxim MAX6675 Driver" + default n + select SPI + ---help--- + Enables support for the MAX6675 driver + config I2C_LM75 bool default y if LM75 diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 89a10808e9..a1c5c69a54 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -90,6 +90,10 @@ ifeq ($(CONFIG_MAX31855),y) CSRCS += max31855.c endif +ifeq ($(CONFIG_MAX6675),y) + CSRCS += max6675.c +endif + ifeq ($(CONFIG_MPL115A),y) CSRCS += mpl115a.c endif -- GitLab From d8731d0ef19bda0e07c49ba62d240942e1b1ccb7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 18 Oct 2015 08:00:06 +0800 Subject: [PATCH 232/858] Add files missed in previous commit --- ChangeLog | 5 + configs | 2 +- drivers/sensors/max6675.c | 278 ++++++++++++++++++++++++++++++++ include/nuttx/sensors/max6675.h | 98 +++++++++++ 4 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 drivers/sensors/max6675.c create mode 100644 include/nuttx/sensors/max6675.h diff --git a/ChangeLog b/ChangeLog index b5fcab5b83..ce7daaffaf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11033,3 +11033,8 @@ * configs/stm32f4discovery/src/stm32_zerocross.c: Add low level support for the Zero Cross driver for the STM32F4-Discovery. From Alan Carvalho de Assis (2015-10-13). + * drivers/sensors/max6675.c and include/nuttx/sensors/max6675.h: Add + support to Thermocouple-to-Digital converter MAX6675. From Alan + Carvalho de Assis (2015-10-18). + * configs/stm32f4discovery/src: Add board config to support MAX6675. + From Alan Carvalho de Assis (2015-10-18). diff --git a/configs b/configs index 47c4c967a3..d459d2d316 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 47c4c967a3dd1c9de5fa41ba587468f744f1ca36 +Subproject commit d459d2d3160b0947ed87f8ebd6a0bf7ad04ebd05 diff --git a/drivers/sensors/max6675.c b/drivers/sensors/max6675.c new file mode 100644 index 0000000000..a39544ecea --- /dev/null +++ b/drivers/sensors/max6675.c @@ -0,0 +1,278 @@ +/**************************************************************************** + * drivers/sensors/max6675.c + * Character driver for the Maxim MAX6675 Thermocouple-to-Digital Converter + * + * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* NOTE: Some Maxim MAX6675 chips have an issue it report value 25% lower + * of real temperature, for more info read this thread: + * http://www.eevblog.com/forum/projects/max6675-temperature-error/ +*/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_SPI) && defined(CONFIG_MAX6675) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private + ****************************************************************************/ + +#define MAX6675_THREE_STATE (1 << 0) +#define MAX6675_DEV_ID (1 << 1) +#define MAX6675_OPEN_CIRCUIT (1 << 2) +#define MAX6675_TEMP_COUPLE 0x7ff8 + +struct max6675_dev_s +{ + FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ + int16_t temp; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Character driver methods */ + +static int max6675_open(FAR struct file *filep); +static int max6675_close(FAR struct file *filep); +static ssize_t max6675_read(FAR struct file *, FAR char *, size_t); +static ssize_t max6675_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_max6675fops = +{ + max6675_open, + max6675_close, + max6675_read, + max6675_write, + NULL, + NULL +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Name: max6675_open + * + * Description: + * This function is called whenever the MAX6675 device is opened. + * + ****************************************************************************/ + +static int max6675_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max6675_close + * + * Description: + * This routine is called when the MAX6675 device is closed. + * + ****************************************************************************/ + +static int max6675_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max6675_read + ****************************************************************************/ + +static ssize_t max6675_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct max6675_dev_s *priv = inode->i_private; + FAR uint16_t *temp = (FAR uint16_t *) buffer; + int ret = 2; + int16_t regmsb; + int16_t regval; + + /* Check for issues */ + + if (!buffer) + { + sndbg("Buffer is null\n"); + return -EINVAL; + } + + if (buflen != 2) + { + sndbg("You can't read something other than 16 bits (2 bytes)\n"); + return -EINVAL; + } + + /* Enable MAX6675's chip select */ + + SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, true); + + /* Read temperature */ + + SPI_RECVBLOCK(priv->spi, ®msb, 2); + + /* Disable MAX6675's chip select */ + + SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, false); + + regval = (regmsb & 0xFF00) >> 8; + regval |= (regmsb & 0xFF) << 8; + + sndbg("Read from MAX6675 = 0x%04X\n", regval); + + /* Verify if the device ID bit is really zero */ + + if (regval & MAX6675_DEV_ID) + { + sndbg("ERROR: The Device ID bit needs to be 0 !\n"); + ret = -EINVAL; + } + + /* Detect if termocople input is open */ + + if (regval & MAX6675_OPEN_CIRCUIT) + { + sndbg("The thermocouple input is not connected!\n"); + ret = -EINVAL; + } + + /* Get the temperature */ + + *temp = (regval & MAX6675_TEMP_COUPLE) >> 3; + + /* Return two bytes, the temperature is fixed point Q10.2, then divide by 4 + * in your application in order to get real temperature in Celsius degrees. + */ + + return ret; +} + +/**************************************************************************** + * Name: max6675_write + ****************************************************************************/ + +static ssize_t max6675_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: max6675_register + * + * Description: + * Register the MAX6675 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * spi - An instance of the SPU interface to use to communicate with + * MAX6675. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int max6675_register(FAR const char *devpath, FAR struct spi_dev_s *spi) +{ + FAR struct max6675_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(spi != NULL); + + /* Initialize the MAX6675 device structure */ + + priv = (FAR struct max6675_dev_s *)kmm_malloc(sizeof(struct max6675_dev_s)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->spi = spi; + priv->temp = 0; + +#ifdef CONFIG_SPI_OWNBUS + /* Configure SPI for the MAX6675 */ + + SPI_SETMODE(priv->spi, SPIDEV_MODE1); + SPI_SETBITS(priv->spi, 8); + SPI_SETFREQUENCY(priv->spi, MAX6675_SPI_MAXFREQ); +#endif + + /* Register the character driver */ + + ret = register_driver(devpath, &g_max6675fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + return ret; +} +#endif /* CONFIG_SPI && CONFIG_MAX6675 */ diff --git a/include/nuttx/sensors/max6675.h b/include/nuttx/sensors/max6675.h new file mode 100644 index 0000000000..0864c7434b --- /dev/null +++ b/include/nuttx/sensors/max6675.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * include/nuttx/input/max6675.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_MAX6675_H +#define __INCLUDE_NUTTX_SENSORS_MAX6675_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_MAX6675) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#define MAX6675_SPI_MAXFREQ 4000000 + +struct spi_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: max6675_register + * + * Description: + * This function will register the max6675 driver as /dev/tempN + * where N is the minor device number + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * spi - An instance of the SPI interface to use to communicate with + * MAX6675 + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int max6675_register(FAR const char *devpath, FAR struct spi_dev_s *spi); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_MAX6675 */ +#endif /* __INCLUDE_NUTTX_SENSORS_MAX6675_H */ -- GitLab From 081fa3e0ec5217d9d9d633169f4b4acdd12a0467 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 18 Oct 2015 08:15:39 +0800 Subject: [PATCH 233/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 235452bd4e..95de278075 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 235452bd4e71740fc5902bcad1016444d0e5e686 +Subproject commit 95de278075782769e147e1fd343f68443829e627 diff --git a/configs b/configs index d459d2d316..b782406b1e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d459d2d3160b0947ed87f8ebd6a0bf7ad04ebd05 +Subproject commit b782406b1e8144d295f3c34ae2926c4f7c10fdd0 -- GitLab From 00af71dd78984237543fb4c9c13fe527d3134623 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Oct 2015 06:02:10 +0800 Subject: [PATCH 234/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ce7daaffaf..59cea52f44 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11038,3 +11038,5 @@ Carvalho de Assis (2015-10-18). * configs/stm32f4discovery/src: Add board config to support MAX6675. From Alan Carvalho de Assis (2015-10-18). + * arch/arm/src/samv7/sam_lowputc.c: Reconfigure System I/O when using + USART1. From Frank Benkert (2015-10-20). diff --git a/arch b/arch index 95de278075..6103907149 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 95de278075782769e147e1fd343f68443829e627 +Subproject commit 6103907149f11534550f840a72c8aec0379feeb5 -- GitLab From af9590eef7cc7f9a13f8471e5820591991f3ced6 Mon Sep 17 00:00:00 2001 From: Marten Svanfeldt Date: Wed, 21 Oct 2015 11:32:57 +0800 Subject: [PATCH 235/858] Extend the AT24Cxx MTD driver with support for -04,-08 and -16 parts. These parts utilize the same one-byte-address in the I2C protocol as the -02, but requires different I2C addresses for different banks of the EEPROM. Signed-off-by: Marten Svanfeldt --- drivers/mtd/at24xx.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 32ea3c618e..b4f982b9ef 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -81,10 +81,22 @@ /* Get the part configuration based on the size configuration */ -#if CONFIG_AT24XX_SIZE == 2 /* AT24C32: 2Kbits = 256; 16 * 16 = 256 */ +#if CONFIG_AT24XX_SIZE == 2 /* AT24C02: 2Kbits = 256; 16 * 16 = 256 */ # define AT24XX_NPAGES 16 # define AT24XX_PAGESIZE 16 # define AT24XX_ADDRSIZE 1 +#elif CONFIG_AT24XX_SIZE == 4 /* AT24C04: 4Kbits = 512B; 32 * 16 = 512 */ +# define AT24XX_NPAGES 32 +# define AT24XX_PAGESIZE 16 +# define AT24XX_ADDRSIZE 1 +#elif CONFIG_AT24XX_SIZE == 8 /* AT24C08: 8Kbits = 1KiB; 64 * 16 = 1024 */ +# define AT24XX_NPAGES 64 +# define AT24XX_PAGESIZE 16 +# define AT24XX_ADDRSIZE 1 +#elif CONFIG_AT24XX_SIZE == 16 /* AT24C16: 16Kbits = 2KiB; 128 * 16 = 2048 */ +# define AT24XX_NPAGES 128 +# define AT24XX_PAGESIZE 16 +# define AT24XX_ADDRSIZE 1 #elif CONFIG_AT24XX_SIZE == 32 /* AT24C32: 32Kbits = 4KiB; 128 * 32 = 4096 */ # define AT24XX_NPAGES 128 # define AT24XX_PAGESIZE 32 @@ -185,12 +197,13 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv) for (startblock = 0; startblock < priv->npages; startblock++) { -#if AT24XX_ADDRSIZE == 2 uint16_t offset = startblock * priv->pagesize; +#if AT24XX_ADDRSIZE == 2 buf[1] = offset & 0xff; buf[0] = (offset >> 8) & 0xff; #else - buf[0] = startblock * priv->pagesize; + buf[0] = offset & 0xff; + I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); #endif while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) @@ -228,7 +241,6 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, fvdbg("offset: %lu nbytes: %lu address: %02x\n", (unsigned long)offset, (unsigned long)nbytes, address); - I2C_SETADDRESS(priv->dev, address, 7); I2C_SETFREQUENCY(priv->dev, 100000); /* "Random Read: A Random Read requires a dummy byte write sequence to load in the @@ -247,8 +259,12 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, #if AT24XX_ADDRSIZE == 2 buf[1] = offset & 0xff; buf[0] = (offset >> 8) & 0xff; + + I2C_SETADDRESS(priv->dev, address, 7); #else - buf[0] = (uint8_t)offset; + buf[0] = offset & 0xff; + + I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7); #endif while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) @@ -356,12 +372,14 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t while (blocksleft-- > 0) { -#if AT24XX_ADDRSIZE == 2 uint16_t offset = startblock * priv->pagesize; +#if AT24XX_ADDRSIZE == 2 buf[1] = offset & 0xff; buf[0] = (offset >> 8) & 0xff; #else - buf[0] = startblock * priv->pagesize; + buf[0] = offset & 0xff; + + I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7); #endif while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) -- GitLab From a31d1fd378381089d430cdd1972e16f8102416a5 Mon Sep 17 00:00:00 2001 From: Marten Svanfeldt Date: Wed, 21 Oct 2015 11:34:34 +0800 Subject: [PATCH 236/858] Make I2C frequency configurable for the AT24Cxx EEPROM driver Signed-off-by: Marten Svanfeldt --- drivers/mtd/Kconfig | 8 ++++++++ drivers/mtd/at24xx.c | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 97ce9effca..c35d28a34b 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -309,6 +309,14 @@ config AT24XX_EXTSIZE Other, block-oriented access are not effected by this setting +config AT24XX_FREQUENCY + int "AT24xx I2C bus frequency" + default 100000 + ---help--- + Set the I2C frequency to use when accessing the AT24CXX EEPROM. This value + must represent a valid I2C speed (normally less than 400.000) or the driver + might fail. + endif config MTD_AT25 diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index b4f982b9ef..e8842f8bdd 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -78,6 +78,9 @@ # warning "Assuming AT24 address of 0x50" # define CONFIG_AT24XX_ADDR 0x50 #endif +#ifndef CONFIG_AT24XX_FREQUENCY +# define CONFIG_AT24XX_FREQUENCY 100000 +#endif /* Get the part configuration based on the size configuration */ @@ -193,7 +196,7 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv) memset(&buf[AT24XX_ADDRSIZE], 0xff, priv->pagesize); I2C_SETADDRESS(priv->dev, priv->addr, 7); - I2C_SETFREQUENCY(priv->dev, 100000); + I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); for (startblock = 0; startblock < priv->npages; startblock++) { @@ -241,7 +244,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, fvdbg("offset: %lu nbytes: %lu address: %02x\n", (unsigned long)offset, (unsigned long)nbytes, address); - I2C_SETFREQUENCY(priv->dev, 100000); + I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); /* "Random Read: A Random Read requires a dummy byte write sequence to load in the * data word address. Once the device address word and data word address are clocked @@ -368,7 +371,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); I2C_SETADDRESS(priv->dev, priv->addr, 7); - I2C_SETFREQUENCY(priv->dev, 100000); + I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); while (blocksleft-- > 0) { -- GitLab From 68c4dedb789d92b2c84f9d6ca3f49a59686cc585 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 23 Oct 2015 07:09:25 +0800 Subject: [PATCH 237/858] Named semaphores: Bad cast in sem_close(). Fixed by reordering fields of struct nsem_inode_s so that the cast will work --- include/nuttx/semaphore.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 5460ce15c5..2eb624bf70 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -60,10 +60,12 @@ struct inode; struct nsem_inode_s { - /* Inode payload unique to named semaphores */ + /* Inode payload unique to named semaphores. ns_sem must appear first in + * this structure in order to support casting between type sem_t and + * types of struct nsem_inode_s. */ - FAR struct inode *ns_inode; /* Containing inode */ sem_t ns_sem; /* The semaphore */ + FAR struct inode *ns_inode; /* Containing inode */ }; #endif -- GitLab From aa92d44caf6afd2f4969eb16bdad0aba832f66f8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 23 Oct 2015 07:12:44 +0800 Subject: [PATCH 238/858] Update ChangeLog --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 59cea52f44..69b2461f44 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11040,3 +11040,7 @@ From Alan Carvalho de Assis (2015-10-18). * arch/arm/src/samv7/sam_lowputc.c: Reconfigure System I/O when using USART1. From Frank Benkert (2015-10-20). + * fs/semaphore: Named semaphores: Bad cast in sem_close(). Fixed by + reordering fields of struct nsem_inode_s so that the cast will work + (2015-10-22). + -- GitLab From a7a405df009bcb70dad92db24e86395d5d11b1d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 23 Oct 2015 07:16:42 +0800 Subject: [PATCH 239/858] Update ChangeLog --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 6103907149..47cd8e4cd2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6103907149f11534550f840a72c8aec0379feeb5 +Subproject commit 47cd8e4cd255d884fe88840e39d6903bcbf4cf6c -- GitLab From e772c56ef6ed7efd88bcc6decee5af6fc8c2aac1 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Sat, 31 Oct 2015 09:04:53 -0600 Subject: [PATCH 240/858] AT24xx EEPROM Driver: Correct typo from last changeset --- drivers/mtd/at24xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index e8842f8bdd..31e909334b 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -382,7 +382,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t #else buf[0] = offset & 0xff; - I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7); + I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); #endif while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) -- GitLab From 148d5fcffdd3ebc916c4ad389185366e78876ba4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 09:04:02 -0600 Subject: [PATCH 241/858] Rename board_led_initialize to board_autoled_initiaize --- arch | 2 +- configs | 2 +- include/nuttx/board.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch b/arch index 47cd8e4cd2..848fedb13d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 47cd8e4cd255d884fe88840e39d6903bcbf4cf6c +Subproject commit 848fedb13d7dca0bfcd85e3e302d0deea23e9ce0 diff --git a/configs b/configs index b782406b1e..2ae6dba193 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b782406b1e8144d295f3c34ae2926c4f7c10fdd0 +Subproject commit 2ae6dba193311d26f3778c2624bf2190d300a72e diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 74431a16eb..2019db6ad5 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -362,7 +362,7 @@ void board_lcd_uninitialize(void); #endif /**************************************************************************** - * Name: board_led_initialize + * Name: board_autoled_initialize * * Description: * This functions is called very early in initialization to perform board- @@ -370,12 +370,12 @@ void board_lcd_uninitialize(void); * things as, for example, configure GPIO pins to drive the LEDs and also * putting the LEDs in their correct initial state. * - * NOTE: In most architectures, board_led_initialize() is called from + * NOTE: In most architectures, board_autoled_initialize() is called from * board-specific initialization logic. But there are a few architectures * where this initialization function is still called from common chip * architecture logic. This interface is not, however, a common board * interface in any event and, hence, the usage of the name - * board_led_initialize is deprecated. + * board_autoled_initialize is deprecated. * * WARNING: This interface name will eventually be removed; do not use it * in new board ports. New implementations should use the naming @@ -391,9 +391,9 @@ void board_lcd_uninitialize(void); ****************************************************************************/ #ifdef CONFIG_ARCH_LEDS -void board_led_initialize(void); +void board_autoled_initialize(void); #else -# define board_led_initialize() +# define board_autoled_initialize() #endif /**************************************************************************** -- GitLab From 8093def2c89cdfe3246d6e0763182fe505896eeb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 09:07:46 -0600 Subject: [PATCH 242/858] Rename board_led_on to board_autoled_on --- arch | 2 +- configs | 2 +- include/nuttx/board.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 848fedb13d..89bca2d78b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 848fedb13d7dca0bfcd85e3e302d0deea23e9ce0 +Subproject commit 89bca2d78b1fcf2292c1b049a9e8a1b6dfe173d5 diff --git a/configs b/configs index 2ae6dba193..bcc35c55a9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2ae6dba193311d26f3778c2624bf2190d300a72e +Subproject commit bcc35c55a98e42fa2e4cc4052468e24aa5c2d43f diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 2019db6ad5..40f17ff3e9 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -397,7 +397,7 @@ void board_autoled_initialize(void); #endif /**************************************************************************** - * Name: board_led_on + * Name: board_autoled_on * * Description: * Set the LED configuration into the ON condition for the state provided @@ -426,9 +426,9 @@ void board_autoled_initialize(void); ****************************************************************************/ #ifdef CONFIG_ARCH_LEDS -void board_led_on(int led); +void board_autoled_on(int led); #else -# define board_led_on(led) +# define board_autoled_on(led) #endif /**************************************************************************** -- GitLab From 2318038bbc7be8e4098a6dbfe1b77e68af35bcab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 09:10:40 -0600 Subject: [PATCH 243/858] Rename board_led_off to board_autoled_off --- Documentation | 2 +- arch | 2 +- configs | 2 +- include/nuttx/board.h | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation b/Documentation index 7a768453c1..81e94b2e1d 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 7a768453c1ca9602d668c79d45db141b74d5c215 +Subproject commit 81e94b2e1d2831d590f07ef729e74a7b66922ac5 diff --git a/arch b/arch index 89bca2d78b..7eca3dcc8f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 89bca2d78b1fcf2292c1b049a9e8a1b6dfe173d5 +Subproject commit 7eca3dcc8f3624c3e0fe383e1d3f047e3d8c4a83 diff --git a/configs b/configs index bcc35c55a9..3b9c3d5ed2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bcc35c55a98e42fa2e4cc4052468e24aa5c2d43f +Subproject commit 3b9c3d5ed2439cf85344999f986150d59d5a5972 diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 40f17ff3e9..385a4ac06e 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -432,7 +432,7 @@ void board_autoled_on(int led); #endif /**************************************************************************** - * Name: board_led_off + * Name: board_autoled_off * * Description: * Set the LED configuration into the OFF condition for the state provided @@ -457,9 +457,9 @@ void board_autoled_on(int led); ****************************************************************************/ #ifdef CONFIG_ARCH_LEDS -void board_led_off(int led); +void board_autoled_off(int led); #else -# define board_led_off(led) +# define board_autoled_off(led) #endif /**************************************************************************** -- GitLab From 56ad07f02b26e1c85f9eacdfd5e47736bdf4a642 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 12:48:13 -0600 Subject: [PATCH 244/858] Add standard naming for board user LED functions --- configs | 2 +- include/nuttx/board.h | 78 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/configs b/configs index 3b9c3d5ed2..b3ac585690 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3b9c3d5ed2439cf85344999f986150d59d5a5972 +Subproject commit b3ac585690e98fc83d1470de900adba112157f49 diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 385a4ac06e..ab0511dff1 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -365,7 +365,7 @@ void board_lcd_uninitialize(void); * Name: board_autoled_initialize * * Description: - * This functions is called very early in initialization to perform board- + * This function is called very early in initialization to perform board- * specific initialization of LED-related resources. This includes such * things as, for example, configure GPIO pins to drive the LEDs and also * putting the LEDs in their correct initial state. @@ -462,6 +462,82 @@ void board_autoled_off(int led); # define board_autoled_off(led) #endif +/**************************************************************************** + * Name: board_userled_initialize + * + * Description: + * This function may called from application-specific logic during its + * to perform board-specific initialization of LED resources. This + * includes such things as, for example, configure GPIO pins to drive the + * LEDs and also putting the LEDs in their correct initial state. + * + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be + * available to control the LEDs directly from user board logic or + * indirectly user applications (via the common LED charater driver). + * + * Most boards have only a few LEDs and in thoses cases all LEDs may be + * used by the NuttX LED logic exclusively and may not be available for + * use by user logic if CONFIG_ARCH_LEDS=y. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_LEDS +void board_userled_initialize(void); +#endif + +/**************************************************************************** + * Name: board_userled + * + * Description: + * This interface may be used by application specific logic to set the + * state of a single LED. Definitions for the led identification are + * provided in the board-specific board.h header file that may be included + * like: + * + * #included + * + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be + * available to control the LEDs directly from user board logic or + * indirectly user applications (via the common LED charater driver). + * + * Most boards have only a few LEDs and in thoses cases all LEDs may be + * used by the NuttX LED logic exclusively and may not be available for + * use by user logic if CONFIG_ARCH_LEDS=y. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_LEDS +void board_userled(int led, bool ledon); +#endif + +/**************************************************************************** + * Name: board_userled_all + * + * Description: + * This interface may be used by application specific logic to set the + * state of all board LED. Definitions for the led set member + * identification is provided in the board-specific board.h header file + * that may be includedlike: + * + * #included + * + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be + * available to control the LEDs directly from user board logic or + * indirectly user applications (via the common LED charater driver). + * + * Most boards have only a few LEDs and in thoses cases all LEDs may be + * used by the NuttX LED logic exclusively and may not be available for + * use by user logic if CONFIG_ARCH_LEDS=y. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_LEDS +void board_userled_all(uint8_t ledset); +#endif + /**************************************************************************** * Name: board_button_initialize * -- GitLab From 0032b91f49e3707e40a4a147270bd98280f697d7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 12:51:03 -0600 Subject: [PATCH 245/858] Update ChangeLog --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 69b2461f44..c897ce1711 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11043,4 +11043,10 @@ * fs/semaphore: Named semaphores: Bad cast in sem_close(). Fixed by reordering fields of struct nsem_inode_s so that the cast will work (2015-10-22). + * Many files: Rename board_led_* functions to board_autoled_* functions. + This makes room in the namespace to handler user LED functions + (2015-11-01). + * Many files: Standardize naming of the user LED interface functions. + The new user LED interface functions are now prototyped in only in + include/nuttx/board.h and have name like board_userled_* (2015-11-01). -- GitLab From cbb78071b3064d1434de9d1102645022992963b2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 13:14:48 -0600 Subject: [PATCH 246/858] Rename ioexpander/ directories to discrete/ --- ChangeLog | 3 +++ drivers/Kconfig | 14 +++++------ drivers/Makefile | 2 +- drivers/{ioexpander => discrete}/Kconfig | 10 ++++++++ drivers/{ioexpander => discrete}/Make.defs | 8 +++--- drivers/{ioexpander => discrete}/pca9555.c | 25 ++++++++++--------- drivers/{ioexpander => discrete}/pca9555.h | 12 ++++----- .../{ioexpander => discrete}/ioexpander.h | 8 +++--- .../nuttx/{ioexpander => discrete}/pca9555.h | 8 +++--- 9 files changed, 52 insertions(+), 38 deletions(-) rename drivers/{ioexpander => discrete}/Kconfig (76%) rename drivers/{ioexpander => discrete}/Make.defs (94%) rename drivers/{ioexpander => discrete}/pca9555.c (96%) rename drivers/{ioexpander => discrete}/pca9555.h (95%) rename include/nuttx/{ioexpander => discrete}/ioexpander.h (98%) rename include/nuttx/{ioexpander => discrete}/pca9555.h (96%) diff --git a/ChangeLog b/ChangeLog index c897ce1711..0297310651 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11049,4 +11049,7 @@ * Many files: Standardize naming of the user LED interface functions. The new user LED interface functions are now prototyped in only in include/nuttx/board.h and have name like board_userled_* (2015-11-01). + * Rename ioexpander/ directories to discrete/. This expands the + namespace so that other discrete I/O drivers can reside there as + well (2015-11-01). diff --git a/drivers/Kconfig b/drivers/Kconfig index 263001d9cc..16fa26de7d 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -292,16 +292,16 @@ if INPUT source drivers/input/Kconfig endif # INPUT -menuconfig IOEXPANDER - bool "IO Expanders Support" +menuconfig DISCRETE_IO + bool "Discrete I/O" default n ---help--- - This directory holds implementations of IO expander drivers. - See include/nuttx/ioexpander/ioexpander.h for registration information. + This directory holds implementations of IO expander and other + discrete I/O drivers. -if IOEXPANDER -source drivers/ioexpander/Kconfig -endif # IOEXPANDER +if DISCRETE_IO +source drivers/discrete/Kconfig +endif # DISCRETE_IO menuconfig LCD bool "LCD Driver Support" diff --git a/drivers/Makefile b/drivers/Makefile index 086cecb2ad..80630ed5af 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -53,7 +53,7 @@ include analog$(DELIM)Make.defs include audio$(DELIM)Make.defs include bch$(DELIM)Make.defs include input$(DELIM)Make.defs -include ioexpander$(DELIM)Make.defs +include discrete$(DELIM)Make.defs include lcd$(DELIM)Make.defs include mmcsd$(DELIM)Make.defs include mtd$(DELIM)Make.defs diff --git a/drivers/ioexpander/Kconfig b/drivers/discrete/Kconfig similarity index 76% rename from drivers/ioexpander/Kconfig rename to drivers/discrete/Kconfig index 1056041063..afeaacb834 100644 --- a/drivers/ioexpander/Kconfig +++ b/drivers/discrete/Kconfig @@ -3,6 +3,15 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menuconfig IOEXPANDER + bool "IO Expander Support" + default n + ---help--- + This directory holds implementations of IO expander drivers. + See include/nuttx/discrete/ioexpander.h for registration information. + +if IOEXPANDER + config IOEXPANDER_MULTIPIN bool "Support multi-pin access routines" default n @@ -32,3 +41,4 @@ config PCA9555_INT_DISABLE Disable driver interrupt functionality endif # IOEXPANDER_PCA9555 +endif # IOEXPANDER diff --git a/drivers/ioexpander/Make.defs b/drivers/discrete/Make.defs similarity index 94% rename from drivers/ioexpander/Make.defs rename to drivers/discrete/Make.defs index 7e34efa8b0..94ae462c7c 100644 --- a/drivers/ioexpander/Make.defs +++ b/drivers/discrete/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# drivers/ioexpander/Make.defs +# drivers/discrete/Make.defs # # Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Sebastien Lorquet @@ -45,8 +45,8 @@ endif # Include io expander device driver build support -DEPPATH += --dep-path ioexpander -VPATH += :ioexpander -CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)ioexpander} +DEPPATH += --dep-path discrete +VPATH += :discrete +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)discrete} endif diff --git a/drivers/ioexpander/pca9555.c b/drivers/discrete/pca9555.c similarity index 96% rename from drivers/ioexpander/pca9555.c rename to drivers/discrete/pca9555.c index 3bf2cf1923..ae5c117d8a 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/discrete/pca9555.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/ioexpander/pca9555.c + * drivers/discrete/pca9555.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -48,7 +48,8 @@ #include #include -#include +#include +#include #include "pca9555.h" @@ -208,7 +209,7 @@ static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, * Name: pca9555_direction * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -224,12 +225,12 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_option * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, - int opt, void *val) + int opt, FAR void *val) { FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; int ival = (int)val; @@ -246,7 +247,7 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_write * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -261,7 +262,7 @@ static int pca9555_write(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_readpin * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -276,7 +277,7 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_readbuf * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -340,7 +341,7 @@ static int pca9555_getmultibits(FAR struct i2c_dev_s *i2c, uint8_t addr, * Name: pca9555_multiwrite * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -402,7 +403,7 @@ static int pca9555_multiwrite(FAR struct ioexpander_dev_s *dev, * Name: pca9555_multireadpin * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -419,7 +420,7 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, * Name: pca9555_multireadbuf * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ @@ -440,7 +441,7 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, * Name: pca9555_gpioworker * * Description: - * See include/nuttx/ioexpander/ioexpander.h + * See include/nuttx/discrete/ioexpander.h * ****************************************************************************/ diff --git a/drivers/ioexpander/pca9555.h b/drivers/discrete/pca9555.h similarity index 95% rename from drivers/ioexpander/pca9555.h rename to drivers/discrete/pca9555.h index ef0495a9f4..2586937c83 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/discrete/pca9555.h @@ -1,5 +1,5 @@ /******************************************************************************************** - * drivers/ioexpander/pca9555.h + * drivers/discrete/pca9555.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -37,8 +37,8 @@ * ********************************************************************************************/ -#ifndef __DRIVERS_IOEXPANDER_PCA9555_H -#define __DRIVERS_IOEXPANDER_PCA9555_H +#ifndef __DRIVERS_DISCRETE_PCA9555_H +#define __DRIVERS_DISCRETE_PCA9555_H /******************************************************************************************** * Included Files @@ -49,8 +49,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -139,4 +139,4 @@ struct pca9555_dev_s }; #endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9555 */ -#endif /* __DRIVERS_IOEXPANDER_PCA9555_H */ +#endif /* __DRIVERS_DISCRETE_PCA9555_H */ diff --git a/include/nuttx/ioexpander/ioexpander.h b/include/nuttx/discrete/ioexpander.h similarity index 98% rename from include/nuttx/ioexpander/ioexpander.h rename to include/nuttx/discrete/ioexpander.h index 96d4197a72..609961d895 100644 --- a/include/nuttx/ioexpander/ioexpander.h +++ b/include/nuttx/discrete/ioexpander.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/ioexpander/ioexpander.h + * include/nuttx/discrete/ioexpander.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H -#define __INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H +#ifndef __INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H +#define __INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H /**************************************************************************** * Included Files @@ -252,5 +252,5 @@ struct ioexpander_dev_s }; #endif //CONFIG_IOEXPANDER -#endif //__INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H +#endif //__INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H diff --git a/include/nuttx/ioexpander/pca9555.h b/include/nuttx/discrete/pca9555.h similarity index 96% rename from include/nuttx/ioexpander/pca9555.h rename to include/nuttx/discrete/pca9555.h index b8c857a3e7..fea1bdb3d4 100644 --- a/include/nuttx/ioexpander/pca9555.h +++ b/include/nuttx/discrete/pca9555.h @@ -1,5 +1,5 @@ /******************************************************************************************** - * include/nuttx/ioexpander/pca9555.h + * include/nuttx/discrete/pca9555.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -37,8 +37,8 @@ * ********************************************************************************************/ -#ifndef __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H -#define __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H +#ifndef __INCLUDE_NUTTX_DISCRETE_PCA9555_H +#define __INCLUDE_NUTTX_DISCRETE_PCA9555_H #include @@ -120,4 +120,4 @@ FAR struct ioexpander_dev_s* pca9555_initialize(FAR struct i2c_dev_s *dev, } #endif -#endif /* __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H */ +#endif /* __INCLUDE_NUTTX_DISCRETE_PCA9555_H */ -- GitLab From 0dea00177e522844548ce693ab0909321185eae0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 14:41:40 -0600 Subject: [PATCH 247/858] Add a generic user LED upper half discrete driver --- Kconfig | 10 + drivers/discrete/Kconfig | 36 ++ drivers/discrete/Make.defs | 20 +- drivers/discrete/userled_upper.c | 599 +++++++++++++++++++++++++++++++ drivers/input/Kconfig | 2 +- include/nuttx/board.h | 1 + include/nuttx/discrete/userled.h | 185 ++++++++++ include/nuttx/fs/ioctl.h | 16 +- 8 files changed, 862 insertions(+), 7 deletions(-) create mode 100644 drivers/discrete/userled_upper.c create mode 100644 include/nuttx/discrete/userled.h diff --git a/Kconfig b/Kconfig index e57918a0ff..ce0bfa5b13 100644 --- a/Kconfig +++ b/Kconfig @@ -548,6 +548,16 @@ config DEBUG_INPUT this debug option is board-specific and may not be available for some boards. +config DEBUG_DISCRETE + bool "Discrete I/O Debug Output" + default n + depends on DISCRETE_IO + ---help--- + Enable low level debug SYSLOG output from the discrete I/O device + drivers such as LEDs and I/O expanders (disabled by default). + Support for this debug option is board-specific and may not be + available for some boards. + config DEBUG_ANALOG bool "Analog Device Debug Output" default n diff --git a/drivers/discrete/Kconfig b/drivers/discrete/Kconfig index afeaacb834..9bd4492a9d 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/discrete/Kconfig @@ -42,3 +42,39 @@ config PCA9555_INT_DISABLE endif # IOEXPANDER_PCA9555 endif # IOEXPANDER + +config USERLED + bool "LED driver" + default n + depends on ARCH_HAVE_LEDS + ---help--- + Enable standard user LED upper half driver. + +if USERLED + +config USERLED_LOWER + bool "Generic Lower Half LED Driver" + default n + ---help--- + If the board supports the standard LED interfaces as + defined in include/nuttx/board.h header file, then this + standard LED lower half driver might be usable. + + In order for this generic driver to be usable: + + 1. The board implementation must provide the LED + interfaces as defined in include/nuttx/board.h + 2. The board.h header file must provide the definition + NUM_USERLED, and + 3. The board.h header file must not include any other + header files that are not accessibble in this context + (such as those in arch//src/) UNLESS those + inclusions are conditioned on __KERNEL__. button_lower.c + will undefine __KERNEL__ before included board.h. + + If your board does not meet these requirements, then the + userled_lower.c file can still be copied to your your + board src/ directory and modified for your specific board + requirements. + +endif # USERLED diff --git a/drivers/discrete/Make.defs b/drivers/discrete/Make.defs index 94ae462c7c..3dc5cfa176 100644 --- a/drivers/discrete/Make.defs +++ b/drivers/discrete/Make.defs @@ -33,17 +33,31 @@ # ############################################################################ -# Don't build anything if there is no support for io expander devices +# Don't build anything if there is no support for discrete devices + +ifeq ($(CONFIG_DISCRETE_IO),y) + +# Include user LED driver + +ifeq ($(CONFIG_USERLED),y) + CSRCS += userled_upper.c +ifeq ($(CONFIG_USERLED_LOWER),y) + CSRCS += userled_lower.c +endif +endif + +# Check if I/O expander support is enabled ifeq ($(CONFIG_IOEXPANDER),y) -# Include the selected io expander drivers +# Include the selected I/O expander drivers ifeq ($(CONFIG_IOEXPANDER_PCA9555),y) CSRCS += pca9555.c endif +endif -# Include io expander device driver build support +# Include discrete I/O device driver build support DEPPATH += --dep-path discrete VPATH += :discrete diff --git a/drivers/discrete/userled_upper.c b/drivers/discrete/userled_upper.c new file mode 100644 index 0000000000..71030ea734 --- /dev/null +++ b/drivers/discrete/userled_upper.c @@ -0,0 +1,599 @@ +/**************************************************************************** + * drivers/button_upper.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* This file provides a driver for a LED input devices. + * + * The LEDs driver exports a standard character driver interface. By + * convention, the LED driver is registered as an input device at + * /dev/btnN where N uniquely identifies the driver instance. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_VERBOSE +# undef CONFIG_DEBUG_DISCRETE +#endif + +#ifdef CONFIG_DEBUG_DISCRETE +# define ddbg lldbg +# ifdef CONFIG_DEBUG_VERBOSE +# define dvdbg lldbg +# else +# define dvdbg(x...) +# endif +#else +# define ddbg(x...) +# define dvdbg(x...) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure provides the state of one LED driver */ + +struct userled_upperhalf_s +{ + /* Saved binding to the lower half LED driver */ + + FAR const struct userled_lowerhalf_s *lu_lower; + + userled_set_t lu_supported; /* The set of supported LEDs */ + userled_set_t lu_ledset; /* Current state of LEDs */ + sem_t lu_exclsem; /* Supports exclusive access to the device */ + + /* The following is a singly linked list of open references to the + * LED device. + */ + + FAR struct userled_open_s *lu_open; +}; + +/* This structure describes the state of one open LED driver instance */ + +struct userled_open_s +{ + /* Supports a singly linked list */ + + FAR struct userled_open_s *bo_flink; + + /* The following will be true if we are closing */ + + volatile bool bo_closing; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Semaphore helpers */ + +static inline int userled_takesem(sem_t *sem); +#define userled_givesem(s) sem_post(s); + +/* Character driver methods */ + +static int userled_open(FAR struct file *filep); +static int userled_close(FAR struct file *filep); +static ssize_t userled_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int userled_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations userled_fops = +{ + userled_open, /* open */ + userled_close, /* close */ + 0, /* read */ + userled_write, /* write */ + 0, /* seek */ + userled_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_takesem + ****************************************************************************/ + +static inline int userled_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + +/**************************************************************************** + * Name: userled_open + ****************************************************************************/ + +static int userled_open(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct userled_upperhalf_s *priv; + FAR struct userled_open_s *opriv; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct userled_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = userled_takesem(&priv->lu_exclsem); + if (ret < 0) + { + dvdbg("ERROR: userled_takesem failed: %d\n", ret); + return ret; + } + + /* Allocate a new open structure */ + + opriv = (FAR struct userled_open_s *)kmm_zalloc(sizeof(struct userled_open_s)); + if (!opriv) + { + dvdbg("ERROR: Failled to allocate open structure\n"); + ret = -ENOMEM; + goto errout_with_sem; + } + + /* Attach the open structure to the device */ + + opriv->bo_flink = priv->lu_open; + priv->lu_open = opriv; + + /* Attach the open structure to the file structure */ + + filep->f_priv = (FAR void *)opriv; + ret = OK; + +errout_with_sem: + userled_givesem(&priv->lu_exclsem); + return ret; +} + +/**************************************************************************** + * Name: userled_close + ****************************************************************************/ + +static int userled_close(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct userled_upperhalf_s *priv; + FAR struct userled_open_s *opriv; + FAR struct userled_open_s *curr; + FAR struct userled_open_s *prev; + irqstate_t flags; + bool closing; + int ret; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct userled_upperhalf_s *)inode->i_private; + + /* Handle an improbable race conditions with the following atomic test + * and set. + * + * This is actually a pretty feeble attempt to handle this. The + * improbable race condition occurs if two different threads try to + * close the LED driver at the same time. The rule: don't do + * that! It is feeble because we do not really enforce stale pointer + * detection anyway. + */ + + flags = irqsave(); + closing = opriv->bo_closing; + opriv->bo_closing = true; + irqrestore(flags); + + if (closing) + { + /* Another thread is doing the close */ + + return OK; + } + + /* Get exclusive access to the driver structure */ + + ret = userled_takesem(&priv->lu_exclsem); + if (ret < 0) + { + dvdbg("ERROR: userled_takesem failed: %d\n", ret); + return ret; + } + + /* Find the open structure in the list of open structures for the device */ + + for (prev = NULL, curr = priv->lu_open; + curr && curr != opriv; + prev = curr, curr = curr->bo_flink); + + DEBUGASSERT(curr); + if (!curr) + { + dvdbg("ERROR: Failed to find open entry\n"); + ret = -ENOENT; + goto errout_with_exclsem; + } + + /* Remove the structure from the device */ + + if (prev) + { + prev->bo_flink = opriv->bo_flink; + } + else + { + priv->lu_open = opriv->bo_flink; + } + + /* And free the open structure */ + + kmm_free(opriv); + ret = OK; + +errout_with_exclsem: + userled_givesem(&priv->lu_exclsem); + return ret; +} + +/**************************************************************************** + * Name: userled_write + ****************************************************************************/ + +static ssize_t userled_write(FAR struct file *filep, FAR const char *buffer, + size_t len) +{ + FAR struct inode *inode; + FAR struct userled_upperhalf_s *priv; + FAR const struct userled_lowerhalf_s *lower; + userled_set_t ledset; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct userled_upperhalf_s *)inode->i_private; + + /* Make sure that the buffer is sufficiently large to hold at least one + * complete sample. + * + * REVISIT: Should also check buffer alignment. + */ + + if (len < sizeof(userled_set_t)) + { + dvdbg("ERROR: buffer too small: %lu\n", (unsigned long)len); + return -EINVAL; + } + + /* Get the LED set to write. + * REVISIT: if sizeof(userled_set_t) > 1, then we will have to address + * some buffer alignment issues. + */ + + DEBUGASSERT(buffer != NULL); + ledset = *(userled_set_t *)buffer; + + /* Get exclusive access to the driver structure */ + + ret = userled_takesem(&priv->lu_exclsem); + if (ret < 0) + { + dvdbg("ERROR: userled_takesem failed: %d\n", ret); + return ret; + } + + /* Read and return the current state of the LEDs */ + + lower = priv->lu_lower; + DEBUGASSERT(lower && lower->ll_ledset); + lower->ll_ledset(lower, ledset); + + userled_givesem(&priv->lu_exclsem); + return (ssize_t)sizeof(userled_set_t); +} + +/**************************************************************************** + * Name: userled_ioctl + ****************************************************************************/ + +static int userled_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct userled_upperhalf_s *priv; + FAR const struct userled_lowerhalf_s *lower; + int ret; + + DEBUGASSERT(filep != NULL && filep->f_priv != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + priv = (FAR struct userled_upperhalf_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = userled_takesem(&priv->lu_exclsem); + if (ret < 0) + { + dvdbg("ERROR: userled_takesem failed: %d\n", ret); + return ret; + } + + /* Handle the ioctl command */ + + ret = -EINVAL; + switch (cmd) + { + /* Command: ULEDIOC_SUPPORTED + * Description: Report the set of LEDs supported by the hardware; + * Argument: A pointer to writeable userled_set_t value in which to + * return the set of supported LEDs. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + + case ULEDIOC_SUPPORTED: + { + FAR userled_set_t *supported = (FAR userled_set_t *)((uintptr_t)arg); + + /* Verify that a non-NULL pointer was provided */ + + if (supported) + { + *supported = priv->lu_supported; + ret = OK; + } + } + break; + + /* Command: ULEDIOC_SETLED + * Description: Set the state of one LED. + * Argument: A read-only pointer to an instance of struct userled_s + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + + case ULEDIOC_SETLED: + { + FAR struct userled_s *userled = (FAR struct userled_s *)((uintptr_t)arg); + int led; + bool ledon; + + /* Verify that a non-NULL pointer was provided */ + + if (userled) + { + led = userled->ul_led; + ledon = userled->ul_on; + + /* Check that a valid LED is being set */ + + if (led < 8 * sizeof(userled_set_t) && + (priv->lu_supported & (1 << led)) != 0) + { + /* Update the LED state */ + + if (ledon) + { + priv->lu_ledset |= (1 << led); + } + else + { + priv->lu_ledset &= ~(1 << led); + } + + /* Set the LED state */ + + lower = priv->lu_lower; + DEBUGASSERT(lower != NULL && lower->ll_led != NULL); + lower->ll_led(lower, led, ledon); + ret = OK; + } + } + } + break; + + /* Command: ULEDIOC_SETALL + * Description: Set the state of all LEDs. + * Argument: A value of type userled_set_t cast to unsigned long + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + + case ULEDIOC_SETALL: + { + userled_set_t ledset = (userled_set_t)((uintptr_t)arg); + + /* Verify that a valid LED set was provided */ + + if ((ledset & priv->lu_supported) == ledset) + { + /* Update the LED state */ + + priv->lu_ledset = ledset; + + /* Set the new LED state */ + + lower = priv->lu_lower; + DEBUGASSERT(lower != NULL && lower->ll_led != NULL); + lower->ll_ledset(lower, ledset); + ret = OK; + } + } + break; + + /* Command: ULEDIOC_GETALL + * Description: Get the state of one LED. + * Argument: A write-able pointer to a userled_set_t memory location in + * which to return the LED state. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + + case ULEDIOC_GETALL: + { + FAR userled_set_t *ledset = (FAR userled_set_t *)((uintptr_t)arg); + + /* Verify that a non-NULL pointer was provided */ + + if (ledset) + { + *ledset = priv->lu_ledset; + ret = OK; + } + } + break; + + default: + dvdbg("ERROR: Unrecognized command: %ld\n", cmd); + ret = -ENOTTY; + break; + } + + userled_givesem(&priv->lu_exclsem); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_register + * + * Description: + * Bind the lower half LED driver to an instance of the upper half + * LED driver and register the composite character driver as the + * specified device. + * + * Input Parameters: + * devname - The name of the LED device to be registered. + * This should be a string of the form "/dev/ledN" where N is the the + * minor device number. + * lower - An instance of the platform-specific LED lower half driver. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int userled_register(FAR const char *devname, + FAR const struct userled_lowerhalf_s *lower) +{ + FAR struct userled_upperhalf_s *priv; + int ret; + + DEBUGASSERT(devname && lower); + + /* Allocate a new LED driver instance */ + + priv = (FAR struct userled_upperhalf_s *) + kmm_zalloc(sizeof(struct userled_upperhalf_s)); + + if (!priv) + { + dvdbg("ERROR: Failed to allocate device structure\n"); + return -ENOMEM; + } + + /* Initialize the new LED driver instance */ + + priv->lu_lower = lower; + sem_init(&priv->lu_exclsem, 0, 1); + + DEBUGASSERT(lower && lower->ll_supported); + priv->lu_supported = lower->ll_supported(lower); + + DEBUGASSERT(lower && lower->ll_ledset); + priv->lu_ledset = 0; + lower->ll_ledset(lower, priv->lu_ledset); + + /* And register the LED driver */ + + ret = register_driver(devname, &userled_fops, 0666, priv); + if (ret < 0) + { + dvdbg("ERROR: register_driver failed: %d\n", ret); + goto errout_with_priv; + } + + return OK; + +errout_with_priv: + sem_destroy(&priv->lu_exclsem); + kmm_free(priv); + return ret; +} diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index e132870fb9..ebf00232ee 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -354,7 +354,7 @@ config BUTTONS_LOWER will undefine __KERNEL__ before included board.h. If your board does not meet these requirements, then the - board_lower.c file can still be copied to your your + button_lower.c file can still be copied to your your board src/ directory and modified for your specific board requirements. diff --git a/include/nuttx/board.h b/include/nuttx/board.h index ab0511dff1..c603f40441 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -101,6 +101,7 @@ #include #include +#include #include diff --git a/include/nuttx/discrete/userled.h b/include/nuttx/discrete/userled.h new file mode 100644 index 0000000000..7d80e1c5a6 --- /dev/null +++ b/include/nuttx/discrete/userled.h @@ -0,0 +1,185 @@ +/************************************************************************************ + * include/nuttx/input/userled.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __INCLUDE_NUTTX_DISCRETE_USERLED_H +#define __INCLUDE_NUTTX_DISCRETE_USERLED_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* ioctl commands */ + +/* Command: ULEDIOC_SUPPORTED + * Description: Report the set of LEDs supported by the hardware; + * Argument: A pointer to writeable userled_set_t value in which to + * return the set of supported LEDs. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define ULEDIOC_SUPPORTED _ULEDIOC(0x0001) + +/* Command: ULEDIOC_SETLED + * Description: Set the state of one LED. + * Argument: A read-only pointer to an instance of struct userled_s + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define ULEDIOC_SETLED _ULEDIOC(0x0002) + +/* Command: ULEDIOC_SETALL + * Description: Set the state of all LEDs. + * Argument: A value of type userled_set_t cast to unsigned long + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define ULEDIOC_SETALL _ULEDIOC(0x0003) + +/* Command: ULEDIOC_GETALL + * Description: Get the state of one LED. + * Argument: A write-able pointer to a userled_set_t memory location in + * which to return the LED state. + * Return: Zero (OK) on success. Minus one will be returned on failure + * with the errno value set appropriately. + */ + +#define ULEDIOC_GETALL _ULEDIOC(0x0004) + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* This type is a bit set that contains the state of all LEDs as defined + * in arch/board/board.h. This is the value that is returned when reading + * from or writing to the LED driver. + */ + +typedef uint8_t userled_set_t; + +/* A reference to this structure is provided with the ULEDIOC_SETLED IOCTL + * command and describes the LED to be set and the new value of the LED. + * The encoding of LEDs is provided in the board-specific board.h header + * file. + */ + +struct userled_s +{ + uint8_t ul_led; /* Identifies the LED */ + bool ul_on; /* The LED state. true: ON; false: OFF */ +}; + +/* The user LED driver is a two-part driver: + * + * 1) A common upper half driver that provides the common user interface to + * the LEDs, + * 2) Platform-specific lower half drivers that provide the interface + * between the common upper half and the platform discrete LED outputs. + * + * This structure defines the interface between an instance of the lower + * half driver and the common upper half driver. Such an instance is + * passed to the upper half driver when the driver is initialized, binding + * the upper and lower halves into one driver. + */ + +struct userled_lowerhalf_s +{ + /* Return the set of LEDs supported by the board */ + + CODE userled_set_t (*ll_supported)(FAR const struct userled_lowerhalf_s *lower); + + /* Set the current state of one LED */ + + CODE void (*ll_led)(FAR const struct userled_lowerhalf_s *lower, + int led, bool ledon); + + /* Set the state of all LEDs */ + + CODE void (*ll_ledset)(FAR const struct userled_lowerhalf_s *lower, + userled_set_t ledset); +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_register + * + * Description: + * Bind the lower half LED driver to an instance of the upper half + * LED driver and register the composite character driver as the + * specified device. + * + * Input Parameters: + * devname - The name of the LED device to be registered. + * This should be a string of the form "/dev/ledN" where N is the the + * minor device number. + * lower - An instance of the platform-specific LED lower half driver. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int userled_register(FAR const char *devname, + FAR const struct userled_lowerhalf_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_DISCRETE_USERLED_H */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 6814787005..2e0d7a1aae 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -78,8 +78,12 @@ #define _RELAYBASE (0x1900) /* Relay devices ioctl commands */ #define _CANBASE (0x1a00) /* CAN ioctl commands */ #define _BTNBASE (0x1b00) /* Button ioctl commands */ -#define _ZCBASE (0x1c00) /* Zero Cross ioctl commands */ -#define _BOARDBASE (0x1d00) /* boardctl ioctl commands */ +#define _ULEDBASE (0x1c00) /* User LED ioctl commands */ +#define _ZCBASE (0x1d00) /* Zero Cross ioctl commands */ + +/* boardctl commands share the same number space */ + +#define _BOARDBASE (0xff00) /* boardctl commands */ /* Macros used to manage ioctl commands */ @@ -339,11 +343,17 @@ #define _CANIOC(nr) _IOC(_CANBASE,nr) /* Button driver ioctl definitions ******************************************/ -/* (see nuttx/can.h */ +/* (see nuttx/input/buttons.h */ #define _BTNIOCVALID(c) (_IOC_TYPE(c)==_BTNBASE) #define _BTNIOC(nr) _IOC(_BTNBASE,nr) +/* User LED driver ioctl definitions ****************************************/ +/* (see nuttx/discrete/userled.h */ + +#define _ULEDIOCVALID(c) (_IOC_TYPE(c)==_ULEDBASE) +#define _ULEDIOC(nr) _IOC(_ULEDBASE,nr) + /* Zero Cross driver ioctl definitions **************************************/ /* (see nuttx/include/sensor/zerocross.h */ -- GitLab From fc91ded8154cada5e2dea7f7e404e0a517cf7692 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 14:57:22 -0600 Subject: [PATCH 248/858] Add support for a general user LED lower-half driver --- ChangeLog | 6 ++ drivers/discrete/Kconfig | 2 +- drivers/discrete/userled_lower.c | 141 +++++++++++++++++++++++++++++++ drivers/discrete/userled_upper.c | 2 +- drivers/input/button_upper.c | 2 +- include/nuttx/discrete/userled.h | 16 ++++ 6 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 drivers/discrete/userled_lower.c diff --git a/ChangeLog b/ChangeLog index 0297310651..246d913890 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11052,4 +11052,10 @@ * Rename ioexpander/ directories to discrete/. This expands the namespace so that other discrete I/O drivers can reside there as well (2015-11-01). + * drivers/discrete/userled_upper.c and include/discrete/userled.h: Add + a generic character driver that may be used by applications to write + to board LEDs (2015-11-01). + * drivers/discrete/userled_lower.c: Add a generic lower-half user LED + driver that may be used by any board that supports the standard + board user LED interfaces (2015-11-01). diff --git a/drivers/discrete/Kconfig b/drivers/discrete/Kconfig index 9bd4492a9d..787c6e541a 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/discrete/Kconfig @@ -65,7 +65,7 @@ config USERLED_LOWER 1. The board implementation must provide the LED interfaces as defined in include/nuttx/board.h 2. The board.h header file must provide the definition - NUM_USERLED, and + BOARD_NLEDS, and 3. The board.h header file must not include any other header files that are not accessibble in this context (such as those in arch//src/) UNLESS those diff --git a/drivers/discrete/userled_lower.c b/drivers/discrete/userled_lower.c new file mode 100644 index 0000000000..52a0daa275 --- /dev/null +++ b/drivers/discrete/userled_lower.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * drivers/discrete/userled_lower.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#undef __KERNEL__ +#include + +#if CONFIG_USERLED_LOWER + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static userled_set_t userled_supported(FAR const struct userled_lowerhalf_s *lower); +static void userled_led(FAR const struct userled_lowerhalf_s *lower, +static void userled_ledset(FAR const struct userled_lowerhalf_s *lower, + userled_set_t ledset); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This is the user LED lower half driver interface */ + +static const struct userled_lowerhalf_s g_userled_lower = +{ + .ll_supported = userled_supported, + .ll_led = userled_led, + .ll_ledset = userled_ledset, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_supported + * + * Description: + * Return the set of LEDs supported by the board + * + ****************************************************************************/ + +static userled_set_t userled_supported(FAR const struct userled_lowerhalf_s *lower) +{ + ivdbg("BOARD_NLEDS: %02x\n", BOARD_NLEDS); + return (userled_set_t)((1 << BOARD_NLEDS) - 1); +} + +/**************************************************************************** + * Name: userled_led + * + * Description: + * Set the current state of one LED + * + ****************************************************************************/ + +static void userled_led(FAR const struct userled_lowerhalf_s *lower, + int led, bool ledon) +{ + board_userled(led, ledon); +} + +/**************************************************************************** + * Name: userled_led + * + * Description: + * Set the state of all LEDs + * + ****************************************************************************/ + +static void userled_ledset(FAR const struct userled_lowerhalf_s *lower, + userled_set_t ledset) +{ + board_userled_all(ledset); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_lower_initialize + * + * Description: + * Initialize the generic LED lower half driver, bind it and register + * it with the upper half LED driver as devname. + * + ****************************************************************************/ + +int userled_lower_initialize(FAR const char *devname) +{ + board_userled_initialize(); + return userled_register(devname, &g_userled_lower); +} + +#endif /* CONFIG_USERLED_LOWER */ diff --git a/drivers/discrete/userled_upper.c b/drivers/discrete/userled_upper.c index 71030ea734..49c3188f97 100644 --- a/drivers/discrete/userled_upper.c +++ b/drivers/discrete/userled_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/button_upper.c + * drivers/discrete/userled_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/drivers/input/button_upper.c b/drivers/input/button_upper.c index deb9492fba..81e2157039 100644 --- a/drivers/input/button_upper.c +++ b/drivers/input/button_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/button_upper.c + * drivers/input/button_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/include/nuttx/discrete/userled.h b/include/nuttx/discrete/userled.h index 7d80e1c5a6..c14fa609de 100644 --- a/include/nuttx/discrete/userled.h +++ b/include/nuttx/discrete/userled.h @@ -43,6 +43,8 @@ #include #include +#ifdef CONFIG_ARCH_HAVE_LEDS + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -177,9 +179,23 @@ extern "C" int userled_register(FAR const char *devname, FAR const struct userled_lowerhalf_s *lower); +/**************************************************************************** + * Name: userled_lower_initialize + * + * Description: + * Initialize the generic LED lower half driver, bind it and register + * it with the upper half LED driver as devname. + * + ****************************************************************************/ + +#ifdef CONFIG_USERLED_LOWER +int userled_lower_initialize(FAR const char *devname); +#endif + #undef EXTERN #ifdef __cplusplus } #endif +#endif /* CONFIG_ARCH_HAVE_LEDS */ #endif /* __INCLUDE_NUTTX_DISCRETE_USERLED_H */ -- GitLab From 7041ba80715dc37c0363e6ce29824e0588e67108 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 15:07:58 -0600 Subject: [PATCH 249/858] Add comments to Make.defs file --- drivers/discrete/Make.defs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/discrete/Make.defs b/drivers/discrete/Make.defs index 3dc5cfa176..c45b869f54 100644 --- a/drivers/discrete/Make.defs +++ b/drivers/discrete/Make.defs @@ -46,6 +46,10 @@ ifeq ($(CONFIG_USERLED_LOWER),y) endif endif +# Include buttion driver +# Although it makes sense for button drivers to be in the discrete driver +# directory, the button drivers current reside in the input dirver directory. + # Check if I/O expander support is enabled ifeq ($(CONFIG_IOEXPANDER),y) -- GitLab From e8c2466c1cecf22035976a2dd577dfc67f9ea373 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Sun, 1 Nov 2015 17:15:12 -0500 Subject: [PATCH 250/858] PWM: Add support for multiple output channels per timer --- drivers/Kconfig | 25 ++++++++++++ drivers/pwm.c | 99 +++++++++++++++++++++++++++------------------ include/nuttx/pwm.h | 27 +++++++++---- 3 files changed, 104 insertions(+), 47 deletions(-) diff --git a/drivers/Kconfig b/drivers/Kconfig index 263001d9cc..f223e1c795 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -139,6 +139,10 @@ config ARCH_HAVE_PWM_PULSECOUNT bool default n +config ARCH_HAVE_PWM_MULTICHAN + bool + default n + menuconfig PWM bool "PWM Driver Support" default n @@ -147,6 +151,7 @@ menuconfig PWM See include/nuttx/pwm.h for further PWM driver information. if PWM + config PWM_PULSECOUNT bool "PWM Pulse Count Support" default n @@ -157,6 +162,26 @@ config PWM_PULSECOUNT hardware will support a fixed pulse count, then this configuration should be set to enable the capability. +config PWM_MULTICHAN + bool "PWM Multiple Output Channel Support" + default n + depends on ARCH_HAVE_PWM_MULTICHAN + depends on !PWM_PULSECOUNT + ---help--- + Enables support for multiple output channels per timer. + +if PWM_MULTICHAN + +config PWM_NCHANNELS + int "Number of Output Channels Per Timer" + default 1 + range 1 4 + ---help--- + Specifies the number of output channels per timer. Each timer + may support fewer output channels than this value. + +endif # PWM_MULTICHAN + endif # PWM config ARCH_HAVE_I2CRESET diff --git a/drivers/pwm.c b/drivers/pwm.c index 9071ab0543..3903bdf4fa 100644 --- a/drivers/pwm.c +++ b/drivers/pwm.c @@ -107,11 +107,17 @@ struct pwm_upperhalf_s * Private Function Prototypes ****************************************************************************/ +static void pwm_dump(FAR const char *msg, + FAR const struct pwm_info_s *info, + bool started); static int pwm_open(FAR struct file *filep); static int pwm_close(FAR struct file *filep); -static ssize_t pwm_read(FAR struct file *filep, FAR char *buffer, size_t buflen); -static ssize_t pwm_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags); +static ssize_t pwm_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t pwm_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int pwm_start(FAR struct pwm_upperhalf_s *upper, + unsigned int oflags); static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** @@ -135,13 +141,43 @@ static const struct file_operations g_pwmops = * Private Functions ****************************************************************************/ -/************************************************************************************ +/**************************************************************************** + * Name: pwm_dump + ****************************************************************************/ + +static void pwm_dump(FAR const char *msg, FAR const struct pwm_info_s *info, + bool started) +{ +#ifdef CONFIG_PWM_MULTICHAN + int i; +#endif + + pwmvdbg("%s: frequency: %d", msg, info->frequency); + +#ifdef CONFIG_PWM_MULTICHAN + for (i = 0; i < CONFIG_PWM_NCHANNELS; i++) + { + pwmvdbg(" channel: %d duty: %08x", + info->channels[i].channel, info->channels[i].duty); + } +#else + pwmvdbg(" duty: %08x", info->duty); +#endif + +#ifdef CONFIG_PWM_PULSECOUNT + pwmvdbg(" count: %d\n", info->count); +#endif + + pwmvdbg(" started: %d\n", started); +} + +/**************************************************************************** * Name: pwm_open * * Description: * This function is called whenever the PWM device is opened. * - ************************************************************************************/ + ****************************************************************************/ static int pwm_open(FAR struct file *filep) { @@ -205,13 +241,13 @@ errout: return ret; } -/************************************************************************************ +/**************************************************************************** * Name: pwm_close * * Description: * This function is called when the PWM device is closed. * - ************************************************************************************/ + ****************************************************************************/ static int pwm_close(FAR struct file *filep) { @@ -262,41 +298,43 @@ errout: return ret; } -/************************************************************************************ +/**************************************************************************** * Name: pwm_read * * Description: * A dummy read method. This is provided only to satisfy the VFS layer. * - ************************************************************************************/ + ****************************************************************************/ -static ssize_t pwm_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +static ssize_t pwm_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) { /* Return zero -- usually meaning end-of-file */ return 0; } -/************************************************************************************ +/**************************************************************************** * Name: pwm_write * * Description: * A dummy write method. This is provided only to satisfy the VFS layer. * - ************************************************************************************/ + ****************************************************************************/ -static ssize_t pwm_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) +static ssize_t pwm_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) { return 0; } -/************************************************************************************ +/**************************************************************************** * Name: pwm_start * * Description: * Handle the PWMIOC_START ioctl command * - ************************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_PWM_PULSECOUNT static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags) @@ -397,13 +435,13 @@ static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags) } #endif -/************************************************************************************ +/**************************************************************************** * Name: pwm_ioctl * * Description: * The standard ioctl method. This is where ALL of the PWM work is done. * - ************************************************************************************/ + ****************************************************************************/ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { @@ -441,13 +479,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) FAR const struct pwm_info_s *info = (FAR const struct pwm_info_s *)((uintptr_t)arg); DEBUGASSERT(info != NULL && lower->ops->start != NULL); -#ifdef CONFIG_PWM_PULSECOUNT - pwmvdbg("PWMIOC_SETCHARACTERISTICS frequency: %d duty: %08x count: %d started: %d\n", - info->frequency, info->duty, info->count, upper->started); -#else - pwmvdbg("PWMIOC_SETCHARACTERISTICS frequency: %d duty: %08x started: %d\n", - info->frequency, info->duty, upper->started); -#endif + pwm_dump("PWMIOC_SETCHARACTERISTICS", info, upper->started); /* Save the pulse train characteristics */ @@ -480,13 +512,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) memcpy(info, &upper->info, sizeof(struct pwm_info_s)); -#ifdef CONFIG_PWM_PULSECOUNT - pwmvdbg("PWMIOC_GETCHARACTERISTICS frequency: %d duty: %08x count: %d\n", - info->frequency, info->duty, info->count); -#else - pwmvdbg("PWMIOC_GETCHARACTERISTICS frequency: %d duty: %08x\n", - info->frequency, info->duty); -#endif + pwm_dump("PWMIOC_GETCHARACTERISTICS", info, upper->started); } break; @@ -498,14 +524,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_START: { -#ifdef CONFIG_PWM_PULSECOUNT - pwmvdbg("PWMIOC_START frequency: %d duty: %08x count: %d started: %d\n", - upper->info.frequency, upper->info.duty, upper->info.count, - upper->started); -#else - pwmvdbg("PWMIOC_START frequency: %d duty: %08x started: %d\n", - upper->info.frequency, upper->info.duty, upper->started); -#endif + pwm_dump("PWMIOC_START", &upper->info, upper->started); DEBUGASSERT(lower->ops->start != NULL); /* Start the pulse train */ @@ -531,7 +550,7 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) #ifdef CONFIG_PWM_PULSECOUNT if (upper->waiting) { - upper->waiting = FALSE; + upper->waiting = false; } #endif } diff --git a/include/nuttx/pwm.h b/include/nuttx/pwm.h index 8abb51e713..f77cbee23a 100644 --- a/include/nuttx/pwm.h +++ b/include/nuttx/pwm.h @@ -122,17 +122,30 @@ /**************************************************************************** * Public Types ****************************************************************************/ + +#ifdef CONFIG_PWM_MULTICHAN +struct pwm_chan_s +{ + ub16_t duty; + uint8_t channel; +}; +#endif + /* This structure describes the characteristics of the pulsed output */ struct pwm_info_s { - uint32_t frequency; /* Frequency of the pulse train */ - ub16_t duty; /* Duty of the pulse train, "1"-to-"0" duration. - * Maximum: 65535/65536 (0x0000ffff) - * Minimum: 1/65536 (0x00000001) */ -#ifdef CONFIG_PWM_PULSECOUNT - uint32_t count; /* The number of pulse to generate. 0 means to - * generate an indefinite number of pulses */ + uint32_t frequency; /* Frequency of the pulse train */ +#ifdef CONFIG_PWM_MULTICHAN + struct pwm_chan_s channels[CONFIG_PWM_NCHANNELS]; +#else + ub16_t duty; /* Duty of the pulse train, "1"-to-"0" duration. + * Maximum: 65535/65536 (0x0000ffff) + * Minimum: 1/65536 (0x00000001) */ +# ifdef CONFIG_PWM_PULSECOUNT + uint32_t count; /* The number of pulse to generate. 0 means to + * generate an indefinite number of pulses */ +# endif #endif }; -- GitLab From 6cfad176025f3cb3f0d882c2bdd9611fb74d938d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Nov 2015 17:45:48 -0600 Subject: [PATCH 251/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 7eca3dcc8f..7526685e83 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7eca3dcc8f3624c3e0fe383e1d3f047e3d8c4a83 +Subproject commit 7526685e83229a7249d739b15bb1844eee9fce8e diff --git a/configs b/configs index b3ac585690..1433eb46e1 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b3ac585690e98fc83d1470de900adba112157f49 +Subproject commit 1433eb46e1c86d422992f7b2bf06eda0b3734f8c -- GitLab From da8950fe5bd7857b9aec8ceb32866b10244b9727 Mon Sep 17 00:00:00 2001 From: Lok Date: Tue, 3 Nov 2015 07:28:46 -0600 Subject: [PATCH 252/858] Fix an error in clock_timespec_subtract --- ChangeLog | 3 ++- arch | 2 +- sched/clock/clock_timespec_subtract.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 246d913890..f02f9dc31a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11058,4 +11058,5 @@ * drivers/discrete/userled_lower.c: Add a generic lower-half user LED driver that may be used by any board that supports the standard board user LED interfaces (2015-11-01). - + * sched/clock: Fix error in clock_timespec_subtract(). Found by Lok + (2015-11-03). diff --git a/arch b/arch index 7526685e83..b763efbe64 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7526685e83229a7249d739b15bb1844eee9fce8e +Subproject commit b763efbe64b84ff1cefdd428c7a3d7b7b69f1c9b diff --git a/sched/clock/clock_timespec_subtract.c b/sched/clock/clock_timespec_subtract.c index c47ea35562..c02dc35538 100644 --- a/sched/clock/clock_timespec_subtract.c +++ b/sched/clock/clock_timespec_subtract.c @@ -83,7 +83,7 @@ void clock_timespec_subtract(FAR const struct timespec *ts1, } else { - sec = ts1->tv_sec + ts2->tv_sec; + sec = ts1->tv_sec - ts2->tv_sec; if (ts1->tv_nsec < ts2->tv_nsec) { nsec = (ts1->tv_nsec + NSEC_PER_SEC) - ts2->tv_nsec; -- GitLab From c6fc285277f1ce920816af34ed62c7d1f4687edd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 3 Nov 2015 10:52:58 -0600 Subject: [PATCH 253/858] CAN: Add a new CAN upper-half interface, can_txready(), that can be used to break deadlock conditions in certain CAN hardware that supports queuing of TX messages --- ChangeLog | 10 +++++ arch | 2 +- drivers/Kconfig | 48 +++++++++++++++++++++++ drivers/can.c | 95 ++++++++++++++++++++++++++++++++++++++++++++- include/nuttx/can.h | 54 ++++++++++++++++++++++++++ 5 files changed, 206 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f02f9dc31a..b03be3d6bf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11060,3 +11060,13 @@ board user LED interfaces (2015-11-01). * sched/clock: Fix error in clock_timespec_subtract(). Found by Lok (2015-11-03). + * drivers/can.c and include/nuttx/can.h: Fix a problem in the CAN + upper-half driver that occurs only for CAN hardware that support a + H/W FIFO of outgoing CAN messages. In this case, there can be a + hang condition if both the H/W and S/W FIFOs are both full. In that + case, there may be no event to awaken the upper half driver. Add a + new (conditional) CAN upper half interface called can_txready() that + can be used by the lower half driver to avoid this hang condition + (2015-11-03). + * arch/arm/src/samv7: Add a call to can_txready() to the MCAN driver + (2015-11-03). diff --git a/arch b/arch index b763efbe64..309bd15763 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b763efbe64b84ff1cefdd428c7a3d7b7b69f1c9b +Subproject commit 309bd15763dfa0d7e803811216c3b17262255de6 diff --git a/drivers/Kconfig b/drivers/Kconfig index 098c21164d..2ead84ff1f 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -125,6 +125,54 @@ config CAN_NPENDINGRTR ---help--- The size of the list of pending RTR requests. Default: 4 +config CAN_TXREADY + bool "can_txready interface" + default n + ---help--- + This selection enables the can_txready() interface. This interface + is needed only for CAN hardware that supports queing of outgoing + messages in a H/W FIFO. + + The CAN upper half driver also supports a queue of output messages + in a S/W FIFO. Messages are added to that queue when when + can_write() is called and removed from the queue in can_txdone() + when each TX message is complete. + + After each message is added to the S/W FIFO, the CAN upper half + driver will attempt to send the message by calling into the lower + half driver. That send will not be performed if the lower half + driver is busy, i.e., if dev_txready() returns false. In that + case, the number of messages in the S/W FIFO can grow. If the + S/W FIFO becomes full, then can_write() will wait for space in + the S/W FIFO. + + If the CAN hardware does not support a H/W FIFO then busy means + that the hardware is actively sending the message and is + guaranteed to become non busy (i.e, dev_txready()) when the + send transfer completes and can_txdone() is called. So the call + to can_txdone() means that the transfer has completed and also + that the hardware is ready to accept another transfer. + + If the CAN hardware supports a H/W FIFO, can_txdone() is not + called when the tranfer is complete, but rather when the + transfer is queued in the H/W FIFO. When the H/W FIFO becomes + full, then dev_txready() will report false and the number of + queued messages in the S/W FIFO will grow. + + There is no mechanism in this case to inform the upper half + driver when the hardware is again available, when there is + again space in the H/W FIFO. can_txdone() will not be called + again. If the S/W FIFO becomes full, then the upper half + driver will wait for space to become available, but there is + no event to awaken it and the driver will hang. + + Enabling this feature adds support for the can_txready() + interface. This function is called from the lower half + driver's CAN interrupt handler each time a TX transfer + completes. This is a sure indication that the H/W FIFO is + no longer full. can_txready() will then awaken the + can_write() logic and the hang condition is avoided. + config CAN_LOOPBACK bool "CAN loopback mode" default n diff --git a/drivers/can.c b/drivers/can.c index 66ba2b467e..3548729388 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -554,7 +554,7 @@ static int can_xmit(FAR struct can_dev_s *dev) DEBUGASSERT(dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail); /* Increment the FIFO queue index before sending (because dev_send() - * might call can_txdone(). + * might call can_txdone()). */ tmpndx = dev->cd_xmit.tx_queue; @@ -634,7 +634,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, { /* The transmit FIFO is full -- was non-blocking mode selected? */ - if (filep->f_oflags & O_NONBLOCK) + if ((filep->f_oflags & O_NONBLOCK) != 0) { if (nsent == 0) { @@ -1007,6 +1007,12 @@ int can_txdone(FAR struct can_dev_s *dev) if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { + /* The tx_queue index is incremented each time can_xmit() queues + * the transmission. When can_txdone() is called, the tx_queue + * index should always have been advanced beyond the current tx_head + * index. + */ + DEBUGASSERT(dev->cd_xmit.tx_head != dev->cd_xmit.tx_queue); /* Remove the message at the head of the xmit FIFO */ @@ -1037,4 +1043,89 @@ int can_txdone(FAR struct can_dev_s *dev) return ret; } +/**************************************************************************** + * Name: can_txready + * + * Description: + * Called from the CAN interrupt handler at the completion of a send + * operation. This interface is needed only for CAN hardware that + * supports queing of outgoing messages in a H/W FIFO. + * + * The CAN upper half driver also supports a queue of output messages in a + * S/W FIFO. Messages are added to that queue when when can_write() is + * called and removed from the queue in can_txdone() when each TX message + * is complete. + * + * After each message is added to the S/W FIFO, the CAN upper half driver + * will attempt to send the message by calling into the lower half driver. + * That send will not be performed if the lower half driver is busy, i.e., + * if dev_txready() returns false. In that case, the number of messages in + * the S/W FIFO can grow. If the S/W FIFO becomes full, then can_write() + * will wait for space in the S/W FIFO. + * + * If the CAN hardware does not support a H/W FIFO then busy means that + * the hardware is actively sending the message and is guaranteed to + * become non-busy (i.e, dev_txready()) when the send transfer completes + * and can_txdone() is called. So the call to can_txdone() means that the + * transfer has completed and also that the hardware is ready to accept + * another transfer. + * + * If the CAN hardware supports a H/W FIFO, can_txdone() is not called + * when the tranfer is complete, but rather when the transfer is queued in + * the H/W FIFO. When the H/W FIFO becomes full, then dev_txready() will + * report false and the number of queued messages in the S/W FIFO will grow. + * + * There is no mechanism in this case to inform the upper half driver when + * the hardware is again available, when there is again space in the H/W + * FIFO. can_txdone() will not be called again. If the S/W FIFO becomes + * full, then the upper half driver will wait for space to become + * available, but there is no event to awaken it and the driver will hang. + * + * Enabling this feature adds support for the can_txready() interface. + * This function is called from the lower half driver's CAN interrupt + * handler each time a TX transfer completes. This is a sure indication + * that the H/W FIFO is no longer full. can_txready() will then awaken + * the can_write() logic and the hang condition is avoided. + * + * Parameters: + * dev - The specific CAN device + * + * Return: + * OK on success; a negated errno on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_CAN_TXREADY +int can_txready(FAR struct can_dev_s *dev) +{ + int ret = -ENOENT; + + canllvdbg("xmit head: %d queue: %d tail: %d waiters: %d\n", + dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, dev->cd_xmit.tx_tail, + dev->cd_ntxwaiters); + + /* Are there any threads waiting for space in the xmit FIFO? */ + + if (dev->cd_ntxwaiters > 0) + { + /* Verify that the xmit FIFO is not empty. + * REVISIT: This probably should be an assertion since we should only + * be waiting for space in the xmit FIFO if the xmit FIFO is full. + */ + + if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) + { + /* Send the next message in the FIFO, making space in the xmit FIFO */ + + (void)can_xmit(dev); + } + + /* Inform one waiter that new xmit space is available */ + + ret = sem_post(&dev->cd_xmit.tx_sem); + } + + return ret; +} +#endif /* CONFIG_CAN_TXREADY */ #endif /* CONFIG_CAN */ diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 18c06e8416..59f4242e63 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -524,6 +524,60 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, int can_txdone(FAR struct can_dev_s *dev); +/************************************************************************************ + * Name: can_txready + * + * Description: + * Called from the CAN interrupt handler at the completion of a send operation. + * This interface is needed only for CAN hardware that supports queing of + * outgoing messages in a H/W FIFO. + * + * The CAN upper half driver also supports a queue of output messages in a S/W + * FIFO. Messages are added to that queue when when can_write() is called and + * removed from the queue in can_txdone() when each TX message is complete. + * + * After each message is added to the S/W FIFO, the CAN upper half driver will + * attempt to send the message by calling into the lower half driver. That send + * will not be performed if the lower half driver is busy, i.e., if dev_txready() + * returns false. In that case, the number of messages in the S/W FIFO can grow. + * If the S/W FIFO becomes full, then can_write() will wait for space in the + * S/W FIFO. + * + * If the CAN hardware does not support a H/W FIFO then busy means that the + * hardware is actively sending the message and is guaranteed to become non- + * busy (i.e, dev_txready()) when the send transfer completes and can_txdone() + * is called. So the call to can_txdone() means that the transfer has + * completed and also that the hardware is ready to accept another transfer. + * + * If the CAN hardware supports a H/W FIFO, can_txdone() is not called when + * the tranfer is complete, but rather when the transfer is queued in the + * H/W FIFO. When the H/W FIFO becomes full, then dev_txready() will report + * false and the number of queued messages in the S/W FIFO will grow. + * + * There is no mechanism in this case to inform the upper half driver when + * the hardware is again available, when there is again space in the H/W + * FIFO. can_txdone() will not be called again. If the S/W FIFO becomes + * full, then the upper half driver will wait for space to become available, + * but there is no event to awaken it and the driver will hang. + * + * Enabling this feature adds support for the can_txready() interface. + * This function is called from the lower half driver's CAN interrupt + * handler each time a TX transfer completes. This is a sure indication + * that the H/W FIFO is no longer full. can_txready() will then awaken + * the can_write() logic and the hang condition is avoided. + * + * Parameters: + * dev - The specific CAN device + * + * Return: + * OK on success; a negated errno on failure. + * + ************************************************************************************/ + +#ifdef CONFIG_CAN_TXREADY +int can_txready(FAR struct can_dev_s *dev); +#endif + #undef EXTERN #if defined(__cplusplus) } -- GitLab From 4c70fc181a077a73759488b707d31b8ad9cd7e69 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 5 Nov 2015 10:27:47 -0500 Subject: [PATCH 254/858] ADC: Fix forgotten FARs --- include/nuttx/analog/adc.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/nuttx/analog/adc.h b/include/nuttx/analog/adc.h index 3d5aa1fb06..04db97626c 100644 --- a/include/nuttx/analog/adc.h +++ b/include/nuttx/analog/adc.h @@ -139,13 +139,13 @@ struct adc_ops_s struct adc_dev_s { - uint8_t ad_ocount; /* The number of times the device has been opened */ - uint8_t ad_nrxwaiters; /* Number of threads waiting to enqueue a message */ - sem_t ad_closesem; /* Locks out new opens while close is in progress */ - sem_t ad_recvsem; /* Used to wakeup user waiting for space in ad_recv.buffer */ - struct adc_fifo_s ad_recv; /* Describes receive FIFO */ - const struct adc_ops_s *ad_ops; /* Arch-specific operations */ - void *ad_priv; /* Used by the arch-specific logic */ + uint8_t ad_ocount; /* The number of times the device has been opened */ + uint8_t ad_nrxwaiters; /* Number of threads waiting to enqueue a message */ + sem_t ad_closesem; /* Locks out new opens while close is in progress */ + sem_t ad_recvsem; /* Used to wakeup user waiting for space in ad_recv.buffer */ + struct adc_fifo_s ad_recv; /* Describes receive FIFO */ + FAR const struct adc_ops_s *ad_ops; /* Arch-specific operations */ + FAR void *ad_priv; /* Used by the arch-specific logic */ }; /************************************************************************************ -- GitLab From b5a77b9403883b3cbe5fd526f447e211dfd778dc Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 5 Nov 2015 10:38:42 -0500 Subject: [PATCH 255/858] RAMLOG: Fix forgotten FARs --- drivers/syslog/ramlog.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index 299ca4f9e9..b74c95f51c 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -91,7 +91,7 @@ struct ramlog_dev_s */ #ifndef CONFIG_DISABLE_POLL - struct pollfd *rl_fds[CONFIG_RAMLOG_NPOLLWAITERS]; + FAR struct pollfd *rl_fds[CONFIG_RAMLOG_NPOLLWAITERS]; #endif }; @@ -172,7 +172,7 @@ static struct ramlog_dev_s g_sysdev = #ifndef CONFIG_DISABLE_POLL static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, - pollevent_t eventset) + pollevent_t eventset) { FAR struct pollfd *fds; irqstate_t flags; @@ -244,8 +244,8 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch) static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer, size_t len) { - struct inode *inode = filep->f_inode; - struct ramlog_dev_s *priv; + FAR struct inode *inode = filep->f_inode; + FAR struct ramlog_dev_s *priv; ssize_t nread; char ch; int ret; @@ -253,7 +253,7 @@ static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer, size_t len) /* Some sanity checking */ DEBUGASSERT(inode && inode->i_private); - priv = inode->i_private; + priv = (FAR struct ramlog_dev_s *)inode->i_private; /* If the circular buffer is empty, then wait for something to be written * to it. This function may NOT be called from an interrupt handler. @@ -417,8 +417,8 @@ errout_without_sem: static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size_t len) { - struct inode *inode = filep->f_inode; - struct ramlog_dev_s *priv; + FAR struct inode *inode = filep->f_inode; + FAR struct ramlog_dev_s *priv; ssize_t nwritten; char ch; int ret; @@ -426,7 +426,7 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size /* Some sanity checking */ DEBUGASSERT(inode && inode->i_private); - priv = inode->i_private; + priv = (FAR struct ramlog_dev_s *)inode->i_private; /* Loop until all of the bytes have been written. This function may be * called from an interrupt handler! Semaphores cannot be used! @@ -536,7 +536,7 @@ int ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) /* Some sanity checking */ DEBUGASSERT(inode && inode->i_private); - priv = inode->i_private; + priv = (FAR struct ramlog_dev_s *)inode->i_private; /* Get exclusive access to the poll structures */ @@ -657,7 +657,7 @@ int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen) /* Allocate a RAM logging device structure */ priv = (struct ramlog_dev_s *)kmm_zalloc(sizeof(struct ramlog_dev_s)); - if (priv) + if (priv != NULL) { /* Initialize the non-zero values in the RAM logging device structure */ -- GitLab From a314b2ac11975248c4e0c0b0f369040b588f5373 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 5 Nov 2015 10:32:56 -0600 Subject: [PATCH 256/858] ST25FL1: Fix error that was overwriting status --- arch | 2 +- drivers/mtd/st25fl1.c | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/arch b/arch index 309bd15763..f0cd7a9c41 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 309bd15763dfa0d7e803811216c3b17262255de6 +Subproject commit f0cd7a9c410151fb4b8c7737366b501294fc54f2 diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 07228c4e29..2db36adbf5 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -319,6 +319,7 @@ struct st25fl1_dev_s uint8_t sectorshift; /* Log2 of sector size */ uint8_t pageshift; /* Log2 of page size */ FAR uint8_t *cmdbuf; /* Allocated command buffer */ + FAR uint8_t *readbuf; /* Allocated status read buffer */ #ifdef CONFIG_ST25FL1_SECTOR512 uint8_t flags; /* Buffered sector flags */ @@ -518,8 +519,8 @@ static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv) { DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS1, - (FAR void *)&priv->cmdbuf[0], 1)); - return priv->cmdbuf[0]; + (FAR void *)&priv->readbuf[0], 1)); + return priv->readbuf[0]; } /************************************************************************************ @@ -529,8 +530,8 @@ static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv) static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv) { DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS2, - (FAR void *)&priv->cmdbuf[0], 1)); - return priv->cmdbuf[0]; + (FAR void *)&priv->readbuf[0], 1)); + return priv->readbuf[0]; } /************************************************************************************ @@ -540,8 +541,8 @@ static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv) static uint8_t sf25fl1_read_status3(FAR struct st25fl1_dev_s *priv) { DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS3, - (FAR void *)&priv->cmdbuf[0], 1)); - return priv->cmdbuf[0]; + (FAR void *)&priv->readbuf[0], 1)); + return priv->readbuf[0]; } /************************************************************************************ @@ -1450,7 +1451,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) priv->mtd.ioctl = st25fl1_ioctl; priv->qspi = qspi; - /* Allocate a tiny buffer to support DMA command data */ + /* Allocate a 4-byte buffer to support DMA command data */ priv->cmdbuf = (FAR uint8_t *)QSPI_ALLOC(qspi, 4); if (priv->cmdbuf == NULL) @@ -1459,6 +1460,15 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) goto errout_with_priv; } + /* Allocate a one-byte buffer to support DMA status read data */ + + priv->readbuf = (FAR uint8_t *)QSPI_ALLOC(qspi, 1); + if (priv->readbuf == NULL) + { + fdbg("ERROR Failed to allocate read buffer\n"); + goto errout_with_cmdbuf; + } + /* Identify the FLASH chip and get its capacity */ ret = st25fl1_readid(priv); @@ -1467,7 +1477,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) /* Unrecognized! Discard all of that work we just did and return NULL */ fdbg("ERROR Unrecognized QSPI device\n"); - goto errout_with_cmdbuf; + goto errout_with_readbuf; } /* Enable quad mode */ @@ -1493,7 +1503,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) /* Allocation failed! Discard all of that work we just did and return NULL */ fdbg("ERROR: Sector allocation failed\n"); - goto errout_with_cmdbuf; + goto errout_with_readbuf; } #endif } @@ -1509,6 +1519,9 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) fvdbg("Return %p\n", priv); return (FAR struct mtd_dev_s *)priv; +errout_with_readbuf: + QSPI_FREE(qspi, priv->readbuf); + errout_with_cmdbuf: QSPI_FREE(qspi, priv->cmdbuf); -- GitLab From bfeef77f1f207c9f715d5f469cbef4256254d913 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 5 Nov 2015 11:25:39 -0600 Subject: [PATCH 257/858] SmartFS: Fix a compile error when FS debug enabled. Plus some changes needed by NuttX coding standard --- arch | 2 +- configs | 2 +- drivers/mtd/smart.c | 74 +++++++++++++++++++++++++++++++-------------- fs/smartfs/Kconfig | 2 +- 4 files changed, 54 insertions(+), 26 deletions(-) diff --git a/arch b/arch index f0cd7a9c41..b7e93fa2b1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f0cd7a9c410151fb4b8c7737366b501294fc54f2 +Subproject commit b7e93fa2b1d96c73c8f7eef7204e524c854d0b4e diff --git a/configs b/configs index 1433eb46e1..964197accd 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 1433eb46e1c86d422992f7b2bf06eda0b3734f8c +Subproject commit 964197accdf2460581266816fe6b21b5ae479380 diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index a565fee9c5..7965bb0dae 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -1025,6 +1025,7 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) smart_free(dev, dev->sMap); dev->sMap = NULL; } + #else if (dev->sBitMap != NULL) { @@ -1209,6 +1210,7 @@ errexit: { smart_free(dev, dev->sMap); } + #else if (dev->sBitMap) { @@ -1365,6 +1367,7 @@ static int smart_add_sector_to_cache(FAR struct smart_struct_s *dev, dev->sCache[index].birth = dev->cache_nextbirth++; dev->cache_lastlog = logical; dev->cache_lastphys = physical; + if (dev->debuglevel > 1) { dbg("Add Cache sector: Log=%d, Phys=%d at index %d from line %d\n", @@ -2060,7 +2063,6 @@ static int smart_scan(FAR struct smart_struct_s *dev) * to resolve who wins. */ - #if SMART_STATUS_VERSION == 1 if (header.status & SMART_STATUS_CRC) { @@ -2101,6 +2103,7 @@ static int smart_scan(FAR struct smart_struct_s *dev) /* Get the logical sector number for this physical sector */ duplogsector = *((FAR uint16_t *) header.logicalsector); + #if CONFIG_SMARTFS_ERASEDSTATE == 0x00 if (duplogsector == 0) { @@ -2208,6 +2211,7 @@ static int smart_scan(FAR struct smart_struct_s *dev) dev->sMap[logicalsector] = sector; #else /* Mark the logical sector as used in the bitmap */ + dev->sBitMap[logicalsector >> 3] |= 1 << (logicalsector & 0x07); if (logicalsector < SMART_FIRST_ALLOC_SECTOR) @@ -2246,11 +2250,13 @@ static int smart_scan(FAR struct smart_struct_s *dev) goto err_out; } - /* Check for old format wear leveling */ + if (dev->rwbuffer[SMART_WEAR_LEVEL_FORMAT_SIG] == 0) { - /* Old format detected. We must relocate sector zero and fill it in with 0xFF */ + /* Old format detected. We must relocate sector zero and fill it + * in with 0xFF. + */ uint16_t newsector = smart_findfreephyssector(dev, FALSE); if (newsector == 0xFFFF) @@ -2282,7 +2288,6 @@ static int smart_scan(FAR struct smart_struct_s *dev) smart_add_count(dev, dev->freecount, newsector / dev->sectorsPerBlk, -1); smart_add_count(dev, dev->releasecount, sector / dev->sectorsPerBlk, 1); #endif - } } @@ -2413,7 +2418,8 @@ static void smart_erase_block_if_empty(FAR struct smart_struct_s *dev, freecount = dev->freecount[block]; #endif - if ((freecount + releasecount == dev->availSectPerBlk && freecount < 1) || forceerase) + if ((freecount + releasecount == dev->availSectPerBlk && freecount < 1) || + forceerase) { /* Erase the block */ @@ -2803,6 +2809,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); /* Check for invalid format */ + if (dev->erasesize == 0) { if (dev->geo.erasesize == 0) @@ -2834,6 +2841,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a sectorheader = (FAR struct smart_sect_header_s *) dev->rwbuffer; memset(dev->rwbuffer, CONFIG_SMARTFS_ERASEDSTATE, dev->sectorsize); + #if SMART_STATUS_VERSION == 1 #ifdef CONFIG_MTD_SMART_ENABLE_CRC /* CRC enabled. Using an 8-bit sequence number */ @@ -2994,10 +3002,10 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a static int smart_relocate_sector(FAR struct smart_struct_s *dev, uint16_t oldsector, uint16_t newsector) { - int ret; size_t offset; FAR struct smart_sect_header_s *header; uint8_t newstatus; + int ret; header = (FAR struct smart_sect_header_s *) dev->rwbuffer; @@ -3161,7 +3169,8 @@ static int smart_relocate_block(FAR struct smart_struct_s *dev, uint16_t block) if (freecount >= dev->freesectors) { - fdbg("Program bug! Relocating the only block (%d) with free sectors!\n", block); + fdbg("Program bug! Relocating the only block (%d) with free sectors!\n", + block); ret = -EIO; goto errout; } @@ -3333,7 +3342,8 @@ static int smart_relocate_block(FAR struct smart_struct_s *dev, uint16_t block) #ifdef CONFIG_SMART_LOCAL_CHECKFREE if (smart_checkfree(dev, __LINE__) != OK) { - fdbg(" ...while relocating block %d, free=%d, release=%d, oldrelease=%d\n", block, freecount, releasecount, oldrelease); + fdbg(" ...while relocating block %d, free=%d, release=%d, oldrelease=%d\n", + block, freecount, releasecount, oldrelease); } #endif @@ -3383,7 +3393,8 @@ static int smart_findfreephyssector(FAR struct smart_struct_s *dev, /* Determine which erase block we should allocate the new * sector from. This is based on the number of free sectors - * available in each erase block. */ + * available in each erase block. + */ #ifdef CONFIG_MTD_SMART_WEAR_LEVEL retry: @@ -3453,8 +3464,11 @@ retry: allocfreecount = count; } } + if (++block >= dev->neraseblocks) - block = 0; + { + block = 0; + } } /* Check if we found an allocblock. */ @@ -3487,6 +3501,7 @@ retry: block++; } + if (x > 0) { /* Disable relocate for retry */ @@ -3539,7 +3554,10 @@ retry: while (allocsect) { if (allocsect->physical == x) - break; + { + break; + } + allocsect = allocsect->next; } @@ -3668,7 +3686,8 @@ static int smart_garbagecollect(FAR struct smart_struct_s *dev) collectblock = x; } #endif - } + } + //releasemax = smart_get_count(dev, dev->releasecount, collectblock); if (collectblock == 0xFFFF) @@ -3769,6 +3788,7 @@ static int smart_write_wearstatus(struct smart_struct_s *dev) req.offset = SMARTFS_FMT_WEAR_POS - 8; req.count = sizeof(buffer); req.buffer = buffer; + ret = smart_writesector(dev, (unsigned long) &req); if (ret != OK) { @@ -4011,7 +4031,7 @@ static int smart_write_alloc_sector(FAR struct smart_struct_s *dev, /* The block is not empty!! What to do? */ fdbg("Write block %d failed: %d.\n", physical * - dev->mtdBlksPerSector, ret); + dev->mtdBlksPerSector, ret); /* Unlock the mutex if we add one */ @@ -4395,7 +4415,8 @@ static int smart_writesector(FAR struct smart_struct_s *dev, ret = smart_bytewrite(dev, offset, 1, &byte); /* Update releasecount for released sector and freecount for the - * newly allocated physical sector. */ + * newly allocated physical sector. + */ block = oldphyssector / dev->sectorsPerBlk; #ifdef CONFIG_MTD_SMART_PACK_COUNTS @@ -4467,7 +4488,8 @@ static int smart_writesector(FAR struct smart_struct_s *dev, } #else /* Not relocated. Just write the portion of the sector that needs - * to be written. */ + * to be written. + */ offset = mtdblock * dev->geo.blocksize + sizeof(struct smart_sect_header_s) + req->offset; @@ -4558,7 +4580,6 @@ static int smart_readsector(FAR struct smart_struct_s *dev, /* Format VERSION 1 supports either no CRC or 8-bit CRC. Looks like * CRC not enabled for this sector, so skip the CRC test. */ - } else #endif @@ -4641,16 +4662,17 @@ errout: static inline int smart_allocsector(FAR struct smart_struct_s *dev, unsigned long requested) { - int x; uint16_t logsector = 0xFFFF; /* Logical sector number selected */ uint16_t physicalsector; /* The selected physical sector */ #ifndef CONFIG_MTD_SMART_ENABLE_CRC int ret; #endif + int x; /* Validate that we have enough sectors available to perform an * allocation. We have to ensure we keep enough reserved sectors - * on hand to do released sector garbage collection. */ + * on hand to do released sector garbage collection. + */ if (dev->freesectors <= (dev->sectorsPerBlk << 0) + 4) { @@ -4664,7 +4686,9 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, smart_garbagecollect(dev); if (dev->freesectors > dev->availSectPerBlk + 4) - break; + { + break; + } } if (dev->freesectors <= (dev->availSectPerBlk << 0) + 4) @@ -4683,7 +4707,8 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, } /* Check if a specific sector is being requested and allocate that - * sector if it isn't already in use */ + * sector if it isn't already in use. + */ if ((requested > 2) && (requested < dev->totalsectors)) { @@ -4699,6 +4724,7 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, FAR struct smart_allocsector_s *allocsect; /* Ensure this logical sector doesn't have a temporary alloc */ + allocsect = dev->allocsector; while (allocsect) { @@ -4778,7 +4804,8 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, * something happened and we didn't find any free * logical sectors. What do do? Report an error? * rescan and try again to "self heal" in case of a - * bug in our code? */ + * bug in our code? + */ fdbg("No free logical sector numbers! Free sectors = %d\n", dev->freesectors); @@ -4790,7 +4817,8 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, * ensure we keep enough reserved free sectors to perform garbage * collection as it involves moving sectors from blocks with * released sectors into blocks with free sectors, then - * erasing the vacated block. */ + * erasing the vacated block. + */ smart_garbagecollect(dev); @@ -4799,7 +4827,7 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, physicalsector = smart_findfreephyssector(dev, FALSE); fvdbg("Alloc: log=%d, phys=%d, erase block=%d, free=%d, released=%d\n", logsector, physicalsector, physicalsector / - dev->sectorsPerBlk, dev->freesectors, releasecount); + dev->sectorsPerBlk, dev->freesectors, dev->releasecount); #ifdef CONFIG_MTD_SMART_ENABLE_CRC diff --git a/fs/smartfs/Kconfig b/fs/smartfs/Kconfig index 0ddffd23ff..6beb521d4b 100644 --- a/fs/smartfs/Kconfig +++ b/fs/smartfs/Kconfig @@ -53,7 +53,7 @@ config SMARTFS_MULTI_ROOT_DIRS Default: y. config SMARTFS_ALIGNED_ACCESS - bool "Ensure 16 and 32 bit accesses are alined" + bool "Ensure 16 and 32 bit accesses are aligned" default n ---help--- Performs little endian byte accesses to 16 and 32 values -- GitLab From 8b0a5955fd66b44c0e6f5f4112ab73e81898761a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 5 Nov 2015 11:27:00 -0600 Subject: [PATCH 258/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 964197accd..449de6ca27 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 964197accdf2460581266816fe6b21b5ae479380 +Subproject commit 449de6ca27fc922687fe586aa65742cffbf2bc2e -- GitLab From f5b82db9b0cc52478a5e6885dc9e2603e0c1c548 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 6 Nov 2015 11:14:33 -0600 Subject: [PATCH 259/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b03be3d6bf..70e64d01fd 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11070,3 +11070,5 @@ (2015-11-03). * arch/arm/src/samv7: Add a call to can_txready() to the MCAN driver (2015-11-03). + * arch/arm/src/samv7: Add MPU and protected build support (2015-11-06). + diff --git a/arch b/arch index b7e93fa2b1..73ffdd85cb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b7e93fa2b1d96c73c8f7eef7204e524c854d0b4e +Subproject commit 73ffdd85cb13b7a129f11248a2db7dcc2f483724 -- GitLab From 41337324ba66c1f5b76dcf67099d2bc6c190826b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 6 Nov 2015 13:03:07 -0600 Subject: [PATCH 260/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 73ffdd85cb..dd5268721c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 73ffdd85cb13b7a129f11248a2db7dcc2f483724 +Subproject commit dd5268721c6a5c05ebd441556d3fddeb4b1d0509 -- GitLab From b2bdba0824e088c7e56cb470a417c0a468f09bca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 7 Nov 2015 11:26:53 -0600 Subject: [PATCH 261/858] S25FL1 FLASH driver: Fix return value from the bwrite() method --- ChangeLog | 6 ++++-- arch | 2 +- configs | 2 +- drivers/mtd/st25fl1.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70e64d01fd..c8dd774237 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10881,7 +10881,7 @@ device (2015-08-24). * networking: Correct return value from psock_tcp_accept(). From SaeHie Park (2015-08-25). - * drivers/mtd/st25fl1.c: Add a driver for ST25L1*K QuadSPI parts + * drivers/mtd/s25fl1.c: Add a driver for ST25L1*K QuadSPI parts (2015-08-25). * include/nuttx/spi/qspi.h: Develop a new interface for QSPI, at least the way that QSPI is implemented on the SAMV71. Originally @@ -11071,4 +11071,6 @@ * arch/arm/src/samv7: Add a call to can_txready() to the MCAN driver (2015-11-03). * arch/arm/src/samv7: Add MPU and protected build support (2015-11-06). - + * arch/arm/src/samv7: The QSPI FLASH driver is now functional. This + driver operates in the memory-mapped, Serial Memory Mode (SMM) + (2015-11-07). diff --git a/arch b/arch index dd5268721c..2137b6c754 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit dd5268721c6a5c05ebd441556d3fddeb4b1d0509 +Subproject commit 2137b6c754118003664432d16dd4b69685939c74 diff --git a/configs b/configs index 449de6ca27..8e4edaaa02 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 449de6ca27fc922687fe586aa65742cffbf2bc2e +Subproject commit 8e4edaaa0293ae3ca1517f6798694d8e96c553bb diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/st25fl1.c index 2db36adbf5..7a0ad758d0 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/st25fl1.c @@ -1289,7 +1289,7 @@ static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, st25fl1_unlock(priv->qspi); - return ret; + return ret < 0 ? ret : nblocks; } /************************************************************************************ -- GitLab From 91429433f688cf694716cdfb1aa12ca45d654673 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 7 Nov 2015 11:51:09 -0600 Subject: [PATCH 262/858] Correct naming of Spansion part. S25FL1, not ST25FL1 --- configs | 2 +- drivers/mtd/Kconfig | 22 +- drivers/mtd/Make.defs | 4 +- drivers/mtd/{st25fl1.c => s25fl1.c} | 554 ++++++++++++++-------------- include/nuttx/mtd/mtd.h | 4 +- 5 files changed, 293 insertions(+), 293 deletions(-) rename drivers/mtd/{st25fl1.c => s25fl1.c} (73%) diff --git a/configs b/configs index 8e4edaaa02..f475b05030 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8e4edaaa0293ae3ca1517f6798694d8e96c553bb +Subproject commit f475b05030ef74cea1941774716b2ba0af1c97ae diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index c35d28a34b..55b40b4c7f 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -395,18 +395,18 @@ config M25P_SUBSECTOR_ERASE endif -config MTD_ST25FL1 - bool "QuadSPI-based ST25FL1 FLASH" +config MTD_S25FL1 + bool "QuadSPI-based S25FL1 FLASH" default n -if MTD_ST25FL1 +if MTD_S25FL1 -config ST25FL1_QSPIMODE - int "ST25FL1 QuadSPI Mode" +config S25FL1_QSPIMODE + int "S25FL1 QuadSPI Mode" default 0 -config ST25FL1_QSPI_FREQUENCY - int "ST25FL1 QuadSPI Frequency" +config S25FL1_QSPI_FREQUENCY + int "S25FL1 QuadSPI Frequency" default 108000000 ---help--- Per data sheet: @@ -430,20 +430,20 @@ config ST25FL1_QSPI_FREQUENCY In this implementation, only "Quad" reads are performed. -config ST25FL1_SECTOR512 +config S25FL1_SECTOR512 bool "Simulate 512 byte Erase Blocks" default n -config ST25FL1_SCRAMBLE +config S25FL1_SCRAMBLE bool "Scramble data" default n ---help--- Requires drviver support for data scrambling/descrambling. -config ST25FL1_SCRAMBLE_KEY +config S25FL1_SCRAMBLE_KEY hex "Scramble key" default 0x0baddead - depends on ST25FL1_SCRAMBLE + depends on S25FL1_SCRAMBLE endif diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs index afbe4bd0e0..cdc9e156cc 100644 --- a/drivers/mtd/Make.defs +++ b/drivers/mtd/Make.defs @@ -92,8 +92,8 @@ ifeq ($(CONFIG_MTD_AT25),y) CSRCS += at25.c endif -ifeq ($(CONFIG_MTD_ST25FL1),y) -CSRCS += st25fl1.c +ifeq ($(CONFIG_MTD_S25FL1),y) +CSRCS += s25fl1.c endif ifeq ($(CONFIG_MTD_SMART),y) diff --git a/drivers/mtd/st25fl1.c b/drivers/mtd/s25fl1.c similarity index 73% rename from drivers/mtd/st25fl1.c rename to drivers/mtd/s25fl1.c index 7a0ad758d0..47cd6739fd 100644 --- a/drivers/mtd/st25fl1.c +++ b/drivers/mtd/s25fl1.c @@ -1,5 +1,5 @@ /************************************************************************************ - * drivers/mtd/st25fl1.c + * drivers/mtd/s25fl1.c * Driver for QuadSPI-based S25FL116K, S25FL132K, and S25L164K * * Copyright (C) 2015 Gregory Nutt. All rights reserved. @@ -62,8 +62,8 @@ /* Configuration ********************************************************************/ /* QuadSPI Mode. Per data sheet, either Mode 0 or Mode 3 may be used. */ -#ifndef CONFIG_ST25FL1_QSPIMODE -# define CONFIG_ST25FL1_QSPIMODE QSPIDEV_MODE0 +#ifndef CONFIG_S25FL1_QSPIMODE +# define CONFIG_S25FL1_QSPIMODE QSPIDEV_MODE0 #endif /* QuadSPI Frequency per data sheet:: @@ -90,78 +90,78 @@ * In this implementation, only "Quad" reads are performed. */ -#ifndef CONFIG_ST25FL1_QSPI_FREQUENCY -# define CONFIG_ST25FL1_QSPI_FREQUENCY 108000000 +#ifndef CONFIG_S25FL1_QSPI_FREQUENCY +# define CONFIG_S25FL1_QSPI_FREQUENCY 108000000 #endif -/* ST25FL1 Commands *****************************************************************/ +/* S25FL1 Commands ******************************************************************/ /* Configuration, Status, Erase, Program Commands ***********************************/ /* Command Value Description: */ /* Data sequence */ -#define ST25FL1_READ_STATUS1 0x05 /* Read status register 1: * +#define S25FL1_READ_STATUS1 0x05 /* Read status register 1: * * 0x05 | SR1 */ -#define ST25FL1_READ_STATUS2 0x35 /* Read status register 2: * +#define S25FL1_READ_STATUS2 0x35 /* Read status register 2: * * 0x35 | SR2 */ -#define ST25FL1_READ_STATUS3 0x33 /* Read status register 3: * +#define S25FL1_READ_STATUS3 0x33 /* Read status register 3: * * 0x33 | SR3 */ -#define ST25FL1_WRITE_ENABLE 0x06 /* Write enable: * +#define S25FL1_WRITE_ENABLE 0x06 /* Write enable: * * 0x06 */ -#define ST25FL1_VWRITE_ENABLE 0x50 /* Write enable for volatile status: * +#define S25FL1_VWRITE_ENABLE 0x50 /* Write enable for volatile status: * * 0x50 */ -#define ST25FL1_WRITE_DISABLE 0x04 /* Write disable command code: * +#define S25FL1_WRITE_DISABLE 0x04 /* Write disable command code: * * 0x04 */ -#define ST25FL1_WRITE_STATUS 0x01 /* Write status register: * +#define S25FL1_WRITE_STATUS 0x01 /* Write status register: * * 0x01 | SR1 | SR2 | SR3 */ -#define ST25FL1_WRAP_ENABLE 0x77 /* Set Burst with Wrap: * +#define S25FL1_WRAP_ENABLE 0x77 /* Set Burst with Wrap: * * 0x77 | xx | xx | xx | SR3 */ -#define ST25FL1_UNPROTECT_SECTOR 0x39 /* Set Block / Pointer Protection: * +#define S25FL1_UNPROTECT_SECTOR 0x39 /* Set Block / Pointer Protection: * * 0x39 | ADDR(MS) | ADDR(MID) | xx */ -#define ST25FL1_PAGE_PROGRAM 0x02 /* Page Program: * +#define S25FL1_PAGE_PROGRAM 0x02 /* Page Program: * * 0x02 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | data */ -#define ST25FL1_SECTOR_ERASE 0x20 /* Sector Erase (4 kB) * +#define S25FL1_SECTOR_ERASE 0x20 /* Sector Erase (4 kB) * * 0x02 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) */ -#define ST25FL1_BLOCK_ERASE 0xd8 /* Block Erase (64 kB): * +#define S25FL1_BLOCK_ERASE 0xd8 /* Block Erase (64 kB): * * 0x02 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) */ -#define ST25FL1_CHIP_ERASE_1 0x60 /* Chip Erase 1: * +#define S25FL1_CHIP_ERASE_1 0x60 /* Chip Erase 1: * * 0x60 */ -#define ST25FL1_CHIP_ERASE_2 0xc7 /* Chip Erase 2: * +#define S25FL1_CHIP_ERASE_2 0xc7 /* Chip Erase 2: * * 0xc7 */ -#define ST25FL1_ERASE_PROG_SUSPEND 0x75 /* Erase / Program Suspend: * +#define S25FL1_ERASE_PROG_SUSPEND 0x75 /* Erase / Program Suspend: * * 0x75 */ -#define ST25FL1_ERASE_PROG_RESUME 0x7a /* Erase / Program Resume: * +#define S25FL1_ERASE_PROG_RESUME 0x7a /* Erase / Program Resume: * * 0x7a */ /* Read Commands ********************************************************************/ /* Command Value Description: */ /* Data sequence */ -#define ST25FL1_READ_DATA 0x03 /* Read Data: * +#define S25FL1_READ_DATA 0x03 /* Read Data: * * 0x03 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | data... */ -#define ST25FL1_FAST_READ 0x0b /* Fast Read: * +#define S25FL1_FAST_READ 0x0b /* Fast Read: * * 0x0b | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | dummy | data... */ -#define ST25FL1_FAST_READ_DUAL 0x3b /* Fast Read Dual Output: * +#define S25FL1_FAST_READ_DUAL 0x3b /* Fast Read Dual Output: * * 0x3b | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | dummy | data... */ -#define ST25FL1_FAST_READ_QUAD 0x6b /* Fast Read Dual Output: * +#define S25FL1_FAST_READ_QUAD 0x6b /* Fast Read Dual Output: * * 0x6b | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | dummy | data... */ -#define ST25FL1_FAST_READ_DUALIO 0xbb /* Fast Read Dual I/O: * +#define S25FL1_FAST_READ_DUALIO 0xbb /* Fast Read Dual I/O: * * 0xbb | ADDR(MS) | ADDR(LS) | data... */ -#define ST25FL1_FAST_READ_QUADIO 0xeb /* Fast Read Quad I/O: * +#define S25FL1_FAST_READ_QUADIO 0xeb /* Fast Read Quad I/O: * * 0xeb | ADDR | data... */ -#define ST25FL1_CONT_READ_RESET 0xff /* Continuous Read Mode Reset: * +#define S25FL1_CONT_READ_RESET 0xff /* Continuous Read Mode Reset: * * 0xff | 0xff */ /* Reset Commands *******************************************************************/ /* Command Value Description: */ /* Data sequence */ -#define ST25FL1_SOFT_RESET_ENABLE 0x66 /* Software Reset Enable: * +#define S25FL1_SOFT_RESET_ENABLE 0x66 /* Software Reset Enable: * * 0x66 */ -#define ST25FL1_SOFT_RESET 0x99 /* Software Reset: * +#define S25FL1_SOFT_RESET 0x99 /* Software Reset: * * 0x99 */ /* Continuous Read Mode Reset: * * 0xff | 0xff */ @@ -169,48 +169,48 @@ /* ID/Security Commands *************************&***********************************/ /* Command Value Description: */ /* Data sequence */ -#define ST25FL1_DEEP_PWRDOWN 0xb9 /* Deep Power-down: * +#define S25FL1_DEEP_PWRDOWN 0xb9 /* Deep Power-down: * * 0xb9 */ -#define ST25FL1_RELEASE_PWRDOWN 0xab /* Release Power down / Device ID: * +#define S25FL1_RELEASE_PWRDOWN 0xab /* Release Power down / Device ID: * * 0xab | dummy | dummy | dummy | * * DeviceID */ -#define ST25FL1_MANUFACTURER 0x90 /* Manufacturer / Device ID: * +#define S25FL1_MANUFACTURER 0x90 /* Manufacturer / Device ID: * * 0x90 | dummy | dummy | 0x00 | * * Manufacturer | DeviceID */ -#define ST25FL1_JEDEC_ID 0x9f /* JEDEC ID: * +#define S25FL1_JEDEC_ID 0x9f /* JEDEC ID: * * 0x9f | Manufacturer | MemoryType | * * Capacity */ -#define ST25FL1_READ_SFDP 0x5a /* Read SFDP Register / Read Unique ID * +#define S25FL1_READ_SFDP 0x5a /* Read SFDP Register / Read Unique ID * * Number: * * 0x5a | 0x00 | 0x00 | ADDR | dummy | * * data... */ -#define ST25FL1_READ_SECURITY 0x48 /* Read Security Registers: * +#define S25FL1_READ_SECURITY 0x48 /* Read Security Registers: * * 0x48 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | dummy | data... */ -#define ST25FL1_ERASE_SECURITY 0x44 /* Erase Security Registers: * +#define S25FL1_ERASE_SECURITY 0x44 /* Erase Security Registers: * * 0x48 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) */ -#define ST25FL1_PROgRAM_SECURITY 0x42 /* Program Security Registers: * +#define S25FL1_PROgRAM_SECURITY 0x42 /* Program Security Registers: * * 0x42 | ADDR(MS) | ADDR(MID) | * * ADDR(LS) | data... */ /* Flash Manufacturer JEDEC IDs */ -#define ST25FL1_JEDEC_ID_SPANSION 0x01 -#define ST25FL1_JEDEC_ID_ATMEL 0x1f -#define ST25FL1_JEDEC_ID_ST 0x20 -#define ST25FL1_JEDEC_ID_SST 0xbf -#define ST25FL1_JEDEC_ID_MACRONIX 0xc2 -#define ST25FL1_JEDEC_ID_WINBOND 0xef +#define S25FL1_JEDEC_ID_SPANSION 0x01 +#define S25FL1_JEDEC_ID_ATMEL 0x1f +#define S25FL1_JEDEC_ID_ST 0x20 +#define S25FL1_JEDEC_ID_SST 0xbf +#define S25FL1_JEDEC_ID_MACRONIX 0xc2 +#define S25FL1_JEDEC_ID_WINBOND 0xef -/* ST25FL1 JEDIC IDs */ +/* S25FL1 JEDIC IDs */ -#define ST25FL1_JEDEC_DEVICE_TYPE 0x40 /* ST25FL1 memory devuce type */ +#define S25FL1_JEDEC_DEVICE_TYPE 0x40 /* S25FL1 memory devuce type */ #define S25FL116K_JEDEC_CAPACITY 0x15 /* S25FL116K memory capacity */ #define S25FL132K_JEDEC_CAPACITY 0x16 /* S25FL132K memory capacity */ #define S25FL164K_JEDEC_CAPACITY 0x17 /* S25FL164K memory capacity */ -/* ST25FL1 Registers ****************************************************************/ +/* S25FL1 Registers ****************************************************************/ /* Status register bit definitions */ #define STATUS1_BUSY_MASK (1 << 0) /* Bit 0: Device ready/busy status */ @@ -255,12 +255,12 @@ #define STATUS3_W4_MASK (1 << 4) /* Bit 4: Burst Wrap Enable */ # define STATUS3_W4_DISABLED (0 << 4) /* 0 = Wrap Enabled */ # define STATUS3_W4_ENABLED (1 << 4) /* 1 = Wrap Disabled */ -#define STATUS3_W56_SHIFT (5) /* Bits 5-6: Burst Wrap Length */ -#define STATUS3_W56_MASK (3 << STATUS3_W56_SHIFT) -# define STATUS3_W56_8BYTE (0 << STATUS3_W56_SHIFT) -# define STATUS3_W56_16BYTE (1 << STATUS3_W56_SHIFT) -# define STATUS3_W56_32BYTE (2 << STATUS3_W56_SHIFT) -# define STATUS3_W56_63BYTE (3 << STATUS3_W56_SHIFT) +#define STATUS3_W56_SHIFT (5) /* Bits 5-6: Burst Wrap Length */ +#define STATUS3_W56_MASK (3 << STATUS3_W56_SHIFT) +# define STATUS3_W56_8BYTE (0 << STATUS3_W56_SHIFT) +# define STATUS3_W56_16BYTE (1 << STATUS3_W56_SHIFT) +# define STATUS3_W56_32BYTE (2 << STATUS3_W56_SHIFT) +# define STATUS3_W56_63BYTE (3 << STATUS3_W56_SHIFT) /* Bit 7: Reserved */ /* Chip Geometries ******************************************************************/ @@ -286,21 +286,21 @@ /* Cache flags **********************************************************************/ -#define ST25FL1_CACHE_VALID (1 << 0) /* 1=Cache has valid data */ -#define ST25FL1_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */ -#define ST25FL1_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */ +#define S25FL1_CACHE_VALID (1 << 0) /* 1=Cache has valid data */ +#define S25FL1_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */ +#define S25FL1_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */ -#define IS_VALID(p) ((((p)->flags) & ST25FL1_CACHE_VALID) != 0) -#define IS_DIRTY(p) ((((p)->flags) & ST25FL1_CACHE_DIRTY) != 0) -#define IS_ERASED(p) ((((p)->flags) & ST25FL1_CACHE_DIRTY) != 0) +#define IS_VALID(p) ((((p)->flags) & S25FL1_CACHE_VALID) != 0) +#define IS_DIRTY(p) ((((p)->flags) & S25FL1_CACHE_DIRTY) != 0) +#define IS_ERASED(p) ((((p)->flags) & S25FL1_CACHE_DIRTY) != 0) -#define SET_VALID(p) do { (p)->flags |= ST25FL1_CACHE_VALID; } while (0) -#define SET_DIRTY(p) do { (p)->flags |= ST25FL1_CACHE_DIRTY; } while (0) -#define SET_ERASED(p) do { (p)->flags |= ST25FL1_CACHE_DIRTY; } while (0) +#define SET_VALID(p) do { (p)->flags |= S25FL1_CACHE_VALID; } while (0) +#define SET_DIRTY(p) do { (p)->flags |= S25FL1_CACHE_DIRTY; } while (0) +#define SET_ERASED(p) do { (p)->flags |= S25FL1_CACHE_DIRTY; } while (0) -#define CLR_VALID(p) do { (p)->flags &= ~ST25FL1_CACHE_VALID; } while (0) -#define CLR_DIRTY(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) -#define CLR_ERASED(p) do { (p)->flags &= ~ST25FL1_CACHE_DIRTY; } while (0) +#define CLR_VALID(p) do { (p)->flags &= ~S25FL1_CACHE_VALID; } while (0) +#define CLR_DIRTY(p) do { (p)->flags &= ~S25FL1_CACHE_DIRTY; } while (0) +#define CLR_ERASED(p) do { (p)->flags &= ~S25FL1_CACHE_DIRTY; } while (0) /************************************************************************************ * Private Types @@ -308,10 +308,10 @@ /* This type represents the state of the MTD device. The struct mtd_dev_s must * appear at the beginning of the definition so that you can freely cast between - * pointers to struct mtd_dev_s and struct st25fl1_dev_s. + * pointers to struct mtd_dev_s and struct s25fl1_dev_s. */ -struct st25fl1_dev_s +struct s25fl1_dev_s { struct mtd_dev_s mtd; /* MTD interface */ FAR struct qspi_dev_s *qspi; /* Saved QuadSPI interface instance */ @@ -321,7 +321,7 @@ struct st25fl1_dev_s FAR uint8_t *cmdbuf; /* Allocated command buffer */ FAR uint8_t *readbuf; /* Allocated status read buffer */ -#ifdef CONFIG_ST25FL1_SECTOR512 +#ifdef CONFIG_S25FL1_SECTOR512 uint8_t flags; /* Buffered sector flags */ uint16_t esectno; /* Erase sector number in the cache */ FAR uint8_t *sector; /* Allocated sector data */ @@ -334,56 +334,56 @@ struct st25fl1_dev_s /* Locking */ -static void st25fl1_lock(FAR struct qspi_dev_s *qspi); -static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi); +static void s25fl1_lock(FAR struct qspi_dev_s *qspi); +static inline void s25fl1_unlock(FAR struct qspi_dev_s *qspi); /* Low-level message helpers */ -static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd); -static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, +static int s25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd); +static int s25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, off_t addr, uint8_t addrlen); -static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, +static int s25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR void *buffer, size_t buflen); -static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, +static int s25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, FAR const void *buffer, size_t buflen); -static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv); -static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv); -static uint8_t sf25fl1_read_status3(FAR struct st25fl1_dev_s *priv); -static void st25fl1_write_enable(FAR struct st25fl1_dev_s *priv); -static void st25fl1_write_disable(FAR struct st25fl1_dev_s *priv); - -static int st25fl1_readid(FAR struct st25fl1_dev_s *priv); -static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, +static uint8_t sf25fl1_read_status1(FAR struct s25fl1_dev_s *priv); +static uint8_t sf25fl1_read_status2(FAR struct s25fl1_dev_s *priv); +static uint8_t sf25fl1_read_status3(FAR struct s25fl1_dev_s *priv); +static void s25fl1_write_enable(FAR struct s25fl1_dev_s *priv); +static void s25fl1_write_disable(FAR struct s25fl1_dev_s *priv); + +static int s25fl1_readid(FAR struct s25fl1_dev_s *priv); +static int s25fl1_protect(FAR struct s25fl1_dev_s *priv, off_t startblock, size_t nblocks); -static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, +static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv, off_t startblock, size_t nblocks); -static bool st25fl1_isprotected(FAR struct st25fl1_dev_s *priv, +static bool s25fl1_isprotected(FAR struct s25fl1_dev_s *priv, uint8_t status, off_t address); -static int st25fl1_erase_sector(FAR struct st25fl1_dev_s *priv, off_t offset); -static int st25fl1_erase_chip(FAR struct st25fl1_dev_s *priv); -static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, +static int s25fl1_erase_sector(FAR struct s25fl1_dev_s *priv, off_t offset); +static int s25fl1_erase_chip(FAR struct s25fl1_dev_s *priv); +static int s25fl1_read_byte(FAR struct s25fl1_dev_s *priv, FAR uint8_t *buffer, off_t address, size_t nbytes); -static int st25fl1_write_page(FAR struct st25fl1_dev_s *priv, +static int s25fl1_write_page(FAR struct s25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t address, size_t nbytes); -#ifdef CONFIG_ST25FL1_SECTOR512 -static int st25fl1_flush_cache(struct st25fl1_dev_s *priv); -static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector); -static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector); -static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, +#ifdef CONFIG_S25FL1_SECTOR512 +static int s25fl1_flush_cache(struct s25fl1_dev_s *priv); +static FAR uint8_t *s25fl1_read_cache(struct s25fl1_dev_s *priv, off_t sector); +static void s25fl1_erase_cache(struct s25fl1_dev_s *priv, off_t sector); +static int s25fl1_write_cache(FAR struct s25fl1_dev_s *priv, FAR const uint8_t *buffer, off_t sector, size_t nsectors); #endif /* MTD driver methods */ -static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, +static int s25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); -static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, +static ssize_t s25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR uint8_t *buf); -static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, +static ssize_t s25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR const uint8_t *buf); -static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, +static ssize_t s25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, FAR uint8_t *buffer); -static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); +static int s25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); /************************************************************************************ * Private Data @@ -394,10 +394,10 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) ************************************************************************************/ /************************************************************************************ - * Name: st25fl1_lock + * Name: s25fl1_lock ************************************************************************************/ -static void st25fl1_lock(FAR struct qspi_dev_s *qspi) +static void s25fl1_lock(FAR struct qspi_dev_s *qspi) { /* On QuadSPI busses where there are multiple devices, it will be necessary to * lock QuadSPI to have exclusive access to the busses for a sequence of @@ -415,25 +415,25 @@ static void st25fl1_lock(FAR struct qspi_dev_s *qspi) * state. */ - QSPI_SETMODE(qspi, CONFIG_ST25FL1_QSPIMODE); + QSPI_SETMODE(qspi, CONFIG_S25FL1_QSPIMODE); QSPI_SETBITS(qspi, 8); - (void)QSPI_SETFREQUENCY(qspi, CONFIG_ST25FL1_QSPI_FREQUENCY); + (void)QSPI_SETFREQUENCY(qspi, CONFIG_S25FL1_QSPI_FREQUENCY); } /************************************************************************************ - * Name: st25fl1_unlock + * Name: s25fl1_unlock ************************************************************************************/ -static inline void st25fl1_unlock(FAR struct qspi_dev_s *qspi) +static inline void s25fl1_unlock(FAR struct qspi_dev_s *qspi) { (void)QSPI_LOCK(qspi, false); } /************************************************************************************ - * Name: st25fl1_command + * Name: s25fl1_command ************************************************************************************/ -static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) +static int s25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) { struct qspi_cmdinfo_s cmdinfo; @@ -450,11 +450,11 @@ static int st25fl1_command(FAR struct qspi_dev_s *qspi, uint8_t cmd) } /************************************************************************************ - * Name: st25fl1_command_address + * Name: s25fl1_command_address ************************************************************************************/ -static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, - off_t addr, uint8_t addrlen) +static int s25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, + off_t addr, uint8_t addrlen) { struct qspi_cmdinfo_s cmdinfo; @@ -471,11 +471,11 @@ static int st25fl1_command_address(FAR struct qspi_dev_s *qspi, uint8_t cmd, } /************************************************************************************ - * Name: st25fl1_command_read + * Name: s25fl1_command_read ************************************************************************************/ -static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, - FAR void *buffer, size_t buflen) +static int s25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR void *buffer, size_t buflen) { struct qspi_cmdinfo_s cmdinfo; @@ -492,11 +492,11 @@ static int st25fl1_command_read(FAR struct qspi_dev_s *qspi, uint8_t cmd, } /************************************************************************************ - * Name: st25fl1_command_write + * Name: s25fl1_command_write ************************************************************************************/ -static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, - FAR const void *buffer, size_t buflen) +static int s25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, + FAR const void *buffer, size_t buflen) { struct qspi_cmdinfo_s cmdinfo; @@ -516,10 +516,10 @@ static int st25fl1_command_write(FAR struct qspi_dev_s *qspi, uint8_t cmd, * Name: sf25fl1_read_status1 ************************************************************************************/ -static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv) +static uint8_t sf25fl1_read_status1(FAR struct s25fl1_dev_s *priv) { - DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS1, - (FAR void *)&priv->readbuf[0], 1)); + DEBUGVERIFY(s25fl1_command_read(priv->qspi, S25FL1_READ_STATUS1, + (FAR void *)&priv->readbuf[0], 1)); return priv->readbuf[0]; } @@ -527,10 +527,10 @@ static uint8_t sf25fl1_read_status1(FAR struct st25fl1_dev_s *priv) * Name: sf25fl1_read_status2 ************************************************************************************/ -static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv) +static uint8_t sf25fl1_read_status2(FAR struct s25fl1_dev_s *priv) { - DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS2, - (FAR void *)&priv->readbuf[0], 1)); + DEBUGVERIFY(s25fl1_command_read(priv->qspi, S25FL1_READ_STATUS2, + (FAR void *)&priv->readbuf[0], 1)); return priv->readbuf[0]; } @@ -538,81 +538,81 @@ static uint8_t sf25fl1_read_status2(FAR struct st25fl1_dev_s *priv) * Name: sf25fl1_read_status3 ************************************************************************************/ -static uint8_t sf25fl1_read_status3(FAR struct st25fl1_dev_s *priv) +static uint8_t sf25fl1_read_status3(FAR struct s25fl1_dev_s *priv) { - DEBUGVERIFY(st25fl1_command_read(priv->qspi, ST25FL1_READ_STATUS3, - (FAR void *)&priv->readbuf[0], 1)); + DEBUGVERIFY(s25fl1_command_read(priv->qspi, S25FL1_READ_STATUS3, + (FAR void *)&priv->readbuf[0], 1)); return priv->readbuf[0]; } /************************************************************************************ - * Name: st25fl1_write_enable + * Name: s25fl1_write_enable ************************************************************************************/ -static void st25fl1_write_enable(FAR struct st25fl1_dev_s *priv) +static void s25fl1_write_enable(FAR struct s25fl1_dev_s *priv) { uint8_t status; do { - st25fl1_command(priv->qspi, ST25FL1_WRITE_ENABLE); + s25fl1_command(priv->qspi, S25FL1_WRITE_ENABLE); status = sf25fl1_read_status1(priv); } while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_ENABLED); } /************************************************************************************ - * Name: st25fl1_write_disable + * Name: s25fl1_write_disable ************************************************************************************/ -static void st25fl1_write_disable(FAR struct st25fl1_dev_s *priv) +static void s25fl1_write_disable(FAR struct s25fl1_dev_s *priv) { uint8_t status; do { - st25fl1_command(priv->qspi, ST25FL1_WRITE_DISABLE); + s25fl1_command(priv->qspi, S25FL1_WRITE_DISABLE); status = sf25fl1_read_status1(priv); } while ((status & STATUS1_WEL_MASK) != STATUS1_WEL_DISABLED); } /************************************************************************************ - * Name: st25fl1_write_status + * Name: s25fl1_write_status ************************************************************************************/ -static void st25fl1_write_status(FAR struct st25fl1_dev_s *priv) +static void s25fl1_write_status(FAR struct s25fl1_dev_s *priv) { - st25fl1_write_enable(priv); - st25fl1_command_write(priv->qspi, ST25FL1_WRITE_STATUS, - (FAR const void *)priv->cmdbuf, 3); - st25fl1_write_disable(priv); + s25fl1_write_enable(priv); + s25fl1_command_write(priv->qspi, S25FL1_WRITE_STATUS, + (FAR const void *)priv->cmdbuf, 3); + s25fl1_write_disable(priv); } /************************************************************************************ - * Name: st25fl1_readid + * Name: s25fl1_readid ************************************************************************************/ -static inline int st25fl1_readid(struct st25fl1_dev_s *priv) +static inline int s25fl1_readid(struct s25fl1_dev_s *priv) { /* Lock the QuadSPI bus and configure the bus. */ - st25fl1_lock(priv->qspi); + s25fl1_lock(priv->qspi); /* Read the JEDEC ID */ - st25fl1_command_read(priv->qspi, ST25FL1_JEDEC_ID, priv->cmdbuf, 3); + s25fl1_command_read(priv->qspi, S25FL1_JEDEC_ID, priv->cmdbuf, 3); /* Unlock the bus */ - st25fl1_unlock(priv->qspi); + s25fl1_unlock(priv->qspi); fvdbg("Manufacturer: %02x Device Type %02x, Capacity: %02x", priv->cmdbuf[0], priv->cmdbuf[1], priv->cmdbuf[2]); /* Check for a recognized memory device type */ - if (priv->cmdbuf[1] != ST25FL1_JEDEC_DEVICE_TYPE) + if (priv->cmdbuf[1] != S25FL1_JEDEC_DEVICE_TYPE) { fdbg("ERROR: Unrecognized device type: %02x\n", priv->cmdbuf[1]); return -ENODEV; @@ -651,11 +651,11 @@ static inline int st25fl1_readid(struct st25fl1_dev_s *priv) } /************************************************************************************ - * Name: st25fl1_protect + * Name: s25fl1_protect ************************************************************************************/ -static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, - off_t startblock, size_t nblocks) +static int s25fl1_protect(FAR struct s25fl1_dev_s *priv, + off_t startblock, size_t nblocks) { /* Get the status register value to check the current protection */ @@ -677,7 +677,7 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, /* Yes.. unprotect section protection registers */ priv->cmdbuf[0] &= ~STATUS1_SRP0_MASK; - st25fl1_write_status(priv); + s25fl1_write_status(priv); } /* Set the protection mask to zero. @@ -686,7 +686,7 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, */ priv->cmdbuf[0] |= STATUS1_BP_MASK; - st25fl1_write_status(priv); + s25fl1_write_status(priv); /* Check the new status */ @@ -700,11 +700,11 @@ static int st25fl1_protect(FAR struct st25fl1_dev_s *priv, } /************************************************************************************ - * Name: st25fl1_unprotect + * Name: s25fl1_unprotect ************************************************************************************/ -static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, - off_t startblock, size_t nblocks) +static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv, + off_t startblock, size_t nblocks) { /* Get the status register value to check the current protection */ @@ -726,7 +726,7 @@ static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, /* Yes.. unprotect section protection registers */ priv->cmdbuf[0] &= ~STATUS1_SRP0_MASK; - st25fl1_write_status(priv); + s25fl1_write_status(priv); } /* Set the protection mask to zero. @@ -735,7 +735,7 @@ static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, */ priv->cmdbuf[0] &= ~STATUS1_BP_MASK; - st25fl1_write_status(priv); + s25fl1_write_status(priv); /* Check the new status */ @@ -749,11 +749,11 @@ static int st25fl1_unprotect(FAR struct st25fl1_dev_s *priv, } /************************************************************************************ - * Name: st25fl1_isprotected + * Name: s25fl1_isprotected ************************************************************************************/ -static bool st25fl1_isprotected(FAR struct st25fl1_dev_s *priv, uint8_t status, - off_t address) +static bool s25fl1_isprotected(FAR struct s25fl1_dev_s *priv, uint8_t status, + off_t address) { off_t protstart; off_t protend; @@ -814,10 +814,10 @@ static bool st25fl1_isprotected(FAR struct st25fl1_dev_s *priv, uint8_t status, } /************************************************************************************ - * Name: st25fl1_erase_sector + * Name: s25fl1_erase_sector ************************************************************************************/ -static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) +static int s25fl1_erase_sector(struct s25fl1_dev_s *priv, off_t sector) { off_t address; uint8_t status; @@ -838,7 +838,7 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) address = (off_t)sector << priv->sectorshift; if ((status & STATUS1_BP_MASK) != 0 && - st25fl1_isprotected(priv, status, address)) + s25fl1_isprotected(priv, status, address)) { fdbg("ERROR: Flash protected: %02x", status); return -EACCES; @@ -846,8 +846,8 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) /* Send the sector erase command */ - st25fl1_write_enable(priv); - st25fl1_command_address(priv->qspi, ST25FL1_SECTOR_ERASE, address, 3); + s25fl1_write_enable(priv); + s25fl1_command_address(priv->qspi, S25FL1_SECTOR_ERASE, address, 3); /* Wait for erasure to finish */ @@ -856,10 +856,10 @@ static int st25fl1_erase_sector(struct st25fl1_dev_s *priv, off_t sector) } /************************************************************************************ - * Name: st25fl1_erase_chip + * Name: s25fl1_erase_chip ************************************************************************************/ -static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) +static int s25fl1_erase_chip(struct s25fl1_dev_s *priv) { uint8_t status; @@ -874,8 +874,8 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) /* Erase the whole chip */ - st25fl1_write_enable(priv); - st25fl1_command(priv->qspi, ST25FL1_CHIP_ERASE_2); + s25fl1_write_enable(priv); + s25fl1_command(priv->qspi, S25FL1_CHIP_ERASE_2); /* Wait for the erasure to complete */ @@ -890,17 +890,17 @@ static int st25fl1_erase_chip(struct st25fl1_dev_s *priv) } /************************************************************************************ - * Name: st25fl1_read_byte + * Name: s25fl1_read_byte ************************************************************************************/ -static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer, - off_t address, size_t buflen) +static int s25fl1_read_byte(FAR struct s25fl1_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t buflen) { struct qspi_meminfo_s meminfo; fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)buflen); -#ifdef CONFIG_ST25FL1_SCRAMBLE +#ifdef CONFIG_S25FL1_SCRAMBLE meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO | QSPIMEM_SCRAMBLE; #else meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO; @@ -908,10 +908,10 @@ static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer meminfo.addrlen = 3; meminfo.dummies = 6; meminfo.buflen = buflen; - meminfo.cmd = ST25FL1_FAST_READ_QUADIO; + meminfo.cmd = S25FL1_FAST_READ_QUADIO; meminfo.addr = address; -#ifdef CONFIG_ST25FL1_SCRAMBLE - meminfo.key = CONFIG_ST25FL1_SCRAMBLE_KEY; +#ifdef CONFIG_S25FL1_SCRAMBLE + meminfo.key = CONFIG_S25FL1_SCRAMBLE_KEY; #endif meminfo.buffer = buffer; @@ -919,11 +919,11 @@ static int st25fl1_read_byte(FAR struct st25fl1_dev_s *priv, FAR uint8_t *buffer } /************************************************************************************ - * Name: st25fl1_write_page + * Name: s25fl1_write_page ************************************************************************************/ -static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buffer, - off_t address, size_t buflen) +static int s25fl1_write_page(struct s25fl1_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t buflen) { struct qspi_meminfo_s meminfo; unsigned int pagesize; @@ -938,16 +938,16 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf /* Set up non-varying parts of transfer description */ -#ifdef CONFIG_ST25FL1_SCRAMBLE +#ifdef CONFIG_S25FL1_SCRAMBLE meminfo.flags = QSPIMEM_WRITE | QSPIMEM_SCRAMBLE; #else meminfo.flags = QSPIMEM_WRITE; #endif - meminfo.cmd = ST25FL1_PAGE_PROGRAM; + meminfo.cmd = S25FL1_PAGE_PROGRAM; meminfo.addrlen = 3; meminfo.buflen = pagesize; -#ifdef CONFIG_ST25FL1_SCRAMBLE - meminfo.key = CONFIG_ST25FL1_SCRAMBLE_KEY; +#ifdef CONFIG_S25FL1_SCRAMBLE + meminfo.key = CONFIG_S25FL1_SCRAMBLE_KEY; #endif meminfo.dummies = 0; @@ -962,7 +962,7 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf /* Write one page */ - st25fl1_write_enable(priv); + s25fl1_write_enable(priv); ret = QSPI_MEMORY(priv->qspi, &meminfo); if (ret < 0) { @@ -983,16 +983,16 @@ static int st25fl1_write_page(struct st25fl1_dev_s *priv, FAR const uint8_t *buf */ DEBUGASSERT(buflen == 0); - st25fl1_write_disable(priv); + s25fl1_write_disable(priv); return OK; } /************************************************************************************ - * Name: st25fl1_flush_cache + * Name: s25fl1_flush_cache ************************************************************************************/ -#ifdef CONFIG_ST25FL1_SECTOR512 -static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) +#ifdef CONFIG_S25FL1_SECTOR512 +static int s25fl1_flush_cache(struct s25fl1_dev_s *priv) { int ret = OK; @@ -1005,10 +1005,10 @@ static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) { /* Write entire erase block to FLASH */ - ret = st25fl1_write_page(priv, priv->sector, 1 << priv->sectorshift); + ret = s25fl1_write_page(priv, priv->sector, 1 << priv->sectorshift); if (ret < 0) { - fdbg("ERROR: st25fl1_write_page failed: %d\n", ret); + fdbg("ERROR: s25fl1_write_page failed: %d\n", ret); } /* The case is no long dirty and the FLASH is no longer erased */ @@ -1022,11 +1022,11 @@ static int st25fl1_flush_cache(struct st25fl1_dev_s *priv) #endif /************************************************************************************ - * Name: st25fl1_read_cache + * Name: s25fl1_read_cache ************************************************************************************/ -#ifdef CONFIG_ST25FL1_SECTOR512 -static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) +#ifdef CONFIG_S25FL1_SECTOR512 +static FAR uint8_t *s25fl1_read_cache(struct s25fl1_dev_s *priv, off_t sector) { off_t esectno; int shift; @@ -1038,7 +1038,7 @@ static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) * shift to the right by 3 to get the sector number in 4096 increments. */ - shift = priv->sectorshift - ST25FL1_SECTOR512_SHIFT; + shift = priv->sectorshift - S25FL1_SECTOR512_SHIFT; esectno = sector >> shift; fvdbg("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift); @@ -1048,21 +1048,21 @@ static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) { /* No.. Flush any dirty erase block currently in the cache */ - ret = st25fl1_flush_cache(priv); + ret = s25fl1_flush_cache(priv); if (ret < 0) { - fdbg("ERROR: st25fl1_flush_cache failed: %d\n", ret); + fdbg("ERROR: s25fl1_flush_cache failed: %d\n", ret); return NULL; } /* Read the erase block into the cache */ - ret = st25fl1_read_byte(priv, priv->sector, + ret = s25fl1_read_byte(priv, priv->sector, (esectno << priv->sectorshift) (1 << priv->sectorshift)); if (ret < 0) { - fdbg("ERROR: st25fl1_read_byte failed: %d\n", ret); + fdbg("ERROR: s25fl1_read_byte failed: %d\n", ret); return NULL; } @@ -1081,16 +1081,16 @@ static FAR uint8_t *st25fl1_read_cache(struct st25fl1_dev_s *priv, off_t sector) /* Return the address in the cache that holds this sector */ - return &priv->sector[index << ST25FL1_SECTOR512_SHIFT]; + return &priv->sector[index << S25FL1_SECTOR512_SHIFT]; } #endif /************************************************************************************ - * Name: st25fl1_erase_cache + * Name: s25fl1_erase_cache ************************************************************************************/ -#ifdef CONFIG_ST25FL1_SECTOR512 -static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) +#ifdef CONFIG_S25FL1_SECTOR512 +static void s25fl1_erase_cache(struct s25fl1_dev_s *priv, off_t sector) { FAR uint8_t *dest; @@ -1098,7 +1098,7 @@ static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) * the cache. */ - dest = st25fl1_read_cache(priv, sector); + dest = s25fl1_read_cache(priv, sector); /* Erase the block containing this sector if it is not already erased. * The erased indicated will be cleared when the data from the erase sector @@ -1107,10 +1107,10 @@ static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) if (!IS_ERASED(priv)) { - off_t esectno = sector >> (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); + off_t esectno = sector >> (priv->sectorshift - S25FL1_SECTOR512_SHIFT); fvdbg("sector: %ld esectno: %d\n", sector, esectno); - DEBUGVERIFY(st25fl1_erase_sector(priv, esectno)); + DEBUGVERIFY(s25fl1_erase_sector(priv, esectno)); SET_ERASED(priv); } @@ -1119,19 +1119,19 @@ static void st25fl1_erase_cache(struct st25fl1_dev_s *priv, off_t sector) * time). */ - memset(dest, ST25FL1_ERASED_STATE, ST25FL1_SECTOR512_SIZE); + memset(dest, S25FL1_ERASED_STATE, S25FL1_SECTOR512_SIZE); SET_DIRTY(priv); } #endif /************************************************************************************ - * Name: st25fl1_write_cache + * Name: s25fl1_write_cache ************************************************************************************/ -#ifdef CONFIG_ST25FL1_SECTOR512 -static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, - FAR const uint8_t *buffer, off_t sector, - size_t nsectors) +#ifdef CONFIG_S25FL1_SECTOR512 +static int s25fl1_write_cache(FAR struct s25fl1_dev_s *priv, + FAR const uint8_t *buffer, off_t sector, + size_t nsectors) { FAR uint8_t *dest; int ret; @@ -1142,7 +1142,7 @@ static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, * memory. */ - dest = st25fl1_read_cache(priv, sector); + dest = s25fl1_read_cache(priv, sector); /* Erase the block containing this sector if it is not already erased. * The erased indicated will be cleared when the data from the erase sector @@ -1151,13 +1151,13 @@ static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, if (!IS_ERASED(priv)) { - off_t esectno = sector >> (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); + off_t esectno = sector >> (priv->sectorshift - S25FL1_SECTOR512_SHIFT); fvdbg("sector: %ld esectno: %d\n", sector, esectno); - ret = st25fl1_erase_sector(priv, esectno); + ret = s25fl1_erase_sector(priv, esectno); if (ret < 0) { - fdbg("ERROR: st25fl1_erase_sector failed: %d\n", ret); + fdbg("ERROR: s25fl1_erase_sector failed: %d\n", ret); return ret; } @@ -1166,44 +1166,44 @@ static int st25fl1_write_cache(FAR struct st25fl1_dev_s *priv, /* Copy the new sector data into cached erase block */ - memcpy(dest, buffer, ST25FL1_SECTOR512_SIZE); + memcpy(dest, buffer, S25FL1_SECTOR512_SIZE); SET_DIRTY(priv); /* Set up for the next 512 byte sector */ - buffer += ST25FL1_SECTOR512_SIZE; + buffer += S25FL1_SECTOR512_SIZE; sector++; } /* Flush the last erase block left in the cache */ - return st25fl1_flush_cache(priv); + return s25fl1_flush_cache(priv); } #endif /************************************************************************************ - * Name: st25fl1_erase + * Name: s25fl1_erase ************************************************************************************/ -static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +static int s25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) { - FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; size_t blocksleft = nblocks; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); /* Lock access to the SPI bus until we complete the erase */ - st25fl1_lock(priv->qspi); + s25fl1_lock(priv->qspi); while (blocksleft-- > 0) { /* Erase each sector */ #ifdef CONFIG_S25FL1_SECTOR512 - st25fl1_erase_cache(priv, startblock); + s25fl1_erase_cache(priv, startblock); #else - st25fl1_erase_sector(priv, startblock); + s25fl1_erase_sector(priv, startblock); #endif startblock++; } @@ -1211,41 +1211,41 @@ static int st25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl #ifdef CONFIG_S25FL1_SECTOR512 /* Flush the last erase block left in the cache */ - ret = st25fl1_flush_cache(priv); + ret = s25fl1_flush_cache(priv); if (ret < 0) { nblocks = ret; } #endif - st25fl1_unlock(priv->qspi); + s25fl1_unlock(priv->qspi); return (int)nblocks; } /************************************************************************************ - * Name: st25fl1_bread + * Name: s25fl1_bread ************************************************************************************/ -static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, - size_t nblocks, FAR uint8_t *buffer) +static ssize_t s25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buffer) { - FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; ssize_t nbytes; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); /* On this device, we can handle the block read just like the byte-oriented read */ -#ifdef CONFIG_ST25FL1_SECTOR512 - nbytes = st25fl1_read(dev, startblock << ST25FL1_SECTOR512_SHIFT, - nblocks << ST25FL1_SECTOR512_SHIFT, buffer); +#ifdef CONFIG_S25FL1_SECTOR512 + nbytes = s25fl1_read(dev, startblock << S25FL1_SECTOR512_SHIFT, + nblocks << S25FL1_SECTOR512_SHIFT, buffer); if (nbytes > 0) { - nbytes >>= ST25FL1_SECTOR512_SHIFT; + nbytes >>= S25FL1_SECTOR512_SHIFT; } #else - nbytes = st25fl1_read(dev, startblock << priv->sectorshift, - nblocks << priv->sectorshift, buffer); + nbytes = s25fl1_read(dev, startblock << priv->sectorshift, + nblocks << priv->sectorshift, buffer); if (nbytes > 0) { nbytes >>= priv->sectorshift; @@ -1256,63 +1256,63 @@ static ssize_t st25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, } /************************************************************************************ - * Name: st25fl1_bwrite + * Name: s25fl1_bwrite ************************************************************************************/ -static ssize_t st25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, - size_t nblocks, FAR const uint8_t *buffer) +static ssize_t s25fl1_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buffer) { - FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; int ret = (int)nblocks; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); /* Lock the QuadSPI bus and write all of the pages to FLASH */ - st25fl1_lock(priv->qspi); + s25fl1_lock(priv->qspi); -#if defined(CONFIG_ST25FL1_SECTOR512) - ret = st25fl1_write_cache(priv, buffer, startblock, nblocks); +#if defined(CONFIG_S25FL1_SECTOR512) + ret = s25fl1_write_cache(priv, buffer, startblock, nblocks); if (ret < 0) { - fdbg("ERROR: st25fl1_write_cache failed: %d\n", ret); + fdbg("ERROR: s25fl1_write_cache failed: %d\n", ret); } #else - ret = st25fl1_write_page(priv, buffer, startblock << priv->sectorshift, - nblocks << priv->sectorshift); + ret = s25fl1_write_page(priv, buffer, startblock << priv->sectorshift, + nblocks << priv->sectorshift); if (ret < 0) { - fdbg("ERROR: st25fl1_write_page failed: %d\n", ret); + fdbg("ERROR: s25fl1_write_page failed: %d\n", ret); } #endif - st25fl1_unlock(priv->qspi); + s25fl1_unlock(priv->qspi); return ret < 0 ? ret : nblocks; } /************************************************************************************ - * Name: st25fl1_read + * Name: s25fl1_read ************************************************************************************/ -static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer) +static ssize_t s25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR uint8_t *buffer) { - FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; int ret; fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes); /* Lock the QuadSPI bus and select this FLASH part */ - st25fl1_lock(priv->qspi); - ret = st25fl1_read_byte(priv, buffer, offset, nbytes); - st25fl1_unlock(priv->qspi); + s25fl1_lock(priv->qspi); + ret = s25fl1_read_byte(priv, buffer, offset, nbytes); + s25fl1_unlock(priv->qspi); if (ret < 0) { - fdbg("ERROR: st25fl1_read_byte returned: %d\n", ret); + fdbg("ERROR: s25fl1_read_byte returned: %d\n", ret); return (ssize_t)ret; } @@ -1321,12 +1321,12 @@ static ssize_t st25fl1_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbyt } /************************************************************************************ - * Name: st25fl1_ioctl + * Name: s25fl1_ioctl ************************************************************************************/ -static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +static int s25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { - FAR struct st25fl1_dev_s *priv = (FAR struct st25fl1_dev_s *)dev; + FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; int ret = -EINVAL; /* Assume good command with bad parameters */ fvdbg("cmd: %d \n", cmd); @@ -1349,10 +1349,10 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * appear so. */ -#ifdef CONFIG_ST25FL1_SECTOR512 - geo->blocksize = (1 << ST25FL1_SECTOR512_SHIFT); - geo->erasesize = (1 << ST25FL1_SECTOR512_SHIFT); - geo->neraseblocks = priv->nsectors << (priv->sectorshift - ST25FL1_SECTOR512_SHIFT); +#ifdef CONFIG_S25FL1_SECTOR512 + geo->blocksize = (1 << S25FL1_SECTOR512_SHIFT); + geo->erasesize = (1 << S25FL1_SECTOR512_SHIFT); + geo->neraseblocks = priv->nsectors << (priv->sectorshift - S25FL1_SECTOR512_SHIFT); #else geo->blocksize = (1 << priv->sectorshift); geo->erasesize = (1 << priv->sectorshift); @@ -1370,9 +1370,9 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { /* Erase the entire device */ - st25fl1_lock(priv->qspi); - ret = st25fl1_erase_chip(priv); - st25fl1_unlock(priv->qspi); + s25fl1_lock(priv->qspi); + ret = s25fl1_erase_chip(priv); + s25fl1_unlock(priv->qspi); } break; @@ -1382,7 +1382,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) (FAR const struct mtd_protect_s *)((uintptr_t)arg); DEBUGASSERT(prot); - ret = st25fl1_protect(priv, prot->startblock, prot->nblocks); + ret = s25fl1_protect(priv, prot->startblock, prot->nblocks); } break; @@ -1392,7 +1392,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) (FAR const struct mtd_protect_s *)((uintptr_t)arg); DEBUGASSERT(prot); - ret = st25fl1_unprotect(priv, prot->startblock, prot->nblocks); + ret = s25fl1_unprotect(priv, prot->startblock, prot->nblocks); } break; @@ -1410,7 +1410,7 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) ************************************************************************************/ /************************************************************************************ - * Name: st25fl1_initialize + * Name: s25fl1_initialize * * Description: * Create an initialize MTD device instance for the QuadSPI-based ST24FL1 @@ -1422,9 +1422,9 @@ static int st25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ************************************************************************************/ -FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) +FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi) { - FAR struct st25fl1_dev_s *priv; + FAR struct s25fl1_dev_s *priv; int ret; fvdbg("qspi: %p\n", qspi); @@ -1437,18 +1437,18 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) * to be extended to handle multiple FLASH parts on the same QuadSPI bus. */ - priv = (FAR struct st25fl1_dev_s *)kmm_zalloc(sizeof(struct st25fl1_dev_s)); + priv = (FAR struct s25fl1_dev_s *)kmm_zalloc(sizeof(struct s25fl1_dev_s)); if (priv) { /* Initialize the allocated structure (unsupported methods were * nullified by kmm_zalloc). */ - priv->mtd.erase = st25fl1_erase; - priv->mtd.bread = st25fl1_bread; - priv->mtd.bwrite = st25fl1_bwrite; - priv->mtd.read = st25fl1_read; - priv->mtd.ioctl = st25fl1_ioctl; + priv->mtd.erase = s25fl1_erase; + priv->mtd.bread = s25fl1_bread; + priv->mtd.bwrite = s25fl1_bwrite; + priv->mtd.read = s25fl1_read; + priv->mtd.ioctl = s25fl1_ioctl; priv->qspi = qspi; /* Allocate a 4-byte buffer to support DMA command data */ @@ -1471,7 +1471,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) /* Identify the FLASH chip and get its capacity */ - ret = st25fl1_readid(priv); + ret = s25fl1_readid(priv); if (ret != OK) { /* Unrecognized! Discard all of that work we just did and return NULL */ @@ -1489,12 +1489,12 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) while ((priv->cmdbuf[1] & STATUS2_QUAD_ENABLE_MASK) == 0) { priv->cmdbuf[1] |= STATUS2_QUAD_ENABLE; - st25fl1_write_status(priv); + s25fl1_write_status(priv); priv->cmdbuf[1] = sf25fl1_read_status2(priv); usleep(50*1000); } -#ifdef CONFIG_ST25FL1_SECTOR512 /* Simulate a 512 byte sector */ +#ifdef CONFIG_S25FL1_SECTOR512 /* Simulate a 512 byte sector */ /* Allocate a buffer for the erase block cache */ priv->sector = (FAR uint8_t *)QSPI_ALLOC(1 << priv->sectorshift); @@ -1511,7 +1511,7 @@ FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi) #ifdef CONFIG_MTD_REGISTRATION /* Register the MTD with the procfs system if enabled */ - mtd_register(&priv->mtd, "st25fl1"); + mtd_register(&priv->mtd, "s25fl1"); #endif /* Return the implementation-specific state structure as the MTD device */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 976b47a367..c7fdde1618 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -475,7 +475,7 @@ FAR struct mtd_dev_s *sst39vf_initialize(void); FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); /**************************************************************************** - * Name: st25fl1_initialize + * Name: s25fl1_initialize * * Description: * Create an initialize MTD device instance for the QuadSPI-based ST24FL1 @@ -484,7 +484,7 @@ FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); ****************************************************************************/ struct qspi_dev_s; /* Forward reference */ -FAR struct mtd_dev_s *st25fl1_initialize(FAR struct qspi_dev_s *qspi); +FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi); /**************************************************************************** * Name: up_flashinitialize -- GitLab From 874862abb9b4ef6d227d9032118b401c3df74a20 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 8 Nov 2015 07:00:09 -0600 Subject: [PATCH 263/858] CAN driver: Improve some comments --- arch | 2 +- drivers/can.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 2137b6c754..c3b18f485b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 2137b6c754118003664432d16dd4b69685939c74 +Subproject commit c3b18f485b208adcc005f39d50c202e4ae795e91 diff --git a/drivers/can.c b/drivers/can.c index 3548729388..8ac3e189ce 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -1109,18 +1109,27 @@ int can_txready(FAR struct can_dev_s *dev) if (dev->cd_ntxwaiters > 0) { /* Verify that the xmit FIFO is not empty. + * * REVISIT: This probably should be an assertion since we should only * be waiting for space in the xmit FIFO if the xmit FIFO is full. */ if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { - /* Send the next message in the FIFO, making space in the xmit FIFO */ + /* Send the next message in the S/W FIFO. In the case where the + * H/W TX FIFO is not empty, this should add one more CAN message + * to the H/W TX FIFO and can_txdone() should be called, making + * space in the S/W FIFO + */ (void)can_xmit(dev); } - /* Inform one waiter that new xmit space is available */ + /* Inform one waiter that new xmit space is available in the S/W FIFO. + * NOTE that is can_txdone() is, indeed, called twice that the tx_sem + * will also be posted twice. This is a little inefficient, but not + * harmful. + */ ret = sem_post(&dev->cd_xmit.tx_sem); } -- GitLab From 95562f8a86f01be15c17e80a378d2b5107d6481a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 8 Nov 2015 07:43:57 -0600 Subject: [PATCH 264/858] CAN driver: More improved comments --- drivers/can.c | 64 +++++++++++++++++++++++++++++++++++++----- include/nuttx/can.h | 68 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 116 insertions(+), 16 deletions(-) diff --git a/drivers/can.c b/drivers/can.c index 8ac3e189ce..998e1c7b97 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -859,11 +859,14 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev) * Description: * Called from the CAN interrupt handler when new read data is available * - * Parameters: + * Input Parameters: * dev - CAN driver state structure * hdr - CAN message header * data - CAN message data (if DLC > 0) * + * Returned Value: + * OK on success; a negated errno on failure. + * * Assumptions: * CAN interrupts are disabled. * @@ -983,15 +986,62 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * Name: can_txdone * * Description: - * Called from the CAN interrupt handler at the completion of a send - * operation. + * Called when the hardware has processed the outgoing TX message. This + * normally means that the CAN messages was sent out on the wire. But + * if the CAN hardware supports a H/W TX FIFO, then this call may mean + * only that the CAN message has been added to the H/W FIFO. In either + * case, the upper-half CAN driver can remove the outgoing message from + * the S/W FIFO and discard it. + * + * This function may be called in different contexts, depending upon the + * nature of the underlying CAN hardware. + * + * 1. No H/W TX FIFO (CONFIG_CAN_TXREADY not defined) + * + * This function is only called from the CAN interrupt handler at the + * completion of a send operation. + * + * can_write() -> can_xmit() -> dev_send() + * CAN interrupt -> can_txdone() + * + * If the CAN hardware is busy, then the call to dev_send() will + * fail, the S/W TX FIFO will accumulate outgoing messages, and the + * thread calling can_write() may eventually block waiting for space in + * the S/W TX FIFO. + * + * When the CAN hardware completes the transfer and processes the + * CAN interrupt, the call to can_txdone() will make space in the S/W + * TX FIFO and will awaken the waiting can_write() thread. * - * Parameters: + * 2a. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO not full + * + * This function will be called back from dev_send() immediately when a + * new CAN message is added to H/W TX FIFO: + * + * can_write() -> can_xmit() -> dev_send() -> can_txdone() + * + * When the H/W TX FIFO becomes full, dev_send() will fail and + * can_txdone() will not be called. In this case the S/W TX FIFO will + * accumulate outgoing messages, and the thread calling can_write() may + * eventually block waiting for space in the S/W TX FIFO. + * + * 2b. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO full + * + * In this case, the thread calling can_write() is blocked waiting for + * space in the S/W TX FIFO. + * + * CAN interrupt -> can_txready() -> can_xmit() -> dev_send() -> can_txdone() + * + * The call dev_send() should not fail in this case and the subsequent + * call to can_txdone() will make space in the S/W TX FIFO and will + * awaken the waiting thread. + * + * Input Parameters: * dev - The specific CAN device * hdr - The 16-bit CAN header * data - An array contain the CAN data. * - * Return: + * Returned Value: * OK on success; a negated errno on failure. * ****************************************************************************/ @@ -1087,10 +1137,10 @@ int can_txdone(FAR struct can_dev_s *dev) * that the H/W FIFO is no longer full. can_txready() will then awaken * the can_write() logic and the hang condition is avoided. * - * Parameters: + * Input Parameters: * dev - The specific CAN device * - * Return: + * Returned Value: * OK on success; a negated errno on failure. * ****************************************************************************/ diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 59f4242e63..904a3a16d3 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -495,12 +495,12 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev); * Description: * Called from the CAN interrupt handler when new read data is available * - * Parameters: + * Input Parameters: * dev - The specific CAN device * hdr - The 16-bit CAN header * data - An array contain the CAN data. * - * Return: + * Returned Value: * OK on success; a negated errno on failure. * ************************************************************************************/ @@ -508,19 +508,69 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev); int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, FAR uint8_t *data); -/************************************************************************************ +/**************************************************************************** * Name: can_txdone * * Description: - * Called from the CAN interrupt handler at the completion of a send operation. + * Called when the hardware has processed the outgoing TX message. This + * normally means that the CAN messages was sent out on the wire. But + * if the CAN hardware supports a H/W TX FIFO, then this call may mean + * only that the CAN message has been added to the H/W FIFO. In either + * case, the upper-half CAN driver can remove the outgoing message from + * the S/W FIFO and discard it. + * + * This function may be called in different contexts, depending upon the + * nature of the underlying CAN hardware. + * + * 1. No H/W TX FIFO (CONFIG_CAN_TXREADY not defined) + * + * This function is only called from the CAN interrupt handler at the + * completion of a send operation. + * + * can_write() -> can_xmit() -> dev_send() + * CAN interrupt -> can_txdone() + * + * If the CAN hardware is busy, then the call to dev_send() will + * fail, the S/W TX FIFO will accumulate outgoing messages, and the + * thread calling can_write() may eventually block waiting for space in + * the S/W TX FIFO. + * + * When the CAN hardware completes the transfer and processes the + * CAN interrupt, the call to can_txdone() will make space in the S/W + * TX FIFO and will awaken the waiting can_write() thread. + * + * 2a. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO not full + * + * This function will be back from can_xmit immediately when a new CAN + * message is added to H/W TX FIFO: * - * Parameters: + * can_write() -> can_xmit() -> dev_send() -> can_txdone() + * + * When the H/W TX FIFO becomes full, dev_send() will fail and + * can_txdone() will not be called. In this case the S/W TX FIFO will + * accumulate outgoing messages, and the thread calling can_write() may + * eventually block waiting for space in the S/W TX FIFO. + * + * 2b. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO full + * + * In this case, the thread calling can_write() is blocked waiting for + * space in the S/W TX FIFO. + * + * CAN interrupt -> can_txready() -> can_xmit() -> dev_send() -> can_txdone() + * + * The call dev_send() should not fail in this case and the subsequent + * call to can_txdone() will make space in the S/W TX FIFO and will + * awaken the waiting thread. + * + * Input Parameters: * dev - The specific CAN device + * hdr - The 16-bit CAN header + * data - An array contain the CAN data. * - * Return: + * Returned Value: * OK on success; a negated errno on failure. * - ************************************************************************************/ + ****************************************************************************/ int can_txdone(FAR struct can_dev_s *dev); @@ -566,10 +616,10 @@ int can_txdone(FAR struct can_dev_s *dev); * that the H/W FIFO is no longer full. can_txready() will then awaken * the can_write() logic and the hang condition is avoided. * - * Parameters: + * Input Parameters: * dev - The specific CAN device * - * Return: + * Returned Value: * OK on success; a negated errno on failure. * ************************************************************************************/ -- GitLab From 2ab0832c269ed1a14d656ec3f3f69ad9ecc854c8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 9 Nov 2015 09:35:14 -0600 Subject: [PATCH 265/858] Smart MTD: fix some outdated logic: geometray erase size is now 32-bits --- configs | 2 +- drivers/mtd/smart.c | 40 +++++++++++++--------------------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/configs b/configs index f475b05030..8c8d6ec2de 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f475b05030ef74cea1941774716b2ba0af1c97ae +Subproject commit 8c8d6ec2de52b4a8e10abc0d36f6ac4391a1f202 diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 7965bb0dae..d219232855 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -220,7 +220,8 @@ struct smart_struct_s uint32_t unusedsectors; /* Count of unused sectors (i.e. free when erased) */ uint32_t blockerases; /* Count of unused sectors (i.e. free when erased) */ #endif - uint16_t neraseblocks; /* Number of erase blocks or sub-sectors */ + uint32_t neraseblocks; /* Number of erase blocks or sub-sectors */ + uint32_t erasesize; /* Size of an erase block */ uint16_t lastallocblock; /* Last block we allocated a sector from */ uint16_t freesectors; /* Total number of free sectors */ uint16_t releasesectors; /* Total number of released sectors */ @@ -228,7 +229,6 @@ struct smart_struct_s uint16_t sectorsPerBlk; /* Number of sectors per erase block */ uint16_t sectorsize; /* Sector size on device */ uint16_t totalsectors; /* Total number of sectors on device */ - uint32_t erasesize; /* Size of an erase block */ FAR uint8_t *releasecount; /* Count of released sectors per erase block */ FAR uint8_t *freecount; /* Count of free sectors per erase block */ FAR char *rwbuffer; /* Our sector read/write buffer */ @@ -924,12 +924,7 @@ static int smart_geometry(FAR struct inode *inode, struct geometry *geometry) geometry->geo_writeenabled = false; #endif - erasesize = dev->geo.erasesize; - if (erasesize == 0) - { - erasesize = 262144; - } - + erasesize = dev->geo.erasesize; geometry->geo_nsectors = dev->geo.neraseblocks * erasesize / dev->sectorsize; geometry->geo_sectorsize = dev->sectorsize; @@ -971,21 +966,12 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) return OK; } - erasesize = dev->geo.erasesize; - dev->neraseblocks = dev->geo.neraseblocks; - - /* Most FLASH devices have erase size of 64K, but geo.erasesize is only - * 16 bits, so it will be zero - */ - - if (erasesize == 0) - { - erasesize = 262144; - } - - dev->erasesize = erasesize; - dev->sectorsize = size; + erasesize = dev->geo.erasesize; + dev->neraseblocks = dev->geo.neraseblocks; + dev->erasesize = erasesize; + dev->sectorsize = size; dev->mtdBlksPerSector = dev->sectorsize / dev->geo.blocksize; + if (erasesize / dev->sectorsize > 256) { /* We can't throw a dbg message here becasue it is too early. @@ -993,8 +979,8 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) * it during mksmartfs or mount. */ - dev->erasesize = 0; - dev->sectorsPerBlk = 256; + dev->erasesize = 0; + dev->sectorsPerBlk = 256; dev->availSectPerBlk = 255; } else @@ -1014,7 +1000,7 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS) dev->unusedsectors = 0; - dev->blockerases = 0; + dev->blockerases = 0; #endif /* Release any existing rwbuffer and sMap */ @@ -1033,8 +1019,8 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) dev->sBitMap = NULL; } - dev->cache_entries = 0; - dev->cache_lastlog = 0xFFFF; + dev->cache_entries = 0; + dev->cache_lastlog = 0xFFFF; dev->cache_nextbirth = 0; #endif -- GitLab From 896834002a51a38c579232da39a5d84545658d29 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 9 Nov 2015 11:47:25 -0600 Subject: [PATCH 266/858] BCH driver should forward ioctl commands to the contained block driver --- ChangeLog | 3 +++ drivers/bch/bch_internal.h | 20 ++++++++++---------- drivers/bch/bchdev_driver.c | 21 ++++++++++++++++++++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8dd774237..2ac723d871 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11074,3 +11074,6 @@ * arch/arm/src/samv7: The QSPI FLASH driver is now functional. This driver operates in the memory-mapped, Serial Memory Mode (SMM) (2015-11-07). + * drivers/bch: Block-to-character (BCH) driver should forward ioctl() + calls to the contained block driver (2015-11-09). + diff --git a/drivers/bch/bch_internal.h b/drivers/bch/bch_internal.h index 3a12c50c9b..653a2767b0 100644 --- a/drivers/bch/bch_internal.h +++ b/drivers/bch/bch_internal.h @@ -61,18 +61,18 @@ struct bchlib_s { - struct inode *inode; /* I-node of the block driver */ - sem_t sem; /* For atomic accesses to this structure */ - size_t nsectors; /* Number of sectors supported by the device */ - size_t sector; /* The current sector in the buffer */ - uint16_t sectsize; /* The size of one sector on the device */ - uint8_t refs; /* Number of references */ - bool dirty; /* Data has been written to the buffer */ - bool readonly; /* true: Only read operations are supported */ - FAR uint8_t *buffer; /* One sector buffer */ + FAR struct inode *inode; /* I-node of the block driver */ + sem_t sem; /* For atomic accesses to this structure */ + size_t nsectors; /* Number of sectors supported by the device */ + size_t sector; /* The current sector in the buffer */ + uint16_t sectsize; /* The size of one sector on the device */ + uint8_t refs; /* Number of references */ + bool dirty; /* Data has been written to the buffer */ + bool readonly; /* true: Only read operations are supported */ + FAR uint8_t *buffer; /* One sector buffer */ #if defined(CONFIG_BCH_ENCRYPTION) - uint8_t key[CONFIG_BCH_ENCRYPTION_KEY_SIZE]; /* Encryption key */ + uint8_t key[CONFIG_BCH_ENCRYPTION_KEY_SIZE]; /* Encryption key */ #endif }; diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 7bf5f54ed9..14ee267d99 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -302,6 +302,8 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(inode && inode->i_private); bch = (FAR struct bchlib_s *)inode->i_private; + /* Is this a request to get the private data structure */ + if (cmd == DIOC_GETPRIV) { FAR struct bchlib_s **bchr = (FAR struct bchlib_s **)((uintptr_t)arg); @@ -319,7 +321,10 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) bchlib_semgive(bch); } -#if defined(CONFIG_BCH_ENCRYPTION) + +#ifdef CONFIG_BCH_ENCRYPTION + /* Is this a request to set the encryption key? */ + else if (cmd == DIOC_SETKEY) { memcpy(bch->key, (FAR void *)arg, CONFIG_BCH_ENCRYPTION_KEY_SIZE); @@ -327,6 +332,20 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } #endif + /* Otherwise, pass the IOCTL command on to the contained block driver */ + + else + { + FAR struct inode *bchinode = bch->inode; + + /* Does the block driver support the ioctl method? */ + + if (bchinode->u.i_bops->ioctl != NULL) + { + ret = bchinode->u.i_bops->ioctl(bchinode, cmd, arg); + } + } + return ret; } -- GitLab From d6cc75dc648b5343a1ae9b73e5e5264a3da08658 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 9 Nov 2015 13:33:53 -0600 Subject: [PATCH 267/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index c3b18f485b..0295d52281 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c3b18f485b208adcc005f39d50c202e4ae795e91 +Subproject commit 0295d52281bd513853b347afe64ee34db51199cc -- GitLab From 1ed69cd53515a37490f0a3dec7751879c78e6186 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 Nov 2015 07:41:40 -0600 Subject: [PATCH 268/858] Fix another corner case in the upper half CAN driver --- drivers/can.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/can.c b/drivers/can.c index 998e1c7b97..f8a6be2e12 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -1044,6 +1044,12 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * Returned Value: * OK on success; a negated errno on failure. * + * Assumptions: + * Interrupts are disabled. This is required by can_xmit() which is called + * by this function. Interrupts are explicitly disabled when called + * through can_write(). Interrupts are expected be disabled when called + * from the CAN interrupt handler. + * ****************************************************************************/ int can_txdone(FAR struct can_dev_s *dev) @@ -1143,6 +1149,10 @@ int can_txdone(FAR struct can_dev_s *dev) * Returned Value: * OK on success; a negated errno on failure. * + * Assumptions: + * Interrupts are disabled. This is required by can_xmit() which is called + * by this function. + * ****************************************************************************/ #ifdef CONFIG_CAN_TXREADY @@ -1154,26 +1164,20 @@ int can_txready(FAR struct can_dev_s *dev) dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, dev->cd_xmit.tx_tail, dev->cd_ntxwaiters); - /* Are there any threads waiting for space in the xmit FIFO? */ + /* Verify that the xmit FIFO is not empty. This is safe because interrupts + * are always disabled when calling into can_xmit(); this cannot collide + * with ongoing activity from can_write(). + */ - if (dev->cd_ntxwaiters > 0) + if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { - /* Verify that the xmit FIFO is not empty. - * - * REVISIT: This probably should be an assertion since we should only - * be waiting for space in the xmit FIFO if the xmit FIFO is full. + /* Send the next message in the S/W FIFO. In the case where the + * H/W TX FIFO is not empty, this should add one more CAN message + * to the H/W TX FIFO and can_txdone() should be called, making + * space in the S/W FIFO */ - if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) - { - /* Send the next message in the S/W FIFO. In the case where the - * H/W TX FIFO is not empty, this should add one more CAN message - * to the H/W TX FIFO and can_txdone() should be called, making - * space in the S/W FIFO - */ - - (void)can_xmit(dev); - } + (void)can_xmit(dev); /* Inform one waiter that new xmit space is available in the S/W FIFO. * NOTE that is can_txdone() is, indeed, called twice that the tx_sem @@ -1181,7 +1185,12 @@ int can_txready(FAR struct can_dev_s *dev) * harmful. */ - ret = sem_post(&dev->cd_xmit.tx_sem); + /* Are there any threads waiting for space in the xmit FIFO? */ + + if (dev->cd_ntxwaiters > 0) + { + ret = sem_post(&dev->cd_xmit.tx_sem); + } } return ret; -- GitLab From 965addb397f62454bfd3bee3c3a322dc4d3b1839 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 Nov 2015 11:33:35 -0600 Subject: [PATCH 269/858] s25fl1: When unprotecting, handle case where protection bits are inverted. Add option to s25flinitilize() to unprotected on power up --- arch | 2 +- configs | 2 +- drivers/mtd/s25fl1.c | 21 +++++++++++++++++---- include/nuttx/mtd/mtd.h | 4 +++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/arch b/arch index 0295d52281..a91eb08c8a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0295d52281bd513853b347afe64ee34db51199cc +Subproject commit a91eb08c8abc2cbcd3b72732dbc2ac0dfa2f2f61 diff --git a/configs b/configs index 8c8d6ec2de..a1a06e149f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8c8d6ec2de52b4a8e10abc0d36f6ac4391a1f202 +Subproject commit a1a06e149f09bc7b1cb7317ba8dc50c730634558 diff --git a/drivers/mtd/s25fl1.c b/drivers/mtd/s25fl1.c index 47cd6739fd..c2a8f05ba2 100644 --- a/drivers/mtd/s25fl1.c +++ b/drivers/mtd/s25fl1.c @@ -712,7 +712,8 @@ static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv, priv->cmdbuf[1] = sf25fl1_read_status2(priv); priv->cmdbuf[2] = sf25fl1_read_status3(priv); - if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE) + if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE && + (priv->cmdbuf[1] & STATUS2_CMP_MASK) == 0) { /* Protection already disabled */ @@ -729,13 +730,14 @@ static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv, s25fl1_write_status(priv); } - /* Set the protection mask to zero. + /* Set the protection mask to zero (and not complemented). * REVISIT: This logic should really just re-write the BP bits as * necessary to unprotect the range of sectors. */ priv->cmdbuf[0] &= ~STATUS1_BP_MASK; - s25fl1_write_status(priv); + priv->cmdbuf[1] &= ~STATUS2_CMP_MASK; + s25fl1_write_status(priv); /* Check the new status */ @@ -1422,7 +1424,7 @@ static int s25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ************************************************************************************/ -FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi) +FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, bool unprotect) { FAR struct s25fl1_dev_s *priv; int ret; @@ -1494,6 +1496,17 @@ FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi) usleep(50*1000); } + /* Unprotect FLASH sectors if so requested. */ + + if (unprotect) + { + ret = s25fl1_unprotect(priv, 0, priv->nsectors - 1); + if (ret < 0) + { + fdbg("ERROR: Sector unprotect failed\n"); + } + } + #ifdef CONFIG_S25FL1_SECTOR512 /* Simulate a 512 byte sector */ /* Allocate a buffer for the erase block cache */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index c7fdde1618..7f4e8f8340 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -45,6 +45,7 @@ #include #include +#include #include @@ -484,7 +485,8 @@ FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); ****************************************************************************/ struct qspi_dev_s; /* Forward reference */ -FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi); +FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, + bool unprotect); /**************************************************************************** * Name: up_flashinitialize -- GitLab From eb1191df63ac28ee6329843840258d1fe1159c37 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 Nov 2015 12:48:29 -0600 Subject: [PATCH 270/858] S24FL1: Fix an error in the page write logic --- arch | 2 +- drivers/mtd/s25fl1.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch b/arch index a91eb08c8a..fb42257296 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a91eb08c8abc2cbcd3b72732dbc2ac0dfa2f2f61 +Subproject commit fb42257296843a19a50cbca004324f1c88a00b8f diff --git a/drivers/mtd/s25fl1.c b/drivers/mtd/s25fl1.c index c2a8f05ba2..4b061a3ba8 100644 --- a/drivers/mtd/s25fl1.c +++ b/drivers/mtd/s25fl1.c @@ -966,6 +966,8 @@ static int s25fl1_write_page(struct s25fl1_dev_s *priv, FAR const uint8_t *buffe s25fl1_write_enable(priv); ret = QSPI_MEMORY(priv->qspi, &meminfo); + s25fl1_write_disable(priv); + if (ret < 0) { fdbg("ERROR: QSPI_MEMORY failed writing address=%06x\n", @@ -985,7 +987,6 @@ static int s25fl1_write_page(struct s25fl1_dev_s *priv, FAR const uint8_t *buffe */ DEBUGASSERT(buflen == 0); - s25fl1_write_disable(priv); return OK; } -- GitLab From 08200d8f86f4d65c7e9ed9fa05e3c0284e635985 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 Nov 2015 13:34:33 -0600 Subject: [PATCH 271/858] S24FL1: Fix so that the driver compiles with 512 byte block support --- drivers/mtd/s25fl1.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/s25fl1.c b/drivers/mtd/s25fl1.c index 4b061a3ba8..5a89c0d9e8 100644 --- a/drivers/mtd/s25fl1.c +++ b/drivers/mtd/s25fl1.c @@ -302,6 +302,12 @@ #define CLR_DIRTY(p) do { (p)->flags &= ~S25FL1_CACHE_DIRTY; } while (0) #define CLR_ERASED(p) do { (p)->flags &= ~S25FL1_CACHE_DIRTY; } while (0) +/* 512 byte sector support **********************************************************/ + +#define S25FL1_SECTOR512_SHIFT 9 +#define S25FL1_SECTOR512_SIZE (1 << 9) +#define S25FL1_ERASED_STATE 0xff + /************************************************************************************ * Private Types ************************************************************************************/ @@ -1006,9 +1012,15 @@ static int s25fl1_flush_cache(struct s25fl1_dev_s *priv) if (IS_DIRTY(priv) || IS_ERASED(priv)) { + off_t address; + + /* Convert the erase sector numuber into a FLASH address */ + + address = (off_t)priv->esectno << priv->sectorshift; + /* Write entire erase block to FLASH */ - ret = s25fl1_write_page(priv, priv->sector, 1 << priv->sectorshift); + ret = s25fl1_write_page(priv, priv->sector, address, 1 << priv->sectorshift); if (ret < 0) { fdbg("ERROR: s25fl1_write_page failed: %d\n", ret); @@ -1061,8 +1073,8 @@ static FAR uint8_t *s25fl1_read_cache(struct s25fl1_dev_s *priv, off_t sector) /* Read the erase block into the cache */ ret = s25fl1_read_byte(priv, priv->sector, - (esectno << priv->sectorshift) - (1 << priv->sectorshift)); + (esectno << priv->sectorshift), + (1 << priv->sectorshift)); if (ret < 0) { fdbg("ERROR: s25fl1_read_byte failed: %d\n", ret); @@ -1192,6 +1204,9 @@ static int s25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblo { FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; size_t blocksleft = nblocks; +#ifdef CONFIG_S25FL1_SECTOR512 + int ret; +#endif fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); @@ -1232,7 +1247,9 @@ static int s25fl1_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblo static ssize_t s25fl1_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR uint8_t *buffer) { +#ifndef CONFIG_S25FL1_SECTOR512 FAR struct s25fl1_dev_s *priv = (FAR struct s25fl1_dev_s *)dev; +#endif ssize_t nbytes; fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); @@ -1511,7 +1528,7 @@ FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, bool unprot #ifdef CONFIG_S25FL1_SECTOR512 /* Simulate a 512 byte sector */ /* Allocate a buffer for the erase block cache */ - priv->sector = (FAR uint8_t *)QSPI_ALLOC(1 << priv->sectorshift); + priv->sector = (FAR uint8_t *)QSPI_ALLOC(qspi, 1 << priv->sectorshift); if (priv->sector == NULL) { /* Allocation failed! Discard all of that work we just did and return NULL */ -- GitLab From f86ca947985d6ac67c5f2296c96ad6ec73a38370 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 Nov 2015 17:45:06 -0600 Subject: [PATCH 272/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index a1a06e149f..e62ee658d5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a1a06e149f09bc7b1cb7317ba8dc50c730634558 +Subproject commit e62ee658d540523e2a8b5ecdd1832e65e9713dc9 -- GitLab From 2ff1b173f23dc52a9a58102c1a312c344663dece Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Nov 2015 08:15:08 -0600 Subject: [PATCH 273/858] SmartFS: Backout last change. It alters the behavior when it should not. Obviously there is something that I do not understand --- arch | 2 +- configs | 2 +- drivers/mtd/smart.c | 40 +++++++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/arch b/arch index fb42257296..6a3129092c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fb42257296843a19a50cbca004324f1c88a00b8f +Subproject commit 6a3129092ce8ef63c608fa932185873850621aa2 diff --git a/configs b/configs index e62ee658d5..d5c2d3699b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e62ee658d540523e2a8b5ecdd1832e65e9713dc9 +Subproject commit d5c2d3699b337a11ef0e5f204537873e719a97ae diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index d219232855..7965bb0dae 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -220,8 +220,7 @@ struct smart_struct_s uint32_t unusedsectors; /* Count of unused sectors (i.e. free when erased) */ uint32_t blockerases; /* Count of unused sectors (i.e. free when erased) */ #endif - uint32_t neraseblocks; /* Number of erase blocks or sub-sectors */ - uint32_t erasesize; /* Size of an erase block */ + uint16_t neraseblocks; /* Number of erase blocks or sub-sectors */ uint16_t lastallocblock; /* Last block we allocated a sector from */ uint16_t freesectors; /* Total number of free sectors */ uint16_t releasesectors; /* Total number of released sectors */ @@ -229,6 +228,7 @@ struct smart_struct_s uint16_t sectorsPerBlk; /* Number of sectors per erase block */ uint16_t sectorsize; /* Sector size on device */ uint16_t totalsectors; /* Total number of sectors on device */ + uint32_t erasesize; /* Size of an erase block */ FAR uint8_t *releasecount; /* Count of released sectors per erase block */ FAR uint8_t *freecount; /* Count of free sectors per erase block */ FAR char *rwbuffer; /* Our sector read/write buffer */ @@ -924,7 +924,12 @@ static int smart_geometry(FAR struct inode *inode, struct geometry *geometry) geometry->geo_writeenabled = false; #endif - erasesize = dev->geo.erasesize; + erasesize = dev->geo.erasesize; + if (erasesize == 0) + { + erasesize = 262144; + } + geometry->geo_nsectors = dev->geo.neraseblocks * erasesize / dev->sectorsize; geometry->geo_sectorsize = dev->sectorsize; @@ -966,12 +971,21 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) return OK; } - erasesize = dev->geo.erasesize; - dev->neraseblocks = dev->geo.neraseblocks; - dev->erasesize = erasesize; - dev->sectorsize = size; - dev->mtdBlksPerSector = dev->sectorsize / dev->geo.blocksize; + erasesize = dev->geo.erasesize; + dev->neraseblocks = dev->geo.neraseblocks; + /* Most FLASH devices have erase size of 64K, but geo.erasesize is only + * 16 bits, so it will be zero + */ + + if (erasesize == 0) + { + erasesize = 262144; + } + + dev->erasesize = erasesize; + dev->sectorsize = size; + dev->mtdBlksPerSector = dev->sectorsize / dev->geo.blocksize; if (erasesize / dev->sectorsize > 256) { /* We can't throw a dbg message here becasue it is too early. @@ -979,8 +993,8 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) * it during mksmartfs or mount. */ - dev->erasesize = 0; - dev->sectorsPerBlk = 256; + dev->erasesize = 0; + dev->sectorsPerBlk = 256; dev->availSectPerBlk = 255; } else @@ -1000,7 +1014,7 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS) dev->unusedsectors = 0; - dev->blockerases = 0; + dev->blockerases = 0; #endif /* Release any existing rwbuffer and sMap */ @@ -1019,8 +1033,8 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) dev->sBitMap = NULL; } - dev->cache_entries = 0; - dev->cache_lastlog = 0xFFFF; + dev->cache_entries = 0; + dev->cache_lastlog = 0xFFFF; dev->cache_nextbirth = 0; #endif -- GitLab From 9f3edd63732c97a9580fe013191e0e0f8fd6ba22 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Nov 2015 08:25:03 -0600 Subject: [PATCH 274/858] MTD Smart: Remove checks for 64KB erase block size. erasesize was changed to 32-bits in struct mtd_geometry_s --- drivers/mtd/smart.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 7965bb0dae..828924418d 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -924,14 +924,9 @@ static int smart_geometry(FAR struct inode *inode, struct geometry *geometry) geometry->geo_writeenabled = false; #endif - erasesize = dev->geo.erasesize; - if (erasesize == 0) - { - erasesize = 262144; - } - + erasesize = dev->geo.erasesize; geometry->geo_nsectors = dev->geo.neraseblocks * erasesize / - dev->sectorsize; + dev->sectorsize; geometry->geo_sectorsize = dev->sectorsize; fvdbg("available: true mediachanged: false writeenabled: %s\n", @@ -971,21 +966,12 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) return OK; } - erasesize = dev->geo.erasesize; - dev->neraseblocks = dev->geo.neraseblocks; - - /* Most FLASH devices have erase size of 64K, but geo.erasesize is only - * 16 bits, so it will be zero - */ - - if (erasesize == 0) - { - erasesize = 262144; - } - - dev->erasesize = erasesize; - dev->sectorsize = size; + erasesize = dev->geo.erasesize; + dev->neraseblocks = dev->geo.neraseblocks; + dev->erasesize = erasesize; + dev->sectorsize = size; dev->mtdBlksPerSector = dev->sectorsize / dev->geo.blocksize; + if (erasesize / dev->sectorsize > 256) { /* We can't throw a dbg message here becasue it is too early. @@ -2812,14 +2798,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a if (dev->erasesize == 0) { - if (dev->geo.erasesize == 0) - { - dev->erasesize = 262144; - } - else - { - dev->erasesize = dev->geo.erasesize; - } + dev->erasesize = dev->geo.erasesize; dbg("ERROR: Invalid geometery ... Sectors per erase block must be 256 or less\n"); dbg(" Erase block size = %d\n", dev->erasesize); -- GitLab From e62673241d5e8e94c89756fa38572a6736c68afe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Nov 2015 11:02:52 -0600 Subject: [PATCH 275/858] Eliminate some useless comments --- arch | 2 +- include/nuttx/progmem.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/arch b/arch index 6a3129092c..352e3775a0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6a3129092ce8ef63c608fa932185873850621aa2 +Subproject commit 352e3775a07839c6747bd29c151fa61dc938b62a diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h index 7797555052..45cc0cdbe9 100644 --- a/include/nuttx/progmem.h +++ b/include/nuttx/progmem.h @@ -202,11 +202,6 @@ ssize_t up_progmem_ispageerased(size_t page); ssize_t up_progmem_write(size_t addr, const void *buf, size_t count); -/* TODO: Define the following functions and their options: - * - up_progmem_protect() - * - up_progmem_unprotect() - */ - #undef EXTERN #if defined(__cplusplus) } -- GitLab From 7fe6200b0f27d3e0dc817662403019780673800b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Nov 2015 14:30:06 -0600 Subject: [PATCH 276/858] progmem.h: Clean-up a few comments --- arch | 2 +- configs | 2 +- include/nuttx/progmem.h | 26 +++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch b/arch index 352e3775a0..20a3b8c8ce 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 352e3775a07839c6747bd29c151fa61dc938b62a +Subproject commit 20a3b8c8cedd8f5d147dcf01599059c8678b123c diff --git a/configs b/configs index d5c2d3699b..758aa6d236 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d5c2d3699b337a11ef0e5f204537873e719a97ae +Subproject commit 758aa6d23647d98fb1a6064175a8abd6c9cc28b2 diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h index 45cc0cdbe9..f7a52399ee 100644 --- a/include/nuttx/progmem.h +++ b/include/nuttx/progmem.h @@ -99,7 +99,7 @@ size_t up_progmem_pagesize(size_t page); * Address to page conversion * * Input Parameters: - * addr - Address with of without flash offset (absolute or aligned to page0) + * addr - Address with or without flash offset (absolute or aligned to page0) * * Returned Value: * Page or negative value on error. The following errors are reported @@ -141,11 +141,11 @@ size_t up_progmem_getaddress(size_t page); * (errno is not set!): * * EFAULT: On invalid page - * EIO: On unsuccessful erase - * EROFS: On access to write protected area + * EIO: On unsuccessful erase + * EROFS: On access to write protected area * EACCES: Insufficient permissions (read/write protected) - * EPERM: If operation is not permitted due to some other constraints - * (i.e. some internal block is not running etc.) + * EPERM: If operation is not permitted due to some other constraints + * (i.e. some internal block is not running etc.) * ****************************************************************************/ @@ -183,24 +183,24 @@ ssize_t up_progmem_ispageerased(size_t page); * Input Parameters: * addr - Address with or without flash offset (absolute or aligned to page0) * buf - Pointer to buffer - * count - Number of bytes to write * + * count - Number of bytes to write * * Returned Value: * Bytes written or negative value on error. The following errors are * reported (errno is not set!) * - * EINVAL: if count is not aligned with the flash boundaries (i.e. - * some MCU's require per half-word or even word access) + * EINVAL: If count is not aligned with the flash boundaries (i.e. + * some MCU's require per half-word or even word access) * EFAULT: On invalid address - * EIO: On unsuccessful write - * EROFS: On access to write protected area + * EIO: On unsuccessful write + * EROFS: On access to write protected area * EACCES: Insufficient permissions (read/write protected) - * EPERM: If operation is not permitted due to some other constraints - * (i.e. some internal block is not running etc.) + * EPERM: If operation is not permitted due to some other constraints + * (i.e. some internal block is not running etc.) * ****************************************************************************/ -ssize_t up_progmem_write(size_t addr, const void *buf, size_t count); +ssize_t up_progmem_write(size_t addr, FAR const void *buf, size_t count); #undef EXTERN #if defined(__cplusplus) -- GitLab From 4a8626d3326e575132ec1b3a4966d32b1ab10776 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Thu, 12 Nov 2015 07:46:05 -0600 Subject: [PATCH 277/858] CAN: Don't disable TX interrupts if the S/W TX FIFO is empty but the hardware supports a H/W TX FIFO --- arch | 2 +- drivers/can.c | 37 +++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/arch b/arch index 20a3b8c8ce..e9fdaa659e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 20a3b8c8cedd8f5d147dcf01599059c8678b123c +Subproject commit e9fdaa659e239d35b7244c4609ae03cad3221fa4 diff --git a/drivers/can.c b/drivers/can.c index f8a6be2e12..5f65c63bb1 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -531,7 +531,15 @@ static int can_xmit(FAR struct can_dev_s *dev) if (dev->cd_xmit.tx_head == dev->cd_xmit.tx_tail) { DEBUGASSERT(dev->cd_xmit.tx_queue == dev->cd_xmit.tx_head); + + /* We can disable CAN TX interrupts -- unless there is a H/W FIFO. In + * that case, TX interrupts must stay enabled until the H/W FIFO is + * fully emptied. + */ + +#ifndef CONFIG_CAN_TXREADY dev_txint(dev, false); +#endif return -EIO; } @@ -1171,27 +1179,28 @@ int can_txready(FAR struct can_dev_s *dev) if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { - /* Send the next message in the S/W FIFO. In the case where the - * H/W TX FIFO is not empty, this should add one more CAN message - * to the H/W TX FIFO and can_txdone() should be called, making - * space in the S/W FIFO - */ - - (void)can_xmit(dev); - - /* Inform one waiter that new xmit space is available in the S/W FIFO. - * NOTE that is can_txdone() is, indeed, called twice that the tx_sem - * will also be posted twice. This is a little inefficient, but not - * harmful. - */ - /* Are there any threads waiting for space in the xmit FIFO? */ if (dev->cd_ntxwaiters > 0) { + /* Inform one waiter that space is now available in the S/W + * TX FIFO. + */ + ret = sem_post(&dev->cd_xmit.tx_sem); } } + else + { + /* When the H/W FIFO has been emptied, we can disable further TX + * interrupts. + * + * REVISIT: Does the fact that the S/W FIFO is empty also mean + * that the H/W FIFO is also empty? + */ + + dev_txint(dev, false); + } return ret; } -- GitLab From 55686245c15e887db0809a2d19ac9fe4acf3e2c2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Nov 2015 07:53:42 -0600 Subject: [PATCH 278/858] Back out a part of the previous commit --- drivers/can.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/can.c b/drivers/can.c index 5f65c63bb1..2f61d6e0c7 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -1190,17 +1190,23 @@ int can_txready(FAR struct can_dev_s *dev) ret = sem_post(&dev->cd_xmit.tx_sem); } } + +#if 0 /* REVISIT */ + /* REVISIT: Does the fact that the S/W FIFO is empty also mean that the + * H/W FIFO is also empty? If we really want this to work this way, then + * we would probably need and additional parameter to tell us if the H/W + * FIFO is empty. + */ + else { /* When the H/W FIFO has been emptied, we can disable further TX * interrupts. - * - * REVISIT: Does the fact that the S/W FIFO is empty also mean - * that the H/W FIFO is also empty? */ dev_txint(dev, false); } +#endif return ret; } -- GitLab From a40496f424b1a70308c635c76f439cdfe094d917 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Nov 2015 07:59:05 -0600 Subject: [PATCH 279/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index e9fdaa659e..24dc5d2231 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e9fdaa659e239d35b7244c4609ae03cad3221fa4 +Subproject commit 24dc5d2231e14e83abd2fb668e3a0850f7f73fe6 -- GitLab From 5eaf368d16080558c2e187bec4f384cf379b3a6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Nov 2015 12:30:15 -0600 Subject: [PATCH 280/858] progmem.h: Cosmetic updates to comments --- ChangeLog | 5 +++++ arch | 2 +- include/nuttx/progmem.h | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ac723d871..32284f93af 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11076,4 +11076,9 @@ (2015-11-07). * drivers/bch: Block-to-character (BCH) driver should forward ioctl() calls to the contained block driver (2015-11-09). + * arch/arm/samv7/sam_qspi.c: The QuadSPI driver is now functional + (2015-11-10). + * drivers/mtd/s25fl1.c: The S25FL1xx QuadSPI FLASH driver is now + functional (2015-10-11). + * arch/arm/samv7: Add an on-chip FLASH driver (2015-11-12). diff --git a/arch b/arch index 24dc5d2231..8d559bd232 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 24dc5d2231e14e83abd2fb668e3a0850f7f73fe6 +Subproject commit 8d559bd23293adb14d68d7d6111ecbab40986a5a diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h index f7a52399ee..7ba0347da1 100644 --- a/include/nuttx/progmem.h +++ b/include/nuttx/progmem.h @@ -105,7 +105,7 @@ size_t up_progmem_pagesize(size_t page); * Page or negative value on error. The following errors are reported * (errno is not set!): * - * EFAULT: On invalid address + * -EFAULT: On invalid address * ****************************************************************************/ @@ -140,12 +140,12 @@ size_t up_progmem_getaddress(size_t page); * Page size or negative value on error. The following errors are reported * (errno is not set!): * - * EFAULT: On invalid page - * EIO: On unsuccessful erase - * EROFS: On access to write protected area - * EACCES: Insufficient permissions (read/write protected) - * EPERM: If operation is not permitted due to some other constraints - * (i.e. some internal block is not running etc.) + * -EFAULT: On invalid page + * -EIO: On unsuccessful erase + * -EROFS: On access to write protected area + * -EACCES: Insufficient permissions (read/write protected) + * -EPERM: If operation is not permitted due to some other constraints + * (i.e. some internal block is not running etc.) * ****************************************************************************/ @@ -161,11 +161,11 @@ ssize_t up_progmem_erasepage(size_t page); * page - * * Returned Value: - * Returns number of bytes written or negative value on error. If it - * returns zero then complete page is empty (erased). + * Returns number of bytes NOT erased or negative value on error. If it + * returns zero then complete page is erased. * - * The following errors are reported (errno is not set!) - * EFAULT: On invalid page + * The following errors are reported: + * -EFAULT: On invalid page * ****************************************************************************/ -- GitLab From ef59f83a38906748ee2ec894c3c09665c8069c7b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Nov 2015 13:40:18 -0600 Subject: [PATCH 281/858] drivers/mtd/mtd_progmem.c: Add an upper-half driver that can be used with any FLASH library that provides the itnerfaces defined in include/nuttx/progmem.h --- ChangeLog | 3 + drivers/mtd/Kconfig | 8 + drivers/mtd/Make.defs | 6 +- drivers/mtd/mtd_progmem.c | 390 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/skeleton.c | 93 ++++----- include/nuttx/progmem.h | 4 +- 6 files changed, 458 insertions(+), 46 deletions(-) create mode 100644 drivers/mtd/mtd_progmem.c diff --git a/ChangeLog b/ChangeLog index 32284f93af..7a21826d7a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11081,4 +11081,7 @@ * drivers/mtd/s25fl1.c: The S25FL1xx QuadSPI FLASH driver is now functional (2015-10-11). * arch/arm/samv7: Add an on-chip FLASH driver (2015-11-12). + * drivers/mtd/mtd_progmem.c: Add an upper half MTD device that can + use the interfaces defined in included/nuttx/progmem.h to provide + a standard MTD interface (2015-11-12). diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 55b40b4c7f..bacabb0856 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -114,6 +114,14 @@ config MTD_NRDBLOCKS endif # MTD_READAHEAD +config MTD_PROGMEM + bool "Enable on-chip program FLASH MTD device" + default n + ---help--- + Enable to support an MTD device that supports the on-chip FLASH + using the interfaces defined in include/nuttx/progmem. Those + interfaces must be exported by chip-specific logic. + config MTD_CONFIG bool "Enable Dev Config (MTD based) device" default n diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs index cdc9e156cc..bd284d6822 100644 --- a/drivers/mtd/Make.defs +++ b/drivers/mtd/Make.defs @@ -3,7 +3,7 @@ # These driver supports various Memory Technology Devices (MTD) using the # NuttX MTD interface. # -# Copyright (C) 2009-2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2009-2013, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -57,6 +57,10 @@ CSRCS += mtd_rwbuffer.c endif endif +ifeq ($(CONFIG_MTD_PROGMEM),y) +CSRCS += mtd_progmem.c +endif + ifeq ($(CONFIG_MTD_NAND),y) CSRCS += mtd_nand.c mtd_onfi.c mtd_nandscheme.c mtd_nandmodel.c mtd_modeltab.c ifeq ($(CONFIG_MTD_NAND_SWECC),y) diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c new file mode 100644 index 0000000000..7a60c8e1c8 --- /dev/null +++ b/drivers/mtd/mtd_progmem.c @@ -0,0 +1,390 @@ +/**************************************************************************** + * drivers/mtd/mtd_progmem.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This type represents the state of the MTD device. The struct mtd_dev_s + * must appear at the beginning of the definition so that you can freely + * cast between pointers to struct mtd_dev_s and struct progmem_dev_s. + */ + +struct progmem_dev_s +{ + /* Publically visible representation of the interface */ + + struct mtd_dev_s mtd; + + /* Fields unique to the progmem MTD driver */ + + bool initialized; /* True: Already initialized */ + uint8_t blkshift; /* Log2 of the flash block size */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Internal helper functions */ + +static int32_t progmem_log2(size_t blocksize); + +/* MTD driver methods */ + +static int progmem_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks); +static ssize_t progmem_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t progmem_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); +static ssize_t progmem_read(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buffer); +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t progmem_write(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buffer); +#endif +static int progmem_ioctl(FAR struct mtd_dev_s *dev, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ +/* This structure holds the state of the MTD driver */ + +static struct progmem_dev_s g_progmem = +{ + { + progmem_erase, + progmem_bread, + progmem_bwrite, + progmem_read, +#ifdef CONFIG_MTD_BYTE_WRITE + progmem_write, +#endif + progmem_ioctl + } +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: progmem_erase + * + * Description: + * Erase several blocks, each of the size previously reported. + * + ****************************************************************************/ + +static int32_t progmem_log2(uint32_t blocksize) +{ + uint32_t log2 = 0; + + /* Search every bit in the blocksize from bit zero to bit 30 (omitting bit + * 31 which is the sign bit on return) + */ + + for (log2 = 0; log2 < 31; log2++, blocksize >>= 1) + { + /* Is bit zero set? */ + + if ((blocksize & 1) != 0) + { + /* Yes... the value should be exactly one. We do not support + * block sizes that are not exact powers of two. + */ + + return blocksize == 1 ? log2 : -ENOSYS; + } + } + + return blocksize == 0 ? -EINVAL : -E2BIG; +} + +/**************************************************************************** + * Name: progmem_erase + * + * Description: + * Erase several blocks, each of the size previously reported. + * + ****************************************************************************/ + +static int progmem_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks) +{ + ssize_t result; + + /* Erase the specified blocks and return status (OK or a negated errno) */ + + while (nblocks > 0) + { + result = up_progmem_erasepage(startblock); + if (result < 0) + { + return (int)result; + } + + /* Setup for the next pass through the loop */ + + startblock++; + nblocks--; + } + + return OK; +} + +/**************************************************************************** + * Name: progmem_bread + * + * Description: + * Read the specified number of blocks into the user provided buffer. + * + ****************************************************************************/ + +static ssize_t progmem_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buffer) +{ + FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev; + FAR const uint8_t *src; + size_t offset; + + /* Read the specified blocks into the provided user buffer and return + * status (The positive, number of blocks actually read or a negated + * errno). + */ + + offset = startblock << priv->blkshift; + src = (FAR const uint8_t *)up_progmem_getaddress(offset); + memcpy(buffer, src, nblocks << priv->blkshift); + return nblocks; +} + +/**************************************************************************** + * Name: progmem_bwrite + * + * Description: + * Write the specified number of blocks from the user provided buffer. + * + ****************************************************************************/ + +static ssize_t progmem_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buffer) +{ + FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev; + ssize_t result; + + /* Write the specified blocks from the provided user buffer and return status + * (The positive, number of blocks actually written or a negated errno) + */ + + result = up_progmem_write(up_progmem_getaddress(startblock), buffer, + nblocks << priv->blkshift); + return result < 0 ? result : nblocks; +} + +/**************************************************************************** + * Name: progmem_read + * + * Description: + * Read the specified number of bytes to the user provided buffer. + * + ****************************************************************************/ + +static ssize_t progmem_read(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buffer) +{ + FAR const uint8_t *src; + + /* Read the specified bytes into the provided user buffer and return + * status (The positive, number of bytes actually read or a negated + * errno) + */ + + src = (FAR const uint8_t *)up_progmem_getaddress(offset); + memcpy(buffer, src, nbytes); + return nbytes; +} + +/**************************************************************************** + * Name: progmem_write + * + * Description: + * Some FLASH parts have the ability to write an arbitrary number of + * bytes to an arbitrary offset on the device. + * + ****************************************************************************/ + +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t progmem_write(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buffer) +{ + FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev; + ssize_t result; + + /* Write the specified blocks from the provided user buffer and return status + * (The positive, number of blocks actually written or a negated errno) + */ + + result = up_progmem_write(up_progmem_getaddress(offset), buffer, nbytes; + return result < 0 ? result : nbytes; +} +#endif + +/**************************************************************************** + * Name: progmem_ioctl + ****************************************************************************/ + +static int progmem_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev; + int ret = -EINVAL; /* Assume good command with bad parameters */ + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)arg; + if (geo) + { + /* Populate the geometry structure with information needed to know + * the capacity and how to access the device. + * + * NOTE: that the device is treated as though it where just an array + * of fixed size blocks. That is most likely not true, but the client + * will expect the device logic to do whatever is necessary to make it + * appear so. + */ + + geo->blocksize = (1 << priv->blkshift); /* Size of one read/write block */ + geo->erasesize = (1 << priv->blkshift); /* Size of one erase block */ + geo->neraseblocks = up_progmem_npages(); /* Number of erase blocks */ + ret = OK; + } + } + break; + + case MTDIOC_XIPBASE: + { + FAR void **ppv = (FAR void**)arg; + + if (ppv) + { + /* Return (void*) base address of FLASH memory. */ + + *ppv = (FAR void *)up_progmem_getaddress(0); + ret = OK; + } + } + break; + + case MTDIOC_BULKERASE: + { + size_t nblocks = up_progmem_npages(); + + /* Erase the entire device */ + + ret = progmem_erase(dev, 0, nblocks); + } + break; + + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: progmem_initialize + * + * Description: + * Create and initialize an MTD device instance. MTD devices are not + * registered in the file system, but are created as instances that can + * be bound to other functions (such as a block or character driver front + * end). + * + ****************************************************************************/ + +FAR struct mtd_dev_s *progmem_initialize(void) +{ + FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)&g_progmem; + int32_t blkshift; + + /* Perform initialization if necessary */ + + if (!g_progmem.initialized) + { + size_t nblocks = up_progmem_npages(); + blkshift = progmem_log2(nblocks); + + if (blkshift < 0) + { + return NULL; + } + + g_progmem.blkshift = blkshift; + g_progmem.initialized = true; + } + + /* Return the implementation-specific state structure as the MTD device */ + + return (FAR struct mtd_dev_s *)priv; +} diff --git a/drivers/mtd/skeleton.c b/drivers/mtd/skeleton.c index 3740a879e0..f9acf80e1e 100644 --- a/drivers/mtd/skeleton.c +++ b/drivers/mtd/skeleton.c @@ -72,18 +72,20 @@ struct skel_dev_s /* MTD driver methods */ -static int skel_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); -static ssize_t skel_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buf); -static ssize_t skel_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR const uint8_t *buf); -static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer); +static int skel_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks); +static ssize_t skel_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t skel_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); +static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buffer); #ifdef CONFIG_MTD_BYTE_WRITE -static ssize_t skel_write(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR const uint8_t *buffer); +static ssize_t skel_write(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buffer); #endif -static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); +static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd, + unsigned long arg); /**************************************************************************** * Private Data @@ -92,8 +94,9 @@ static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); static struct skel_dev_s g_skeldev = { - { skel_erase, - skel_rbead, + { + skel_erase, + skel_bread, skel_bwrite, skel_read, #ifdef CONFIG_MTD_BYTE_WRITE @@ -101,6 +104,7 @@ static struct skel_dev_s g_skeldev = #endif skel_ioctl }, + /* Initialization of any other implementation specific data goes here */ }; @@ -121,9 +125,9 @@ static int skel_erase(FAR struct mtd_dev_s *dev, off_t startblock, { FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; - /* The interface definition assumes that all erase blocks are the same size. - * If that is not true for this particular device, then transform the - * start block and nblocks as necessary. + /* The interface definition assumes that all erase blocks are the same + * size. If that is not true for this particular device, then transform + * the start block and nblocks as necessary. */ /* Erase the specified blocks and return status (OK or a negated errno) */ @@ -139,18 +143,19 @@ static int skel_erase(FAR struct mtd_dev_s *dev, off_t startblock, * ****************************************************************************/ -static ssize_t skel_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buf) +static ssize_t skel_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf) { FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; - /* The interface definition assumes that all read/write blocks are the same size. - * If that is not true for this particular device, then transform the - * start block and nblocks as necessary. + /* The interface definition assumes that all read/write blocks are the + * same size. If that is not true for this particular device, then + * transform the start block and nblocks as necessary. */ - /* Read the specified blocks into the provided user buffer and return status - * (The positive, number of blocks actually read or a negated errno). + /* Read the specified blocks into the provided user buffer and return + * status (The positive, number of blocks actually read or a negated + * errno). */ return 0; @@ -164,18 +169,19 @@ static ssize_t skel_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nb * ****************************************************************************/ -static ssize_t skel_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR const uint8_t *buf) +static ssize_t skel_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf) { FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; - /* The interface definition assumes that all read/write blocks are the same size. - * If that is not true for this particular device, then transform the - * start block and nblocks as necessary. + /* The interface definition assumes that all read/write blocks are the + * same size. If that is not true for this particular device, then + * transform the start block and nblocks as necessary. */ - /* Write the specified blocks from the provided user buffer and return status - * (The positive, number of blocks actually written or a negated errno) + /* Write the specified blocks from the provided user buffer and return + * status (The positive, number of blocks actually written or a negated + * errno) */ return 0; @@ -189,26 +195,27 @@ static ssize_t skel_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t n * ****************************************************************************/ -static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer) +static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buffer) { FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; /* Some devices may support byte oriented read (optional). Byte-oriented - * writing is inherently block oriented on most MTD devices and is not supported. - * It is recommended that low-level drivers not support read() if it requires - * buffering -- let the higher level logic handle that. If the read method is - * not implemented, just set the method pointer to NULL in the struct mtd_dev_s - * instance. + * writing is inherently block oriented on most MTD devices and is not + * supported. It is recommended that low-level drivers not support read() + * if it requires buffering -- let the higher level logic handle that. If + * the read method is not implemented, just set the method pointer to NULL + * in the struct mtd_dev_s instance. */ - /* The interface definition assumes that all read/write blocks are the same size. - * If that is not true for this particular device, then transform the - * start block and nblocks as necessary. + /* The interface definition assumes that all read/write blocks are the + * same size. If that is not true for this particular device, then + * transform the start block and nblocks as necessary. */ - /* Read the specified blocks into the provided user buffer and return status - * (The positive, number of blocks actually read or a negated errno) + /* Read the specified bytes into the provided user buffer and return + * status (The positive, number of bytes actually read or a negated + * errno) */ return 0; @@ -224,8 +231,8 @@ static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, ****************************************************************************/ #ifdef CONFIG_MTD_BYTE_WRITE -static ssize_t skel_write(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR const uint8_t *buffer) +static ssize_t skel_write(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buffer) { return -ENOSYS; } diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h index 7ba0347da1..a5ed707a61 100644 --- a/include/nuttx/progmem.h +++ b/include/nuttx/progmem.h @@ -134,7 +134,7 @@ size_t up_progmem_getaddress(size_t page); * Erase selected page. * * Input Parameters: - * page - + * page - The page index to be erased. * * Returned Value: * Page size or negative value on error. The following errors are reported @@ -158,7 +158,7 @@ ssize_t up_progmem_erasepage(size_t page); * Checks whether page is erased * * Input Parameters: - * page - + * page - The page index to be checked. * * Returned Value: * Returns number of bytes NOT erased or negative value on error. If it -- GitLab From d54a39832a770c08f4797ca2ee21e655529c2cfa Mon Sep 17 00:00:00 2001 From: Max Neklyudov Date: Thu, 12 Nov 2015 14:16:19 -0600 Subject: [PATCH 282/858] Implement high level DMA infrastructure for serial devices --- ChangeLog | 3 + configs | 2 +- drivers/serial/Kconfig | 136 +++++++++++++++ drivers/serial/serial.c | 47 ++++++ drivers/serial/serialirq.c | 307 +++++++++++++++++++++++++++++----- include/nuttx/serial/serial.h | 102 ++++++++++- 6 files changed, 553 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a21826d7a..6cc87c42c9 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11084,4 +11084,7 @@ * drivers/mtd/mtd_progmem.c: Add an upper half MTD device that can use the interfaces defined in included/nuttx/progmem.h to provide a standard MTD interface (2015-11-12). + * drivers/serial/serial.c, serialirq.c and include/nuttx/serial/serial.h: + Implement high level DMA infrastructure for serial devices. From + Max Neklyudov (2015-11-12). diff --git a/configs b/configs index 758aa6d236..4d23ce39bf 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 758aa6d23647d98fb1a6064175a8abd6c9cc28b2 +Subproject commit 4d23ce39bf6bbf3ca0161ff6247fc9fe1610890f diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 6e7d7865e5..ec333bc0d8 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -540,6 +540,10 @@ config SERIAL_OFLOWCONTROL bool default n +config SERIAL_DMA + bool + default n + config SERIAL_IFLOWCONTROL_WATERMARKS bool "RX flow control watermarks" default n @@ -762,6 +766,13 @@ config UART_OFLOWCONTROL ---help--- Enable UART CTS flow control +config UART_DMA + bool "UART DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART + endmenu menu "UART0 Configuration" @@ -820,6 +831,13 @@ config UART0_OFLOWCONTROL ---help--- Enable UART0 CTS flow control +config UART0_DMA + bool "UART0 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART0 + endmenu menu "USART0 Configuration" @@ -878,6 +896,13 @@ config USART0_OFLOWCONTROL ---help--- Enable USART0 CTS flow control +config USART0_DMA + bool "USART0 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART0 + endmenu menu "UART1 Configuration" @@ -936,6 +961,13 @@ config UART1_OFLOWCONTROL ---help--- Enable UART1 CTS flow control +config UART1_DMA + bool "UART1 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART1 + endmenu menu "USART1 Configuration" @@ -994,6 +1026,13 @@ config USART1_OFLOWCONTROL ---help--- Enable USART1 CTS flow control +config USART1_DMA + bool "USART1 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART1 + endmenu menu "UART2 Configuration" @@ -1052,6 +1091,13 @@ config UART2_OFLOWCONTROL ---help--- Enable UART2 CTS flow control +config UART2_DMA + bool "UART2 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART2 + endmenu menu "USART2 Configuration" @@ -1110,6 +1156,12 @@ config USART2_OFLOWCONTROL ---help--- Enable USART2 CTS flow control +config USART2_DMA + bool "USART2 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART2 endmenu menu "UART3 Configuration" @@ -1168,6 +1220,13 @@ config UART3_OFLOWCONTROL ---help--- Enable UART3 CTS flow control +config UART3_DMA + bool "UART3 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART3 + endmenu menu "USART3 Configuration" @@ -1226,6 +1285,13 @@ config USART3_OFLOWCONTROL ---help--- Enable USART3 CTS flow control +config USART3_DMA + bool "USART3 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART3 + endmenu menu "UART4 Configuration" @@ -1284,6 +1350,13 @@ config UART4_OFLOWCONTROL ---help--- Enable UART4 CTS flow control +config UART4_DMA + bool "UART4 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART4 + endmenu menu "USART4 Configuration" @@ -1342,6 +1415,13 @@ config USART4_OFLOWCONTROL ---help--- Enable USART4 CTS flow control +config USART4_DMA + bool "USART4 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART4 + endmenu menu "UART5 Configuration" @@ -1400,6 +1480,13 @@ config UART5_OFLOWCONTROL ---help--- Enable UART5 CTS flow control +config UART5_DMA + bool "UART5 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART5 + endmenu menu "USART5 Configuration" @@ -1458,6 +1545,13 @@ config USART5_OFLOWCONTROL ---help--- Enable USART5 CTS flow control +config USART5_DMA + bool "USART5 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART5 + endmenu menu "USART6 Configuration" @@ -1516,6 +1610,13 @@ config USART6_OFLOWCONTROL ---help--- Enable USART6 CTS flow control +config USART6_DMA + bool "USART6 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART6 + endmenu menu "UART6 Configuration" @@ -1574,6 +1675,13 @@ config UART6_OFLOWCONTROL ---help--- Enable UART6 CTS flow control +config UART6_DMA + bool "UART6 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART6 + endmenu menu "USART7 Configuration" @@ -1632,6 +1740,13 @@ config USART7_OFLOWCONTROL ---help--- Enable USART7 CTS flow control +config USART7_DMA + bool "USART7 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART7 + endmenu menu "UART7 Configuration" @@ -1690,6 +1805,13 @@ config UART7_OFLOWCONTROL ---help--- Enable UART7 CTS flow control +config UART7_DMA + bool "UART7 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART7 + endmenu menu "USART8 Configuration" @@ -1748,6 +1870,13 @@ config USART8_OFLOWCONTROL ---help--- Enable USART8 CTS flow control +config USART8_DMA + bool "USART8 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on USART8 + endmenu menu "UART8 Configuration" @@ -1806,6 +1935,13 @@ config UART8_OFLOWCONTROL ---help--- Enable UART8 CTS flow control +config UART8_DMA + bool "UART8 DMA support" + default n + select SERIAL_DMA + ---help--- + Enable DMA transfers on UART8 + endmenu menu "SCI0 Configuration" diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 9930810fc7..378a696b4c 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -249,6 +249,9 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) */ dev->xmitwaiting = true; +#ifdef CONFIG_SERIAL_DMA + uart_dmatxavail(dev); +#endif uart_enabletxint(dev); ret = uart_takesem(&dev->xmitsem, true); uart_disabletxint(dev); @@ -507,6 +510,9 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, if (dev->xmit.head != dev->xmit.tail) { +#ifdef CONFIG_SERIAL_DMA + uart_dmatxavail(dev); +#endif uart_enabletxint(dev); } @@ -707,6 +713,20 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen */ flags = irqsave(); + +#ifdef CONFIG_SERIAL_DMA + /* If RX buffer is empty move tail and head to zero position */ + + if (rxbuf->head == rxbuf->tail) + { + rxbuf->head = rxbuf->tail = 0; + } + + /* Notify DMA that there is free space in the RX buffer */ + + uart_dmarxfree(dev); +#endif + uart_enablerxint(dev); #ifdef CONFIG_SERIAL_REMOVABLE @@ -778,6 +798,27 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen } } +#ifdef CONFIG_SERIAL_DMA + flags = irqsave(); + + /* If RX buffer is empty move tail and head to zero position */ + + if (rxbuf->head == rxbuf->tail) + { + rxbuf->head = rxbuf->tail = 0; + } + + irqrestore(flags); + + /* Notify DMA that there is free space in the RX buffer */ + + uart_dmarxfree(dev); + + /* RX interrupt could be disabled by RX buffer overflow. Enable it now. */ + + uart_enablerxint(dev); +#endif + #ifdef CONFIG_SERIAL_IFLOWCONTROL #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS /* How many bytes are now buffered */ @@ -1281,6 +1322,12 @@ static int uart_open(FAR struct file *filep) } #endif +#ifdef CONFIG_SERIAL_DMA + /* Notify DMA that there is free space in the RX buffer */ + + uart_dmarxfree(dev); +#endif + /* Enable the RX interrupt */ uart_enablerxint(dev); diff --git a/drivers/serial/serialirq.c b/drivers/serial/serialirq.c index 3962d985cf..b58867f71d 100644 --- a/drivers/serial/serialirq.c +++ b/drivers/serial/serialirq.c @@ -1,7 +1,7 @@ /************************************************************************************ * drivers/serial/serialirq.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -65,10 +65,269 @@ * Private Functions ************************************************************************************/ +/************************************************************************************ + * Name: uart_dorxflowcontrol + * + * Description: + * Handle RX flow control using watermark levels or not + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS +static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, + FAR struct uart_buffer_s *rxbuf, + unsigned int watermark) +{ + unsigned int nbuffered; + + /* How many bytes are buffered */ + + if (rxbuf->head >= rxbuf->tail) + { + nbuffered = rxbuf->head - rxbuf->tail; + } + else + { + nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; + } + + /* Is the level now above the watermark level that we need to report? */ + + if (nbuffered >= watermark) + { + /* Let the lower level driver know that the watermark level has been + * crossed. It will probably activate RX flow control. + */ + + if (uart_rxflowcontrol(dev, nbuffered, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + return true; + } + } + + return false; +} +#else +static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, + FAR struct uart_buffer_s *rxbuf, + bool is_full) +{ + /* Check if RX buffer is full and allow serial low-level driver to pause + * processing. This allows proper utilization of hardware flow control. + */ + + if (is_full) + { + if (uart_rxflowcontrol(dev, rxbuf->size, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + return true; + } + } + + return false; +} +#endif +#endif + /************************************************************************************ * Public Functions ************************************************************************************/ +/************************************************************************************ + * Name: uart_xmitchars_dma + * + * Description: + * Set up to transfer bytes from the TX circular buffer using DMA + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_xmitchars_dma(FAR uart_dev_t *dev) +{ + FAR struct uart_dmaxfer_s *xfer = &dev->dmatx; + + if (dev->xmit.head == dev->xmit.tail) + { + /* No data to transfer. */ + + return; + } + + if (dev->xmit.tail < dev->xmit.head) + { + xfer->buffer = &dev->xmit.buffer[dev->xmit.tail]; + xfer->length = dev->xmit.head - dev->xmit.tail; + xfer->nbuffer = NULL; + xfer->nlength = 0; + } + else + { + xfer->buffer = &dev->xmit.buffer[dev->xmit.tail]; + xfer->length = dev->xmit.size - dev->xmit.tail; + xfer->nbuffer = dev->xmit.buffer; + xfer->nlength = dev->xmit.head; + } + + uart_dmasend(dev); +} +#endif /* CONFIG_SERIAL_DMA */ + +/************************************************************************************ + * Name: uart_xmitchars_done + * + * Description: + * Perform operations necessary at the complete of DMA including adjusting the + * TX circular buffer indices and waking up of any threads that may have been + * waiting for space to become available in the TX circular buffer. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_xmitchars_done(FAR uart_dev_t *dev) +{ + FAR struct uart_dmaxfer_s *xfer = &dev->dmatx; + size_t nbytes = xfer->nbytes; + struct uart_buffer_s *txbuf = &dev->xmit; + + /* Move tail for nbytes. */ + + txbuf->tail = (txbuf->tail + nbytes) % txbuf->size; + xfer->nbytes = 0; + xfer->length = xfer->nlength = 0; + + /* If any bytes were removed from the buffer, inform any waiters there there is + * space available. + */ + + if (nbytes) + { + uart_datasent(dev); + } +} +#endif /* CONFIG_SERIAL_DMA */ + +/************************************************************************************ + * Name: uart_recvchars_dma + * + * Description: + * Set up to receive bytes into the RX circular buffer using DMA + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_recvchars_dma(FAR uart_dev_t *dev) +{ + FAR struct uart_dmaxfer_s *xfer = &dev->dmarx; + FAR struct uart_buffer_s *rxbuf = &dev->recv; +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + unsigned int watermark; +#endif + bool is_full; + int nexthead = rxbuf->head + 1; + + if (nexthead >= rxbuf->size) + { + nexthead = 0; + } + + is_full = nexthead == rxbuf->tail; + +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + /* Pre-calcuate the watermark level that we will need to test against. */ + + watermark = (CONFIG_SERIAL_IFLOWCONTROL_UPPER_WATERMARK * rxbuf->size) / 100; +#endif + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + if (uart_dorxflowcontrol(dev, rxbuf, watermark)) + { + return; + } +#else + if (uart_dorxflowcontrol(dev, rxbuf, is_full)) + { + return; + } +#endif +#endif + + if (is_full) + { + /* If there is no free space in receive buffer we cannot start DMA + * transfer. + */ + + return; + } + + if (rxbuf->tail <= rxbuf->head) + { + xfer->buffer = &rxbuf->buffer[rxbuf->head]; + xfer->nbuffer = rxbuf->buffer; + + if (rxbuf->tail > 0) + { + xfer->length = rxbuf->size - rxbuf->head; + xfer->nlength = rxbuf->tail - 1; + } + else + { + xfer->length = rxbuf->size - rxbuf->head - 1; + xfer->nlength = 0; + } + } + else + { + xfer->buffer = &rxbuf->buffer[rxbuf->head]; + xfer->length = rxbuf->tail - rxbuf->head - 1; + xfer->nbuffer = NULL; + xfer->nlength = 0; + } + + uart_dmareceive(dev); +} +#endif /* CONFIG_SERIAL_DMA */ + +/************************************************************************************ + * Name: uart_recvchars_done + * + * Description: + * Perform operations necessary at the complete of DMA including adjusting the + * RX circular buffer indices and waking up of any threads that may have been + * waiting for new data to become available in the RX circular buffer. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_recvchars_done(FAR uart_dev_t *dev) +{ + FAR struct uart_dmaxfer_s *xfer = &dev->dmarx; + FAR struct uart_buffer_s *rxbuf = &dev->recv; + size_t nbytes = xfer->nbytes; + + /* Move head for nbytes. */ + + rxbuf->head = (rxbuf->head + nbytes) % rxbuf->size; + xfer->nbytes = 0; + xfer->length = xfer->nlength = 0; + + /* If any bytes were added to the buffer, inform any waiters there is new + * incoming data available. + */ + + if (nbytes) + { + uart_datareceived(dev); + } +} +#endif /* CONFIG_SERIAL_DMA */ + /************************************************************************************ * Name: uart_xmitchars * @@ -145,6 +404,7 @@ void uart_recvchars(FAR uart_dev_t *dev) unsigned int status; int nexthead = rxbuf->head + 1; uint16_t nbytes = 0; + bool is_full; if (nexthead >= rxbuf->size) { @@ -163,52 +423,19 @@ void uart_recvchars(FAR uart_dev_t *dev) while (uart_rxavailable(dev)) { - bool is_full = (nexthead == rxbuf->tail); + is_full = (nexthead == rxbuf->tail); char ch; #ifdef CONFIG_SERIAL_IFLOWCONTROL #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - unsigned int nbuffered; - - /* How many bytes are buffered */ - - if (rxbuf->head >= rxbuf->tail) + if (uart_dorxflowcontrol(dev, rxbuf, watermark)) { - nbuffered = rxbuf->head - rxbuf->tail; - } - else - { - nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; - } - - /* Is the level now above the watermark level that we need to report? */ - - if (nbuffered >= watermark) - { - /* Let the lower level driver know that the watermark level has been - * crossed. It will probably activate RX flow control. - */ - - if (uart_rxflowcontrol(dev, nbuffered, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - break; - } + break; } #else - /* Check if RX buffer is full and allow serial low-level driver to pause - * processing. This allows proper utilization of hardware flow control. - */ - - if (is_full) + if (uart_dorxflowcontrol(dev, rxbuf, is_full)) { - if (uart_rxflowcontrol(dev, rxbuf->size, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - break; - } + break; } #endif #endif @@ -240,7 +467,7 @@ void uart_recvchars(FAR uart_dev_t *dev) } } - /* If any bytes were added to the buffer, inform any waiters there there is new + /* If any bytes were added to the buffer, inform any waiters there is new * incoming data available. */ diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h index 710345511f..493c0d53ba 100644 --- a/include/nuttx/serial/serial.h +++ b/include/nuttx/serial/serial.h @@ -1,7 +1,7 @@ /************************************************************************************ * include/nuttx/serial/serial.h * - * Copyright (C) 2007-2008, 2012-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2012-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -104,9 +104,16 @@ #define uart_send(dev,ch) dev->ops->send(dev,ch) #define uart_receive(dev,s) dev->ops->receive(dev,s) +#ifdef CONFIG_SERIAL_DMA +# define uart_dmasend(dev) dev->ops->dmasend(dev) +# define uart_dmareceive(dev) dev->ops->dmareceive(dev) +# define uart_dmarxfree(dev) dev->ops->dmarxfree(dev) +# define uart_dmatxavail(dev) dev->ops->dmatxavail(dev) +#endif + #ifdef CONFIG_SERIAL_IFLOWCONTROL -#define uart_rxflowcontrol(dev,n,u) \ - (dev->ops->rxflowcontrol && dev->ops->rxflowcontrol(dev,n,u)) +# define uart_rxflowcontrol(dev,n,u) \ + (dev->ops->rxflowcontrol && dev->ops->rxflowcontrol(dev,n,u)) #endif /************************************************************************************ @@ -127,6 +134,17 @@ struct uart_buffer_s FAR char *buffer; /* Pointer to the allocated buffer memory */ }; +#ifdef CONFIG_SERIAL_DMA +struct uart_dmaxfer_s +{ + FAR char *buffer; /* First DMA buffer */ + FAR char *nbuffer; /* Next DMA buffer */ + size_t length; /* Length of first DMA buffer */ + size_t nlength; /* Length of next DMA buffer */ + size_t nbytes; /* Bytes actually transferred by DMA from both buffers */ +}; +#endif /* CONFIG_SERIAL_DMA */ + /* This structure defines all of the operations providd by the architecture specific * logic. All fields must be provided with non-NULL function pointers by the * caller of uart_register(). @@ -199,6 +217,24 @@ struct uart_ops_s unsigned int nbuffered, bool upper); #endif +#ifdef CONFIG_SERIAL_DMA + /* Start transfer bytes from the TX circular buffer using DMA */ + + CODE void (*dmasend)(FAR struct uart_dev_s *dev); + + /* Start transfer bytes from the TX circular buffer using DMA */ + + CODE void (*dmareceive)(FAR struct uart_dev_s *dev); + + /* Notify DMA that there is free space in the RX buffer */ + + CODE void (*dmarxfree)(FAR struct uart_dev_s *dev); + + /* Notify DMA that there is data to be transferred in the TX buffer */ + + CODE void (*dmatxavail)(FAR struct uart_dev_s *dev); +#endif + /* This method will send one byte on the UART */ CODE void (*send)(FAR struct uart_dev_s *dev, int ch); @@ -266,6 +302,14 @@ struct uart_dev_s struct uart_buffer_s xmit; /* Describes transmit buffer */ struct uart_buffer_s recv; /* Describes receive buffer */ +#ifdef CONFIG_SERIAL_DMA + + /* DMA transfers */ + + struct uart_dmaxfer_s dmatx; /* Describes transmit DMA transfer */ + struct uart_dmaxfer_s dmarx; /* Describes receive DMA transfer */ +#endif + /* Driver interface */ FAR const struct uart_ops_s *ops; /* Arch-specific operations */ @@ -385,6 +429,58 @@ void uart_datasent(FAR uart_dev_t *dev); void uart_connected(FAR uart_dev_t *dev, bool connected); #endif +/************************************************************************************ + * Name: uart_xmitchars_dma + * + * Description: + * Set up to transfer bytes from the TX circular buffer using DMA + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_xmitchars_dma(FAR uart_dev_t *dev); +#endif + +/************************************************************************************ + * Name: uart_xmitchars_done + * + * Description: + * Perform operations necessary at the complete of DMA including adjusting the + * TX circular buffer indices and waking up of any threads that may have been + * waiting for space to become available in the TX circular buffer. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_xmitchars_done(FAR uart_dev_t *dev); +#endif + +/************************************************************************************ + * Name: uart_recvchars_dma + * + * Description: + * Set up to receive bytes into the RX circular buffer using DMA + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_recvchars_dma(FAR uart_dev_t *dev); +#endif + +/************************************************************************************ + * Name: uart_recvchars_done + * + * Description: + * Perform operations necessary at the complete of DMA including adjusting the + * RX circular buffer indices and waking up of any threads that may have been + * waiting for new data to become available in the RX circular buffer. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_DMA +void uart_recvchars_done(FAR uart_dev_t *dev); +#endif + #undef EXTERN #if defined(__cplusplus) } -- GitLab From fdb17620a05d3a279651c9a4bffaddba60f7deb7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Nov 2015 16:03:24 -0600 Subject: [PATCH 283/858] Need a prototype for progmem_initialize in include/nuttx/mtd/mtd.h --- configs | 2 +- drivers/mtd/mtd_progmem.c | 10 ++++++---- include/nuttx/mtd/mtd.h | 25 ++++++++++++++++--------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/configs b/configs index 4d23ce39bf..0282533628 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4d23ce39bf6bbf3ca0161ff6247fc9fe1610890f +Subproject commit 028253362897e3ca895cf772dc817423842e8915 diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c index 7a60c8e1c8..6fde9e6975 100644 --- a/drivers/mtd/mtd_progmem.c +++ b/drivers/mtd/mtd_progmem.c @@ -356,10 +356,12 @@ static int progmem_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * Name: progmem_initialize * * Description: - * Create and initialize an MTD device instance. MTD devices are not - * registered in the file system, but are created as instances that can - * be bound to other functions (such as a block or character driver front - * end). + * Create and initialize an MTD device instance that can be used to access + * on-chip program memory. + * + * MTD devices are not registered in the file system, but are created as + * instances that can be bound to other functions (such as a block or + * character driver front end). * ****************************************************************************/ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 7f4e8f8340..fca8cac94a 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -336,24 +336,31 @@ int smart_initialize(int minor, FAR struct mtd_dev_s *mtd, * functions (such as a block or character driver front end). */ -/************************************************************************************ +/**************************************************************************** * Name: s512_initialize * * Description: - * Create an initialized MTD device instance. This MTD driver contains another - * MTD driver and converts a larger sector size to a standard 512 byte sector - * size. - * - * MTD devices are not registered in the file system, but are created as instances - * that can be bound to other functions (such as a block or character driver front - * end). + * Create an initialized MTD device instance. This MTD driver contains + * another MTD driver and converts a larger sector size to a standard 512 + * byte sector size. * - ************************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_MTD_SECT512 FAR struct mtd_dev_s *s512_initialize(FAR struct mtd_dev_s *mtd); #endif +/**************************************************************************** + * Name: progmem_initialize + * + * Description: + * Create and initialize an MTD device instance that can be used to access + * on-chip program memory. + * + ****************************************************************************/ + +FAR struct mtd_dev_s *progmem_initialize(void); + /**************************************************************************** * Name: at45db_initialize * -- GitLab From 2706b4f8aace2478658b831193b03618c03fdafc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 13 Nov 2015 09:19:25 -0600 Subject: [PATCH 284/858] mtd_progmem.c: Fix calculation of block size --- arch | 2 +- configs | 2 +- drivers/mtd/mtd_progmem.c | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 8d559bd232..24f87df3fa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8d559bd23293adb14d68d7d6111ecbab40986a5a +Subproject commit 24f87df3fa8d9fec9044e2c2bb37d12260fd02de diff --git a/configs b/configs index 0282533628..2a4b5e665a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 028253362897e3ca895cf772dc817423842e8915 +Subproject commit 2a4b5e665ac98b72920739eb12144462ca38e675 diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c index 6fde9e6975..ac9be0f497 100644 --- a/drivers/mtd/mtd_progmem.c +++ b/drivers/mtd/mtd_progmem.c @@ -374,14 +374,23 @@ FAR struct mtd_dev_s *progmem_initialize(void) if (!g_progmem.initialized) { - size_t nblocks = up_progmem_npages(); - blkshift = progmem_log2(nblocks); + /* Get the size of one block. Here we assume that the block size is + * uniform and that the size of block0 is the same as the size of any + * other block. + */ + size_t blocksize = up_progmem_pagesize(0); + + /* Calculate Log2 of the flash block size */ + + blkshift = progmem_log2(blocksize); if (blkshift < 0) { return NULL; } + /* Save the configuration data */ + g_progmem.blkshift = blkshift; g_progmem.initialized = true; } -- GitLab From 8242600e5e52baf8683263c750ff54a9e5d44b42 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Fri, 13 Nov 2015 16:28:46 +0100 Subject: [PATCH 285/858] WIP for pca9555 irq --- drivers/discrete/pca9555.c | 71 +++++++++++++++++--------------- drivers/discrete/pca9555.h | 1 - include/nuttx/discrete/pca9555.h | 3 -- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/drivers/discrete/pca9555.c b/drivers/discrete/pca9555.c index ae5c117d8a..da8a385d6b 100644 --- a/drivers/discrete/pca9555.c +++ b/drivers/discrete/pca9555.c @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -437,21 +438,6 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, #ifndef CONFIG_PCA9555_INT_DISABLE -/**************************************************************************** - * Name: pca9555_gpioworker - * - * Description: - * See include/nuttx/discrete/ioexpander.h - * - ****************************************************************************/ - -static int pca9555_attach(FAR struct ioexpander_dev_s *dev, uint8_t pin, - ioexpander_handler_t handler) -{ - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return 0; -} - /**************************************************************************** * Name: pca9555_irqworker * @@ -461,32 +447,46 @@ static int pca9555_attach(FAR struct ioexpander_dev_s *dev, uint8_t pin, * ****************************************************************************/ -static void pca9555_irqworker(FAR struct pca9555_dev_s *priv) +static void pca9555_irqworker(void *arg) { - uint8_t regval; - uint8_t pinmask; - int pin; + uint8_t addr = PCA9555_REG_INPUT; + uint8_t buf[2]; + int ret; + FAR struct pca9555_dev_s *dev = (FAR struct pca9555_dev_s*)arg; - /* Get the set of pending GPIO interrupts */ + /* read inputs */ + ret = I2C_WRITEREAD(dev->i2c, &addr, 1, buf, 2); + dbg("> %02X %02X\n",buf[0],buf[1]); - /* Look at each pin */ + /* re-enable */ + dev->config->enable(dev->config, TRUE); +} - for (pin = 0; pin < PCA9555_GPIO_NPINS; pin++) - { - /* Check if we have a handler for this interrupt (there should - * be one) - */ +static int pca9555_interrupt(int irq, FAR void *context) +{ + /* To support multiple devices, + * retrieve the priv structure using the irq number */ - /* Interrupt is pending... dispatch the interrupt to the - * callback - */ + register FAR struct pca9555_dev_s *dev = &g_pca9555; - /* Clear the pending GPIO interrupt by writing a '1' to the - * pin position in the status register. - */ + /* In complex environments, we cannot do I2C transfers from the interrupt + * handler because semaphores are probably used to lock the I2C bus. In + * this case, we will defer processing to the worker thread. This is also + * much kinder in the use of system resources and is, therefore, probably + * a good thing to do in any event. + */ - } + DEBUGASSERT(work_available(&dev->work)); + + /* Notice that further GPIO interrupts are disabled until the work is + * actually performed. This is to prevent overrun of the worker thread. + * Interrupts are re-enabled in pca9555_irqworker() when the work is completed. + */ + + dev->config->enable(dev->config, FALSE); + return work_queue(HPWORK, &dev->work, pca9555_irqworker, (FAR void *)dev, 0); } + #endif /**************************************************************************** @@ -536,6 +536,7 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_dev_s *i2cdev, pcadev->i2c = i2cdev; pcadev->dev.ops = &g_pca9555_ops; + pcadev->config = config; /* Set the I2C address and frequency. REVISIT: This logic would be * insufficient if we share the I2C bus with any other devices that also @@ -545,6 +546,10 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_dev_s *i2cdev, I2C_SETADDRESS(i2cdev, config->address, 7); I2C_SETFREQUENCY(i2cdev, config->frequency); +#ifndef CONFIG_PCA9555_INT_DISABLE + pcadev->config->attach(pcadev->config, pca9555_interrupt); + pcadev->config->enable(pcadev->config, TRUE); +#endif return &pcadev->dev; } diff --git a/drivers/discrete/pca9555.h b/drivers/discrete/pca9555.h index 2586937c83..4819e0f880 100644 --- a/drivers/discrete/pca9555.h +++ b/drivers/discrete/pca9555.h @@ -134,7 +134,6 @@ struct pca9555_dev_s #ifndef CONFIG_PCA9555_INT_DISABLE struct work_s work; /* Supports the interrupt handling "bottom half" */ - pca9555_handler_t handlers[PCA9555_GPIO_NPINS]; /* GPIO "interrupt handlers" */ #endif }; diff --git a/include/nuttx/discrete/pca9555.h b/include/nuttx/discrete/pca9555.h index fea1bdb3d4..5f71c02dbd 100644 --- a/include/nuttx/discrete/pca9555.h +++ b/include/nuttx/discrete/pca9555.h @@ -63,7 +63,6 @@ struct pca9555_config_s */ #ifndef CONFIG_PCA9555_INT_DISABLE -/* IRQ support TODO */ #ifdef CONFIG_PCA9555_MULTIPLE int irq; /* IRQ number received by interrupt handler. */ @@ -75,12 +74,10 @@ struct pca9555_config_s * * attach - Attach the PCA9555 interrupt handler to the GPIO interrupt * enable - Enable or disable the GPIO interrupt - * clear - Acknowledge/clear any pending GPIO interrupt */ CODE int (*attach)(FAR struct pca9555_config_s *state, xcpt_t isr); CODE void (*enable)(FAR struct pca9555_config_s *state, bool enable); - CODE void (*clear)(FAR struct pca9555_config_s *state); #endif }; -- GitLab From 015429684fec77264bc686cdc9851b1f92607fa1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 13 Nov 2015 11:32:34 -0600 Subject: [PATCH 286/858] MTD progmem: Fix an address calculation --- arch | 2 +- drivers/mtd/ftl.c | 2 +- drivers/mtd/mtd_progmem.c | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 24f87df3fa..1c26392beb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 24f87df3fa8d9fec9044e2c2bb37d12260fd02de +Subproject commit 1c26392bebcb3135b214e12594b701c172bd1236 diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index a0260a1f4d..6ed8529ac3 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -329,7 +329,7 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, buffer += dev->geo.erasesize; } - /* Finally, handler any partial blocks after the last full erase block */ + /* Finally, handle any partial blocks after the last full erase block */ if (remaining > 0) { diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c index ac9be0f497..8fcda67aae 100644 --- a/drivers/mtd/mtd_progmem.c +++ b/drivers/mtd/mtd_progmem.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -199,15 +200,13 @@ static ssize_t progmem_bread(FAR struct mtd_dev_s *dev, off_t startblock, { FAR struct progmem_dev_s *priv = (FAR struct progmem_dev_s *)dev; FAR const uint8_t *src; - size_t offset; /* Read the specified blocks into the provided user buffer and return * status (The positive, number of blocks actually read or a negated * errno). */ - offset = startblock << priv->blkshift; - src = (FAR const uint8_t *)up_progmem_getaddress(offset); + src = (FAR const uint8_t *)up_progmem_getaddress(startblock); memcpy(buffer, src, nblocks << priv->blkshift); return nblocks; } -- GitLab From 4a7fb2cbc17165e8df7311ec5fe00d567082de59 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 14 Nov 2015 07:29:47 -0600 Subject: [PATCH 287/858] binfmt: Cosmetic -- rename binfmt_internal.h to binfmt.h. Move related argument copy logic into new file, binfmt_copyargv.c --- binfmt/Makefile | 2 +- binfmt/{binfmt_internal.h => binfmt.h} | 28 +++- binfmt/binfmt_copyargv.c | 197 +++++++++++++++++++++++++ binfmt/binfmt_dumpmodule.c | 2 +- binfmt/binfmt_exec.c | 121 +-------------- binfmt/binfmt_execmodule.c | 2 +- binfmt/binfmt_loadmodule.c | 2 +- binfmt/binfmt_register.c | 2 +- binfmt/binfmt_schedunload.c | 2 +- binfmt/binfmt_unloadmodule.c | 35 +---- binfmt/binfmt_unregister.c | 2 +- configs | 2 +- 12 files changed, 231 insertions(+), 166 deletions(-) rename binfmt/{binfmt_internal.h => binfmt.h} (82%) create mode 100644 binfmt/binfmt_copyargv.c diff --git a/binfmt/Makefile b/binfmt/Makefile index c5cfe9736b..9da55ea973 100644 --- a/binfmt/Makefile +++ b/binfmt/Makefile @@ -46,7 +46,7 @@ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)sched"} BINFMT_ASRCS = BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c -BINFMT_CSRCS += binfmt_exec.c binfmt_dumpmodule.c +BINFMT_CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_dumpmodule.c ifeq ($(CONFIG_BINFMT_EXEPATH),y) BINFMT_CSRCS += binfmt_exepath.c diff --git a/binfmt/binfmt_internal.h b/binfmt/binfmt.h similarity index 82% rename from binfmt/binfmt_internal.h rename to binfmt/binfmt.h index 11b036fe74..370ef57eae 100644 --- a/binfmt/binfmt_internal.h +++ b/binfmt/binfmt.h @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/binfmt_internal.h + * binfmt/binfmt.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __BINFMT_BINFMT_INTERNAL_H -#define __BINFMT_BINFMT_INTERNAL_H +#ifndef __BINFMT_BINFMT_H +#define __BINFMT_BINFMT_H /**************************************************************************** * Included Files @@ -92,6 +92,26 @@ int dump_module(FAR const struct binary_s *bin); # define dump_module(bin) #endif +/**************************************************************************** + * Name: binfmt_copyargv + * + * Description: + * In the kernel build, the argv list will likely lie in the caller's + * address environment and, hence, by inaccessible when we swith to the + * address environment of the new process address environment. So we + * do not have any real option other than to copy the callers argv[] list. + * + * Input Parameter: + * bin - Load structure + * argv - Argument list + * + * Returned Value: + * Zero (OK) on sucess; a negater erro value on failure. + * + ****************************************************************************/ + +int binfmt_copyargv(FAR struct binary_s *bin, FAR char * const *argv); + /**************************************************************************** * Name: binfmt_freeargv * @@ -117,5 +137,5 @@ void binfmt_freeargv(FAR struct binary_s *bin); } #endif -#endif /* __BINFMT_BINFMT_INTERNAL_H */ +#endif /* __BINFMT_BINFMT_H */ diff --git a/binfmt/binfmt_copyargv.c b/binfmt/binfmt_copyargv.c new file mode 100644 index 0000000000..2fee46d047 --- /dev/null +++ b/binfmt/binfmt_copyargv.c @@ -0,0 +1,197 @@ +/**************************************************************************** + * binfmt/binfmt_copyargv.c + * + * Copyright (C) 2009, 2013-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "binfmt.h" + +#ifndef CONFIG_BINFMT_DISABLE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* This is an artificial limit to detect error conditions where an argv[] + * list is not properly terminated. + */ + +#define MAX_EXEC_ARGS 256 + +/**************************************************************************** + * Public Function + ****************************************************************************/ + +/**************************************************************************** + * Name: binfmt_copyargv + * + * Description: + * In the kernel build, the argv list will likely lie in the caller's + * address environment and, hence, by inaccessible when we switch to the + * address environment of the new process address environment. So we + * do not have any real option other than to copy the callers argv[] list. + * + * Input Parameter: + * bin - Load structure + * argv - Argument list + * + * Returned Value: + * Zero (OK) on sucess; a negater erro value on failure. + * + ****************************************************************************/ + +int binfmt_copyargv(FAR struct binary_s *bin, FAR char * const *argv) +{ +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) + FAR char *ptr; + size_t argvsize; + size_t argsize; + int nargs; + int i; + + /* Get the number of arguments and the size of the argument list */ + + bin->argv = (FAR char **)NULL; + bin->argbuffer = (FAR char *)NULL; + + if (argv) + { + argsize = 0; + nargs = 0; + + for (i = 0; argv[i]; i++) + { + /* Increment the size of the allocation with the size of the next string */ + + argsize += (strlen(argv[i]) + 1); + nargs++; + + /* This is a sanity check to prevent running away with an unterminated + * argv[] list. MAX_EXEC_ARGS should be sufficiently large that this + * never happens in normal usage. + */ + + if (nargs > MAX_EXEC_ARGS) + { + bdbg("ERROR: Too many arguments: %lu\n", (unsigned long)argvsize); + return -E2BIG; + } + } + + bvdbg("args=%d argsize=%lu\n", nargs, (unsigned long)argsize); + + /* Allocate the argv array and an argument buffer */ + + if (argsize > 0) + { + argvsize = (nargs + 1) * sizeof(FAR char *); + bin->argbuffer = (FAR char *)kmm_malloc(argvsize + argsize); + if (!bin->argbuffer) + { + bdbg("ERROR: Failed to allocate the argument buffer\n"); + return -ENOMEM; + } + + /* Copy the argv list */ + + bin->argv = (FAR char **)bin->argbuffer; + ptr = bin->argbuffer + argvsize; + for (i = 0; argv[i]; i++) + { + bin->argv[i] = ptr; + argsize = strlen(argv[i]) + 1; + memcpy(ptr, argv[i], argsize); + ptr += argsize; + } + + /* Terminate the argv[] list */ + + bin->argv[i] = (FAR char *)NULL; + } + } + + return OK; + +#else + /* Just save the caller's argv pointer */ + + bin->argv = argv; + return OK; +#endif +} + +/**************************************************************************** + * Name: binfmt_freeargv + * + * Description: + * Release the copied argv[] list. + * + * Input Parameter: + * binp - Load structure + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) +void binfmt_freeargv(FAR struct binary_s *binp) +{ + /* Is there an allocated argument buffer */ + + if (binp->argbuffer) + { + /* Free the argument buffer */ + + kmm_free(binp->argbuffer); + } + + /* Nullify the allocated argv[] array and the argument buffer pointers */ + + binp->argbuffer = (FAR char *)NULL; + binp->argv = (FAR char **)NULL; +} +#endif + +#endif /* !CONFIG_BINFMT_DISABLE */ diff --git a/binfmt/binfmt_dumpmodule.c b/binfmt/binfmt_dumpmodule.c index 59ed17a94e..c69fed83c4 100644 --- a/binfmt/binfmt_dumpmodule.c +++ b/binfmt/binfmt_dumpmodule.c @@ -45,7 +45,7 @@ #include -#include "binfmt_internal.h" +#include "binfmt.h" #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) && !defined(CONFIG_BINFMT_DISABLE) diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c index 3f866fe99a..f3f62027eb 100644 --- a/binfmt/binfmt_exec.c +++ b/binfmt/binfmt_exec.c @@ -46,129 +46,10 @@ #include #include -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* This is an artificial limit to detect error conditions where an argv[] - * list is not properly terminated. - */ - -#define MAX_EXEC_ARGS 256 - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: binfmt_copyargv - * - * Description: - * In the kernel build, the argv list will likely lie in the caller's - * address environment and, hence, by inaccessible when we swith to the - * address environment of the new process address environment. So we - * do not have any real option other than to copy the callers argv[] list. - * - * Input Parameter: - * bin - Load structure - * argv - Argument list - * - * Returned Value: - * Zero (OK) on sucess; a negater erro value on failure. - * - ****************************************************************************/ - -static inline int binfmt_copyargv(FAR struct binary_s *bin, FAR char * const *argv) -{ -#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) - FAR char *ptr; - size_t argvsize; - size_t argsize; - int nargs; - int i; - - /* Get the number of arguments and the size of the argument list */ - - bin->argv = (FAR char **)NULL; - bin->argbuffer = (FAR char *)NULL; - - if (argv) - { - argsize = 0; - nargs = 0; - - for (i = 0; argv[i]; i++) - { - /* Increment the size of the allocation with the size of the next string */ - - argsize += (strlen(argv[i]) + 1); - nargs++; - - /* This is a sanity check to prevent running away with an unterminated - * argv[] list. MAX_EXEC_ARGS should be sufficiently large that this - * never happens in normal usage. - */ - - if (nargs > MAX_EXEC_ARGS) - { - bdbg("ERROR: Too many arguments: %lu\n", (unsigned long)argvsize); - return -E2BIG; - } - } - - bvdbg("args=%d argsize=%lu\n", nargs, (unsigned long)argsize); - - /* Allocate the argv array and an argument buffer */ - - if (argsize > 0) - { - argvsize = (nargs + 1) * sizeof(FAR char *); - bin->argbuffer = (FAR char *)kmm_malloc(argvsize + argsize); - if (!bin->argbuffer) - { - bdbg("ERROR: Failed to allocate the argument buffer\n"); - return -ENOMEM; - } - - /* Copy the argv list */ - - bin->argv = (FAR char **)bin->argbuffer; - ptr = bin->argbuffer + argvsize; - for (i = 0; argv[i]; i++) - { - bin->argv[i] = ptr; - argsize = strlen(argv[i]) + 1; - memcpy(ptr, argv[i], argsize); - ptr += argsize; - } - - /* Terminate the argv[] list */ - - bin->argv[i] = (FAR char *)NULL; - } - } - - return OK; - -#else - /* Just save the caller's argv pointer */ - - bin->argv = argv; - return OK; -#endif -} - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index f8701be8ce..971c47123c 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -53,7 +53,7 @@ #include #include "sched/sched.h" -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE diff --git a/binfmt/binfmt_loadmodule.c b/binfmt/binfmt_loadmodule.c index 83868460a6..1b614838e6 100644 --- a/binfmt/binfmt_loadmodule.c +++ b/binfmt/binfmt_loadmodule.c @@ -46,7 +46,7 @@ #include #include -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE diff --git a/binfmt/binfmt_register.c b/binfmt/binfmt_register.c index 925f29353f..48ddfc1daa 100644 --- a/binfmt/binfmt_register.c +++ b/binfmt/binfmt_register.c @@ -46,7 +46,7 @@ #include -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE diff --git a/binfmt/binfmt_schedunload.c b/binfmt/binfmt_schedunload.c index 89d5815918..b9c6a9d6d1 100644 --- a/binfmt/binfmt_schedunload.c +++ b/binfmt/binfmt_schedunload.c @@ -46,7 +46,7 @@ #include #include -#include "binfmt_internal.h" +#include "binfmt.h" #if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_SCHED_HAVE_PARENT) diff --git a/binfmt/binfmt_unloadmodule.c b/binfmt/binfmt_unloadmodule.c index 535942b0f6..887d6d66c0 100644 --- a/binfmt/binfmt_unloadmodule.c +++ b/binfmt/binfmt_unloadmodule.c @@ -48,7 +48,7 @@ #include #include -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE @@ -211,38 +211,5 @@ int unload_module(FAR struct binary_s *binp) return OK; } -/**************************************************************************** - * Name: binfmt_freeargv - * - * Description: - * Release the copied argv[] list. - * - * Input Parameter: - * binp - Load structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) -void binfmt_freeargv(FAR struct binary_s *binp) -{ - /* Is there an allocated argument buffer */ - - if (binp->argbuffer) - { - /* Free the argument buffer */ - - kmm_free(binp->argbuffer); - } - - /* Nullify the allocated argv[] array and the argument buffer pointers */ - - binp->argbuffer = (FAR char *)NULL; - binp->argv = (FAR char **)NULL; -} -#endif - #endif /* CONFIG_BINFMT_DISABLE */ diff --git a/binfmt/binfmt_unregister.c b/binfmt/binfmt_unregister.c index f895e354d0..f97b06ff2d 100644 --- a/binfmt/binfmt_unregister.c +++ b/binfmt/binfmt_unregister.c @@ -46,7 +46,7 @@ #include -#include "binfmt_internal.h" +#include "binfmt.h" #ifndef CONFIG_BINFMT_DISABLE diff --git a/configs b/configs index 2a4b5e665a..95afbd39b4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2a4b5e665ac98b72920739eb12144462ca38e675 +Subproject commit 95afbd39b42d2689c894fdfc4e8b6123446772a9 -- GitLab From 81ab270a96eb67a365c7285882c94cca1164b54e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 14 Nov 2015 10:33:02 -0600 Subject: [PATCH 288/858] CAN driver: Removing call to can_xmit() from can_txready() in a previous commit was a mistake. This commit restores the call to can_xmit(), but does the call in a safer environment on the work thread. --- drivers/Kconfig | 17 ++++++ drivers/can.c | 133 ++++++++++++++++++++++++++++++++++++++------ include/nuttx/can.h | 13 +++++ 3 files changed, 146 insertions(+), 17 deletions(-) diff --git a/drivers/Kconfig b/drivers/Kconfig index 2ead84ff1f..ab903e5c9c 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -128,6 +128,7 @@ config CAN_NPENDINGRTR config CAN_TXREADY bool "can_txready interface" default n + select SCHED_WORKQUEUE ---help--- This selection enables the can_txready() interface. This interface is needed only for CAN hardware that supports queing of outgoing @@ -173,6 +174,22 @@ config CAN_TXREADY no longer full. can_txready() will then awaken the can_write() logic and the hang condition is avoided. +choice + prompt "TX Ready Work Queue" + default CAN_TXREADY_LOPRI if SCHED_LPWORK + default CAN_TXREADY_HIPRI if !SCHED_LPWORK + depends on CAN_TXREADY + +config CAN_TXREADY_LOPRI + bool "Low-priority work queue" + select SCHED_LPWORK + +config CAN_TXREADY_HIPRI + bool "High-priority work queue" + select SCHED_HPWORK + +endchoice # TX Ready Work Queue + config CAN_LOOPBACK bool "CAN loopback mode" default n diff --git a/drivers/can.c b/drivers/can.c index 2f61d6e0c7..aea5959c3e 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -54,6 +54,10 @@ #include #include +#ifdef CONFIG_CAN_TXREADY +# include +#endif + #include #ifdef CONFIG_CAN @@ -61,6 +65,37 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifdef CONFIG_CAN_TXREADY +# if !defined(CONFIG_SCHED_WORKQUEUE) +# error Work queue support required in this configuration +# undef CONFIG_CAN_TXREADY +# undef CONFIG_CAN_TXREADY_LOPRI +# undef CONFIG_CAN_TXREADY_HIPRI +# elif defined(CONFIG_CAN_TXREADY_LOPRI) +# undef CONFIG_CAN_TXREADY_HIPRI +# ifdef CONFIG_SCHED_LPWORK +# define CANWORK LPWORK +# else +# error Low priority work queue support required in this configuration +# undef CONFIG_CAN_TXREADY +# undef CONFIG_CAN_TXREADY_LOPRI +# endif +# elif defined(CONFIG_CAN_TXREADY_HIPRI) +# ifdef CONFIG_SCHED_HPWORK +# define CANWORK HPWORK +# else +# error High priority work queue support required in this configuration +# undef CONFIG_CAN_TXREADY +# undef CONFIG_CAN_TXREADY_HIPRI +# endif +# else +# error No work queue selection +# undef CONFIG_CAN_TXREADY +# endif +#endif + /* Debug ********************************************************************/ /* Non-standard debug that may be enabled just for testing CAN */ @@ -95,6 +130,9 @@ static uint8_t can_dlc2bytes(uint8_t dlc); #if 0 /* Not used */ static uint8_t can_bytes2dlc(uint8_t nbytes); #endif +#ifdef CONFIG_CAN_TXREADY +static void can_txready_work(FAR void *arg); +#endif /* Character driver methods */ @@ -246,6 +284,50 @@ static uint8_t can_bytes2dlc(FAR struct sam_can_s *priv, uint8_t nbytes) } #endif +/**************************************************************************** + * Name: can_txready_work + * + * Description: + * This function performs deferred processing from can_txready. See the + * discription of can_txready below for additionla information. + * + ****************************************************************************/ + +#ifdef CONFIG_CAN_TXREADY +static void can_txready_work(FAR void *arg) +{ + FAR struct can_dev_s *dev = (FAR struct can_dev_s *)arg; + irqstate_t flags; + + canllvdbg("xmit head: %d queue: %d tail: %d\n", + dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, + dev->cd_xmit.tx_tail); + + /* Verify that the xmit FIFO is not empty. The following operations must + * be performed with interrupt disabled. + */ + + flags = irqsave(); + if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) + { + /* Send the next message in the FIFO. */ + + (void)can_xmit(dev); + + /* Are there any threads waiting for space in the TX FIFO? */ + + if (dev->cd_ntxwaiters > 0) + { + /* Yes.. Inform them that new xmit space is available */ + + (void)sem_post(&dev->cd_xmit.tx_sem); + } + } + + irqrestore(flags); +} +#endif + /**************************************************************************** * Name: can_open * @@ -532,12 +614,12 @@ static int can_xmit(FAR struct can_dev_s *dev) { DEBUGASSERT(dev->cd_xmit.tx_queue == dev->cd_xmit.tx_head); +#ifndef CONFIG_CAN_TXREADY /* We can disable CAN TX interrupts -- unless there is a H/W FIFO. In * that case, TX interrupts must stay enabled until the H/W FIFO is * fully emptied. */ -#ifndef CONFIG_CAN_TXREADY dev_txint(dev, false); #endif return -EIO; @@ -1036,9 +1118,11 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * 2b. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO full * * In this case, the thread calling can_write() is blocked waiting for - * space in the S/W TX FIFO. + * space in the S/W TX FIFO. can_txdone() will be called, indirectly, + * from can_txready_work() running on the thread of the work queue. * - * CAN interrupt -> can_txready() -> can_xmit() -> dev_send() -> can_txdone() + * CAN interrupt -> can_txready() -> Schedule can_txready_work() + * can_txready_work() -> can_xmit() -> dev_send() -> can_txdone() * * The call dev_send() should not fail in this case and the subsequent * call to can_txdone() will make space in the S/W TX FIFO and will @@ -1179,34 +1263,49 @@ int can_txready(FAR struct can_dev_s *dev) if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { - /* Are there any threads waiting for space in the xmit FIFO? */ + /* Is work already scheduled? */ - if (dev->cd_ntxwaiters > 0) + if (work_available(&dev->cd_work)) { - /* Inform one waiter that space is now available in the S/W - * TX FIFO. + /* Yes... schedule to perform can_txready() work on the worker + * thread. Although data structures are protected by disabling + * interrupts, the can_xmit() operations may involve semaphore + * operations and, hence, should not be done at the interrupt + * level. */ - ret = sem_post(&dev->cd_xmit.tx_sem); + ret = work_queue(CANWORK, &dev->cd_work, can_txready_work, dev, 0); + } + else + { + ret = -EBUSY; } } - -#if 0 /* REVISIT */ - /* REVISIT: Does the fact that the S/W FIFO is empty also mean that the - * H/W FIFO is also empty? If we really want this to work this way, then - * we would probably need and additional parameter to tell us if the H/W - * FIFO is empty. - */ - else { + /* There should not be any threads waiting for space in the S/W TX + * FIFO is it is empty. + * + * REVISIT: Assertion can fire in certain race conditions, i.e, when + * all waiters have been awakened but have not yet had a chance to + * decrement cd_ntxwaiters. + */ + + //DEBUGASSERT(dev->cd_ntxwaiters == 0); + +#if 0 /* REVISIT */ /* When the H/W FIFO has been emptied, we can disable further TX * interrupts. + * + * REVISIT: The fact that the S/W FIFO is empty does not mean that + * the H/W FIFO is also empty. If we really want this to work this + * way, then we would probably need and additional parameter to tell + * us if the H/W FIFO is empty. */ dev_txint(dev, false); - } #endif + } return ret; } diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 904a3a16d3..67f07bb0f5 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -51,6 +51,10 @@ #include #include +#ifdef CONFIG_CAN_TXREADY +# include +#endif + #ifdef CONFIG_CAN /************************************************************************************ @@ -70,6 +74,12 @@ * CONFIG_CAN_LOOPBACK - A CAN driver may or may not support a loopback * mode for testing. If the driver does support loopback mode, the setting * will enable it. (If the driver does not, this setting will have no effect). + * CONFIG_CAN_TXREADY - Add support for the can_txready() callback. This is needed + * only for CAN hardware the supports an separate H/W TX message FIFO. The call + * back is needed to keep the S/W FIFO and the H/W FIFO in sync. Work queue + * support is needed for this feature. + * CONFIG_CAN_TXREADY_HIPRI or CONFIG_CAN_TXREADY_LOPRI - Selects which work queue + * will be used for the can_txready() processing. */ /* Default configuration settings that may be overridden in the NuttX configuration @@ -405,6 +415,9 @@ struct can_dev_s sem_t cd_closesem; /* Locks out new opens while close is in progress */ struct can_txfifo_s cd_xmit; /* Describes transmit FIFO */ struct can_rxfifo_s cd_recv; /* Describes receive FIFO */ +#ifdef CONFIG_CAN_TXREADY + struct work_s cd_work; /* Use to manage can_txready() work */ +#endif /* List of pending RTR requests */ struct can_rtrwait_s cd_rtr[CONFIG_CAN_NPENDINGRTR]; FAR const struct can_ops_s *cd_ops; /* Arch-specific operations */ -- GitLab From 457796d39edce37d87f33c121dd91db9a536185a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 14 Nov 2015 12:15:38 -0600 Subject: [PATCH 289/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6cc87c42c9..b381dcd3fe 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11087,4 +11087,6 @@ * drivers/serial/serial.c, serialirq.c and include/nuttx/serial/serial.h: Implement high level DMA infrastructure for serial devices. From Max Neklyudov (2015-11-12). + * arch/arm/src/samv7 and arch/arm/include/samv7: Add support for the + SAME70 family of chips (2015-11-14). diff --git a/arch b/arch index 1c26392beb..9d327e658d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1c26392bebcb3135b214e12594b701c172bd1236 +Subproject commit 9d327e658d7849b2e1b92e01cc82b4a56b757fec -- GitLab From 5e241cd1572aaa2399a9e0412de361db31c6959a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 14 Nov 2015 13:36:48 -0600 Subject: [PATCH 290/858] CAN Kconfig: Resolve a circular dependency. I am not sure if the correct version foolproof, however --- arch | 2 +- drivers/Kconfig | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 9d327e658d..e2ea7cb875 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9d327e658d7849b2e1b92e01cc82b4a56b757fec +Subproject commit e2ea7cb875351c6354ab956f40f830f8510e64b9 diff --git a/drivers/Kconfig b/drivers/Kconfig index ab903e5c9c..52f5b5a6f5 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -176,8 +176,7 @@ config CAN_TXREADY choice prompt "TX Ready Work Queue" - default CAN_TXREADY_LOPRI if SCHED_LPWORK - default CAN_TXREADY_HIPRI if !SCHED_LPWORK + default CAN_TXREADY_HIPRI depends on CAN_TXREADY config CAN_TXREADY_LOPRI -- GitLab From d6eb48d1ab336b75b20a29d08fd7aa3933c0cd7d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 14 Nov 2015 14:00:39 -0600 Subject: [PATCH 291/858] Update comments --- include/nuttx/can.h | 80 ++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 67f07bb0f5..3aaffd34d6 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -521,7 +521,7 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev); int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, FAR uint8_t *data); -/**************************************************************************** +/************************************************************************************ * Name: can_txdone * * Description: @@ -554,8 +554,8 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * * 2a. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO not full * - * This function will be back from can_xmit immediately when a new CAN - * message is added to H/W TX FIFO: + * This function will be called back from dev_send() immediately when a + * new CAN message is added to H/W TX FIFO: * * can_write() -> can_xmit() -> dev_send() -> can_txdone() * @@ -567,9 +567,11 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * 2b. H/W TX FIFO (CONFIG_CAN_TXREADY=y) and S/W TX FIFO full * * In this case, the thread calling can_write() is blocked waiting for - * space in the S/W TX FIFO. + * space in the S/W TX FIFO. can_txdone() will be called, indirectly, + * from can_txready_work() running on the thread of the work queue. * - * CAN interrupt -> can_txready() -> can_xmit() -> dev_send() -> can_txdone() + * CAN interrupt -> can_txready() -> Schedule can_txready_work() + * can_txready_work() -> can_xmit() -> dev_send() -> can_txdone() * * The call dev_send() should not fail in this case and the subsequent * call to can_txdone() will make space in the S/W TX FIFO and will @@ -583,7 +585,13 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, * Returned Value: * OK on success; a negated errno on failure. * - ****************************************************************************/ + * Assumptions: + * Interrupts are disabled. This is required by can_xmit() which is called + * by this function. Interrupts are explicitly disabled when called + * through can_write(). Interrupts are expected be disabled when called + * from the CAN interrupt handler. + * + ************************************************************************************/ int can_txdone(FAR struct can_dev_s *dev); @@ -591,37 +599,39 @@ int can_txdone(FAR struct can_dev_s *dev); * Name: can_txready * * Description: - * Called from the CAN interrupt handler at the completion of a send operation. - * This interface is needed only for CAN hardware that supports queing of - * outgoing messages in a H/W FIFO. - * - * The CAN upper half driver also supports a queue of output messages in a S/W - * FIFO. Messages are added to that queue when when can_write() is called and - * removed from the queue in can_txdone() when each TX message is complete. - * - * After each message is added to the S/W FIFO, the CAN upper half driver will - * attempt to send the message by calling into the lower half driver. That send - * will not be performed if the lower half driver is busy, i.e., if dev_txready() - * returns false. In that case, the number of messages in the S/W FIFO can grow. - * If the S/W FIFO becomes full, then can_write() will wait for space in the - * S/W FIFO. - * - * If the CAN hardware does not support a H/W FIFO then busy means that the - * hardware is actively sending the message and is guaranteed to become non- - * busy (i.e, dev_txready()) when the send transfer completes and can_txdone() - * is called. So the call to can_txdone() means that the transfer has - * completed and also that the hardware is ready to accept another transfer. - * - * If the CAN hardware supports a H/W FIFO, can_txdone() is not called when - * the tranfer is complete, but rather when the transfer is queued in the - * H/W FIFO. When the H/W FIFO becomes full, then dev_txready() will report - * false and the number of queued messages in the S/W FIFO will grow. + * Called from the CAN interrupt handler at the completion of a send + * operation. This interface is needed only for CAN hardware that + * supports queing of outgoing messages in a H/W FIFO. + * + * The CAN upper half driver also supports a queue of output messages in a + * S/W FIFO. Messages are added to that queue when when can_write() is + * called and removed from the queue in can_txdone() when each TX message + * is complete. + * + * After each message is added to the S/W FIFO, the CAN upper half driver + * will attempt to send the message by calling into the lower half driver. + * That send will not be performed if the lower half driver is busy, i.e., + * if dev_txready() returns false. In that case, the number of messages in + * the S/W FIFO can grow. If the S/W FIFO becomes full, then can_write() + * will wait for space in the S/W FIFO. + * + * If the CAN hardware does not support a H/W FIFO then busy means that + * the hardware is actively sending the message and is guaranteed to + * become non-busy (i.e, dev_txready()) when the send transfer completes + * and can_txdone() is called. So the call to can_txdone() means that the + * transfer has completed and also that the hardware is ready to accept + * another transfer. + * + * If the CAN hardware supports a H/W FIFO, can_txdone() is not called + * when the tranfer is complete, but rather when the transfer is queued in + * the H/W FIFO. When the H/W FIFO becomes full, then dev_txready() will + * report false and the number of queued messages in the S/W FIFO will grow. * * There is no mechanism in this case to inform the upper half driver when * the hardware is again available, when there is again space in the H/W * FIFO. can_txdone() will not be called again. If the S/W FIFO becomes - * full, then the upper half driver will wait for space to become available, - * but there is no event to awaken it and the driver will hang. + * full, then the upper half driver will wait for space to become + * available, but there is no event to awaken it and the driver will hang. * * Enabling this feature adds support for the can_txready() interface. * This function is called from the lower half driver's CAN interrupt @@ -635,6 +645,10 @@ int can_txdone(FAR struct can_dev_s *dev); * Returned Value: * OK on success; a negated errno on failure. * + * Assumptions: + * Interrupts are disabled. This is required by can_xmit() which is called + * by this function. + * ************************************************************************************/ #ifdef CONFIG_CAN_TXREADY -- GitLab From 815ec07b5530ec7d2dd086c7acdff41e99eb9457 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Nov 2015 06:36:30 -0600 Subject: [PATCH 292/858] CAN: A minor improvement to can_txready design --- drivers/can.c | 27 ++++++++++++++++++--------- include/nuttx/can.h | 4 ++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/can.c b/drivers/can.c index aea5959c3e..e00d7ca337 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -298,6 +298,7 @@ static void can_txready_work(FAR void *arg) { FAR struct can_dev_s *dev = (FAR struct can_dev_s *)arg; irqstate_t flags; + int ret; canllvdbg("xmit head: %d queue: %d tail: %d\n", dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, @@ -312,15 +313,23 @@ static void can_txready_work(FAR void *arg) { /* Send the next message in the FIFO. */ - (void)can_xmit(dev); + ret = can_xmit(dev); - /* Are there any threads waiting for space in the TX FIFO? */ + /* If the message was successfully queued in the H/W FIFO, then + * can_txdone() should have been called. If the S/W FIFO were + * full before then there should now be free space in the S/W FIFO. + */ - if (dev->cd_ntxwaiters > 0) + if (ret >= 0) { - /* Yes.. Inform them that new xmit space is available */ + /* Are there any threads waiting for space in the TX FIFO? */ - (void)sem_post(&dev->cd_xmit.tx_sem); + if (dev->cd_ntxwaiters > 0) + { + /* Yes.. Inform them that new xmit space is available */ + + (void)sem_post(&dev->cd_xmit.tx_sem); + } } } @@ -745,7 +754,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, if (inactive) { - can_xmit(dev); + (void)can_xmit(dev); } /* Wait for a message to be sent */ @@ -794,7 +803,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, if (inactive) { - can_xmit(dev); + (void)can_xmit(dev); } /* Return the number of bytes that were sent */ @@ -1242,8 +1251,8 @@ int can_txdone(FAR struct can_dev_s *dev) * OK on success; a negated errno on failure. * * Assumptions: - * Interrupts are disabled. This is required by can_xmit() which is called - * by this function. + * Interrupts are disabled. This function may execute in the context of + * and interrupt handler. * ****************************************************************************/ diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 3aaffd34d6..38f84a42ff 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -646,8 +646,8 @@ int can_txdone(FAR struct can_dev_s *dev); * OK on success; a negated errno on failure. * * Assumptions: - * Interrupts are disabled. This is required by can_xmit() which is called - * by this function. + * Interrupts are disabled. This function may execute in the context of + * and interrupt handler. * ************************************************************************************/ -- GitLab From 7f1ac3619462a442683922b9301817c11322414d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Nov 2015 07:58:08 -0600 Subject: [PATCH 293/858] Serial driver: Move serial DMA logic to a separate file --- drivers/serial/Make.defs | 7 +- drivers/serial/{serialirq.c => serial_dma.c} | 178 +----------- drivers/serial/serial_io.c | 273 +++++++++++++++++++ 3 files changed, 284 insertions(+), 174 deletions(-) rename drivers/serial/{serialirq.c => serial_dma.c} (63%) create mode 100644 drivers/serial/serial_io.c diff --git a/drivers/serial/Make.defs b/drivers/serial/Make.defs index b99f4eb362..372a86c551 100644 --- a/drivers/serial/Make.defs +++ b/drivers/serial/Make.defs @@ -37,7 +37,12 @@ ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) # Include serial drivers -CSRCS += serial.c serialirq.c lowconsole.c +CSRCS += serial.c serial_io.c lowconsole.c + +ifeq ($(CONFIG_SERIAL_DMA),y) + CSRCS += serial_dma.c +endif + ifeq ($(CONFIG_16550_UART),y) CSRCS += uart_16550.c diff --git a/drivers/serial/serialirq.c b/drivers/serial/serial_dma.c similarity index 63% rename from drivers/serial/serialirq.c rename to drivers/serial/serial_dma.c index b58867f71d..9a02875dd8 100644 --- a/drivers/serial/serialirq.c +++ b/drivers/serial/serial_dma.c @@ -1,7 +1,7 @@ /************************************************************************************ - * drivers/serial/serialirq.c + * drivers/serial/serial_dma.c * - * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,23 +43,10 @@ #include #include #include -#include - -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ -/************************************************************************************ - * Private Types - ************************************************************************************/ - -/************************************************************************************ - * Private Function Prototypes - ************************************************************************************/ +#include -/************************************************************************************ - * Private Variables - ************************************************************************************/ +#ifdef CONFIG_SERIAL_DMA /************************************************************************************ * Private Functions @@ -146,7 +133,6 @@ static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, * ************************************************************************************/ -#ifdef CONFIG_SERIAL_DMA void uart_xmitchars_dma(FAR uart_dev_t *dev) { FAR struct uart_dmaxfer_s *xfer = &dev->dmatx; @@ -175,7 +161,6 @@ void uart_xmitchars_dma(FAR uart_dev_t *dev) uart_dmasend(dev); } -#endif /* CONFIG_SERIAL_DMA */ /************************************************************************************ * Name: uart_xmitchars_done @@ -187,7 +172,6 @@ void uart_xmitchars_dma(FAR uart_dev_t *dev) * ************************************************************************************/ -#ifdef CONFIG_SERIAL_DMA void uart_xmitchars_done(FAR uart_dev_t *dev) { FAR struct uart_dmaxfer_s *xfer = &dev->dmatx; @@ -209,7 +193,6 @@ void uart_xmitchars_done(FAR uart_dev_t *dev) uart_datasent(dev); } } -#endif /* CONFIG_SERIAL_DMA */ /************************************************************************************ * Name: uart_recvchars_dma @@ -219,7 +202,6 @@ void uart_xmitchars_done(FAR uart_dev_t *dev) * ************************************************************************************/ -#ifdef CONFIG_SERIAL_DMA void uart_recvchars_dma(FAR uart_dev_t *dev) { FAR struct uart_dmaxfer_s *xfer = &dev->dmarx; @@ -292,7 +274,6 @@ void uart_recvchars_dma(FAR uart_dev_t *dev) uart_dmareceive(dev); } -#endif /* CONFIG_SERIAL_DMA */ /************************************************************************************ * Name: uart_recvchars_done @@ -304,7 +285,6 @@ void uart_recvchars_dma(FAR uart_dev_t *dev) * ************************************************************************************/ -#ifdef CONFIG_SERIAL_DMA void uart_recvchars_done(FAR uart_dev_t *dev) { FAR struct uart_dmaxfer_s *xfer = &dev->dmarx; @@ -326,153 +306,5 @@ void uart_recvchars_done(FAR uart_dev_t *dev) uart_datareceived(dev); } } -#endif /* CONFIG_SERIAL_DMA */ - -/************************************************************************************ - * Name: uart_xmitchars - * - * Description: - * This function is called from the UART interrupt handler when an interrupt - * is received indicating that there is more space in the transmit FIFO. This - * function will send characters from the tail of the xmit buffer while the driver - * write() logic adds data to the head of the xmit buffer. - * - ************************************************************************************/ - -void uart_xmitchars(FAR uart_dev_t *dev) -{ - uint16_t nbytes = 0; - /* Send while we still have data in the TX buffer & room in the fifo */ - - while (dev->xmit.head != dev->xmit.tail && uart_txready(dev)) - { - /* Send the next byte */ - - uart_send(dev, dev->xmit.buffer[dev->xmit.tail]); - nbytes++; - - /* Increment the tail index */ - - if (++(dev->xmit.tail) >= dev->xmit.size) - { - dev->xmit.tail = 0; - } - } - - /* When all of the characters have been sent from the buffer disable the TX - * interrupt. - * - * Potential bug? If nbytes == 0 && (dev->xmit.head == dev->xmit.tail) && - * dev->xmitwaiting == true, then disabling the TX interrupt will leave - * the uart_write() logic waiting to TX to complete with no TX interrupts. - * Can that happen? - */ - - if (dev->xmit.head == dev->xmit.tail) - { - uart_disabletxint(dev); - } - - /* If any bytes were removed from the buffer, inform any waiters there there is - * space available. - */ - - if (nbytes) - { - uart_datasent(dev); - } -} - -/************************************************************************************ - * Name: uart_receivechars - * - * Description: - * This function is called from the UART interrupt handler when an interrupt - * is received indicating that are bytes available in the receive fifo. This - * function will add chars to head of receive buffer. Driver read() logic will - * take characters from the tail of the buffer. - * - ************************************************************************************/ - -void uart_recvchars(FAR uart_dev_t *dev) -{ - FAR struct uart_buffer_s *rxbuf = &dev->recv; -#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - unsigned int watermark; -#endif - unsigned int status; - int nexthead = rxbuf->head + 1; - uint16_t nbytes = 0; - bool is_full; - - if (nexthead >= rxbuf->size) - { - nexthead = 0; - } - -#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - /* Pre-calcuate the watermark level that we will need to test against. */ - - watermark = (CONFIG_SERIAL_IFLOWCONTROL_UPPER_WATERMARK * rxbuf->size) / 100; -#endif - - /* Loop putting characters into the receive buffer until there are no further - * characters to available. - */ - - while (uart_rxavailable(dev)) - { - is_full = (nexthead == rxbuf->tail); - char ch; - -#ifdef CONFIG_SERIAL_IFLOWCONTROL -#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - if (uart_dorxflowcontrol(dev, rxbuf, watermark)) - { - break; - } -#else - if (uart_dorxflowcontrol(dev, rxbuf, is_full)) - { - break; - } -#endif -#endif - - ch = uart_receive(dev, &status); - - /* If the RX buffer becomes full, then the serial data is discarded. This is - * necessary because on most serial hardware, you must read the data in order - * to clear the RX interrupt. An option on some hardware might be to simply - * disable RX interrupts until the RX buffer becomes non-FULL. However, that - * would probably just cause the overrun to occur in hardware (unless it has - * some large internal buffering). - */ - - if (!is_full) - { - /* Add the character to the buffer */ - - rxbuf->buffer[rxbuf->head] = ch; - nbytes++; - - /* Increment the head index */ - - rxbuf->head = nexthead; - if (++nexthead >= rxbuf->size) - { - nexthead = 0; - } - } - } - - /* If any bytes were added to the buffer, inform any waiters there is new - * incoming data available. - */ - - if (nbytes) - { - uart_datareceived(dev); - } -} +#endif /* CONFIG_SERIAL_DMA */ diff --git a/drivers/serial/serial_io.c b/drivers/serial/serial_io.c new file mode 100644 index 0000000000..d248a886bc --- /dev/null +++ b/drivers/serial/serial_io.c @@ -0,0 +1,273 @@ +/************************************************************************************ + * drivers/serial/serial_io.c + * + * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: uart_dorxflowcontrol + * + * Description: + * Handle RX flow control using watermark levels or not + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS +static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, + FAR struct uart_buffer_s *rxbuf, + unsigned int watermark) +{ + unsigned int nbuffered; + + /* How many bytes are buffered */ + + if (rxbuf->head >= rxbuf->tail) + { + nbuffered = rxbuf->head - rxbuf->tail; + } + else + { + nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; + } + + /* Is the level now above the watermark level that we need to report? */ + + if (nbuffered >= watermark) + { + /* Let the lower level driver know that the watermark level has been + * crossed. It will probably activate RX flow control. + */ + + if (uart_rxflowcontrol(dev, nbuffered, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + return true; + } + } + + return false; +} +#else +static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, + FAR struct uart_buffer_s *rxbuf, + bool is_full) +{ + /* Check if RX buffer is full and allow serial low-level driver to pause + * processing. This allows proper utilization of hardware flow control. + */ + + if (is_full) + { + if (uart_rxflowcontrol(dev, rxbuf->size, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + return true; + } + } + + return false; +} +#endif +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: uart_xmitchars + * + * Description: + * This function is called from the UART interrupt handler when an interrupt + * is received indicating that there is more space in the transmit FIFO. This + * function will send characters from the tail of the xmit buffer while the driver + * write() logic adds data to the head of the xmit buffer. + * + ************************************************************************************/ + +void uart_xmitchars(FAR uart_dev_t *dev) +{ + uint16_t nbytes = 0; + + /* Send while we still have data in the TX buffer & room in the fifo */ + + while (dev->xmit.head != dev->xmit.tail && uart_txready(dev)) + { + /* Send the next byte */ + + uart_send(dev, dev->xmit.buffer[dev->xmit.tail]); + nbytes++; + + /* Increment the tail index */ + + if (++(dev->xmit.tail) >= dev->xmit.size) + { + dev->xmit.tail = 0; + } + } + + /* When all of the characters have been sent from the buffer disable the TX + * interrupt. + * + * Potential bug? If nbytes == 0 && (dev->xmit.head == dev->xmit.tail) && + * dev->xmitwaiting == true, then disabling the TX interrupt will leave + * the uart_write() logic waiting to TX to complete with no TX interrupts. + * Can that happen? + */ + + if (dev->xmit.head == dev->xmit.tail) + { + uart_disabletxint(dev); + } + + /* If any bytes were removed from the buffer, inform any waiters there there is + * space available. + */ + + if (nbytes) + { + uart_datasent(dev); + } +} + +/************************************************************************************ + * Name: uart_receivechars + * + * Description: + * This function is called from the UART interrupt handler when an interrupt + * is received indicating that are bytes available in the receive fifo. This + * function will add chars to head of receive buffer. Driver read() logic will + * take characters from the tail of the buffer. + * + ************************************************************************************/ + +void uart_recvchars(FAR uart_dev_t *dev) +{ + FAR struct uart_buffer_s *rxbuf = &dev->recv; +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + unsigned int watermark; +#endif + unsigned int status; + int nexthead = rxbuf->head + 1; + uint16_t nbytes = 0; + bool is_full; + + if (nexthead >= rxbuf->size) + { + nexthead = 0; + } + +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + /* Pre-calcuate the watermark level that we will need to test against. */ + + watermark = (CONFIG_SERIAL_IFLOWCONTROL_UPPER_WATERMARK * rxbuf->size) / 100; +#endif + + /* Loop putting characters into the receive buffer until there are no further + * characters to available. + */ + + while (uart_rxavailable(dev)) + { + is_full = (nexthead == rxbuf->tail); + char ch; + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + if (uart_dorxflowcontrol(dev, rxbuf, watermark)) + { + break; + } +#else + if (uart_dorxflowcontrol(dev, rxbuf, is_full)) + { + break; + } +#endif +#endif + + ch = uart_receive(dev, &status); + + /* If the RX buffer becomes full, then the serial data is discarded. This is + * necessary because on most serial hardware, you must read the data in order + * to clear the RX interrupt. An option on some hardware might be to simply + * disable RX interrupts until the RX buffer becomes non-FULL. However, that + * would probably just cause the overrun to occur in hardware (unless it has + * some large internal buffering). + */ + + if (!is_full) + { + /* Add the character to the buffer */ + + rxbuf->buffer[rxbuf->head] = ch; + nbytes++; + + /* Increment the head index */ + + rxbuf->head = nexthead; + if (++nexthead >= rxbuf->size) + { + nexthead = 0; + } + } + } + + /* If any bytes were added to the buffer, inform any waiters there is new + * incoming data available. + */ + + if (nbytes) + { + uart_datareceived(dev); + } +} -- GitLab From ab9d124528085bfc00dd313a42242b37a2415ee5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Nov 2015 08:39:01 -0600 Subject: [PATCH 294/858] serial: Remove confusing inline functions. Correct attribution for serial DMA logic --- arch | 2 +- drivers/serial/Make.defs | 1 - drivers/serial/serial_dma.c | 116 ++++++++++++----------------------- drivers/serial/serial_io.c | 117 ++++++++++++------------------------ 4 files changed, 77 insertions(+), 159 deletions(-) diff --git a/arch b/arch index e2ea7cb875..2ed5f475b1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e2ea7cb875351c6354ab956f40f830f8510e64b9 +Subproject commit 2ed5f475b11e34cd926c9591892d149d622e872f diff --git a/drivers/serial/Make.defs b/drivers/serial/Make.defs index 372a86c551..bcbffd8368 100644 --- a/drivers/serial/Make.defs +++ b/drivers/serial/Make.defs @@ -43,7 +43,6 @@ ifeq ($(CONFIG_SERIAL_DMA),y) CSRCS += serial_dma.c endif - ifeq ($(CONFIG_16550_UART),y) CSRCS += uart_16550.c endif diff --git a/drivers/serial/serial_dma.c b/drivers/serial/serial_dma.c index 9a02875dd8..f363f9ed0a 100644 --- a/drivers/serial/serial_dma.c +++ b/drivers/serial/serial_dma.c @@ -2,7 +2,7 @@ * drivers/serial/serial_dma.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Max Neklyudov * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,79 +48,6 @@ #ifdef CONFIG_SERIAL_DMA -/************************************************************************************ - * Private Functions - ************************************************************************************/ - -/************************************************************************************ - * Name: uart_dorxflowcontrol - * - * Description: - * Handle RX flow control using watermark levels or not - * - ************************************************************************************/ - -#ifdef CONFIG_SERIAL_IFLOWCONTROL -#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS -static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, - FAR struct uart_buffer_s *rxbuf, - unsigned int watermark) -{ - unsigned int nbuffered; - - /* How many bytes are buffered */ - - if (rxbuf->head >= rxbuf->tail) - { - nbuffered = rxbuf->head - rxbuf->tail; - } - else - { - nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; - } - - /* Is the level now above the watermark level that we need to report? */ - - if (nbuffered >= watermark) - { - /* Let the lower level driver know that the watermark level has been - * crossed. It will probably activate RX flow control. - */ - - if (uart_rxflowcontrol(dev, nbuffered, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - return true; - } - } - - return false; -} -#else -static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, - FAR struct uart_buffer_s *rxbuf, - bool is_full) -{ - /* Check if RX buffer is full and allow serial low-level driver to pause - * processing. This allows proper utilization of hardware flow control. - */ - - if (is_full) - { - if (uart_rxflowcontrol(dev, rxbuf->size, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - return true; - } - } - - return false; -} -#endif -#endif - /************************************************************************************ * Public Functions ************************************************************************************/ @@ -207,6 +134,7 @@ void uart_recvchars_dma(FAR uart_dev_t *dev) FAR struct uart_dmaxfer_s *xfer = &dev->dmarx; FAR struct uart_buffer_s *rxbuf = &dev->recv; #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS + unsigned int nbuffered; unsigned int watermark; #endif bool is_full; @@ -227,14 +155,46 @@ void uart_recvchars_dma(FAR uart_dev_t *dev) #ifdef CONFIG_SERIAL_IFLOWCONTROL #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - if (uart_dorxflowcontrol(dev, rxbuf, watermark)) + /* How many bytes are buffered */ + + if (rxbuf->head >= rxbuf->tail) { - return; + nbuffered = rxbuf->head - rxbuf->tail; + } + else + { + nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; + } + + /* Is the level now above the watermark level that we need to report? */ + + if (nbuffered >= watermark) + { + /* Let the lower level driver know that the watermark level has been + * crossed. It will probably activate RX flow control. + */ + + if (uart_rxflowcontrol(dev, nbuffered, true)) + { + /* Low-level driver activated RX flow control, return now. */ + + return; + } } + #else - if (uart_dorxflowcontrol(dev, rxbuf, is_full)) + /* Check if RX buffer is full and allow serial low-level driver to pause + * processing. This allows proper utilization of hardware flow control. + */ + + if (is_full) { - return; + if (uart_rxflowcontrol(dev, rxbuf->size, true)) + { + /* Low-level driver activated RX flow control, return now. */ + + return; + } } #endif #endif diff --git a/drivers/serial/serial_io.c b/drivers/serial/serial_io.c index d248a886bc..9d28d64b74 100644 --- a/drivers/serial/serial_io.c +++ b/drivers/serial/serial_io.c @@ -46,79 +46,6 @@ #include -/************************************************************************************ - * Private Functions - ************************************************************************************/ - -/************************************************************************************ - * Name: uart_dorxflowcontrol - * - * Description: - * Handle RX flow control using watermark levels or not - * - ************************************************************************************/ - -#ifdef CONFIG_SERIAL_IFLOWCONTROL -#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS -static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, - FAR struct uart_buffer_s *rxbuf, - unsigned int watermark) -{ - unsigned int nbuffered; - - /* How many bytes are buffered */ - - if (rxbuf->head >= rxbuf->tail) - { - nbuffered = rxbuf->head - rxbuf->tail; - } - else - { - nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; - } - - /* Is the level now above the watermark level that we need to report? */ - - if (nbuffered >= watermark) - { - /* Let the lower level driver know that the watermark level has been - * crossed. It will probably activate RX flow control. - */ - - if (uart_rxflowcontrol(dev, nbuffered, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - return true; - } - } - - return false; -} -#else -static inline bool uart_dorxflowcontrol(FAR uart_dev_t *dev, - FAR struct uart_buffer_s *rxbuf, - bool is_full) -{ - /* Check if RX buffer is full and allow serial low-level driver to pause - * processing. This allows proper utilization of hardware flow control. - */ - - if (is_full) - { - if (uart_rxflowcontrol(dev, rxbuf->size, true)) - { - /* Low-level driver activated RX flow control, exit loop now. */ - - return true; - } - } - - return false; -} -#endif -#endif - /************************************************************************************ * Public Functions ************************************************************************************/ @@ -199,7 +126,6 @@ void uart_recvchars(FAR uart_dev_t *dev) unsigned int status; int nexthead = rxbuf->head + 1; uint16_t nbytes = 0; - bool is_full; if (nexthead >= rxbuf->size) { @@ -218,19 +144,52 @@ void uart_recvchars(FAR uart_dev_t *dev) while (uart_rxavailable(dev)) { - is_full = (nexthead == rxbuf->tail); + bool is_full = (nexthead == rxbuf->tail); char ch; #ifdef CONFIG_SERIAL_IFLOWCONTROL #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS - if (uart_dorxflowcontrol(dev, rxbuf, watermark)) + unsigned int nbuffered; + + /* How many bytes are buffered */ + + if (rxbuf->head >= rxbuf->tail) { - break; + nbuffered = rxbuf->head - rxbuf->tail; + } + else + { + nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head; + } + + /* Is the level now above the watermark level that we need to report? */ + + if (nbuffered >= watermark) + { + /* Let the lower level driver know that the watermark level has been + * crossed. It will probably activate RX flow control. + */ + + if (uart_rxflowcontrol(dev, nbuffered, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + break; + } } #else - if (uart_dorxflowcontrol(dev, rxbuf, is_full)) + /* Check if RX buffer is full and allow serial low-level driver to pause + * processing. This allows proper utilization of hardware flow control. + */ + + if (is_full) { - break; + if (uart_rxflowcontrol(dev, rxbuf->size, true)) + { + /* Low-level driver activated RX flow control, exit loop now. */ + + break; + } } #endif #endif -- GitLab From 2ae7485a57e03a8ff562498d1619d75ee804c88e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 16 Nov 2015 10:47:21 -0600 Subject: [PATCH 295/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b381dcd3fe..3614e40162 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11089,4 +11089,8 @@ Max Neklyudov (2015-11-12). * arch/arm/src/samv7 and arch/arm/include/samv7: Add support for the SAME70 family of chips (2015-11-14). + * configs/stm32f429i-disco: configs/stm32f429i-disco/src/stm32_nsh.c + file calculated partition boundries based on page block sizes but + mtd_partition() is expecting calculations based on erase block size. + From Alan Carvalho de Assis (2015-11-16). diff --git a/arch b/arch index 2ed5f475b1..cce873c460 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 2ed5f475b11e34cd926c9591892d149d622e872f +Subproject commit cce873c46060fe663f571cb922e642e097249c60 diff --git a/configs b/configs index 95afbd39b4..744d52f25f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 95afbd39b42d2689c894fdfc4e8b6123446772a9 +Subproject commit 744d52f25f764e1f31906d0e6491e9171840f262 -- GitLab From c955cdccd9cef5d2aecfa03fe33d6221bb6186fd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 16 Nov 2015 13:31:02 -0600 Subject: [PATCH 296/858] Move rivers/wireless/cc3000/security.c to crypto/aes.c; move include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h --- configs | 2 +- crypto/Kconfig | 9 +- crypto/Makefile | 30 +- .../cc3000/security.c => crypto/aes.c | 418 ++++++++---------- drivers/wireless/cc3000/Kconfig | 2 + drivers/wireless/cc3000/Make.defs | 2 +- drivers/wireless/cc3000/wlan.c | 55 ++- include/nuttx/crypto/aes.h | 108 +++++ include/nuttx/wireless/cc3000/security.h | 142 ------ include/nuttx/wireless/cc3000/wlan.h | 34 ++ 10 files changed, 419 insertions(+), 383 deletions(-) rename drivers/wireless/cc3000/security.c => crypto/aes.c (55%) create mode 100644 include/nuttx/crypto/aes.h delete mode 100644 include/nuttx/wireless/cc3000/security.h diff --git a/configs b/configs index 744d52f25f..174b30da6b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 744d52f25f764e1f31906d0e6491e9171840f262 +Subproject commit 174b30da6b334c1e040d4212e31237b5b6aabd06 diff --git a/crypto/Kconfig b/crypto/Kconfig index b23d23f56f..7da34a7a45 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -39,4 +39,11 @@ config CRYPTO_CRYPTODEV bool "cryptodev support" default n -endif +config CRYPTO_SW_AES + bool "Software AES library" + default n + ---help--- + Enable the software AES library as described in + include/nuttx/crypto/aes.h + +endif # CRYPTO diff --git a/crypto/Makefile b/crypto/Makefile index b3131531e8..c56640534e 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -35,33 +35,41 @@ -include $(TOPDIR)/Make.defs +CRYPTO_ASRCS = +CRYPTO_CSRCS = + ifeq ($(CONFIG_CRYPTO),y) # Basic -CRYPTO_ASRCS = -CRYPTO_CSRCS = crypto.c testmngr.c +CRYPTO_CSRCS += crypto.c testmngr.c # cryptodev support ifeq ($(CONFIG_CRYPTO_CRYPTODEV),y) -CRYPTO_CSRCS += cryptodev.c + CRYPTO_CSRCS += cryptodev.c +endif + +# Sofware AES library + +ifeq ($(CONFIG_CRYPTO_SW_AES),y) + CRYPTO_CSRCS += aes.c endif endif # CONFIG_CRYPTO -ASRCS = $(CRYPTO_ASRCS) -AOBJS = $(ASRCS:.S=$(OBJEXT)) +ASRCS = $(CRYPTO_ASRCS) +AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = $(CRYPTO_CSRCS) -COBJS = $(CSRCS:.c=$(OBJEXT)) +CSRCS = $(CRYPTO_CSRCS) +COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) -BIN = libcrypto$(LIBEXT) +BIN = libcrypto$(LIBEXT) -all: $(BIN) +all: $(BIN) $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) diff --git a/drivers/wireless/cc3000/security.c b/crypto/aes.c similarity index 55% rename from drivers/wireless/cc3000/security.c rename to crypto/aes.c index bd30a78121..fb05a4cab2 100644 --- a/drivers/wireless/cc3000/security.c +++ b/crypto/aes.c @@ -1,34 +1,36 @@ /**************************************************************************** - * security.c - CC3000 Host Driver Implementation. - * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * crypto/aes.c + * + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ + * Extracted from the CC3000 Host Driver Implementation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ @@ -36,9 +38,11 @@ * Included Files ****************************************************************************/ -#include +#include + +#include -#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +#include /**************************************************************************** * Private Data @@ -46,7 +50,7 @@ /* Forward sbox */ -const uint8_t sbox[256] = +static const uint8_t g_sbox[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, /* 0 */ @@ -69,7 +73,7 @@ const uint8_t sbox[256] = /* Inverse sbox */ -const uint8_t rsbox[256] = +static const uint8_t g_rsbox[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, @@ -91,59 +95,61 @@ const uint8_t rsbox[256] = /* Round constant */ -const uint8_t Rcon[11] = +static const uint8_t g_rcon[11] = { 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; -uint8_t aexpandedKey[176]; +static uint8_t g_expanded_key[176]; /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ + /**************************************************************************** - * Name: expandKey + * Name: expand_key * * Description: * Expend a 16 bytes key for AES128 implementation * * Input Parameters: * key AES128 key - 16 bytes - * expandedKey expanded AES128 key + * expanded_key expanded AES128 key * * Returned Value: * None * ****************************************************************************/ -void expandKey(uint8_t *expandedKey, uint8_t *key) +static void expand_key(FAR uint8_t *expanded_key, FAR uint8_t *key) { - uint16_t ii, buf1; + uint16_t buf1; + uint16_t ii; for (ii = 0; ii < 16; ii++) { - expandedKey[ii] = key[ii]; + expanded_key[ii] = key[ii]; } for (ii = 1; ii < 11; ii++) { - buf1 = expandedKey[ii*16 - 4]; - expandedKey[ii * 16 + 0] = sbox[expandedKey[ii *16 - 3]] ^ expandedKey[(ii - 1) * 16 + 0] ^ Rcon[ii]; - expandedKey[ii * 16 + 1] = sbox[expandedKey[ii *16 - 2]] ^ expandedKey[(ii - 1) * 16 + 1]; - expandedKey[ii * 16 + 2] = sbox[expandedKey[ii *16 - 1]] ^ expandedKey[(ii - 1) * 16 + 2]; - expandedKey[ii * 16 + 3] = sbox[buf1] ^ expandedKey[(ii - 1) * 16 + 3]; - expandedKey[ii * 16 + 4] = expandedKey[(ii - 1) * 16 + 4] ^ expandedKey[ii * 16 + 0]; - expandedKey[ii * 16 + 5] = expandedKey[(ii - 1) * 16 + 5] ^ expandedKey[ii * 16 + 1]; - expandedKey[ii * 16 + 6] = expandedKey[(ii - 1) * 16 + 6] ^ expandedKey[ii * 16 + 2]; - expandedKey[ii * 16 + 7] = expandedKey[(ii - 1) * 16 + 7] ^ expandedKey[ii * 16 + 3]; - expandedKey[ii * 16 + 8] = expandedKey[(ii - 1) * 16 + 8] ^ expandedKey[ii * 16 + 4]; - expandedKey[ii * 16 + 9] = expandedKey[(ii - 1) * 16 + 9] ^ expandedKey[ii * 16 + 5]; - expandedKey[ii * 16 +10] = expandedKey[(ii - 1) * 16 +10] ^ expandedKey[ii * 16 + 6]; - expandedKey[ii * 16 +11] = expandedKey[(ii - 1) * 16 +11] ^ expandedKey[ii * 16 + 7]; - expandedKey[ii * 16 +12] = expandedKey[(ii - 1) * 16 +12] ^ expandedKey[ii * 16 + 8]; - expandedKey[ii * 16 +13] = expandedKey[(ii - 1) * 16 +13] ^ expandedKey[ii * 16 + 9]; - expandedKey[ii * 16 +14] = expandedKey[(ii - 1) * 16 +14] ^ expandedKey[ii * 16 +10]; - expandedKey[ii * 16 +15] = expandedKey[(ii - 1) * 16 +15] ^ expandedKey[ii * 16 +11]; + buf1 = expanded_key[ii*16 - 4]; + expanded_key[ii * 16 + 0] = g_sbox[expanded_key[ii *16 - 3]] ^ expanded_key[(ii - 1) * 16 + 0] ^ g_rcon[ii]; + expanded_key[ii * 16 + 1] = g_sbox[expanded_key[ii *16 - 2]] ^ expanded_key[(ii - 1) * 16 + 1]; + expanded_key[ii * 16 + 2] = g_sbox[expanded_key[ii *16 - 1]] ^ expanded_key[(ii - 1) * 16 + 2]; + expanded_key[ii * 16 + 3] = g_sbox[buf1] ^ expanded_key[(ii - 1) * 16 + 3]; + expanded_key[ii * 16 + 4] = expanded_key[(ii - 1) * 16 + 4] ^ expanded_key[ii * 16 + 0]; + expanded_key[ii * 16 + 5] = expanded_key[(ii - 1) * 16 + 5] ^ expanded_key[ii * 16 + 1]; + expanded_key[ii * 16 + 6] = expanded_key[(ii - 1) * 16 + 6] ^ expanded_key[ii * 16 + 2]; + expanded_key[ii * 16 + 7] = expanded_key[(ii - 1) * 16 + 7] ^ expanded_key[ii * 16 + 3]; + expanded_key[ii * 16 + 8] = expanded_key[(ii - 1) * 16 + 8] ^ expanded_key[ii * 16 + 4]; + expanded_key[ii * 16 + 9] = expanded_key[(ii - 1) * 16 + 9] ^ expanded_key[ii * 16 + 5]; + expanded_key[ii * 16 +10] = expanded_key[(ii - 1) * 16 +10] ^ expanded_key[ii * 16 + 6]; + expanded_key[ii * 16 +11] = expanded_key[(ii - 1) * 16 +11] ^ expanded_key[ii * 16 + 7]; + expanded_key[ii * 16 +12] = expanded_key[(ii - 1) * 16 +12] ^ expanded_key[ii * 16 + 8]; + expanded_key[ii * 16 +13] = expanded_key[(ii - 1) * 16 +13] ^ expanded_key[ii * 16 + 9]; + expanded_key[ii * 16 +14] = expanded_key[(ii - 1) * 16 +14] ^ expanded_key[ii * 16 +10]; + expanded_key[ii * 16 +15] = expanded_key[(ii - 1) * 16 +15] ^ expanded_key[ii * 16 +11]; } } @@ -161,7 +167,7 @@ void expandKey(uint8_t *expandedKey, uint8_t *key) * ******************************************************************************/ -uint8_t galois_mul2(uint8_t value) +static uint8_t galois_mul2(uint8_t value) { if (value >> 7) { @@ -189,7 +195,7 @@ uint8_t galois_mul2(uint8_t value) * cycles for function calls no structuring with "for (....)" to save cycles. * * Input Parameters: - * expandedKey expanded AES128 key + * expanded_key expanded AES128 key * state 16 bytes of plain text and cipher text * * Returned Value: @@ -197,44 +203,47 @@ uint8_t galois_mul2(uint8_t value) * ******************************************************************************/ -void aes_encr(uint8_t *state, uint8_t *expandedKey) +static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key) { - uint8_t buf1, buf2, buf3, round; + uint8_t buf1; + uint8_t buf2; + uint8_t buf3; + uint8_t round; for (round = 0; round < 9; round ++) { /* addroundkey, sbox and shiftrows */ /* Row 0 */ - state[0] = sbox[(state[0] ^ expandedKey[(round * 16)])]; - state[4] = sbox[(state[4] ^ expandedKey[(round * 16) + 4])]; - state[8] = sbox[(state[8] ^ expandedKey[(round * 16) + 8])]; - state[12] = sbox[(state[12] ^ expandedKey[(round * 16) + 12])]; + state[0] = g_sbox[(state[0] ^ expanded_key[(round * 16)])]; + state[4] = g_sbox[(state[4] ^ expanded_key[(round * 16) + 4])]; + state[8] = g_sbox[(state[8] ^ expanded_key[(round * 16) + 8])]; + state[12] = g_sbox[(state[12] ^ expanded_key[(round * 16) + 12])]; /* Row 1 */ - buf1 = state[1] ^ expandedKey[(round * 16) + 1]; - state[1] = sbox[(state[5] ^ expandedKey[(round * 16) + 5])]; - state[5] = sbox[(state[9] ^ expandedKey[(round * 16) + 9])]; - state[9] = sbox[(state[13] ^ expandedKey[(round * 16) + 13])]; - state[13] = sbox[buf1]; + buf1 = state[1] ^ expanded_key[(round * 16) + 1]; + state[1] = g_sbox[(state[5] ^ expanded_key[(round * 16) + 5])]; + state[5] = g_sbox[(state[9] ^ expanded_key[(round * 16) + 9])]; + state[9] = g_sbox[(state[13] ^ expanded_key[(round * 16) + 13])]; + state[13] = g_sbox[buf1]; /* Row 2 */ - buf1 = state[2] ^ expandedKey[(round * 16) + 2]; - buf2 = state[6] ^ expandedKey[(round * 16) + 6]; - state[2] = sbox[(state[10] ^ expandedKey[(round * 16) + 10])]; - state[6] = sbox[(state[14] ^ expandedKey[(round * 16) + 14])]; - state[10] = sbox[buf1]; - state[14] = sbox[buf2]; + buf1 = state[2] ^ expanded_key[(round * 16) + 2]; + buf2 = state[6] ^ expanded_key[(round * 16) + 6]; + state[2] = g_sbox[(state[10] ^ expanded_key[(round * 16) + 10])]; + state[6] = g_sbox[(state[14] ^ expanded_key[(round * 16) + 14])]; + state[10] = g_sbox[buf1]; + state[14] = g_sbox[buf2]; /* Row 3 */ - buf1 = state[15] ^ expandedKey[(round * 16) + 15]; - state[15] = sbox[(state[11] ^ expandedKey[(round * 16) + 11])]; - state[11] = sbox[(state[7] ^ expandedKey[(round * 16) + 7])]; - state[7] = sbox[(state[3] ^ expandedKey[(round * 16) + 3])]; - state[3] = sbox[buf1]; + buf1 = state[15] ^ expanded_key[(round * 16) + 15]; + state[15] = g_sbox[(state[11] ^ expanded_key[(round * 16) + 11])]; + state[11] = g_sbox[(state[7] ^ expanded_key[(round * 16) + 7])]; + state[7] = g_sbox[(state[3] ^ expanded_key[(round * 16) + 3])]; + state[3] = g_sbox[buf1]; /* mixcolums */ /* Col1 */ @@ -276,54 +285,54 @@ void aes_encr(uint8_t *state, uint8_t *expandedKey) /* 10th round without mixcols */ - state[0] = sbox[(state[0] ^ expandedKey[(round * 16)])]; - state[4] = sbox[(state[4] ^ expandedKey[(round * 16) + 4])]; - state[8] = sbox[(state[8] ^ expandedKey[(round * 16) + 8])]; - state[12] = sbox[(state[12] ^ expandedKey[(round * 16) + 12])]; + state[0] = g_sbox[(state[0] ^ expanded_key[(round * 16)])]; + state[4] = g_sbox[(state[4] ^ expanded_key[(round * 16) + 4])]; + state[8] = g_sbox[(state[8] ^ expanded_key[(round * 16) + 8])]; + state[12] = g_sbox[(state[12] ^ expanded_key[(round * 16) + 12])]; /* Row 1 */ - buf1 = state[1] ^ expandedKey[(round * 16) + 1]; - state[1] = sbox[(state[5] ^ expandedKey[(round * 16) + 5])]; - state[5] = sbox[(state[9] ^ expandedKey[(round * 16) + 9])]; - state[9] = sbox[(state[13] ^ expandedKey[(round * 16) + 13])]; - state[13] = sbox[buf1]; + buf1 = state[1] ^ expanded_key[(round * 16) + 1]; + state[1] = g_sbox[(state[5] ^ expanded_key[(round * 16) + 5])]; + state[5] = g_sbox[(state[9] ^ expanded_key[(round * 16) + 9])]; + state[9] = g_sbox[(state[13] ^ expanded_key[(round * 16) + 13])]; + state[13] = g_sbox[buf1]; /* Row 2 */ - buf1 = state[2] ^ expandedKey[(round * 16) + 2]; - buf2 = state[6] ^ expandedKey[(round * 16) + 6]; - state[2] = sbox[(state[10] ^ expandedKey[(round * 16) + 10])]; - state[6] = sbox[(state[14] ^ expandedKey[(round * 16) + 14])]; - state[10] = sbox[buf1]; - state[14] = sbox[buf2]; + buf1 = state[2] ^ expanded_key[(round * 16) + 2]; + buf2 = state[6] ^ expanded_key[(round * 16) + 6]; + state[2] = g_sbox[(state[10] ^ expanded_key[(round * 16) + 10])]; + state[6] = g_sbox[(state[14] ^ expanded_key[(round * 16) + 14])]; + state[10] = g_sbox[buf1]; + state[14] = g_sbox[buf2]; /* Row 3 */ - buf1 = state[15] ^ expandedKey[(round * 16) + 15]; - state[15] = sbox[(state[11] ^ expandedKey[(round * 16) + 11])]; - state[11] = sbox[(state[7] ^ expandedKey[(round * 16) + 7])]; - state[7] = sbox[(state[3] ^ expandedKey[(round * 16) + 3])]; - state[3] = sbox[buf1]; + buf1 = state[15] ^ expanded_key[(round * 16) + 15]; + state[15] = g_sbox[(state[11] ^ expanded_key[(round * 16) + 11])]; + state[11] = g_sbox[(state[7] ^ expanded_key[(round * 16) + 7])]; + state[7] = g_sbox[(state[3] ^ expanded_key[(round * 16) + 3])]; + state[3] = g_sbox[buf1]; /* Last addroundkey */ - state[0] ^= expandedKey[160]; - state[1] ^= expandedKey[161]; - state[2] ^= expandedKey[162]; - state[3] ^= expandedKey[163]; - state[4] ^= expandedKey[164]; - state[5] ^= expandedKey[165]; - state[6] ^= expandedKey[166]; - state[7] ^= expandedKey[167]; - state[8] ^= expandedKey[168]; - state[9] ^= expandedKey[169]; - state[10] ^= expandedKey[170]; - state[11] ^= expandedKey[171]; - state[12] ^= expandedKey[172]; - state[13] ^= expandedKey[173]; - state[14] ^= expandedKey[174]; - state[15] ^= expandedKey[175]; + state[0] ^= expanded_key[160]; + state[1] ^= expanded_key[161]; + state[2] ^= expanded_key[162]; + state[3] ^= expanded_key[163]; + state[4] ^= expanded_key[164]; + state[5] ^= expanded_key[165]; + state[6] ^= expanded_key[166]; + state[7] ^= expanded_key[167]; + state[8] ^= expanded_key[168]; + state[9] ^= expanded_key[169]; + state[10] ^= expanded_key[170]; + state[11] ^= expanded_key[171]; + state[12] ^= expanded_key[172]; + state[13] ^= expanded_key[173]; + state[14] ^= expanded_key[174]; + state[15] ^= expanded_key[175]; } /****************************************************************************** @@ -341,7 +350,7 @@ void aes_encr(uint8_t *state, uint8_t *expandedKey) * with "for (....)" to save cycles * * Input Parameters: - * expandedKey expanded AES128 key + * expanded_key expanded AES128 key * state 16 bytes of cipher text and plain text * * Returned Value: @@ -349,61 +358,64 @@ void aes_encr(uint8_t *state, uint8_t *expandedKey) * ******************************************************************************/ -void aes_decr(uint8_t *state, uint8_t *expandedKey) +static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key) { - uint8_t buf1, buf2, buf3; + uint8_t buf1; + uint8_t buf2; + uint8_t buf3; int8_t round; + round = 9; /* Initial addroundkey */ - state[0] ^= expandedKey[160]; - state[1] ^= expandedKey[161]; - state[2] ^= expandedKey[162]; - state[3] ^= expandedKey[163]; - state[4] ^= expandedKey[164]; - state[5] ^= expandedKey[165]; - state[6] ^= expandedKey[166]; - state[7] ^= expandedKey[167]; - state[8] ^= expandedKey[168]; - state[9] ^= expandedKey[169]; - state[10] ^= expandedKey[170]; - state[11] ^= expandedKey[171]; - state[12] ^= expandedKey[172]; - state[13] ^= expandedKey[173]; - state[14] ^= expandedKey[174]; - state[15] ^= expandedKey[175]; + state[0] ^= expanded_key[160]; + state[1] ^= expanded_key[161]; + state[2] ^= expanded_key[162]; + state[3] ^= expanded_key[163]; + state[4] ^= expanded_key[164]; + state[5] ^= expanded_key[165]; + state[6] ^= expanded_key[166]; + state[7] ^= expanded_key[167]; + state[8] ^= expanded_key[168]; + state[9] ^= expanded_key[169]; + state[10] ^= expanded_key[170]; + state[11] ^= expanded_key[171]; + state[12] ^= expanded_key[172]; + state[13] ^= expanded_key[173]; + state[14] ^= expanded_key[174]; + state[15] ^= expanded_key[175]; /* 10th round without mixcols */ - state[0] = rsbox[state[0]] ^ expandedKey[(round * 16)]; - state[4] = rsbox[state[4]] ^ expandedKey[(round * 16) + 4]; - state[8] = rsbox[state[8]] ^ expandedKey[(round * 16) + 8]; - state[12] = rsbox[state[12]] ^ expandedKey[(round * 16) + 12]; + state[0] = g_rsbox[state[0]] ^ expanded_key[(round * 16)]; + state[4] = g_rsbox[state[4]] ^ expanded_key[(round * 16) + 4]; + state[8] = g_rsbox[state[8]] ^ expanded_key[(round * 16) + 8]; + state[12] = g_rsbox[state[12]] ^ expanded_key[(round * 16) + 12]; /* Row 1 */ - buf1 = rsbox[state[13]] ^ expandedKey[(round * 16) + 1]; - state[13] = rsbox[state[9]] ^ expandedKey[(round * 16) + 13]; - state[9] = rsbox[state[5]] ^ expandedKey[(round * 16) + 9]; - state[5] = rsbox[state[1]] ^ expandedKey[(round * 16) + 5]; + buf1 = g_rsbox[state[13]] ^ expanded_key[(round * 16) + 1]; + state[13] = g_rsbox[state[9]] ^ expanded_key[(round * 16) + 13]; + state[9] = g_rsbox[state[5]] ^ expanded_key[(round * 16) + 9]; + state[5] = g_rsbox[state[1]] ^ expanded_key[(round * 16) + 5]; state[1] = buf1; /* Row 2 */ - buf1 = rsbox[state[2]] ^ expandedKey[(round * 16) + 10]; - buf2 = rsbox[state[6]] ^ expandedKey[(round * 16) + 14]; - state[2] = rsbox[state[10]] ^ expandedKey[(round * 16) + 2]; - state[6] = rsbox[state[14]] ^ expandedKey[(round * 16) + 6]; + buf1 = g_rsbox[state[2]] ^ expanded_key[(round * 16) + 10]; + buf2 = g_rsbox[state[6]] ^ expanded_key[(round * 16) + 14]; + state[2] = g_rsbox[state[10]] ^ expanded_key[(round * 16) + 2]; + state[6] = g_rsbox[state[14]] ^ expanded_key[(round * 16) + 6]; state[10] = buf1; state[14] = buf2; /* Row 3 */ - buf1 = rsbox[state[3]] ^ expandedKey[(round * 16) + 15]; - state[3] = rsbox[state[7]] ^ expandedKey[(round * 16) + 3]; - state[7] = rsbox[state[11]] ^ expandedKey[(round * 16) + 7]; - state[11] = rsbox[state[15]] ^ expandedKey[(round * 16) + 11]; + buf1 = g_rsbox[state[3]] ^ expanded_key[(round * 16) + 15]; + state[3] = g_rsbox[state[7]] ^ expanded_key[(round * 16) + 3]; + state[7] = g_rsbox[state[11]] ^ expanded_key[(round * 16) + 7]; + state[11] = g_rsbox[state[15]] ^ expanded_key[(round * 16) + 11]; state[15] = buf1; for (round = 8; round >= 0; round--) @@ -485,39 +497,43 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) /* addroundkey, rsbox and shiftrows */ /* Row 0 */ - state[0] = rsbox[state[0]] ^ expandedKey[(round * 16)]; - state[4] = rsbox[state[4]] ^ expandedKey[(round * 16) + 4]; - state[8] = rsbox[state[8]] ^ expandedKey[(round * 16) + 8]; - state[12] = rsbox[state[12]] ^ expandedKey[(round * 16) + 12]; + state[0] = g_rsbox[state[0]] ^ expanded_key[(round * 16)]; + state[4] = g_rsbox[state[4]] ^ expanded_key[(round * 16) + 4]; + state[8] = g_rsbox[state[8]] ^ expanded_key[(round * 16) + 8]; + state[12] = g_rsbox[state[12]] ^ expanded_key[(round * 16) + 12]; /* Row 1 */ - buf1 = rsbox[state[13]] ^ expandedKey[(round * 16) + 1]; - state[13] = rsbox[state[9]] ^ expandedKey[(round * 16) + 13]; - state[9] = rsbox[state[5]] ^ expandedKey[(round * 16) + 9]; - state[5] = rsbox[state[1]] ^ expandedKey[(round * 16) + 5]; + buf1 = g_rsbox[state[13]] ^ expanded_key[(round * 16) + 1]; + state[13] = g_rsbox[state[9]] ^ expanded_key[(round * 16) + 13]; + state[9] = g_rsbox[state[5]] ^ expanded_key[(round * 16) + 9]; + state[5] = g_rsbox[state[1]] ^ expanded_key[(round * 16) + 5]; state[1] = buf1; /* Row 2 */ - buf1 = rsbox[state[2]] ^ expandedKey[(round * 16) + 10]; - buf2 = rsbox[state[6]] ^ expandedKey[(round * 16) + 14]; - state[2] = rsbox[state[10]] ^ expandedKey[(round * 16) + 2]; - state[6] = rsbox[state[14]] ^ expandedKey[(round * 16) + 6]; + buf1 = g_rsbox[state[2]] ^ expanded_key[(round * 16) + 10]; + buf2 = g_rsbox[state[6]] ^ expanded_key[(round * 16) + 14]; + state[2] = g_rsbox[state[10]] ^ expanded_key[(round * 16) + 2]; + state[6] = g_rsbox[state[14]] ^ expanded_key[(round * 16) + 6]; state[10] = buf1; state[14] = buf2; /* Row 3 */ - buf1 = rsbox[state[3]] ^ expandedKey[(round * 16) + 15]; - state[3] = rsbox[state[7]] ^ expandedKey[(round * 16) + 3]; - state[7] = rsbox[state[11]] ^ expandedKey[(round * 16) + 7]; - state[11] = rsbox[state[15]] ^ expandedKey[(round * 16) + 11]; + buf1 = g_rsbox[state[3]] ^ expanded_key[(round * 16) + 15]; + state[3] = g_rsbox[state[7]] ^ expanded_key[(round * 16) + 3]; + state[7] = g_rsbox[state[11]] ^ expanded_key[(round * 16) + 7]; + state[11] = g_rsbox[state[15]] ^ expanded_key[(round * 16) + 11]; state[15] = buf1; } } /**************************************************************************** + * Public Functions + ****************************************************************************/ + + /**************************************************************************** * Name: aes_encrypt * * Description: @@ -534,12 +550,12 @@ void aes_decr(uint8_t *state, uint8_t *expandedKey) * ****************************************************************************/ -void aes_encrypt(uint8_t *state, uint8_t *key) +void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key) { /* Expand the key into 176 bytes */ - expandKey(aexpandedKey, key); - aes_encr(state, aexpandedKey); + expand_key(g_expanded_key, key); + aes_encr(state, g_expanded_key); } /**************************************************************************** @@ -559,58 +575,8 @@ void aes_encrypt(uint8_t *state, uint8_t *key) * ****************************************************************************/ -void aes_decrypt(uint8_t *state, uint8_t *key) +void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key) { - expandKey(aexpandedKey, key); /* Expand the key into 176 bytes */ - aes_decr(state, aexpandedKey); + expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */ + aes_decr(state, g_expanded_key); } - -/**************************************************************************** - * Name: aes_read_key - * - * Description: - * Reads AES128 key from EEPROM. Reads the AES128 key from fileID #12 in - * EEPROM returns an error if the key does not exist. - * - * Input Parameters: - * key AES128 key of size 16 bytes - * - * Returned Value - * On success 0, error otherwise. - * - ****************************************************************************/ - -signed long aes_read_key(uint8_t *key) -{ - signed long returnValue; - - returnValue = nvmem_read(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); - - return returnValue; -} - -/**************************************************************************** - * Name: aes_write_key - * - * Description: - * Writes AES128 key from EEPROM Writes the AES128 key to fileID #12 in - * EEPROM - * - * Input Parameters: - * key AES128 key of size 16 bytes - * - * Returned Value - * On success 0, error otherwise. - * - ****************************************************************************/ - -signed long aes_write_key(uint8_t *key) -{ - signed long returnValue; - - returnValue = nvmem_write(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); - - return returnValue; -} - -#endif /* CC3000_UNENCRYPTED_SMART_CONFIG */ diff --git a/drivers/wireless/cc3000/Kconfig b/drivers/wireless/cc3000/Kconfig index 038fd348f2..c1e65c4099 100644 --- a/drivers/wireless/cc3000/Kconfig +++ b/drivers/wireless/cc3000/Kconfig @@ -8,6 +8,8 @@ config WL_CC3000 default n select SPI select ARCH_HAVE_NET + select CRYPTO + select CRYPTO_SW_AES ---help--- Enable support for the TI CC3000 Wifi Module diff --git a/drivers/wireless/cc3000/Make.defs b/drivers/wireless/cc3000/Make.defs index 8ab9cb9211..9571d750ab 100644 --- a/drivers/wireless/cc3000/Make.defs +++ b/drivers/wireless/cc3000/Make.defs @@ -38,7 +38,7 @@ ifeq ($(CONFIG_WL_CC3000),y) # Include cc3000 drivers CSRCS += cc3000.c cc3000_common.c cc3000drv.c evnt_handler.c hci.c netapp.c -CSRCS += nvmem.c security.c socket.c socket_imp.c wlan.c +CSRCS += nvmem.c socket.c socket_imp.c wlan.c # Include wireless devices build support diff --git a/drivers/wireless/cc3000/wlan.c b/drivers/wireless/cc3000/wlan.c index 6d9ad12997..3b3eda23e8 100644 --- a/drivers/wireless/cc3000/wlan.c +++ b/drivers/wireless/cc3000/wlan.c @@ -43,11 +43,12 @@ #include #include +#include + #include #include #include #include -#include #include #include "cc3000.h" @@ -1204,6 +1205,58 @@ long wlan_smart_config_set_prefix(FAR char *cNewPrefix) return ret; } +/**************************************************************************** + * Name: aes_read_key + * + * Description: + * Reads AES128 key from EEPROM. Reads the AES128 key from fileID #12 in + * EEPROM returns an error if the key does not exist. + * + * Input Parameters: + * key AES128 key of size 16 bytes + * + * Returned Value + * On success 0, error otherwise. + * + ****************************************************************************/ + +#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +signed long aes_read_key(uint8_t *key) +{ + signed long returnValue; + + returnValue = nvmem_read(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); + + return returnValue; +} +#endif + +/**************************************************************************** + * Name: aes_write_key + * + * Description: + * Writes AES128 key from EEPROM Writes the AES128 key to fileID #12 in + * EEPROM + * + * Input Parameters: + * key AES128 key of size 16 bytes + * + * Returned Value + * On success 0, error otherwise. + * + ****************************************************************************/ + +#if 0 //#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +signed long aes_write_key(uint8_t *key) +{ + signed long returnValue; + + returnValue = nvmem_write(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); + + return returnValue; +} +#endif + /**************************************************************************** * Name: wlan_smart_config_process * diff --git a/include/nuttx/crypto/aes.h b/include/nuttx/crypto/aes.h new file mode 100644 index 0000000000..aebe59e84b --- /dev/null +++ b/include/nuttx/crypto/aes.h @@ -0,0 +1,108 @@ +/**************************************************************************** + * include/nuttx/crypto/aes.h + * + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ + * Extracted from the CC3000 Host Driver Implementation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_CRYPTO_AES_H +#define __INCLUDE_NUTTX_CRYPTO_AES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define AES128_KEY_SIZE 16 + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/**************************************************************************** + * Public Function Prototypes +/**************************************************************************** + +/**************************************************************************** + * Name: aes_encrypt + * + * Description: + * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher + * text of 16 bytes is computed. The AES implementation is in mode ECB + * (Electronic Code Book). + * + * Input Parameters: + * key AES128 key of size 16 bytes + * state 16 bytes of plain text and cipher text + * + * Returned Value + * None + * + ****************************************************************************/ + +void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key); + +/**************************************************************************** + * Name: aes_decrypt + * + * Description: + * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain + * text of 16 bytes is computed The AES implementation is in mode ECB + * (Electronic Code Book). + * + * Input Parameters: + * key AES128 key of size 16 bytes + * state 16 bytes of plain text and cipher text + * + * Returned Value + * None + * + ****************************************************************************/ + +void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __INCLUDE_NUTTX_CRYPTO_AES_H */ diff --git a/include/nuttx/wireless/cc3000/security.h b/include/nuttx/wireless/cc3000/security.h deleted file mode 100644 index 4a57340bb1..0000000000 --- a/include/nuttx/wireless/cc3000/security.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * security.h - CC3000 Host Driver Implementation. - * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef _INCLUDE_NUTTX_WIRELESS_CC3000_SECURITY_H -#define _INCLUDE_NUTTX_WIRELESS_CC3000_SECURITY_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "nvmem.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define AES128_KEY_SIZE 16 - -#ifndef CC3000_UNENCRYPTED_SMART_CONFIG - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Public Function Prototypes -/**************************************************************************** - -/**************************************************************************** - * Name: aes_encrypt - * - * Description: - * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher - * text of 16 bytes is computed. The AES implementation is in mode ECB - * (Electronic Code Book). - * - * Input Parameters: - * key AES128 key of size 16 bytes - * state 16 bytes of plain text and cipher text - * - * Returned Value - * None - * - ****************************************************************************/ - -void aes_encrypt(uint8_t *state, uint8_t *key); - -/**************************************************************************** - * Name: aes_decrypt - * - * Description: - * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain - * text of 16 bytes is computed The AES implementation is in mode ECB - * (Electronic Code Book). - * - * Input Parameters: - * key AES128 key of size 16 bytes - * state 16 bytes of plain text and cipher text - * - * Returned Value - * None - * - ****************************************************************************/ - -void aes_decrypt(uint8_t *state, uint8_t *key); - -/**************************************************************************** - * Name: aes_read_key - * - * Description: - * Reads AES128 key from EEPROM. Reads the AES128 key from fileID #12 in - * EEPROM returns an error if the key does not exist. - * - * Input Parameters: - * key AES128 key of size 16 bytes - * - * Returned Value - * On success 0, error otherwise. - * - ****************************************************************************/ - -signed long aes_read_key(uint8_t *key); - -/**************************************************************************** - * Name: aes_write_key - * - * Description: - * Writes AES128 key from EEPROM Writes the AES128 key to fileID #12 in - * EEPROM - * - * Input Parameters: - * key AES128 key of size 16 bytes - * - * Returned Value - * On success 0, error otherwise. - * - ****************************************************************************/ - -signed long aes_write_key(uint8_t *key); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CC3000_UNENCRYPTED_SMART_CONFIG */ -#endif /* _INCLUDE_NUTTX_WIRELESS_CC3000_SECURITY_H */ diff --git a/include/nuttx/wireless/cc3000/wlan.h b/include/nuttx/wireless/cc3000/wlan.h index 867ea2032b..b0a07c67d8 100644 --- a/include/nuttx/wireless/cc3000/wlan.h +++ b/include/nuttx/wireless/cc3000/wlan.h @@ -489,6 +489,40 @@ long wlan_smart_config_stop(void); long wlan_smart_config_set_prefix(char* cNewPrefix); +/**************************************************************************** + * Name: aes_read_key + * + * Description: + * Reads AES128 key from EEPROM. Reads the AES128 key from fileID #12 in + * EEPROM returns an error if the key does not exist. + * + * Input Parameters: + * key AES128 key of size 16 bytes + * + * Returned Value + * On success 0, error otherwise. + * + ****************************************************************************/ + +signed long aes_read_key(FAR uint8_t *key); + +/**************************************************************************** + * Name: aes_write_key + * + * Description: + * Writes AES128 key from EEPROM Writes the AES128 key to fileID #12 in + * EEPROM + * + * Input Parameters: + * key AES128 key of size 16 bytes + * + * Returned Value + * On success 0, error otherwise. + * + ****************************************************************************/ + +signed long aes_write_key(FAR uint8_t *key); + /**************************************************************************** * Name: wlan_smart_config_process * -- GitLab From 580529ba238d3799a8bfe0f8998510590f70a639 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 16 Nov 2015 14:30:43 -0600 Subject: [PATCH 297/858] crypto/aes.c: Make refernce to key const --- ChangeLog | 3 +++ crypto/aes.c | 26 ++++++++++++++++---------- include/nuttx/crypto/aes.h | 8 ++++---- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3614e40162..27e9dae4d0 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11093,4 +11093,7 @@ file calculated partition boundries based on page block sizes but mtd_partition() is expecting calculations based on erase block size. From Alan Carvalho de Assis (2015-11-16). + * Move rivers/wireless/cc3000/security.c to crypto/aes.c; move + include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h + (2015-11-16). diff --git a/crypto/aes.c b/crypto/aes.c index fb05a4cab2..d82e16f46a 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -121,7 +121,7 @@ static uint8_t g_expanded_key[176]; * ****************************************************************************/ -static void expand_key(FAR uint8_t *expanded_key, FAR uint8_t *key) +static void expand_key(FAR uint8_t *expanded_key, FAR const uint8_t *key) { uint16_t buf1; uint16_t ii; @@ -185,25 +185,28 @@ static uint8_t galois_mul2(uint8_t value) * * Description: * Internal implementation of AES128 encryption. - * Straight forward aes encryption implementation. First the group of operations + * Straight forward aes encryption implementation. First the group of + * operations: + * * - addRoundKey * - subbytes * - shiftrows * - mixcolums + * * is executed 9 times, after this addroundkey to finish the 9th round, after * that the 10th round without mixcolums no further subfunctions to save * cycles for function calls no structuring with "for (....)" to save cycles. * * Input Parameters: * expanded_key expanded AES128 key - * state 16 bytes of plain text and cipher text + * state 16 bytes of plain text and cipher text * * Returned Value: * None * ******************************************************************************/ -static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key) +static void aes_encr(FAR uint8_t *state, FAR const uint8_t *expanded_key) { uint8_t buf1; uint8_t buf2; @@ -342,23 +345,25 @@ static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key) * Internal implementation of AES128 decryption. * Straight forward aes decryption implementation. The order of substeps is * the exact reverse of decryption inverse functions: + * * - addRoundKey is its own inverse * - rsbox is inverse of sbox * - rightshift instead of leftshift * - invMixColumns = barreto + mixColumns + * * No further subfunctions to save cycles for function calls no structuring * with "for (....)" to save cycles * * Input Parameters: * expanded_key expanded AES128 key - * state 16 bytes of cipher text and plain text + * state 16 bytes of cipher text and plain text * * Returned Value: * None * ******************************************************************************/ -static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key) +static void aes_decr(FAR uint8_t *state, FAR const uint8_t *expanded_key) { uint8_t buf1; uint8_t buf2; @@ -537,7 +542,7 @@ static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key) * Name: aes_encrypt * * Description: - * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher + * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher * text of 16 bytes is computed. The AES implementation is in mode ECB * (Electronic Code Book). * @@ -550,7 +555,7 @@ static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key) * ****************************************************************************/ -void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key) +void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key) { /* Expand the key into 176 bytes */ @@ -562,7 +567,7 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key) * Name: aes_decrypt * * Description: - * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain + * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain * text of 16 bytes is computed The AES implementation is in mode ECB * (Electronic Code Book). * @@ -575,8 +580,9 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key) * ****************************************************************************/ -void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key) +void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key) { expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */ aes_decr(state, g_expanded_key); } + diff --git a/include/nuttx/crypto/aes.h b/include/nuttx/crypto/aes.h index aebe59e84b..5c4d3e8050 100644 --- a/include/nuttx/crypto/aes.h +++ b/include/nuttx/crypto/aes.h @@ -67,7 +67,7 @@ extern "C" * Name: aes_encrypt * * Description: - * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher + * AES128 encryption: Given AES128 key and 16 bytes plain text, cipher * text of 16 bytes is computed. The AES implementation is in mode ECB * (Electronic Code Book). * @@ -80,13 +80,13 @@ extern "C" * ****************************************************************************/ -void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key); +void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key); /**************************************************************************** * Name: aes_decrypt * * Description: - * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain + * AES128 decryption: Given AES128 key and 16 bytes cipher text, plain * text of 16 bytes is computed The AES implementation is in mode ECB * (Electronic Code Book). * @@ -99,7 +99,7 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key); * ****************************************************************************/ -void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key); +void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key); #ifdef __cplusplus } -- GitLab From 876cb1335653775b1a33ef30572a30fdd3e9890a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 16 Nov 2015 16:10:01 -0600 Subject: [PATCH 298/858] Crypto: Mostly cosmetic changes --- crypto/Kconfig | 4 +++ crypto/aes.c | 10 ++++-- crypto/cryptodev.c | 80 ++++++++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/crypto/Kconfig b/crypto/Kconfig index 7da34a7a45..022fce7a05 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -46,4 +46,8 @@ config CRYPTO_SW_AES Enable the software AES library as described in include/nuttx/crypto/aes.h + TODO: Adapt interfaces so that they are consistent with H/W AES + implemenations. This needs to support up_aesinitialize() and + aes_cypher() per include/nuttx/crypto/crypto.h. + endif # CRYPTO diff --git a/crypto/aes.c b/crypto/aes.c index d82e16f46a..e7c638f718 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -34,6 +34,11 @@ * ****************************************************************************/ +/* TODO: Adapt interfaces so that they are consistent with H/W AES + * implemenations. This needs to support up_aesinitialize() and + * aes_cypher() per include/nuttx/crypto/crypto.h. + */ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -582,7 +587,8 @@ void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key) void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key) { - expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */ + /* Expand the key into 176 bytes */ + + expand_key(g_expanded_key, key); aes_decr(state, g_expanded_key); } - diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index c81585c329..9710acf028 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -50,6 +50,16 @@ #include #include +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_CRYPTO_AES +# define AES_CYPHER(mode) \ + aes_cypher(op->dst, op->src, op->len, op->iv, ses->key, ses->keylen, \ + mode, encrypt) +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -69,13 +79,18 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, static const struct file_operations g_cryptodevops = { - 0, /* open */ - 0, /* close */ - cryptodev_read, /* read */ - cryptodev_write, /* write */ - 0, /* seek */ - cryptodev_ioctl, /* ioctl */ - 0, /* poll */ + 0, /* open */ + 0, /* close */ + cryptodev_read, /* read */ + cryptodev_write, /* write */ + 0, /* seek */ + cryptodev_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , 0 /* unlink */ +#endif }; /**************************************************************************** @@ -110,6 +125,7 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return OK; } +#ifdef CONFIG_CRYPTO_AES case CIOCCRYPT: { FAR struct crypt_op *op = (FAR struct crypt_op *)arg; @@ -117,44 +133,38 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) int encrypt; switch (op->op) - { - case COP_ENCRYPT: - encrypt = 1; - break; + { + case COP_ENCRYPT: + encrypt = 1; + break; - case COP_DECRYPT: - encrypt = 0; - break; + case COP_DECRYPT: + encrypt = 0; + break; - default: - return -EINVAL; - } + default: + return -EINVAL; + } switch (ses->cipher) - { - -#if defined(CONFIG_CRYPTO_AES) -# define AES_CYPHER(mode) aes_cypher(op->dst, op->src, op->len, op->iv, ses->key, ses->keylen, mode, encrypt) - - case CRYPTO_AES_ECB: - return AES_CYPHER(AES_MODE_ECB); + { + case CRYPTO_AES_ECB: + return AES_CYPHER(AES_MODE_ECB); - case CRYPTO_AES_CBC: - return AES_CYPHER(AES_MODE_CBC); + case CRYPTO_AES_CBC: + return AES_CYPHER(AES_MODE_CBC); - case CRYPTO_AES_CTR: - return AES_CYPHER(AES_MODE_CTR); + case CRYPTO_AES_CTR: + return AES_CYPHER(AES_MODE_CTR); -# undef AES_CYPHER -#endif - - default: - return -EINVAL; - } + default: + return -EINVAL; + } } +#endif default: - return -EINVAL; + return -ENOTTY; } } -- GitLab From 826aadbce8cb570e36dfefa882aae4b7ee855835 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Tue, 17 Nov 2015 14:09:43 +0100 Subject: [PATCH 299/858] Include support for PCA9555 interrupt driven IO changes detection. Currently using a signal, and a single notified task. signal handling support moved to generic IO expander header (not pca specific) --- drivers/discrete/Kconfig | 30 ++++++++++------ drivers/discrete/pca9555.c | 53 +++++++++++++++++++++++------ drivers/discrete/pca9555.h | 16 ++------- include/nuttx/discrete/ioexpander.h | 12 +++++++ 4 files changed, 76 insertions(+), 35 deletions(-) diff --git a/drivers/discrete/Kconfig b/drivers/discrete/Kconfig index 787c6e541a..4a25c72703 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/discrete/Kconfig @@ -12,13 +12,6 @@ menuconfig IOEXPANDER if IOEXPANDER -config IOEXPANDER_MULTIPIN - bool "Support multi-pin access routines" - default n - ---help--- - This settings enable the definition of routines for - optimized simultaneous access to multiple pins. - config IOEXPANDER_PCA9555 bool "PCA9555 I2C IO expander" default n @@ -34,13 +27,28 @@ config PCA9555_MULTIPLE ---help--- Can be defined to support multiple PCA9555 devices on board. -config PCA9555_INT_DISABLE - bool "Disable PCA9555 Interrupt Support" - default y +config PCA9555_INT_ENABLE + bool "Enable PCA9555 Interrupt Support" + default n + select IOEXPANDER_INT_ENABLE ---help--- - Disable driver interrupt functionality + Enable driver interrupt functionality endif # IOEXPANDER_PCA9555 + +config IOEXPANDER_INT_ENABLE + bool + default y if PCA9555_INT_ENABLE + ---help--- + This is the global INT supported flag for io expanders + +config IOEXPANDER_MULTIPIN + bool "Support multi-pin access routines" + default n + ---help--- + This settings enable the definition of routines for + optimized simultaneous access to multiple pins. + endif # IOEXPANDER config USERLED diff --git a/drivers/discrete/pca9555.c b/drivers/discrete/pca9555.c index da8a385d6b..5651641d98 100644 --- a/drivers/discrete/pca9555.c +++ b/drivers/discrete/pca9555.c @@ -436,7 +436,7 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, #endif -#ifndef CONFIG_PCA9555_INT_DISABLE +#ifdef CONFIG_PCA9555_INT_ENABLE /**************************************************************************** * Name: pca9555_irqworker @@ -451,23 +451,54 @@ static void pca9555_irqworker(void *arg) { uint8_t addr = PCA9555_REG_INPUT; uint8_t buf[2]; - int ret; - FAR struct pca9555_dev_s *dev = (FAR struct pca9555_dev_s*)arg; + int ret, bits; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)arg; /* read inputs */ - ret = I2C_WRITEREAD(dev->i2c, &addr, 1, buf, 2); - dbg("> %02X %02X\n",buf[0],buf[1]); + ret = I2C_WRITEREAD(pca->i2c, &addr, 1, buf, 2); + if( ret != OK) + { + return; + } + + bits = (buf[0]<<8) | buf[1]; + + /* if signal PID is registered, enqueue signal. */ + if(pca->dev.sigpid) + { +#ifdef CONFIG_CAN_PASS_STRUCTS + union sigval value; + value.sival_int = bits; + ret = sigqueue(pca->dev.sigpid, pca->dev.sigval, value); +#else + ret = sigqueue(pca->dev.sigpid, pca->dev.sigval, (FAR void*)bits); +#endif + dbg("pca signal %04X (sig %d to pid %d)\n",bits, pca->dev.sigval, pca->dev.sigpid); + } + else + { + dbg("no handler registered\n"); + } /* re-enable */ - dev->config->enable(dev->config, TRUE); + pca->config->enable(pca->config, TRUE); } +/**************************************************************************** + * Name: pca9555_interrupt + * + * Description: + * Handle GPIO interrupt events (this function executes in the + * context of the interrupt). + * + ****************************************************************************/ + static int pca9555_interrupt(int irq, FAR void *context) { /* To support multiple devices, * retrieve the priv structure using the irq number */ - register FAR struct pca9555_dev_s *dev = &g_pca9555; + register FAR struct pca9555_dev_s *pca = &g_pca9555; /* In complex environments, we cannot do I2C transfers from the interrupt * handler because semaphores are probably used to lock the I2C bus. In @@ -476,15 +507,15 @@ static int pca9555_interrupt(int irq, FAR void *context) * a good thing to do in any event. */ - DEBUGASSERT(work_available(&dev->work)); + DEBUGASSERT(work_available(&pca->dev.work)); /* Notice that further GPIO interrupts are disabled until the work is * actually performed. This is to prevent overrun of the worker thread. * Interrupts are re-enabled in pca9555_irqworker() when the work is completed. */ - dev->config->enable(dev->config, FALSE); - return work_queue(HPWORK, &dev->work, pca9555_irqworker, (FAR void *)dev, 0); + pca->config->enable(pca->config, FALSE); + return work_queue(HPWORK, &pca->dev.work, pca9555_irqworker, (FAR void *)pca, 0); } #endif @@ -546,7 +577,7 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_dev_s *i2cdev, I2C_SETADDRESS(i2cdev, config->address, 7); I2C_SETFREQUENCY(i2cdev, config->frequency); -#ifndef CONFIG_PCA9555_INT_DISABLE +#ifdef CONFIG_PCA9555_INT_ENABLE pcadev->config->attach(pcadev->config, pca9555_interrupt); pcadev->config->enable(pcadev->config, TRUE); #endif diff --git a/drivers/discrete/pca9555.h b/drivers/discrete/pca9555.h index 4819e0f880..638180e291 100644 --- a/drivers/discrete/pca9555.h +++ b/drivers/discrete/pca9555.h @@ -48,7 +48,6 @@ #include #include -#include #include #include @@ -95,12 +94,6 @@ #error "CONFIG_I2C is required by PCA9555" #endif -#ifndef CONFIG_PCA9555_INT_DISABLE -#ifndef CONFIG_SCHED_WORKQUEUE -#error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." -#endif -#endif - #define PCA9555_MAXDEVS 8 /* I2C frequency */ @@ -123,18 +116,15 @@ struct pca9555_dev_s { - struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio expander. */ + struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio expander. */ #ifdef CONFIG_PCA9555_MULTIPLE - FAR struct pca9555_dev_s *flink; /* Supports a singly linked list of drivers */ + FAR struct pca9555_dev_s * flink; /* Supports a singly linked list of drivers */ #endif FAR struct pca9555_config_s *config; /* Board configuration data */ - FAR struct i2c_dev_s *i2c; /* Saved I2C driver instance */ + FAR struct i2c_dev_s * i2c; /* Saved I2C driver instance */ -#ifndef CONFIG_PCA9555_INT_DISABLE - struct work_s work; /* Supports the interrupt handling "bottom half" */ -#endif }; #endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9555 */ diff --git a/include/nuttx/discrete/ioexpander.h b/include/nuttx/discrete/ioexpander.h index 609961d895..9adbb065d3 100644 --- a/include/nuttx/discrete/ioexpander.h +++ b/include/nuttx/discrete/ioexpander.h @@ -41,9 +41,16 @@ ****************************************************************************/ #include +#include #if defined(CONFIG_IOEXPANDER) +#ifndef CONFIG_PCA9555_INT_DISABLE +#ifndef CONFIG_SCHED_WORKQUEUE +#error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." +#endif +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -249,6 +256,11 @@ struct ioexpander_ops_s struct ioexpander_dev_s { FAR const struct ioexpander_ops_s *ops; +#ifdef CONFIG_IOEXPANDER_INT_ENABLE + struct work_s work; /* Supports the interrupt handling "bottom half" */ + int sigpid; /* PID to be signaled in case of interrupt */ + int sigval; /* signal to be sent in case of interrupt */ +#endif }; #endif //CONFIG_IOEXPANDER -- GitLab From 724901ceb9a5c30f473d9173802b4cd9d7323306 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 07:40:17 -0600 Subject: [PATCH 300/858] Add support for multiple AT24xx EEPROM devices --- ChangeLog | 2 ++ drivers/mtd/Kconfig | 10 ++++++++++ drivers/mtd/at24xx.c | 40 ++++++++++++++++++++++++++++++++++------ include/nuttx/mtd/mtd.h | 6 ++++++ 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27e9dae4d0..3713274c66 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11096,4 +11096,6 @@ * Move rivers/wireless/cc3000/security.c to crypto/aes.c; move include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h (2015-11-16). + * drivers/mtd/at24xx.c: Add support for multiple AT24xx EEPROM parts, + each with unique I2C addresses, but otherwise idential (2015-11-17). diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index bacabb0856..03f08fd0e7 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -278,6 +278,15 @@ config MTD_AT24XX if MTD_AT24XX +config AT24XX_MULTI + bool "Multiple AT24XX devices" + default n + ---help--- + Build in additional support for multiple AT24XX devices, each with + dynamically allocated device structures wiath a separate I2C + addresses (but otherwise identical -- support for multiple, different + AT24xx, devices not yet supported). + config AT24XX_SIZE int "AT24xx size (Kbit)" default 64 @@ -291,6 +300,7 @@ config AT24XX_ADDR hex "AT24XX I2C address" default 0x50 range 0x50 0x57 + depends on !AT24XX_MULTI ---help--- The I2C address of the FLASH part. This is should be 0b01010aaa (where aaa is determined by board/pin configuration). diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 31e909334b..f928f27d4a 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -74,11 +74,12 @@ # warning "Assuming AT24 size 64" # define CONFIG_AT24XX_SIZE 64 #endif -#ifndef CONFIG_AT24XX_ADDR -# warning "Assuming AT24 address of 0x50" +#if !defined(CONFIG_AT24XX_ADDR) && !defined(CONFIG_AT24XX_MULTI) +# warning "Assuming AT24 I2C address of 0x50" # define CONFIG_AT24XX_ADDR 0x50 #endif #ifndef CONFIG_AT24XX_FREQUENCY +# warning "Assuming AT24 I2C frequency of 100KHz" # define CONFIG_AT24XX_FREQUENCY 100000 #endif @@ -134,7 +135,7 @@ */ #ifndef CONFIG_AT24XX_MTD_BLOCKSIZE -# warning "Assuming driver block size is the same as the FLASH page size" +# warning "Assuming MTD driver block size is the same as the FLASH page size" # define CONFIG_AT24XX_MTD_BLOCKSIZE AT24XX_PAGESIZE #endif @@ -179,11 +180,13 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); * Private Data ************************************************************************************/ -/* At present, only a signal AT24 part is supported. In this case, a statically - * allocated state structure may be used. +#ifndef CONFIG_AT24XX_MULTI +/* If only a signal AT24 part is supported then a statically allocated state + * structure may be used. */ static struct at24c_dev_s g_at24c; +#endif /************************************************************************************ * Private Functions @@ -543,11 +546,16 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ************************************************************************************/ +#ifdef CONFIG_AT24XX_MULTI +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, uint8_t address) +#else FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) +#endif { FAR struct at24c_dev_s *priv; - fvdbg("dev: %p\n", dev); +#ifdef CONFIG_AT24XX_MULTI + fvdbg("dev: %p address: %02x\n", dev, address); /* Allocate a state structure (we allocate the structure instead of using * a fixed, static allocation so that we can handle multiple FLASH devices. @@ -556,12 +564,32 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) * to be extended to handle multiple FLASH parts on the same I2C bus. */ + priv = (FAR struct at24c_dev_s *)kmm_zalloc(sizeof(struct at24c_dev_s)); + if (priv == NULL) + { + fdbg("ERROR: Failed to allocate device structure\n"); + return NULL; + } + +#else + fvdbg("dev: %p\n", dev); + + /* If only a signal AT24 part is supported then a statically allocated state + * structure is used. + */ + priv = &g_at24c; +#endif + if (!priv->initd) { /* Initialize the allocated structure */ +#ifdef CONFIG_AT24XX_MULTI + priv->addr = address; +#else priv->addr = CONFIG_AT24XX_ADDR; +#endif priv->pagesize = AT24XX_PAGESIZE; priv->npages = AT24XX_NPAGES; diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index fca8cac94a..69866d1752 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -382,7 +382,13 @@ FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *dev); ****************************************************************************/ struct i2c_dev_s; /* Forward reference */ + +#ifdef CONFIG_AT24XX_MULTI +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, + uint8_t address); +#else FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); +#endif /**************************************************************************** * Name: at25_initialize -- GitLab From e61d51dab3fce109dc31ac88dbbc3701ea23bd6d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 08:39:06 -0600 Subject: [PATCH 301/858] If multiple AT24xx devices are supported and resources are allocated, then it may also be necessary to free those resource --- drivers/mtd/at24xx.c | 19 ++++++++++++++++++- include/nuttx/mtd/mtd.h | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index f928f27d4a..9ce0ee31c8 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -540,7 +540,7 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * Name: at24c_initialize * * Description: - * Create an initialize MTD device instance. MTD devices are not registered + * Create an initialized MTD device instance. MTD devices are not registered * in the file system, but are created as instances that can be bound to * other functions (such as a block or character driver front end). * @@ -618,4 +618,21 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) return (FAR struct mtd_dev_s *)priv; } +/************************************************************************************ + * Name: at24c_uninitialize + * + * Description: + * Release resources held by an allocated MTD device instance. Resources are only + * allocated for the case where multiple AT24xx devices are support. + * + ************************************************************************************/ + +#ifdef CONFIG_AT24XX_MULTI +void at24c_uninitialize(FAR struct mtd_dev_s *mtd) +{ + FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)mtd; + DEBUGASSERT(priv != NULL); + kmm_free(priv); +} +#endif /* CONFIG_AT24XX_MULTI */ #endif /* CONFIG_MTD_AT24XX */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 69866d1752..4bd25a612f 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -390,6 +390,19 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); #endif +/************************************************************************************ + * Name: at24c_uninitialize + * + * Description: + * Release resources held by an allocated MTD device instance. Resources are only + * allocated for the case where multiple AT24xx devices are support. + * + ************************************************************************************/ + +#ifdef CONFIG_AT24XX_MULTI +void at24c_uninitialize(FAR struct mtd_dev_s *mtd); +#endif + /**************************************************************************** * Name: at25_initialize * -- GitLab From 45530a77d42bc7a0411ddd37dc7f6b267fe2590b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 14:07:55 -0600 Subject: [PATCH 302/858] Add support for DS3231 I2C RTC. Untested on initial commit. --- ChangeLog | 2 + Documentation | 2 +- configs | 2 +- drivers/timers/Kconfig | 18 ++ drivers/timers/Make.defs | 6 + drivers/timers/ds3231.c | 474 ++++++++++++++++++++++++++++++++++ drivers/timers/ds3231.h | 274 ++++++++++++++++++++ include/nuttx/timers/ds3231.h | 83 ++++++ 8 files changed, 859 insertions(+), 2 deletions(-) create mode 100644 drivers/timers/ds3231.c create mode 100644 drivers/timers/ds3231.h create mode 100644 include/nuttx/timers/ds3231.h diff --git a/ChangeLog b/ChangeLog index 3713274c66..f8cab43b1e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11098,4 +11098,6 @@ (2015-11-16). * drivers/mtd/at24xx.c: Add support for multiple AT24xx EEPROM parts, each with unique I2C addresses, but otherwise idential (2015-11-17). + * drivers/timers/ds3231.c: Add support for the DS3231 I2C RTC. Untested + on the initial commit (2015-11-17). diff --git a/Documentation b/Documentation index 81e94b2e1d..9a0efe5bb5 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 81e94b2e1d2831d590f07ef729e74a7b66922ac5 +Subproject commit 9a0efe5bb5e0a817f74b4521f4bb0d91b6f0c2cf diff --git a/configs b/configs index 174b30da6b..8a8b3d3ea6 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 174b30da6b334c1e040d4212e31237b5b6aabd06 +Subproject commit 8a8b3d3ea61739a5462058889e8ba5352100ab5f diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index c8579a8fea..1c4f5685de 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -117,6 +117,24 @@ config RTC_IOCTL architecture-specific RTC operations to the RTC interface endif # RTC_DRIVER + +config RTC_DS3231 + bool "DS3231 RTC Driver" + default n + select I2C + select I2C_TRANSFER + select RTC_DATETIME + ---help--- + Enables support for the Maxim Integrated DS3231 I2C RTC timer. + +if RTC_DS3231 + +config DS3231_I2C_FREQUENCY + int "DS3231 I2C frequency" + default 400000 + range 1 4000000 + +endif # RTC_DS3231 endif # RTC menuconfig WATCHDOG diff --git a/drivers/timers/Make.defs b/drivers/timers/Make.defs index f70052a21f..e856991826 100644 --- a/drivers/timers/Make.defs +++ b/drivers/timers/Make.defs @@ -51,6 +51,12 @@ ifeq ($(CONFIG_TIMER),y) TMRVPATH = :timers endif +ifeq ($(CONFIG_RTC_DS3231),y) + CSRCS += ds3231.c + TMRDEPPATH = --dep-path timers + TMRVPATH = :timers +endif + ifeq ($(CONFIG_RTC_DRIVER),y) CSRCS += rtc.c TMRDEPPATH = --dep-path timers diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c new file mode 100644 index 0000000000..c47485d60f --- /dev/null +++ b/drivers/timers/ds3231.c @@ -0,0 +1,474 @@ +/************************************************************************************ + * drivers/timers/ds3231.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "ds3231.h" + +#ifdef CONFIG_RTC_DS3231 + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ +/* This RTC implementation supports only date/time RTC hardware */ + +#ifndef CONFIG_RTC_DATETIME +# error CONFIG_RTC_DATETIME must be set to use this driver +#endif + +#ifdef CONFIG_RTC_HIRES +# error CONFIG_RTC_HIRES must NOT be set with this driver +#endif + +#ifndef CONFIG_I2C_TRANSFER +# error CONFIG_I2C_TRANSFER is required by this driver +#endif + +#ifndef CONFIG_DS3231_I2C_FREQUENCY +# error CONFIG_DS3231_I2C_FREQUENCY is not configured +# define CONFIG_DS3231_I2C_FREQUENCY 400000 +#endif + +#if CONFIG_DS3231_I2C_FREQUENCY > 400000 +# error CONFIG_DS3231_I2C_FREQUENCY is out of range +#endif + +#define DS3231_I2C_ADDRESS 0x68 + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_RTC +#endif + +/* Debug ****************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC +# define rtcdbg dbg +# define rtcvdbg vdbg +# define rtclldbg lldbg +# define rtcllvdbg llvdbg +#else +# define rtcdbg(x...) +# define rtcvdbg(x...) +# define rtclldbg(x...) +# define rtcllvdbg(x...) +#endif + +/************************************************************************************ + * Priviate Types + ************************************************************************************/ +/* This structure describes the state of the DS3231 chip. Only a single RTC is + * supported. + */ + +struct ds3231_dev_s +{ + FAR struct i2c_dev_s *i2c; /* Contained reference to the I2C bus driver */ +}; + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +/* g_rtc_enabled is set true after the RTC has successfully initialized */ + +volatile bool g_rtc_enabled = false; + +/************************************************************************************ + * Private Data + ************************************************************************************/ +/* The state of the DS3231 chip. Only a single RTC is supported */ + +static struct ds3231_dev_s g_ds3231; + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: rtc_dumptime + * + * Description: + * Show the broken out time. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC +static void rtc_dumptime(FAR struct tm *tp, FAR const char *msg) +{ + rtclldbg("%s:\n", msg); + rtclldbg(" tm_sec: %08x\n", tp->tm_sec); + rtclldbg(" tm_min: %08x\n", tp->tm_min); + rtclldbg(" tm_hour: %08x\n", tp->tm_hour); + rtclldbg(" tm_mday: %08x\n", tp->tm_mday); + rtclldbg(" tm_mon: %08x\n", tp->tm_mon); + rtclldbg(" tm_year: %08x\n", tp->tm_year); +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + rtclldbg(" tm_wday: %08x\n", tp->tm_wday); + rtclldbg(" tm_yday: %08x\n", tp->tm_yday); + rtclldbg(" tm_isdst: %08x\n", tp->tm_isdst); +#endif +} +#else +# define rtc_dumptime(tp, msg) +#endif + +/************************************************************************************ + * Name: rtc_bin2bcd + * + * Description: + * Converts a 2 digit binary to BCD format + * + * Input Parameters: + * value - The byte to be converted. + * + * Returned Value: + * The value in BCD representation + * + ************************************************************************************/ + +static uint8_t rtc_bin2bcd(int value) +{ + uint8_t msbcd = 0; + + while (value >= 10) + { + msbcd++; + value -= 10; + } + + return (msbcd << 4) | value; +} + +/************************************************************************************ + * Name: rtc_bin2bcd + * + * Description: + * Convert from 2 digit BCD to binary. + * + * Input Parameters: + * value - The BCD value to be converted. + * + * Returned Value: + * The value in binary representation + * + ************************************************************************************/ + +static int rtc_bcd2bin(uint8_t value) +{ + int tens = ((int)value >> 4) * 10; + return tens + (value & 0x0f); +} + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: ds3231_rtc_initialize + * + * Description: + * Initialize the hardware RTC per the selected configuration. This function is + * called once during the OS initialization sequence + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int ds3231_rtc_initialize(FAR struct i2c_dev_s *i2c) +{ + /* Remember the i2c device and claim that the RTC is enabled */ + + g_ds3231.i2c = i2c; + g_rtc_enabled = true; + return OK; +} + +/************************************************************************************ + * Name: up_rtc_getdatetime + * + * Description: + * Get the current date and time from the date/time RTC. This interface + * is only supported by the date/time RTC hardware implementation. + * It is used to replace the system timer. It is only used by the RTOS during + * initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME + * are selected (and CONFIG_RTC_HIRES is not). + * + * NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That + * sub-second accuracy is lost in this interface. However, since the system time + * is reinitialized on each power-up/reset, there will be no timing inaccuracy in + * the long run. + * + * Input Parameters: + * tp - The location to return the high resolution time value. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int up_rtc_getdatetime(FAR struct tm *tp) +{ + struct i2c_msg_s msg[2]; + uint8_t buffer[8]; + int tmp; + int ret; + + /* Select to begin reading at the seconds register */ + + buffer[0] = DS3231_TIME_SECR; + + msg[0].addr = DS3231_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = buffer; + msg[0].length = 1; + + /* Set up to read 7 registers: secs, min, hr, dow, date, mth, yr */ + + msg[1].addr = DS3231_I2C_ADDRESS; + msg[1].flags = I2C_M_READ; + msg[1].buffer = &buffer[1]; + msg[1].length = 7; + + /* Configure I2C before using it */ + + I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); + + /* Perform the transfer (This could be done with I2C_WRITEREAD()) */ + + ret = I2C_TRANSFER(g_ds3231.i2c, msg, 1); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + return ret; + } + + /* Format the return time */ + /* Return seconds (0-61) */ + + tp->tm_sec = rtc_bcd2bin(buffer[1] & DS3231_TIME_SEC_BCDMASK); + + /* Return minutes (0-59) */ + + tp->tm_min = rtc_bcd2bin(buffer[2] & DS3231_TIME_MIN_BCDMASK); + + /* Return hour (0-23). This assumes 24-hour time was set. */ + + tp->tm_hour = rtc_bcd2bin(buffer[3] & DS3231_TIME_HOUR24_BCDMASK); + + #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + /* Return the day of the week (0-6) */ + + tp->tm_wday = (rtc_bcd2bin(buffer[4]) & DS3231_TIME_DAY_MASK)- 1; +#endif + + /* Return the day of the month (1-31) */ + + tp->tm_mday = rtc_bcd2bin(buffer[5] & DS3231_TIME_DATE_BCDMASK); + + /* Return the month (0-11) */ + + tp->tm_mon = rtc_bcd2bin(buffer[6] & DS3231_TIME_MONTH_BCDMASK) - 1; + + /* Return the years since 1990 */ + + tmp = rtc_bcd2bin(buffer[7] & DS3231_TIME_YEAR_BCDMASK); + + if ((buffer[6] & DS3231_TIME_CENTURY_MASK) == DS3231_TIME_1900) + { + tp->tm_year = tmp; + } + else + { + tp->tm_year = tmp + 100; + } + + rtc_dumptime(tp, "Returning"); + return OK; +} + +/************************************************************************************ + * Name: up_rtc_settime + * + * Description: + * Set the RTC to the provided time. All RTC implementations must be able to + * set their time based on a standard timespec. + * + * Input Parameters: + * tp - the time to use + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int up_rtc_settime(FAR const struct timespec *tp) +{ + struct i2c_msg_s msg; + struct tm newtm; + time_t newtime; + uint8_t buffer[8]; + uint8_t century; + uint8_t year; + int ret; + + rtc_dumptime(tp, "Setting time"); + + /* Get the broken out time */ + + newtime = (time_t)tp->tv_sec; + if (tp->tv_nsec >= 500000000) + { + /* Round up */ + + newtime++; + } + + #ifdef CONFIG_LIBC_LOCALTIME + if (localtime_r(&newtime, &newtm) == NULL) + { + rtcdbg("ERROR: localtime_r failed\n") + return -EINVAL; + } +#else + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcdbg("ERROR: gmtime_r failed\n") + return -EINVAL; + } +#endif + + rtc_dumptime(&tm, "New time"); + + /* Construct the message */ + /* Write starting with the seconds regiser */ + + buffer[0] = DS3231_TIME_SECR; + + /* Save seconds (0-59) converted to BCD */ + + buffer[1] = rtc_bin2bcd(newtm.tm_sec); + + /* Save minutes (0-59) converted to BCD */ + + buffer[2] = rtc_bin2bcd(newtm.tm_min); + + /* Save hour (0-23) with 24-hour time indicatin */ + + buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DS3231_TIME_24; + + /* Save the day of the week (1-7) */ + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + buffer[4] = rtc_bin2bcd(newtm.tm_wday + 1); +#else + buffer[4] = 1; +#endif + + /* Save the day of the week (1-31) */ + + buffer[5] = rtc_bin2bcd(newtm.tm_mday); + + /* Handle years in the 20th vs the 21st century */ + + if (newtm.tm_year < 100) + { + /* Convert years in the range 1900-1999 */ + + century = DS3231_TIME_1900; + year = newtm.tm_year; + } + else + { + /* Convert years in the range 2000-2099 */ + + century = DS3231_TIME_2000; + year = newtm.tm_year - 100; + } + + /* Save the month (1-12) with century */ + + buffer[6] = rtc_bin2bcd(newtm.tm_mon + 1) | century; + + /* Save the year */ + + buffer[7] = year; + + /* Setup the I2C message */ + + msg.addr = DS3231_I2C_ADDRESS; + msg.flags = 0; + msg.buffer = buffer; + msg.length = 8; + + /* Configure I2C before using it */ + + I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); + + /* Perform the transfer (This could be done with I2C_READ) */ + + ret = I2C_TRANSFER(g_ds3231.i2c, &msg, 1); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + } + + return ret; +} + +#endif /* CONFIG_RTC_DS3231 */ diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h new file mode 100644 index 0000000000..4c2a4cbc14 --- /dev/null +++ b/drivers/timers/ds3231.h @@ -0,0 +1,274 @@ +/**************************************************************************** + * drivers/timers/ds3231.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __DRIVERS_TIMERS_DS3231_H +#define __DRIVERS_TIMERS_DS3231_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define DS3231_TIME_SECR 0x00 /* Seconds register */ +# define DS3231_TIME_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DS3231_TIME_SEC_MASK (15 << DS3231_TIME_SEC_SHIFT) +# define DS3231_TIME_SEC(n) ((uint8_t)(n) << DS3231_TIME_SEC_SHIFT) +# define DS3231_TIME_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DS3231_TIME_10SEC_MASK (7 << DS3231_TIME_10SEC_SHIFT) +# define DS3231_TIME_10SEC(n) ((uint8_t)(n) << DS3231_TIME_10SEC_SHIFT) +# define DS3231_TIME_SEC_BCDMASK (DS3231_TIME_SEC_MASK | DS3231_TIME_10SEC_MASK) + +#define DS3231_TIME_MINR 0x01 /* Minutes register */ +# define DS3231_TIME_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3231_TIME_MIN_MASK (15 << DS3231_TIME_MIN_SHIFT) +# define DS3231_TIME_MIN(n) ((uint8_t)(n) << DS3231_TIME_MIN_SHIFT) +# define DS3231_TIME_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3231_TIME_10MIN_MASK (7 << DS3231_TIME_10MIN_SHIFT) +# define DS3231_TIME_10MIN(n) ((uint8_t)(n) << DS3231_TIME_10MIN_SHIFT) +# define DS3231_TIME_MIN_BCDMASK (DS3231_TIME_MIN_MASK | DS3231_TIME_10MIN_MASK) + +#define DS3231_TIME_HOURR 0x02 /* Hours register */ +# define DS3231_TIME_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3231_TIME_HOUR_MASK (15 << DS3231_TIME_HOUR_SHIFT) +# define DS3231_TIME_HOUR(n) ((uint8_t)(n) << DS3231_TIME_HOUR_SHIFT) +# define DS3231_TIME_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3231_TIME_10HOUR12_MASK (1 << DS3231_TIME_10HOUR12_SHIFT) +# define DS3231_TIME_10HOUR12(n) ((uint8_t)(n) << DS3231_TIME_10HOUR12_SHIFT) +# define DS3231_TIME_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3231_TIME_10HOUR24_MASK (3 << DS3231_TIME_10HOUR24_SHIFT) +# define DS3231_TIME_10HOUR24(n) ((uint8_t)(n) << DS3231_TIME_10HOUR24_SHIFT) +# define DS3231_TIME_HOUR12_BCDMASK (DS3231_TIME_HOUR_MASK | DS3231_TIME_10HOUR12_MASK) +# define DS3231_TIME_HOUR24_BCDMASK (DS3231_TIME_HOUR_MASK | DS3231_TIME_10HOUR24_MASK) +# define DS3231_TIME_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3231_TIME_AMPM_MASK (1 << DS3231_TIME_AMPM_SHIFT) +# define DS3231_TIME_AM ((uint8_t)(0) << DS3231_TIME_AMPM_SHIFT) +# define DS3231_TIME_PM ((uint8_t)(1) << DS3231_TIME_AMPM_SHIFT) +# define DS3231_TIME_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3231_TIME_1224_MASK (1 << DS3231_TIME_1224_SHIFT) +# define DS3231_TIME_24 ((uint8_t)(0) << DS3231_TIME_1224_SHIFT) +# define DS3231_TIME_12 ((uint8_t)(1) << DS3231_TIME_1224_SHIFT) + +#define DS3231_TIME_DAYR 0x03 /* Day of the week register */ +# define DS3231_TIME_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3231_TIME_DAY_MASK (7 << DS3231_TIME_DAY_SHIFT) +# define DS3231_TIME_DAY(n) ((uint8_t)(n) << DS3231_TIME_DAY_SHIFT) + +#define DS3231_TIME_DATER 0x04 /* Date register */ +# define DS3231_TIME_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3231_TIME_DATE_MASK (15 << DS3231_TIME_DATE_SHIFT) +# define DS3231_TIME_DATE(n) ((uint8_t)(n) << DS3231_TIME_DATE_SHIFT) +# define DS3231_TIME_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3231_TIME_10DATE_MASK (3 << DS3231_TIME_10DATE_SHIFT) +# define DS3231_TIME_10DATE(n) ((uint8_t)(n) << DS3231_TIME_10DATE_SHIFT) +# define DS3231_TIME_DATE_BCDMASK (DS3231_TIME_DATE_MASK | DS3231_TIME_10DATE_MASK) + +#define DS3231_TIME_MONTHR 0x05 /* Month register */ +# define DS3231_TIME_MONTH_SHIFT 0 /* Bits 0-3: Month, range 0-9 */ +# define DS3231_TIME_MONTH_MASK (15 << DS3231_TIME_MONTH_SHIFT) +# define DS3231_TIME_MONTH(n) ((uint8_t)(n) << DS3231_TIME_MONTH_SHIFT) +# define DS3231_TIME_10MONTH_SHIFT 4 /* Bit 4: 10 month, range 0-1 */ +# define DS3231_TIME_10MONTH_MASK (1 << DS3231_TIME_10MONTH_SHIFT) +# define DS3231_TIME_10MONTH(n) ((uint8_t)(n) << DS3231_TIME_10MONTH_SHIFT) +# define DS3231_TIME_MONTH_BCDMASK (DS3231_TIME_MONTH_MASK | DS3231_TIME_10MONTH_MASK) +# define DS3231_TIME_CENTURY_SHIFT 7 /* Bit 7: AM/PM Indication */ +# define DS3231_TIME_CENTURY_MASK (1 << DS3231_TIME_CENTURY_SHIFT) +# define DS3231_TIME_1900 ((uint8_t)(0) << DS3231_TIME_CENTURY_SHIFT) +# define DS3231_TIME_2000 ((uint8_t)(1) << DS3231_TIME_CENTURY_SHIFT) + +#define DS3231_TIME_YEARR 0x06 /* Date register */ +# define DS3231_TIME_YEAR_SHIFT 0 /* Bits 0-3: Year, range 0-9 */ +# define DS3231_TIME_YEAR_MASK (15 << DS3231_TIME_YEAR_SHIFT) +# define DS3231_TIME_YEAR(n) ((uint8_t)(n) << DS3231_TIME_YEAR_SHIFT) +# define DS3231_TIME_10YEAR_SHIFT 4 /* Bits 4-7: 10 year, range 0-9 */ +# define DS3231_TIME_10YEAR_MASK (15 << DS3231_TIME_10YEAR_SHIFT) +# define DS3231_TIME_10YEAR(n) ((uint8_t)(n) << DS3231_TIME_10YEAR_SHIFT) +# define DS3231_TIME_YEAR_BCDMASK (DS3231_TIME_YEAR_MASK | DS3231_TIME_10YEAR_MASK) + +#define DS3231_ALARM1_SECR 0x07 /* Alarm1 seconds register */ +# define DS3231_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DS3231_ALARM1_SEC_MASK (15 << DS3231_ALARM1_SEC_SHIFT) +# define DS3231_ALARM1_SEC(n) ((uint8_t)(n) << DS3231_ALARM1_SEC_SHIFT) +# define DS3231_ALARM1_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DS3231_ALARM1_10SEC_MASK (7 << DS3231_ALARM1_10SEC_SHIFT) +# define DS3231_ALARM1_10SEC(n) ((uint8_t)(n) << DS3231_ALARM1_10SEC_SHIFT) +# define DS3231_ALARM1_SEC_BCDMASK (DS3231_ALARM1_SEC_MASK | DS3231_ALARM1_10SEC_MASK) +# define DS3231_ALARM1_A1M1_SHIFT 7 /* Bits 7: A1M1 mask */ +# define DS3231_ALARM1_A1M1_MASK (1 << DS3231_ALARM1_A1M1_SHIFT) +# define DS3231_ALARM1_A1M1(n) ((uint8_t)(n) << DS3231_ALARM1_A1M1_SHIFT) + +#define DS3231_ALARM1_MINR 0x08 /* Alarm1 minutes register */ +# define DS3231_ALARM1_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3231_ALARM1_MIN_MASK (15 << DS3231_ALARM1_MIN_SHIFT) +# define DS3231_ALARM1_MIN(n) ((uint8_t)(n) << DS3231_ALARM1_MIN_SHIFT) +# define DS3231_ALARM1_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3231_ALARM1_10MIN_MASK (7 << DS3231_ALARM1_10MIN_SHIFT) +# define DS3231_ALARM1_10MIN(n) ((uint8_t)(n) << DS3231_ALARM1_10MIN_SHIFT) +# define DS3231_ALARM1_MIN_BCDMASK (DS3231_ALARM1_MIN_MASK | DS3231_ALARM1_10MIN_MASK) +# define DS3231_ALARM1_A1M2_SHIFT 7 /* Bits 7: A1M2 mask */ +# define DS3231_ALARM1_A1M2_MASK (1 << DS3231_ALARM1_A1M2_SHIFT) +# define DS3231_ALARM1_A1M2(n) ((uint8_t)(n) << DS3231_ALARM1_A1M2_SHIFT) + +#define DS3231_ALARM1_HOURR 0x09 /* Alarm1 hours register */ +# define DS3231_ALARM1_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3231_ALARM1_HOUR_MASK (15 << DS3231_ALARM1_HOUR_SHIFT) +# define DS3231_ALARM1_HOUR(n) ((uint8_t)(n) << DS3231_ALARM1_HOUR_SHIFT) +# define DS3231_ALARM1_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3231_ALARM1_10HOUR12_MASK (1 << DS3231_ALARM1_10HOUR12_SHIFT) +# define DS3231_ALARM1_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR12_SHIFT) +# define DS3231_ALARM1_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3231_ALARM1_10HOUR24_MASK (3 << DS3231_ALARM1_10HOUR24_SHIFT) +# define DS3231_ALARM1_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR24_SHIFT) +# define DS3231_ALARM1_HOUR12_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR12_MASK) +# define DS3231_ALARM1_HOUR24_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR24_MASK) +# define DS3231_ALARM1_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3231_ALARM1_AMPM_MASK (1 << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_AM ((uint8_t)(0) << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_PM ((uint8_t)(1) << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3231_ALARM1_1224_MASK (1 << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_12 ((uint8_t)(0) << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_24 ((uint8_t)(1) << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_A1M3_SHIFT 7 /* Bits 7: A1M3 mask */ +# define DS3231_ALARM1_A1M3_MASK (1 << DS3231_ALARM1_A1M3_SHIFT) +# define DS3231_ALARM1_A1M3(n) ((uint8_t)(n) << DS3231_ALARM1_A1M3_SHIFT) + +#define DS3231_ALARM1_DAYDATER 0x0a /* Alarm1 date / day of the week register */ +# define DS3231_ALARM1_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3231_ALARM1_DAY_MASK (7 << DS3231_ALARM1_DAY_SHIFT) +# define DS3231_ALARM1_DAY(n) ((uint8_t)(n) << DS3231_ALARM1_DAY_SHIFT) +# define DS3231_ALARM1_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3231_ALARM1_DATE_MASK (15 << DS3231_ALARM1_DATE_SHIFT) +# define DS3231_ALARM1_DATE(n) ((uint8_t)(n) << DS3231_ALARM1_DATE_SHIFT) +# define DS3231_ALARM1_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3231_ALARM1_10DATE_MASK (3 << DS3231_ALARM1_10DATE_SHIFT) +# define DS3231_ALARM1_10DATE(n) ((uint8_t)(n) << DS3231_ALARM1_10DATE_SHIFT) +# define DS3231_ALARM1_DATE_BCDMASK (DS3231_ALARM1_DATE_MASK | DS3231_ALARM1_10DATE_MASK) +# define DS3231_ALARM1_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS3231_ALARM1_DYDT_MASK (1 << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_A1M4_SHIFT 7 /* Bits 7: A1M4 mask */ +# define DS3231_ALARM1_A1M4_MASK (1 << DS3231_ALARM1_A1M4_SHIFT) +# define DS3231_ALARM1_A1M4(n) ((uint8_t)(n) << DS3231_ALARM1_A1M4_SHIFT) + +#define DS3231_ALARM2_MINR 0x0b /* Alarm2 minutes register */ +# define DS3231_ALARM2_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3231_ALARM2_MIN_MASK (15 << DS3231_ALARM2_MIN_SHIFT) +# define DS3231_ALARM2_MIN(n) ((uint8_t)(n) << DS3231_ALARM2_MIN_SHIFT) +# define DS3231_ALARM2_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3231_ALARM2_10MIN_MASK (7 << DS3231_ALARM2_10MIN_SHIFT) +# define DS3231_ALARM2_10MIN(n) ((uint8_t)(n) << DS3231_ALARM2_10MIN_SHIFT) +# define DS3231_ALARM2_MIN_BCDMASK (DS3231_ALARM2_MIN_MASK | DS3231_ALARM2_10MIN_MASK) +# define DS3231_ALARM2_A2M2_SHIFT 7 /* Bits 7: A2M2 mask */ +# define DS3231_ALARM2_A2M2_MASK (1 << DS3231_ALARM2_A2M2_SHIFT) +# define DS3231_ALARM2_A2M2(n) ((uint8_t)(n) << DS3231_ALARM2_A2M2_SHIFT) + +#define DS3231_ALARM2_HOURR 0x0c /* Alarm2 hours register */ +# define DS3231_ALARM2_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3231_ALARM2_HOUR_MASK (15 << DS3231_ALARM2_HOUR_SHIFT) +# define DS3231_ALARM2_HOUR(n) ((uint8_t)(n) << DS3231_ALARM2_HOUR_SHIFT) +# define DS3231_ALARM2_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3231_ALARM2_10HOUR12_MASK (1 << DS3231_ALARM2_10HOUR12_SHIFT) +# define DS3231_ALARM2_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR12_SHIFT) +# define DS3231_ALARM2_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3231_ALARM2_10HOUR24_MASK (3 << DS3231_ALARM2_10HOUR24_SHIFT) +# define DS3231_ALARM2_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR24_SHIFT) +# define DS3231_ALARM2_HOUR12_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR12_MASK) +# define DS3231_ALARM2_HOUR24_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR24_MASK) +# define DS3231_ALARM2_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3231_ALARM2_AMPM_MASK (1 << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_AM ((uint8_t)(0) << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_PM ((uint8_t)(1) << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3231_ALARM2_1224_MASK (1 << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_12 ((uint8_t)(0) << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_24 ((uint8_t)(1) << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_A2M3_SHIFT 7 /* Bits 7: A2M3 mask */ +# define DS3231_ALARM2_A2M3_MASK (1 << DS3231_ALARM2_A2M3_SHIFT) +# define DS3231_ALARM2_A2M3(n) ((uint8_t)(n) << DS3231_ALARM2_A2M3_SHIFT) + +#define DS3231_ALARM2_DAYDATER 0x0d /* Alarm2 date / day of the week register */ +# define DS3231_ALARM2_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3231_ALARM2_DAY_MASK (7 << DS3231_ALARM2_DAY_SHIFT) +# define DS3231_ALARM2_DAY(n) ((uint8_t)(n) << DS3231_ALARM2_DAY_SHIFT) +# define DS3231_ALARM2_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3231_ALARM2_DATE_MASK (15 << DS3231_ALARM2_DATE_SHIFT) +# define DS3231_ALARM2_DATE(n) ((uint8_t)(n) << DS3231_ALARM2_DATE_SHIFT) +# define DS3231_ALARM2_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3231_ALARM2_10DATE_MASK (3 << DS3231_ALARM2_10DATE_SHIFT) +# define DS3231_ALARM2_10DATE(n) ((uint8_t)(n) << DS3231_ALARM2_10DATE_SHIFT) +# define DS3231_ALARM2_DATE_BCDMASK (DS3231_ALARM2_DATE_MASK | DS3231_ALARM2_10DATE_MASK) +# define DS3231_ALARM2_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS3231_ALARM2_DYDT_MASK (1 << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_A2M4_SHIFT 7 /* Bits 7: A2M4 mask */ +# define DS3231_ALARM2_A2M4_MASK (1 << DS3231_ALARM2_A2M4_SHIFT) +# define DS3231_ALARM2_A2M4(n) ((uint8_t)(n) << DS3231_ALARM2_A2M4_SHIFT) + +#define DS3231_CR 0x0e /* Control register */ +# define DS3231_CR_A1IE (1 << 0) /* Bit 0: Alarm 1 interrupt enable */ +# define DS3231_CR_A2IE (1 << 1) /* Bit 1: Alarm 2 interrupt enable */ +# define DS3231_CR_INTCN (1 << 2) /* Bit 2: Interrupt control */ +# define DS3231_CR_RS_SHIFT (3) /* Bit 3-4: Rate selection */ +# define DS3231_CR_RS_MASK (3 << DS3231_CR_RS_SHIFT) +# define DS3231_CR_RS_1HZ (0 << DS3231_CR_RS_SHIFT) /* 1Hz */ +# define DS3231_CR_RS_1KHZ (1 << DS3231_CR_RS_SHIFT) /* 1.024kHz */ +# define DS3231_CR_RS_4KHZ (2 << DS3231_CR_RS_SHIFT) /* 4.096kHz */ +# define DS3231_CR_RS_8KHZ (3 << DS3231_CR_RS_SHIFT) /* 8.192kHz */ +# define DS3231_CR_CONV (1 << 5) /* Bit 5: Convert temperature */ +# define DS3231_CR_BBSQW (1 << 6) /* Bit 6: Battery backed square wave enable */ +# define DS3231_CR_EOSC (1 << 7) /* Bit 7: Enable oscillator */ + +#define DS3231_CSR 0x0f /* Control/status register */ +# define DS3231_CSR_A1F (1 << 0) /* Bit 0: Alarm 1 flag */ +# define DS3231_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ +# define DS3231_CSR_BSY (1 << 2) /* Bit 2: Busy */ +# define DS3231_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ +# define DS3231_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ + +#define DS3231_AGINGR 0x10 /* Aging offset register (8-bit, 2's complement) */ + +#define DS3231_TMPMR 0x11 /* MSB of temp register (8-bit, 2's complement) */ + +#define DS3231_TMPLR 0x12 /* LSB of temp register (2-bits) */ +# define DS3231_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ + +#endif /* __DRIVERS_TIMERS_DS3231_H */ diff --git a/include/nuttx/timers/ds3231.h b/include/nuttx/timers/ds3231.h new file mode 100644 index 0000000000..c67edb30cb --- /dev/null +++ b/include/nuttx/timers/ds3231.h @@ -0,0 +1,83 @@ +/**************************************************************************** + * include/nuttx/timers/ds3231.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_TIMERS_DS3231_H +#define __INCLUDE_NUTTX_TIMERS_DS3231_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_RTC_DS3231 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Name: ds3231_rtc_initialize + * + * Description: + * Initialize the hardware RTC per the selected configuration. This function is + * called once during the OS initialization sequence + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +struct i2c_dev_s; /* Forward reference */ +int ds3231_rtc_initialize(FAR struct i2c_dev_s *i2c); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_RTC_DS3231 */ +#endif /* __INCLUDE_NUTTX_TIMERS_DS3231_H */ -- GitLab From 249fa2475bfb96017764323d50d7169046250cac Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 14:39:47 -0600 Subject: [PATCH 303/858] Add logic to detect rollowing while reading or setting the time --- drivers/timers/ds3231.c | 100 +++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index c47485d60f..9378a5e8aa 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -264,70 +264,93 @@ int ds3231_rtc_initialize(FAR struct i2c_dev_s *i2c) int up_rtc_getdatetime(FAR struct tm *tp) { - struct i2c_msg_s msg[2]; - uint8_t buffer[8]; + struct i2c_msg_s msg[4]; + uint8_t secaddr; + uint8_t buffer[7]; + uint8_t seconds; int tmp; int ret; /* Select to begin reading at the seconds register */ - buffer[0] = DS3231_TIME_SECR; + secaddr = DS3231_TIME_SECR; msg[0].addr = DS3231_I2C_ADDRESS; msg[0].flags = 0; - msg[0].buffer = buffer; + msg[0].buffer = &secaddr; msg[0].length = 1; - /* Set up to read 7 registers: secs, min, hr, dow, date, mth, yr */ + /* Set up to read 7 registers: secondss, minutes, hour, day-of-week, date, + * month, year + */ msg[1].addr = DS3231_I2C_ADDRESS; msg[1].flags = I2C_M_READ; - msg[1].buffer = &buffer[1]; + msg[1].buffer = buffer; msg[1].length = 7; + /* Read the seconds register again */ + + msg[2].addr = DS3231_I2C_ADDRESS; + msg[2].flags = 0; + msg[2].buffer = &secaddr; + msg[2].length = 1; + + msg[3].addr = DS3231_I2C_ADDRESS; + msg[3].flags = I2C_M_READ; + msg[3].buffer = &seconds; + msg[3].length = 1; + /* Configure I2C before using it */ I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_WRITEREAD()) */ + /* Perform the transfer (This could be done with I2C_WRITEREAD()). The + * transfer may be performed repeatedly of the seconds values decreases, + * meaning that that was a rollover in the seconds. + */ - ret = I2C_TRANSFER(g_ds3231.i2c, msg, 1); - if (ret < 0) + do { - rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) - return ret; + ret = I2C_TRANSFER(g_ds3231.i2c, msg, 4); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + return ret; + } } + while (buffer[0] > seconds); /* Format the return time */ /* Return seconds (0-61) */ - tp->tm_sec = rtc_bcd2bin(buffer[1] & DS3231_TIME_SEC_BCDMASK); + tp->tm_sec = rtc_bcd2bin(buffer[0] & DS3231_TIME_SEC_BCDMASK); /* Return minutes (0-59) */ - tp->tm_min = rtc_bcd2bin(buffer[2] & DS3231_TIME_MIN_BCDMASK); + tp->tm_min = rtc_bcd2bin(buffer[1] & DS3231_TIME_MIN_BCDMASK); /* Return hour (0-23). This assumes 24-hour time was set. */ - tp->tm_hour = rtc_bcd2bin(buffer[3] & DS3231_TIME_HOUR24_BCDMASK); + tp->tm_hour = rtc_bcd2bin(buffer[2] & DS3231_TIME_HOUR24_BCDMASK); #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /* Return the day of the week (0-6) */ - tp->tm_wday = (rtc_bcd2bin(buffer[4]) & DS3231_TIME_DAY_MASK)- 1; + tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3231_TIME_DAY_MASK)- 1; #endif /* Return the day of the month (1-31) */ - tp->tm_mday = rtc_bcd2bin(buffer[5] & DS3231_TIME_DATE_BCDMASK); + tp->tm_mday = rtc_bcd2bin(buffer[4] & DS3231_TIME_DATE_BCDMASK); /* Return the month (0-11) */ - tp->tm_mon = rtc_bcd2bin(buffer[6] & DS3231_TIME_MONTH_BCDMASK) - 1; + tp->tm_mon = rtc_bcd2bin(buffer[5] & DS3231_TIME_MONTH_BCDMASK) - 1; /* Return the years since 1990 */ - tmp = rtc_bcd2bin(buffer[7] & DS3231_TIME_YEAR_BCDMASK); + tmp = rtc_bcd2bin(buffer[5] & DS3231_TIME_YEAR_BCDMASK); if ((buffer[6] & DS3231_TIME_CENTURY_MASK) == DS3231_TIME_1900) { @@ -359,10 +382,11 @@ int up_rtc_getdatetime(FAR struct tm *tp) int up_rtc_settime(FAR const struct timespec *tp) { - struct i2c_msg_s msg; + struct i2c_msg_s msg[3]; struct tm newtm; time_t newtime; uint8_t buffer[8]; + uint8_t seconds; uint8_t century; uint8_t year; int ret; @@ -451,24 +475,44 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Setup the I2C message */ - msg.addr = DS3231_I2C_ADDRESS; - msg.flags = 0; - msg.buffer = buffer; - msg.length = 8; + msg[0].addr = DS3231_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = buffer; + msg[0].length = 8; + + /* Read back the seconds register */ + + msg[1].addr = DS3231_I2C_ADDRESS; + msg[1].flags = 0; + msg[1].buffer = buffer; + msg[1].length = 1; + + msg[2].addr = DS3231_I2C_ADDRESS; + msg[2].flags = I2C_M_READ; + msg[2].buffer = &seconds; + msg[2].length = 1; /* Configure I2C before using it */ I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_READ) */ + /* Perform the transfer (This could be done with I2C_READ). This transfer + * will be repeated if the seconds count rolls over to a smaller value + * while writing. + */ - ret = I2C_TRANSFER(g_ds3231.i2c, &msg, 1); - if (ret < 0) + do { - rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + ret = I2C_TRANSFER(g_ds3231.i2c, msg, 3); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + return ret; + } } + while (buffer[1] > seconds); - return ret; + return OK; } #endif /* CONFIG_RTC_DS3231 */ -- GitLab From 09b9d6ba1fe5f7732c77c17940ea5d247797a30e Mon Sep 17 00:00:00 2001 From: Wail Khemir Date: Tue, 17 Nov 2015 16:39:21 -0500 Subject: [PATCH 304/858] Added a lower-half timer driver for stm32 which is compatible with the upper-half driver located at /drivers/timers/timer.c --- include/nuttx/timers/timer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nuttx/timers/timer.h b/include/nuttx/timers/timer.h index 8e6926083c..5d11498e71 100644 --- a/include/nuttx/timers/timer.h +++ b/include/nuttx/timers/timer.h @@ -45,6 +45,7 @@ #include #include #include +#include #ifdef CONFIG_TIMER -- GitLab From 2578994e74b9e618a08eeaa15ba9f56ddd0c7af6 Mon Sep 17 00:00:00 2001 From: Karim Keddam Date: Tue, 17 Nov 2015 17:19:11 -0500 Subject: [PATCH 305/858] Fixed a bug with the CRC for the ms58xx sensor --- drivers/sensors/ms58xx.c | 53 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index ad5108f6cf..f0fefba5ba 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -4,6 +4,7 @@ * * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience + * Updated by: Karim Keddam * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -130,7 +131,7 @@ struct ms58xx_dev_s ****************************************************************************/ /* CRC Calculation */ -static uint8_t ms58xx_crc(FAR const uint8_t *src, size_t len); +static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex); /* I2C Helpers */ @@ -187,29 +188,36 @@ static const struct file_operations g_fops = * ****************************************************************************/ -static uint8_t ms58xx_crc(FAR const uint8_t *src, size_t len) +static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) { - uint16_t crc = 0; - size_t i; - int j; - - for (i = 0; i < len; i++) + uint16_t cnt; + uint16_t n_rem; + uint16_t crc_read; + uint8_t n_bit; + n_rem = 0x00; + crc_read = src[crcIndex]; + src[crcIndex] = (0xFF00 & (src[7])); + for(cnt=0;cnt<16;cnt++) + { + if(cnt%2==1) + n_rem ^= (uint16_t)((src[cnt>>1]) & 0x00FF); + else + n_rem ^= (uint16_t)(src[cnt>>1] >> 8); + for(n_bit=8; n_bit > 0; n_bit--) { - crc ^= src[i]; - - for (j = 0; j < 8; j++) - { - bool xor = (crc & 0x8000) != 0; - - crc <<= 1; - if (xor) - { - crc ^= 0x3000; - } - } + if(n_rem & (0x8000)) + { + n_rem = (n_rem << 1) ^ 0x3000; + } + else + { + n_rem = (n_rem << 1); + } } - - return (uint8_t)(crc >> 12); + } + n_rem = (0x000F & (n_rem >> 12)); + src[crcIndex] = crc_read; + return (n_rem ^ 0x00); } /**************************************************************************** @@ -417,9 +425,8 @@ static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv) crcmask = (uint16_t)0xf << crcshift; crc = (uint8_t)((prom[crcindex] & crcmask) >> crcshift); - prom[crcindex] &= ~crcmask; - if (crc != ms58xx_crc((uint8_t *)prom, sizeof(prom))) + if (crc != ms58xx_crc(prom, crcindex)) { sndbg("crc mismatch\n"); return -ENODEV; -- GitLab From 522d8917595ff6b004fc4fb07c618a4f77c9cbd6 Mon Sep 17 00:00:00 2001 From: Karim Keddam Date: Tue, 17 Nov 2015 17:21:46 -0500 Subject: [PATCH 306/858] Fixed a bug with the ms58xx sensor initialization --- drivers/sensors/ms58xx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index f0fefba5ba..1a4352acdf 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -413,6 +413,8 @@ static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv) break; } + // We have to wait before the prom is ready is be read + up_udelay(10000); for (i = 0; i < len; i++) { ret = ms58xx_readu16(priv, MS58XX_PROM_REG+i*2, prom+i); -- GitLab From 25c4ff828592f7f3c8e2f0a534d7fa1424abce0e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 16:24:09 -0600 Subject: [PATCH 307/858] Update some comments --- drivers/timers/ds3231.c | 9 ++++++++- include/nuttx/timers/ds3231.h | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 9378a5e8aa..66ec1fe7f6 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -220,7 +220,14 @@ static int rtc_bcd2bin(uint8_t value) * * Description: * Initialize the hardware RTC per the selected configuration. This function is - * called once during the OS initialization sequence + * called once during the OS initialization sequence by board-specific logic. + * + * After ds3231_rtc_initialize() is called, the OS function clock_synchronize() + * should also be called to synchronize the system timer to a hardware RTC. That + * operation is normally performed automatically by the system during clock + * initialization. However, when an external RTC is used, the board logic will + * need to explicitly re-synchronize the system timer to the RTC when the RTC + * becomes available. * * Input Parameters: * None diff --git a/include/nuttx/timers/ds3231.h b/include/nuttx/timers/ds3231.h index c67edb30cb..98bf8bbb20 100644 --- a/include/nuttx/timers/ds3231.h +++ b/include/nuttx/timers/ds3231.h @@ -61,7 +61,14 @@ extern "C" * * Description: * Initialize the hardware RTC per the selected configuration. This function is - * called once during the OS initialization sequence + * called once during the OS initialization sequence by board-specific logic. + * + * After ds3231_rtc_initialize() is called, the OS function clock_synchronize() + * should also be called to synchronize the system timer to a hardware RTC. That + * operation is normally performed automatically by the system during clock + * initialization. However, when an external RTC is used, the board logic will + * need to explicitly re-synchronize the system timer to the RTC when the RTC + * becomes available. * * Input Parameters: * None -- GitLab From 5a99735782c8a913696aaa2b28c1c9a6a5639575 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 16:54:15 -0600 Subject: [PATCH 308/858] (Hopefully) cosmetic changes from review of recent merges for conformance to coding standard --- arch | 2 +- configs | 2 +- drivers/sensors/ms58xx.c | 45 ++++++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/arch b/arch index cce873c460..1a44ba0197 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cce873c46060fe663f571cb922e642e097249c60 +Subproject commit 1a44ba01975e3cfabc4294b055478aa5ea4684f6 diff --git a/configs b/configs index 8a8b3d3ea6..001222765f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8a8b3d3ea61739a5462058889e8ba5352100ab5f +Subproject commit 001222765f770a9ec4bd58b95fd065fbf4fbcec0 diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 1a4352acdf..324a076444 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -194,27 +194,35 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) uint16_t n_rem; uint16_t crc_read; uint8_t n_bit; + n_rem = 0x00; crc_read = src[crcIndex]; - src[crcIndex] = (0xFF00 & (src[7])); - for(cnt=0;cnt<16;cnt++) - { - if(cnt%2==1) - n_rem ^= (uint16_t)((src[cnt>>1]) & 0x00FF); - else - n_rem ^= (uint16_t)(src[cnt>>1] >> 8); - for(n_bit=8; n_bit > 0; n_bit--) + src[crcIndex] = (0xff00 & (src[7])); + + for (cnt = 0; cnt < 16; cnt++) { - if(n_rem & (0x8000)) - { - n_rem = (n_rem << 1) ^ 0x3000; - } + if (cnt % 2 == 1) + { + n_rem ^= (uint16_t)((src[cnt>>1]) & 0x00FF); + } else - { - n_rem = (n_rem << 1); - } + { + n_rem ^= (uint16_t)(src[cnt>>1] >> 8); + } + + for (n_bit = 8; n_bit > 0; n_bit--) + { + if (n_rem & (0x8000)) + { + n_rem = (n_rem << 1) ^ 0x3000; + } + else + { + n_rem = (n_rem << 1); + } + } } - } + n_rem = (0x000F & (n_rem >> 12)); src[crcIndex] = crc_read; return (n_rem ^ 0x00); @@ -413,11 +421,12 @@ static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv) break; } - // We have to wait before the prom is ready is be read + /* We have to wait before the prom is ready is be read */ + up_udelay(10000); for (i = 0; i < len; i++) { - ret = ms58xx_readu16(priv, MS58XX_PROM_REG+i*2, prom+i); + ret = ms58xx_readu16(priv, MS58XX_PROM_REG + i * 2, prom + i); if (ret < 0) { sndbg("ms58xx_readu16 failed: %d\n", ret); -- GitLab From 9d0984e21ecafb9f62b51a7c2271a348a5f43da6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 17:21:36 -0600 Subject: [PATCH 309/858] Update ChangeLog --- ChangeLog | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f8cab43b1e..9c2f19c18f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11100,4 +11100,8 @@ each with unique I2C addresses, but otherwise idential (2015-11-17). * drivers/timers/ds3231.c: Add support for the DS3231 I2C RTC. Untested on the initial commit (2015-11-17). - + * arch/arm/src/stm32/stm32_tim_lowerhalf.c: Add a compatible lower-half + timer driver for use with drivers/timers/timer.c. From Wail Khemir + (2015-11-17). + * drivers/sensors/ms58xx.c: Fix some issues with initialization and with + CRC calculation. From Karim Keddam (2015-11-17). -- GitLab From 8d963e66cfa0b876319de0f7c2d9d59d646603c0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 17:31:57 -0600 Subject: [PATCH 310/858] Fix some stylistic issues found by tools/nxstyle --- arch | 2 +- drivers/sensors/ms58xx.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 1a44ba0197..94c884e558 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1a44ba01975e3cfabc4294b055478aa5ea4684f6 +Subproject commit 94c884e5587e058cf65d7db352ea44203330db5a diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 324a076444..86f69ea511 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -203,11 +203,11 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) { if (cnt % 2 == 1) { - n_rem ^= (uint16_t)((src[cnt>>1]) & 0x00FF); + n_rem ^= (uint16_t)((src[cnt >> 1]) & 0x00ff); } else { - n_rem ^= (uint16_t)(src[cnt>>1] >> 8); + n_rem ^= (uint16_t)(src[cnt >> 1] >> 8); } for (n_bit = 8; n_bit > 0; n_bit--) -- GitLab From a654f35d98e4b54fe6893d13d5778a0391b79ab6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 17:35:17 -0600 Subject: [PATCH 311/858] Fix some stylistic issues found by tools/nxstyle --- drivers/timers/ds3231.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 66ec1fe7f6..396e5f92be 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -344,7 +344,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /* Return the day of the week (0-6) */ - tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3231_TIME_DAY_MASK)- 1; + tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3231_TIME_DAY_MASK) - 1; #endif /* Return the day of the month (1-31) */ @@ -505,8 +505,8 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Perform the transfer (This could be done with I2C_READ). This transfer * will be repeated if the seconds count rolls over to a smaller value - * while writing. - */ + * while writing. + */ do { -- GitLab From b60422836e89394dc5deed4468d3732d91cee36c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 17:38:46 -0600 Subject: [PATCH 312/858] Fix some stylistic issues found by tools/nxstyle --- drivers/discrete/pca9555.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/discrete/pca9555.c b/drivers/discrete/pca9555.c index 5651641d98..0139a0f61f 100644 --- a/drivers/discrete/pca9555.c +++ b/drivers/discrete/pca9555.c @@ -452,35 +452,39 @@ static void pca9555_irqworker(void *arg) uint8_t addr = PCA9555_REG_INPUT; uint8_t buf[2]; int ret, bits; - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)arg; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)arg; + + /* Read inputs */ - /* read inputs */ ret = I2C_WRITEREAD(pca->i2c, &addr, 1, buf, 2); - if( ret != OK) + if (ret != OK) { return; } - bits = (buf[0]<<8) | buf[1]; + bits = (buf[0] << 8) | buf[1]; + /* If signal PID is registered, enqueue signal. */ - /* if signal PID is registered, enqueue signal. */ - if(pca->dev.sigpid) + if (pca->dev.sigpid) { #ifdef CONFIG_CAN_PASS_STRUCTS union sigval value; value.sival_int = bits; ret = sigqueue(pca->dev.sigpid, pca->dev.sigval, value); #else - ret = sigqueue(pca->dev.sigpid, pca->dev.sigval, (FAR void*)bits); + ret = sigqueue(pca->dev.sigpid, pca->dev.sigval, (FAR void *)bits); #endif - dbg("pca signal %04X (sig %d to pid %d)\n",bits, pca->dev.sigval, pca->dev.sigpid); + dbg("pca signal %04X (sig %d to pid %d)\n", + bits, pca->dev.sigval, pca->dev.sigpid); } else { - dbg("no handler registered\n"); + dbg("no handler registered\n"); } - /* re-enable */ + + /* Re-enable */ + pca->config->enable(pca->config, TRUE); } -- GitLab From 7e58e4c4cfdf86ef233ad75717f58c3226d9e347 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Wed, 18 Nov 2015 06:56:53 -0600 Subject: [PATCH 313/858] W25: Fix W25 page read/write logic --- ChangeLog | 2 ++ drivers/discrete/pca9555.c | 1 - drivers/mtd/w25.c | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c2f19c18f..89a5e5ff9e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11105,3 +11105,5 @@ (2015-11-17). * drivers/sensors/ms58xx.c: Fix some issues with initialization and with CRC calculation. From Karim Keddam (2015-11-17). + * drivers/mtd/w25.c: Fix W25 FLASH driver page read/write logic. From + Ken Petit (2015-11-18). diff --git a/drivers/discrete/pca9555.c b/drivers/discrete/pca9555.c index 0139a0f61f..106942b69d 100644 --- a/drivers/discrete/pca9555.c +++ b/drivers/discrete/pca9555.c @@ -589,4 +589,3 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_dev_s *i2cdev, } #endif /* CONFIG_IOEXPANDER_PCA9555 */ - diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index cb9c2980fa..31dbe6d1fe 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -771,7 +771,7 @@ static void w25_cacheflush(struct w25_dev_s *priv) { /* Write entire erase block to FLASH */ - w25_pagewrite(priv, priv->sector, (off_t)priv->esectno << W25_SECTOR_SHIFT, + w25_pagewrite(priv, priv->sector, (off_t)priv->esectno << W25_PAGE_SHIFT, W25_SECTOR_SIZE); /* The case is no long dirty and the FLASH is no longer erased */ @@ -982,10 +982,10 @@ static ssize_t w25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl nbytes >>= W25_SECTOR512_SHIFT; } #else - nbytes = w25_read(dev, startblock << W25_SECTOR_SHIFT, nblocks << W25_SECTOR_SHIFT, buffer); + nbytes = w25_read(dev, startblock << W25_PAGE_SHIFT, nblocks << W25_PAGE_SHIFT, buffer); if (nbytes > 0) { - nbytes >>= W25_SECTOR_SHIFT; + nbytes >>= W25_PAGE_SHIFT; } #endif @@ -1013,8 +1013,8 @@ static ssize_t w25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nb #if defined(CONFIG_W25_SECTOR512) w25_cachewrite(priv, buffer, startblock, nblocks); #else - w25_pagewrite(priv, buffer, startblock << W25_SECTOR_SHIFT, - nblocks << W25_SECTOR_SHIFT); + w25_pagewrite(priv, buffer, startblock << W25_PAGE_SHIFT, + nblocks << W25_PAGE_SHIFT); #endif w25_unlock(priv->spi); @@ -1075,7 +1075,7 @@ static int w25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) geo->erasesize = (1 << W25_SECTOR512_SHIFT); geo->neraseblocks = priv->nsectors << (W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT); #else - geo->blocksize = W25_SECTOR_SIZE; + geo->blocksize = W25_PAGE_SIZE; geo->erasesize = W25_SECTOR_SIZE; geo->neraseblocks = priv->nsectors; #endif -- GitLab From f0f7dd99562990180d3103e09bb8db35ad4580b9 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Wed, 18 Nov 2015 07:01:13 -0600 Subject: [PATCH 314/858] drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit --- ChangeLog | 2 ++ drivers/mtd/smart.c | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89a5e5ff9e..26f03abe0b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11107,3 +11107,5 @@ CRC calculation. From Karim Keddam (2015-11-17). * drivers/mtd/w25.c: Fix W25 FLASH driver page read/write logic. From Ken Petit (2015-11-18). + * drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit + (2015-11-18). diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 828924418d..dba5101134 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -3895,9 +3895,9 @@ static inline int smart_read_wearstatus(FAR struct smart_struct_s *dev) /* Calculate number of bytes to read from this sector */ toread = remaining; - if (toread > dev->sectorsize - SMARTFS_FMT_WEAR_POS) + if (toread > dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s))) { - toread = dev->sectorsize - SMARTFS_FMT_WEAR_POS; + toread = dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s)); } /* Setup the sector read request (we are our own client) */ @@ -4509,7 +4509,8 @@ static int smart_readsector(FAR struct smart_struct_s *dev, fvdbg("Entry\n"); req = (FAR struct smart_read_write_s *) arg; DEBUGASSERT(req->offset < dev->sectorsize); - DEBUGASSERT(req->offset+req->count < dev->sectorsize); + DEBUGASSERT(req->offset+req->count+ sizeof(struct smart_sect_header_s) <= + dev->sectorsize); /* Ensure the logical sector has been allocated */ -- GitLab From 0d18b13a16d6f8f207eeb9cb9a69eadea7cd4abb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 07:09:59 -0600 Subject: [PATCH 315/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 26f03abe0b..c626c83175 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11109,3 +11109,5 @@ Ken Petit (2015-11-18). * drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit (2015-11-18). + * arch/sim/src/up_spiflash.c: Add support for W25 FLASH simulation. + From Ken Petit (2015-11-18). diff --git a/arch b/arch index 94c884e558..c0b78aab85 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 94c884e5587e058cf65d7db352ea44203330db5a +Subproject commit c0b78aab85f0a31a85c90d01c60d4749a193af73 -- GitLab From 4579f0c1fcd182440f1dd9358ec07d53845fa950 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 07:31:53 -0600 Subject: [PATCH 316/858] Add a command to boardctl() to obtain a baord unique ID --- ChangeLog | 3 +++ configs | 2 +- include/nuttx/board.h | 26 ++++++++++++++++++++++++++ include/sys/boardctl.h | 30 +++++++++++++++++++----------- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index c626c83175..1d42014845 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11111,3 +11111,6 @@ (2015-11-18). * arch/sim/src/up_spiflash.c: Add support for W25 FLASH simulation. From Ken Petit (2015-11-18). + * configs/boardctl.h, Kconfig, include/sys/boardctl.h, and nuttx/board.h: + Add a command to the boardctl() interface to obtain a board unique ID + (2015-11-18). diff --git a/configs b/configs index 001222765f..ca62315de4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 001222765f770a9ec4bd58b95fd065fbf4fbcec0 +Subproject commit ca62315de49f3627e05136ba49d4ce0f9dff7784 diff --git a/include/nuttx/board.h b/include/nuttx/board.h index c603f40441..6c8578321f 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -193,6 +193,32 @@ int board_power_off(int status); int board_reset(int status); #endif +/**************************************************************************** + * Name: board_uniqueid + * + * Description: + * Return a unique ID associated with the board. The meaning of this + * unique ID is not specified. It may be a chip identifying number, a + * serial number, a MAC address, etc. It may be in binary or it may be + * ASCII. The only only requirement is that the length of the unique + * ID be exactly CONFIG_BOARDCTL_UNIQUEID_SIZE in length. + * + * Input Parameters: + * uniqueid - A reference to a writable memory location provided by the + * caller to receive the board unique ID. The memory memory referenced + * by this pointer must be at least CONFIG_BOARDCTL_UNIQUEID_SIZE in + * length. + * + * Returned Value: + * Zero (OK) is returned on success. Otherwize a negated errno value is + * returned indicating the nature of the failure. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARDCTL_UNIQUEID +int board_uniqueid(FAR uint8_t *uniqueid); +#endif + /**************************************************************************** * Name: board_tsc_setup * diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index 28d08d81e4..81b511bb5b 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -56,19 +56,26 @@ * DESCRIPTION: Perform one-time application initialization. * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL - * DEPENDENCIES: Board logic must provide board_app_initialization + * DEPENDENCIES: Board logic must provide board_app_initialization() * * CMD: BOARDIOC_POWEROFF * DESCRIPTION: Power off the board * ARG: Integer value providing power off status information * CONFIGURATION: CONFIG_BOARDCTL_POWEROFF - * DEPENDENCIES: Board logic must provide board_power_off + * DEPENDENCIES: Board logic must provide the board_power_off() interface. * * CMD: BOARDIOC_RESET * DESCRIPTION: Reset the board * ARG: Integer value providing power off status information * CONFIGURATION: CONFIG_BOARDCTL_RESET - * DEPENDENCIES: Board logic must provide board_reset + * DEPENDENCIES: Board logic must provide the board_reset() interface. + * + * CMD: BOARDIOC_UNIQUEID + * DESCRIPTION: Return a unique ID associated with the board (such as a + * serial number or a MAC address). + * ARG: A writable array of size CONFIG_BOARDCTL_UNIQUEID_SIZE in + * which to receive the board unique ID. + * DEPENDENCIES: Board logic must provide the board_uniqueid() interface. * * CMD: BOARDIOC_SYMTAB * DESCRIPTION: Select a symbol table @@ -117,13 +124,14 @@ #define BOARDIOC_INIT _BOARDIOC(0x0001) #define BOARDIOC_POWEROFF _BOARDIOC(0x0002) #define BOARDIOC_RESET _BOARDIOC(0x0003) -#define BOARDIOC_SYMTAB _BOARDIOC(0x0004) -#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0005) -#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0006) -#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0007) -#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0008) -#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x0009) -#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000a) +#define BOARDIOC_UNIQUEID _BOARDIOC(0x0004) +#define BOARDIOC_SYMTAB _BOARDIOC(0x0005) +#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0006) +#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0007) +#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0008) +#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0009) +#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000a) +#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000b) /* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support. * In this case, all commands not recognized by boardctl() will be forwarded @@ -132,7 +140,7 @@ * User defined board commands may begin with this value: */ -#define BOARDIOC_USER _BOARDIOC(0x000b) +#define BOARDIOC_USER _BOARDIOC(0x000c) /**************************************************************************** * Public Type Definitions -- GitLab From 622ea95ab159f198ba977e2231bd57ec28bbf789 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 08:43:19 -0600 Subject: [PATCH 317/858] drivers/timers/ds3213.c: Extend to include support for the DS1307 RTC --- ChangeLog | 3 + drivers/timers/Kconfig | 26 ++- drivers/timers/Make.defs | 2 +- drivers/timers/ds3231.c | 36 +-- drivers/timers/ds3231.h | 427 ++++++++++++++++++---------------- include/nuttx/timers/ds3231.h | 10 +- 6 files changed, 269 insertions(+), 235 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d42014845..f879a7bb38 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11114,3 +11114,6 @@ * configs/boardctl.h, Kconfig, include/sys/boardctl.h, and nuttx/board.h: Add a command to the boardctl() interface to obtain a board unique ID (2015-11-18). + * drivers/timers/ds3231.c: Driver extended to include support for the + DS1307 RTC (2015-11-18). + diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 1c4f5685de..95167ecd8f 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -118,8 +118,8 @@ config RTC_IOCTL endif # RTC_DRIVER -config RTC_DS3231 - bool "DS3231 RTC Driver" +config RTC_DS3XXX + bool "DS3231/DS1307 RTC Driver" default n select I2C select I2C_TRANSFER @@ -127,14 +127,30 @@ config RTC_DS3231 ---help--- Enables support for the Maxim Integrated DS3231 I2C RTC timer. -if RTC_DS3231 +if RTC_DS3XXX + +choice + prompt "Maxim Integrated RTC" + default RTC_DS3231 + +config RTC_DS1307 + bool "DS1307" + ---help--- + Enables support for the Maxim Integrated DS3231 I2C RTC timer. + +config RTC_DS3231 + bool "DS3231" + ---help--- + Enables support for the Maxim Integrated DS1307 I2C RTC timer. + +endchoice # Maxim Integrated RTC config DS3231_I2C_FREQUENCY - int "DS3231 I2C frequency" + int "DS3231/DS1307 I2C frequency" default 400000 range 1 4000000 -endif # RTC_DS3231 +endif # RTC_DS3XXX endif # RTC menuconfig WATCHDOG diff --git a/drivers/timers/Make.defs b/drivers/timers/Make.defs index e856991826..f52599e1f8 100644 --- a/drivers/timers/Make.defs +++ b/drivers/timers/Make.defs @@ -51,7 +51,7 @@ ifeq ($(CONFIG_TIMER),y) TMRVPATH = :timers endif -ifeq ($(CONFIG_RTC_DS3231),y) +ifeq ($(CONFIG_RTC_DS3XXX),y) CSRCS += ds3231.c TMRDEPPATH = --dep-path timers TMRVPATH = :timers diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 396e5f92be..d3c122f273 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -50,7 +50,7 @@ #include "ds3231.h" -#ifdef CONFIG_RTC_DS3231 +#ifdef CONFIG_RTC_DS3XXX /************************************************************************************ * Pre-processor Definitions @@ -216,13 +216,13 @@ static int rtc_bcd2bin(uint8_t value) ************************************************************************************/ /************************************************************************************ - * Name: ds3231_rtc_initialize + * Name: ds3xxx_rtc_initialize * * Description: * Initialize the hardware RTC per the selected configuration. This function is * called once during the OS initialization sequence by board-specific logic. * - * After ds3231_rtc_initialize() is called, the OS function clock_synchronize() + * After ds3xxx_rtc_initialize() is called, the OS function clock_synchronize() * should also be called to synchronize the system timer to a hardware RTC. That * operation is normally performed automatically by the system during clock * initialization. However, when an external RTC is used, the board logic will @@ -237,7 +237,7 @@ static int rtc_bcd2bin(uint8_t value) * ************************************************************************************/ -int ds3231_rtc_initialize(FAR struct i2c_dev_s *i2c) +int ds3xxx_rtc_initialize(FAR struct i2c_dev_s *i2c) { /* Remember the i2c device and claim that the RTC is enabled */ @@ -280,7 +280,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) /* Select to begin reading at the seconds register */ - secaddr = DS3231_TIME_SECR; + secaddr = DS3XXX_TIME_SECR; msg[0].addr = DS3231_I2C_ADDRESS; msg[0].flags = 0; @@ -331,35 +331,35 @@ int up_rtc_getdatetime(FAR struct tm *tp) /* Format the return time */ /* Return seconds (0-61) */ - tp->tm_sec = rtc_bcd2bin(buffer[0] & DS3231_TIME_SEC_BCDMASK); + tp->tm_sec = rtc_bcd2bin(buffer[0] & DS3XXX_TIME_SEC_BCDMASK); /* Return minutes (0-59) */ - tp->tm_min = rtc_bcd2bin(buffer[1] & DS3231_TIME_MIN_BCDMASK); + tp->tm_min = rtc_bcd2bin(buffer[1] & DS3XXX_TIME_MIN_BCDMASK); /* Return hour (0-23). This assumes 24-hour time was set. */ - tp->tm_hour = rtc_bcd2bin(buffer[2] & DS3231_TIME_HOUR24_BCDMASK); + tp->tm_hour = rtc_bcd2bin(buffer[2] & DS3XXX_TIME_HOUR24_BCDMASK); #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /* Return the day of the week (0-6) */ - tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3231_TIME_DAY_MASK) - 1; + tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3XXX_TIME_DAY_MASK) - 1; #endif /* Return the day of the month (1-31) */ - tp->tm_mday = rtc_bcd2bin(buffer[4] & DS3231_TIME_DATE_BCDMASK); + tp->tm_mday = rtc_bcd2bin(buffer[4] & DS3XXX_TIME_DATE_BCDMASK); /* Return the month (0-11) */ - tp->tm_mon = rtc_bcd2bin(buffer[5] & DS3231_TIME_MONTH_BCDMASK) - 1; + tp->tm_mon = rtc_bcd2bin(buffer[5] & DS3XXX_TIME_MONTH_BCDMASK) - 1; /* Return the years since 1990 */ - tmp = rtc_bcd2bin(buffer[5] & DS3231_TIME_YEAR_BCDMASK); + tmp = rtc_bcd2bin(buffer[5] & DS3XXX_TIME_YEAR_BCDMASK); - if ((buffer[6] & DS3231_TIME_CENTURY_MASK) == DS3231_TIME_1900) + if ((buffer[6] & DS3XXX_TIME_CENTURY_MASK) == DS3XXX_TIME_1900) { tp->tm_year = tmp; } @@ -429,7 +429,7 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Construct the message */ /* Write starting with the seconds regiser */ - buffer[0] = DS3231_TIME_SECR; + buffer[0] = DS3XXX_TIME_SECR; /* Save seconds (0-59) converted to BCD */ @@ -441,7 +441,7 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Save hour (0-23) with 24-hour time indicatin */ - buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DS3231_TIME_24; + buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DS3XXX_TIME_24; /* Save the day of the week (1-7) */ @@ -461,14 +461,14 @@ int up_rtc_settime(FAR const struct timespec *tp) { /* Convert years in the range 1900-1999 */ - century = DS3231_TIME_1900; + century = DS3XXX_TIME_1900; year = newtm.tm_year; } else { /* Convert years in the range 2000-2099 */ - century = DS3231_TIME_2000; + century = DS3XXX_TIME_2000; year = newtm.tm_year - 100; } @@ -522,4 +522,4 @@ int up_rtc_settime(FAR const struct timespec *tp) return OK; } -#endif /* CONFIG_RTC_DS3231 */ +#endif /* CONFIG_RTC_DS3XXX */ diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index 4c2a4cbc14..57ea6f5bec 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -46,229 +46,244 @@ * Pre-processor Definitions ****************************************************************************/ -#define DS3231_TIME_SECR 0x00 /* Seconds register */ -# define DS3231_TIME_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ -# define DS3231_TIME_SEC_MASK (15 << DS3231_TIME_SEC_SHIFT) -# define DS3231_TIME_SEC(n) ((uint8_t)(n) << DS3231_TIME_SEC_SHIFT) -# define DS3231_TIME_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ -# define DS3231_TIME_10SEC_MASK (7 << DS3231_TIME_10SEC_SHIFT) -# define DS3231_TIME_10SEC(n) ((uint8_t)(n) << DS3231_TIME_10SEC_SHIFT) -# define DS3231_TIME_SEC_BCDMASK (DS3231_TIME_SEC_MASK | DS3231_TIME_10SEC_MASK) +#define DS3XXX_TIME_SECR 0x00 /* Seconds register */ +# define DS3XXX_TIME_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DS3XXX_TIME_SEC_MASK (15 << DS3XXX_TIME_SEC_SHIFT) +# define DS3XXX_TIME_SEC(n) ((uint8_t)(n) << DS3XXX_TIME_SEC_SHIFT) +# define DS3XXX_TIME_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DS3XXX_TIME_10SEC_MASK (7 << DS3XXX_TIME_10SEC_SHIFT) +# define DS3XXX_TIME_10SEC(n) ((uint8_t)(n) << DS3XXX_TIME_10SEC_SHIFT) +# define DS3XXX_TIME_SEC_BCDMASK (DS3XXX_TIME_SEC_MASK | DS3XXX_TIME_10SEC_MASK) -#define DS3231_TIME_MINR 0x01 /* Minutes register */ -# define DS3231_TIME_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3231_TIME_MIN_MASK (15 << DS3231_TIME_MIN_SHIFT) -# define DS3231_TIME_MIN(n) ((uint8_t)(n) << DS3231_TIME_MIN_SHIFT) -# define DS3231_TIME_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3231_TIME_10MIN_MASK (7 << DS3231_TIME_10MIN_SHIFT) -# define DS3231_TIME_10MIN(n) ((uint8_t)(n) << DS3231_TIME_10MIN_SHIFT) -# define DS3231_TIME_MIN_BCDMASK (DS3231_TIME_MIN_MASK | DS3231_TIME_10MIN_MASK) +#define DS3XXX_TIME_MINR 0x01 /* Minutes register */ +# define DS3XXX_TIME_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3XXX_TIME_MIN_MASK (15 << DS3XXX_TIME_MIN_SHIFT) +# define DS3XXX_TIME_MIN(n) ((uint8_t)(n) << DS3XXX_TIME_MIN_SHIFT) +# define DS3XXX_TIME_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3XXX_TIME_10MIN_MASK (7 << DS3XXX_TIME_10MIN_SHIFT) +# define DS3XXX_TIME_10MIN(n) ((uint8_t)(n) << DS3XXX_TIME_10MIN_SHIFT) +# define DS3XXX_TIME_MIN_BCDMASK (DS3XXX_TIME_MIN_MASK | DS3XXX_TIME_10MIN_MASK) -#define DS3231_TIME_HOURR 0x02 /* Hours register */ -# define DS3231_TIME_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3231_TIME_HOUR_MASK (15 << DS3231_TIME_HOUR_SHIFT) -# define DS3231_TIME_HOUR(n) ((uint8_t)(n) << DS3231_TIME_HOUR_SHIFT) -# define DS3231_TIME_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3231_TIME_10HOUR12_MASK (1 << DS3231_TIME_10HOUR12_SHIFT) -# define DS3231_TIME_10HOUR12(n) ((uint8_t)(n) << DS3231_TIME_10HOUR12_SHIFT) -# define DS3231_TIME_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3231_TIME_10HOUR24_MASK (3 << DS3231_TIME_10HOUR24_SHIFT) -# define DS3231_TIME_10HOUR24(n) ((uint8_t)(n) << DS3231_TIME_10HOUR24_SHIFT) -# define DS3231_TIME_HOUR12_BCDMASK (DS3231_TIME_HOUR_MASK | DS3231_TIME_10HOUR12_MASK) -# define DS3231_TIME_HOUR24_BCDMASK (DS3231_TIME_HOUR_MASK | DS3231_TIME_10HOUR24_MASK) -# define DS3231_TIME_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3231_TIME_AMPM_MASK (1 << DS3231_TIME_AMPM_SHIFT) -# define DS3231_TIME_AM ((uint8_t)(0) << DS3231_TIME_AMPM_SHIFT) -# define DS3231_TIME_PM ((uint8_t)(1) << DS3231_TIME_AMPM_SHIFT) -# define DS3231_TIME_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3231_TIME_1224_MASK (1 << DS3231_TIME_1224_SHIFT) -# define DS3231_TIME_24 ((uint8_t)(0) << DS3231_TIME_1224_SHIFT) -# define DS3231_TIME_12 ((uint8_t)(1) << DS3231_TIME_1224_SHIFT) +#define DS3XXX_TIME_HOURR 0x02 /* Hours register */ +# define DS3XXX_TIME_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3XXX_TIME_HOUR_MASK (15 << DS3XXX_TIME_HOUR_SHIFT) +# define DS3XXX_TIME_HOUR(n) ((uint8_t)(n) << DS3XXX_TIME_HOUR_SHIFT) +# define DS3XXX_TIME_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3XXX_TIME_10HOUR12_MASK (1 << DS3XXX_TIME_10HOUR12_SHIFT) +# define DS3XXX_TIME_10HOUR12(n) ((uint8_t)(n) << DS3XXX_TIME_10HOUR12_SHIFT) +# define DS3XXX_TIME_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3XXX_TIME_10HOUR24_MASK (3 << DS3XXX_TIME_10HOUR24_SHIFT) +# define DS3XXX_TIME_10HOUR24(n) ((uint8_t)(n) << DS3XXX_TIME_10HOUR24_SHIFT) +# define DS3XXX_TIME_HOUR12_BCDMASK (DS3XXX_TIME_HOUR_MASK | DS3XXX_TIME_10HOUR12_MASK) +# define DS3XXX_TIME_HOUR24_BCDMASK (DS3XXX_TIME_HOUR_MASK | DS3XXX_TIME_10HOUR24_MASK) +# define DS3XXX_TIME_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3XXX_TIME_AMPM_MASK (1 << DS3XXX_TIME_AMPM_SHIFT) +# define DS3XXX_TIME_AM ((uint8_t)(0) << DS3XXX_TIME_AMPM_SHIFT) +# define DS3XXX_TIME_PM ((uint8_t)(1) << DS3XXX_TIME_AMPM_SHIFT) +# define DS3XXX_TIME_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3XXX_TIME_1224_MASK (1 << DS3XXX_TIME_1224_SHIFT) +# define DS3XXX_TIME_24 ((uint8_t)(0) << DS3XXX_TIME_1224_SHIFT) +# define DS3XXX_TIME_12 ((uint8_t)(1) << DS3XXX_TIME_1224_SHIFT) -#define DS3231_TIME_DAYR 0x03 /* Day of the week register */ -# define DS3231_TIME_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3231_TIME_DAY_MASK (7 << DS3231_TIME_DAY_SHIFT) -# define DS3231_TIME_DAY(n) ((uint8_t)(n) << DS3231_TIME_DAY_SHIFT) +#define DS3XXX_TIME_DAYR 0x03 /* Day of the week register */ +# define DS3XXX_TIME_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3XXX_TIME_DAY_MASK (7 << DS3XXX_TIME_DAY_SHIFT) +# define DS3XXX_TIME_DAY(n) ((uint8_t)(n) << DS3XXX_TIME_DAY_SHIFT) -#define DS3231_TIME_DATER 0x04 /* Date register */ -# define DS3231_TIME_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3231_TIME_DATE_MASK (15 << DS3231_TIME_DATE_SHIFT) -# define DS3231_TIME_DATE(n) ((uint8_t)(n) << DS3231_TIME_DATE_SHIFT) -# define DS3231_TIME_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3231_TIME_10DATE_MASK (3 << DS3231_TIME_10DATE_SHIFT) -# define DS3231_TIME_10DATE(n) ((uint8_t)(n) << DS3231_TIME_10DATE_SHIFT) -# define DS3231_TIME_DATE_BCDMASK (DS3231_TIME_DATE_MASK | DS3231_TIME_10DATE_MASK) +#define DS3XXX_TIME_DATER 0x04 /* Date register */ +# define DS3XXX_TIME_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3XXX_TIME_DATE_MASK (15 << DS3XXX_TIME_DATE_SHIFT) +# define DS3XXX_TIME_DATE(n) ((uint8_t)(n) << DS3XXX_TIME_DATE_SHIFT) +# define DS3XXX_TIME_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3XXX_TIME_10DATE_MASK (3 << DS3XXX_TIME_10DATE_SHIFT) +# define DS3XXX_TIME_10DATE(n) ((uint8_t)(n) << DS3XXX_TIME_10DATE_SHIFT) +# define DS3XXX_TIME_DATE_BCDMASK (DS3XXX_TIME_DATE_MASK | DS3XXX_TIME_10DATE_MASK) -#define DS3231_TIME_MONTHR 0x05 /* Month register */ -# define DS3231_TIME_MONTH_SHIFT 0 /* Bits 0-3: Month, range 0-9 */ -# define DS3231_TIME_MONTH_MASK (15 << DS3231_TIME_MONTH_SHIFT) -# define DS3231_TIME_MONTH(n) ((uint8_t)(n) << DS3231_TIME_MONTH_SHIFT) -# define DS3231_TIME_10MONTH_SHIFT 4 /* Bit 4: 10 month, range 0-1 */ -# define DS3231_TIME_10MONTH_MASK (1 << DS3231_TIME_10MONTH_SHIFT) -# define DS3231_TIME_10MONTH(n) ((uint8_t)(n) << DS3231_TIME_10MONTH_SHIFT) -# define DS3231_TIME_MONTH_BCDMASK (DS3231_TIME_MONTH_MASK | DS3231_TIME_10MONTH_MASK) -# define DS3231_TIME_CENTURY_SHIFT 7 /* Bit 7: AM/PM Indication */ -# define DS3231_TIME_CENTURY_MASK (1 << DS3231_TIME_CENTURY_SHIFT) -# define DS3231_TIME_1900 ((uint8_t)(0) << DS3231_TIME_CENTURY_SHIFT) -# define DS3231_TIME_2000 ((uint8_t)(1) << DS3231_TIME_CENTURY_SHIFT) +#define DS3XXX_TIME_MONTHR 0x05 /* Month register */ +# define DS3XXX_TIME_MONTH_SHIFT 0 /* Bits 0-3: Month, range 0-9 */ +# define DS3XXX_TIME_MONTH_MASK (15 << DS3XXX_TIME_MONTH_SHIFT) +# define DS3XXX_TIME_MONTH(n) ((uint8_t)(n) << DS3XXX_TIME_MONTH_SHIFT) +# define DS3XXX_TIME_10MONTH_SHIFT 4 /* Bit 4: 10 month, range 0-1 */ +# define DS3XXX_TIME_10MONTH_MASK (1 << DS3XXX_TIME_10MONTH_SHIFT) +# define DS3XXX_TIME_10MONTH(n) ((uint8_t)(n) << DS3XXX_TIME_10MONTH_SHIFT) +# define DS3XXX_TIME_MONTH_BCDMASK (DS3XXX_TIME_MONTH_MASK | DS3XXX_TIME_10MONTH_MASK) +# define DS3XXX_TIME_CENTURY_SHIFT 7 /* Bit 7: AM/PM Indication */ +# define DS3XXX_TIME_CENTURY_MASK (1 << DS3XXX_TIME_CENTURY_SHIFT) +# define DS3XXX_TIME_1900 ((uint8_t)(0) << DS3XXX_TIME_CENTURY_SHIFT) +# define DS3XXX_TIME_2000 ((uint8_t)(1) << DS3XXX_TIME_CENTURY_SHIFT) -#define DS3231_TIME_YEARR 0x06 /* Date register */ -# define DS3231_TIME_YEAR_SHIFT 0 /* Bits 0-3: Year, range 0-9 */ -# define DS3231_TIME_YEAR_MASK (15 << DS3231_TIME_YEAR_SHIFT) -# define DS3231_TIME_YEAR(n) ((uint8_t)(n) << DS3231_TIME_YEAR_SHIFT) -# define DS3231_TIME_10YEAR_SHIFT 4 /* Bits 4-7: 10 year, range 0-9 */ -# define DS3231_TIME_10YEAR_MASK (15 << DS3231_TIME_10YEAR_SHIFT) -# define DS3231_TIME_10YEAR(n) ((uint8_t)(n) << DS3231_TIME_10YEAR_SHIFT) -# define DS3231_TIME_YEAR_BCDMASK (DS3231_TIME_YEAR_MASK | DS3231_TIME_10YEAR_MASK) +#define DS3XXX_TIME_YEARR 0x06 /* Date register */ +# define DS3XXX_TIME_YEAR_SHIFT 0 /* Bits 0-3: Year, range 0-9 */ +# define DS3XXX_TIME_YEAR_MASK (15 << DS3XXX_TIME_YEAR_SHIFT) +# define DS3XXX_TIME_YEAR(n) ((uint8_t)(n) << DS3XXX_TIME_YEAR_SHIFT) +# define DS3XXX_TIME_10YEAR_SHIFT 4 /* Bits 4-7: 10 year, range 0-9 */ +# define DS3XXX_TIME_10YEAR_MASK (15 << DS3XXX_TIME_10YEAR_SHIFT) +# define DS3XXX_TIME_10YEAR(n) ((uint8_t)(n) << DS3XXX_TIME_10YEAR_SHIFT) +# define DS3XXX_TIME_YEAR_BCDMASK (DS3XXX_TIME_YEAR_MASK | DS3XXX_TIME_10YEAR_MASK) -#define DS3231_ALARM1_SECR 0x07 /* Alarm1 seconds register */ -# define DS3231_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ -# define DS3231_ALARM1_SEC_MASK (15 << DS3231_ALARM1_SEC_SHIFT) -# define DS3231_ALARM1_SEC(n) ((uint8_t)(n) << DS3231_ALARM1_SEC_SHIFT) -# define DS3231_ALARM1_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ -# define DS3231_ALARM1_10SEC_MASK (7 << DS3231_ALARM1_10SEC_SHIFT) -# define DS3231_ALARM1_10SEC(n) ((uint8_t)(n) << DS3231_ALARM1_10SEC_SHIFT) -# define DS3231_ALARM1_SEC_BCDMASK (DS3231_ALARM1_SEC_MASK | DS3231_ALARM1_10SEC_MASK) -# define DS3231_ALARM1_A1M1_SHIFT 7 /* Bits 7: A1M1 mask */ -# define DS3231_ALARM1_A1M1_MASK (1 << DS3231_ALARM1_A1M1_SHIFT) -# define DS3231_ALARM1_A1M1(n) ((uint8_t)(n) << DS3231_ALARM1_A1M1_SHIFT) +#ifdef CONFIG_RTC_DS1307 +# define DS1307_CR 0x07 /* Control register */ +# define DS1307_CR_RS_SHIFT (3) /* Bits 0-1: Rate selection */ +# define DS1307_CR_RS_MASK (3 << DS1307_CR_RS_SHIFT) +# define DS1307_CR_RS_1HZ (0 << DS1307_CR_RS_SHIFT) /* 1Hz */ +# define DS1307_CR_RS_4KHZ (1 << DS1307_CR_RS_SHIFT) /* 4.096kHz */ +# define DS1307_CR_RS_8KHZ (2 << DS1307_CR_RS_SHIFT) /* 8.192kHz */ +# define DS1307_CR_RS_32KHZ (3 << DS1307_CR_RS_SHIFT) /* 32.768kHz */ +# define DS1307_CR_SQWE (1 << 4) /* Bit 4: Square wave enable */ +# define DS1307_CR_OUT (1 << 7) /* Bit 7: Output control */ +# define DS1307_RAM_BASE 0x08 /* 0x08-0x3f: 56x8 RAM */ +#endif -#define DS3231_ALARM1_MINR 0x08 /* Alarm1 minutes register */ -# define DS3231_ALARM1_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3231_ALARM1_MIN_MASK (15 << DS3231_ALARM1_MIN_SHIFT) -# define DS3231_ALARM1_MIN(n) ((uint8_t)(n) << DS3231_ALARM1_MIN_SHIFT) -# define DS3231_ALARM1_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3231_ALARM1_10MIN_MASK (7 << DS3231_ALARM1_10MIN_SHIFT) -# define DS3231_ALARM1_10MIN(n) ((uint8_t)(n) << DS3231_ALARM1_10MIN_SHIFT) -# define DS3231_ALARM1_MIN_BCDMASK (DS3231_ALARM1_MIN_MASK | DS3231_ALARM1_10MIN_MASK) -# define DS3231_ALARM1_A1M2_SHIFT 7 /* Bits 7: A1M2 mask */ -# define DS3231_ALARM1_A1M2_MASK (1 << DS3231_ALARM1_A1M2_SHIFT) -# define DS3231_ALARM1_A1M2(n) ((uint8_t)(n) << DS3231_ALARM1_A1M2_SHIFT) +#ifdef CONFIG_RTC_DS3231 +# define DS3231_ALARM1_SECR 0x07 /* Alarm1 seconds register */ +# define DS3231_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DS3231_ALARM1_SEC_MASK (15 << DS3231_ALARM1_SEC_SHIFT) +# define DS3231_ALARM1_SEC(n) ((uint8_t)(n) << DS3231_ALARM1_SEC_SHIFT) +# define DS3231_ALARM1_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DS3231_ALARM1_10SEC_MASK (7 << DS3231_ALARM1_10SEC_SHIFT) +# define DS3231_ALARM1_10SEC(n) ((uint8_t)(n) << DS3231_ALARM1_10SEC_SHIFT) +# define DS3231_ALARM1_SEC_BCDMASK (DS3231_ALARM1_SEC_MASK | DS3231_ALARM1_10SEC_MASK) +# define DS3231_ALARM1_A1M1_SHIFT 7 /* Bits 7: A1M1 mask */ +# define DS3231_ALARM1_A1M1_MASK (1 << DS3231_ALARM1_A1M1_SHIFT) +# define DS3231_ALARM1_A1M1(n) ((uint8_t)(n) << DS3231_ALARM1_A1M1_SHIFT) -#define DS3231_ALARM1_HOURR 0x09 /* Alarm1 hours register */ -# define DS3231_ALARM1_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3231_ALARM1_HOUR_MASK (15 << DS3231_ALARM1_HOUR_SHIFT) -# define DS3231_ALARM1_HOUR(n) ((uint8_t)(n) << DS3231_ALARM1_HOUR_SHIFT) -# define DS3231_ALARM1_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3231_ALARM1_10HOUR12_MASK (1 << DS3231_ALARM1_10HOUR12_SHIFT) -# define DS3231_ALARM1_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR12_SHIFT) -# define DS3231_ALARM1_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3231_ALARM1_10HOUR24_MASK (3 << DS3231_ALARM1_10HOUR24_SHIFT) -# define DS3231_ALARM1_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR24_SHIFT) -# define DS3231_ALARM1_HOUR12_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR12_MASK) -# define DS3231_ALARM1_HOUR24_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR24_MASK) -# define DS3231_ALARM1_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3231_ALARM1_AMPM_MASK (1 << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_AM ((uint8_t)(0) << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_PM ((uint8_t)(1) << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3231_ALARM1_1224_MASK (1 << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_12 ((uint8_t)(0) << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_24 ((uint8_t)(1) << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_A1M3_SHIFT 7 /* Bits 7: A1M3 mask */ -# define DS3231_ALARM1_A1M3_MASK (1 << DS3231_ALARM1_A1M3_SHIFT) -# define DS3231_ALARM1_A1M3(n) ((uint8_t)(n) << DS3231_ALARM1_A1M3_SHIFT) +# define DS3231_ALARM1_MINR 0x08 /* Alarm1 minutes register */ +# define DS3231_ALARM1_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3231_ALARM1_MIN_MASK (15 << DS3231_ALARM1_MIN_SHIFT) +# define DS3231_ALARM1_MIN(n) ((uint8_t)(n) << DS3231_ALARM1_MIN_SHIFT) +# define DS3231_ALARM1_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3231_ALARM1_10MIN_MASK (7 << DS3231_ALARM1_10MIN_SHIFT) +# define DS3231_ALARM1_10MIN(n) ((uint8_t)(n) << DS3231_ALARM1_10MIN_SHIFT) +# define DS3231_ALARM1_MIN_BCDMASK (DS3231_ALARM1_MIN_MASK | DS3231_ALARM1_10MIN_MASK) +# define DS3231_ALARM1_A1M2_SHIFT 7 /* Bits 7: A1M2 mask */ +# define DS3231_ALARM1_A1M2_MASK (1 << DS3231_ALARM1_A1M2_SHIFT) +# define DS3231_ALARM1_A1M2(n) ((uint8_t)(n) << DS3231_ALARM1_A1M2_SHIFT) -#define DS3231_ALARM1_DAYDATER 0x0a /* Alarm1 date / day of the week register */ -# define DS3231_ALARM1_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3231_ALARM1_DAY_MASK (7 << DS3231_ALARM1_DAY_SHIFT) -# define DS3231_ALARM1_DAY(n) ((uint8_t)(n) << DS3231_ALARM1_DAY_SHIFT) -# define DS3231_ALARM1_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3231_ALARM1_DATE_MASK (15 << DS3231_ALARM1_DATE_SHIFT) -# define DS3231_ALARM1_DATE(n) ((uint8_t)(n) << DS3231_ALARM1_DATE_SHIFT) -# define DS3231_ALARM1_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3231_ALARM1_10DATE_MASK (3 << DS3231_ALARM1_10DATE_SHIFT) -# define DS3231_ALARM1_10DATE(n) ((uint8_t)(n) << DS3231_ALARM1_10DATE_SHIFT) -# define DS3231_ALARM1_DATE_BCDMASK (DS3231_ALARM1_DATE_MASK | DS3231_ALARM1_10DATE_MASK) -# define DS3231_ALARM1_DYDT_SHIFT 6 /* Bits 6: DY/DT */ -# define DS3231_ALARM1_DYDT_MASK (1 << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_A1M4_SHIFT 7 /* Bits 7: A1M4 mask */ -# define DS3231_ALARM1_A1M4_MASK (1 << DS3231_ALARM1_A1M4_SHIFT) -# define DS3231_ALARM1_A1M4(n) ((uint8_t)(n) << DS3231_ALARM1_A1M4_SHIFT) +# define DS3231_ALARM1_HOURR 0x09 /* Alarm1 hours register */ +# define DS3231_ALARM1_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3231_ALARM1_HOUR_MASK (15 << DS3231_ALARM1_HOUR_SHIFT) +# define DS3231_ALARM1_HOUR(n) ((uint8_t)(n) << DS3231_ALARM1_HOUR_SHIFT) +# define DS3231_ALARM1_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3231_ALARM1_10HOUR12_MASK (1 << DS3231_ALARM1_10HOUR12_SHIFT) +# define DS3231_ALARM1_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR12_SHIFT) +# define DS3231_ALARM1_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3231_ALARM1_10HOUR24_MASK (3 << DS3231_ALARM1_10HOUR24_SHIFT) +# define DS3231_ALARM1_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR24_SHIFT) +# define DS3231_ALARM1_HOUR12_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR12_MASK) +# define DS3231_ALARM1_HOUR24_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR24_MASK) +# define DS3231_ALARM1_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3231_ALARM1_AMPM_MASK (1 << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_AM ((uint8_t)(0) << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_PM ((uint8_t)(1) << DS3231_ALARM1_AMPM_SHIFT) +# define DS3231_ALARM1_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3231_ALARM1_1224_MASK (1 << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_12 ((uint8_t)(0) << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_24 ((uint8_t)(1) << DS3231_ALARM1_1224_SHIFT) +# define DS3231_ALARM1_A1M3_SHIFT 7 /* Bits 7: A1M3 mask */ +# define DS3231_ALARM1_A1M3_MASK (1 << DS3231_ALARM1_A1M3_SHIFT) +# define DS3231_ALARM1_A1M3(n) ((uint8_t)(n) << DS3231_ALARM1_A1M3_SHIFT) -#define DS3231_ALARM2_MINR 0x0b /* Alarm2 minutes register */ -# define DS3231_ALARM2_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3231_ALARM2_MIN_MASK (15 << DS3231_ALARM2_MIN_SHIFT) -# define DS3231_ALARM2_MIN(n) ((uint8_t)(n) << DS3231_ALARM2_MIN_SHIFT) -# define DS3231_ALARM2_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3231_ALARM2_10MIN_MASK (7 << DS3231_ALARM2_10MIN_SHIFT) -# define DS3231_ALARM2_10MIN(n) ((uint8_t)(n) << DS3231_ALARM2_10MIN_SHIFT) -# define DS3231_ALARM2_MIN_BCDMASK (DS3231_ALARM2_MIN_MASK | DS3231_ALARM2_10MIN_MASK) -# define DS3231_ALARM2_A2M2_SHIFT 7 /* Bits 7: A2M2 mask */ -# define DS3231_ALARM2_A2M2_MASK (1 << DS3231_ALARM2_A2M2_SHIFT) -# define DS3231_ALARM2_A2M2(n) ((uint8_t)(n) << DS3231_ALARM2_A2M2_SHIFT) +# define DS3231_ALARM1_DAYDATER 0x0a /* Alarm1 date / day of the week register */ +# define DS3231_ALARM1_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3231_ALARM1_DAY_MASK (7 << DS3231_ALARM1_DAY_SHIFT) +# define DS3231_ALARM1_DAY(n) ((uint8_t)(n) << DS3231_ALARM1_DAY_SHIFT) +# define DS3231_ALARM1_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3231_ALARM1_DATE_MASK (15 << DS3231_ALARM1_DATE_SHIFT) +# define DS3231_ALARM1_DATE(n) ((uint8_t)(n) << DS3231_ALARM1_DATE_SHIFT) +# define DS3231_ALARM1_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3231_ALARM1_10DATE_MASK (3 << DS3231_ALARM1_10DATE_SHIFT) +# define DS3231_ALARM1_10DATE(n) ((uint8_t)(n) << DS3231_ALARM1_10DATE_SHIFT) +# define DS3231_ALARM1_DATE_BCDMASK (DS3231_ALARM1_DATE_MASK | DS3231_ALARM1_10DATE_MASK) +# define DS3231_ALARM1_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS3231_ALARM1_DYDT_MASK (1 << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM1_DYDT_SHIFT) +# define DS3231_ALARM1_A1M4_SHIFT 7 /* Bits 7: A1M4 mask */ +# define DS3231_ALARM1_A1M4_MASK (1 << DS3231_ALARM1_A1M4_SHIFT) +# define DS3231_ALARM1_A1M4(n) ((uint8_t)(n) << DS3231_ALARM1_A1M4_SHIFT) -#define DS3231_ALARM2_HOURR 0x0c /* Alarm2 hours register */ -# define DS3231_ALARM2_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3231_ALARM2_HOUR_MASK (15 << DS3231_ALARM2_HOUR_SHIFT) -# define DS3231_ALARM2_HOUR(n) ((uint8_t)(n) << DS3231_ALARM2_HOUR_SHIFT) -# define DS3231_ALARM2_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3231_ALARM2_10HOUR12_MASK (1 << DS3231_ALARM2_10HOUR12_SHIFT) -# define DS3231_ALARM2_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR12_SHIFT) -# define DS3231_ALARM2_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3231_ALARM2_10HOUR24_MASK (3 << DS3231_ALARM2_10HOUR24_SHIFT) -# define DS3231_ALARM2_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR24_SHIFT) -# define DS3231_ALARM2_HOUR12_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR12_MASK) -# define DS3231_ALARM2_HOUR24_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR24_MASK) -# define DS3231_ALARM2_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3231_ALARM2_AMPM_MASK (1 << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_AM ((uint8_t)(0) << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_PM ((uint8_t)(1) << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3231_ALARM2_1224_MASK (1 << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_12 ((uint8_t)(0) << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_24 ((uint8_t)(1) << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_A2M3_SHIFT 7 /* Bits 7: A2M3 mask */ -# define DS3231_ALARM2_A2M3_MASK (1 << DS3231_ALARM2_A2M3_SHIFT) -# define DS3231_ALARM2_A2M3(n) ((uint8_t)(n) << DS3231_ALARM2_A2M3_SHIFT) +# define DS3231_ALARM2_MINR 0x0b /* Alarm2 minutes register */ +# define DS3231_ALARM2_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS3231_ALARM2_MIN_MASK (15 << DS3231_ALARM2_MIN_SHIFT) +# define DS3231_ALARM2_MIN(n) ((uint8_t)(n) << DS3231_ALARM2_MIN_SHIFT) +# define DS3231_ALARM2_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS3231_ALARM2_10MIN_MASK (7 << DS3231_ALARM2_10MIN_SHIFT) +# define DS3231_ALARM2_10MIN(n) ((uint8_t)(n) << DS3231_ALARM2_10MIN_SHIFT) +# define DS3231_ALARM2_MIN_BCDMASK (DS3231_ALARM2_MIN_MASK | DS3231_ALARM2_10MIN_MASK) +# define DS3231_ALARM2_A2M2_SHIFT 7 /* Bits 7: A2M2 mask */ +# define DS3231_ALARM2_A2M2_MASK (1 << DS3231_ALARM2_A2M2_SHIFT) +# define DS3231_ALARM2_A2M2(n) ((uint8_t)(n) << DS3231_ALARM2_A2M2_SHIFT) -#define DS3231_ALARM2_DAYDATER 0x0d /* Alarm2 date / day of the week register */ -# define DS3231_ALARM2_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3231_ALARM2_DAY_MASK (7 << DS3231_ALARM2_DAY_SHIFT) -# define DS3231_ALARM2_DAY(n) ((uint8_t)(n) << DS3231_ALARM2_DAY_SHIFT) -# define DS3231_ALARM2_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3231_ALARM2_DATE_MASK (15 << DS3231_ALARM2_DATE_SHIFT) -# define DS3231_ALARM2_DATE(n) ((uint8_t)(n) << DS3231_ALARM2_DATE_SHIFT) -# define DS3231_ALARM2_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3231_ALARM2_10DATE_MASK (3 << DS3231_ALARM2_10DATE_SHIFT) -# define DS3231_ALARM2_10DATE(n) ((uint8_t)(n) << DS3231_ALARM2_10DATE_SHIFT) -# define DS3231_ALARM2_DATE_BCDMASK (DS3231_ALARM2_DATE_MASK | DS3231_ALARM2_10DATE_MASK) -# define DS3231_ALARM2_DYDT_SHIFT 6 /* Bits 6: DY/DT */ -# define DS3231_ALARM2_DYDT_MASK (1 << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_A2M4_SHIFT 7 /* Bits 7: A2M4 mask */ -# define DS3231_ALARM2_A2M4_MASK (1 << DS3231_ALARM2_A2M4_SHIFT) -# define DS3231_ALARM2_A2M4(n) ((uint8_t)(n) << DS3231_ALARM2_A2M4_SHIFT) +# define DS3231_ALARM2_HOURR 0x0c /* Alarm2 hours register */ +# define DS3231_ALARM2_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS3231_ALARM2_HOUR_MASK (15 << DS3231_ALARM2_HOUR_SHIFT) +# define DS3231_ALARM2_HOUR(n) ((uint8_t)(n) << DS3231_ALARM2_HOUR_SHIFT) +# define DS3231_ALARM2_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS3231_ALARM2_10HOUR12_MASK (1 << DS3231_ALARM2_10HOUR12_SHIFT) +# define DS3231_ALARM2_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR12_SHIFT) +# define DS3231_ALARM2_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS3231_ALARM2_10HOUR24_MASK (3 << DS3231_ALARM2_10HOUR24_SHIFT) +# define DS3231_ALARM2_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR24_SHIFT) +# define DS3231_ALARM2_HOUR12_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR12_MASK) +# define DS3231_ALARM2_HOUR24_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR24_MASK) +# define DS3231_ALARM2_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS3231_ALARM2_AMPM_MASK (1 << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_AM ((uint8_t)(0) << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_PM ((uint8_t)(1) << DS3231_ALARM2_AMPM_SHIFT) +# define DS3231_ALARM2_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS3231_ALARM2_1224_MASK (1 << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_12 ((uint8_t)(0) << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_24 ((uint8_t)(1) << DS3231_ALARM2_1224_SHIFT) +# define DS3231_ALARM2_A2M3_SHIFT 7 /* Bits 7: A2M3 mask */ +# define DS3231_ALARM2_A2M3_MASK (1 << DS3231_ALARM2_A2M3_SHIFT) +# define DS3231_ALARM2_A2M3(n) ((uint8_t)(n) << DS3231_ALARM2_A2M3_SHIFT) -#define DS3231_CR 0x0e /* Control register */ -# define DS3231_CR_A1IE (1 << 0) /* Bit 0: Alarm 1 interrupt enable */ -# define DS3231_CR_A2IE (1 << 1) /* Bit 1: Alarm 2 interrupt enable */ -# define DS3231_CR_INTCN (1 << 2) /* Bit 2: Interrupt control */ -# define DS3231_CR_RS_SHIFT (3) /* Bit 3-4: Rate selection */ -# define DS3231_CR_RS_MASK (3 << DS3231_CR_RS_SHIFT) -# define DS3231_CR_RS_1HZ (0 << DS3231_CR_RS_SHIFT) /* 1Hz */ -# define DS3231_CR_RS_1KHZ (1 << DS3231_CR_RS_SHIFT) /* 1.024kHz */ -# define DS3231_CR_RS_4KHZ (2 << DS3231_CR_RS_SHIFT) /* 4.096kHz */ -# define DS3231_CR_RS_8KHZ (3 << DS3231_CR_RS_SHIFT) /* 8.192kHz */ -# define DS3231_CR_CONV (1 << 5) /* Bit 5: Convert temperature */ -# define DS3231_CR_BBSQW (1 << 6) /* Bit 6: Battery backed square wave enable */ -# define DS3231_CR_EOSC (1 << 7) /* Bit 7: Enable oscillator */ +# define DS3231_ALARM2_DAYDATER 0x0d /* Alarm2 date / day of the week register */ +# define DS3231_ALARM2_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS3231_ALARM2_DAY_MASK (7 << DS3231_ALARM2_DAY_SHIFT) +# define DS3231_ALARM2_DAY(n) ((uint8_t)(n) << DS3231_ALARM2_DAY_SHIFT) +# define DS3231_ALARM2_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS3231_ALARM2_DATE_MASK (15 << DS3231_ALARM2_DATE_SHIFT) +# define DS3231_ALARM2_DATE(n) ((uint8_t)(n) << DS3231_ALARM2_DATE_SHIFT) +# define DS3231_ALARM2_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS3231_ALARM2_10DATE_MASK (3 << DS3231_ALARM2_10DATE_SHIFT) +# define DS3231_ALARM2_10DATE(n) ((uint8_t)(n) << DS3231_ALARM2_10DATE_SHIFT) +# define DS3231_ALARM2_DATE_BCDMASK (DS3231_ALARM2_DATE_MASK | DS3231_ALARM2_10DATE_MASK) +# define DS3231_ALARM2_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS3231_ALARM2_DYDT_MASK (1 << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM2_DYDT_SHIFT) +# define DS3231_ALARM2_A2M4_SHIFT 7 /* Bits 7: A2M4 mask */ +# define DS3231_ALARM2_A2M4_MASK (1 << DS3231_ALARM2_A2M4_SHIFT) +# define DS3231_ALARM2_A2M4(n) ((uint8_t)(n) << DS3231_ALARM2_A2M4_SHIFT) -#define DS3231_CSR 0x0f /* Control/status register */ -# define DS3231_CSR_A1F (1 << 0) /* Bit 0: Alarm 1 flag */ -# define DS3231_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ -# define DS3231_CSR_BSY (1 << 2) /* Bit 2: Busy */ -# define DS3231_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ -# define DS3231_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ +# define DS3231_CR 0x0e /* Control register */ +# define DS3231_CR_A1IE (1 << 0) /* Bit 0: Alarm 1 interrupt enable */ +# define DS3231_CR_A2IE (1 << 1) /* Bit 1: Alarm 2 interrupt enable */ +# define DS3231_CR_INTCN (1 << 2) /* Bit 2: Interrupt control */ +# define DS3231_CR_RS_SHIFT (3) /* Bits 3-4: Rate selection */ +# define DS3231_CR_RS_MASK (3 << DS3231_CR_RS_SHIFT) +# define DS3231_CR_RS_1HZ (0 << DS3231_CR_RS_SHIFT) /* 1Hz */ +# define DS3231_CR_RS_1KHZ (1 << DS3231_CR_RS_SHIFT) /* 1.024kHz */ +# define DS3231_CR_RS_4KHZ (2 << DS3231_CR_RS_SHIFT) /* 4.096kHz */ +# define DS3231_CR_RS_8KHZ (3 << DS3231_CR_RS_SHIFT) /* 8.192kHz */ +# define DS3231_CR_CONV (1 << 5) /* Bit 5: Convert temperature */ +# define DS3231_CR_BBSQW (1 << 6) /* Bit 6: Battery backed square wave enable */ +# define DS3231_CR_EOSC (1 << 7) /* Bit 7: Enable oscillator */ -#define DS3231_AGINGR 0x10 /* Aging offset register (8-bit, 2's complement) */ +# define DS3231_CSR 0x0f /* Control/status register */ +# define DS3231_CSR_A1F (1 << 0) /* Bit 0: Alarm 1 flag */ +# define DS3231_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ +# define DS3231_CSR_BSY (1 << 2) /* Bit 2: Busy */ +# define DS3231_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ +# define DS3231_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ -#define DS3231_TMPMR 0x11 /* MSB of temp register (8-bit, 2's complement) */ +# define DS3231_AGINGR 0x10 /* Aging offset register (8-bit, 2's complement) */ -#define DS3231_TMPLR 0x12 /* LSB of temp register (2-bits) */ -# define DS3231_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ +# define DS3231_TMPMR 0x11 /* MSB of temp register (8-bit, 2's complement) */ + +# define DS3231_TMPLR 0x12 /* LSB of temp register (2-bits) */ +# define DS3231_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ +#endif #endif /* __DRIVERS_TIMERS_DS3231_H */ diff --git a/include/nuttx/timers/ds3231.h b/include/nuttx/timers/ds3231.h index 98bf8bbb20..1dec1ab7df 100644 --- a/include/nuttx/timers/ds3231.h +++ b/include/nuttx/timers/ds3231.h @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_RTC_DS3231 +#ifdef CONFIG_RTC_DS3XXX /**************************************************************************** * Public Function Prototypes @@ -57,13 +57,13 @@ extern "C" #endif /************************************************************************************ - * Name: ds3231_rtc_initialize + * Name: ds3xxx_rtc_initialize * * Description: * Initialize the hardware RTC per the selected configuration. This function is * called once during the OS initialization sequence by board-specific logic. * - * After ds3231_rtc_initialize() is called, the OS function clock_synchronize() + * After ds3xxx_rtc_initialize() is called, the OS function clock_synchronize() * should also be called to synchronize the system timer to a hardware RTC. That * operation is normally performed automatically by the system during clock * initialization. However, when an external RTC is used, the board logic will @@ -79,12 +79,12 @@ extern "C" ************************************************************************************/ struct i2c_dev_s; /* Forward reference */ -int ds3231_rtc_initialize(FAR struct i2c_dev_s *i2c); +int ds3xxx_rtc_initialize(FAR struct i2c_dev_s *i2c); #undef EXTERN #ifdef __cplusplus } #endif -#endif /* CONFIG_RTC_DS3231 */ +#endif /* CONFIG_RTC_DS3XXX */ #endif /* __INCLUDE_NUTTX_TIMERS_DS3231_H */ -- GitLab From 432395218adb09b7f3372c222aa43f85648e08a5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 11:45:24 -0600 Subject: [PATCH 318/858] Refress submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index ca62315de4..2c7b756e0b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ca62315de49f3627e05136ba49d4ce0f9dff7784 +Subproject commit 2c7b756e0be05ebf388b685604a64449d0449b38 -- GitLab From 706218d18f028cffadee91a4b85ab87f9779fc77 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 18 Nov 2015 14:11:58 -0500 Subject: [PATCH 319/858] atoi(): Cast return value to int --- include/stdlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stdlib.h b/include/stdlib.h index ff10da14c5..d792d3b554 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -180,7 +180,7 @@ unsigned long long strtoull(const char *, char **, int); #endif double_t strtod(const char *, char **); -#define atoi(nptr) strtol((nptr), NULL, 10) +#define atoi(nptr) ((int)strtol((nptr), NULL, 10)) #define atol(nptr) strtol((nptr), NULL, 10) #ifdef CONFIG_HAVE_LONG_LONG #define atoll(nptr) strtoll((nptr), NULL, 10) -- GitLab From bfc95c641f58e16dcfe1dbb12a453723baa30618 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 18 Nov 2015 14:22:43 -0500 Subject: [PATCH 320/858] stdlib: Fix forgotten FARs --- include/stdlib.h | 29 +++++++++++++++-------------- libc/stdlib/lib_itoa.c | 6 +++--- libc/stdlib/lib_strtod.c | 3 +-- libc/stdlib/lib_strtol.c | 3 +-- libc/stdlib/lib_strtoll.c | 3 +-- libc/stdlib/lib_strtoul.c | 3 +-- libc/stdlib/lib_strtoull.c | 4 ++-- mm/umm_heap/umm_mallinfo.c | 2 +- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/include/stdlib.h b/include/stdlib.h index ff10da14c5..b1ef867ae3 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -76,7 +76,7 @@ */ #ifndef CONFIG_DISABLE_ENVIRON -# define environ get_environ_ptr() +# define environ get_environ_ptr() #endif /**************************************************************************** @@ -146,12 +146,12 @@ int rand(void); /* Environment variable support */ #ifndef CONFIG_DISABLE_ENVIRON -FAR char **get_environ_ptr( void ); +FAR char **get_environ_ptr(void); FAR char *getenv(FAR const char *name); int putenv(FAR const char *string); int clearenv(void); -int setenv(const char *name, const char *value, int overwrite); -int unsetenv(const char *name); +int setenv(FAR const char *name, FAR const char *value, int overwrite); +int unsetenv(FAR const char *name); #endif /* Process exit functions */ @@ -172,13 +172,14 @@ void _exit(int status); /* See unistd.h */ /* String to binary conversions */ -long strtol(const char *, char **, int); -unsigned long strtoul(const char *, char **, int); +long strtol(FAR const char *nptr, FAR char **endptr, int base); +unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base); #ifdef CONFIG_HAVE_LONG_LONG -long long strtoll(const char *, char **, int); -unsigned long long strtoull(const char *, char **, int); +long long strtoll(FAR const char *nptr, FAR char **endptr, int base); +unsigned long long strtoull(FAR const char *nptr, FAR char **endptr, + int base); #endif -double_t strtod(const char *, char **); +double_t strtod(FAR const char *str, FAR char **endptr); #define atoi(nptr) strtol((nptr), NULL, 10) #define atol(nptr) strtol((nptr), NULL, 10) @@ -189,13 +190,13 @@ double_t strtod(const char *, char **); /* Binary to string conversions */ -char *itoa(int value, char *str, int base); +FAR char *itoa(int val, FAR char *str, int base); /* Memory Management */ FAR void *malloc(size_t); -void free(FAR void*); -FAR void *realloc(FAR void*, size_t); +void free(FAR void *); +FAR void *realloc(FAR void *, size_t); FAR void *memalign(size_t, size_t); FAR void *zalloc(size_t); FAR void *calloc(size_t, size_t); @@ -203,7 +204,7 @@ FAR void *calloc(size_t, size_t); #ifdef CONFIG_CAN_PASS_STRUCTS struct mallinfo mallinfo(void); #else -int mallinfo(struct mallinfo *info); +int mallinfo(FAR struct mallinfo *info); #endif /* Arithmetic */ @@ -230,7 +231,7 @@ int mkstemp(FAR char *path_template); /* Sorting */ void qsort(FAR void *base, size_t nel, size_t width, - int (*compar)(FAR const void *, FAR const void *)); + CODE int (*compar)(FAR const void *, FAR const void *)); /* Binary search */ diff --git a/libc/stdlib/lib_itoa.c b/libc/stdlib/lib_itoa.c index 16170160aa..ad3563cde9 100644 --- a/libc/stdlib/lib_itoa.c +++ b/libc/stdlib/lib_itoa.c @@ -49,11 +49,11 @@ * Public Functions ****************************************************************************/ -char *itoa(int val, char *str, int base) +FAR char *itoa(int val, FAR char *str, int base) { - static const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + static FAR const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; int intval = abs(val), digit, pos, len; - char *buf = str; + FAR char *buf = str; char swap; if (base >= 2 && base <= 36) diff --git a/libc/stdlib/lib_strtod.c b/libc/stdlib/lib_strtod.c index 2f7ed81f55..9b7462368b 100644 --- a/libc/stdlib/lib_strtod.c +++ b/libc/stdlib/lib_strtod.c @@ -87,7 +87,7 @@ static inline int is_real(double x) * ****************************************************************************/ -double_t strtod(const char *str, char **endptr) +double_t strtod(FAR const char *str, FAR char **endptr) { double_t number; int exponent; @@ -238,4 +238,3 @@ double_t strtod(const char *str, char **endptr) } #endif /* CONFIG_HAVE_DOUBLE */ - diff --git a/libc/stdlib/lib_strtol.c b/libc/stdlib/lib_strtol.c index dd17691a07..5518172949 100644 --- a/libc/stdlib/lib_strtol.c +++ b/libc/stdlib/lib_strtol.c @@ -64,7 +64,7 @@ * ****************************************************************************/ -long strtol(const char *nptr, char **endptr, int base) +long strtol(FAR const char *nptr, FAR char **endptr, int base) { unsigned long accum = 0; bool negate = false; @@ -101,4 +101,3 @@ long strtol(const char *nptr, char **endptr, int base) return (long)accum; } - diff --git a/libc/stdlib/lib_strtoll.c b/libc/stdlib/lib_strtoll.c index af4afb90d1..7ed5ecab20 100644 --- a/libc/stdlib/lib_strtoll.c +++ b/libc/stdlib/lib_strtoll.c @@ -66,7 +66,7 @@ * ****************************************************************************/ -long long strtoll(const char *nptr, char **endptr, int base) +long long strtoll(FAR const char *nptr, FAR char **endptr, int base) { unsigned long long accum = 0; bool negate = false; @@ -105,4 +105,3 @@ long long strtoll(const char *nptr, char **endptr, int base) } #endif - diff --git a/libc/stdlib/lib_strtoul.c b/libc/stdlib/lib_strtoul.c index c9b0915e6f..712a658e26 100644 --- a/libc/stdlib/lib_strtoul.c +++ b/libc/stdlib/lib_strtoul.c @@ -63,7 +63,7 @@ * ****************************************************************************/ -unsigned long strtoul(const char *nptr, char **endptr, int base) +unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base) { unsigned long accum = 0; int value; @@ -96,4 +96,3 @@ unsigned long strtoul(const char *nptr, char **endptr, int base) return accum; } - diff --git a/libc/stdlib/lib_strtoull.c b/libc/stdlib/lib_strtoull.c index 7e961d7333..169058128a 100644 --- a/libc/stdlib/lib_strtoull.c +++ b/libc/stdlib/lib_strtoull.c @@ -64,7 +64,7 @@ * ****************************************************************************/ -unsigned long long strtoull(const char *nptr, char **endptr, int base) +unsigned long long strtoull(FAR const char *nptr, FAR char **endptr, int base) { unsigned long long accum = 0; int value; @@ -96,5 +96,5 @@ unsigned long long strtoull(const char *nptr, char **endptr, int base) } return accum; } -#endif +#endif diff --git a/mm/umm_heap/umm_mallinfo.c b/mm/umm_heap/umm_mallinfo.c index f7a5b9dc07..a6c1aaa847 100644 --- a/mm/umm_heap/umm_mallinfo.c +++ b/mm/umm_heap/umm_mallinfo.c @@ -69,7 +69,7 @@ struct mallinfo mallinfo(void) #else -int mallinfo(struct mallinfo *info) +int mallinfo(FAR struct mallinfo *info) { return mm_mallinfo(USR_HEAP, info); } -- GitLab From 687cea60b3e2980f372327c1270adb00d476f0ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 13:57:02 -0600 Subject: [PATCH 321/858] Add basic support for the SAME70-Xplained board --- ChangeLog | 3 +++ Documentation | 2 +- README.txt | 4 +++- configs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f879a7bb38..c2dc38ad9d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11116,4 +11116,7 @@ (2015-11-18). * drivers/timers/ds3231.c: Driver extended to include support for the DS1307 RTC (2015-11-18). + * configs/same70-xplained: Add basic NSH configuration for the SAME70 + Xplained board. Initial commit is just the SAMV71-XULT files with + names changed appropriately (2015-11-18). diff --git a/Documentation b/Documentation index 9a0efe5bb5..ffe506af46 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 9a0efe5bb5e0a817f74b4521f4bb0d91b6f0c2cf +Subproject commit ffe506af460b9828138ee395b7a3b7ab8ff9ef73 diff --git a/README.txt b/README.txt index ee336105b0..df625bcb75 100644 --- a/README.txt +++ b/README.txt @@ -1416,7 +1416,9 @@ nuttx/ | | `- README.txt | |- sam4s-xplained-pro/ | | `- README.txt - | |- samv7i-xult/ + | |- same70-xplained/ + | | `- README.txt + | |- samv71-xult/ | | `- README.txt | |- sim/ | | `- README.txt diff --git a/configs b/configs index 2c7b756e0b..c4dede71f2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2c7b756e0be05ebf388b685604a64449d0449b38 +Subproject commit c4dede71f2de2441f4cd3c01c88617c819de8137 -- GitLab From c0a1d8e960eb518a04bbc41e6aae658720fe122a Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 18 Nov 2015 15:09:43 -0500 Subject: [PATCH 322/858] stdio: Define BUFSIZ --- include/stdio.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 3a0745c84f..057a58c9a8 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -58,7 +58,13 @@ #define FILENAME_MAX _POSIX_NAME_MAX -/* File system error values *************************************************/ +/* The size of the I/O buffers */ + +#if CONFIG_STDIO_BUFFER_SIZE > 0 +# define BUFSIZ CONFIG_STDIO_BUFFER_SIZE +#endif + +/* File system error values */ #define EOF (-1) @@ -94,7 +100,7 @@ #define L_tmpnam CONFIG_LIBC_MAX_TMPFILE -/* the maximum number of unique temporary file names that can be generated */ +/* The maximum number of unique temporary file names that can be generated */ #define TMP_MAX 56800235584ull -- GitLab From 1b7d7a53b2b63d0782e82ee3a0e4adfe84a93f08 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Nov 2015 14:35:24 -0600 Subject: [PATCH 323/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index c0b78aab85..a3bf280f61 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c0b78aab85f0a31a85c90d01c60d4749a193af73 +Subproject commit a3bf280f61d4670019587c67526ea076af134f89 diff --git a/configs b/configs index c4dede71f2..8615cb1106 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c4dede71f2de2441f4cd3c01c88617c819de8137 +Subproject commit 8615cb11063524b142c9fda9c536e54dd462e3cc -- GitLab From 7b590ec9a27e41e36b8787d04b484359e398b9db Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Wed, 18 Nov 2015 18:12:06 -0600 Subject: [PATCH 324/858] drivers/mtd/smart.c Fixed SmartFS wear level error that occurs when the logical sector size is too small to save all wear level status bytes in a single sector. Logical sectors 1 and 2 were simply not being allocated and then the read_sector and write_sector routines were failing. From Ken Petit --- ChangeLog | 5 ++++ configs | 2 +- drivers/mtd/smart.c | 59 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2dc38ad9d..e1e1c13306 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11119,4 +11119,9 @@ * configs/same70-xplained: Add basic NSH configuration for the SAME70 Xplained board. Initial commit is just the SAMV71-XULT files with names changed appropriately (2015-11-18). + * drivers/mtd/smart.c: Fixed SmartFS wear level error that occurs when + the logical sector size is too small to save all wear level status + bytes in a single sector. Logical sectors 1 and 2 were simply not + being allocated and then the read_sector and write_sector routinesi + were failing. From Ken Petit (2015-11-18). diff --git a/configs b/configs index 8615cb1106..165837ff2a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8615cb11063524b142c9fda9c536e54dd462e3cc +Subproject commit 165837ff2aa39c6cb478223c0b1bbec4a42dadc6 diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index dba5101134..a07bd22097 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -3,7 +3,7 @@ * * Sector Mapped Allocation for Really Tiny (SMART) Flash block driver. * - * Copyright (C) 2013-2014 Ken Pettit. All rights reserved. + * Copyright (C) 2013-2015 Ken Pettit. All rights reserved. * Author: Ken Pettit * * Redistribution and use in source and binary forms, with or without @@ -372,6 +372,8 @@ static int smart_findfreephyssector(FAR struct smart_struct_s *dev, uint8_t canr #ifdef CONFIG_FS_WRITABLE static int smart_writesector(FAR struct smart_struct_s *dev, unsigned long arg); +static inline int smart_allocsector(FAR struct smart_struct_s *dev, + unsigned long requested); #endif static int smart_readsector(FAR struct smart_struct_s *dev, unsigned long arg); @@ -381,7 +383,7 @@ static int smart_relocate_static_data(FAR struct smart_struct_s *dev, uint16_t b #endif static int smart_relocate_sector(FAR struct smart_struct_s *dev, - uint16_t oldsector, uint16_t newsector); + uint16_t oldsector, uint16_t newsector); /**************************************************************************** * Private Data @@ -3782,9 +3784,9 @@ static int smart_write_wearstatus(struct smart_struct_s *dev) /* Calculate the number of bytes to write to this sector */ towrite = remaining; - if (towrite > dev->sectorsize - SMARTFS_FMT_WEAR_POS) + if (towrite > dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s))) { - towrite = dev->sectorsize - SMARTFS_FMT_WEAR_POS; + towrite = dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s)); } /* Setup the sector write request (we are our own client) */ @@ -3843,19 +3845,20 @@ errout: #ifdef CONFIG_MTD_SMART_WEAR_LEVEL static inline int smart_read_wearstatus(FAR struct smart_struct_s *dev) { - uint16_t sector; - uint16_t remaining, toread; struct smart_read_write_s req; - int ret; - uint8_t buffer[8]; + uint16_t sector, physsector; + uint16_t remaining, toread; + uint8_t buffer[8]; + int ret; /* Prepare to read the total block erases and uneven wearcount values */ - sector = 0; + sector = 0; req.logsector = sector; - req.offset = SMARTFS_FMT_WEAR_POS - 8; - req.count = sizeof(buffer); - req.buffer = buffer; + req.offset = SMARTFS_FMT_WEAR_POS - 8; + req.count = sizeof(buffer); + req.buffer = buffer; + ret = smart_readsector(dev, (unsigned long) &req); if (ret != sizeof(buffer)) { @@ -3908,6 +3911,29 @@ static inline int smart_read_wearstatus(FAR struct smart_struct_s *dev) req.buffer = &dev->wearstatus[(dev->geo.neraseblocks >> SMART_WEAR_BIT_DIVIDE) - remaining]; + /* Validate wear status sector has been allocated */ + +#ifndef CONFIG_MTD_SMART_MINIMIZE_RAM + physsector = dev->sMap[req.logsector]; +#else + physsector = smart_cache_lookup(dev, req->logsector); +#endif + if ((sector != 0) && (physsector == 0xFFFF)) + { +#ifdef CONFIG_FS_WRITABLE + + /* This logical sector does not exist yet. We must allocate it */ + + ret = smart_allocsector(dev, sector); + if (ret != sector) + { + fdbg("Unable to allocate wear level status sector %d\n", sector); + ret = -EINVAL; + goto errout; + } +#endif + } + /* Read the sector */ ret = smart_readsector(dev, (unsigned long) &req); @@ -4690,7 +4716,7 @@ static inline int smart_allocsector(FAR struct smart_struct_s *dev, * sector if it isn't already in use. */ - if ((requested > 2) && (requested < dev->totalsectors)) + if ((requested > 0) && (requested < dev->totalsectors)) { /* Validate the sector is not already allocated */ @@ -5059,6 +5085,13 @@ static int smart_ioctl(FAR struct inode *inode, int cmd, unsigned long arg) case BIOC_ALLOCSECT: + /* Ensure the FS is not trying to allocate a reserved sector */ + + if (arg < 3) + { + arg = (unsigned long) -1; + } + /* Allocate a logical sector for the upper layer file system */ ret = smart_allocsector(dev, arg); -- GitLab From 1c86c004c4fcf34b95beaab6ce9a585fd8d9a568 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 06:57:02 -0600 Subject: [PATCH 325/858] FLASH progmem memory MTD: Need to register with PROCFS if enabled --- drivers/mtd/mtd_progmem.c | 6 ++++++ drivers/mtd/skeleton.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c index 8fcda67aae..e3eca2ee5f 100644 --- a/drivers/mtd/mtd_progmem.c +++ b/drivers/mtd/mtd_progmem.c @@ -392,6 +392,12 @@ FAR struct mtd_dev_s *progmem_initialize(void) g_progmem.blkshift = blkshift; g_progmem.initialized = true; + +#ifdef CONFIG_MTD_REGISTRATION + /* Register the MTD with the procfs system if enabled */ + + mtd_register(&priv->mtd, "progmem"); +#endif } /* Return the implementation-specific state structure as the MTD device */ diff --git a/drivers/mtd/skeleton.c b/drivers/mtd/skeleton.c index f9acf80e1e..1ccc1d879b 100644 --- a/drivers/mtd/skeleton.c +++ b/drivers/mtd/skeleton.c @@ -321,8 +321,19 @@ static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) FAR struct mtd_dev_s *skel_initialize(void) { + /* Allocate an instance of the private data structure -- OR, if there can + * only be a single instance of the driver, then use a shared, global + * device structure. + */ + /* Perform initialization as necessary */ +#ifdef CONFIG_MTD_REGISTRATION + /* Register the MTD with the procfs system if enabled */ + + mtd_register(&priv->mtd, "skeleton"); +#endif + /* Return the implementation-specific state structure as the MTD device */ return (FAR struct mtd_dev_s *)&g_skeldev; -- GitLab From c34b5108a720256239e980fe87bc275d183395c8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 14:54:30 -0600 Subject: [PATCH 326/858] RTC: Fix system time initialization when using an exernal RTC. Fix some bugs in the DS1307/DS3231 RTC driver --- configs | 2 +- drivers/timers/Kconfig | 21 ++++- drivers/timers/Make.defs | 2 +- drivers/timers/ds3231.c | 93 ++++++++++++++++------ drivers/timers/ds3231.h | 141 +++++++++++++++++---------------- include/nuttx/timers/ds3231.h | 10 +-- sched/clock/clock_initialize.c | 6 +- 7 files changed, 172 insertions(+), 103 deletions(-) diff --git a/configs b/configs index 165837ff2a..388caf6346 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 165837ff2aa39c6cb478223c0b1bbec4a42dadc6 +Subproject commit 388caf63466f447ce0fc6924dc50e79b9ba70cf8 diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 95167ecd8f..6f8de15273 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -118,16 +118,31 @@ config RTC_IOCTL endif # RTC_DRIVER -config RTC_DS3XXX +config RTC_EXTERNAL + bool "External RTC Support" + default n + ---help--- + In modern MCUs, the RTC is usually implement as an internal + peripheral to the MCU. An option is to use an external RTC + connected to the MCU typically via SPI or I2C. + + If an external RTC is connect to the MCU through some bus, then the + RTC will not be available to the system until after the system + fully boots up and is able to access the bus. In that case, this + setting must be included to suppress attempts to initialize the RTC + early in the boot sequence. + +config RTC_DSXXXX bool "DS3231/DS1307 RTC Driver" default n select I2C select I2C_TRANSFER + select RTC_EXTERNAL select RTC_DATETIME ---help--- Enables support for the Maxim Integrated DS3231 I2C RTC timer. -if RTC_DS3XXX +if RTC_DSXXXX choice prompt "Maxim Integrated RTC" @@ -150,7 +165,7 @@ config DS3231_I2C_FREQUENCY default 400000 range 1 4000000 -endif # RTC_DS3XXX +endif # RTC_DSXXXX endif # RTC menuconfig WATCHDOG diff --git a/drivers/timers/Make.defs b/drivers/timers/Make.defs index f52599e1f8..0707c244a6 100644 --- a/drivers/timers/Make.defs +++ b/drivers/timers/Make.defs @@ -51,7 +51,7 @@ ifeq ($(CONFIG_TIMER),y) TMRVPATH = :timers endif -ifeq ($(CONFIG_RTC_DS3XXX),y) +ifeq ($(CONFIG_RTC_DSXXXX),y) CSRCS += ds3231.c TMRDEPPATH = --dep-path timers TMRVPATH = :timers diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index d3c122f273..9704a7a2c7 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -50,7 +50,7 @@ #include "ds3231.h" -#ifdef CONFIG_RTC_DS3XXX +#ifdef CONFIG_RTC_DSXXXX /************************************************************************************ * Pre-processor Definitions @@ -192,7 +192,7 @@ static uint8_t rtc_bin2bcd(int value) } /************************************************************************************ - * Name: rtc_bin2bcd + * Name: rtc_bcd2bin * * Description: * Convert from 2 digit BCD to binary. @@ -216,13 +216,13 @@ static int rtc_bcd2bin(uint8_t value) ************************************************************************************/ /************************************************************************************ - * Name: ds3xxx_rtc_initialize + * Name: dsxxxx_rtc_initialize * * Description: * Initialize the hardware RTC per the selected configuration. This function is * called once during the OS initialization sequence by board-specific logic. * - * After ds3xxx_rtc_initialize() is called, the OS function clock_synchronize() + * After dsxxxx_rtc_initialize() is called, the OS function clock_synchronize() * should also be called to synchronize the system timer to a hardware RTC. That * operation is normally performed automatically by the system during clock * initialization. However, when an external RTC is used, the board logic will @@ -237,7 +237,7 @@ static int rtc_bcd2bin(uint8_t value) * ************************************************************************************/ -int ds3xxx_rtc_initialize(FAR struct i2c_dev_s *i2c) +int dsxxxx_rtc_initialize(FAR struct i2c_dev_s *i2c) { /* Remember the i2c device and claim that the RTC is enabled */ @@ -278,9 +278,31 @@ int up_rtc_getdatetime(FAR struct tm *tp) int tmp; int ret; + /* If this function is called before the RTC has been initialized (and it will be), + * then just return the data/time of the epoch, 12:00 am, Jan 1, 1970. + */ + + if (!g_rtc_enabled) + { + tp->tm_sec = 0; + tp->tm_min = 0; + tp->tm_hour = 0; + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + /* Jan 1, 1970 was a Thursday */ + + tp->tm_wday = 4; +#endif + + tp->tm_mday = 1; + tp->tm_mon = 0; + tp->tm_year = 70; + return -EAGAIN; + } + /* Select to begin reading at the seconds register */ - secaddr = DS3XXX_TIME_SECR; + secaddr = DSXXXX_TIME_SECR; msg[0].addr = DS3231_I2C_ADDRESS; msg[0].flags = 0; @@ -326,40 +348,42 @@ int up_rtc_getdatetime(FAR struct tm *tp) return ret; } } - while (buffer[0] > seconds); + while ((buffer[0] & DSXXXX_TIME_SEC_BCDMASK) > + (seconds & DSXXXX_TIME_SEC_BCDMASK)); /* Format the return time */ /* Return seconds (0-61) */ - tp->tm_sec = rtc_bcd2bin(buffer[0] & DS3XXX_TIME_SEC_BCDMASK); + tp->tm_sec = rtc_bcd2bin(buffer[0] & DSXXXX_TIME_SEC_BCDMASK); /* Return minutes (0-59) */ - tp->tm_min = rtc_bcd2bin(buffer[1] & DS3XXX_TIME_MIN_BCDMASK); + tp->tm_min = rtc_bcd2bin(buffer[1] & DSXXXX_TIME_MIN_BCDMASK); /* Return hour (0-23). This assumes 24-hour time was set. */ - tp->tm_hour = rtc_bcd2bin(buffer[2] & DS3XXX_TIME_HOUR24_BCDMASK); + tp->tm_hour = rtc_bcd2bin(buffer[2] & DSXXXX_TIME_HOUR24_BCDMASK); #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /* Return the day of the week (0-6) */ - tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DS3XXX_TIME_DAY_MASK) - 1; + tp->tm_wday = (rtc_bcd2bin(buffer[3]) & DSXXXX_TIME_DAY_MASK) - 1; #endif /* Return the day of the month (1-31) */ - tp->tm_mday = rtc_bcd2bin(buffer[4] & DS3XXX_TIME_DATE_BCDMASK); + tp->tm_mday = rtc_bcd2bin(buffer[4] & DSXXXX_TIME_DATE_BCDMASK); /* Return the month (0-11) */ - tp->tm_mon = rtc_bcd2bin(buffer[5] & DS3XXX_TIME_MONTH_BCDMASK) - 1; + tp->tm_mon = rtc_bcd2bin(buffer[5] & DSXXXX_TIME_MONTH_BCDMASK) - 1; - /* Return the years since 1990 */ + /* Return the years since 1900 */ - tmp = rtc_bcd2bin(buffer[5] & DS3XXX_TIME_YEAR_BCDMASK); + tmp = rtc_bcd2bin(buffer[6] & DSXXXX_TIME_YEAR_BCDMASK); - if ((buffer[6] & DS3XXX_TIME_CENTURY_MASK) == DS3XXX_TIME_1900) +#ifdef CONFIG_RTC_DS3231 + if ((buffer[5] & DS3231_TIME_CENTURY_MASK) == DS3231_TIME_1900) { tp->tm_year = tmp; } @@ -367,6 +391,11 @@ int up_rtc_getdatetime(FAR struct tm *tp) { tp->tm_year = tmp + 100; } +#else + /* No century indicator. The RTC will hold years since 1970 */ + + tp->tm_year = tmp + 70; +#endif rtc_dumptime(tp, "Returning"); return OK; @@ -398,6 +427,15 @@ int up_rtc_settime(FAR const struct timespec *tp) uint8_t year; int ret; + /* If this function is called before the RTC has been initialized then just return + * an error. + */ + + if (!g_rtc_enabled) + { + return -EAGAIN; + } + rtc_dumptime(tp, "Setting time"); /* Get the broken out time */ @@ -429,7 +467,7 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Construct the message */ /* Write starting with the seconds regiser */ - buffer[0] = DS3XXX_TIME_SECR; + buffer[0] = DSXXXX_TIME_SECR; /* Save seconds (0-59) converted to BCD */ @@ -441,7 +479,7 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Save hour (0-23) with 24-hour time indicatin */ - buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DS3XXX_TIME_24; + buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DSXXXX_TIME_24; /* Save the day of the week (1-7) */ @@ -455,30 +493,38 @@ int up_rtc_settime(FAR const struct timespec *tp) buffer[5] = rtc_bin2bcd(newtm.tm_mday); +#ifdef CONFIG_RTC_DS3231 /* Handle years in the 20th vs the 21st century */ if (newtm.tm_year < 100) { /* Convert years in the range 1900-1999 */ - century = DS3XXX_TIME_1900; + century = DS3231_TIME_1900; year = newtm.tm_year; } else { /* Convert years in the range 2000-2099 */ - century = DS3XXX_TIME_2000; + century = DS3231_TIME_2000; year = newtm.tm_year - 100; } +#else + /* Use years since 1970 */ + + century = 0; + year = newtm.tm_year - 70; +#endif + /* Save the month (1-12) with century */ buffer[6] = rtc_bin2bcd(newtm.tm_mon + 1) | century; /* Save the year */ - buffer[7] = year; + buffer[7] = rtc_bin2bcd(year); /* Setup the I2C message */ @@ -517,9 +563,10 @@ int up_rtc_settime(FAR const struct timespec *tp) return ret; } } - while (buffer[1] > seconds); + while ((buffer[1] & DSXXXX_TIME_SEC_BCDMASK) > + (seconds & DSXXXX_TIME_SEC_BCDMASK)); return OK; } -#endif /* CONFIG_RTC_DS3XXX */ +#endif /* CONFIG_RTC_DSXXXX */ diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index 57ea6f5bec..3c7a64ecab 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -46,80 +46,85 @@ * Pre-processor Definitions ****************************************************************************/ -#define DS3XXX_TIME_SECR 0x00 /* Seconds register */ -# define DS3XXX_TIME_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ -# define DS3XXX_TIME_SEC_MASK (15 << DS3XXX_TIME_SEC_SHIFT) -# define DS3XXX_TIME_SEC(n) ((uint8_t)(n) << DS3XXX_TIME_SEC_SHIFT) -# define DS3XXX_TIME_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ -# define DS3XXX_TIME_10SEC_MASK (7 << DS3XXX_TIME_10SEC_SHIFT) -# define DS3XXX_TIME_10SEC(n) ((uint8_t)(n) << DS3XXX_TIME_10SEC_SHIFT) -# define DS3XXX_TIME_SEC_BCDMASK (DS3XXX_TIME_SEC_MASK | DS3XXX_TIME_10SEC_MASK) +#define DSXXXX_TIME_SECR 0x00 /* Seconds register */ +# define DSXXXX_TIME_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DSXXXX_TIME_SEC_MASK (15 << DSXXXX_TIME_SEC_SHIFT) +# define DSXXXX_TIME_SEC(n) ((uint8_t)(n) << DSXXXX_TIME_SEC_SHIFT) +# define DSXXXX_TIME_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DSXXXX_TIME_10SEC_MASK (7 << DSXXXX_TIME_10SEC_SHIFT) +# define DSXXXX_TIME_10SEC(n) ((uint8_t)(n) << DSXXXX_TIME_10SEC_SHIFT) +# define DSXXXX_TIME_SEC_BCDMASK (DSXXXX_TIME_SEC_MASK | DSXXXX_TIME_10SEC_MASK) +#ifdef CONFIG_RTC_DS1307 +# define DS1307_TIME_CH (1 << 7) /* Bit 7: Clock halt */ +#endif -#define DS3XXX_TIME_MINR 0x01 /* Minutes register */ -# define DS3XXX_TIME_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3XXX_TIME_MIN_MASK (15 << DS3XXX_TIME_MIN_SHIFT) -# define DS3XXX_TIME_MIN(n) ((uint8_t)(n) << DS3XXX_TIME_MIN_SHIFT) -# define DS3XXX_TIME_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3XXX_TIME_10MIN_MASK (7 << DS3XXX_TIME_10MIN_SHIFT) -# define DS3XXX_TIME_10MIN(n) ((uint8_t)(n) << DS3XXX_TIME_10MIN_SHIFT) -# define DS3XXX_TIME_MIN_BCDMASK (DS3XXX_TIME_MIN_MASK | DS3XXX_TIME_10MIN_MASK) +#define DSXXXX_TIME_MINR 0x01 /* Minutes register */ +# define DSXXXX_TIME_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DSXXXX_TIME_MIN_MASK (15 << DSXXXX_TIME_MIN_SHIFT) +# define DSXXXX_TIME_MIN(n) ((uint8_t)(n) << DSXXXX_TIME_MIN_SHIFT) +# define DSXXXX_TIME_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DSXXXX_TIME_10MIN_MASK (7 << DSXXXX_TIME_10MIN_SHIFT) +# define DSXXXX_TIME_10MIN(n) ((uint8_t)(n) << DSXXXX_TIME_10MIN_SHIFT) +# define DSXXXX_TIME_MIN_BCDMASK (DSXXXX_TIME_MIN_MASK | DSXXXX_TIME_10MIN_MASK) -#define DS3XXX_TIME_HOURR 0x02 /* Hours register */ -# define DS3XXX_TIME_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3XXX_TIME_HOUR_MASK (15 << DS3XXX_TIME_HOUR_SHIFT) -# define DS3XXX_TIME_HOUR(n) ((uint8_t)(n) << DS3XXX_TIME_HOUR_SHIFT) -# define DS3XXX_TIME_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3XXX_TIME_10HOUR12_MASK (1 << DS3XXX_TIME_10HOUR12_SHIFT) -# define DS3XXX_TIME_10HOUR12(n) ((uint8_t)(n) << DS3XXX_TIME_10HOUR12_SHIFT) -# define DS3XXX_TIME_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3XXX_TIME_10HOUR24_MASK (3 << DS3XXX_TIME_10HOUR24_SHIFT) -# define DS3XXX_TIME_10HOUR24(n) ((uint8_t)(n) << DS3XXX_TIME_10HOUR24_SHIFT) -# define DS3XXX_TIME_HOUR12_BCDMASK (DS3XXX_TIME_HOUR_MASK | DS3XXX_TIME_10HOUR12_MASK) -# define DS3XXX_TIME_HOUR24_BCDMASK (DS3XXX_TIME_HOUR_MASK | DS3XXX_TIME_10HOUR24_MASK) -# define DS3XXX_TIME_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3XXX_TIME_AMPM_MASK (1 << DS3XXX_TIME_AMPM_SHIFT) -# define DS3XXX_TIME_AM ((uint8_t)(0) << DS3XXX_TIME_AMPM_SHIFT) -# define DS3XXX_TIME_PM ((uint8_t)(1) << DS3XXX_TIME_AMPM_SHIFT) -# define DS3XXX_TIME_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3XXX_TIME_1224_MASK (1 << DS3XXX_TIME_1224_SHIFT) -# define DS3XXX_TIME_24 ((uint8_t)(0) << DS3XXX_TIME_1224_SHIFT) -# define DS3XXX_TIME_12 ((uint8_t)(1) << DS3XXX_TIME_1224_SHIFT) +#define DSXXXX_TIME_HOURR 0x02 /* Hours register */ +# define DSXXXX_TIME_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DSXXXX_TIME_HOUR_MASK (15 << DSXXXX_TIME_HOUR_SHIFT) +# define DSXXXX_TIME_HOUR(n) ((uint8_t)(n) << DSXXXX_TIME_HOUR_SHIFT) +# define DSXXXX_TIME_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DSXXXX_TIME_10HOUR12_MASK (1 << DSXXXX_TIME_10HOUR12_SHIFT) +# define DSXXXX_TIME_10HOUR12(n) ((uint8_t)(n) << DSXXXX_TIME_10HOUR12_SHIFT) +# define DSXXXX_TIME_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DSXXXX_TIME_10HOUR24_MASK (3 << DSXXXX_TIME_10HOUR24_SHIFT) +# define DSXXXX_TIME_10HOUR24(n) ((uint8_t)(n) << DSXXXX_TIME_10HOUR24_SHIFT) +# define DSXXXX_TIME_HOUR12_BCDMASK (DSXXXX_TIME_HOUR_MASK | DSXXXX_TIME_10HOUR12_MASK) +# define DSXXXX_TIME_HOUR24_BCDMASK (DSXXXX_TIME_HOUR_MASK | DSXXXX_TIME_10HOUR24_MASK) +# define DSXXXX_TIME_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DSXXXX_TIME_AMPM_MASK (1 << DSXXXX_TIME_AMPM_SHIFT) +# define DSXXXX_TIME_AM ((uint8_t)(0) << DSXXXX_TIME_AMPM_SHIFT) +# define DSXXXX_TIME_PM ((uint8_t)(1) << DSXXXX_TIME_AMPM_SHIFT) +# define DSXXXX_TIME_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DSXXXX_TIME_1224_MASK (1 << DSXXXX_TIME_1224_SHIFT) +# define DSXXXX_TIME_24 ((uint8_t)(0) << DSXXXX_TIME_1224_SHIFT) +# define DSXXXX_TIME_12 ((uint8_t)(1) << DSXXXX_TIME_1224_SHIFT) -#define DS3XXX_TIME_DAYR 0x03 /* Day of the week register */ -# define DS3XXX_TIME_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3XXX_TIME_DAY_MASK (7 << DS3XXX_TIME_DAY_SHIFT) -# define DS3XXX_TIME_DAY(n) ((uint8_t)(n) << DS3XXX_TIME_DAY_SHIFT) +#define DSXXXX_TIME_DAYR 0x03 /* Day of the week register */ +# define DSXXXX_TIME_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DSXXXX_TIME_DAY_MASK (7 << DSXXXX_TIME_DAY_SHIFT) +# define DSXXXX_TIME_DAY(n) ((uint8_t)(n) << DSXXXX_TIME_DAY_SHIFT) -#define DS3XXX_TIME_DATER 0x04 /* Date register */ -# define DS3XXX_TIME_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3XXX_TIME_DATE_MASK (15 << DS3XXX_TIME_DATE_SHIFT) -# define DS3XXX_TIME_DATE(n) ((uint8_t)(n) << DS3XXX_TIME_DATE_SHIFT) -# define DS3XXX_TIME_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3XXX_TIME_10DATE_MASK (3 << DS3XXX_TIME_10DATE_SHIFT) -# define DS3XXX_TIME_10DATE(n) ((uint8_t)(n) << DS3XXX_TIME_10DATE_SHIFT) -# define DS3XXX_TIME_DATE_BCDMASK (DS3XXX_TIME_DATE_MASK | DS3XXX_TIME_10DATE_MASK) +#define DSXXXX_TIME_DATER 0x04 /* Date register */ +# define DSXXXX_TIME_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DSXXXX_TIME_DATE_MASK (15 << DSXXXX_TIME_DATE_SHIFT) +# define DSXXXX_TIME_DATE(n) ((uint8_t)(n) << DSXXXX_TIME_DATE_SHIFT) +# define DSXXXX_TIME_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DSXXXX_TIME_10DATE_MASK (3 << DSXXXX_TIME_10DATE_SHIFT) +# define DSXXXX_TIME_10DATE(n) ((uint8_t)(n) << DSXXXX_TIME_10DATE_SHIFT) +# define DSXXXX_TIME_DATE_BCDMASK (DSXXXX_TIME_DATE_MASK | DSXXXX_TIME_10DATE_MASK) -#define DS3XXX_TIME_MONTHR 0x05 /* Month register */ -# define DS3XXX_TIME_MONTH_SHIFT 0 /* Bits 0-3: Month, range 0-9 */ -# define DS3XXX_TIME_MONTH_MASK (15 << DS3XXX_TIME_MONTH_SHIFT) -# define DS3XXX_TIME_MONTH(n) ((uint8_t)(n) << DS3XXX_TIME_MONTH_SHIFT) -# define DS3XXX_TIME_10MONTH_SHIFT 4 /* Bit 4: 10 month, range 0-1 */ -# define DS3XXX_TIME_10MONTH_MASK (1 << DS3XXX_TIME_10MONTH_SHIFT) -# define DS3XXX_TIME_10MONTH(n) ((uint8_t)(n) << DS3XXX_TIME_10MONTH_SHIFT) -# define DS3XXX_TIME_MONTH_BCDMASK (DS3XXX_TIME_MONTH_MASK | DS3XXX_TIME_10MONTH_MASK) -# define DS3XXX_TIME_CENTURY_SHIFT 7 /* Bit 7: AM/PM Indication */ -# define DS3XXX_TIME_CENTURY_MASK (1 << DS3XXX_TIME_CENTURY_SHIFT) -# define DS3XXX_TIME_1900 ((uint8_t)(0) << DS3XXX_TIME_CENTURY_SHIFT) -# define DS3XXX_TIME_2000 ((uint8_t)(1) << DS3XXX_TIME_CENTURY_SHIFT) +#define DSXXXX_TIME_MONTHR 0x05 /* Month register */ +# define DSXXXX_TIME_MONTH_SHIFT 0 /* Bits 0-3: Month, range 0-9 */ +# define DSXXXX_TIME_MONTH_MASK (15 << DSXXXX_TIME_MONTH_SHIFT) +# define DSXXXX_TIME_MONTH(n) ((uint8_t)(n) << DSXXXX_TIME_MONTH_SHIFT) +# define DSXXXX_TIME_10MONTH_SHIFT 4 /* Bit 4: 10 month, range 0-1 */ +# define DSXXXX_TIME_10MONTH_MASK (1 << DSXXXX_TIME_10MONTH_SHIFT) +# define DSXXXX_TIME_10MONTH(n) ((uint8_t)(n) << DSXXXX_TIME_10MONTH_SHIFT) +# define DSXXXX_TIME_MONTH_BCDMASK (DSXXXX_TIME_MONTH_MASK | DSXXXX_TIME_10MONTH_MASK) +#ifdef CONFIG_RTC_DS3231 +# define DS3231_TIME_CENTURY_SHIFT 7 /* Bit 7: Century Indication */ +# define DS3231_TIME_CENTURY_MASK (1 << DS3231_TIME_CENTURY_SHIFT) +# define DS3231_TIME_1900 ((uint8_t)(0) << DS3231_TIME_CENTURY_SHIFT) +# define DS3231_TIME_2000 ((uint8_t)(1) << DS3231_TIME_CENTURY_SHIFT) +#endif -#define DS3XXX_TIME_YEARR 0x06 /* Date register */ -# define DS3XXX_TIME_YEAR_SHIFT 0 /* Bits 0-3: Year, range 0-9 */ -# define DS3XXX_TIME_YEAR_MASK (15 << DS3XXX_TIME_YEAR_SHIFT) -# define DS3XXX_TIME_YEAR(n) ((uint8_t)(n) << DS3XXX_TIME_YEAR_SHIFT) -# define DS3XXX_TIME_10YEAR_SHIFT 4 /* Bits 4-7: 10 year, range 0-9 */ -# define DS3XXX_TIME_10YEAR_MASK (15 << DS3XXX_TIME_10YEAR_SHIFT) -# define DS3XXX_TIME_10YEAR(n) ((uint8_t)(n) << DS3XXX_TIME_10YEAR_SHIFT) -# define DS3XXX_TIME_YEAR_BCDMASK (DS3XXX_TIME_YEAR_MASK | DS3XXX_TIME_10YEAR_MASK) +#define DSXXXX_TIME_YEARR 0x06 /* Date register */ +# define DSXXXX_TIME_YEAR_SHIFT 0 /* Bits 0-3: Year, range 0-9 */ +# define DSXXXX_TIME_YEAR_MASK (15 << DSXXXX_TIME_YEAR_SHIFT) +# define DSXXXX_TIME_YEAR(n) ((uint8_t)(n) << DSXXXX_TIME_YEAR_SHIFT) +# define DSXXXX_TIME_10YEAR_SHIFT 4 /* Bits 4-7: 10 year, range 0-9 */ +# define DSXXXX_TIME_10YEAR_MASK (15 << DSXXXX_TIME_10YEAR_SHIFT) +# define DSXXXX_TIME_10YEAR(n) ((uint8_t)(n) << DSXXXX_TIME_10YEAR_SHIFT) +# define DSXXXX_TIME_YEAR_BCDMASK (DSXXXX_TIME_YEAR_MASK | DSXXXX_TIME_10YEAR_MASK) #ifdef CONFIG_RTC_DS1307 # define DS1307_CR 0x07 /* Control register */ diff --git a/include/nuttx/timers/ds3231.h b/include/nuttx/timers/ds3231.h index 1dec1ab7df..b3f239e3ad 100644 --- a/include/nuttx/timers/ds3231.h +++ b/include/nuttx/timers/ds3231.h @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_RTC_DS3XXX +#ifdef CONFIG_RTC_DSXXXX /**************************************************************************** * Public Function Prototypes @@ -57,13 +57,13 @@ extern "C" #endif /************************************************************************************ - * Name: ds3xxx_rtc_initialize + * Name: dsxxxx_rtc_initialize * * Description: * Initialize the hardware RTC per the selected configuration. This function is * called once during the OS initialization sequence by board-specific logic. * - * After ds3xxx_rtc_initialize() is called, the OS function clock_synchronize() + * After dsxxxx_rtc_initialize() is called, the OS function clock_synchronize() * should also be called to synchronize the system timer to a hardware RTC. That * operation is normally performed automatically by the system during clock * initialization. However, when an external RTC is used, the board logic will @@ -79,12 +79,12 @@ extern "C" ************************************************************************************/ struct i2c_dev_s; /* Forward reference */ -int ds3xxx_rtc_initialize(FAR struct i2c_dev_s *i2c); +int dsxxxx_rtc_initialize(FAR struct i2c_dev_s *i2c); #undef EXTERN #ifdef __cplusplus } #endif -#endif /* CONFIG_RTC_DS3XXX */ +#endif /* CONFIG_RTC_DSXXXX */ #endif /* __INCLUDE_NUTTX_TIMERS_DS3231_H */ diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 1871e90d2b..de855e3bc6 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -201,9 +201,11 @@ static void clock_inittime(void) void clock_initialize(void) { - /* Initialize the RTC hardware */ + /* Initialize the internal RTC hardware. Initialization of external RTC + * must be deferred until the system has booted. + */ -#ifdef CONFIG_RTC +#if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL) up_rtcinitialize(); #endif -- GitLab From 892ba4f26afff2498f9f35b986d232d20e2e2541 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 15:12:40 -0600 Subject: [PATCH 327/858] DS1307: Change year bias to 1968 which is a leap year juse like 2000 --- drivers/timers/ds3231.c | 10 ++++++---- sched/clock/clock_initialize.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 9704a7a2c7..c00b5e11a6 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -392,9 +392,11 @@ int up_rtc_getdatetime(FAR struct tm *tp) tp->tm_year = tmp + 100; } #else - /* No century indicator. The RTC will hold years since 1970 */ + /* No century indicator. The RTC will hold years since 1968 (a leap year like + * 2000) + */ - tp->tm_year = tmp + 70; + tp->tm_year = tmp + 68; #endif rtc_dumptime(tp, "Returning"); @@ -512,10 +514,10 @@ int up_rtc_settime(FAR const struct timespec *tp) } #else - /* Use years since 1970 */ + /* Use years since 1968 (a leap year like 2000) */ century = 0; - year = newtm.tm_year - 70; + year = newtm.tm_year - 68; #endif /* Save the month (1-12) with century */ diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index de855e3bc6..11d889f6d0 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -201,11 +201,11 @@ static void clock_inittime(void) void clock_initialize(void) { +#if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL) /* Initialize the internal RTC hardware. Initialization of external RTC * must be deferred until the system has booted. */ -#if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL) up_rtcinitialize(); #endif -- GitLab From 367d8020be201f84f45257901626e504833e74d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 15:57:36 -0600 Subject: [PATCH 328/858] Add some definitions for future support for the DS3234 SPI RTC --- drivers/timers/Kconfig | 16 ++- drivers/timers/ds3231.c | 10 +- drivers/timers/ds3231.h | 304 +++++++++++++++++++++------------------- 3 files changed, 176 insertions(+), 154 deletions(-) diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 6f8de15273..c42ee79df7 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -133,7 +133,7 @@ config RTC_EXTERNAL early in the boot sequence. config RTC_DSXXXX - bool "DS3231/DS1307 RTC Driver" + bool "DS1307/DS323x RTC Driver" default n select I2C select I2C_TRANSFER @@ -151,17 +151,25 @@ choice config RTC_DS1307 bool "DS1307" ---help--- - Enables support for the Maxim Integrated DS3231 I2C RTC timer. + Enables support for the Maxim Integrated DS1307 I2C RTC timer. config RTC_DS3231 bool "DS3231" ---help--- - Enables support for the Maxim Integrated DS1307 I2C RTC timer. + Enables support for the Maxim Integrated DS3231 I2C RTC timer. + +config RTC_DS3234 + bool "DS3234" + depends on EXPERIMENTAL + ---help--- + Enables support for the Maxim Integrated DS3234 SPI RTC timer. + + Not yet implemented. endchoice # Maxim Integrated RTC config DS3231_I2C_FREQUENCY - int "DS3231/DS1307 I2C frequency" + int "DS1307/DS323x I2C frequency" default 400000 range 1 4000000 diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index c00b5e11a6..a368a71648 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -382,8 +382,8 @@ int up_rtc_getdatetime(FAR struct tm *tp) tmp = rtc_bcd2bin(buffer[6] & DSXXXX_TIME_YEAR_BCDMASK); -#ifdef CONFIG_RTC_DS3231 - if ((buffer[5] & DS3231_TIME_CENTURY_MASK) == DS3231_TIME_1900) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) + if ((buffer[5] & DS323X_TIME_CENTURY_MASK) == DS323X_TIME_1900) { tp->tm_year = tmp; } @@ -495,21 +495,21 @@ int up_rtc_settime(FAR const struct timespec *tp) buffer[5] = rtc_bin2bcd(newtm.tm_mday); -#ifdef CONFIG_RTC_DS3231 +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) /* Handle years in the 20th vs the 21st century */ if (newtm.tm_year < 100) { /* Convert years in the range 1900-1999 */ - century = DS3231_TIME_1900; + century = DS323X_TIME_1900; year = newtm.tm_year; } else { /* Convert years in the range 2000-2099 */ - century = DS3231_TIME_2000; + century = DS323X_TIME_2000; year = newtm.tm_year - 100; } diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index 3c7a64ecab..e1c238484c 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -110,11 +110,11 @@ # define DSXXXX_TIME_10MONTH_MASK (1 << DSXXXX_TIME_10MONTH_SHIFT) # define DSXXXX_TIME_10MONTH(n) ((uint8_t)(n) << DSXXXX_TIME_10MONTH_SHIFT) # define DSXXXX_TIME_MONTH_BCDMASK (DSXXXX_TIME_MONTH_MASK | DSXXXX_TIME_10MONTH_MASK) -#ifdef CONFIG_RTC_DS3231 -# define DS3231_TIME_CENTURY_SHIFT 7 /* Bit 7: Century Indication */ -# define DS3231_TIME_CENTURY_MASK (1 << DS3231_TIME_CENTURY_SHIFT) -# define DS3231_TIME_1900 ((uint8_t)(0) << DS3231_TIME_CENTURY_SHIFT) -# define DS3231_TIME_2000 ((uint8_t)(1) << DS3231_TIME_CENTURY_SHIFT) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +# define DS323X_TIME_CENTURY_SHIFT 7 /* Bit 7: Century Indication */ +# define DS323X_TIME_CENTURY_MASK (1 << DS323X_TIME_CENTURY_SHIFT) +# define DS323X_TIME_1900 ((uint8_t)(0) << DS323X_TIME_CENTURY_SHIFT) +# define DS323X_TIME_2000 ((uint8_t)(1) << DS323X_TIME_CENTURY_SHIFT) #endif #define DSXXXX_TIME_YEARR 0x06 /* Date register */ @@ -139,156 +139,170 @@ # define DS1307_RAM_BASE 0x08 /* 0x08-0x3f: 56x8 RAM */ #endif -#ifdef CONFIG_RTC_DS3231 -# define DS3231_ALARM1_SECR 0x07 /* Alarm1 seconds register */ -# define DS3231_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ -# define DS3231_ALARM1_SEC_MASK (15 << DS3231_ALARM1_SEC_SHIFT) -# define DS3231_ALARM1_SEC(n) ((uint8_t)(n) << DS3231_ALARM1_SEC_SHIFT) -# define DS3231_ALARM1_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ -# define DS3231_ALARM1_10SEC_MASK (7 << DS3231_ALARM1_10SEC_SHIFT) -# define DS3231_ALARM1_10SEC(n) ((uint8_t)(n) << DS3231_ALARM1_10SEC_SHIFT) -# define DS3231_ALARM1_SEC_BCDMASK (DS3231_ALARM1_SEC_MASK | DS3231_ALARM1_10SEC_MASK) -# define DS3231_ALARM1_A1M1_SHIFT 7 /* Bits 7: A1M1 mask */ -# define DS3231_ALARM1_A1M1_MASK (1 << DS3231_ALARM1_A1M1_SHIFT) -# define DS3231_ALARM1_A1M1(n) ((uint8_t)(n) << DS3231_ALARM1_A1M1_SHIFT) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +# define DS323X_ALARM1_SECR 0x07 /* Alarm1 seconds register */ +# define DS323X_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ +# define DS323X_ALARM1_SEC_MASK (15 << DS323X_ALARM1_SEC_SHIFT) +# define DS323X_ALARM1_SEC(n) ((uint8_t)(n) << DS323X_ALARM1_SEC_SHIFT) +# define DS323X_ALARM1_10SEC_SHIFT 4 /* Bits 4-6: 10 seconds, range 0-5 */ +# define DS323X_ALARM1_10SEC_MASK (7 << DS323X_ALARM1_10SEC_SHIFT) +# define DS323X_ALARM1_10SEC(n) ((uint8_t)(n) << DS323X_ALARM1_10SEC_SHIFT) +# define DS323X_ALARM1_SEC_BCDMASK (DS323X_ALARM1_SEC_MASK | DS323X_ALARM1_10SEC_MASK) +# define DS323X_ALARM1_A1M1_SHIFT 7 /* Bits 7: A1M1 mask */ +# define DS323X_ALARM1_A1M1_MASK (1 << DS323X_ALARM1_A1M1_SHIFT) +# define DS323X_ALARM1_A1M1(n) ((uint8_t)(n) << DS323X_ALARM1_A1M1_SHIFT) -# define DS3231_ALARM1_MINR 0x08 /* Alarm1 minutes register */ -# define DS3231_ALARM1_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3231_ALARM1_MIN_MASK (15 << DS3231_ALARM1_MIN_SHIFT) -# define DS3231_ALARM1_MIN(n) ((uint8_t)(n) << DS3231_ALARM1_MIN_SHIFT) -# define DS3231_ALARM1_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3231_ALARM1_10MIN_MASK (7 << DS3231_ALARM1_10MIN_SHIFT) -# define DS3231_ALARM1_10MIN(n) ((uint8_t)(n) << DS3231_ALARM1_10MIN_SHIFT) -# define DS3231_ALARM1_MIN_BCDMASK (DS3231_ALARM1_MIN_MASK | DS3231_ALARM1_10MIN_MASK) -# define DS3231_ALARM1_A1M2_SHIFT 7 /* Bits 7: A1M2 mask */ -# define DS3231_ALARM1_A1M2_MASK (1 << DS3231_ALARM1_A1M2_SHIFT) -# define DS3231_ALARM1_A1M2(n) ((uint8_t)(n) << DS3231_ALARM1_A1M2_SHIFT) +# define DS323X_ALARM1_MINR 0x08 /* Alarm1 minutes register */ +# define DS323X_ALARM1_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS323X_ALARM1_MIN_MASK (15 << DS323X_ALARM1_MIN_SHIFT) +# define DS323X_ALARM1_MIN(n) ((uint8_t)(n) << DS323X_ALARM1_MIN_SHIFT) +# define DS323X_ALARM1_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS323X_ALARM1_10MIN_MASK (7 << DS323X_ALARM1_10MIN_SHIFT) +# define DS323X_ALARM1_10MIN(n) ((uint8_t)(n) << DS323X_ALARM1_10MIN_SHIFT) +# define DS323X_ALARM1_MIN_BCDMASK (DS323X_ALARM1_MIN_MASK | DS323X_ALARM1_10MIN_MASK) +# define DS323X_ALARM1_A1M2_SHIFT 7 /* Bits 7: A1M2 mask */ +# define DS323X_ALARM1_A1M2_MASK (1 << DS323X_ALARM1_A1M2_SHIFT) +# define DS323X_ALARM1_A1M2(n) ((uint8_t)(n) << DS323X_ALARM1_A1M2_SHIFT) -# define DS3231_ALARM1_HOURR 0x09 /* Alarm1 hours register */ -# define DS3231_ALARM1_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3231_ALARM1_HOUR_MASK (15 << DS3231_ALARM1_HOUR_SHIFT) -# define DS3231_ALARM1_HOUR(n) ((uint8_t)(n) << DS3231_ALARM1_HOUR_SHIFT) -# define DS3231_ALARM1_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3231_ALARM1_10HOUR12_MASK (1 << DS3231_ALARM1_10HOUR12_SHIFT) -# define DS3231_ALARM1_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR12_SHIFT) -# define DS3231_ALARM1_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3231_ALARM1_10HOUR24_MASK (3 << DS3231_ALARM1_10HOUR24_SHIFT) -# define DS3231_ALARM1_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM1_10HOUR24_SHIFT) -# define DS3231_ALARM1_HOUR12_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR12_MASK) -# define DS3231_ALARM1_HOUR24_BCDMASK (DS3231_ALARM1_HOUR_MASK | DS3231_ALARM1_10HOUR24_MASK) -# define DS3231_ALARM1_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3231_ALARM1_AMPM_MASK (1 << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_AM ((uint8_t)(0) << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_PM ((uint8_t)(1) << DS3231_ALARM1_AMPM_SHIFT) -# define DS3231_ALARM1_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3231_ALARM1_1224_MASK (1 << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_12 ((uint8_t)(0) << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_24 ((uint8_t)(1) << DS3231_ALARM1_1224_SHIFT) -# define DS3231_ALARM1_A1M3_SHIFT 7 /* Bits 7: A1M3 mask */ -# define DS3231_ALARM1_A1M3_MASK (1 << DS3231_ALARM1_A1M3_SHIFT) -# define DS3231_ALARM1_A1M3(n) ((uint8_t)(n) << DS3231_ALARM1_A1M3_SHIFT) +# define DS323X_ALARM1_HOURR 0x09 /* Alarm1 hours register */ +# define DS323X_ALARM1_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS323X_ALARM1_HOUR_MASK (15 << DS323X_ALARM1_HOUR_SHIFT) +# define DS323X_ALARM1_HOUR(n) ((uint8_t)(n) << DS323X_ALARM1_HOUR_SHIFT) +# define DS323X_ALARM1_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS323X_ALARM1_10HOUR12_MASK (1 << DS323X_ALARM1_10HOUR12_SHIFT) +# define DS323X_ALARM1_10HOUR12(n) ((uint8_t)(n) << DS323X_ALARM1_10HOUR12_SHIFT) +# define DS323X_ALARM1_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS323X_ALARM1_10HOUR24_MASK (3 << DS323X_ALARM1_10HOUR24_SHIFT) +# define DS323X_ALARM1_10HOUR24(n) ((uint8_t)(n) << DS323X_ALARM1_10HOUR24_SHIFT) +# define DS323X_ALARM1_HOUR12_BCDMASK (DS323X_ALARM1_HOUR_MASK | DS323X_ALARM1_10HOUR12_MASK) +# define DS323X_ALARM1_HOUR24_BCDMASK (DS323X_ALARM1_HOUR_MASK | DS323X_ALARM1_10HOUR24_MASK) +# define DS323X_ALARM1_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS323X_ALARM1_AMPM_MASK (1 << DS323X_ALARM1_AMPM_SHIFT) +# define DS323X_ALARM1_AM ((uint8_t)(0) << DS323X_ALARM1_AMPM_SHIFT) +# define DS323X_ALARM1_PM ((uint8_t)(1) << DS323X_ALARM1_AMPM_SHIFT) +# define DS323X_ALARM1_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS323X_ALARM1_1224_MASK (1 << DS323X_ALARM1_1224_SHIFT) +# define DS323X_ALARM1_12 ((uint8_t)(0) << DS323X_ALARM1_1224_SHIFT) +# define DS323X_ALARM1_24 ((uint8_t)(1) << DS323X_ALARM1_1224_SHIFT) +# define DS323X_ALARM1_A1M3_SHIFT 7 /* Bits 7: A1M3 mask */ +# define DS323X_ALARM1_A1M3_MASK (1 << DS323X_ALARM1_A1M3_SHIFT) +# define DS323X_ALARM1_A1M3(n) ((uint8_t)(n) << DS323X_ALARM1_A1M3_SHIFT) -# define DS3231_ALARM1_DAYDATER 0x0a /* Alarm1 date / day of the week register */ -# define DS3231_ALARM1_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3231_ALARM1_DAY_MASK (7 << DS3231_ALARM1_DAY_SHIFT) -# define DS3231_ALARM1_DAY(n) ((uint8_t)(n) << DS3231_ALARM1_DAY_SHIFT) -# define DS3231_ALARM1_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3231_ALARM1_DATE_MASK (15 << DS3231_ALARM1_DATE_SHIFT) -# define DS3231_ALARM1_DATE(n) ((uint8_t)(n) << DS3231_ALARM1_DATE_SHIFT) -# define DS3231_ALARM1_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3231_ALARM1_10DATE_MASK (3 << DS3231_ALARM1_10DATE_SHIFT) -# define DS3231_ALARM1_10DATE(n) ((uint8_t)(n) << DS3231_ALARM1_10DATE_SHIFT) -# define DS3231_ALARM1_DATE_BCDMASK (DS3231_ALARM1_DATE_MASK | DS3231_ALARM1_10DATE_MASK) -# define DS3231_ALARM1_DYDT_SHIFT 6 /* Bits 6: DY/DT */ -# define DS3231_ALARM1_DYDT_MASK (1 << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM1_DYDT_SHIFT) -# define DS3231_ALARM1_A1M4_SHIFT 7 /* Bits 7: A1M4 mask */ -# define DS3231_ALARM1_A1M4_MASK (1 << DS3231_ALARM1_A1M4_SHIFT) -# define DS3231_ALARM1_A1M4(n) ((uint8_t)(n) << DS3231_ALARM1_A1M4_SHIFT) +# define DS323X_ALARM1_DAYDATER 0x0a /* Alarm1 date / day of the week register */ +# define DS323X_ALARM1_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS323X_ALARM1_DAY_MASK (7 << DS323X_ALARM1_DAY_SHIFT) +# define DS323X_ALARM1_DAY(n) ((uint8_t)(n) << DS323X_ALARM1_DAY_SHIFT) +# define DS323X_ALARM1_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS323X_ALARM1_DATE_MASK (15 << DS323X_ALARM1_DATE_SHIFT) +# define DS323X_ALARM1_DATE(n) ((uint8_t)(n) << DS323X_ALARM1_DATE_SHIFT) +# define DS323X_ALARM1_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS323X_ALARM1_10DATE_MASK (3 << DS323X_ALARM1_10DATE_SHIFT) +# define DS323X_ALARM1_10DATE(n) ((uint8_t)(n) << DS323X_ALARM1_10DATE_SHIFT) +# define DS323X_ALARM1_DATE_BCDMASK (DS323X_ALARM1_DATE_MASK | DS323X_ALARM1_10DATE_MASK) +# define DS323X_ALARM1_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS323X_ALARM1_DYDT_MASK (1 << DS323X_ALARM1_DYDT_SHIFT) +# define DS323X_ALARM1_DYDT_DATE ((uint8_t)(0) << DS323X_ALARM1_DYDT_SHIFT) +# define DS323X_ALARM1_DYDT_DAY ((uint8_t)(1) << DS323X_ALARM1_DYDT_SHIFT) +# define DS323X_ALARM1_A1M4_SHIFT 7 /* Bits 7: A1M4 mask */ +# define DS323X_ALARM1_A1M4_MASK (1 << DS323X_ALARM1_A1M4_SHIFT) +# define DS323X_ALARM1_A1M4(n) ((uint8_t)(n) << DS323X_ALARM1_A1M4_SHIFT) -# define DS3231_ALARM2_MINR 0x0b /* Alarm2 minutes register */ -# define DS3231_ALARM2_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ -# define DS3231_ALARM2_MIN_MASK (15 << DS3231_ALARM2_MIN_SHIFT) -# define DS3231_ALARM2_MIN(n) ((uint8_t)(n) << DS3231_ALARM2_MIN_SHIFT) -# define DS3231_ALARM2_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ -# define DS3231_ALARM2_10MIN_MASK (7 << DS3231_ALARM2_10MIN_SHIFT) -# define DS3231_ALARM2_10MIN(n) ((uint8_t)(n) << DS3231_ALARM2_10MIN_SHIFT) -# define DS3231_ALARM2_MIN_BCDMASK (DS3231_ALARM2_MIN_MASK | DS3231_ALARM2_10MIN_MASK) -# define DS3231_ALARM2_A2M2_SHIFT 7 /* Bits 7: A2M2 mask */ -# define DS3231_ALARM2_A2M2_MASK (1 << DS3231_ALARM2_A2M2_SHIFT) -# define DS3231_ALARM2_A2M2(n) ((uint8_t)(n) << DS3231_ALARM2_A2M2_SHIFT) +# define DS323X_ALARM2_MINR 0x0b /* Alarm2 minutes register */ +# define DS323X_ALARM2_MIN_SHIFT 0 /* Bits 0-3: Minutes, range 0-9 */ +# define DS323X_ALARM2_MIN_MASK (15 << DS323X_ALARM2_MIN_SHIFT) +# define DS323X_ALARM2_MIN(n) ((uint8_t)(n) << DS323X_ALARM2_MIN_SHIFT) +# define DS323X_ALARM2_10MIN_SHIFT 4 /* Bits 4-6: 10 minutes, range 0-5 */ +# define DS323X_ALARM2_10MIN_MASK (7 << DS323X_ALARM2_10MIN_SHIFT) +# define DS323X_ALARM2_10MIN(n) ((uint8_t)(n) << DS323X_ALARM2_10MIN_SHIFT) +# define DS323X_ALARM2_MIN_BCDMASK (DS323X_ALARM2_MIN_MASK | DS323X_ALARM2_10MIN_MASK) +# define DS323X_ALARM2_A2M2_SHIFT 7 /* Bits 7: A2M2 mask */ +# define DS323X_ALARM2_A2M2_MASK (1 << DS323X_ALARM2_A2M2_SHIFT) +# define DS323X_ALARM2_A2M2(n) ((uint8_t)(n) << DS323X_ALARM2_A2M2_SHIFT) -# define DS3231_ALARM2_HOURR 0x0c /* Alarm2 hours register */ -# define DS3231_ALARM2_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ -# define DS3231_ALARM2_HOUR_MASK (15 << DS3231_ALARM2_HOUR_SHIFT) -# define DS3231_ALARM2_HOUR(n) ((uint8_t)(n) << DS3231_ALARM2_HOUR_SHIFT) -# define DS3231_ALARM2_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ -# define DS3231_ALARM2_10HOUR12_MASK (1 << DS3231_ALARM2_10HOUR12_SHIFT) -# define DS3231_ALARM2_10HOUR12(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR12_SHIFT) -# define DS3231_ALARM2_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ -# define DS3231_ALARM2_10HOUR24_MASK (3 << DS3231_ALARM2_10HOUR24_SHIFT) -# define DS3231_ALARM2_10HOUR24(n) ((uint8_t)(n) << DS3231_ALARM2_10HOUR24_SHIFT) -# define DS3231_ALARM2_HOUR12_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR12_MASK) -# define DS3231_ALARM2_HOUR24_BCDMASK (DS3231_ALARM2_HOUR_MASK | DS3231_ALARM2_10HOUR24_MASK) -# define DS3231_ALARM2_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ -# define DS3231_ALARM2_AMPM_MASK (1 << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_AM ((uint8_t)(0) << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_PM ((uint8_t)(1) << DS3231_ALARM2_AMPM_SHIFT) -# define DS3231_ALARM2_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ -# define DS3231_ALARM2_1224_MASK (1 << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_12 ((uint8_t)(0) << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_24 ((uint8_t)(1) << DS3231_ALARM2_1224_SHIFT) -# define DS3231_ALARM2_A2M3_SHIFT 7 /* Bits 7: A2M3 mask */ -# define DS3231_ALARM2_A2M3_MASK (1 << DS3231_ALARM2_A2M3_SHIFT) -# define DS3231_ALARM2_A2M3(n) ((uint8_t)(n) << DS3231_ALARM2_A2M3_SHIFT) +# define DS323X_ALARM2_HOURR 0x0c /* Alarm2 hours register */ +# define DS323X_ALARM2_HOUR_SHIFT 0 /* Bits 0-3: Hours, range 0-9 */ +# define DS323X_ALARM2_HOUR_MASK (15 << DS323X_ALARM2_HOUR_SHIFT) +# define DS323X_ALARM2_HOUR(n) ((uint8_t)(n) << DS323X_ALARM2_HOUR_SHIFT) +# define DS323X_ALARM2_10HOUR12_SHIFT 4 /* Bit 4: 10 hours, range 0-1 */ +# define DS323X_ALARM2_10HOUR12_MASK (1 << DS323X_ALARM2_10HOUR12_SHIFT) +# define DS323X_ALARM2_10HOUR12(n) ((uint8_t)(n) << DS323X_ALARM2_10HOUR12_SHIFT) +# define DS323X_ALARM2_10HOUR24_SHIFT 4 /* Bits 4-5: 10 hours, range 0-2 */ +# define DS323X_ALARM2_10HOUR24_MASK (3 << DS323X_ALARM2_10HOUR24_SHIFT) +# define DS323X_ALARM2_10HOUR24(n) ((uint8_t)(n) << DS323X_ALARM2_10HOUR24_SHIFT) +# define DS323X_ALARM2_HOUR12_BCDMASK (DS323X_ALARM2_HOUR_MASK | DS323X_ALARM2_10HOUR12_MASK) +# define DS323X_ALARM2_HOUR24_BCDMASK (DS323X_ALARM2_HOUR_MASK | DS323X_ALARM2_10HOUR24_MASK) +# define DS323X_ALARM2_AMPM_SHIFT 5 /* Bit 5: AM/PM Indication */ +# define DS323X_ALARM2_AMPM_MASK (1 << DS323X_ALARM2_AMPM_SHIFT) +# define DS323X_ALARM2_AM ((uint8_t)(0) << DS323X_ALARM2_AMPM_SHIFT) +# define DS323X_ALARM2_PM ((uint8_t)(1) << DS323X_ALARM2_AMPM_SHIFT) +# define DS323X_ALARM2_1224_SHIFT 6 /* Bit 6: 12/24 Indication */ +# define DS323X_ALARM2_1224_MASK (1 << DS323X_ALARM2_1224_SHIFT) +# define DS323X_ALARM2_12 ((uint8_t)(0) << DS323X_ALARM2_1224_SHIFT) +# define DS323X_ALARM2_24 ((uint8_t)(1) << DS323X_ALARM2_1224_SHIFT) +# define DS323X_ALARM2_A2M3_SHIFT 7 /* Bits 7: A2M3 mask */ +# define DS323X_ALARM2_A2M3_MASK (1 << DS323X_ALARM2_A2M3_SHIFT) +# define DS323X_ALARM2_A2M3(n) ((uint8_t)(n) << DS323X_ALARM2_A2M3_SHIFT) -# define DS3231_ALARM2_DAYDATER 0x0d /* Alarm2 date / day of the week register */ -# define DS3231_ALARM2_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ -# define DS3231_ALARM2_DAY_MASK (7 << DS3231_ALARM2_DAY_SHIFT) -# define DS3231_ALARM2_DAY(n) ((uint8_t)(n) << DS3231_ALARM2_DAY_SHIFT) -# define DS3231_ALARM2_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ -# define DS3231_ALARM2_DATE_MASK (15 << DS3231_ALARM2_DATE_SHIFT) -# define DS3231_ALARM2_DATE(n) ((uint8_t)(n) << DS3231_ALARM2_DATE_SHIFT) -# define DS3231_ALARM2_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ -# define DS3231_ALARM2_10DATE_MASK (3 << DS3231_ALARM2_10DATE_SHIFT) -# define DS3231_ALARM2_10DATE(n) ((uint8_t)(n) << DS3231_ALARM2_10DATE_SHIFT) -# define DS3231_ALARM2_DATE_BCDMASK (DS3231_ALARM2_DATE_MASK | DS3231_ALARM2_10DATE_MASK) -# define DS3231_ALARM2_DYDT_SHIFT 6 /* Bits 6: DY/DT */ -# define DS3231_ALARM2_DYDT_MASK (1 << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_DYDT_DATE ((uint8_t)(0) << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_DYDT_DAY ((uint8_t)(1) << DS3231_ALARM2_DYDT_SHIFT) -# define DS3231_ALARM2_A2M4_SHIFT 7 /* Bits 7: A2M4 mask */ -# define DS3231_ALARM2_A2M4_MASK (1 << DS3231_ALARM2_A2M4_SHIFT) -# define DS3231_ALARM2_A2M4(n) ((uint8_t)(n) << DS3231_ALARM2_A2M4_SHIFT) +# define DS323X_ALARM2_DAYDATER 0x0d /* Alarm2 date / day of the week register */ +# define DS323X_ALARM2_DAY_SHIFT 0 /* Bits 0-3: Day of the week, range 1-7 */ +# define DS323X_ALARM2_DAY_MASK (7 << DS323X_ALARM2_DAY_SHIFT) +# define DS323X_ALARM2_DAY(n) ((uint8_t)(n) << DS323X_ALARM2_DAY_SHIFT) +# define DS323X_ALARM2_DATE_SHIFT 0 /* Bits 0-3: Days, range 0-9 */ +# define DS323X_ALARM2_DATE_MASK (15 << DS323X_ALARM2_DATE_SHIFT) +# define DS323X_ALARM2_DATE(n) ((uint8_t)(n) << DS323X_ALARM2_DATE_SHIFT) +# define DS323X_ALARM2_10DATE_SHIFT 4 /* Bits 4-5: 10 days, range 0-5 */ +# define DS323X_ALARM2_10DATE_MASK (3 << DS323X_ALARM2_10DATE_SHIFT) +# define DS323X_ALARM2_10DATE(n) ((uint8_t)(n) << DS323X_ALARM2_10DATE_SHIFT) +# define DS323X_ALARM2_DATE_BCDMASK (DS323X_ALARM2_DATE_MASK | DS323X_ALARM2_10DATE_MASK) +# define DS323X_ALARM2_DYDT_SHIFT 6 /* Bits 6: DY/DT */ +# define DS323X_ALARM2_DYDT_MASK (1 << DS323X_ALARM2_DYDT_SHIFT) +# define DS323X_ALARM2_DYDT_DATE ((uint8_t)(0) << DS323X_ALARM2_DYDT_SHIFT) +# define DS323X_ALARM2_DYDT_DAY ((uint8_t)(1) << DS323X_ALARM2_DYDT_SHIFT) +# define DS323X_ALARM2_A2M4_SHIFT 7 /* Bits 7: A2M4 mask */ +# define DS323X_ALARM2_A2M4_MASK (1 << DS323X_ALARM2_A2M4_SHIFT) +# define DS323X_ALARM2_A2M4(n) ((uint8_t)(n) << DS3231_ALARM2_A2M4_SHIFT) -# define DS3231_CR 0x0e /* Control register */ -# define DS3231_CR_A1IE (1 << 0) /* Bit 0: Alarm 1 interrupt enable */ -# define DS3231_CR_A2IE (1 << 1) /* Bit 1: Alarm 2 interrupt enable */ -# define DS3231_CR_INTCN (1 << 2) /* Bit 2: Interrupt control */ -# define DS3231_CR_RS_SHIFT (3) /* Bits 3-4: Rate selection */ -# define DS3231_CR_RS_MASK (3 << DS3231_CR_RS_SHIFT) -# define DS3231_CR_RS_1HZ (0 << DS3231_CR_RS_SHIFT) /* 1Hz */ -# define DS3231_CR_RS_1KHZ (1 << DS3231_CR_RS_SHIFT) /* 1.024kHz */ -# define DS3231_CR_RS_4KHZ (2 << DS3231_CR_RS_SHIFT) /* 4.096kHz */ -# define DS3231_CR_RS_8KHZ (3 << DS3231_CR_RS_SHIFT) /* 8.192kHz */ -# define DS3231_CR_CONV (1 << 5) /* Bit 5: Convert temperature */ -# define DS3231_CR_BBSQW (1 << 6) /* Bit 6: Battery backed square wave enable */ -# define DS3231_CR_EOSC (1 << 7) /* Bit 7: Enable oscillator */ +# define DS323X_CR 0x0e /* Control register */ +# define DS323X_CR_A1IE (1 << 0) /* Bit 0: Alarm 1 interrupt enable */ +# define DS323X_CR_A2IE (1 << 1) /* Bit 1: Alarm 2 interrupt enable */ +# define DS323X_CR_INTCN (1 << 2) /* Bit 2: Interrupt control */ +# define DS323X_CR_RS_SHIFT (3) /* Bits 3-4: Rate selection */ +# define DS323X_CR_RS_MASK (3 << DS323X_CR_RS_SHIFT) +# define DS323X_CR_RS_1HZ (0 << DS323X_CR_RS_SHIFT) /* 1Hz */ +# define DS323X_CR_RS_1KHZ (1 << DS323X_CR_RS_SHIFT) /* 1.024kHz */ +# define DS323X_CR_RS_4KHZ (2 << DS323X_CR_RS_SHIFT) /* 4.096kHz */ +# define DS323X_CR_RS_8KHZ (3 << DS323X_CR_RS_SHIFT) /* 8.192kHz */ +# define DS323X_CR_CONV (1 << 5) /* Bit 5: Convert temperature */ +# define DS323X_CR_BBSQW (1 << 6) /* Bit 6: Battery backed square wave enable */ +# define DS323X_CR_EOSC (1 << 7) /* Bit 7: Enable oscillator */ -# define DS3231_CSR 0x0f /* Control/status register */ -# define DS3231_CSR_A1F (1 << 0) /* Bit 0: Alarm 1 flag */ -# define DS3231_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ -# define DS3231_CSR_BSY (1 << 2) /* Bit 2: Busy */ -# define DS3231_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ -# define DS3231_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ +# define DS323X_CSR 0x0f /* Control/status register */ +# define DS323X_CSR_A1F (1 << 0) /* Bit 0: Alarm 1 flag */ +# define DS323X_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ +# define DS323X_CSR_BSY (1 << 2) /* Bit 2: Busy */ +# define DS323X_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ +# ifdef CONFIG_RTC_DS3234 +# define DS3234_CSR_CRATE_SHIFT (4) /* Bits 4-5: Conversion rate */ +# define DS3234_CSR_CRATE_MASK (3 << DS3234_CSR_CRATE_SHIFT) +# define DS3234_CSR_CRATE_64SEC (0 << DS3234_CSR_CRATE_SHIFT) +# define DS3234_CSR_CRATE_128SEC (1 << DS3234_CSR_CRATE_SHIFT) +# define DS3234_CSR_CRATE_256SEC (2 << DS3234_CSR_CRATE_SHIFT) +# define DS3234_CSR_CRATE_512SEC (3 << DS3234_CSR_CRATE_SHIFT) +# define DS3234_CSR_BB32KHZ (1 << 6) /* Bit 6: Battery-Backed 32kHz Output */ +# endif +# define DS323X_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ -# define DS3231_AGINGR 0x10 /* Aging offset register (8-bit, 2's complement) */ +# define DS323X_AGINGR 0x10 /* Aging offset register (8-bit, 2's complement) */ -# define DS3231_TMPMR 0x11 /* MSB of temp register (8-bit, 2's complement) */ +# define DS323X_TMPMR 0x11 /* MSB of temp register (8-bit, 2's complement) */ -# define DS3231_TMPLR 0x12 /* LSB of temp register (2-bits) */ -# define DS3231_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ -#endif +# define DS323X_TMPLR 0x12 /* LSB of temp register (2-bits) */ +# define DS323X_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ +#endif /* CONFIG_RTC_DS3231 || CONFIG_RTC_DS3234 */ + +#ifdef CONFIG_RTC_DS3234 +# define DS3234_SRAM_ADDRR 0x98 /* SRAM address register */ +# define DS3234_SRAM_DATAR 0x99 /* SRAM data register */ +#endif /* CONFIG_RTC_DS3234 */ #endif /* __DRIVERS_TIMERS_DS3231_H */ -- GitLab From 9a1ca0d4899b19ba9188fea80c44294a83db3e70 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 19:26:09 -0600 Subject: [PATCH 329/858] Add support for DS1302 and DS3232 RTC chips --- configs | 2 +- drivers/timers/Kconfig | 12 ++++++++- drivers/timers/ds3231.h | 55 +++++++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/configs b/configs index 388caf6346..2a5172fbb3 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 388caf63466f447ce0fc6924dc50e79b9ba70cf8 +Subproject commit 2a5172fbb37ada3f8119c99af34a1bbf70120ee3 diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index c42ee79df7..333b65d2aa 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -133,7 +133,7 @@ config RTC_EXTERNAL early in the boot sequence. config RTC_DSXXXX - bool "DS1307/DS323x RTC Driver" + bool "DS130x/DS323x RTC Driver" default n select I2C select I2C_TRANSFER @@ -148,6 +148,11 @@ choice prompt "Maxim Integrated RTC" default RTC_DS3231 +config RTC_DS1302 + bool "DS1302" + ---help--- + Enables support for the Maxim Integrated DS1307 serial RTC timer. + config RTC_DS1307 bool "DS1307" ---help--- @@ -158,6 +163,11 @@ config RTC_DS3231 ---help--- Enables support for the Maxim Integrated DS3231 I2C RTC timer. +config RTC_DS3232 + bool "DS3232" + ---help--- + Enables support for the Maxim Integrated DS3232 I2C RTC timer. + config RTC_DS3234 bool "DS3234" depends on EXPERIMENTAL diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index e1c238484c..6e88f7b71e 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -54,8 +54,8 @@ # define DSXXXX_TIME_10SEC_MASK (7 << DSXXXX_TIME_10SEC_SHIFT) # define DSXXXX_TIME_10SEC(n) ((uint8_t)(n) << DSXXXX_TIME_10SEC_SHIFT) # define DSXXXX_TIME_SEC_BCDMASK (DSXXXX_TIME_SEC_MASK | DSXXXX_TIME_10SEC_MASK) -#ifdef CONFIG_RTC_DS1307 -# define DS1307_TIME_CH (1 << 7) /* Bit 7: Clock halt */ +#if defined(CONFIG_RTC_DS1302) || defined(CONFIG_RTC_DS1307) +# define DS130x_TIME_CH (1 << 7) /* Bit 7: Clock halt */ #endif #define DSXXXX_TIME_MINR 0x01 /* Minutes register */ @@ -110,7 +110,7 @@ # define DSXXXX_TIME_10MONTH_MASK (1 << DSXXXX_TIME_10MONTH_SHIFT) # define DSXXXX_TIME_10MONTH(n) ((uint8_t)(n) << DSXXXX_TIME_10MONTH_SHIFT) # define DSXXXX_TIME_MONTH_BCDMASK (DSXXXX_TIME_MONTH_MASK | DSXXXX_TIME_10MONTH_MASK) -#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3232) || defined(CONFIG_RTC_DS3234) # define DS323X_TIME_CENTURY_SHIFT 7 /* Bit 7: Century Indication */ # define DS323X_TIME_CENTURY_MASK (1 << DS323X_TIME_CENTURY_SHIFT) # define DS323X_TIME_1900 ((uint8_t)(0) << DS323X_TIME_CENTURY_SHIFT) @@ -126,6 +126,31 @@ # define DSXXXX_TIME_10YEAR(n) ((uint8_t)(n) << DSXXXX_TIME_10YEAR_SHIFT) # define DSXXXX_TIME_YEAR_BCDMASK (DSXXXX_TIME_YEAR_MASK | DSXXXX_TIME_10YEAR_MASK) +#ifdef CONFIG_RTC_DS1302 +# define DS1302_CR 0x07 /* Control register */ +# define DS1302_CR_WP (1 << 7) /* Bit 7: Write protect */ + +# define DS1302_TCR 0x08 /* Trickle charge register */ +# define DS1302_TCR_RS_SHIFT (0) /* Bits 0-1: Range select */ +# define DS1302_TCR_RS_MASK (3 << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_RS(n) ((uint8_t)(n) << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_DS_SHIFT (4) /* Bits 2-3: Diode select */ +# define DS1302_TCR_DS_MASK (3 << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_DS(n) ((uint8_t)(n) << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_TCS_SHIFT (4) /* Bits 4-7: Trickle charge select */ +# define DS1302_TCR_TCS_MASK (15 << DS1302_TCR_TCS_SHIFT) +# define DS1302_TCR_TCS(n) ((uint8_t)(n) << DS1302_TCR_TCS_SHIFT) + +# define DS1302_TCR_DISABLED (DS1302_TCR_RS(0) | define DS1302_TCR_DS(0) | define DS1302_TCR_TCS(0)) +# define DS1302_TCR_1DIODE_2OHM (DS1302_TCR_RS(1) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_1DIODE_4OHM (DS1302_TCR_RS(2) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_1DIODE_8OHM (DS1302_TCR_RS(3) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_2OHM (DS1302_TCR_RS(1) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_4OHM (DS1302_TCR_RS(2) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_8OHM (DS1302_TCR_RS(3) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_INIT (DS1302_TCR_RS(0) | define DS1302_TCR_DS(3) | define DS1302_TCR_TCS(5)) +#endif + #ifdef CONFIG_RTC_DS1307 # define DS1307_CR 0x07 /* Control register */ # define DS1307_CR_RS_SHIFT (3) /* Bits 0-1: Rate selection */ @@ -139,7 +164,7 @@ # define DS1307_RAM_BASE 0x08 /* 0x08-0x3f: 56x8 RAM */ #endif -#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3232) || defined(CONFIG_RTC_DS3234) # define DS323X_ALARM1_SECR 0x07 /* Alarm1 seconds register */ # define DS323X_ALARM1_SEC_SHIFT 0 /* Bits 0-3: Seconds, range 0-9 */ # define DS323X_ALARM1_SEC_MASK (15 << DS323X_ALARM1_SEC_SHIFT) @@ -281,14 +306,14 @@ # define DS323X_CSR_A2F (1 << 1) /* Bit 1: Alarm 2 flag */ # define DS323X_CSR_BSY (1 << 2) /* Bit 2: Busy */ # define DS323X_CSR_EN32kHz (1 << 3) /* Bit 3: Enable 32kHz output */ -# ifdef CONFIG_RTC_DS3234 -# define DS3234_CSR_CRATE_SHIFT (4) /* Bits 4-5: Conversion rate */ -# define DS3234_CSR_CRATE_MASK (3 << DS3234_CSR_CRATE_SHIFT) -# define DS3234_CSR_CRATE_64SEC (0 << DS3234_CSR_CRATE_SHIFT) -# define DS3234_CSR_CRATE_128SEC (1 << DS3234_CSR_CRATE_SHIFT) -# define DS3234_CSR_CRATE_256SEC (2 << DS3234_CSR_CRATE_SHIFT) -# define DS3234_CSR_CRATE_512SEC (3 << DS3234_CSR_CRATE_SHIFT) -# define DS3234_CSR_BB32KHZ (1 << 6) /* Bit 6: Battery-Backed 32kHz Output */ +# if defined(CONFIG_RTC_DS3232) || defined(CONFIG_RTC_DS3234) +# define DS323x_CSR_CRATE_SHIFT (4) /* Bits 4-5: Conversion rate */ +# define DS323x_CSR_CRATE_MASK (3 << DS323x_CSR_CRATE_SHIFT) +# define DS323x_CSR_CRATE_64SEC (0 << DS323x_CSR_CRATE_SHIFT) +# define DS323x_CSR_CRATE_128SEC (1 << DS323x_CSR_CRATE_SHIFT) +# define DS323x_CSR_CRATE_256SEC (2 << DS323x_CSR_CRATE_SHIFT) +# define DS323x_CSR_CRATE_512SEC (3 << DS323x_CSR_CRATE_SHIFT) +# define DS323x_CSR_BB32KHZ (1 << 6) /* Bit 6: Battery-Backed 32kHz Output */ # endif # define DS323X_CSR_OSF (1 << 7) /* Bit 7: Oscillator stop flag */ @@ -298,7 +323,11 @@ # define DS323X_TMPLR 0x12 /* LSB of temp register (2-bits) */ # define DS323X_TMPLR_MASK 0xc0 /* Bits 6-7: LSB of temp register (2-bits) */ -#endif /* CONFIG_RTC_DS3231 || CONFIG_RTC_DS3234 */ +#endif /* CONFIG_RTC_DS3231 || CONFIG_RTC_DS3232 || CONFIG_RTC_DS3234 */ + +#ifdef CONFIG_RTC_DS3232 +# define DS3232_SRAM_BASE 0x14 /* 0x14-0xff: SRAM */ +#endif /* CONFIG_RTC_DS3232 */ #ifdef CONFIG_RTC_DS3234 # define DS3234_SRAM_ADDRR 0x98 /* SRAM address register */ -- GitLab From b951533514f5c7cbfbce6888ac17ff1c5248152c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 19:31:52 -0600 Subject: [PATCH 330/858] DS3232 not DS3234 --- drivers/timers/ds3231.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index a368a71648..5466c99f33 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -382,7 +382,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) tmp = rtc_bcd2bin(buffer[6] & DSXXXX_TIME_YEAR_BCDMASK); -#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3232) if ((buffer[5] & DS323X_TIME_CENTURY_MASK) == DS323X_TIME_1900) { tp->tm_year = tmp; @@ -495,7 +495,7 @@ int up_rtc_settime(FAR const struct timespec *tp) buffer[5] = rtc_bin2bcd(newtm.tm_mday); -#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3234) +#if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3232) /* Handle years in the 20th vs the 21st century */ if (newtm.tm_year < 100) -- GitLab From 9af0ee7fdbbe1c5b7c6cb074aec32d9fa2ba9774 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Nov 2015 19:43:01 -0600 Subject: [PATCH 331/858] DS323x: Costmetic cleanup --- drivers/timers/ds3231.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index 6e88f7b71e..8df61d3dee 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -131,24 +131,32 @@ # define DS1302_CR_WP (1 << 7) /* Bit 7: Write protect */ # define DS1302_TCR 0x08 /* Trickle charge register */ -# define DS1302_TCR_RS_SHIFT (0) /* Bits 0-1: Range select */ +# define DS1302_TCR_RS_SHIFT (0) /* Bits 0-1: Reistance select */ # define DS1302_TCR_RS_MASK (3 << DS1302_TCR_RS_SHIFT) # define DS1302_TCR_RS(n) ((uint8_t)(n) << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_RS_DISABLED (0 << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_RS_2OHM (1 << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_RS_4OHM (2 << DS1302_TCR_RS_SHIFT) +# define DS1302_TCR_RS_8OHM (3 << DS1302_TCR_RS_SHIFT) # define DS1302_TCR_DS_SHIFT (4) /* Bits 2-3: Diode select */ # define DS1302_TCR_DS_MASK (3 << DS1302_TCR_DS_SHIFT) # define DS1302_TCR_DS(n) ((uint8_t)(n) << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_DS_DISABLED (0 << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_DS_1DIODE (1 << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_DS_2DIODE (2 << DS1302_TCR_DS_SHIFT) +# define DS1302_TCR_DS_DISABLED_2 (3 << DS1302_TCR_DS_SHIFT) # define DS1302_TCR_TCS_SHIFT (4) /* Bits 4-7: Trickle charge select */ # define DS1302_TCR_TCS_MASK (15 << DS1302_TCR_TCS_SHIFT) # define DS1302_TCR_TCS(n) ((uint8_t)(n) << DS1302_TCR_TCS_SHIFT) -# define DS1302_TCR_DISABLED (DS1302_TCR_RS(0) | define DS1302_TCR_DS(0) | define DS1302_TCR_TCS(0)) -# define DS1302_TCR_1DIODE_2OHM (DS1302_TCR_RS(1) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_1DIODE_4OHM (DS1302_TCR_RS(2) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_1DIODE_8OHM (DS1302_TCR_RS(3) | define DS1302_TCR_DS(1) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_2DIODE_2OHM (DS1302_TCR_RS(1) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_2DIODE_4OHM (DS1302_TCR_RS(2) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_2DIODE_8OHM (DS1302_TCR_RS(3) | define DS1302_TCR_DS(2) | define DS1302_TCR_TCS(10)) -# define DS1302_TCR_INIT (DS1302_TCR_RS(0) | define DS1302_TCR_DS(3) | define DS1302_TCR_TCS(5)) +# define DS1302_TCR_DISABLED (DS1302_TCR_RS_DISABLED | DS1302_TCR_DS_DISABLED | define DS1302_TCR_TCS(0)) +# define DS1302_TCR_1DIODE_2OHM (DS1302_TCR_RS_2OHM | DS1302_TCR_DS_1DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_1DIODE_4OHM (DS1302_TCR_RS_4OHM | DS1302_TCR_DS_1DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_1DIODE_8OHM (DS1302_TCR_RS_8OHM | DS1302_TCR_DS_1DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_2OHM (DS1302_TCR_RS_2OHM | DS1302_TCR_DS_2DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_4OHM (DS1302_TCR_RS_4OHM | DS1302_TCR_DS_2DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_2DIODE_8OHM (DS1302_TCR_RS_8OHM | DS1302_TCR_DS_2DIODE | define DS1302_TCR_TCS(10)) +# define DS1302_TCR_INIT (DS1302_TCR_RS_DISABLED | DS1302_TCR_DS_DISABLED_2 | define DS1302_TCR_TCS(5)) #endif #ifdef CONFIG_RTC_DS1307 -- GitLab From b60c2519d7bac1d70379f0b437ae5f2aa36eece6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 07:13:16 -0600 Subject: [PATCH 332/858] arch.h: Update some comments and conditional compilation --- include/nuttx/arch.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 4c070a7d1a..0c79bd292c 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1768,8 +1768,14 @@ size_t up_check_intstack_remain(void); * Name: up_rtcinitialize * * Description: - * Initialize the hardware RTC per the selected configuration. This - * function is called once during the OS initialization sequence + * Initialize the builtin, MCU hardware RTC per the selected + * configuration. This function is called once very early in the OS + * initialization sequence + * + * NOTE that initialization of external RTC hardware that depends on the + * availability of OS resources (such as SPI or I2C) must be deferred + * until the system has fully booted. Other, RTC-specific initialization + * functions are used in that case. * * Input Parameters: * None @@ -1779,7 +1785,7 @@ size_t up_check_intstack_remain(void); * ****************************************************************************/ -#ifdef CONFIG_RTC +#if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL) int up_rtcinitialize(void); #endif -- GitLab From d30b73be82659fe9a4c9aeb8b1454fd60ead8b8d Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Fri, 20 Nov 2015 07:34:07 -0600 Subject: [PATCH 333/858] W25: Add support for byte write mode. From Ken Petit --- ChangeLog | 5 ++ drivers/mtd/w25.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) diff --git a/ChangeLog b/ChangeLog index e1e1c13306..c903285da5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11124,4 +11124,9 @@ bytes in a single sector. Logical sectors 1 and 2 were simply not being allocated and then the read_sector and write_sector routinesi were failing. From Ken Petit (2015-11-18). + * drivers/timers/ds3231.c: Untested support for DS1302 and DS3232. + Also definitions for the DS3234, but that is an unsupported SPI RTC + (2015-11-19). + * drivers/mtd/w25.c: Add support for byte write mode. From Ken Peit + (2015-11-20). diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index 31dbe6d1fe..df5ec83df6 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -273,6 +273,10 @@ static ssize_t w25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, static ssize_t w25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, FAR uint8_t *buffer); static int w25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); +#if defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) +static ssize_t w25_write(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR const uint8_t *buffer); +#endif /************************************************************************************ * Private Data @@ -755,6 +759,53 @@ static void w25_pagewrite(struct w25_dev_s *priv, FAR const uint8_t *buffer, } #endif +/************************************************************************************ + * Name: w25_bytewrite + ************************************************************************************/ + +#if defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) +static inline void w25_bytewrite(struct w25_dev_s *priv, FAR const uint8_t *buffer, + off_t offset, uint16_t count) +{ + fvdbg("offset: %08lx count:%d\n", (long)offset, count); + + /* Wait for any preceding write to complete. We could simplify things by + * perform this wait at the end of each write operation (rather than at + * the beginning of ALL operations), but have the wait first will slightly + * improve performance. + */ + + w25_waitwritecomplete(priv); + + /* Enable the write access to the FLASH */ + + w25_wren(priv); + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Page Program (PP)" command */ + + (void)SPI_SEND(priv->spi, W25_PP); + + /* Send the page offset high byte first. */ + + (void)SPI_SEND(priv->spi, (offset >> 16) & 0xff); + (void)SPI_SEND(priv->spi, (offset >> 8) & 0xff); + (void)SPI_SEND(priv->spi, offset & 0xff); + + /* Then write the specified number of bytes */ + + SPI_SNDBLOCK(priv->spi, buffer, count); + + /* Deselect the FLASH: Chip Select high */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + fvdbg("Written\n"); +} +#endif /* defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) */ + /************************************************************************************ * Name: w25_cacheflush ************************************************************************************/ @@ -1043,6 +1094,76 @@ static ssize_t w25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, return nbytes; } +/************************************************************************************ + * Name: w25_write + ************************************************************************************/ + +#if defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) +static ssize_t w25_write(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR const uint8_t *buffer) +{ + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + int startpage; + int endpage; + int count; + int index; + int bytestowrite; + + fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes); + + /* We must test if the offset + count crosses one or more pages + * and perform individual writes. The devices can only write in + * page increments. + */ + + startpage = offset / W25_PAGE_SIZE; + endpage = (offset + nbytes) / W25_PAGE_SIZE; + + if (startpage == endpage) + { + /* All bytes within one programmable page. Just do the write. */ + + w25_bytewrite(priv, buffer, offset, nbytes); + } + else + { + /* Write the 1st partial-page */ + + count = nbytes; + bytestowrite = W25_PAGE_SIZE - (offset & (W25_PAGE_SIZE-1)); + w25_bytewrite(priv, buffer, offset, bytestowrite); + + /* Update offset and count */ + + offset += bytestowrite; + count -= bytestowrite; + index = bytestowrite; + + /* Write full pages */ + + while (count >= W25_PAGE_SIZE) + { + w25_bytewrite(priv, &buffer[index], offset, W25_PAGE_SIZE); + + /* Update offset and count */ + + offset += W25_PAGE_SIZE; + count -= W25_PAGE_SIZE; + index += W25_PAGE_SIZE; + } + + /* Now write any partial page at the end */ + + if (count > 0) + { + w25_bytewrite(priv, &buffer[index], offset, count); + } + } + + return nbytes; +} +#endif /* defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) */ + /************************************************************************************ * Name: w25_ioctl ************************************************************************************/ @@ -1147,6 +1268,9 @@ FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *spi) priv->mtd.bwrite = w25_bwrite; priv->mtd.read = w25_read; priv->mtd.ioctl = w25_ioctl; +#if defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY) + priv->mtd.write = w25_write; +#endif priv->spi = spi; /* Deselect the FLASH */ -- GitLab From 4b29bcee7ffe01b48d910f5a65b7f434dc9126e3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 08:27:52 -0600 Subject: [PATCH 334/858] Rename up_rtcinitialize to up_rtc_initialize so that it looks like other RTC interfaces --- ChangeLog | 2 +- Documentation | 2 +- ReleaseNotes | 2 +- arch | 2 +- include/nuttx/arch.h | 4 ++-- sched/clock/clock_initialize.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c903285da5..24b20e48c9 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10045,7 +10045,7 @@ stm32_rtcc.c, stm32_rtcounter.c, and stm32f*_rcc.c: The STM32F4Discovery board doesn't come with a Low speed external oscillator so the default LSE source for the RTC doesn't work. In - stm32_rtcc.c the up_rtcinitialize() logic doesn't work with the LSI. + stm32_rtcc.c the up_rtc_initialize() logic doesn't work with the LSI. The check on RTC_MAGIC on the BK0R register lead to rtc_setup() call that rightfully enables the lsi clock; but the next times, when the rtc is already setup, the rtc_resume() call does NOT start the lsi diff --git a/Documentation b/Documentation index ffe506af46..4025464640 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit ffe506af460b9828138ee395b7a3b7ab8ff9ef73 +Subproject commit 402546464095015a48662c75a13861a6100153fd diff --git a/ReleaseNotes b/ReleaseNotes index 1e5eb013d7..60634816ac 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -8777,7 +8777,7 @@ detailed bugfix information): Jussi Kivilinna. - STM32 RTC and clock control: The STM32F4Discovery board doesn't come with a Low speed external oscillator so the default LSE source - for the RTC doesn't work. In stm32_rtcc.c the up_rtcinitialize() + for the RTC doesn't work. In stm32_rtcc.c the up_rtc_initialize() logic doesn't work with the LSI. The check on RTC_MAGIC on the BK0R register lead to rtc_setup() call that rightfully enables the LSI clock; but the next times, when the rtc is already setup, the diff --git a/arch b/arch index a3bf280f61..676240da11 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a3bf280f61d4670019587c67526ea076af134f89 +Subproject commit 676240da1156f13127dea95216f164d6ab4a766b diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 0c79bd292c..3a03216d89 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1765,7 +1765,7 @@ size_t up_check_intstack_remain(void); ****************************************************************************/ /**************************************************************************** - * Name: up_rtcinitialize + * Name: up_rtc_initialize * * Description: * Initialize the builtin, MCU hardware RTC per the selected @@ -1786,7 +1786,7 @@ size_t up_check_intstack_remain(void); ****************************************************************************/ #if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL) -int up_rtcinitialize(void); +int up_rtc_initialize(void); #endif /************************************************************************************ diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 11d889f6d0..507d61c772 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -206,7 +206,7 @@ void clock_initialize(void) * must be deferred until the system has booted. */ - up_rtcinitialize(); + up_rtc_initialize(); #endif /* Initialize the time value to match the RTC */ -- GitLab From db2fe45666e7d0aba3b151631425f5d5fc8784b6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 09:55:18 -0600 Subject: [PATCH 335/858] Update some comments --- Documentation | 2 +- drivers/mtd/skeleton.c | 5 +++-- drivers/timers/ds3231.h | 4 ++-- include/nuttx/arch.h | 10 +++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Documentation b/Documentation index 4025464640..bc3e253711 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 402546464095015a48662c75a13861a6100153fd +Subproject commit bc3e2537116a608a90b89e9e1a7b2c72593d8c58 diff --git a/drivers/mtd/skeleton.c b/drivers/mtd/skeleton.c index 1ccc1d879b..dc40675620 100644 --- a/drivers/mtd/skeleton.c +++ b/drivers/mtd/skeleton.c @@ -100,7 +100,7 @@ static struct skel_dev_s g_skeldev = skel_bwrite, skel_read, #ifdef CONFIG_MTD_BYTE_WRITE - skel_write, + skel_write, /* Should be NULL if the byte write method is not supported */ #endif skel_ioctl }, @@ -226,7 +226,8 @@ static ssize_t skel_read(FAR struct mtd_dev_s *dev, off_t offset, * * Description: * Some FLASH parts have the ability to write an arbitrary number of - * bytes to an arbitrary offset on the device. + * bytes to an arbitrary offset on the device. This method should be + * implement only for devices that support such access. * ****************************************************************************/ diff --git a/drivers/timers/ds3231.h b/drivers/timers/ds3231.h index 8df61d3dee..737e0b48f2 100644 --- a/drivers/timers/ds3231.h +++ b/drivers/timers/ds3231.h @@ -169,7 +169,7 @@ # define DS1307_CR_RS_32KHZ (3 << DS1307_CR_RS_SHIFT) /* 32.768kHz */ # define DS1307_CR_SQWE (1 << 4) /* Bit 4: Square wave enable */ # define DS1307_CR_OUT (1 << 7) /* Bit 7: Output control */ -# define DS1307_RAM_BASE 0x08 /* 0x08-0x3f: 56x8 RAM */ +# define DS1307_RAM_BASER 0x08 /* 0x08-0x3f: 56x8 RAM */ #endif #if defined(CONFIG_RTC_DS3231) || defined(CONFIG_RTC_DS3232) || defined(CONFIG_RTC_DS3234) @@ -334,7 +334,7 @@ #endif /* CONFIG_RTC_DS3231 || CONFIG_RTC_DS3232 || CONFIG_RTC_DS3234 */ #ifdef CONFIG_RTC_DS3232 -# define DS3232_SRAM_BASE 0x14 /* 0x14-0xff: SRAM */ +# define DS3232_SRAM_BASER 0x14 /* 0x14-0xff: SRAM */ #endif /* CONFIG_RTC_DS3232 */ #ifdef CONFIG_RTC_DS3234 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 3a03216d89..b3aa8d6631 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1770,7 +1770,7 @@ size_t up_check_intstack_remain(void); * Description: * Initialize the builtin, MCU hardware RTC per the selected * configuration. This function is called once very early in the OS - * initialization sequence + * initialization sequence. * * NOTE that initialization of external RTC hardware that depends on the * availability of OS resources (such as SPI or I2C) must be deferred @@ -1803,7 +1803,7 @@ int up_rtc_initialize(void); * None * * Returned Value: - * The current time in seconds + * The current time in seconds. * ************************************************************************************/ @@ -1823,7 +1823,7 @@ time_t up_rtc_time(void); * tp - The location to return the high resolution time value. * * Returned Value: - * Zero (OK) on success; a negated errno on failure + * Zero (OK) on success; a negated errno value on failure. * ************************************************************************************/ @@ -1850,7 +1850,7 @@ int up_rtc_gettime(FAR struct timespec *tp); * tp - The location to return the high resolution time value. * * Returned Value: - * Zero (OK) on success; a negated errno on failure + * Zero (OK) on success; a negated errno value on failure. * ************************************************************************************/ @@ -1869,7 +1869,7 @@ int up_rtc_getdatetime(FAR struct tm *tp); * tp - the time to use * * Returned Value: - * Zero (OK) on success; a negated errno on failure + * Zero (OK) on success; a negated errno value on failure. * ************************************************************************************/ -- GitLab From eb4c2f9c4134c4b8ee4ae99ca85d25a593de3a7e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 14:51:43 -0600 Subject: [PATCH 336/858] PCF85263 RTC register definition header file. Incomplete on initial commit --- drivers/timers/pcf85263.h | 324 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) create mode 100644 drivers/timers/pcf85263.h diff --git a/drivers/timers/pcf85263.h b/drivers/timers/pcf85263.h new file mode 100644 index 0000000000..ab77a0badc --- /dev/null +++ b/drivers/timers/pcf85263.h @@ -0,0 +1,324 @@ +/**************************************************************************** + * drivers/timers/pcf85263.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __DRIVERS_TIMERS_PCF85263_H +#define __DRIVERS_TIMERS_PCF85263_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RTC time and date registers */ + +#define PCF85263_RTC_100TH_SECONDS 0x00 /* RTC 100ths of seconds register */ + /* Bits 0-7: 100ths of seconds register (0-99 BCD) */ +#define PCF85263_RTC_SECONDS 0x01 /* RTC seconds register */ +# define PCF85263_RTC_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +# define PCF85263_RTC_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ +#define PCF85263_RTC_MINUTES 0x02 /* RTC minutes register */ +# define PCF85263_RTC_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +# define PCF85263_RTC_MINUTES_EMON (1 << 7) /* Bit 7: Event monitor */ +#define PCF85263_RTC_HOURS 0x03 /* RTC hours register */ +# define PCF85263_RTC_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_AMPM (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_DAYS 0x04 /* RTC days register */ +# define PCF85263_RTC_DAYS_MASK 0x3f /* Bit 0-5: Day of the month (1-31 BCD) */ +#define PCF85263_RTC_WEEKDAYS 0x05 /* RTC day-of-week register */ +# define PCF85263_RTC_WEEKDAYS_MASK 0x07 /* Bits 0-2: Day of the week (0-6) */ +#define PCF85263_RTC_MONTHS 0x06 /* RTC month register */ +# define PCF85263_RTC_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ +#define PCF85263_RTC_YEARS 0x07 /* RTC year register */ + /* Bits 0-7: Year (0-99 BCD) */ + +/* RTC alarm1 */ + +#define PCF85263_RTC_SECOND_ALARM1 0x08 /* RTC alarm1 seconds register */ +# define PCF85263_RTC_SECOND_ALARM1_MASK 0x7f /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_RTC_MINUTE_ALARM1 0x09 /* RTC alarm1 minutes register */ +# define PCF85263_RTC_MINUTE_ALARM1_MASK 0x7f /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_RTC_HOUR_ALARM1 0x0a /* RTC alarm1 hours register */ +# define PCF85263_RTC_HOURS12_ALARM1_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_AMPM_ALARM1 (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_HOURS24_ALARM1_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_DAY_ALARM1 0x0b /* RTC alarm1 days register */ +# define PCF85263_RTC_DAY_ALARM1_MASK 0x3f /* Bits 0-5: Days (1-31 BCD) */ +#define PCF85263_RTC_MONTH_ALARM1 0x0c /* RTC alarm1 month register */ +# define PCF85263_RTC_MONTH_ALARM1_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ + +/* RTC alarm2 */ + +#define PCF85263_RTC_MINUTE_ALARM2 0x0d /* RTC alarm2 seconds register */ +# define PCF85263_RTC_MINUTE_ALARM2_MASK 0x7f /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_RTC_HOUR_ALARM2 0x0e /* RTC alarm1 minutes register */ +# define PCF85263_RTC_HOURS12_ALARM2_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_AMPM_ALARM2 (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_HOURS24_ALARM2_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_WEEKDAY_ALARM 0x0f /* RTC alarm1 day-of-week register */ +# define PCF85263_RTC_WEEKDAY_ALARM_MASK 0x07 /* Bits 0-2: Day-of-week (0-6) */ + +/* RTC alarm enables */ + +#define PCF85263_RTC_ALARM_ENABLES 0x10 /* RTC alarem enables */ +# define PCF85263_RTC_ALARM_SEC_A1E (1 << 0) /* Second alarm1 enable */ +# define PCF85263_RTC_ALARM_MIN_A1E (1 << 1) /* Minute alarm1 enable */ +# define PCF85263_RTC_ALARM_HR_A1E (1 << 2) /* Hour alarm1 enable */ +# define PCF85263_RTC_ALARM_DAY_A1E (1 << 3) /* Day alarm1 enable */ +# define PCF85263_RTC_ALARM_MON_A1E (1 << 4) /* Month alarm1 enable */ +# define PCF85263_RTC_ALARM_MIN_A2E (1 << 5) /* Minute alarm2 enable */ +# define PCF85263_RTC_ALARM_HR_A2E (1 << 6) /* Hour alarm2 enable */ +# define PCF85263_RTC_ALARM_WDAY_A2E (1 << 7) /* Day-of-week alarm2 enable */ + +/* RTC timestamp1 (TSR1) */ + +#define PCF85263_RTC_TSR1_SECONDS 0x11 /* TSR1 seconds register */ +# define PCF85263_RTC_TSR1_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +# define PCF85263_RTC_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ +#define PCF85263_RTC_TSR1_MINUTES 0x12 /* TSR1 minutes register */ +# define PCF85263_RTC_TSR1_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_RTC_TSR1_HOURS 0x13 /* TSR1 hours register */ +# define PCF85263_RTC_TSR1_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_TSR1_AMPM (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_TSR1_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_TSR1_DAYS 0x14 /* TSR1 days register */ +# define PCF85263_RTC_TSR1_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ +#define PCF85263_RTC_TSR1_MONTHS 0x15 /* TSR1 month register */ +# define PCF85263_RTC_TSR1_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ +#define PCF85263_RTC_TSR1_YEARS 0x16 /* TSR1 year register */ + /* Bits 0-7: Year (0-99 BCD) */ + +/* RTC timestamp2 (TSR2) */ + +#define PCF85263_RTC_TSR2_SECONDS 0x17 /* TSR2 seconds register */ +# define PCF85263_RTC_TSR2_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_RTC_TSR2_MINUTES 0x18 /* TSR2 minutes register */ +# define PCF85263_RTC_TSR2_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_RTC_TSR2_HOURS 0x19 /* TSR2 hours register */ +# define PCF85263_RTC_TSR2_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_TSR2_AMPM (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_TSR2_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_TSR2_DAYS 0x1a /* TSR2 days register */ +# define PCF85263_RTC_TSR2_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ +#define PCF85263_RTC_TSR2_MONTHS 0x1b /* TSR2 month register */ +# define PCF85263_RTC_TSR2_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ +#define PCF85263_RTC_TSR2_YEARS 0x1c /* TSR2 year register */ + /* Bits 0-7: Year (0-99 BCD) */ + +/* RTC timestamp3 (TSR3) */ + +#define PCF85263_RTC_TSR3_SECONDS 0x1d /* TSR3 seconds register */ +# define PCF85263_RTC_TSR3_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_RTC_TSR3_MINUTES 0x1e /* TSR3 minutes register */ +# define PCF85263_RTC_TSR3_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_RTC_TSR3_HOURS 0x1f /* TSR3 hours register */ +# define PCF85263_RTC_TSR3_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ +# define PCF85263_RTC_TSR3_AMPM (1 << 5) /* Bit 5: AM/PM */ +# define PCF85263_RTC_TSR3_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ +#define PCF85263_RTC_TSR3_DAYS 0x20 /* TSR3 days register */ +# define PCF85263_RTC_TSR3_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ +#define PCF85263_RTC_TSR3_MONTHS 0x21 /* TSR3 month register */ +# define PCF85263_RTC_TSR3_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ +#define PCF85263_RTC_TSR3_YEARS 0x22 /* TSR3 year register */ + /* Bits 0-7: Year (0-99 BCD) */ + +/* RTC timestamp mode control */ + +#define PCF85263_RTC_TSR_MODE 0x23 /* Timestamp mode control register */ +# define PCF85263_RTC_TSR_TSR1M_SHIFT (0) /* Bit 0-1: Timestamp register 1 mode */ +# define PCF85263_RTC_TSR_TSR1M_MASK (3 << PCF85263_RTC_TSR_TSR1M_SHIFT) +# define PCF85263_RTC_TSR_TSR1M_NONE (0 << PCF85263_RTC_TSR_TSR1M_SHIFT) /* No timestamp */ +# define PCF85263_RTC_TSR_TSR1M_FE (1 << PCF85263_RTC_TSR_TSR1M_SHIFT) /* Record First TS pin Event */ +# define PCF85263_RTC_TSR_TSR1M_LE (2 << PCF85263_RTC_TSR_TSR1M_SHIFT) /* Record Last TS pin Event */ +# define PCF85263_RTC_TSR_TSR2M_SHIFT (2) /* Bit 2-4: Timestamp register 2 mode */ +# define PCF85263_RTC_TSR_TSR2M_MASK (7 << PCF85263_RTC_TSR_TSR2M_SHIFT) +# define PCF85263_RTC_TSR_TSR2M_NONE (0 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* No timestamp */ +# define PCF85263_RTC_TSR_TSR2M_FB (1 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* Record First time switch to Battery event */ +# define PCF85263_RTC_TSR_TSR2M_LB (2 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* Record Last time switch to Battery event */ +# define PCF85263_RTC_TSR_TSR2M_LV (3 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* Record Last time switch to VDD event */ +# define PCF85263_RTC_TSR_TSR2M_FE (4 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* Record First TS pin Event */ +# define PCF85263_RTC_TSR_TSR2M_LE (5 << PCF85263_RTC_TSR_TSR2M_SHIFT) /* Record Last TS pin Event */ +# define PCF85263_RTC_TSR_TSR3M_SHIFT (6) /* Bit 6-7: Timestamp register 3 mode */ +# define PCF85263_RTC_TSR_TSR3M_MASK (3 << PCF85263_RTC_TSR_TSR3M_SHIFT) +# define PCF85263_RTC_TSR_TSR3M_NONE (0 << PCF85263_RTC_TSR_TSR3M_SHIFT) /* No timestamp */ +# define PCF85263_RTC_TSR_TSR3M_FB (1 << PCF85263_RTC_TSR_TSR3M_SHIFT) /* Record First time switch to Battery event */ +# define PCF85263_RTC_TSR_TSR3M_LB (2 << PCF85263_RTC_TSR_TSR3M_SHIFT) /* Record Last time switch to Battery event */ +# define PCF85263_RTC_TSR_TSR3M_LV (3 << PCF85263_RTC_TSR_TSR3M_SHIFT) /* Record Last time switch to VDD event */ + +/* Stop-watch time registers */ + +#define PCF85263_STW_100TH_SECONDS 0x00 /* Stopwatch 100ths of seconds register */ + /* Bits 0-7: 100ths of seconds register (0-99 BCD) */ +#define PCF85263_STW_SECONDS 0x01 /* Stopwatch seconds register */ +# define PCF85263_STW_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +# define PCF85263_STW_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ +#define PCF85263_STW_MINUTES 0x02 /* Stopwatch minutes register */ +# define PCF85263_STW_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_HOURS_XX_XX_00 0x03 /* Stopwatch hours register xx_xx_00 */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_HOURS_XX_00_XX 0x04 /* Stopwatch hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_HOURS_00_XX_XX 0x05 /* Stopwatch hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch alarm1 */ + +#define PCF85263_STW_SECOND_ALM1 0x08 /* Stopwatch alarm1 seconds register */ +# define PCF85263_STW_SECOND_ALM1_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_STW_MINUTE_ALM1 0x09 /* Stopwatch alarm1 minutes register */ +# define PCF85263_STW_MINUTE_ALM1_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_HR_XX_XX_00_ALM1 0x0a /* Stopwatch alarm1 hours register xx_xx_00 */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_HR_XX_00_XX_ALM1 0x0b /* Stopwatch alarm1 hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_HR_00_XX_XX_ALM1 0x0c /* Stopwatch alarm1 hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch alarm2 */ + +#define PCF85263_STW_MINUTE_ALM2 0x0d /* Stopwatch alarm2 minutes register */ +# define PCF85263_STW_MINUTE_ALM2_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_HR_XX_00_ALM2 0x0e /* Stopwatch alarm2 hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_HR_00_XX_ALM2 0x0f /* Stopwatch alarm2 hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch alarm enables */ + +#define PCF85263_STW_ALARM_ENABLES 0x10 /* +HR_00_XX +_A2E +HR_XX_00 +_A2E +MIN_A2E HR_00_XX +_XX_A1E +HR_XX_00 +_XX_A1E +HR_XX_XX +_00_A1E +MIN_A1E SEC_A1E + +/* Stop-watch timestamp1 (TSR1) */ + +#define PCF85263_STW_TSR1_SECONDS 0x11 /* TSR1 seconds register */ +# define PCF85263_STW_TSR1_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_STW_TSR1_MINUTES 0x12 /* TSR1 minutes register */ +# define PCF85263_STW_TSR1_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_TSR1_HR_XX_XX_00 0x13 /* Stopwatch TSR1 hours register xx_xx_00 */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR1_HR_XX_00_XX 0x14 /* Stopwatch TSR1 hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR1_HR_00_XX_XX 0x15 /* Stopwatch TSR1 hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch timestamp2 (TSR2) */ + +#define PCF85263_STW_TSR2_SECONDS 0x17 /* TSR2 seconds register */ +# define PCF85263_STW_TSR2_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_STW_TSR2_MINUTES 0x18 /* TSR2 minutes register */ +# define PCF85263_RTC_TSR2_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_TSR2_HR_XX_XX_00 0x19 /* Stopwatch TSR2 hours register xx_xx_00 */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR2_HR_XX_00_XX 0x1a /* Stopwatch TSR2 hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR2_HR_00_XX_XX 0x1b /* Stopwatch TSR2 hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch timestamp3 (TSR3) */ + +#define PCF85263_STW_TSR3_SECONDS 0x1d /* TSR3 seconds register */ +# define PCF85263_STW_TSR3_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ +#define PCF85263_STW_TSR3_MINUTES 0x1e /* TSR3 minutes register */ +# define PCF85263_RTC_TSR3_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ +#define PCF85263_STW_TSR3_HR_XX_XX_00 0x1f /* Stopwatch TSR3 hours register xx_xx_00 */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR3_HR_XX_00_XX 0x20 /* Stopwatch TSR3 hours register xx_00_xx */ + /* Bits 0-7: hours (0-99 BCD) */ +#define PCF85263_STW_TSR3_HR_00_XX_XX 0x21 /* Stopwatch TSR3 hours register 00_xx_xx */ + /* Bits 0-7: hours (0-99 BCD) */ + +/* Stop-watch timestamp mode control */ + +#define PCF85263_STW_TSR_MODE 0x23 /* +TSR3M[1:0] - TSR2M[2:0] TSR1M[1:0] + +/* Offset register */ + +#define PCF85263_STW_OFFSET 0x24 /* +OFFSET[7:0] + +/* Control registers */ + +#define PCF85263_STW_OSCILLATOR 0x25 /* +CLKIV OFFM 12_24 LOWJ OSCD[1:0] CL[1:0] +#define PCF85263_STW_BATTERY_SWITCH 0x26 /* +BSOFF BSRR BSM[1:0] BSTH +#define PCF85263_STW_PIN_IO 0x27 /* +CLKPM TSPULL TSL TSIM TSPM[1:0] INTAPM[1:0] +#define PCF85263_STW_FUNCTION 0x28 /* +100TH PI[1:0] RTCM STOPM COF[2:0] +#define PCF85263_STW_INTA_ENABLE 0x29 /* +ILPA PIEA OIEA A1IEA A2IEA TSRIEA BSIEA WDIEA +#define PCF85263_STW_INTB_ENABLE 0x2a /* +ILPB PIEB OIEB A1IEB A2IEB TSRIEB BSIEB WDIEB +#define PCF85263_STW_FLAGS 0x2b /* +PIF A2F A1F WDF BSF TSR3F TSR2F TSR1F + +/* RAM byte */ + +#define PCF85263_STW_RAM_BYTE 0x2c /* + /* Bits 0-7: RAM data */ + +/* WatchDog registers */ + +#define PCF85263_STW_WATCHDOG 0x2d /* +WDM WDR[4:0] WDS[1:0] + +/* Stop */ + +#define PCF85263_STW_STOP_ENABLE 0x2e /* +STOP + +/* Reset */ + +#define PCF85263_STW_RESETS 0x2f /* +CPR 0 1 0 SR 1 0 CTS + +#endif /* __DRIVERS_TIMERS_PCF85263_H */ -- GitLab From 26cbdd8939e09e3b9546d0cadaeaf6e514f7a1c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 16:09:23 -0600 Subject: [PATCH 337/858] Completes PCF85263 RTC register definition header file. --- drivers/timers/pcf85263.h | 225 +++++++++++++++++++++++++++++++------- 1 file changed, 186 insertions(+), 39 deletions(-) diff --git a/drivers/timers/pcf85263.h b/drivers/timers/pcf85263.h index ab77a0badc..a1d8b933da 100644 --- a/drivers/timers/pcf85263.h +++ b/drivers/timers/pcf85263.h @@ -50,22 +50,29 @@ #define PCF85263_RTC_100TH_SECONDS 0x00 /* RTC 100ths of seconds register */ /* Bits 0-7: 100ths of seconds register (0-99 BCD) */ + #define PCF85263_RTC_SECONDS 0x01 /* RTC seconds register */ # define PCF85263_RTC_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ # define PCF85263_RTC_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ + #define PCF85263_RTC_MINUTES 0x02 /* RTC minutes register */ # define PCF85263_RTC_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ # define PCF85263_RTC_MINUTES_EMON (1 << 7) /* Bit 7: Event monitor */ + #define PCF85263_RTC_HOURS 0x03 /* RTC hours register */ # define PCF85263_RTC_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_AMPM (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_DAYS 0x04 /* RTC days register */ # define PCF85263_RTC_DAYS_MASK 0x3f /* Bit 0-5: Day of the month (1-31 BCD) */ + #define PCF85263_RTC_WEEKDAYS 0x05 /* RTC day-of-week register */ # define PCF85263_RTC_WEEKDAYS_MASK 0x07 /* Bits 0-2: Day of the week (0-6) */ + #define PCF85263_RTC_MONTHS 0x06 /* RTC month register */ # define PCF85263_RTC_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ + #define PCF85263_RTC_YEARS 0x07 /* RTC year register */ /* Bits 0-7: Year (0-99 BCD) */ @@ -73,14 +80,18 @@ #define PCF85263_RTC_SECOND_ALARM1 0x08 /* RTC alarm1 seconds register */ # define PCF85263_RTC_SECOND_ALARM1_MASK 0x7f /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_RTC_MINUTE_ALARM1 0x09 /* RTC alarm1 minutes register */ # define PCF85263_RTC_MINUTE_ALARM1_MASK 0x7f /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_RTC_HOUR_ALARM1 0x0a /* RTC alarm1 hours register */ # define PCF85263_RTC_HOURS12_ALARM1_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_AMPM_ALARM1 (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_HOURS24_ALARM1_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_DAY_ALARM1 0x0b /* RTC alarm1 days register */ # define PCF85263_RTC_DAY_ALARM1_MASK 0x3f /* Bits 0-5: Days (1-31 BCD) */ + #define PCF85263_RTC_MONTH_ALARM1 0x0c /* RTC alarm1 month register */ # define PCF85263_RTC_MONTH_ALARM1_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ @@ -88,10 +99,12 @@ #define PCF85263_RTC_MINUTE_ALARM2 0x0d /* RTC alarm2 seconds register */ # define PCF85263_RTC_MINUTE_ALARM2_MASK 0x7f /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_RTC_HOUR_ALARM2 0x0e /* RTC alarm1 minutes register */ # define PCF85263_RTC_HOURS12_ALARM2_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_AMPM_ALARM2 (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_HOURS24_ALARM2_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_WEEKDAY_ALARM 0x0f /* RTC alarm1 day-of-week register */ # define PCF85263_RTC_WEEKDAY_ALARM_MASK 0x07 /* Bits 0-2: Day-of-week (0-6) */ @@ -112,16 +125,21 @@ #define PCF85263_RTC_TSR1_SECONDS 0x11 /* TSR1 seconds register */ # define PCF85263_RTC_TSR1_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ # define PCF85263_RTC_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ + #define PCF85263_RTC_TSR1_MINUTES 0x12 /* TSR1 minutes register */ # define PCF85263_RTC_TSR1_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_RTC_TSR1_HOURS 0x13 /* TSR1 hours register */ # define PCF85263_RTC_TSR1_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_TSR1_AMPM (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_TSR1_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_TSR1_DAYS 0x14 /* TSR1 days register */ # define PCF85263_RTC_TSR1_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ + #define PCF85263_RTC_TSR1_MONTHS 0x15 /* TSR1 month register */ # define PCF85263_RTC_TSR1_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ + #define PCF85263_RTC_TSR1_YEARS 0x16 /* TSR1 year register */ /* Bits 0-7: Year (0-99 BCD) */ @@ -129,16 +147,21 @@ #define PCF85263_RTC_TSR2_SECONDS 0x17 /* TSR2 seconds register */ # define PCF85263_RTC_TSR2_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_RTC_TSR2_MINUTES 0x18 /* TSR2 minutes register */ # define PCF85263_RTC_TSR2_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_RTC_TSR2_HOURS 0x19 /* TSR2 hours register */ # define PCF85263_RTC_TSR2_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_TSR2_AMPM (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_TSR2_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_TSR2_DAYS 0x1a /* TSR2 days register */ # define PCF85263_RTC_TSR2_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ + #define PCF85263_RTC_TSR2_MONTHS 0x1b /* TSR2 month register */ # define PCF85263_RTC_TSR2_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ + #define PCF85263_RTC_TSR2_YEARS 0x1c /* TSR2 year register */ /* Bits 0-7: Year (0-99 BCD) */ @@ -146,16 +169,21 @@ #define PCF85263_RTC_TSR3_SECONDS 0x1d /* TSR3 seconds register */ # define PCF85263_RTC_TSR3_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_RTC_TSR3_MINUTES 0x1e /* TSR3 minutes register */ # define PCF85263_RTC_TSR3_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_RTC_TSR3_HOURS 0x1f /* TSR3 hours register */ # define PCF85263_RTC_TSR3_HOURS12_MASK 0x1f /* Bits 0-4: Hours (1-12 BCD) */ # define PCF85263_RTC_TSR3_AMPM (1 << 5) /* Bit 5: AM/PM */ # define PCF85263_RTC_TSR3_HOURS24_MASK 0x3f /* Bits 0-5: Hours (0-23 BCD) */ + #define PCF85263_RTC_TSR3_DAYS 0x20 /* TSR3 days register */ # define PCF85263_RTC_TSR3_DAYS_MASK 0x3f /* Bits 0-5: Day of the month (1-31 BCD) */ + #define PCF85263_RTC_TSR3_MONTHS 0x21 /* TSR3 month register */ # define PCF85263_RTC_TSR3_MONTHS_MASK 0x1f /* Bits 0-4: Month (1-12 BCD) */ + #define PCF85263_RTC_TSR3_YEARS 0x22 /* TSR3 year register */ /* Bits 0-7: Year (0-99 BCD) */ @@ -189,8 +217,10 @@ #define PCF85263_STW_SECONDS 0x01 /* Stopwatch seconds register */ # define PCF85263_STW_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ # define PCF85263_STW_SECONDS_OS (1 << 7) /* Bit 7: Oscillator stop */ + #define PCF85263_STW_MINUTES 0x02 /* Stopwatch minutes register */ # define PCF85263_STW_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_HOURS_XX_XX_00 0x03 /* Stopwatch hours register xx_xx_00 */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_HOURS_XX_00_XX 0x04 /* Stopwatch hours register xx_00_xx */ @@ -202,8 +232,10 @@ #define PCF85263_STW_SECOND_ALM1 0x08 /* Stopwatch alarm1 seconds register */ # define PCF85263_STW_SECOND_ALM1_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_STW_MINUTE_ALM1 0x09 /* Stopwatch alarm1 minutes register */ # define PCF85263_STW_MINUTE_ALM1_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_HR_XX_XX_00_ALM1 0x0a /* Stopwatch alarm1 hours register xx_xx_00 */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_HR_XX_00_XX_ALM1 0x0b /* Stopwatch alarm1 hours register xx_00_xx */ @@ -215,6 +247,7 @@ #define PCF85263_STW_MINUTE_ALM2 0x0d /* Stopwatch alarm2 minutes register */ # define PCF85263_STW_MINUTE_ALM2_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_HR_XX_00_ALM2 0x0e /* Stopwatch alarm2 hours register xx_00_xx */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_HR_00_XX_ALM2 0x0f /* Stopwatch alarm2 hours register 00_xx_xx */ @@ -222,25 +255,24 @@ /* Stop-watch alarm enables */ -#define PCF85263_STW_ALARM_ENABLES 0x10 /* -HR_00_XX -_A2E -HR_XX_00 -_A2E -MIN_A2E HR_00_XX -_XX_A1E -HR_XX_00 -_XX_A1E -HR_XX_XX -_00_A1E -MIN_A1E SEC_A1E +#define PCF85263_STW_ALARM_ENABLES 0x10 /* Alarm enable control register */ +# define PCF85263_STW_SEC_A1E (1 << 0) /* Bit 0: Second alarm1 enable */ +# define PCF85263_STW_MIN_A1E (1 << 1) /* Bit 1: Minute alarm1 enable */ +# define PCF85263_STW_HR_XX_XX_00_A1E (1 << 2) /* Bit 2: Tens of hour alarm1 enable */ +# define PCF85263_STW_HR_XX_00_XX_A1E (1 << 3) /* Bit 3: Thousands of hours alarm1 enable */ +# define PCF85263_STW_HR_00_XX_XX_A1E (1 << 4) /* Bit 4: 100 thousands of hours alarm1 enable */ +# define PCF85263_STW_MIN_A2E (1 << 5) /* Bit 5: Minute alarm2 enable */ +# define PCF85263_STW_HR_XX_00_A2E (1 << 6) /* Bit 6: Tens of hours alarm2 enable */ +# define PCF85263_STW_HR_00_XX_A2E (1 << 7) /* Bit 7: Thousands of hours alarm2 enable */ /* Stop-watch timestamp1 (TSR1) */ #define PCF85263_STW_TSR1_SECONDS 0x11 /* TSR1 seconds register */ # define PCF85263_STW_TSR1_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_STW_TSR1_MINUTES 0x12 /* TSR1 minutes register */ # define PCF85263_STW_TSR1_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_TSR1_HR_XX_XX_00 0x13 /* Stopwatch TSR1 hours register xx_xx_00 */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_TSR1_HR_XX_00_XX 0x14 /* Stopwatch TSR1 hours register xx_00_xx */ @@ -252,8 +284,10 @@ MIN_A1E SEC_A1E #define PCF85263_STW_TSR2_SECONDS 0x17 /* TSR2 seconds register */ # define PCF85263_STW_TSR2_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_STW_TSR2_MINUTES 0x18 /* TSR2 minutes register */ # define PCF85263_RTC_TSR2_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_TSR2_HR_XX_XX_00 0x19 /* Stopwatch TSR2 hours register xx_xx_00 */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_TSR2_HR_XX_00_XX 0x1a /* Stopwatch TSR2 hours register xx_00_xx */ @@ -265,8 +299,10 @@ MIN_A1E SEC_A1E #define PCF85263_STW_TSR3_SECONDS 0x1d /* TSR3 seconds register */ # define PCF85263_STW_TSR3_SECONDS_MASK (0x7f) /* Bits 0-6: Seconds (0-59 BCD) */ + #define PCF85263_STW_TSR3_MINUTES 0x1e /* TSR3 minutes register */ # define PCF85263_RTC_TSR3_MINUTES_MASK (0x7f) /* Bits 0-6: Minutes (0-59 BCD) */ + #define PCF85263_STW_TSR3_HR_XX_XX_00 0x1f /* Stopwatch TSR3 hours register xx_xx_00 */ /* Bits 0-7: hours (0-99 BCD) */ #define PCF85263_STW_TSR3_HR_XX_00_XX 0x20 /* Stopwatch TSR3 hours register xx_00_xx */ @@ -276,49 +312,160 @@ MIN_A1E SEC_A1E /* Stop-watch timestamp mode control */ -#define PCF85263_STW_TSR_MODE 0x23 /* -TSR3M[1:0] - TSR2M[2:0] TSR1M[1:0] +#define PCF85263_STW_TSR_MODE 0x23 /* Timestamp mode control register */ +# define PCF85263_STW_TSR_TSR1M_SHIFT (0) /* Bit 0-1: Timestamp register 1 mode */ +# define PCF85263_STW_TSR_TSR1M_MASK (3 << PCF85263_STW_TSR_TSR1M_SHIFT) +# define PCF85263_STW_TSR_TSR1M_NONE (0 << PCF85263_STW_TSR_TSR1M_SHIFT) /* No timestamp */ +# define PCF85263_STW_TSR_TSR1M_FE (1 << PCF85263_STW_TSR_TSR1M_SHIFT) /* Record First TS pin Event */ +# define PCF85263_STW_TSR_TSR1M_LE (2 << PCF85263_STW_TSR_TSR1M_SHIFT) /* Record Last TS pin Event */ +# define PCF85263_STW_TSR_TSR2M_SHIFT (2) /* Bit 2-4: Timestamp register 2 mode */ +# define PCF85263_STW_TSR_TSR2M_MASK (7 << PCF85263_STW_TSR_TSR2M_SHIFT) +# define PCF85263_STW_TSR_TSR2M_NONE (0 << PCF85263_STW_TSR_TSR2M_SHIFT) /* No timestamp */ +# define PCF85263_STW_TSR_TSR2M_FB (1 << PCF85263_STW_TSR_TSR2M_SHIFT) /* Record First time switch to Battery event */ +# define PCF85263_STW_TSR_TSR2M_LB (2 << PCF85263_STW_TSR_TSR2M_SHIFT) /* Record Last time switch to Battery event */ +# define PCF85263_STW_TSR_TSR2M_LV (3 << PCF85263_STW_TSR_TSR2M_SHIFT) /* Record Last time switch to VDD event */ +# define PCF85263_STW_TSR_TSR2M_FE (4 << PCF85263_STW_TSR_TSR2M_SHIFT) /* Record First TS pin Event */ +# define PCF85263_STW_TSR_TSR2M_LE (5 << PCF85263_STW_TSR_TSR2M_SHIFT) /* Record Last TS pin Event */ +# define PCF85263_STW_TSR_TSR3M_SHIFT (6) /* Bit 6-7: Timestamp register 3 mode */ +# define PCF85263_STW_TSR_TSR3M_MASK (3 << PCF85263_STW_TSR_TSR3M_SHIFT) +# define PCF85263_STW_TSR_TSR3M_NONE (0 << PCF85263_STW_TSR_TSR3M_SHIFT) /* No timestamp */ +# define PCF85263_STW_TSR_TSR3M_FB (1 << PCF85263_STW_TSR_TSR3M_SHIFT) /* Record First time switch to Battery event */ +# define PCF85263_STW_TSR_TSR3M_LB (2 << PCF85263_STW_TSR_TSR3M_SHIFT) /* Record Last time switch to Battery event */ +# define PCF85263_STW_TSR_TSR3M_LV (3 << PCF85263_STW_TSR_TSR3M_SHIFT) /* Record Last time switch to VDD event */ /* Offset register */ -#define PCF85263_STW_OFFSET 0x24 /* -OFFSET[7:0] +#define PCF85263_CTL_OFFSET 0x24 /* Offset regsiter */ + /* Bits 0-7: Offset value */ /* Control registers */ -#define PCF85263_STW_OSCILLATOR 0x25 /* -CLKIV OFFM 12_24 LOWJ OSCD[1:0] CL[1:0] -#define PCF85263_STW_BATTERY_SWITCH 0x26 /* -BSOFF BSRR BSM[1:0] BSTH -#define PCF85263_STW_PIN_IO 0x27 /* -CLKPM TSPULL TSL TSIM TSPM[1:0] INTAPM[1:0] -#define PCF85263_STW_FUNCTION 0x28 /* -100TH PI[1:0] RTCM STOPM COF[2:0] -#define PCF85263_STW_INTA_ENABLE 0x29 /* -ILPA PIEA OIEA A1IEA A2IEA TSRIEA BSIEA WDIEA -#define PCF85263_STW_INTB_ENABLE 0x2a /* -ILPB PIEB OIEB A1IEB A2IEB TSRIEB BSIEB WDIEB -#define PCF85263_STW_FLAGS 0x2b /* -PIF A2F A1F WDF BSF TSR3F TSR2F TSR1F +#define PCF85263_CTL_OSCILLATOR 0x25 /* Oscillator control register */ +# define PCF85263_CTL_OSC_CL_SHIFT (0) /* Bits 0-1: Quartz oscillator load capacitance */ +# define PCF85263_CTL_OSC_CL_MASK (3 << PCF85263_CTL_OSC_CL_SHIFT) +# define PCF85263_CTL_OSC_CL_7PF (0 << PCF85263_CTL_OSC_CL_SHIFT) /* 7.0 pF */ +# define PCF85263_CTL_OSC_CL_6PF (1 << PCF85263_CTL_OSC_CL_SHIFT) /* 6.0 pF */ +# define PCF85263_CTL_OSC_CL_12p5PF (2 << PCF85263_CTL_OSC_CL_SHIFT) /* 12.5 pF */ +# define PCF85263_CTL_OSC_OSCD_SHIFT (2) /* Bits 1-2: Oscillator driver bits */ +# define PCF85263_CTL_OSC_OSCD_MASK (3 << PCF85263_CTL_OSC_OSCD_SHIFT) +# define PCF85263_CTL_OSC_OSCD_NORMAL (0 << PCF85263_CTL_OSC_OSCD_SHIFT) /* Normal drive; RS(max): 100 kohm */ +# define PCF85263_CTL_OSC_OSCD_LOW (1 << PCF85263_CTL_OSC_OSCD_SHIFT) /* Low drive; RS(max): 60 kohm; reduced IDD */ +# define PCF85263_CTL_OSC_OSCD_HIGH (2 << PCF85263_CTL_OSC_OSCD_SHIFT) /* High drive; RS(max): 500 kohm; increased IDD */ +# define PCF85263_CTL_OSC_LOWJ (1 << 4) /* Bit 4: Low jitter mode */ +# define PCF85263_CTL_OSC_12_24 (1 << 5) /* Bit 5: 12-/24-hour mode */ +# define PCF85263_CTL_OSC_OFFM (1 << 6) /* Bit 6: Offset calibration mode */ +# define PCF85263_CTL_OSC_CLKIV (1 << 7) /* Bit 7: Output clock inversion */ + +#define PCF85263_CTL_BATTERY_SWITCH 0x26 /* Battery switch control register */ +# define PCF85263_CTL_BATTERY_BSTH (1 << 0) /* Bit 0: +# define PCF85263_CTL_BATTERY_BSM_SHIFT (1) /* Bits 1-2: Battery switch mode bits */ +# define PCF85263_CTL_BATTERY_BSM_MASK (3 << PCF85263_CTL_BATTERY_BSM_SHIFT) +# define PCF85263_CTL_BATTERY_BSM_VTH (0 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the Vth level */ +# define PCF85263_CTL_BATTERY_BSM_VBAT (1 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the VBAT level */ +# define PCF85263_CTL_BATTERY_BSM_MAX (2 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the higher level of Vth or VBAT */ +# define PCF85263_CTL_BATTERY_BSM_MIN (3 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the lower level of Vth or VBAT */ +# define PCF85263_CTL_BATTERY_BSRR (1 << 3) /* Bit 3: Battery switch refresh rate */ +# define PCF85263_CTL_BATTERY_BSOFF (1 << 4) /* Bit 4: Battery switch on/off */ + +#define PCF85263_CTL_PIN_IO 0x27 /* Pin input/output control register */ +# define PCF85263_CTL_INTAPM_SHIFT (0) /* Bits 0-1: INTA pin mode */ +# define PCF85263_CTL_INTAPM_MASK (3 << PCF85263_CTL_INTAPM_SHIFT) +# define PCF85263_CTL_INTAPM_CLK (0 << PCF85263_CTL_INTAPM_SHIFT) /* CLK output mode */ +# define PCF85263_CTL_INTAPM_BAT (1 << PCF85263_CTL_INTAPM_SHIFT) /* Battery mode indication */ +# define PCF85263_CTL_INTAPM_INTA (2 << PCF85263_CTL_INTAPM_SHIFT) /* INTA output */ +# define PCF85263_CTL_INTAPM_HIZ (3 << PCF85263_CTL_INTAPM_SHIFT) /* Hi-Z */ +# define PCF85263_CTL_TSPM_SHIFT (2) /* Bits 2-3: TS pin I/O control */ +# define PCF85263_CTL_TSPM_MASK (3 << PCF85263_CTL_TSPM_SHIFT) +# define PCF85263_CTL_TSPM_DISABLED (0 << PCF85263_CTL_TSPM_SHIFT) /* Disabled; input can be left floating */ +# define PCF85263_CTL_TSPM_INTB (1 << PCF85263_CTL_TSPM_SHIFT) /* INTB output; push-pull */ +# define PCF85263_CTL_TSPM_CLK (2 << PCF85263_CTL_TSPM_SHIFT) /* CLK output; push-pull */ +# define PCF85263_CTL_TSPM_INPUT (3 << PCF85263_CTL_TSPM_SHIFT) /* Input mode */ +# define PCF85263_CTL_TSIM (1 << 4) /* Bit 4: TS pin input mode */ +# define PCF85263_CTL_TSL (1 << 5) /* Bit 5: TS pin input sense */ +# define PCF85263_CTL_TSPULL (1 << 6) /* Bit 6: TS pin pull-up resistor value */ +# define PCF85263_CTL_CLKPM (1 << 7) /* Bit 7: CLK pin mode */ + +#define PCF85263_CTL_FUNCTION 0x28 /* Function control register */ +# define PCF85263_CTL_FUNC_COF_SHIFT (0) /* Bits 0-2: Clock output frequency */ +# define PCF85263_CTL_FUNC_COF_MASK (7 << PCF85263_CTL_FUNC_COF_SHIFT) /* CLK pin TS pin INTA pin */ +# define PCF85263_CTL_FUNC_COF_32KHZ (0 << PCF85263_CTL_FUNC_COF_SHIFT) /* 32768 32768 32768 */ +# define PCF85263_CTL_FUNC_COF_16KHZ (1 << PCF85263_CTL_FUNC_COF_SHIFT) /* 16384 16384 16384 */ +# define PCF85263_CTL_FUNC_COF_8KHZ (2 << PCF85263_CTL_FUNC_COF_SHIFT) /* 8192 8192 8192 */ +# define PCF85263_CTL_FUNC_COF_4KHZ (3 << PCF85263_CTL_FUNC_COF_SHIFT) /* 4096 4096 4096 */ +# define PCF85263_CTL_FUNC_COF_2KHZ (4 << PCF85263_CTL_FUNC_COF_SHIFT) /* 2048 2048 2048 */ +# define PCF85263_CTL_FUNC_COF_1KHZ (5 << PCF85263_CTL_FUNC_COF_SHIFT) /* 1024 1024 1024 */ +# define PCF85263_CTL_FUNC_COF_1HZ (6 << PCF85263_CTL_FUNC_COF_SHIFT) /* 1 1 1 */ +# define PCF85263_CTL_FUNC_COF_LOW (7 << PCF85263_CTL_FUNC_COF_SHIFT) /* static LOW static LOW Hi-Z */ +# define PCF85263_CTL_FUNC_STOPM (1 << 3) /* Bit 3: STOP mode */ +# define PCF85263_CTL_FUNC_RTCM (1 << 4) /* Bit 4: RTC mode */ +# define PCF85263_CTL_FUNC_PI_SHIFT (5) /* Bits 5-6: Periodic interrupt */ +# define PCF85263_CTL_FUNC_PI_MASK (3 << PCF85263_CTL_FUNC_PI_SHIFT) +# define PCF85263_CTL_FUNC_PI_NONE (0 << PCF85263_CTL_FUNC_PI_SHIFT) /* No periodic interrupt */ +# define PCF85263_CTL_FUNC_PI_SEC (1 << PCF85263_CTL_FUNC_PI_SHIFT) /* Once per second */ +# define PCF85263_CTL_FUNC_PI_MIN (2 << PCF85263_CTL_FUNC_PI_SHIFT) /* Once per minute */ +# define PCF85263_CTL_FUNC_PI_HOUR (3 << PCF85263_CTL_FUNC_PI_SHIFT) /* Once per hour */ +# define PCF85263_CTL_FUNC_100TH (1 << 7) /* Bit 7: 100th seconds mode */ + +#define PCF85263_CTL_INTA_ENABLE 0x29 /* Interrupt A control bits */ +# define PCF85263_CTL_INTA_WDIEA (1 << 0) /* Bit 0: Watchdog interrupt enable */ +# define PCF85263_CTL_INTA_BSIEA (1 << 1) /* Bit 1: Battery switch interrupt enable */ +# define PCF85263_CTL_INTA_TSRIEA (1 << 2) /* Bit 2: Timestamp register interrupt enable */ +# define PCF85263_CTL_INTA_A2IEA (1 << 3) /* Bit 3: Alarm2 interrupt enable */ +# define PCF85263_CTL_INTA_A1IEA (1 << 4) /* Bit 4: Alarm1 interrupt enable */ +# define PCF85263_CTL_INTA_OIEA (1 << 5) /* Bit 5: Offset correction interrupt enable */ +# define PCF85263_CTL_INTA_PIEA (1 << 6) /* Bit 6: Periodic interrupt enable */ +# define PCF85263_CTL_INTA_ILPA (1 << 7) /* Bit 7: Interrupt generates a pulse */ + +#define PCF85263_CTL_INTB_ENABLE 0x2a /* Interrupt B control bits */ +# define PCF85263_CTL_INTB_WDIEB (1 << 0) /* Bit 0: Watchdog interrupt enable */ +# define PCF85263_CTL_INTB_BSIEB (1 << 1) /* Bit 1: Battery switch interrupt enable */ +# define PCF85263_CTL_INTB_TSRIEB (1 << 2) /* Bit 2: Timestamp register interrupt enable */ +# define PCF85263_CTL_INTB_A2IEB (1 << 3) /* Bit 3: Alarm2 interrupt enable */ +# define PCF85263_CTL_INTB_A1IEB (1 << 4) /* Bit 4: Alarm1 interrupt enable */ +# define PCF85263_CTL_INTB_OIEB (1 << 5) /* Bit 5: Offset correction interrupt enable */ +# define PCF85263_CTL_INTB_PIEB (1 << 6) /* Bit 6: Periodic interrupt enable */ +# define PCF85263_CTL_INTB_ILPB (1 << 7) /* Bit 7: Interrupt generates a pulse */ + +#define PCF85263_CTL_FLAGS 0x2b /* Flag status register */ +# define PCF85263_CTL_FLAGS_TSR1F (1 << 0) /* Bit 0: Timestamp register 1 event flag */ +# define PCF85263_CTL_FLAGS_TSR2F (1 << 1) /* Bit 1: Timestamp register 2 event flag */ +# define PCF85263_CTL_FLAGS_TSR3F (1 << 2) /* Bit 2: Timestamp register 3 event flag */ +# define PCF85263_CTL_FLAGS_BSF (1 << 3) /* Bit 3: Battery switch flag */ +# define PCF85263_CTL_FLAGS_WDF (1 << 4) /* Bit 4: Watchdog flag */ +# define PCF85263_CTL_FLAGS_A1F (1 << 5) /* Bit 5: Alarm1 flag */ +# define PCF85263_CTL_FLAGS_A2F (1 << 6) /* Bit 6: Alarm2 flag */ +# define PCF85263_CTL_FLAGS_PIF (1 << 7) /* Bit 7: Periodic interrupt flag */ /* RAM byte */ -#define PCF85263_STW_RAM_BYTE 0x2c /* - /* Bits 0-7: RAM data */ +#define PCF85263_CTL_RAM_BYTE 0x2c /* RAM byte register */ + /* Bits 0-7: RAM data */ -/* WatchDog registers */ +/* Watchdog registers */ -#define PCF85263_STW_WATCHDOG 0x2d /* -WDM WDR[4:0] WDS[1:0] +#define PCF85263_CTL_WATCHDOG 0x2d /* Watchdog control and status register */ +# define PCF85263_CTL_WDS_SHIFT (0) /* Bits 0-1: Watchdog step size (source clock) */ +# define PCF85263_CTL_WDS_MASK (3 << PCF85263_CTL_WDS_SHIFT) +# define PCF85263_CTL_WDS_4SEC (0 << PCF85263_CTL_WDS_SHIFT) /* 4 seconds (0.25 Hz) */ +# define PCF85263_CTL_WDS_1SEC (1 << PCF85263_CTL_WDS_SHIFT) /* 1 second (1 Hz) */ +# define PCF85263_CTL_WDS_250MSEC (2 << PCF85263_CTL_WDS_SHIFT) /* 1â„4 second (4 Hz) */ +# define PCF85263_CTL_WDS_67MSEC (3 << PCF85263_CTL_WDS_SHIFT) /* 1â„16 second (16 Hz) */ +# define PCF85263_CTL_WDR_SHIFT (2) /* Bits 2-6: Watchdog register bits */ +# define PCF85263_CTL_WDR_MASK (31 << PCF85263_CTL_WDR_SHIFT) +# define PCF85263_CTL_WDR(n) ((uint9_t)(n) << PCF85263_CTL_WDR_SHIFT) +# define PCF85263_CTL_WDM (1 << 7) /* Bit 7: Watchdog mode /* Stop */ -#define PCF85263_STW_STOP_ENABLE 0x2e /* -STOP +#define PCF85263_CTL_STOP_ENABLE 0x2e /* Stop enable register */ +# define PCF85263_CTL_STOP (1 << 0) /* Bit 0: Stop bit */ /* Reset */ -#define PCF85263_STW_RESETS 0x2f /* -CPR 0 1 0 SR 1 0 CTS +#define PCF85263_CTL_RESETS 0x2f /* +# define PCF85263_CTL_CTS (1 << 0) /* Bit 0: Clear timestamp */ +# define PCF85263_CTL_SR (1 << 3) /* Bit 3: Software reset */ +# define PCF85263_CTL_CPR (1 << 7) /* Bit 7: Clear prescaler */ +# define PCF85263_CTL_RESETS_BITS 0x24 /* Fixed register bits */ #endif /* __DRIVERS_TIMERS_PCF85263_H */ -- GitLab From 11c0f5be6ffbabfbc61ef58df6a0368306707d59 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 16:10:01 -0600 Subject: [PATCH 338/858] Clear some trailing whitespace --- drivers/timers/pcf85263.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/timers/pcf85263.h b/drivers/timers/pcf85263.h index a1d8b933da..fac163fd94 100644 --- a/drivers/timers/pcf85263.h +++ b/drivers/timers/pcf85263.h @@ -357,7 +357,7 @@ # define PCF85263_CTL_OSC_CLKIV (1 << 7) /* Bit 7: Output clock inversion */ #define PCF85263_CTL_BATTERY_SWITCH 0x26 /* Battery switch control register */ -# define PCF85263_CTL_BATTERY_BSTH (1 << 0) /* Bit 0: +# define PCF85263_CTL_BATTERY_BSTH (1 << 0) /* Bit 0: # define PCF85263_CTL_BATTERY_BSM_SHIFT (1) /* Bits 1-2: Battery switch mode bits */ # define PCF85263_CTL_BATTERY_BSM_MASK (3 << PCF85263_CTL_BATTERY_BSM_SHIFT) # define PCF85263_CTL_BATTERY_BSM_VTH (0 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the Vth level */ @@ -462,7 +462,7 @@ /* Reset */ -#define PCF85263_CTL_RESETS 0x2f /* +#define PCF85263_CTL_RESETS 0x2f /* # define PCF85263_CTL_CTS (1 << 0) /* Bit 0: Clear timestamp */ # define PCF85263_CTL_SR (1 << 3) /* Bit 3: Software reset */ # define PCF85263_CTL_CPR (1 << 7) /* Bit 7: Clear prescaler */ -- GitLab From 3cff8a725b3a7a351588fb3c7763616f9f5a8302 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 16:13:28 -0600 Subject: [PATCH 339/858] Add a missing comment --- drivers/timers/pcf85263.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/timers/pcf85263.h b/drivers/timers/pcf85263.h index fac163fd94..f8e5b7e559 100644 --- a/drivers/timers/pcf85263.h +++ b/drivers/timers/pcf85263.h @@ -462,7 +462,7 @@ /* Reset */ -#define PCF85263_CTL_RESETS 0x2f /* +#define PCF85263_CTL_RESETS 0x2f /* Software reset control register */ # define PCF85263_CTL_CTS (1 << 0) /* Bit 0: Clear timestamp */ # define PCF85263_CTL_SR (1 << 3) /* Bit 3: Software reset */ # define PCF85263_CTL_CPR (1 << 7) /* Bit 7: Clear prescaler */ -- GitLab From 38c9d42e2187bccd31383640dbc610efeeee084c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 17:36:10 -0600 Subject: [PATCH 340/858] drivers/timers/pcf85263.c: Add a driver for the NXP PCF85263 I2C RTC --- ChangeLog | 3 + drivers/timers/Kconfig | 21 +- drivers/timers/Make.defs | 6 + drivers/timers/ds3231.c | 6 +- drivers/timers/pcf85263.c | 531 ++++++++++++++++++++++++++++++++ drivers/timers/pcf85263.h | 4 +- include/nuttx/timers/pcf85263.h | 90 ++++++ 7 files changed, 655 insertions(+), 6 deletions(-) create mode 100644 drivers/timers/pcf85263.c create mode 100644 include/nuttx/timers/pcf85263.h diff --git a/ChangeLog b/ChangeLog index 24b20e48c9..59ba77c5ca 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11129,4 +11129,7 @@ (2015-11-19). * drivers/mtd/w25.c: Add support for byte write mode. From Ken Peit (2015-11-20). + * drivers/timers/pcf85263.c and include/nuttx/times/pcf85263.h: Add + a driver for the NXP PCF85263 I2C RTC. Untested on initial commit + (2015-11-20). diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 333b65d2aa..af8b8a4a9e 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -181,9 +181,28 @@ endchoice # Maxim Integrated RTC config DS3231_I2C_FREQUENCY int "DS1307/DS323x I2C frequency" default 400000 - range 1 4000000 + range 1 400000 endif # RTC_DSXXXX + +config RTC_PCF85263 + bool "PCF85263 RTC Driver" + default n + select I2C + select I2C_TRANSFER + select RTC_EXTERNAL + select RTC_DATETIME + ---help--- + Enables support for the Maxim Integrated DS3231 I2C RTC timer. + +if RTC_PCF85263 + +config PCF85263_I2C_FREQUENCY + int "PCF85263 I2C frequency" + default 400000 + range 1 400000 + +endif # RTC_PCF85263 endif # RTC menuconfig WATCHDOG diff --git a/drivers/timers/Make.defs b/drivers/timers/Make.defs index 0707c244a6..7e3073d324 100644 --- a/drivers/timers/Make.defs +++ b/drivers/timers/Make.defs @@ -57,6 +57,12 @@ ifeq ($(CONFIG_RTC_DSXXXX),y) TMRVPATH = :timers endif +ifeq ($(CONFIG_RTC_PCF85263),y) + CSRCS += pcf85263.c + TMRDEPPATH = --dep-path timers + TMRVPATH = :timers +endif + ifeq ($(CONFIG_RTC_DRIVER),y) CSRCS += rtc.c TMRDEPPATH = --dep-path timers diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 5466c99f33..894c069d22 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -463,7 +463,7 @@ int up_rtc_settime(FAR const struct timespec *tp) return -EINVAL; } #endif - + rtc_dumptime(&tm, "New time"); /* Construct the message */ @@ -479,7 +479,7 @@ int up_rtc_settime(FAR const struct timespec *tp) buffer[2] = rtc_bin2bcd(newtm.tm_min); - /* Save hour (0-23) with 24-hour time indicatin */ + /* Save hour (0-23) with 24-hour time indication */ buffer[3] = rtc_bin2bcd(newtm.tm_hour) | DSXXXX_TIME_24; @@ -491,7 +491,7 @@ int up_rtc_settime(FAR const struct timespec *tp) buffer[4] = 1; #endif - /* Save the day of the week (1-31) */ + /* Save the day of the month (1-31) */ buffer[5] = rtc_bin2bcd(newtm.tm_mday); diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c new file mode 100644 index 0000000000..7eca679715 --- /dev/null +++ b/drivers/timers/pcf85263.c @@ -0,0 +1,531 @@ +/************************************************************************************ + * drivers/timers/pcf85263.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "pcf85263.h" + +#ifdef CONFIG_RTC_PCF85263 + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ +/* This RTC implementation supports only date/time RTC hardware */ + +#ifndef CONFIG_RTC_DATETIME +# error CONFIG_RTC_DATETIME must be set to use this driver +#endif + +#ifdef CONFIG_RTC_HIRES +# error CONFIG_RTC_HIRES must NOT be set with this driver +#endif + +#ifndef CONFIG_I2C_TRANSFER +# error CONFIG_I2C_TRANSFER is required by this driver +#endif + +#ifndef CONFIG_PCF85263_I2C_FREQUENCY +# error CONFIG_PCF85263_I2C_FREQUENCY is not configured +# define CONFIG_PCF85263_I2C_FREQUENCY 400000 +#endif + +#if CONFIG_PCF85263_I2C_FREQUENCY > 400000 +# error CONFIG_PCF85263_I2C_FREQUENCY is out of range +#endif + +#define PCF85263_I2C_ADDRESS 0x68 + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_RTC +#endif + +/* Debug ****************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC +# define rtcdbg dbg +# define rtcvdbg vdbg +# define rtclldbg lldbg +# define rtcllvdbg llvdbg +#else +# define rtcdbg(x...) +# define rtcvdbg(x...) +# define rtclldbg(x...) +# define rtcllvdbg(x...) +#endif + +/************************************************************************************ + * Priviate Types + ************************************************************************************/ +/* This structure describes the state of the PCF85263 chip. Only a single RTC is + * supported. + */ + +struct pcf85263_dev_s +{ + FAR struct i2c_dev_s *i2c; /* Contained reference to the I2C bus driver */ +}; + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +/* g_rtc_enabled is set true after the RTC has successfully initialized */ + +volatile bool g_rtc_enabled = false; + +/************************************************************************************ + * Private Data + ************************************************************************************/ +/* The state of the PCF85263 chip. Only a single RTC is supported */ + +static struct pcf85263_dev_s g_pcf85263; + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: rtc_dumptime + * + * Description: + * Show the broken out time. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC +static void rtc_dumptime(FAR struct tm *tp, FAR const char *msg) +{ + rtclldbg("%s:\n", msg); + rtclldbg(" tm_sec: %08x\n", tp->tm_sec); + rtclldbg(" tm_min: %08x\n", tp->tm_min); + rtclldbg(" tm_hour: %08x\n", tp->tm_hour); + rtclldbg(" tm_mday: %08x\n", tp->tm_mday); + rtclldbg(" tm_mon: %08x\n", tp->tm_mon); + rtclldbg(" tm_year: %08x\n", tp->tm_year); +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + rtclldbg(" tm_wday: %08x\n", tp->tm_wday); + rtclldbg(" tm_yday: %08x\n", tp->tm_yday); + rtclldbg(" tm_isdst: %08x\n", tp->tm_isdst); +#endif +} +#else +# define rtc_dumptime(tp, msg) +#endif + +/************************************************************************************ + * Name: rtc_bin2bcd + * + * Description: + * Converts a 2 digit binary to BCD format + * + * Input Parameters: + * value - The byte to be converted. + * + * Returned Value: + * The value in BCD representation + * + ************************************************************************************/ + +static uint8_t rtc_bin2bcd(int value) +{ + uint8_t msbcd = 0; + + while (value >= 10) + { + msbcd++; + value -= 10; + } + + return (msbcd << 4) | value; +} + +/************************************************************************************ + * Name: rtc_bcd2bin + * + * Description: + * Convert from 2 digit BCD to binary. + * + * Input Parameters: + * value - The BCD value to be converted. + * + * Returned Value: + * The value in binary representation + * + ************************************************************************************/ + +static int rtc_bcd2bin(uint8_t value) +{ + int tens = ((int)value >> 4) * 10; + return tens + (value & 0x0f); +} + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: pcf85263_rtc_initialize + * + * Description: + * Initialize the hardware RTC per the selected configuration. This function is + * called once during the OS initialization sequence by board-specific logic. + * + * After pcf85263_rtc_initialize() is called, the OS function clock_synchronize() + * should also be called to synchronize the system timer to a hardware RTC. That + * operation is normally performed automatically by the system during clock + * initialization. However, when an external RTC is used, the board logic will + * need to explicitly re-synchronize the system timer to the RTC when the RTC + * becomes available. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c) +{ + /* Remember the i2c device and claim that the RTC is enabled */ + + g_pcf85263.i2c = i2c; + g_rtc_enabled = true; + return OK; +} + +/************************************************************************************ + * Name: up_rtc_getdatetime + * + * Description: + * Get the current date and time from the date/time RTC. This interface + * is only supported by the date/time RTC hardware implementation. + * It is used to replace the system timer. It is only used by the RTOS during + * initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME + * are selected (and CONFIG_RTC_HIRES is not). + * + * NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That + * sub-second accuracy is lost in this interface. However, since the system time + * is reinitialized on each power-up/reset, there will be no timing inaccuracy in + * the long run. + * + * Input Parameters: + * tp - The location to return the high resolution time value. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int up_rtc_getdatetime(FAR struct tm *tp) +{ + struct i2c_msg_s msg[4]; + uint8_t secaddr; + uint8_t buffer[7]; + uint8_t seconds; + int ret; + + /* If this function is called before the RTC has been initialized (and it will be), + * then just return the data/time of the epoch, 12:00 am, Jan 1, 1970. + */ + + if (!g_rtc_enabled) + { + tp->tm_sec = 0; + tp->tm_min = 0; + tp->tm_hour = 0; + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + /* Jan 1, 1970 was a Thursday */ + + tp->tm_wday = 4; +#endif + + tp->tm_mday = 1; + tp->tm_mon = 0; + tp->tm_year = 70; + return -EAGAIN; + } + + /* Select to begin reading at the seconds register */ + + secaddr = PCF85263_RTC_SECONDS; + + msg[0].addr = PCF85263_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = &secaddr; + msg[0].length = 1; + + /* Set up to read 7 registers: secondss, minutes, hour, day-of-week, date, + * month, year + */ + + msg[1].addr = PCF85263_I2C_ADDRESS; + msg[1].flags = I2C_M_READ; + msg[1].buffer = buffer; + msg[1].length = 7; + + /* Read the seconds register again */ + + msg[2].addr = PCF85263_I2C_ADDRESS; + msg[2].flags = 0; + msg[2].buffer = &secaddr; + msg[2].length = 1; + + msg[3].addr = PCF85263_I2C_ADDRESS; + msg[3].flags = I2C_M_READ; + msg[3].buffer = &seconds; + msg[3].length = 1; + + /* Configure I2C before using it */ + + I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); + + /* Perform the transfer (This could be done with I2C_WRITEREAD()). The + * transfer may be performed repeatedly of the seconds values decreases, + * meaning that that was a rollover in the seconds. + */ + + do + { + ret = I2C_TRANSFER(g_pcf85263.i2c, msg, 4); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + return ret; + } + } + while ((buffer[0] & PCF85263_RTC_SECONDS_MASK) > + (seconds & PCF85263_RTC_SECONDS_MASK)); + + /* Format the return time */ + /* Return seconds (0-61) */ + + tp->tm_sec = rtc_bcd2bin(buffer[0] & PCF85263_RTC_SECONDS_MASK); + + /* Return minutes (0-59) */ + + tp->tm_min = rtc_bcd2bin(buffer[1] & PCF85263_RTC_MINUTES_MASK); + + /* Return hour (0-23). This assumes 24-hour time was set. */ + + tp->tm_hour = rtc_bcd2bin(buffer[2] & PCF85263_RTC_HOURS24_MASK); + + /* Return the day of the month (1-31) */ + + tp->tm_mday = rtc_bcd2bin(buffer[3] & PCF85263_RTC_DAYS_MASK); + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + /* Return the day of the week (0-6) */ + + tp->tm_wday = (rtc_bcd2bin(buffer[4]) & PCF85263_RTC_WEEKDAYS_MASK); +#endif + + /* Return the month (0-11) */ + + tp->tm_mon = rtc_bcd2bin(buffer[5] & PCF85263_RTC_MONTHS_MASK) - 1; + + /* Return the years since 1900. The RTC will hold years since 1968 (a leap year + * like 2000). + */ + + tp->tm_year = rtc_bcd2bin(buffer[6]) + 68; + + rtc_dumptime(tp, "Returning"); + return OK; +} + +/************************************************************************************ + * Name: up_rtc_settime + * + * Description: + * Set the RTC to the provided time. All RTC implementations must be able to + * set their time based on a standard timespec. + * + * Input Parameters: + * tp - the time to use + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +int up_rtc_settime(FAR const struct timespec *tp) +{ + struct i2c_msg_s msg[3]; + struct tm newtm; + time_t newtime; + uint8_t buffer[8]; + uint8_t seconds; + int ret; + + /* If this function is called before the RTC has been initialized then just return + * an error. + */ + + if (!g_rtc_enabled) + { + return -EAGAIN; + } + + rtc_dumptime(tp, "Setting time"); + + /* Get the broken out time */ + + newtime = (time_t)tp->tv_sec; + if (tp->tv_nsec >= 500000000) + { + /* Round up */ + + newtime++; + } + + #ifdef CONFIG_LIBC_LOCALTIME + if (localtime_r(&newtime, &newtm) == NULL) + { + rtcdbg("ERROR: localtime_r failed\n") + return -EINVAL; + } +#else + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcdbg("ERROR: gmtime_r failed\n") + return -EINVAL; + } +#endif + + rtc_dumptime(&tm, "New time"); + + /* Construct the message */ + /* Write starting with the seconds regiser */ + + buffer[0] = PCF85263_RTC_SECONDS; + + /* Save seconds (0-59) converted to BCD */ + + buffer[1] = rtc_bin2bcd(newtm.tm_sec); + + /* Save minutes (0-59) converted to BCD */ + + buffer[2] = rtc_bin2bcd(newtm.tm_min); + + /* Save hour (0-23) with 24-hour time indication */ + + buffer[3] = rtc_bin2bcd(newtm.tm_hour); + + /* Save the day of the month (1-31) */ + + buffer[4] = rtc_bin2bcd(newtm.tm_mday); + + /* Save the day of the week (1-7) */ + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + buffer[5] = rtc_bin2bcd(newtm.tm_wday); +#else + buffer[5] = 0; +#endif + + /* Save the month (1-12) */ + + buffer[6] = rtc_bin2bcd(newtm.tm_mon + 1); + + /* Save the year. Use years since 1968 (a leap year like 2000) */ + + buffer[7] = rtc_bin2bcd(newtm.tm_year - 68); + + /* Setup the I2C message */ + + msg[0].addr = PCF85263_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = buffer; + msg[0].length = 8; + + /* Read back the seconds register */ + + msg[1].addr = PCF85263_I2C_ADDRESS; + msg[1].flags = 0; + msg[1].buffer = buffer; + msg[1].length = 1; + + msg[2].addr = PCF85263_I2C_ADDRESS; + msg[2].flags = I2C_M_READ; + msg[2].buffer = &seconds; + msg[2].length = 1; + + /* Configure I2C before using it */ + + I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); + + /* Perform the transfer (This could be done with I2C_READ). This transfer + * will be repeated if the seconds count rolls over to a smaller value + * while writing. + */ + + do + { + ret = I2C_TRANSFER(g_pcf85263.i2c, msg, 3); + if (ret < 0) + { + rtcdbg("ERROR: I2C_TRANSFER failed: %d\n", ret) + return ret; + } + } + while ((buffer[1] & PCF85263_RTC_SECONDS_MASK) > + (seconds & PCF85263_RTC_SECONDS_MASK)); + + return OK; +} + +#endif /* CONFIG_RTC_PCF85263 */ diff --git a/drivers/timers/pcf85263.h b/drivers/timers/pcf85263.h index f8e5b7e559..344a3f2873 100644 --- a/drivers/timers/pcf85263.h +++ b/drivers/timers/pcf85263.h @@ -357,7 +357,7 @@ # define PCF85263_CTL_OSC_CLKIV (1 << 7) /* Bit 7: Output clock inversion */ #define PCF85263_CTL_BATTERY_SWITCH 0x26 /* Battery switch control register */ -# define PCF85263_CTL_BATTERY_BSTH (1 << 0) /* Bit 0: +# define PCF85263_CTL_BATTERY_BSTH (1 << 0) /* Bit 0: Threshold voltage control */ # define PCF85263_CTL_BATTERY_BSM_SHIFT (1) /* Bits 1-2: Battery switch mode bits */ # define PCF85263_CTL_BATTERY_BSM_MASK (3 << PCF85263_CTL_BATTERY_BSM_SHIFT) # define PCF85263_CTL_BATTERY_BSM_VTH (0 << PCF85263_CTL_BATTERY_BSM_SHIFT) /* Switching at the Vth level */ @@ -453,7 +453,7 @@ # define PCF85263_CTL_WDR_SHIFT (2) /* Bits 2-6: Watchdog register bits */ # define PCF85263_CTL_WDR_MASK (31 << PCF85263_CTL_WDR_SHIFT) # define PCF85263_CTL_WDR(n) ((uint9_t)(n) << PCF85263_CTL_WDR_SHIFT) -# define PCF85263_CTL_WDM (1 << 7) /* Bit 7: Watchdog mode +# define PCF85263_CTL_WDM (1 << 7) /* Bit 7: Watchdog mode */ /* Stop */ diff --git a/include/nuttx/timers/pcf85263.h b/include/nuttx/timers/pcf85263.h new file mode 100644 index 0000000000..fdda2b815e --- /dev/null +++ b/include/nuttx/timers/pcf85263.h @@ -0,0 +1,90 @@ +/**************************************************************************** + * include/nuttx/timers/pcf85263.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_TIMERS_PCF85263_H +#define __INCLUDE_NUTTX_TIMERS_PCF85263_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_RTC_PCF85263 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Name: pcf85263_rtc_initialize + * + * Description: + * Initialize the hardware RTC per the selected configuration. This function is + * called once during the OS initialization sequence by board-specific logic. + * + * After pcf85263_rtc_initialize() is called, the OS function clock_synchronize() + * should also be called to synchronize the system timer to a hardware RTC. That + * operation is normally performed automatically by the system during clock + * initialization. However, when an external RTC is used, the board logic will + * need to explicitly re-synchronize the system timer to the RTC when the RTC + * becomes available. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ************************************************************************************/ + +struct i2c_dev_s; /* Forward reference */ +int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_RTC_PCF85263 */ +#endif /* __INCLUDE_NUTTX_TIMERS_PCF85263_H */ -- GitLab From 294950ea3da179621ab3209931fbdf6f4b33ffba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 20 Nov 2015 17:39:41 -0600 Subject: [PATCH 341/858] PCF85263: Need to clear the 100ths of second register when setting the time --- drivers/timers/pcf85263.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 7eca679715..b2ee0bf172 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -407,7 +407,7 @@ int up_rtc_settime(FAR const struct timespec *tp) struct i2c_msg_s msg[3]; struct tm newtm; time_t newtime; - uint8_t buffer[8]; + uint8_t buffer[9]; uint8_t seconds; int ret; @@ -451,46 +451,50 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Construct the message */ /* Write starting with the seconds regiser */ - buffer[0] = PCF85263_RTC_SECONDS; + buffer[0] = PCF85263_RTC_100TH_SECONDS; + + /* Clear the 100ths of seconds */ + + buffer[1] = 0; /* Save seconds (0-59) converted to BCD */ - buffer[1] = rtc_bin2bcd(newtm.tm_sec); + buffer[2] = rtc_bin2bcd(newtm.tm_sec); /* Save minutes (0-59) converted to BCD */ - buffer[2] = rtc_bin2bcd(newtm.tm_min); + buffer[3] = rtc_bin2bcd(newtm.tm_min); /* Save hour (0-23) with 24-hour time indication */ - buffer[3] = rtc_bin2bcd(newtm.tm_hour); + buffer[4] = rtc_bin2bcd(newtm.tm_hour); /* Save the day of the month (1-31) */ - buffer[4] = rtc_bin2bcd(newtm.tm_mday); + buffer[5] = rtc_bin2bcd(newtm.tm_mday); /* Save the day of the week (1-7) */ #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) - buffer[5] = rtc_bin2bcd(newtm.tm_wday); + buffer[6] = rtc_bin2bcd(newtm.tm_wday); #else - buffer[5] = 0; + buffer[6] = 0; #endif /* Save the month (1-12) */ - buffer[6] = rtc_bin2bcd(newtm.tm_mon + 1); + buffer[7] = rtc_bin2bcd(newtm.tm_mon + 1); /* Save the year. Use years since 1968 (a leap year like 2000) */ - buffer[7] = rtc_bin2bcd(newtm.tm_year - 68); + buffer[8] = rtc_bin2bcd(newtm.tm_year - 68); /* Setup the I2C message */ msg[0].addr = PCF85263_I2C_ADDRESS; msg[0].flags = 0; msg[0].buffer = buffer; - msg[0].length = 8; + msg[0].length = 9; /* Read back the seconds register */ @@ -522,7 +526,7 @@ int up_rtc_settime(FAR const struct timespec *tp) return ret; } } - while ((buffer[1] & PCF85263_RTC_SECONDS_MASK) > + while ((buffer[2] & PCF85263_RTC_SECONDS_MASK) > (seconds & PCF85263_RTC_SECONDS_MASK)); return OK; -- GitLab From 89144007506f462a26da6b9c59aa52db08a0abc9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 07:14:36 -0600 Subject: [PATCH 342/858] PCF85163: Correct I2C address --- arch | 2 +- configs | 2 +- drivers/timers/pcf85263.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 676240da11..b417eaa97e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 676240da1156f13127dea95216f164d6ab4a766b +Subproject commit b417eaa97e68b4dfe81bb3515a68d53ffa00233b diff --git a/configs b/configs index 2a5172fbb3..680f486f3d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2a5172fbb37ada3f8119c99af34a1bbf70120ee3 +Subproject commit 680f486f3d31e64277ea651abf4daae13e62f188 diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index b2ee0bf172..8d5db98e6d 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -79,7 +79,7 @@ # error CONFIG_PCF85263_I2C_FREQUENCY is out of range #endif -#define PCF85263_I2C_ADDRESS 0x68 +#define PCF85263_I2C_ADDRESS 0x51 #ifndef CONFIG_DEBUG # undef CONFIG_DEBUG_RTC -- GitLab From f03e435e439b92affa1fb7e2793a712289f0c3b4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 09:15:12 -0600 Subject: [PATCH 343/858] drivers/bch: Add support for delayed unlinking of BCH driver --- drivers/bch/{bch_internal.h => bch.h} | 15 ++-- drivers/bch/bchdev_driver.c | 102 +++++++++++++++++++++++--- drivers/bch/bchdev_register.c | 2 +- drivers/bch/bchdev_unregister.c | 2 +- drivers/bch/bchlib_cache.c | 2 +- drivers/bch/bchlib_read.c | 2 +- drivers/bch/bchlib_sem.c | 2 +- drivers/bch/bchlib_setup.c | 2 +- drivers/bch/bchlib_teardown.c | 2 +- drivers/bch/bchlib_write.c | 2 +- 10 files changed, 109 insertions(+), 24 deletions(-) rename drivers/bch/{bch_internal.h => bch.h} (90%) diff --git a/drivers/bch/bch_internal.h b/drivers/bch/bch.h similarity index 90% rename from drivers/bch/bch_internal.h rename to drivers/bch/bch.h index 653a2767b0..5463518349 100644 --- a/drivers/bch/bch_internal.h +++ b/drivers/bch/bch.h @@ -1,7 +1,7 @@ /**************************************************************************** - * drivers/bch/bch_internal.h + * drivers/bch/bch.h * - * Copyright (C) 2008-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __FS_BCH_INTERNAL_H -#define __FS_BCH_INTERNAL_H +#ifndef __DRIVERS_BCH_BCH_H +#define __DRIVERS_BCH_BCH_H /**************************************************************************** * Included Files @@ -67,8 +67,9 @@ struct bchlib_s size_t sector; /* The current sector in the buffer */ uint16_t sectsize; /* The size of one sector on the device */ uint8_t refs; /* Number of references */ - bool dirty; /* Data has been written to the buffer */ - bool readonly; /* true: Only read operations are supported */ + bool dirty; /* true: Data has been written to the buffer */ + bool readonly; /* true: Only read operations are supported */ + bool unlinked; /* true: The driver has been unlinked */ FAR uint8_t *buffer; /* One sector buffer */ #if defined(CONFIG_BCH_ENCRYPTION) @@ -103,4 +104,4 @@ EXTERN int bchlib_readsector(FAR struct bchlib_s *bch, size_t sector); } #endif -#endif /* __FS_BCH_INTERNAL_H */ +#endif /* __DRIVERS_BCH_BCH_H */ diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 14ee267d99..577128b039 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -58,7 +58,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Pre-processor Definitions @@ -77,6 +77,9 @@ static ssize_t bch_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int bch_unlink(FAR struct inode *inode); +#endif /**************************************************************************** * Public Data @@ -84,14 +87,17 @@ static int bch_ioctl(FAR struct file *filep, int cmd, const struct file_operations bch_fops = { - bch_open, /* open */ - bch_close, /* close */ - bch_read, /* read */ - bch_write, /* write */ - bch_seek, /* seek */ - bch_ioctl /* ioctl */ + bch_open, /* open */ + bch_close, /* close */ + bch_read, /* read */ + bch_write, /* write */ + bch_seek, /* seek */ + bch_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , 0 /* poll */ + , 0 /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , bch_unlink /* unlink */ #endif }; @@ -152,7 +158,8 @@ static int bch_close(FAR struct file *filep) (void)bchlib_flushsector(bch); /* Decrement the reference count (I don't use bchlib_decref() because I - * want the entire close operation to be atomic wrt other driver operations. + * want the entire close operation to be atomic wrt other driver + * operations. */ if (bch->refs == 0) @@ -162,6 +169,30 @@ static int bch_close(FAR struct file *filep) else { bch->refs--; + + /* If the reference count decremented to zero AND if the character + * driver has been unlinked, then teardown the BCH device now. + */ + + if (bch->refs == 0 && bch->unlinked) + { + /* Tear the driver down now. */ + + ret = bchlib_teardown((FAR void *)bch); + + /* bchlib_teardown() would only fail if there are outstanding + * references on the device. Since we know that is not true, it + * should not fail at all. + */ + + DEBUGASSERT(ret >= 0); + if (ret >= 0) + { + /* Return without releasing the stale semaphore */ + + return OK; + } + } } bchlib_semgive(bch); @@ -349,6 +380,59 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return ret; } +/**************************************************************************** + * Name: bch_unlink + * + * Handle unlinking of the BCH device + * + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int bch_unlink(FAR struct inode *inode) +{ + FAR struct bchlib_s *bch; + int ret = OK; + + DEBUGASSERT(inode && inode->i_private); + bch = (FAR struct bchlib_s *)inode->i_private; + + /* Get exclusive access to the BCH device */ + + bchlib_semtake(bch); + + /* Indicate that the driver has been unlinked */ + + bch->unlinked = true; + + /* If there are no open references to the drvier then teardown the BCH + * device now. + */ + + if (bch->refs == 0) + { + /* Tear the driver down now. */ + + ret = bchlib_teardown((FAR void *)bch); + + /* bchlib_teardown() would only fail if there are outstanding + * references on the device. Since we know that is not true, it + * should not fail at all. + */ + + DEBUGASSERT(ret >= 0); + if (ret >= 0) + { + /* Return without releasing the stale semaphore */ + + return OK; + } + } + + bchlib_semgive(bch); + return ret; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/drivers/bch/bchdev_register.c b/drivers/bch/bchdev_register.c index 924977371e..139c292576 100644 --- a/drivers/bch/bchdev_register.c +++ b/drivers/bch/bchdev_register.c @@ -44,7 +44,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Pre-processor Definitions diff --git a/drivers/bch/bchdev_unregister.c b/drivers/bch/bchdev_unregister.c index 8c7360882b..0c6a35d4b1 100644 --- a/drivers/bch/bchdev_unregister.c +++ b/drivers/bch/bchdev_unregister.c @@ -52,7 +52,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Pre-processor Definitions diff --git a/drivers/bch/bchlib_cache.c b/drivers/bch/bchlib_cache.c index 009a3eb631..8ad543b4b0 100644 --- a/drivers/bch/bchlib_cache.c +++ b/drivers/bch/bchlib_cache.c @@ -47,7 +47,7 @@ #include -#include "bch_internal.h" +#include "bch.h" #if defined(CONFIG_BCH_ENCRYPTION) # include diff --git a/drivers/bch/bchlib_read.c b/drivers/bch/bchlib_read.c index e275d5943b..d534d84919 100644 --- a/drivers/bch/bchlib_read.c +++ b/drivers/bch/bchlib_read.c @@ -48,7 +48,7 @@ #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Private Types diff --git a/drivers/bch/bchlib_sem.c b/drivers/bch/bchlib_sem.c index 1698ed0a54..ff221d934f 100644 --- a/drivers/bch/bchlib_sem.c +++ b/drivers/bch/bchlib_sem.c @@ -43,7 +43,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Pre-processor Definitions diff --git a/drivers/bch/bchlib_setup.c b/drivers/bch/bchlib_setup.c index 8dfcbbbf5b..6ec7a878a6 100644 --- a/drivers/bch/bchlib_setup.c +++ b/drivers/bch/bchlib_setup.c @@ -52,7 +52,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Private Types diff --git a/drivers/bch/bchlib_teardown.c b/drivers/bch/bchlib_teardown.c index 8d1f45ed9b..d97d3b8ffc 100644 --- a/drivers/bch/bchlib_teardown.c +++ b/drivers/bch/bchlib_teardown.c @@ -47,7 +47,7 @@ #include #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Private Types diff --git a/drivers/bch/bchlib_write.c b/drivers/bch/bchlib_write.c index 2336b11dda..b1636c6d45 100644 --- a/drivers/bch/bchlib_write.c +++ b/drivers/bch/bchlib_write.c @@ -49,7 +49,7 @@ #include -#include "bch_internal.h" +#include "bch.h" /**************************************************************************** * Private Types -- GitLab From 968de101f0bfffca811a88bf26bfd6b1cc7aec70 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 10:12:21 -0600 Subject: [PATCH 344/858] Eliminate a warning --- fs/binfs/fs_binfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 8cd8b7e5c5..726a68cbef 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -171,7 +171,7 @@ static int binfs_open(FAR struct file *filep, FAR const char *relpath, /* Save the index as the open-specific state in filep->f_priv */ - filep->f_priv = (FAR void *)index; + filep->f_priv = (FAR void *)((uintptr_t)index); return OK; } @@ -223,7 +223,7 @@ static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } else { - *ptr = builtin_getname((int)filep->f_priv); + *ptr = builtin_getname((int)((uintptr_t)filep->f_priv)); ret = OK; } } -- GitLab From dcb85af387ff27de15de436d49e8593bfbe6e8dc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 10:14:01 -0600 Subject: [PATCH 345/858] Add logic to automatically wrap a block device as a BCH device with no visible character device --- drivers/bch/bchdev_driver.c | 2 +- fs/driver/Make.defs | 5 +- fs/driver/fs_blockproxy.c | 246 ++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 fs/driver/fs_blockproxy.c diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 577128b039..198cd334b3 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/bch/bchdev_driver.c * - * Copyright (C) 2008-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/fs/driver/Make.defs b/fs/driver/Make.defs index 7cf8c344b3..e280ea1580 100644 --- a/fs/driver/Make.defs +++ b/fs/driver/Make.defs @@ -41,10 +41,13 @@ CSRCS += fs_registerdriver.c fs_unregisterdriver.c # Don't build-in block driver support if there are no mountpoints - ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c + +ifneq ($(CONFIG_DISABLE_PSEUDOFS_OPERATIONS),y) +CSRCS += fs_blockproxy.c +endif endif # System logging to a character device (or file) diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c new file mode 100644 index 0000000000..73e7285795 --- /dev/null +++ b/fs/driver/fs_blockproxy.c @@ -0,0 +1,246 @@ +/**************************************************************************** + * fs/driver/fs_blockproxy.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \ + !defined(CONFIG_DISABLE_MOUNTPOINT) + +/**************************************************************************** + * Pre-processor oDefinitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint32_t g_devno; +static sem_t g_devno_sem = SEM_INITIALIZER(1); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: unique_chardev + * + * Description: + * Create a unique temporary device name in the /dev/ directory of the + * psuedo-file system. We cannot use mktemp for this because it will + * attempt to open() the file. + * + * Input parameters: + * None + * + * Returned Value: + * The allocated path to the device. This must be released by the caller + * to prevent memory links. NULL will be returned only the case where + * we fail to allocate memory. + * + ****************************************************************************/ + +static FAR char *unique_chardev(void) +{ + struct stat statbuf; + char devbuf[16]; + uint32_t devno; + int ret; + + /* Loop until we get a unique device name */ + + for (; ; ) + { + /* Get the semaphore protecting the path number */ + + while (sem_wait(&g_devno_sem) < 0) + { + DEBUGASSERT(errno == EINTR); + } + + /* Get the next device number and release the semaphore */ + + devno = ++g_devno; + sem_post(&g_devno_sem); + + /* Construct the full device number */ + + devno &= 0xffffff; + snprintf(devbuf, 16, "/dev/tmp%06lx", (unsigned long)devno); + + /* Make sure that file name is not in use */ + + ret = stat(devbuf, &statbuf); + if (ret < 0) + { + DEBUGASSERT(errno == ENOENT); + return strdup(devbuf); + } + + /* It is in use, try again */ + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: block_proxy + * + * Description: + * Create a temporary char driver using drivers/bch that mediate character + * oriented accessed to the block driver. + * + * Input parameters: + * blkdev - The path to the block driver + * mode - Character driver access priviledges + * + * Returned Value: + * If positive, non-zero file descriptor is returned on success. This + * is the file descriptor of the nameless character driver that mediates + * accesses to the block driver. + * + * Errors that may be returned: + * + * ENOMEM - Failed to create a temporay path name. + * + * Plus: + * + * - Errors reported from bchdev_register() + * - Errors reported from open() or unlink() + * + ****************************************************************************/ + +int block_proxy(FAR const char *blkdev, mode_t mode) +{ + FAR char *chardev; + bool readonly; + int ret; + int fd; + + DEBUGASSERT(blkdev); + DEBUGASSERT((mode & (O_CREAT | O_EXCL | O_APPEND | O_TRUNC)) == 0); + + /* Create a unique temporary file name for the character device */ + + chardev = unique_chardev(); + if (chardev == NULL) + { + fdbg("ERROR: Failed to create temporary device name\n"); + return -ENOMEM; + } + + /* Should this character driver be read-only? */ + + readonly = ((mode & O_WROK) == 0); + + /* Wrap the block driver with an instance of the BCH driver */ + + ret = bchdev_register(blkdev, chardev, readonly); + if (ret < 0) + { + fdbg("ERROR: bchdev_register(%s, %s) failed: %d\n", + blkdev, chardev, ret); + + goto errout_with_chardev; + } + + /* Open the newly created character driver */ + + mode &= ~(O_CREAT | O_EXCL | O_APPEND | O_TRUNC); + fd = open(chardev, mode); + if (fd < 0) + { + ret = -errno; + fdbg("ERROR: Failed to open %s: %d\n", chardev, ret); + goto errout_with_bchdev; + } + + /* Unlink the character device name. The driver instance will persist, + * provided that CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y (otherwise, we have + * a problem here!) + */ + + ret = unlink(chardev); + if (ret < 0) + { + ret = -errno; + fdbg("ERROR: Failed to unlink %s: %d\n", chardev, ret); + } + + /* Free the allocate character driver name and return the open file + * descriptor. + */ + + kmm_free(chardev); + return fd; + +errout_with_bchdev: + (void)unlink(chardev); + +errout_with_chardev: + kmm_free(chardev); + return ret; +} + +#endif /* !CONFIG_DISABLE_PSEUDOFS_OPERATIONS && !CONFIG_DISABLE_MOUNTPOINT */ -- GitLab From 84a5f846c952785afc96a6f75b4db418e4511cff Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 11:24:55 -0600 Subject: [PATCH 346/858] open() has been extended. You can now open block drivers and access them just as you can character drivers. For example, you can hexdump a block device. --- ChangeLog | 7 ++++++- fs/driver/driver.h | 35 +++++++++++++++++++++++++++++++++++ fs/driver/fs_blockproxy.c | 14 +++++++------- fs/vfs/fs_open.c | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59ba77c5ca..cd40ad5570 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11132,4 +11132,9 @@ * drivers/timers/pcf85263.c and include/nuttx/times/pcf85263.h: Add a driver for the NXP PCF85263 I2C RTC. Untested on initial commit (2015-11-20). - + * fs/driver/fs_blockproxy.c: Add logic to create a temporary char driver + using drivers/bch to mediate character oriented accessed to a block + driver (2015-11-21). + * fs/vfs/open.c: If the use attempts to open a block driver, use + block_proxy() to insert a character driver conversion layer in front + of the block driver (2015-11-21). diff --git a/fs/driver/driver.h b/fs/driver/driver.h index 066d3ebd64..72ba7318a0 100644 --- a/fs/driver/driver.h +++ b/fs/driver/driver.h @@ -91,8 +91,43 @@ extern "C" * ****************************************************************************/ +#ifndef CONFIG_DISABLE_MOUNTPOINT int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode **ppinode); +#endif + +/* fs/drivers/fs_blockproxy.c ***********************************************/ +/**************************************************************************** + * Name: block_proxy + * + * Description: + * Create a temporary char driver using drivers/bch to mediate character + * oriented accessed to the block driver. + * + * Input parameters: + * blkdev - The path to the block driver + * oflags - Character driver open flags + * + * Returned Value: + * If positive, non-zero file descriptor is returned on success. This + * is the file descriptor of the nameless character driver that mediates + * accesses to the block driver. + * + * Errors that may be returned: + * + * ENOMEM - Failed to create a temporay path name. + * + * Plus: + * + * - Errors reported from bchdev_register() + * - Errors reported from open() or unlink() + * + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \ + !defined(CONFIG_DISABLE_MOUNTPOINT) +int block_proxy(FAR const char *blkdev, int oflags); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c index 73e7285795..afabd1880f 100644 --- a/fs/driver/fs_blockproxy.c +++ b/fs/driver/fs_blockproxy.c @@ -148,12 +148,12 @@ static FAR char *unique_chardev(void) * Name: block_proxy * * Description: - * Create a temporary char driver using drivers/bch that mediate character + * Create a temporary char driver using drivers/bch to mediate character * oriented accessed to the block driver. * * Input parameters: * blkdev - The path to the block driver - * mode - Character driver access priviledges + * oflags - Character driver open flags * * Returned Value: * If positive, non-zero file descriptor is returned on success. This @@ -171,7 +171,7 @@ static FAR char *unique_chardev(void) * ****************************************************************************/ -int block_proxy(FAR const char *blkdev, mode_t mode) +int block_proxy(FAR const char *blkdev, int oflags) { FAR char *chardev; bool readonly; @@ -179,7 +179,7 @@ int block_proxy(FAR const char *blkdev, mode_t mode) int fd; DEBUGASSERT(blkdev); - DEBUGASSERT((mode & (O_CREAT | O_EXCL | O_APPEND | O_TRUNC)) == 0); + DEBUGASSERT((oflags & (O_CREAT | O_EXCL | O_APPEND | O_TRUNC)) == 0); /* Create a unique temporary file name for the character device */ @@ -192,7 +192,7 @@ int block_proxy(FAR const char *blkdev, mode_t mode) /* Should this character driver be read-only? */ - readonly = ((mode & O_WROK) == 0); + readonly = ((oflags & O_WROK) == 0); /* Wrap the block driver with an instance of the BCH driver */ @@ -207,8 +207,8 @@ int block_proxy(FAR const char *blkdev, mode_t mode) /* Open the newly created character driver */ - mode &= ~(O_CREAT | O_EXCL | O_APPEND | O_TRUNC); - fd = open(chardev, mode); + oflags &= ~(O_CREAT | O_EXCL | O_APPEND | O_TRUNC); + fd = open(chardev, oflags); if (fd < 0) { ret = -errno; diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index ae903970fe..b0a5ca2c50 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -130,9 +130,42 @@ int open(const char *path, int oflags, ...) goto errout; } - /* Verify that the inode is valid and either a "normal" character driver or a - * mountpoint. We specifically exclude block drivers and and "special" - * inodes (semaphores, message queues, shared memory). +#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \ + !defined(CONFIG_DISABLE_MOUNTPOINT) + /* If the inode is block driver, then we may return a character driver + * proxy for the block driver. block_proxy() will instantiate a BCH + * character driver wrapper around the block driver, open(), then + * unlink() the character driver. On success, block_proxy() will + * return the file descriptor of the opened character driver. + * + * NOTE: This will recurse to open the character driver proxy. + */ + + if (INODE_IS_BLOCK(inode)) + { + /* Release the inode reference */ + + inode_release(inode); + + /* Get the file descriptor of the opened character driver proxy */ + + fd = block_proxy(path, oflags); + if (fd < 0) + { + ret = fd; + goto errout; + } + + /* Return the file descriptor */ + + return fd; + } + else +#endif + + /* Verify that the inode is either a "normal" character driver or a + * mountpoint. We specifically "special" inodes (semaphores, message + * queues, shared memory). */ #ifndef CONFIG_DISABLE_MOUNTPOINT -- GitLab From 23a62dec5012947284c820abd05b332bfb9520eb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 Nov 2015 11:58:26 -0600 Subject: [PATCH 347/858] Update TODO --- TODO | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TODO b/TODO index c6c07c00f3..4fae0d8c11 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 24, 2015) +NuttX TODO List (Last updated November 21, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -442,8 +442,6 @@ o Kernel/Protected Build losetup losetup(), loteardown() mkfatfs mkfatfs mkrd ramdisk_register() - dd bchlib_setup(), bchlib_read(), bchlib_write(), - bchlib_teardown() ps sched_foreach() ifup netdev_foreach() ifdown netdev_foreach() -- GitLab From ca182201e44b64aa5430e627d8a6fc59df4e6f98 Mon Sep 17 00:00:00 2001 From: Slimane Bendelloul Date: Sat, 21 Nov 2015 15:06:05 -0500 Subject: [PATCH 348/858] Fixed a mismatching between the drawlinewindow's prototype and it's implementation --- libnx/nxtk/nxtk_drawlinewindow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnx/nxtk/nxtk_drawlinewindow.c b/libnx/nxtk/nxtk_drawlinewindow.c index 4c4dd49d07..a616ce1320 100644 --- a/libnx/nxtk/nxtk_drawlinewindow.c +++ b/libnx/nxtk/nxtk_drawlinewindow.c @@ -94,7 +94,7 @@ int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector, nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES], - bool caps) + uint8_t caps) { struct nxgl_trapezoid_s trap[3]; -- GitLab From 006528b144e8c624bb1303fa5ee6943ba58c3b50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 08:38:55 -0600 Subject: [PATCH 349/858] Add support for freopen() --- ChangeLog | 2 + drivers/pipes/pipe_common.c | 2 +- fs/vfs/fs_open.c | 1 + include/fcntl.h | 2 +- include/stdio.h | 3 +- libc/lib_internal.h | 6 +- libc/stdio/Make.defs | 17 +++-- libc/stdio/lib_fileno.c | 1 + libc/stdio/lib_fopen.c | 130 +++++++++++++++----------------- libc/stdio/lib_freopen.c | 143 ++++++++++++++++++++++++++++++++++++ 10 files changed, 226 insertions(+), 81 deletions(-) create mode 100644 libc/stdio/lib_freopen.c diff --git a/ChangeLog b/ChangeLog index cd40ad5570..d3a5f291cb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11138,3 +11138,5 @@ * fs/vfs/open.c: If the use attempts to open a block driver, use block_proxy() to insert a character driver conversion layer in front of the block driver (2015-11-21). + * libc/stdio/lib_freopen.c and include/stdio.h: Add support for + freopen() (2015-11-22). diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 37e1fc18cd..346bb5dc69 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -371,7 +371,7 @@ int pipecommon_close(FAR struct file *filep) } } - /* What is the buffer management policy? Do we free the buffe when the + /* What is the buffer management policy? Do we free the buffer when the * last client closes the pipe policy 0, or when the buffer becomes empty. * In the latter case, the buffer data will remain valid and can be * obtained when the pipe is re-opened. diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index b0a5ca2c50..81a2ef7f7c 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -51,6 +51,7 @@ #include #include "inode/inode.h" +#include "driver/driver.h" /**************************************************************************** * Private Functions diff --git a/include/fcntl.h b/include/fcntl.h index 6bec04f0ac..6145c11fd6 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -102,7 +102,7 @@ #define F_GETSIG 6 /* Get the signal sent */ #define F_NOTIFY 7 /* Provide notification when directory referred to by fd changes (linux)*/ #define F_SETFD 8 /* Set the file descriptor flags to value */ -#define F_SETFL 9 /* Set the file status flags to the value */ +#define F_SETFL 9 /* Set the file status flags to the value */ #define F_SETLEASE 10 /* Set or remove file lease (linux) */ #define F_SETLK 11 /* Acquire or release a lock on range of bytes */ #define F_SETLKW 12 /* Like F_SETLK, but wait for lock to become available */ diff --git a/include/stdio.h b/include/stdio.h index 057a58c9a8..d8f0c3479a 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/stdio.h * - * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -147,6 +147,7 @@ int fprintf(FAR FILE *stream, FAR const char *format, ...); int fputc(int c, FAR FILE *stream); int fputs(FAR const char *s, FAR FILE *stream); size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream); +FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream); int fseek(FAR FILE *stream, long int offset, int whence); int fsetpos(FAR FILE *stream, FAR fpos_t *pos); long ftell(FAR FILE *stream); diff --git a/libc/lib_internal.h b/libc/lib_internal.h index c4610dfe62..29bbd136f5 100644 --- a/libc/lib_internal.h +++ b/libc/lib_internal.h @@ -155,7 +155,11 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve); #endif -/* Defined in lib_libwrite.c */ +/* Defined in lib_fopen.c */ + +int lib_mode2oflags(FAR const char *mode); + +/* Defined in lib_libfwrite.c */ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream); diff --git a/libc/stdio/Make.defs b/libc/stdio/Make.defs index fbda15caaa..595a222b27 100644 --- a/libc/stdio/Make.defs +++ b/libc/stdio/Make.defs @@ -56,14 +56,15 @@ CSRCS += lib_rawsostream.c ifneq ($(CONFIG_NFILE_STREAMS),0) -CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c -CSRCS += lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c -CSRCS += lib_gets_s.c lib_gets.c lib_libfgets.c lib_fwrite.c lib_libfwrite.c -CSRCS += lib_fflush.c lib_libflushall.c lib_libfflush.c lib_rdflush.c -CSRCS += lib_wrflush.c lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c -CSRCS += lib_vprintf.c lib_fprintf.c lib_vfprintf.c lib_stdinstream.c -CSRCS += lib_stdoutstream.c lib_stdsistream.c lib_stdsostream.c lib_perror.c -CSRCS += lib_feof.c lib_ferror.c lib_clearerr.c +CSRCS += lib_fopen.c lib_freopen.c lib_fclose.c lib_fread.c lib_libfread.c +CSRCS += lib_fseek.c lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c +CSRCS += lib_fgets.c lib_gets_s.c lib_gets.c lib_libfgets.c lib_fwrite.c +CSRCS += lib_libfwrite.c lib_fflush.c lib_libflushall.c lib_libfflush.c +CSRCS += lib_rdflush.c lib_wrflush.c lib_fputc.c lib_puts.c lib_fputs.c +CSRCS += lib_ungetc.c lib_vprintf.c lib_fprintf.c lib_vfprintf.c +CSRCS += lib_stdinstream.c lib_stdoutstream.c lib_stdsistream.c +CSRCS += lib_stdsostream.c lib_perror.c lib_feof.c lib_ferror.c +CSRCS += lib_clearerr.c endif diff --git a/libc/stdio/lib_fileno.c b/libc/stdio/lib_fileno.c index 555d288759..73e6951da0 100644 --- a/libc/stdio/lib_fileno.c +++ b/libc/stdio/lib_fileno.c @@ -53,6 +53,7 @@ int fileno(FAR FILE *stream) { int ret = -1; + if (stream) { ret = stream->fs_fd; diff --git a/libc/stdio/lib_fopen.c b/libc/stdio/lib_fopen.c index fc0856ce5b..957e439b19 100644 --- a/libc/stdio/lib_fopen.c +++ b/libc/stdio/lib_fopen.c @@ -69,18 +69,76 @@ #define MODE_MASK (MODE_R | MODE_W | MODE_A) /**************************************************************************** - * Private Types + * Public Functions ****************************************************************************/ /**************************************************************************** - * Private Functions + * Name: fdopen ****************************************************************************/ +FAR FILE *fdopen(int fd, FAR const char *mode) +{ + FAR FILE *ret = NULL; + int oflags; + + /* Map the open mode string to open flags */ + + oflags = lib_mode2oflags(mode); + if (oflags >= 0) + { + ret = fs_fdopen(fd, oflags, NULL); + } + + return ret; +} + +/**************************************************************************** + * Name: fopen + ****************************************************************************/ + +FAR FILE *fopen(FAR const char *path, FAR const char *mode) +{ + FAR FILE *ret = NULL; + int oflags; + int fd; + + /* Map the open mode string to open flags */ + + oflags = lib_mode2oflags(mode); + if (oflags < 0) + { + return NULL; + } + + /* Open the file */ + + fd = open(path, oflags, 0666); + + /* If the open was successful, then fdopen() the fil using the file + * descriptor returned by open. If open failed, then just return the + * NULL stream -- open() has already set the errno. + */ + + if (fd >= 0) + { + ret = fs_fdopen(fd, oflags, NULL); + if (!ret) + { + /* Don't forget to close the file descriptor if any other + * failures are reported by fdopen(). + */ + + (void)close(fd); + } + } + return ret; +} + /**************************************************************************** * Name: lib_mode2oflags ****************************************************************************/ -static int lib_mode2oflags(FAR const char *mode) +int lib_mode2oflags(FAR const char *mode) { unsigned int state; int oflags; @@ -246,69 +304,3 @@ errout: set_errno(EINVAL); return ERROR; } - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fdopen - ****************************************************************************/ - -FAR FILE *fdopen(int fd, FAR const char *mode) -{ - FAR FILE *ret = NULL; - int oflags; - - /* Map the open mode string to open flags */ - - oflags = lib_mode2oflags(mode); - if (oflags >= 0) - { - ret = fs_fdopen(fd, oflags, NULL); - } - - return ret; -} - -/**************************************************************************** - * Name: fopen - ****************************************************************************/ - -FAR FILE *fopen(FAR const char *path, FAR const char *mode) -{ - FAR FILE *ret = NULL; - int oflags; - int fd; - - /* Map the open mode string to open flags */ - - oflags = lib_mode2oflags(mode); - if (oflags < 0) - { - return NULL; - } - - /* Open the file */ - - fd = open(path, oflags, 0666); - - /* If the open was successful, then fdopen() the fil using the file - * descriptor returned by open. If open failed, then just return the - * NULL stream -- open() has already set the errno. - */ - - if (fd >= 0) - { - ret = fs_fdopen(fd, oflags, NULL); - if (!ret) - { - /* Don't forget to close the file descriptor if any other - * failures are reported by fdopen(). - */ - - (void)close(fd); - } - } - return ret; -} diff --git a/libc/stdio/lib_freopen.c b/libc/stdio/lib_freopen.c new file mode 100644 index 0000000000..f90546067e --- /dev/null +++ b/libc/stdio/lib_freopen.c @@ -0,0 +1,143 @@ +/**************************************************************************** + * libc/stdio/lib_freopen.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: freopen + * + * Description: + * Reuses stream to either open the file specified by path or to change + * its access mode. + * + * If a new path is specified, the function first attempts to close + * any file already associated with stream (third parameter) and + * disassociates it. Then, independently of whether that stream was + * successfuly closed or not, freopen opens the file specified by path + * and associates it with the stream just as fopen would do using the + * specified mode. + * + * If path is a null pointer, the function attempts to change the mode + * of the stream. Although a particular library implementation is allowed + * to restrict the changes permitted, and under which circumstances. + * + * The error indicator and eof indicator are automatically cleared (as if + * clearerr was called). + * + * Input Paramters: + * path - If non-NULL, refers to the name of the file to be opened. + * mode - String describing the new file access mode + * stream - Pointer to the type FILE to be reopened. + * + * Returned Value: + * If the file is successfully reopened, the function returns the pointer + * passed as parameter stream, which can be used to identify the reopened + * stream. Otherwise, a null pointer is returned and the errno variable + * is also set to a system-specific error code on failure. + * + ****************************************************************************/ + +FAR FILE *freopen(FAR const char *path, FAR const char *mode, + FAR FILE *stream) +{ + int oflags; + int ret; + int fd; + + /* Was a file name provided? */ + + if (path != NULL) + { + /* Yes, close the stream */ + + if (stream) + { + (void)fclose(stream); + } + + /* And attempt to reopen the file at the provided path */ + + return fopen(path, mode); + } + + /* Otherwise, we are just changing the mode of the current file. */ + + if (stream) + { + /* Convert the mode string into standard file open mode flags. */ + + oflags = lib_mode2oflags(mode); + if (oflags == 0) + { + return NULL; + } + + /* Get the underlying file descriptor from the stream */ + + fd = fileno(stream); + if (fd < 0) + { + return NULL; + } + + /* Set the new file mode for the file descriptor */ + + ret = fcntl(fd, F_SETFL, oflags); + if (ret < 0) + { + return NULL; + } + + clearerr(stream); + return stream; + } + + set_errno(EINVAL); + return NULL; +} -- GitLab From 64e8f12e2bf02886723bf2fd68e3d6886e684d32 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 10:07:35 -0600 Subject: [PATCH 350/858] Add option to specify logical sector size during low level format plus adds some run-time geometry tests. fs/smartfs: Remove the 'mksmartfs()' code from the kernel 'fs' directory and build. --- ChangeLog | 5 + drivers/mtd/smart.c | 53 +++++++-- fs/smartfs/Make.defs | 5 - fs/smartfs/smartfs.h | 9 -- fs/smartfs/smartfs_mksmartfs.c | 191 --------------------------------- include/nuttx/fs/mksmartfs.h | 110 ------------------- include/nuttx/fs/smart.h | 9 ++ 7 files changed, 60 insertions(+), 322 deletions(-) delete mode 100644 fs/smartfs/smartfs_mksmartfs.c delete mode 100644 include/nuttx/fs/mksmartfs.h diff --git a/ChangeLog b/ChangeLog index d3a5f291cb..280e7bb4a7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11140,3 +11140,8 @@ of the block driver (2015-11-21). * libc/stdio/lib_freopen.c and include/stdio.h: Add support for freopen() (2015-11-22). + * drivers/mtd/smart.c: Add option to specify logical sector size + during low level format plus adds some run-time geometry tests. From + Ken Petit (2015-11-22). + * fs/smartfs: Remove the 'mksmartfs()' code from the kernel 'fs' + directory and build. From Ken Petit (2015-11-22). diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index a07bd22097..08bae53c0d 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -994,6 +994,10 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) { dev->availSectPerBlk = 255; } + else if (dev->sectorsPerBlk == 0) + { + return -EINVAL; + } else { dev->availSectPerBlk = dev->sectorsPerBlk; @@ -1442,7 +1446,7 @@ static uint16_t smart_cache_lookup(FAR struct smart_struct_s *dev, uint16_t logi /* Calculate the read address for this sector */ readaddress = block * dev->erasesize + - sector * CONFIG_MTD_SMART_SECTOR_SIZE; + sector * dev->sectorsize; /* Read the header for this sector */ @@ -1818,6 +1822,10 @@ static int smart_scan(FAR struct smart_struct_s *dev) offset >>= 1; if (offset < 256 && sectorsize == 0xFFFF) { + /* No valid sectors found on device. Default the + * sector size to the CONFIG value + */ + sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; } } @@ -2293,6 +2301,17 @@ static int smart_scan(FAR struct smart_struct_s *dev) fdbg(" Erase count: %10d\n", dev->neraseblocks); fdbg(" Sect/block: %10d\n", dev->sectorsPerBlk); fdbg(" MTD Blk/Sect: %10d\n", dev->mtdBlksPerSector); + + /* Validate the geometry */ + + if (dev->mtdBlksPerSector == 0 || dev->sectorsPerBlk == 0 || + dev->sectorsPerBlk == 0 || dev->sectorsize == 0) + { + fdbg("Invalid Geometry!\n"); + ret = -EINVAL; + goto err_out; + } + #ifdef CONFIG_MTD_SMART_ALLOC_DEBUG fdbg(" Allocations:\n"); for (sector = 0; sector < SMART_MAX_ALLOCS; sector++) @@ -2781,6 +2800,11 @@ static crc_t smart_calc_sector_crc(FAR struct smart_struct_s *dev) * involves erasing the device and writing a valid sector * zero (logical) with proper format signature. * + * Input Parameters: + * + * arg: Upper 16 bits contains the sector size + * Lower 16 bits contains the number of root dir entries + * ****************************************************************************/ #ifdef CONFIG_FS_WRITABLE @@ -2791,18 +2815,29 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a int x; int ret; uint8_t sectsize, prerelease; + uint16_t sectorsize; fvdbg("Entry\n"); - smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); + /* Get the sector size from the provided arg */ + + sectorsize = arg >> 16; + if (sectorsize == 0) + { + sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; + } + + /* Set the sector size for the device */ + + smart_setsectorsize(dev, sectorsize); /* Check for invalid format */ - if (dev->erasesize == 0) + if (dev->erasesize == 0 || dev->sectorsPerBlk == 0) { dev->erasesize = dev->geo.erasesize; - dbg("ERROR: Invalid geometery ... Sectors per erase block must be 256 or less\n"); + dbg("ERROR: Invalid geometery ... Sectors per erase block must be 1-256\n"); dbg(" Erase block size = %d\n", dev->erasesize); dbg(" Sector size = %d\n", dev->sectorsize); dbg(" Sectors/erase block = %d\n", dev->erasesize / dev->sectorsize); @@ -2828,18 +2863,22 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* CRC enabled. Using an 8-bit sequence number */ sectorheader->seq = 0; + #else /* CRC not enabled. Using a 16-bit sequence number */ *((FAR uint16_t *) §orheader->seq) = 0; + #endif #else /* SMART_STATUS_VERSION == 1 */ + sectorheader->seq = 0; + #endif /* SMART_STATUS_VERSION == 1 */ /* Set the sector size of this sector */ - sectsize = (CONFIG_MTD_SMART_SECTOR_SIZE >> 9) << 2; + sectsize = (sectorsize >> 9) << 2; /* Set the sector logical sector to zero and setup the header status */ @@ -2873,7 +2912,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Record the number of root directory entries we have */ - dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) arg; + dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) (arg & 0xFF); #ifdef CONFIG_SMART_CRC_8 sectorheader->crc8 = smart_calc_sector_crc(dev); @@ -2900,7 +2939,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Now initialize our internal control variables */ - ret = smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); + ret = smart_setsectorsize(dev, sectorsize); if (ret != OK) { return ret; diff --git a/fs/smartfs/Make.defs b/fs/smartfs/Make.defs index 97bf50fbb9..3be1487cde 100644 --- a/fs/smartfs/Make.defs +++ b/fs/smartfs/Make.defs @@ -40,11 +40,6 @@ ifeq ($(CONFIG_FS_SMARTFS),y) ASRCS += CSRCS += smartfs_smart.c smartfs_utils.c smartfs_procfs.c -# Files required for mksmartfs utility function - -ASRCS += -CSRCS += smartfs_mksmartfs.c - # Include SMART build support DEPPATH += --dep-path smartfs diff --git a/fs/smartfs/smartfs.h b/fs/smartfs/smartfs.h index 36ed65b41b..189d521d72 100644 --- a/fs/smartfs/smartfs.h +++ b/fs/smartfs/smartfs.h @@ -188,15 +188,6 @@ #define FS_BOPS(f) (f)->fs_blkdriver->u.i_bops #define FS_IOCTL(f,c,a) (FS_BOPS(f)->ioctl ? FS_BOPS(f)->ioctl((f)->fs_blkdriver,c,a) : (-ENOSYS)) -/* The logical sector number of the root directory. */ - -#define SMARTFS_ROOT_DIR_SECTOR 3 - -/* Defines the sector types */ - -#define SMARTFS_SECTOR_TYPE_DIR 1 -#define SMARTFS_SECTOR_TYPE_FILE 2 - #ifndef CONFIG_SMARTFS_DIRDEPTH # define CONFIG_SMARTFS_DIRDEPTH 8 #endif diff --git a/fs/smartfs/smartfs_mksmartfs.c b/fs/smartfs/smartfs_mksmartfs.c deleted file mode 100644 index 076915e169..0000000000 --- a/fs/smartfs/smartfs_mksmartfs.c +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** - * fs/smartfs/smartfs_mksmartfs.c - * - * Copyright (C) 2013 Ken Pettit. All rights reserved. - * Author: Ken Pettit - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "smartfs.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mksmartfs - * - * Description: - * Make a SMART Flash file system image on the specified block device - * - * Inputs: - * pathname - the full path to a registered block driver - * nrootdirs - Number of root directory entries to create. - * - * Return: - * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: - * - * EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT - * size in 'fmt', bad cluster size in 'fmt' - * ENOENT - 'pathname' does not refer to anything in the filesystem. - * ENOTBLK - 'pathname' does not refer to a block driver - * EACCES - block driver does not support wrie or geometry methods - * - * Assumptions: - * - The caller must assure that the block driver is not mounted and not in - * use when this function is called. The result of formatting a mounted - * device is indeterminate (but likely not good). - * - ****************************************************************************/ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS -int mksmartfs(FAR const char *pathname, uint8_t nrootdirs) -#else -int mksmartfs(FAR const char *pathname) -#endif -{ - FAR struct inode *inode; - struct smart_format_s fmt; - int ret; - int x; - uint8_t type; - struct smart_read_write_s request; - - /* Find the inode of the block driver indentified by 'source' */ - - ret = open_blockdriver(pathname, 0, &inode); - if (ret < 0) - { - fdbg("Failed to open %s\n", pathname); - goto errout; - } - - /* Make sure that the inode supports the write and geometry methods at a minimum */ - - if (!inode->u.i_bops->write || !inode->u.i_bops->geometry) - { - fdbg("%s does not support write or geometry methods\n", pathname); - ret = -EACCES; - goto errout_with_driver; - } - - /* Validate the block device is a SMART device */ - - /* Perform a low-level SMART format */ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, nrootdirs); -#else - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, 0); -#endif - if (ret != OK) - { - fdbg("Error creating low-level format: %d\n", ret); - goto errout_with_driver; - } - - /* Get the format information so we know how big the sectors are */ - - ret = inode->u.i_bops->ioctl(inode, BIOC_GETFORMAT, (unsigned long) &fmt); - - /* Now Write the filesystem to media. Loop for each root dir entry and - * allocate the reserved Root Dir Enty, then write a blank root dir for it. - */ - - type = SMARTFS_SECTOR_TYPE_DIR; - request.offset = 0; - request.count = 1; - request.buffer = &type; - x = 0; -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - for (; x < nrootdirs; x++) -#endif - { - ret = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x); - if (ret != SMARTFS_ROOT_DIR_SECTOR + x) - { - ret = -EIO; - goto errout_with_driver; - } - - /* Mark this block as a directory entry */ - - request.logsector = SMARTFS_ROOT_DIR_SECTOR + x; - - /* Issue a write to the sector, single byte */ - - ret = inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &request); - if (ret != 0) - { - ret = -EIO; - goto errout_with_driver; - } - } - -errout_with_driver: - /* Close the driver */ - - (void)close_blockdriver(inode); - -errout: - /* Release all allocated memory */ - - /* Return any reported errors */ - - if (ret < 0) - { - set_errno(-ret); - return ERROR; - } - - return OK; -} diff --git a/include/nuttx/fs/mksmartfs.h b/include/nuttx/fs/mksmartfs.h deleted file mode 100644 index f907ba305a..0000000000 --- a/include/nuttx/fs/mksmartfs.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * include/nuttx/fs/mksmartfs.h - * - * Copyright (C) 2013, 2015 Ken Pettit. All rights reserved. - * Author: Ken Pettit - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_SMART_MKSMARTFS_H -#define __INCLUDE_NUTTX_SMART_MKSMARTFS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: mksmartfs - * - * Description: - * Make a SMART (Sector Mapped Allocation for Really Tiny) Flash file - * system image on the specified block device (must be a SMART device). - * - * Inputs: - * pathname - the full path to a registered block driver - * nrootdirs - the number of Root Directory entries to support - * on this device (supports multiple mount points). - * - * Return: - * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: - * - * EINVAL - NULL block driver string - * ENOENT - 'pathname' does not refer to anything in the filesystem. - * ENOTBLK - 'pathname' does not refer to a block driver - * EACCESS - block driver does not support write or geometry methods or - * is not a SMART device - * - * Assumptions: - * - The caller must assure that the block driver is not mounted and not in - * use when this function is called. The result of formatting a mounted - * device is indeterminate (but likely not good). - * - ****************************************************************************/ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS -int mksmartfs(FAR const char *pathname, uint8_t nrootdirs); -#else -int mksmartfs(FAR const char *pathname); -#endif - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_SMART_MKSMARTFS_H */ diff --git a/include/nuttx/fs/smart.h b/include/nuttx/fs/smart.h index 2621dd77f6..f3bff10cb6 100644 --- a/include/nuttx/fs/smart.h +++ b/include/nuttx/fs/smart.h @@ -55,6 +55,15 @@ #define SMART_FMT_ISFORMATTED 0x01 #define SMART_FMT_HASBYTEWRITE 0x02 +/* The logical sector number of the root directory. */ + +#define SMARTFS_ROOT_DIR_SECTOR 3 + +/* Defines the sector types */ + +#define SMARTFS_SECTOR_TYPE_DIR 1 +#define SMARTFS_SECTOR_TYPE_FILE 2 + /**************************************************************************** * Public Types ****************************************************************************/ -- GitLab From 54549ef082b9399b68e241886bd1ab819268a4de Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 10:15:06 -0600 Subject: [PATCH 351/858] Revert "Add option to specify logical sector size during low level format plus adds some run-time geometry tests. fs/smartfs: Remove the 'mksmartfs()' code from the kernel 'fs'" This reverts commit 96faf0fa3251ca10a17daddc728d931be5a206e0. --- ChangeLog | 5 - drivers/mtd/smart.c | 53 ++------- fs/smartfs/Make.defs | 5 + fs/smartfs/smartfs.h | 9 ++ fs/smartfs/smartfs_mksmartfs.c | 191 +++++++++++++++++++++++++++++++++ include/nuttx/fs/mksmartfs.h | 110 +++++++++++++++++++ include/nuttx/fs/smart.h | 9 -- 7 files changed, 322 insertions(+), 60 deletions(-) create mode 100644 fs/smartfs/smartfs_mksmartfs.c create mode 100644 include/nuttx/fs/mksmartfs.h diff --git a/ChangeLog b/ChangeLog index 280e7bb4a7..d3a5f291cb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11140,8 +11140,3 @@ of the block driver (2015-11-21). * libc/stdio/lib_freopen.c and include/stdio.h: Add support for freopen() (2015-11-22). - * drivers/mtd/smart.c: Add option to specify logical sector size - during low level format plus adds some run-time geometry tests. From - Ken Petit (2015-11-22). - * fs/smartfs: Remove the 'mksmartfs()' code from the kernel 'fs' - directory and build. From Ken Petit (2015-11-22). diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 08bae53c0d..a07bd22097 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -994,10 +994,6 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) { dev->availSectPerBlk = 255; } - else if (dev->sectorsPerBlk == 0) - { - return -EINVAL; - } else { dev->availSectPerBlk = dev->sectorsPerBlk; @@ -1446,7 +1442,7 @@ static uint16_t smart_cache_lookup(FAR struct smart_struct_s *dev, uint16_t logi /* Calculate the read address for this sector */ readaddress = block * dev->erasesize + - sector * dev->sectorsize; + sector * CONFIG_MTD_SMART_SECTOR_SIZE; /* Read the header for this sector */ @@ -1822,10 +1818,6 @@ static int smart_scan(FAR struct smart_struct_s *dev) offset >>= 1; if (offset < 256 && sectorsize == 0xFFFF) { - /* No valid sectors found on device. Default the - * sector size to the CONFIG value - */ - sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; } } @@ -2301,17 +2293,6 @@ static int smart_scan(FAR struct smart_struct_s *dev) fdbg(" Erase count: %10d\n", dev->neraseblocks); fdbg(" Sect/block: %10d\n", dev->sectorsPerBlk); fdbg(" MTD Blk/Sect: %10d\n", dev->mtdBlksPerSector); - - /* Validate the geometry */ - - if (dev->mtdBlksPerSector == 0 || dev->sectorsPerBlk == 0 || - dev->sectorsPerBlk == 0 || dev->sectorsize == 0) - { - fdbg("Invalid Geometry!\n"); - ret = -EINVAL; - goto err_out; - } - #ifdef CONFIG_MTD_SMART_ALLOC_DEBUG fdbg(" Allocations:\n"); for (sector = 0; sector < SMART_MAX_ALLOCS; sector++) @@ -2800,11 +2781,6 @@ static crc_t smart_calc_sector_crc(FAR struct smart_struct_s *dev) * involves erasing the device and writing a valid sector * zero (logical) with proper format signature. * - * Input Parameters: - * - * arg: Upper 16 bits contains the sector size - * Lower 16 bits contains the number of root dir entries - * ****************************************************************************/ #ifdef CONFIG_FS_WRITABLE @@ -2815,29 +2791,18 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a int x; int ret; uint8_t sectsize, prerelease; - uint16_t sectorsize; fvdbg("Entry\n"); - /* Get the sector size from the provided arg */ - - sectorsize = arg >> 16; - if (sectorsize == 0) - { - sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; - } - - /* Set the sector size for the device */ - - smart_setsectorsize(dev, sectorsize); + smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); /* Check for invalid format */ - if (dev->erasesize == 0 || dev->sectorsPerBlk == 0) + if (dev->erasesize == 0) { dev->erasesize = dev->geo.erasesize; - dbg("ERROR: Invalid geometery ... Sectors per erase block must be 1-256\n"); + dbg("ERROR: Invalid geometery ... Sectors per erase block must be 256 or less\n"); dbg(" Erase block size = %d\n", dev->erasesize); dbg(" Sector size = %d\n", dev->sectorsize); dbg(" Sectors/erase block = %d\n", dev->erasesize / dev->sectorsize); @@ -2863,22 +2828,18 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* CRC enabled. Using an 8-bit sequence number */ sectorheader->seq = 0; - #else /* CRC not enabled. Using a 16-bit sequence number */ *((FAR uint16_t *) §orheader->seq) = 0; - #endif #else /* SMART_STATUS_VERSION == 1 */ - sectorheader->seq = 0; - #endif /* SMART_STATUS_VERSION == 1 */ /* Set the sector size of this sector */ - sectsize = (sectorsize >> 9) << 2; + sectsize = (CONFIG_MTD_SMART_SECTOR_SIZE >> 9) << 2; /* Set the sector logical sector to zero and setup the header status */ @@ -2912,7 +2873,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Record the number of root directory entries we have */ - dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) (arg & 0xFF); + dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) arg; #ifdef CONFIG_SMART_CRC_8 sectorheader->crc8 = smart_calc_sector_crc(dev); @@ -2939,7 +2900,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Now initialize our internal control variables */ - ret = smart_setsectorsize(dev, sectorsize); + ret = smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); if (ret != OK) { return ret; diff --git a/fs/smartfs/Make.defs b/fs/smartfs/Make.defs index 3be1487cde..97bf50fbb9 100644 --- a/fs/smartfs/Make.defs +++ b/fs/smartfs/Make.defs @@ -40,6 +40,11 @@ ifeq ($(CONFIG_FS_SMARTFS),y) ASRCS += CSRCS += smartfs_smart.c smartfs_utils.c smartfs_procfs.c +# Files required for mksmartfs utility function + +ASRCS += +CSRCS += smartfs_mksmartfs.c + # Include SMART build support DEPPATH += --dep-path smartfs diff --git a/fs/smartfs/smartfs.h b/fs/smartfs/smartfs.h index 189d521d72..36ed65b41b 100644 --- a/fs/smartfs/smartfs.h +++ b/fs/smartfs/smartfs.h @@ -188,6 +188,15 @@ #define FS_BOPS(f) (f)->fs_blkdriver->u.i_bops #define FS_IOCTL(f,c,a) (FS_BOPS(f)->ioctl ? FS_BOPS(f)->ioctl((f)->fs_blkdriver,c,a) : (-ENOSYS)) +/* The logical sector number of the root directory. */ + +#define SMARTFS_ROOT_DIR_SECTOR 3 + +/* Defines the sector types */ + +#define SMARTFS_SECTOR_TYPE_DIR 1 +#define SMARTFS_SECTOR_TYPE_FILE 2 + #ifndef CONFIG_SMARTFS_DIRDEPTH # define CONFIG_SMARTFS_DIRDEPTH 8 #endif diff --git a/fs/smartfs/smartfs_mksmartfs.c b/fs/smartfs/smartfs_mksmartfs.c new file mode 100644 index 0000000000..076915e169 --- /dev/null +++ b/fs/smartfs/smartfs_mksmartfs.c @@ -0,0 +1,191 @@ +/**************************************************************************** + * fs/smartfs/smartfs_mksmartfs.c + * + * Copyright (C) 2013 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "smartfs.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mksmartfs + * + * Description: + * Make a SMART Flash file system image on the specified block device + * + * Inputs: + * pathname - the full path to a registered block driver + * nrootdirs - Number of root directory entries to create. + * + * Return: + * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: + * + * EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT + * size in 'fmt', bad cluster size in 'fmt' + * ENOENT - 'pathname' does not refer to anything in the filesystem. + * ENOTBLK - 'pathname' does not refer to a block driver + * EACCES - block driver does not support wrie or geometry methods + * + * Assumptions: + * - The caller must assure that the block driver is not mounted and not in + * use when this function is called. The result of formatting a mounted + * device is indeterminate (but likely not good). + * + ****************************************************************************/ + +#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS +int mksmartfs(FAR const char *pathname, uint8_t nrootdirs) +#else +int mksmartfs(FAR const char *pathname) +#endif +{ + FAR struct inode *inode; + struct smart_format_s fmt; + int ret; + int x; + uint8_t type; + struct smart_read_write_s request; + + /* Find the inode of the block driver indentified by 'source' */ + + ret = open_blockdriver(pathname, 0, &inode); + if (ret < 0) + { + fdbg("Failed to open %s\n", pathname); + goto errout; + } + + /* Make sure that the inode supports the write and geometry methods at a minimum */ + + if (!inode->u.i_bops->write || !inode->u.i_bops->geometry) + { + fdbg("%s does not support write or geometry methods\n", pathname); + ret = -EACCES; + goto errout_with_driver; + } + + /* Validate the block device is a SMART device */ + + /* Perform a low-level SMART format */ + +#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS + ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, nrootdirs); +#else + ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, 0); +#endif + if (ret != OK) + { + fdbg("Error creating low-level format: %d\n", ret); + goto errout_with_driver; + } + + /* Get the format information so we know how big the sectors are */ + + ret = inode->u.i_bops->ioctl(inode, BIOC_GETFORMAT, (unsigned long) &fmt); + + /* Now Write the filesystem to media. Loop for each root dir entry and + * allocate the reserved Root Dir Enty, then write a blank root dir for it. + */ + + type = SMARTFS_SECTOR_TYPE_DIR; + request.offset = 0; + request.count = 1; + request.buffer = &type; + x = 0; +#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS + for (; x < nrootdirs; x++) +#endif + { + ret = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x); + if (ret != SMARTFS_ROOT_DIR_SECTOR + x) + { + ret = -EIO; + goto errout_with_driver; + } + + /* Mark this block as a directory entry */ + + request.logsector = SMARTFS_ROOT_DIR_SECTOR + x; + + /* Issue a write to the sector, single byte */ + + ret = inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &request); + if (ret != 0) + { + ret = -EIO; + goto errout_with_driver; + } + } + +errout_with_driver: + /* Close the driver */ + + (void)close_blockdriver(inode); + +errout: + /* Release all allocated memory */ + + /* Return any reported errors */ + + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + + return OK; +} diff --git a/include/nuttx/fs/mksmartfs.h b/include/nuttx/fs/mksmartfs.h new file mode 100644 index 0000000000..f907ba305a --- /dev/null +++ b/include/nuttx/fs/mksmartfs.h @@ -0,0 +1,110 @@ +/**************************************************************************** + * include/nuttx/fs/mksmartfs.h + * + * Copyright (C) 2013, 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SMART_MKSMARTFS_H +#define __INCLUDE_NUTTX_SMART_MKSMARTFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: mksmartfs + * + * Description: + * Make a SMART (Sector Mapped Allocation for Really Tiny) Flash file + * system image on the specified block device (must be a SMART device). + * + * Inputs: + * pathname - the full path to a registered block driver + * nrootdirs - the number of Root Directory entries to support + * on this device (supports multiple mount points). + * + * Return: + * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: + * + * EINVAL - NULL block driver string + * ENOENT - 'pathname' does not refer to anything in the filesystem. + * ENOTBLK - 'pathname' does not refer to a block driver + * EACCESS - block driver does not support write or geometry methods or + * is not a SMART device + * + * Assumptions: + * - The caller must assure that the block driver is not mounted and not in + * use when this function is called. The result of formatting a mounted + * device is indeterminate (but likely not good). + * + ****************************************************************************/ + +#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS +int mksmartfs(FAR const char *pathname, uint8_t nrootdirs); +#else +int mksmartfs(FAR const char *pathname); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_SMART_MKSMARTFS_H */ diff --git a/include/nuttx/fs/smart.h b/include/nuttx/fs/smart.h index f3bff10cb6..2621dd77f6 100644 --- a/include/nuttx/fs/smart.h +++ b/include/nuttx/fs/smart.h @@ -55,15 +55,6 @@ #define SMART_FMT_ISFORMATTED 0x01 #define SMART_FMT_HASBYTEWRITE 0x02 -/* The logical sector number of the root directory. */ - -#define SMARTFS_ROOT_DIR_SECTOR 3 - -/* Defines the sector types */ - -#define SMARTFS_SECTOR_TYPE_DIR 1 -#define SMARTFS_SECTOR_TYPE_FILE 2 - /**************************************************************************** * Public Types ****************************************************************************/ -- GitLab From 891589b30735b7a938afba05d00471a431436b7f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 17:10:42 -0600 Subject: [PATCH 352/858] drivers/mtd/smart.c: Add some run-time geometry tests --- drivers/mtd/smart.c | 49 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index a07bd22097..6ea69cb040 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -994,6 +994,10 @@ static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size) { dev->availSectPerBlk = 255; } + else if (dev->sectorsPerBlk == 0) + { + return -EINVAL; + } else { dev->availSectPerBlk = dev->sectorsPerBlk; @@ -1442,7 +1446,7 @@ static uint16_t smart_cache_lookup(FAR struct smart_struct_s *dev, uint16_t logi /* Calculate the read address for this sector */ readaddress = block * dev->erasesize + - sector * CONFIG_MTD_SMART_SECTOR_SIZE; + sector * dev->sectorsize; /* Read the header for this sector */ @@ -1818,6 +1822,10 @@ static int smart_scan(FAR struct smart_struct_s *dev) offset >>= 1; if (offset < 256 && sectorsize == 0xFFFF) { + /* No valid sectors found on device. Default the + * sector size to the CONFIG value + */ + sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; } } @@ -2293,6 +2301,17 @@ static int smart_scan(FAR struct smart_struct_s *dev) fdbg(" Erase count: %10d\n", dev->neraseblocks); fdbg(" Sect/block: %10d\n", dev->sectorsPerBlk); fdbg(" MTD Blk/Sect: %10d\n", dev->mtdBlksPerSector); + + /* Validate the geometry */ + + if (dev->mtdBlksPerSector == 0 || dev->sectorsPerBlk == 0 || + dev->sectorsPerBlk == 0 || dev->sectorsize == 0) + { + fdbg("Invalid Geometry!\n"); + ret = -EINVAL; + goto err_out; + } + #ifdef CONFIG_MTD_SMART_ALLOC_DEBUG fdbg(" Allocations:\n"); for (sector = 0; sector < SMART_MAX_ALLOCS; sector++) @@ -2781,6 +2800,11 @@ static crc_t smart_calc_sector_crc(FAR struct smart_struct_s *dev) * involves erasing the device and writing a valid sector * zero (logical) with proper format signature. * + * Input Parameters: + * + * arg: Upper 16 bits contains the sector size + * Lower 16 bits contains the number of root dir entries + * ****************************************************************************/ #ifdef CONFIG_FS_WRITABLE @@ -2791,18 +2815,29 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a int x; int ret; uint8_t sectsize, prerelease; + uint16_t sectorsize; fvdbg("Entry\n"); - smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); + /* Get the sector size from the provided arg */ + + sectorsize = arg >> 16; + if (sectorsize == 0) + { + sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; + } + + /* Set the sector size for the device */ + + smart_setsectorsize(dev, sectorsize); /* Check for invalid format */ - if (dev->erasesize == 0) + if (dev->erasesize == 0 || dev->sectorsPerBlk == 0) { dev->erasesize = dev->geo.erasesize; - dbg("ERROR: Invalid geometery ... Sectors per erase block must be 256 or less\n"); + dbg("ERROR: Invalid geometery ... Sectors per erase block must be 1-256\n"); dbg(" Erase block size = %d\n", dev->erasesize); dbg(" Sector size = %d\n", dev->sectorsize); dbg(" Sectors/erase block = %d\n", dev->erasesize / dev->sectorsize); @@ -2839,7 +2874,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Set the sector size of this sector */ - sectsize = (CONFIG_MTD_SMART_SECTOR_SIZE >> 9) << 2; + sectsize = (sectorsize >> 9) << 2; /* Set the sector logical sector to zero and setup the header status */ @@ -2873,7 +2908,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Record the number of root directory entries we have */ - dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) arg; + dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) (arg & 0xFF); #ifdef CONFIG_SMART_CRC_8 sectorheader->crc8 = smart_calc_sector_crc(dev); @@ -2900,7 +2935,7 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a /* Now initialize our internal control variables */ - ret = smart_setsectorsize(dev, CONFIG_MTD_SMART_SECTOR_SIZE); + ret = smart_setsectorsize(dev, sectorsize); if (ret != OK) { return ret; -- GitLab From 289b3e281f6d9c655f52b1375c59f52d70a03086 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 17:18:43 -0600 Subject: [PATCH 353/858] drivers/mtd/smart.c: Fix a compile error when CONFIG_MTD_SMART_MINIMIZE_RAM=y --- drivers/mtd/smart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 6ea69cb040..c82a3af112 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -3951,7 +3951,7 @@ static inline int smart_read_wearstatus(FAR struct smart_struct_s *dev) #ifndef CONFIG_MTD_SMART_MINIMIZE_RAM physsector = dev->sMap[req.logsector]; #else - physsector = smart_cache_lookup(dev, req->logsector); + physsector = smart_cache_lookup(dev, req.logsector); #endif if ((sector != 0) && (physsector == 0xFFFF)) { -- GitLab From 375419eaf28aa3eb988fa048657ecc9944020998 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Mon, 23 Nov 2015 07:05:09 -0600 Subject: [PATCH 354/858] mksmartfs: Remove fs/smartfs/fs_mksmartfs.c and related headers. This has been moved to apps/fsutils/mksmartfs. From Ken Petit --- fs/smartfs/Make.defs | 5 - fs/smartfs/smartfs_mksmartfs.c | 191 --------------------------------- include/nuttx/fs/mksmartfs.h | 110 ------------------- include/nuttx/fs/smart.h | 9 ++ 4 files changed, 9 insertions(+), 306 deletions(-) delete mode 100644 fs/smartfs/smartfs_mksmartfs.c delete mode 100644 include/nuttx/fs/mksmartfs.h diff --git a/fs/smartfs/Make.defs b/fs/smartfs/Make.defs index 97bf50fbb9..3be1487cde 100644 --- a/fs/smartfs/Make.defs +++ b/fs/smartfs/Make.defs @@ -40,11 +40,6 @@ ifeq ($(CONFIG_FS_SMARTFS),y) ASRCS += CSRCS += smartfs_smart.c smartfs_utils.c smartfs_procfs.c -# Files required for mksmartfs utility function - -ASRCS += -CSRCS += smartfs_mksmartfs.c - # Include SMART build support DEPPATH += --dep-path smartfs diff --git a/fs/smartfs/smartfs_mksmartfs.c b/fs/smartfs/smartfs_mksmartfs.c deleted file mode 100644 index 076915e169..0000000000 --- a/fs/smartfs/smartfs_mksmartfs.c +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** - * fs/smartfs/smartfs_mksmartfs.c - * - * Copyright (C) 2013 Ken Pettit. All rights reserved. - * Author: Ken Pettit - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "smartfs.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mksmartfs - * - * Description: - * Make a SMART Flash file system image on the specified block device - * - * Inputs: - * pathname - the full path to a registered block driver - * nrootdirs - Number of root directory entries to create. - * - * Return: - * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: - * - * EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT - * size in 'fmt', bad cluster size in 'fmt' - * ENOENT - 'pathname' does not refer to anything in the filesystem. - * ENOTBLK - 'pathname' does not refer to a block driver - * EACCES - block driver does not support wrie or geometry methods - * - * Assumptions: - * - The caller must assure that the block driver is not mounted and not in - * use when this function is called. The result of formatting a mounted - * device is indeterminate (but likely not good). - * - ****************************************************************************/ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS -int mksmartfs(FAR const char *pathname, uint8_t nrootdirs) -#else -int mksmartfs(FAR const char *pathname) -#endif -{ - FAR struct inode *inode; - struct smart_format_s fmt; - int ret; - int x; - uint8_t type; - struct smart_read_write_s request; - - /* Find the inode of the block driver indentified by 'source' */ - - ret = open_blockdriver(pathname, 0, &inode); - if (ret < 0) - { - fdbg("Failed to open %s\n", pathname); - goto errout; - } - - /* Make sure that the inode supports the write and geometry methods at a minimum */ - - if (!inode->u.i_bops->write || !inode->u.i_bops->geometry) - { - fdbg("%s does not support write or geometry methods\n", pathname); - ret = -EACCES; - goto errout_with_driver; - } - - /* Validate the block device is a SMART device */ - - /* Perform a low-level SMART format */ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, nrootdirs); -#else - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, 0); -#endif - if (ret != OK) - { - fdbg("Error creating low-level format: %d\n", ret); - goto errout_with_driver; - } - - /* Get the format information so we know how big the sectors are */ - - ret = inode->u.i_bops->ioctl(inode, BIOC_GETFORMAT, (unsigned long) &fmt); - - /* Now Write the filesystem to media. Loop for each root dir entry and - * allocate the reserved Root Dir Enty, then write a blank root dir for it. - */ - - type = SMARTFS_SECTOR_TYPE_DIR; - request.offset = 0; - request.count = 1; - request.buffer = &type; - x = 0; -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - for (; x < nrootdirs; x++) -#endif - { - ret = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x); - if (ret != SMARTFS_ROOT_DIR_SECTOR + x) - { - ret = -EIO; - goto errout_with_driver; - } - - /* Mark this block as a directory entry */ - - request.logsector = SMARTFS_ROOT_DIR_SECTOR + x; - - /* Issue a write to the sector, single byte */ - - ret = inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long) &request); - if (ret != 0) - { - ret = -EIO; - goto errout_with_driver; - } - } - -errout_with_driver: - /* Close the driver */ - - (void)close_blockdriver(inode); - -errout: - /* Release all allocated memory */ - - /* Return any reported errors */ - - if (ret < 0) - { - set_errno(-ret); - return ERROR; - } - - return OK; -} diff --git a/include/nuttx/fs/mksmartfs.h b/include/nuttx/fs/mksmartfs.h deleted file mode 100644 index f907ba305a..0000000000 --- a/include/nuttx/fs/mksmartfs.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * include/nuttx/fs/mksmartfs.h - * - * Copyright (C) 2013, 2015 Ken Pettit. All rights reserved. - * Author: Ken Pettit - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_SMART_MKSMARTFS_H -#define __INCLUDE_NUTTX_SMART_MKSMARTFS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: mksmartfs - * - * Description: - * Make a SMART (Sector Mapped Allocation for Really Tiny) Flash file - * system image on the specified block device (must be a SMART device). - * - * Inputs: - * pathname - the full path to a registered block driver - * nrootdirs - the number of Root Directory entries to support - * on this device (supports multiple mount points). - * - * Return: - * Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately: - * - * EINVAL - NULL block driver string - * ENOENT - 'pathname' does not refer to anything in the filesystem. - * ENOTBLK - 'pathname' does not refer to a block driver - * EACCESS - block driver does not support write or geometry methods or - * is not a SMART device - * - * Assumptions: - * - The caller must assure that the block driver is not mounted and not in - * use when this function is called. The result of formatting a mounted - * device is indeterminate (but likely not good). - * - ****************************************************************************/ - -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS -int mksmartfs(FAR const char *pathname, uint8_t nrootdirs); -#else -int mksmartfs(FAR const char *pathname); -#endif - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_SMART_MKSMARTFS_H */ diff --git a/include/nuttx/fs/smart.h b/include/nuttx/fs/smart.h index 2621dd77f6..f3bff10cb6 100644 --- a/include/nuttx/fs/smart.h +++ b/include/nuttx/fs/smart.h @@ -55,6 +55,15 @@ #define SMART_FMT_ISFORMATTED 0x01 #define SMART_FMT_HASBYTEWRITE 0x02 +/* The logical sector number of the root directory. */ + +#define SMARTFS_ROOT_DIR_SECTOR 3 + +/* Defines the sector types */ + +#define SMARTFS_SECTOR_TYPE_DIR 1 +#define SMARTFS_SECTOR_TYPE_FILE 2 + /**************************************************************************** * Public Types ****************************************************************************/ -- GitLab From 25ab59bf809c3133a3cf69afd4a57756fdba43a8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Nov 2015 07:11:05 -0600 Subject: [PATCH 355/858] stddef.h: Use a round-about cast in the definition of offsetof() to avoid warnings on machines with 64 bit addresses and when size_t is less than 64-bits. --- include/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stddef.h b/include/stddef.h index ecc5eb94ce..bcd09d249b 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -65,7 +65,7 @@ * Reference: Opengroup.org */ -#define offsetof(a,b) ((size_t)(&(((a *)(0))->b))) +#define offsetof(type, member) ((size_t)(uintptr_t)&(((type *)0)->member)) /**************************************************************************** * Type Definitions -- GitLab From 5f7dac80767945ba803d0c7dc1a1c4f2d3c2ec04 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Nov 2015 11:19:02 -0600 Subject: [PATCH 356/858] Update sub-modules --- Documentation | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index bc3e253711..407fb6f151 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit bc3e2537116a608a90b89e9e1a7b2c72593d8c58 +Subproject commit 407fb6f15111fdca9eedf1845406ac688960d441 diff --git a/configs b/configs index 680f486f3d..48b7ae421b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 680f486f3d31e64277ea651abf4daae13e62f188 +Subproject commit 48b7ae421b8c84ddfd8d6045b82557124f8b5549 -- GitLab From 6230e6e19981900ac0354ea1b573cde022821e92 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Nov 2015 12:03:36 -0600 Subject: [PATCH 357/858] size_t should be 64-bits on a 64-bit machine. mmsize_t should be 32-bits (unless CONFIG_MM_SMALL is selected). This commit backs out the last change to stddef.h --- ChangeLog | 6 ++++++ arch | 2 +- configs | 2 +- include/nuttx/mm/mm.h | 2 +- include/stddef.h | 2 +- include/sys/types.h | 10 +++++++--- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3a5f291cb..d14dd884b7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11140,3 +11140,9 @@ of the block driver (2015-11-21). * libc/stdio/lib_freopen.c and include/stdio.h: Add support for freopen() (2015-11-22). + * include/sys/types.h and include/nuttx/mm.h: When building on a 64-bit + machine, the size of size_t should be 64-bits. In general, I believe + that sizeof(size_t) should be the same as sizeof(uinptr_t). mmsize_t + should always be 32-bits in any event. The last change to stddef has + been backed out. With these changes, the simulator builds without + warnings on a 64-bit machine (2015-11-23). diff --git a/arch b/arch index b417eaa97e..ffcd26aff9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b417eaa97e68b4dfe81bb3515a68d53ffa00233b +Subproject commit ffcd26aff904843e043a333e6f73d900423ca211 diff --git a/configs b/configs index 48b7ae421b..82d56af701 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 48b7ae421b8c84ddfd8d6045b82557124f8b5549 +Subproject commit 82d56af7017b9524403d5f10b612effa08e71d61 diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 3d2523eeac..482b7e926d 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -186,7 +186,7 @@ typedef uint16_t mmsize_t; # define MMSIZE_MAX 0xffff #else - typedef size_t mmsize_t; + typedef uint32_t mmsize_t; # define MMSIZE_MAX SIZE_MAX #endif diff --git a/include/stddef.h b/include/stddef.h index bcd09d249b..2b59c58a3d 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -65,7 +65,7 @@ * Reference: Opengroup.org */ -#define offsetof(type, member) ((size_t)(uintptr_t)&(((type *)0)->member)) +#define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) /**************************************************************************** * Type Definitions diff --git a/include/sys/types.h b/include/sys/types.h index babc723d92..298414c408 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -142,10 +142,14 @@ typedef int16_t ssize_t; typedef uint16_t rsize_t; #else /* CONFIG_SMALL_MEMORY */ +/* As a general rule, the size of size_t should be the same as the size of + * uintptr_t: 32-bits on a machine with 32-bit addressing but 64-bits on a + * machine with 64-bit addressing. + */ -typedef uint32_t size_t; -typedef int32_t ssize_t; -typedef uint32_t rsize_t; +typedef uintptr_t size_t; +typedef intptr_t ssize_t; +typedef uintptr_t rsize_t; #endif /* CONFIG_SMALL_MEMORY */ -- GitLab From 56d29bbc347495adc6d1eb0e2952918cbc82c591 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Nov 2015 12:45:56 -0600 Subject: [PATCH 358/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ffcd26aff9..7b1e8100d0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ffcd26aff904843e043a333e6f73d900423ca211 +Subproject commit 7b1e8100d08314058272aaff13cb1538ee47c8b4 diff --git a/configs b/configs index 82d56af701..d1c15cfd4d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 82d56af7017b9524403d5f10b612effa08e71d61 +Subproject commit d1c15cfd4d5e421b8867b1403e5c8a77f020d3c8 -- GitLab From cd7c6705a8bb5fd62f11b3e9840fe1e1972b83ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 08:11:32 -0600 Subject: [PATCH 359/858] mm.h: Use UINT32_MAX vs. SIZE_MAX in definition of MMSIZE_MAX --- include/nuttx/mm/mm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 482b7e926d..a18f12c6fa 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -184,10 +184,10 @@ #ifdef CONFIG_MM_SMALL typedef uint16_t mmsize_t; -# define MMSIZE_MAX 0xffff +# define MMSIZE_MAX UINT16_MAX #else typedef uint32_t mmsize_t; -# define MMSIZE_MAX SIZE_MAX +# define MMSIZE_MAX UINT32_MAX #endif /* This describes an allocated chunk. An allocated chunk is -- GitLab From c0b9dcf8a92566832b68137f6f9c0ee851732cc0 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Wed, 25 Nov 2015 08:26:26 -0600 Subject: [PATCH 360/858] fs/hostfs: Add a special file system for use with simulator that supports access to the host file system from the simulation. From Ken Petit --- ChangeLog | 5 +- arch | 2 +- configs | 2 +- fs/Kconfig | 1 + fs/Makefile | 1 + fs/hostfs/Kconfig | 24 + fs/hostfs/Make.defs | 48 ++ fs/hostfs/hostfs.c | 1217 +++++++++++++++++++++++++++++++++++++ fs/hostfs/hostfs.h | 117 ++++ fs/mount/fs_mount.c | 6 + include/nuttx/fs/dirent.h | 14 + include/nuttx/fs/hostfs.h | 133 ++++ include/sys/statfs.h | 1 + 13 files changed, 1568 insertions(+), 3 deletions(-) create mode 100644 fs/hostfs/Kconfig create mode 100644 fs/hostfs/Make.defs create mode 100644 fs/hostfs/hostfs.c create mode 100644 fs/hostfs/hostfs.h create mode 100644 include/nuttx/fs/hostfs.h diff --git a/ChangeLog b/ChangeLog index d14dd884b7..02abd97d7e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11145,4 +11145,7 @@ that sizeof(size_t) should be the same as sizeof(uinptr_t). mmsize_t should always be 32-bits in any event. The last change to stddef has been backed out. With these changes, the simulator builds without - warnings on a 64-bit machine (2015-11-23). + * fs/hostfs: Add a special file system for use with simulator that + supports access to the host file system from the simulation. From + Ken Petit (2015-11-25). + diff --git a/arch b/arch index ffcd26aff9..93f8b673c8 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ffcd26aff904843e043a333e6f73d900423ca211 +Subproject commit 93f8b673c8d0c4d3f534ef08163d51187a07a390 diff --git a/configs b/configs index 82d56af701..98ebc3e0a5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 82d56af7017b9524403d5f10b612effa08e71d61 +Subproject commit 98ebc3e0a5f2313942a5083bbc177388aad59fb3 diff --git a/fs/Kconfig b/fs/Kconfig index 91f4d10fad..8f25c3d43f 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -62,6 +62,7 @@ source fs/smartfs/Kconfig source fs/binfs/Kconfig source fs/procfs/Kconfig source fs/unionfs/Kconfig +source fs/hostfs/Kconfig comment "System Logging" diff --git a/fs/Makefile b/fs/Makefile index 58d9c2fb0e..e60af07ae0 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -71,6 +71,7 @@ include smartfs/Make.defs include binfs/Make.defs include procfs/Make.defs include unionfs/Make.defs +include hostfs/Make.defs endif endif diff --git a/fs/hostfs/Kconfig b/fs/hostfs/Kconfig new file mode 100644 index 0000000000..ab2abc12fb --- /dev/null +++ b/fs/hostfs/Kconfig @@ -0,0 +1,24 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config FS_HOSTFS + bool "Host File System" + default n + depends on !DISABLE_MOUNTPOINT + depends on ARCH_SIM + select FS_READABLE + select FS_WRITABLE + ---help--- + The Host file system provides a mechanism to mount directories + from the host OS during simulation mode. The host directory + to be "mounted" is specified during the mount command using + the -o command line switch, such as: + + mount -t hostfs -o fs=/home/user/nuttx_root /host + + For non-NSH operation, the option "fs=home/user/nuttx_root" would + be passed to the 'mount()' routine using the optional 'void *data' + parameter. + diff --git a/fs/hostfs/Make.defs b/fs/hostfs/Make.defs new file mode 100644 index 0000000000..441221d298 --- /dev/null +++ b/fs/hostfs/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# Make.defs +# +# Copyright (C) 2015 Ken Pettit. All rights reserved. +# Author: Ken Pettit +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name Nuttx nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_FS_HOSTFS),y) + +# Files required for HostFS file system support + +ASRCS += +CSRCS += hostfs.c + +# Include HOSTFS build support + +DEPPATH += --dep-path hostfs +VPATH += :hostfs + +endif diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c new file mode 100644 index 0000000000..6e45e86353 --- /dev/null +++ b/fs/hostfs/hostfs.c @@ -0,0 +1,1217 @@ +/**************************************************************************** + * nuttx/fs/hostfs/hostfs.c + * + * Copyright (C) 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "hostfs.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int hostfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int hostfs_close(FAR struct file *filep); +static ssize_t hostfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t hostfs_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static off_t hostfs_seek(FAR struct file *filep, off_t offset, + int whence); +static int hostfs_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +static int hostfs_sync(FAR struct file *filep); +static int hostfs_dup(FAR const struct file *oldp, + FAR struct file *newp); + +static int hostfs_opendir(FAR struct inode *mountpt, + FAR const char *relpath, + FAR struct fs_dirent_s *dir); +static int hostfs_closedir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); +static int hostfs_readdir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); +static int hostfs_rewinddir(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); + +static int hostfs_bind(FAR struct inode *blkdriver, + FAR const void *data, FAR void **handle); +static int hostfs_unbind(FAR void *handle, FAR struct inode **blkdriver, + unsigned int flags); +static int hostfs_statfs(FAR struct inode *mountpt, + FAR struct statfs *buf); + +static int hostfs_unlink(FAR struct inode *mountpt, + FAR const char *relpath); +static int hostfs_mkdir(FAR struct inode *mountpt, + FAR const char *relpath, mode_t mode); +static int hostfs_rmdir(FAR struct inode *mountpt, const char *relpath); +static int hostfs_rename(FAR struct inode *mountpt, + FAR const char *oldrelpath, + FAR const char *newrelpath); +static int hostfs_stat(FAR struct inode *mountpt, + FAR const char *relpath, FAR struct stat *buf); + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +static uint8_t g_seminitialized = FALSE; +static sem_t g_sem; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* See fs_mount.c -- this structure is explicitly externed there. + * We use the old-fashioned kind of initializers so that this will compile + * with any compiler. + */ + +const struct mountpt_operations hostfs_operations = +{ + hostfs_open, /* open */ + hostfs_close, /* close */ + hostfs_read, /* read */ + hostfs_write, /* write */ + hostfs_seek, /* seek */ + hostfs_ioctl, /* ioctl */ + + hostfs_sync, /* sync */ + hostfs_dup, /* dup */ + + hostfs_opendir, /* opendir */ + hostfs_closedir, /* closedir */ + hostfs_readdir, /* readdir */ + hostfs_rewinddir, /* rewinddir */ + + hostfs_bind, /* bind */ + hostfs_unbind, /* unbind */ + hostfs_statfs, /* statfs */ + + hostfs_unlink, /* unlinke */ + hostfs_mkdir, /* mkdir */ + hostfs_rmdir, /* rmdir */ + hostfs_rename, /* rename */ + hostfs_stat /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: hostfs_semtake + ****************************************************************************/ + +void hostfs_semtake(struct hostfs_mountpt_s *fs) +{ + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(fs->fs_sem) != 0) + { + /* The only case that an error should occur here is if + * the wait was awakened by a signal. + */ + + ASSERT(*get_errno_ptr() == EINTR); + } +} + +/**************************************************************************** + * Name: hostfs_semgive + ****************************************************************************/ + +void hostfs_semgive(struct hostfs_mountpt_s *fs) +{ + sem_post(fs->fs_sem); +} + +/**************************************************************************** + * Name: hostfs_mkpath + * + * Description: Build absolute host path from relative NuttX path. + * + ****************************************************************************/ + +static void hostfs_mkpath(struct hostfs_mountpt_s *fs, const char *relpath, + char *path, int pathlen) +{ + int depth = 0; + int first; + int x; + + /* Copy base host path to output */ + + strncpy(path, fs->fs_root, pathlen); + + /* Be sure we aren't trying to use ".." to display outside of our + * mounted path. + */ + + x = 0; + while (relpath[x] == '/') + { + x++; + } + + first = x; + + while (relpath[x] != '\0') + { + /* Test for ".." occurance */ + + if (strncmp(&relpath[x], "..", 2) == 0) + { + /* Reduce depth by 1 */ + + depth--; + x += 2; + } + + else if (relpath[x] == '/' && relpath[x+1] != '/' && relpath[x+1] != '\0') + { + depth++; + x++; + } + else + { + x++; + } + } + + if (depth >= 0) + { + strncat(path, &relpath[first], pathlen-strlen(path)-1); + } +} + +/**************************************************************************** + * Name: hostfs_open + ****************************************************************************/ + +static int hostfs_open(FAR struct file *filep, const char *relpath, + int oflags, mode_t mode) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + int ret; + struct hostfs_ofile_s *hf; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT((filep->f_priv == NULL) && (filep->f_inode != NULL)); + + + /* Get the mountpoint inode reference from the file structure and the + * mountpoint private data from the inode structure + */ + + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Allocate memory for the open file */ + + hf = (struct hostfs_ofile_s *) kmm_malloc(sizeof *hf); + if (hf == NULL) + { + ret = -ENOMEM; + goto errout_with_semaphore; + } + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Try to open the file in the host file system */ + + hf->fd = host_open(path, oflags, mode); + if (hf->fd == -1) + { + /* Error opening file */ + + ret = -EBADF; + goto errout_with_buffer; + } + + /* Attach the private date to the struct file instance */ + + filep->f_priv = hf; + + /* Then insert the new instance into the mountpoint structure. + * It needs to be there (1) to handle error conditions that effect + * all files, and (2) to inform the umount logic that we are busy + * (but a simple reference count could have done that). + */ + + hf->fnext = fs->fs_head; + hf->crefs = 1; + hf->oflags = oflags; + fs->fs_head = hf; + + ret = OK; + goto errout_with_semaphore; + +errout_with_buffer: + kmm_free(hf); + +errout_with_semaphore: + hostfs_semgive(fs); + if (ret == -EINVAL) + { + ret = -EIO; + } + + return ret; +} + +/**************************************************************************** + * Name: hostfs_close + ****************************************************************************/ + +static int hostfs_close(FAR struct file *filep) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + struct hostfs_ofile_s *nextfile; + struct hostfs_ofile_s *prevfile; + + /* Sanity checks */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + inode = filep->f_inode; + fs = inode->i_private; + hf = filep->f_priv; + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Check if we are the last one with a reference to the file and + * only close if we are. */ + + if (hf->crefs > 1) + { + /* The file is opened more than once. Just decrement the + * reference count and return. */ + + hf->crefs--; + goto okout; + } + + /* Remove ourselves from the linked list */ + + nextfile = fs->fs_head; + prevfile = nextfile; + while ((nextfile != hf) && (nextfile != NULL)) + { + /* Save the previous file pointer too */ + + prevfile = nextfile; + nextfile = nextfile->fnext; + } + + if (nextfile != NULL) + { + /* Test if we were the first entry */ + + if (nextfile == fs->fs_head) + { + /* Assign a new head */ + + fs->fs_head = nextfile->fnext; + } + else + { + /* Take ourselves out of the list */ + + prevfile->fnext = nextfile->fnext; + } + } + + /* Close the host file */ + + host_close(hf->fd); + + /* Now free the pointer */ + + filep->f_priv = NULL; + kmm_free(hf); + +okout: + hostfs_semgive(fs); + return OK; +} + +/**************************************************************************** + * Name: hostfs_read + ****************************************************************************/ + +static ssize_t hostfs_read(FAR struct file *filep, char *buffer, size_t buflen) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + int ret = OK; + + /* Sanity checks */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + hf = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Call the host to perform the read */ + + ret = host_read(hf->fd, buffer, buflen); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_write + ****************************************************************************/ + +static ssize_t hostfs_write(FAR struct file *filep, const char *buffer, + size_t buflen) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + int ret; + + /* Sanity checks. I have seen the following assertion misfire if + * CONFIG_DEBUG_MM is enabled while re-directing output to a + * file. In this case, the debug output can get generated while + * the file is being opened, FAT data structures are being allocated, + * and things are generally in a perverse state. + */ + +#ifdef CONFIG_DEBUG_MM + if (filep->f_priv == NULL || filep->f_inode == NULL) + { + return -ENXIO; + } +#else + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); +#endif + + /* Recover our private data from the struct file instance */ + + hf = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Test the permissions. Only allow write if the file was opened with + * write flags. + */ + + if ((hf->oflags & O_WROK) == 0) + { + ret = -EACCES; + goto errout_with_semaphore; + } + + /* Call the host to perform the write */ + + ret = host_write(hf->fd, buffer, buflen); + +errout_with_semaphore: + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_seek + ****************************************************************************/ + +static off_t hostfs_seek(FAR struct file *filep, off_t offset, int whence) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + int ret; + + /* Sanity checks */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + hf = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Call our internal routine to perform the seek */ + + ret = host_lseek(hf->fd, offset, whence); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_ioctl + ****************************************************************************/ + +static int hostfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + int ret; + + /* Sanity checks */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + hf = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Call our internal routine to perform the ioctl */ + + ret = host_ioctl(hf->fd, cmd, arg); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_sync + * + * Description: Synchronize the file state on disk to match internal, in- + * memory state. + * + ****************************************************************************/ + +static int hostfs_sync(FAR struct file *filep) +{ + struct inode *inode; + struct hostfs_mountpt_s *fs; + struct hostfs_ofile_s *hf; + + /* Sanity checks */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + hf = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); + + /* Take the semaphore */ + + hostfs_semtake(fs); + + host_sync(hf->fd); + + hostfs_semgive(fs); + return OK; +} + +/**************************************************************************** + * Name: hostfs_dup + * + * Description: Duplicate open file data in the new file structure. + * + ****************************************************************************/ + +static int hostfs_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + struct hostfs_ofile_s *sf; + + /* Sanity checks */ + + DEBUGASSERT(oldp->f_priv != NULL && + newp->f_priv == NULL && + newp->f_inode != NULL); + + /* Recover our private data from the struct file instance */ + + sf = oldp->f_priv; + + DEBUGASSERT(sf != NULL); + + /* Just increment the reference count on the ofile */ + + sf->crefs++; + newp->f_priv = (FAR void *)sf; + + return OK; +} + +/**************************************************************************** + * Name: hostfs_opendir + * + * Description: Open a directory for read access + * + ****************************************************************************/ + +static int hostfs_opendir(struct inode *mountpt, const char *relpath, struct fs_dirent_s *dir) +{ + struct hostfs_mountpt_s *fs; + int ret; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); + + /* Recover our private data from the inode instance */ + + fs = mountpt->i_private; + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Call the host's opendir function */ + + dir->u.hostfs.fs_dir = host_opendir(path); + + if (dir->u.hostfs.fs_dir == NULL) + { + ret = -ENOENT; + goto errout_with_semaphore; + } + + ret = OK; + +errout_with_semaphore: + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_closedir + * + * Description: Open a directory for read access + * + ****************************************************************************/ + +static int hostfs_closedir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) +{ + struct hostfs_mountpt_s *fs; + + /* Sanity checks */ + + DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); + + /* Recover our private data from the inode instance */ + + fs = mountpt->i_private; + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Call the host's closedir function */ + + host_closedir(dir->u.hostfs.fs_dir); + + hostfs_semgive(fs); + return OK; +} + +/**************************************************************************** + * Name: hostfs_readdir + * + * Description: Read the next directory entry + * + ****************************************************************************/ + +static int hostfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) +{ + struct hostfs_mountpt_s *fs; + int ret; + struct host_dirent_s entry; + + /* Sanity checks */ + + DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); + + /* Recover our private data from the inode instance */ + + fs = mountpt->i_private; + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Call the host OS's readdir function */ + + ret = host_readdir(dir->u.hostfs.fs_dir, &entry); + + /* Save the entry name when successful */ + + if (ret == OK) + { + /* Copy the entry name */ + memset(dir->fd_dir.d_name, 0, sizeof(dir->fd_dir.d_name)); + strncpy(dir->fd_dir.d_name, entry.d_name, sizeof(dir->fd_dir.d_name)); + + /* Copy the entry type */ + + /* TODO: May need to do some type mapping */ + + dir->fd_dir.d_type = entry.d_type; + } + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_rewindir + * + * Description: Reset directory read to the first entry + * + ****************************************************************************/ + +static int hostfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir) +{ + /* Sanity checks */ + + DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); + + /* Call the host and let it do all the work */ + + host_rewinddir(dir->u.hostfs.fs_dir); + + return OK; +} + +/**************************************************************************** + * Name: hostfs_bind + * + * Description: This implements a portion of the mount operation. This + * function allocates and initializes the mountpoint private data and + * binds the blockdriver inode to the filesystem private data. The final + * binding of the private data (containing the blockdriver) to the + * mountpoint is performed by mount(). + * + ****************************************************************************/ + +static int hostfs_bind(FAR struct inode *blkdriver, const void *data, + void **handle) +{ + struct hostfs_mountpt_s *fs; + struct host_stat_s buf; + int ret, len; + const char * options; + + /* Validate the block driver is NULL */ + + if (blkdriver || !data) + { + return -ENODEV; + } + + /* The only options we suppor are "-o fs=whatever", so search + * for the 'dir=' portion + */ + + options = (const char *) data; + if ((strncmp(options, "fs=", 3) != 0) || (strlen(options) < 5)) + { + return -ENODEV; + } + + /* Create an instance of the mountpt state structure */ + + fs = (struct hostfs_mountpt_s *)kmm_zalloc(sizeof(struct hostfs_mountpt_s)); + if (!fs) + { + return -ENOMEM; + } + + /* If the global semaphore hasn't been initialized, then + * initialized it now. */ + + fs->fs_sem = &g_sem; + if (!g_seminitialized) + { + /* Initialize the semaphore that controls access */ + + sem_init(&g_sem, 0, 0); + g_seminitialized = TRUE; + } + else + { + /* Take the semaphore for the mount */ + + hostfs_semtake(fs); + } + + /* Initialize the allocated mountpt state structure. The filesystem is + * responsible for one reference ont the blkdriver inode and does not + * have to addref() here (but does have to release in ubind(). + */ + + fs->fs_head = NULL; + + /* Now perform the mount. */ + + strncpy(fs->fs_root, &options[3], sizeof(fs->fs_root)); + len = strlen(fs->fs_root); + if (len && fs->fs_root[len-1] == '/') + { + /* Remove trailing '/' */ + + fs->fs_root[len-1] = '\0'; + } + + /* Try to stat the file in the host FS */ + + ret = host_stat(fs->fs_root, &buf); + if ((ret != 0) || ((buf.st_mode & HOST_ST_MODE_DIR) == 0)) + { + hostfs_semgive(fs); + kmm_free(fs); + return -ENOENT; + } + + /* Append a '/' to the name now */ + + strcat(fs->fs_root, "/"); + + *handle = (FAR void *)fs; + hostfs_semgive(fs); + return OK; +} + +/**************************************************************************** + * Name: hostfs_unbind + * + * Description: This implements the filesystem portion of the umount + * operation. + * + ****************************************************************************/ + +static int hostfs_unbind(FAR void *handle, FAR struct inode **blkdriver, + unsigned int flags) +{ + FAR struct hostfs_mountpt_s *fs = (FAR struct hostfs_mountpt_s *)handle; + int ret; + + if (!fs) + { + return -EINVAL; + } + + /* Check if there are sill any files opened on the filesystem. */ + + ret = OK; /* Assume success */ + hostfs_semtake(fs); + if (fs->fs_head != NULL) + { + /* We cannot unmount now.. there are open files */ + + hostfs_semgive(fs); + + /* This implementation currently only supports unmounting if there are + * no open file references. + */ + + return (flags != 0) ? -ENOSYS : -EBUSY; + } + + hostfs_semgive(fs); + kmm_free(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_statfs + * + * Description: Return filesystem statistics + * + ****************************************************************************/ + +static int hostfs_statfs(struct inode *mountpt, struct statfs *buf) +{ + struct hostfs_mountpt_s *fs; + struct host_statfs_s host_buf; + int ret; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + hostfs_semtake(fs); + + /* Implement the logic!! */ + + memset(buf, 0, sizeof(struct statfs)); + buf->f_type = HOSTFS_MAGIC; + + /* Call the host fs to perform the statfs */ + + ret = host_statfs(fs->fs_root, &host_buf); + + buf->f_namelen = host_buf.f_namelen; + buf->f_bsize = host_buf.f_bsize; + buf->f_blocks = host_buf.f_blocks; + buf->f_bfree = host_buf.f_bfree; + buf->f_bavail = host_buf.f_bavail; + buf->f_files = host_buf.f_files; + buf->f_ffree = host_buf.f_ffree; + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_unlink + * + * Description: Remove a file + * + ****************************************************************************/ + +static int hostfs_unlink(struct inode *mountpt, const char *relpath) +{ + struct hostfs_mountpt_s *fs; + int ret; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Call the host fs to perform the unlink */ + + ret = host_unlink(path); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_mkdir + * + * Description: Create a directory + * + ****************************************************************************/ + +static int hostfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) +{ + struct hostfs_mountpt_s *fs; + int ret; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Call the host FS to do the mkdir */ + + ret = host_mkdir(path, mode); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_rmdir + * + * Description: Remove a directory + * + ****************************************************************************/ + +int hostfs_rmdir(struct inode *mountpt, const char *relpath) +{ + struct hostfs_mountpt_s *fs; + int ret; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + /* Take the semaphore */ + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Call the host FS to do the mkdir */ + + ret = host_rmdir(path); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_rename + * + * Description: Rename a file or directory + * + ****************************************************************************/ + +int hostfs_rename(struct inode *mountpt, const char *oldrelpath, + const char *newrelpath) +{ + struct hostfs_mountpt_s *fs; + int ret; + char oldpath[HOSTFS_MAX_PATH]; + char newpath[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + strncpy(oldpath, fs->fs_root, sizeof(oldpath)); + strncat(oldpath, oldrelpath, sizeof(oldpath)-strlen(oldpath)-1); + strncpy(newpath, fs->fs_root, sizeof(newpath)); + strncat(newpath, newrelpath, sizeof(newpath)-strlen(newpath)-1); + + /* Call the host FS to do the mkdir */ + + ret = host_rename(oldpath, newpath); + + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Name: hostfs_stat + * + * Description: Return information about a file or directory + * + ****************************************************************************/ + +static int hostfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf) +{ + struct hostfs_mountpt_s *fs; + int ret; + struct host_stat_s host_buf; + char path[HOSTFS_MAX_PATH]; + + /* Sanity checks */ + + DEBUGASSERT(mountpt && mountpt->i_private); + + /* Get the mountpoint private data from the inode structure */ + + fs = mountpt->i_private; + + hostfs_semtake(fs); + + /* Append to the host's root directory */ + + hostfs_mkpath(fs, relpath, path, sizeof(path)); + + /* Call the host FS to do the mkdir */ + + ret = host_stat(path, &host_buf); + + if (ret != 0) + { + goto errout_with_semaphore; + } + + /* Initialize the stat structure */ + + memset(buf, 0, sizeof(struct stat)); + + buf->st_mode = host_buf.st_mode & 0xFFF; + + if (host_buf.st_mode & HOST_ST_MODE_DIR) + { + buf->st_mode |= S_IFDIR; + } + + if (host_buf.st_mode & HOST_ST_MODE_REG) + { + buf->st_mode |= S_IFREG; + } + + if (host_buf.st_mode & HOST_ST_MODE_CHR) + { + buf->st_mode |= S_IFCHR; + } + + if (host_buf.st_mode & HOST_ST_MODE_BLK) + { + buf->st_mode |= S_IFBLK; + } + + if (host_buf.st_mode & HOST_ST_MODE_LINK) + { + buf->st_mode |= S_IFLNK; + } + + if (host_buf.st_mode & HOST_ST_MODE_PIPE) + buf->st_mode |= S_IFIFO; + } + + buf->st_size = host_buf.st_size; + buf->st_blksize = host_buf.st_blksize; + buf->st_blocks = host_buf.st_blocks; + buf->st_atime = host_buf.st_atim; + buf->st_ctime = host_buf.st_ctim; + + ret = OK; + +errout_with_semaphore: + hostfs_semgive(fs); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h new file mode 100644 index 0000000000..5e60969835 --- /dev/null +++ b/fs/hostfs/hostfs.h @@ -0,0 +1,117 @@ +/**************************************************************************** + * nuttx/fs/hostfs/hostfs.h + * + * Copyright (C) 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __FS_HOSTFS_HOSTFS_H +#define __FS_HOSTFS_HOSTFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Quasi-standard definitions */ + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + +#ifndef MAX +# define MAX(a,b) (a > b ? a : b) +#endif + +#define HOSTFS_MAX_PATH 256 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This structure describes the state of one open file. This structure + * is protected by the volume semaphore. + */ + +struct hostfs_ofile_s +{ + struct hostfs_ofile_s *fnext; /* Supports a singly linked list */ + int16_t crefs; /* Reference count */ + mode_t oflags; /* Open mode */ + int fd; +}; + +/* This structure represents the overall mountpoint state. An instance of this + * structure is retained as inode private data on each mountpoint that is + * mounted with a hostfs filesystem. + */ + +struct hostfs_mountpt_s +{ + sem_t *fs_sem; /* Used to assure thread-safe access */ + FAR struct hostfs_ofile_s *fs_head; /* A singly-linked list of open files */ + char fs_root[HOSTFS_MAX_PATH]; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Internal function prototypes + ****************************************************************************/ + +/* Semaphore access for internal use */ + +void hostfs_semtake(struct hostfs_mountpt_s *fs); +void hostfs_semgive(struct hostfs_mountpt_s *fs); + +/* Forward references for utility functions */ + +struct hostfs_mountpt_s; + +struct file; /* Forward references */ +struct inode; +struct fs_dirent_s; +struct statfs; +struct stat; + +#endif /* __FS_HOSTFS_HOSTFS_H */ diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index e2f116aa22..533df4c6bc 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -138,6 +138,9 @@ extern const struct mountpt_operations binfs_operations; #ifdef CONFIG_FS_PROCFS extern const struct mountpt_operations procfs_operations; #endif +#ifdef CONFIG_FS_HOSTFS +extern const struct mountpt_operations hostfs_operations; +#endif static const struct fsmap_t g_nonbdfsmap[] = { @@ -155,6 +158,9 @@ static const struct fsmap_t g_nonbdfsmap[] = #endif #ifdef CONFIG_FS_PROCFS { "procfs", &procfs_operations }, +#endif +#ifdef CONFIG_FS_HOSTFS + { "hostfs", &hostfs_operations }, #endif { NULL, NULL }, }; diff --git a/include/nuttx/fs/dirent.h b/include/nuttx/fs/dirent.h index d7b91a80ec..efd270fbee 100644 --- a/include/nuttx/fs/dirent.h +++ b/include/nuttx/fs/dirent.h @@ -177,6 +177,17 @@ struct fs_unionfsdir_s }; #endif +#ifdef CONFIG_FS_HOSTFS +/* HOSTFS provides mapping to directories on the host machine in the + * sim environment. + */ + +struct fs_hostfsdir_s +{ + FAR void * fs_dir; /* Opaque pointer to host DIR * */ +}; +#endif + #endif /* CONFIG_DISABLE_MOUNTPOINT */ struct fs_dirent_s @@ -243,6 +254,9 @@ struct fs_dirent_s #ifdef CONFIG_FS_UNIONFS struct fs_unionfsdir_s unionfs; #endif +#ifdef CONFIG_FS_HOSTFS + struct fs_hostfsdir_s hostfs; +#endif #endif /* !CONFIG_DISABLE_MOUNTPOINT */ } u; diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h new file mode 100644 index 0000000000..0a57797e57 --- /dev/null +++ b/include/nuttx/fs/hostfs.h @@ -0,0 +1,133 @@ +/**************************************************************************** + * include/nuttx/fs/hostfs.h + * + * Copyright (C) 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_FS_HOSTFS_H +#define __INCLUDE_NUTTX_FS_HOSTFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define HOST_ST_MODE_REG 0x01000 +#define HOST_ST_MODE_DIR 0x02000 +#define HOST_ST_MODE_CHR 0x04000 +#define HOST_ST_MODE_BLK 0x08000 +#define HOST_ST_MODE_PIPE 0x10000 +#define HOST_ST_MODE_LINK 0x20000 + +#define HOSTFS_FLAG_RDOK 0x0001 +#define HOSTFS_FLAG_WROK 0x0002 +#define HOSTFS_FLAG_CREAT 0x0004 +#define HOSTFS_FLAG_EXCL 0x0008 +#define HOSTFS_FLAG_APPEND 0x0010 +#define HOSTFS_FLAG_TRUNC 0x0020 + +#define HOSTFS_DTYPE_FILE 0x0001 +#define HOSTFS_DTYPE_CHR 0x0002 +#define HOSTFS_DTYPE_BLK 0x0004 +#define HOSTFS_DTYPE_DIRECTORY 0x0008 + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +struct host_dirent_s +{ + size_t d_ino; + size_t d_off; + unsigned short d_reclen; + unsigned char d_type; + char d_name[256]; +}; + +struct host_statfs_s +{ + size_t f_type; /* Type of file system */ + size_t f_bsize; /* Optimal transfer block size */ + size_t f_blocks; /* Total data blocks in the file system */ + size_t f_bfree; /* Free blocks */ + size_t f_bavail; /* Free blocks available */ + size_t f_files; /* Total file nodes in file system */ + size_t f_ffree; /* Free file nodes in fs */ + size_t f_fsid; /* File Systme ID */ + size_t f_namelen; /* Max length of filenames */ + size_t f_frsize; /* Fragment size */ +}; + +struct host_stat_s +{ + int st_dev; /* ID of the device containing file */ + size_t st_ino; /* inode number */ + size_t st_mode; /* protection */ + size_t st_nlink; /* number of hard links */ + size_t st_uid; /* user ID of owner */ + size_t st_gid; /* group ID of owner */ + size_t st_rdev; /* device ID */ + size_t st_size; /* total size, in bytes */ + size_t st_blksize; /* blocksize for file system I/O */ + size_t st_blocks; /* number of 512B blocks allocated */ + size_t st_atim; /* time of last access */ + size_t st_mtim; /* time of last modification */ + size_t st_ctim; /* time of last status change */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int host_open(const char *pathname, int flags, int mode); +int host_close(int fd); +ssize_t host_read(int fd, void* buf, size_t count); +ssize_t host_write(int fd, const void *buf, size_t count); +off_t host_lseek(int fd, off_t offset, int whence); +int host_ioctl(int fd, int request, unsigned long arg); +void host_sync(int fd); +int host_dup(int fd); +void *host_opendir(const char *name); +int host_readdir(void* dirp, struct host_dirent_s* entry); +void host_rewinddir(void* dirp); +int host_closedir(void* dirp); +int host_statfs(const char *path, struct host_statfs_s *buf); +int host_unlink(const char *pathname); +int host_mkdir(const char *pathname, mode_t mode); +int host_rmdir(const char *pathname); +int host_rename(const char *oldpath, const char *newpath); +int host_stat(const char *path, struct host_stat_s *buf); + +#endif /* __INCLUDE_NUTTX_FS_HOSTFS_H */ diff --git a/include/sys/statfs.h b/include/sys/statfs.h index 4daf188e9a..1d1786a3f8 100644 --- a/include/sys/statfs.h +++ b/include/sys/statfs.h @@ -103,6 +103,7 @@ #define NXFFS_MAGIC 0x4747 #define SMARTFS_MAGIC 0x54524D53 #define UNIONFS_MAGIC 0x53464e55 +#define HOSTFS_MAGIC 0x54534f48 /**************************************************************************** * Type Definitions -- GitLab From 8f5047323fd3c932197fc3abafe19c69654e5590 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 08:38:58 -0600 Subject: [PATCH 361/858] Update ChangeLog and submodules --- ChangeLog | 7 +++---- arch | 2 +- fs/hostfs/hostfs.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02abd97d7e..560b838ccf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11145,7 +11145,6 @@ that sizeof(size_t) should be the same as sizeof(uinptr_t). mmsize_t should always be 32-bits in any event. The last change to stddef has been backed out. With these changes, the simulator builds without - * fs/hostfs: Add a special file system for use with simulator that - supports access to the host file system from the simulation. From - Ken Petit (2015-11-25). - + * fs/hostfs and arch/sim/src: Add a special file system for use with + simulator that supports access to the host file system from the + simulation. From Ken Petit (2015-11-25). diff --git a/arch b/arch index 93f8b673c8..6e383188c0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 93f8b673c8d0c4d3f534ef08163d51187a07a390 +Subproject commit 6e383188c0735cb0f813db3d5142541ffd80dad8 diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h index 5e60969835..3982e09184 100644 --- a/fs/hostfs/hostfs.h +++ b/fs/hostfs/hostfs.h @@ -96,7 +96,7 @@ struct hostfs_mountpt_s ****************************************************************************/ /**************************************************************************** - * Internal function prototypes + * Public Function Prototypes ****************************************************************************/ /* Semaphore access for internal use */ -- GitLab From 070d95d161c2491c8042a21683e048b1e7941c89 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 09:11:03 -0600 Subject: [PATCH 362/858] Trivial change --- fs/hostfs/hostfs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h index 3982e09184..17227611a1 100644 --- a/fs/hostfs/hostfs.h +++ b/fs/hostfs/hostfs.h @@ -54,14 +54,14 @@ /* Quasi-standard definitions */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (a < b ? a : b) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (a > b ? a : b) #endif -#define HOSTFS_MAX_PATH 256 +#define HOSTFS_MAX_PATH 256 /**************************************************************************** * Public Types @@ -96,7 +96,7 @@ struct hostfs_mountpt_s ****************************************************************************/ /**************************************************************************** - * Public Function Prototypes + * Internal function prototypes ****************************************************************************/ /* Semaphore access for internal use */ -- GitLab From 064ef4f1fb98401c0034b23d8cdb4b131e24f213 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 11:51:46 -0600 Subject: [PATCH 363/858] At day-of-week support to strftime() --- configs | 2 +- libc/time/lib_strftime.c | 42 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/configs b/configs index 98ebc3e0a5..c8d8045996 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 98ebc3e0a5f2313942a5083bbc177388aad59fb3 +Subproject commit c8d80459962144a49edfc6861127b66c13009320 diff --git a/libc/time/lib_strftime.c b/libc/time/lib_strftime.c index 83171c7cb4..6d338fa66d 100644 --- a/libc/time/lib_strftime.c +++ b/libc/time/lib_strftime.c @@ -70,7 +70,19 @@ * Private Data ****************************************************************************/ -static const char * const g_abbrevmonthname[12] = +#ifdef CONFIG_TIME_EXTENDED +static const char * const g_abbrev_wdayname[7] = +{ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char * const g_wdayname[7] = +{ + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" +}; +#endif + +static const char * const g_abbrev_monthname[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" @@ -169,6 +181,31 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, switch (*format++) { +#ifdef CONFIG_TIME_EXTENDED + /* %a: A three-letter abbreviation for the day of the week. */ + + case 'a': + { + if (tm->tm_wday < 7) + { + str = g_abbrev_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %A: The full name for the day of the week. */ + + case 'A': + { + if (tm->tm_wday < 7) + { + str = g_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; +#else /* %a: A three-letter abbreviation for the day of the week. */ /* %A: The full name for the day of the week. */ @@ -178,6 +215,7 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, len = snprintf(dest, chleft, "Day"); /* Not supported */ } break; +#endif /* %h: Equivalent to %b */ @@ -189,7 +227,7 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, { if (tm->tm_mon < 12) { - str = g_abbrevmonthname[tm->tm_mon]; + str = g_abbrev_monthname[tm->tm_mon]; len = snprintf(dest, chleft, "%s", str); } } -- GitLab From fb0a148812459d27da1e6c1f709f6e40b9f63fe7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 12:02:25 -0600 Subject: [PATCH 364/858] Update ChangeLog/TODO --- ChangeLog | 2 ++ TODO | 9 ++------- configs | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 560b838ccf..3eaa45621e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11148,3 +11148,5 @@ * fs/hostfs and arch/sim/src: Add a special file system for use with simulator that supports access to the host file system from the simulation. From Ken Petit (2015-11-25). + * libc/time/lib_strftime.c: Add day-of-week support. (2015-11-25). + diff --git a/TODO b/TODO index 4fae0d8c11..bc7a4bdb83 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated November 21, 2015) +NuttX TODO List (Last updated November 25, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -18,7 +18,7 @@ nuttx/ (6) Binary loaders (binfmt/) (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) - (12) Libraries (libc/, libm/) + (11) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) (8) Graphics subsystem (graphics/) (1) Pascal add-on (pcode/) @@ -1220,11 +1220,6 @@ o Libraries (libc/) Status: Open Priority: Low - Title: DAYS OF THE WEEK - Description: strftime() and other timing functions do not handle days of the week. - Status: Open - Priority: Low - Title: RESETTING GETOPT() Description: There is an issue with the way that getopt() handles errors that return '?'. diff --git a/configs b/configs index c8d8045996..bf0c883295 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c8d80459962144a49edfc6861127b66c13009320 +Subproject commit bf0c88329540d1e674e0c2bfeee2350e7898c5b5 -- GitLab From e5f27f5865aa088e955a1a1550ca078b192beccf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 12:51:45 -0600 Subject: [PATCH 365/858] Fix some conditional compilation. CONFIG_LIBC_LOCALTIME should be checked in most of the same places wehre CONFIG_TIME_EXTENDED is checked --- Documentation | 2 +- arch | 2 +- include/nuttx/timers/rtc.h | 2 +- include/time.h | 2 +- libc/time/lib_asctime.c | 4 ++-- libc/time/lib_asctimer.c | 4 ++-- libc/time/lib_ctime.c | 4 ++-- libc/time/lib_ctimer.c | 4 ++-- libc/time/lib_strftime.c | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Documentation b/Documentation index 9ad99e6fed..1972785856 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 9ad99e6fed5b7b654ce805e6ec77f7d6287746b2 +Subproject commit 197278585682ff0a7caee714f7706a0361b80144 diff --git a/arch b/arch index 6e383188c0..6fa995b0aa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6e383188c0735cb0f813db3d5142541ffd80dad8 +Subproject commit 6fa995b0aac7816b4250c41a737309417f6e2d1e diff --git a/include/nuttx/timers/rtc.h b/include/nuttx/timers/rtc.h index 7cbc928d92..a6e3edcc19 100644 --- a/include/nuttx/timers/rtc.h +++ b/include/nuttx/timers/rtc.h @@ -291,7 +291,7 @@ struct rtc_time int tm_mday; /* Day of the month (1-31) */ int tm_mon; /* Month (0-11) */ int tm_year; /* Years since 1900 */ -#ifdef CONFIG_LIBC_LOCALTIME +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) int tm_wday; /* Day of the week (0-6) (unused) */ int tm_yday; /* Day of the year (0-365) (unused) */ int tm_isdst; /* Non-0 if daylight savings time is in effect (unused) */ diff --git a/include/time.h b/include/time.h index 8608c22fdf..0fd4b7611b 100644 --- a/include/time.h +++ b/include/time.h @@ -205,7 +205,7 @@ FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result); size_t strftime(FAR char *s, size_t max, FAR const char *format, FAR const struct tm *tm); -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) FAR char *asctime(FAR const struct tm *tp); FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf); FAR char *ctime(FAR const time_t *timep); diff --git a/libc/time/lib_asctime.c b/libc/time/lib_asctime.c index 6583969dc8..cd15699559 100644 --- a/libc/time/lib_asctime.c +++ b/libc/time/lib_asctime.c @@ -41,7 +41,7 @@ #include -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /**************************************************************************** * Public Functions @@ -70,4 +70,4 @@ FAR char *asctime(FAR const struct tm *tp) return asctime_r(tp, buf); } -#endif /* CONFIG_TIME_EXTENDED */ +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_asctimer.c b/libc/time/lib_asctimer.c index 77ee312796..0235b89c15 100644 --- a/libc/time/lib_asctimer.c +++ b/libc/time/lib_asctimer.c @@ -42,7 +42,7 @@ #include #include -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /**************************************************************************** * Private Data @@ -94,4 +94,4 @@ FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf) return buf; } -#endif /* CONFIG_TIME_EXTENDED */ +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_ctime.c b/libc/time/lib_ctime.c index 2d0b8023ab..6d1bcb8efe 100644 --- a/libc/time/lib_ctime.c +++ b/libc/time/lib_ctime.c @@ -41,7 +41,7 @@ #include -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /**************************************************************************** * Public Functions @@ -79,4 +79,4 @@ FAR char *ctime(FAR const time_t *timep) #endif } -#endif /* CONFIG_TIME_EXTENDED */ +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_ctimer.c b/libc/time/lib_ctimer.c index 7f7cf0b31c..935a72bbd6 100644 --- a/libc/time/lib_ctimer.c +++ b/libc/time/lib_ctimer.c @@ -41,7 +41,7 @@ #include -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /**************************************************************************** * Private Data @@ -80,4 +80,4 @@ FAR char *ctime_r(FAR const time_t *timep, FAR char *buf) #endif } -#endif /* CONFIG_TIME_EXTENDED */ +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_strftime.c b/libc/time/lib_strftime.c index 6d338fa66d..fafdedc6b4 100644 --- a/libc/time/lib_strftime.c +++ b/libc/time/lib_strftime.c @@ -181,7 +181,7 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, switch (*format++) { -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) /* %a: A three-letter abbreviation for the day of the week. */ case 'a': -- GitLab From b1b97e89c8792b326aa7c3a2c737f556c8c289c8 Mon Sep 17 00:00:00 2001 From: Marco Krahl Date: Wed, 25 Nov 2015 13:01:37 -0600 Subject: [PATCH 366/858] drivers/lcd/ili9432.c: Fixed errors in orientation. Portrait, RPortrait, and RLandscript should work correly now. They were displayed mirrored. From Marco Krahl --- ChangeLog | 3 +++ drivers/lcd/ili9341.c | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3eaa45621e..9c7be4e864 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11149,4 +11149,7 @@ simulator that supports access to the host file system from the simulation. From Ken Petit (2015-11-25). * libc/time/lib_strftime.c: Add day-of-week support. (2015-11-25). + * drivers/lcd/ili9432.c: Fixed errors in orientation. Portrait, + RPortrait, and RLandscript should work correly now. They were + displayed mirrored. From Marco Krahl (2015-11-25). diff --git a/drivers/lcd/ili9341.c b/drivers/lcd/ili9341.c index 7fb8612db7..1c19187ab5 100644 --- a/drivers/lcd/ili9341.c +++ b/drivers/lcd/ili9341.c @@ -195,9 +195,9 @@ */ #define ILI9341_MADCTL_PORTRAIT_MY 0 -#define ILI9341_MADCTL_PORTRAIT_MX 0 +#define ILI9341_MADCTL_PORTRAIT_MX ILI9341_MEMORY_ACCESS_CONTROL_MX #define ILI9341_MADCTL_PORTRAIT_MV 0 -#define ILI9341_MADCTL_PORTRAIT_ML 0 +#define ILI9341_MADCTL_PORTRAIT_ML ILI9341_MEMORY_ACCESS_CONTROL_ML #ifdef CONFIG_BIG_ENDIAN # define ILI9341_MADCTL_PORTRAIT_BGR 0 #else @@ -221,7 +221,7 @@ * MH: 0 */ -#define ILI9341_MADCTL_RLANDSCAPE_MY 0 +#define ILI9341_MADCTL_RLANDSCAPE_MY ILI9341_MEMORY_ACCESS_CONTROL_MY #define ILI9341_MADCTL_RLANDSCAPE_MX ILI9341_MEMORY_ACCESS_CONTROL_MX #define ILI9341_MADCTL_RLANDSCAPE_MV ILI9341_MEMORY_ACCESS_CONTROL_MV #define ILI9341_MADCTL_RLANDSCAPE_ML 0 @@ -252,9 +252,9 @@ */ #define ILI9341_MADCTL_RPORTRAIT_MY ILI9341_MEMORY_ACCESS_CONTROL_MY -#define ILI9341_MADCTL_RPORTRAIT_MX ILI9341_MEMORY_ACCESS_CONTROL_MX +#define ILI9341_MADCTL_RPORTRAIT_MX 0 #define ILI9341_MADCTL_RPORTRAIT_MV 0 -#define ILI9341_MADCTL_RPORTRAIT_ML 0 +#define ILI9341_MADCTL_RPORTRAIT_ML ILI9341_MEMORY_ACCESS_CONTROL_ML #ifdef CONFIG_BIG_ENDIAN # define ILI9341_MADCTL_RPORTRAIT_BGR 0 #else -- GitLab From 9d1404e06d32e7ab84252f0e64f9e318d6508e18 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 14:38:10 -0600 Subject: [PATCH 367/858] Fix an error introduced in last commit --- fs/hostfs/hostfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index 6e45e86353..77aa771c92 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -1196,6 +1196,7 @@ static int hostfs_stat(struct inode *mountpt, const char *relpath, struct stat * } if (host_buf.st_mode & HOST_ST_MODE_PIPE) + { buf->st_mode |= S_IFIFO; } -- GitLab From d4a58af3808895e2d4ef8af74f47690039575be2 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Wed, 25 Nov 2015 14:46:28 -0600 Subject: [PATCH 368/858] drivers/mtd/mtd/mtd_procfs/c and include/nuttx/mtd/mtd.h: Add an interface to un-regiser an MTD procfs entry. drivers/mtd/filemtd.c: New new MTD conversion layer that will convert a regular file (or driver file) to an MTD device. This is useful for testing on the simulation using the hostfs. From Ken Petit --- ChangeLog | 8 +- drivers/mtd/filemtd.c | 590 +++++++++++++++++++++++++++++++++++++++ drivers/mtd/mtd_procfs.c | 41 +++ include/nuttx/mtd/mtd.h | 27 ++ 4 files changed, 665 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/filemtd.c diff --git a/ChangeLog b/ChangeLog index 9c7be4e864..4dbe42cd16 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11152,4 +11152,10 @@ * drivers/lcd/ili9432.c: Fixed errors in orientation. Portrait, RPortrait, and RLandscript should work correly now. They were displayed mirrored. From Marco Krahl (2015-11-25). - + * drivers/mtd/mtd/mtd_procfs/c and include/nuttx/mtd/mtd.h: Add an + interface to un-regiser an MTD procfs entry. From Ken Petit + (2015-11-25). + * drivers/mtd/filemtd.c: New new MTD conversion layer that will + convert a regular file (or driver file) to an MTD device. This is + useful for testing on the simulation using the hostfs. From Ken + Petit (2015-11-25). diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c new file mode 100644 index 0000000000..ba24f4a023 --- /dev/null +++ b/drivers/mtd/filemtd.c @@ -0,0 +1,590 @@ +/**************************************************************************** + * drivers/mtd/filemtd.c + * + * Copyright (C) 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_FILEMTD_BLOCKSIZE +# define CONFIG_FILEMTD_BLOCKSIZE 512 +#endif + +#ifndef CONFIG_FILEMTD_ERASESIZE +# define CONFIG_FILEMTD_ERASESIZE 4096 +#endif + +#ifndef CONFIG_FILEMTD_ERASESTATE +# define CONFIG_FILEMTD_ERASESTATE 0xff +#endif + +#if CONFIG_FILEMTD_ERASESTATE != 0xff && CONFIG_FILEMTD_ERASESTATE != 0x00 +# error "Unsupported value for CONFIG_FILEMTD_ERASESTATE" +#endif + +#if CONFIG_FILEMTD_BLOCKSIZE > CONFIG_FILEMTD_ERASESIZE +# error "Must have CONFIG_FILEMTD_BLOCKSIZE <= CONFIG_FILEMTD_ERASESIZE" +#endif + +#undef FILEMTD_BLKPER +#define FILEMTD_BLKPER (CONFIG_FILEMTD_ERASESIZE/CONFIG_FILEMTD_BLOCKSIZE) + +#if FILEMTD_BLKPER*CONFIG_FILEMTD_BLOCKSIZE != CONFIG_FILEMTD_ERASESIZE +# error "CONFIG_FILEMTD_ERASESIZE must be an even multiple of CONFIG_FILEMTD_BLOCKSIZE" +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This type represents the state of the MTD device. The struct mtd_dev_s + * must appear at the beginning of the definition so that you can freely + * cast between pointers to struct mtd_dev_s and struct file_dev_s. + */ + +struct file_dev_s +{ + struct mtd_dev_s mtd; /* MTD device */ + int fd; /* File descriptor of underlying file */ + size_t nblocks; /* Number of erase blocks */ + size_t offset; /* Offset from start of file */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static ssize_t filemtd_read(FAR struct file_dev_s *priv, unsigned char *buffer, + size_t offsetbytes, unsigned int nbytes); +static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, FAR const void *src, size_t len); + +/* MTD driver methods */ + +static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); +static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR uint8_t *buf); +static ssize_t file_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR const uint8_t *buf); +static ssize_t file_byteread(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buf); +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buf); +#endif +static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: filemtd_write + ****************************************************************************/ + +static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, + FAR const void *src, size_t len) +{ + FAR const uint8_t *pin = (FAR const uint8_t *)src; + FAR uint8_t *pout; + char buf[128]; + int buflen = 0; + uint8_t oldvalue; + uint8_t srcvalue; + uint8_t newvalue; + size_t seekpos; + + /* Set the starting location in the file */ + + seekpos = priv->offset + offset; + + while (len-- > 0) + { + if (buflen == 0) + { + /* Read more data from the file */ + + lseek(priv->fd, seekpos, SEEK_SET); + buflen = read(priv->fd, buf, sizeof(buf)); + pout = (FAR uint8_t *) buf; + } + + /* Get the source and destination values */ + + oldvalue = *pout; + srcvalue = *pin++; + + /* Get the new destination value, accounting for bits that cannot be + * changes because they are not in the erased state. + */ + +#if CONFIG_FILEMTD_ERASESTATE == 0xff + newvalue = oldvalue & srcvalue; /* We can only clear bits */ +#else /* CONFIG_FILEMTD_ERASESTATE == 0x00 */ + newvalue = oldvalue | srcvalue; /* We can only set bits */ +#endif + + /* Report any attempt to change the value of bits that are not in the + * erased state. + */ + +#ifdef CONFIG_DEBUG + if (newvalue != srcvalue) + { + dbg("ERROR: Bad write: source=%02x dest=%02x result=%02x\n", + srcvalue, oldvalue, newvalue); + } +#endif + + /* Write the modified value to simulated FLASH */ + + *pout++ = newvalue; + buflen--; + + /* If our buffer is full, then seek back to beginning of + * the file and write the buffer contents + */ + + if (buflen == 0) + { + lseek(priv->fd, seekpos, SEEK_SET); + write(priv->fd, buf, sizeof(buf)); + seekpos += sizeof(buf); + } + } + + /* Write remaining bytes */ + + if (buflen != 0) + { + lseek(priv->fd, seekpos, SEEK_SET); + write(priv->fd, buf, sizeof(buf)); + } + + return len; +} + +/**************************************************************************** + * Name: filemtd_read + ****************************************************************************/ + +static ssize_t filemtd_read(FAR struct file_dev_s *priv, unsigned char *buffer, + size_t offsetbytes, unsigned int nbytes) +{ + /* Set the starting location in the file */ + + lseek(priv->fd, priv->offset + offsetbytes, SEEK_SET); + + return read(priv->fd, buffer, nbytes); +} + +/**************************************************************************** + * Name: file_erase + ****************************************************************************/ + +static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + size_t nbytes; + size_t offset; + char buffer[128]; + + DEBUGASSERT(dev); + + /* Don't let the erase exceed the original size of the file */ + + if (startblock >= priv->nblocks) + { + return 0; + } + + if (startblock + nblocks > priv->nblocks) + { + nblocks = priv->nblocks - startblock; + } + + /* Convert the erase block to a logical block and the number of blocks + * in logical block numbers + */ + + startblock *= FILEMTD_BLKPER; + nblocks *= FILEMTD_BLKPER; + + /* Get the offset corresponding to the first block and the size + * corresponding to the number of blocks. + */ + + offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; + nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + + /* Then erase the data in the file */ + + lseek(priv->fd, priv->offset + offset, SEEK_SET); + memset(buffer, CONFIG_FILEMTD_ERASESTATE, sizeof(buffer)); + while (nbytes) + { + write(priv->fd, buffer, sizeof(buffer)); + nbytes -= sizeof(buffer); + } + + return OK; +} + +/**************************************************************************** + * Name: file_bread + ****************************************************************************/ + +static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR uint8_t *buf) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + off_t offset; + off_t maxblock; + size_t nbytes; + + DEBUGASSERT(dev && buf); + + /* Don't let the read exceed the original size of the file */ + + maxblock = priv->nblocks * FILEMTD_BLKPER; + if (startblock >= maxblock) + { + return 0; + } + + if (startblock + nblocks > maxblock) + { + nblocks = maxblock - startblock; + } + + /* Get the offset corresponding to the first block and the size + * corresponding to the number of blocks. + */ + + offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; + nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + + /* Then read the data from the file */ + + filemtd_read(priv, buf, offset, nbytes); + return nblocks; +} + +/**************************************************************************** + * Name: file_bwrite + ****************************************************************************/ + +static ssize_t file_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + off_t offset; + off_t maxblock; + size_t nbytes; + + DEBUGASSERT(dev && buf); + + /* Don't let the write exceed the original size of the file */ + + maxblock = priv->nblocks * FILEMTD_BLKPER; + if (startblock >= maxblock) + { + return 0; + } + + if (startblock + nblocks > maxblock) + { + nblocks = maxblock - startblock; + } + + /* Get the offset corresponding to the first block and the size + * corresponding to the number of blocks. + */ + + offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; + nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + + /* Then write the data to the file */ + + filemtd_write(priv, offset, buf, nbytes); + return nblocks; +} + +/**************************************************************************** + * Name: file_byteread + ****************************************************************************/ + +static ssize_t file_byteread(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buf) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + + DEBUGASSERT(dev && buf); + + /* Don't let read read past end of buffer */ + + if (offset + nbytes > priv->nblocks * CONFIG_FILEMTD_ERASESIZE) + { + return 0; + } + + filemtd_read(priv, buf, offset, nbytes); + return nbytes; +} + +/**************************************************************************** + * Name: file_bytewrite + ****************************************************************************/ + +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buf) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + off_t maxoffset; + + DEBUGASSERT(dev && buf); + + /* Don't let the write exceed the original size of the file */ + + maxoffset = priv->nblocks * CONFIG_FILEMTD_ERASESIZE; + if (offset + nbytes > maxoffset) + { + return 0; + } + + /* Then write the data to the file */ + + filemtd_write(priv, offset, buf, nbytes); + return nbytes; +} +#endif + +/**************************************************************************** + * Name: file_ioctl + ****************************************************************************/ + +static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; + int ret = -EINVAL; /* Assume good command with bad parameters */ + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) + { + /* Populate the geometry structure with information need to know + * the capacity and how to access the device. + */ + + geo->blocksize = CONFIG_FILEMTD_BLOCKSIZE; + geo->erasesize = CONFIG_FILEMTD_ERASESIZE; + geo->neraseblocks = priv->nblocks; + ret = OK; + } + } + break; + + case MTDIOC_XIPBASE: + ret = -ENOTTY; /* Bad command */ + break; + + case MTDIOC_BULKERASE: + { + /* Erase the entire device */ + + file_erase(dev, 0, priv->nblocks); + ret = OK; + } + break; + + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: filemtd_initialize + * + * Description: + * Create and initialize a FILE MTD device instance. + * + * Input Parameters: + * path - Path name of the file backing the MTD device + * + ****************************************************************************/ + +FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset) +{ + FAR struct file_dev_s *priv; + struct stat sb; + size_t nblocks; + size_t filelen; + int mode, ret; + + /* Create an instance of the FILE MTD device state structure */ + + priv = (FAR struct file_dev_s *)kmm_zalloc(sizeof(struct file_dev_s)); + if (!priv) + { + fdbg("Failed to allocate the FILE MTD state structure\n"); + return NULL; + } + + /* Determine the file open mode */ + + mode = O_RDOK; +#ifdef CONFIG_FS_WRITABLE + mode |= O_WROK; +#endif + + /* Stat the file */ + + ret = stat(path, &sb); + if (ret < 0) + { + dbg("Failed to stat %s: %d\n", path, get_errno()); + return NULL; + } + + filelen = sb.st_size; + + /* Try to open the file */ + + priv->fd = open(path, mode); + if (priv->fd == -1) + { + fdbg("Failed to open the FILE MTD file %s\n", path); + kmm_free(priv); + return NULL; + } + + /* Force the size to be an even number of the erase block size */ + + nblocks = (filelen - offset) / CONFIG_FILEMTD_ERASESIZE; + if (nblocks < 3) + { + fdbg("Need to provide at least three full erase block\n"); + kmm_free(priv); + return NULL; + } + + /* Perform initialization as necessary. (unsupported methods were + * nullified by kmm_zalloc). + */ + + priv->mtd.erase = file_erase; + priv->mtd.bread = file_bread; + priv->mtd.bwrite = file_bwrite; + priv->mtd.read = file_byteread; +#ifdef CONFIG_MTD_BYTE_WRITE + priv->mtd.write = file_bytewrite; +#endif + priv->mtd.ioctl = file_ioctl; + priv->offset = offset; + priv->nblocks = nblocks; + + /* Register the MTD with the procfs system if enabled */ + +#ifdef CONFIG_MTD_REGISTRATION + mtd_register(&priv->mtd, "filemtd"); +#endif + + return &priv->mtd; +} + +/**************************************************************************** + * Name: filemtd_teardown + * + * Description: + * Teardown a previously created filemtd device. + * + * Input Parameters: + * path - Path name of the file backing the MTD device + * + ****************************************************************************/ + +void filemtd_teardown(FAR struct mtd_dev_s *dev) +{ + FAR struct file_dev_s *priv; + + /* Close the enclosed file */ + + priv = (FAR struct file_dev_s *) dev; + close(priv->fd); + + /* Register the MTD with the procfs system if enabled */ + +#ifdef CONFIG_MTD_REGISTRATION + mtd_unregister(&priv->mtd); +#endif + + /* Free the memory */ + + kmm_free(priv); +} + diff --git a/drivers/mtd/mtd_procfs.c b/drivers/mtd/mtd_procfs.c index 2f640b1a3f..b410df8756 100644 --- a/drivers/mtd/mtd_procfs.c +++ b/drivers/mtd/mtd_procfs.c @@ -363,4 +363,45 @@ int mtd_register(FAR struct mtd_dev_s *mtd, FAR const char *name) return OK; } +/**************************************************************************** + * Name: mtd_unregister + * + * Description: + * Un-Registers an MTD device with the procfs file system. + * + * In an embedded system, this all is really unnecessary, but is provided + * in the procfs system simply for information purposes (if desired). + * + ****************************************************************************/ + +int mtd_unregister(FAR struct mtd_dev_s *mtd) +{ + FAR struct mtd_dev_s *plast; + + /* Remove the MTD from the list of registered devices */ + + if (g_pfirstmtd == mtd) + { + g_pfirstmtd = mtd->pnext; + } + else + { + /* Remove from middle of list */ + + plast = g_pfirstmtd; + while (plast->pnext != mtd) + { + /* Skip to next entry as long as there is one */ + + plast = plast->pnext; + } + + /* Now remove at this location */ + + plast->pnext = mtd->pnext; + } + + return OK; +} + #endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 4bd25a612f..367fbad1b8 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -524,6 +524,18 @@ FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, FAR struct mtd_dev_s *up_flashinitialize(void); +/**************************************************************************** + * Name: up_flashinitialize + * + * Description: + * Create a file backed MTD device. + * + ****************************************************************************/ + +FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset); + +void filemtd_teardown(FAR struct mtd_dev_s* mtd); + /**************************************************************************** * Name: mtd_register * @@ -541,6 +553,21 @@ FAR struct mtd_dev_s *up_flashinitialize(void); int mtd_register(FAR struct mtd_dev_s *mtd, FAR const char *name); #endif +/**************************************************************************** + * Name: mtd_unregister + * + * Description: + * Un-registers an MTD device with the procfs file system. + * + * In an embedded system, this all is really unnecessary, but is provided + * in the procfs system simply for information purposes (if desired). + * + ****************************************************************************/ + +#ifdef CONFIG_MTD_REGISTRATION +int mtd_unregister(FAR struct mtd_dev_s *mtd); +#endif + #undef EXTERN #ifdef __cplusplus } -- GitLab From 6ff67d3061a5727b1b5c43cb563baf926d779913 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 14:57:25 -0600 Subject: [PATCH 369/858] Minor changes from code review --- drivers/mtd/filemtd.c | 57 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index ba24f4a023..c4dee5db75 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -105,28 +105,28 @@ struct file_dev_s * Private Function Prototypes ****************************************************************************/ -static ssize_t filemtd_read(FAR struct file_dev_s *priv, unsigned char *buffer, - size_t offsetbytes, unsigned int nbytes); -static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, FAR const void *src, size_t len); +static ssize_t filemtd_read(FAR struct file_dev_s *priv, + FAR unsigned char *buffer, size_t offsetbytes, + unsigned int nbytes); +static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, + FAR const void *src, size_t len); /* MTD driver methods */ -static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); -static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buf); -static ssize_t file_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR const uint8_t *buf); +static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks); +static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t file_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); static ssize_t file_byteread(FAR struct mtd_dev_s *dev, off_t offset, - size_t nbytes, FAR uint8_t *buf); + size_t nbytes, FAR uint8_t *buf); #ifdef CONFIG_MTD_BYTE_WRITE static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, - size_t nbytes, FAR const uint8_t *buf); + size_t nbytes, FAR const uint8_t *buf); #endif -static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ +static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, + unsigned long arg); /**************************************************************************** * Private Functions @@ -137,7 +137,7 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); ****************************************************************************/ static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, - FAR const void *src, size_t len) + FAR const void *src, size_t len) { FAR const uint8_t *pin = (FAR const uint8_t *)src; FAR uint8_t *pout; @@ -222,8 +222,9 @@ static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, * Name: filemtd_read ****************************************************************************/ -static ssize_t filemtd_read(FAR struct file_dev_s *priv, unsigned char *buffer, - size_t offsetbytes, unsigned int nbytes) +static ssize_t filemtd_read(FAR struct file_dev_s *priv, + FAR unsigned char *buffer, size_t offsetbytes, + unsigned int nbytes) { /* Set the starting location in the file */ @@ -236,7 +237,8 @@ static ssize_t filemtd_read(FAR struct file_dev_s *priv, unsigned char *buffer, * Name: file_erase ****************************************************************************/ -static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks) { FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; size_t nbytes; @@ -288,8 +290,8 @@ static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblock * Name: file_bread ****************************************************************************/ -static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buf) +static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf) { FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev; off_t offset; @@ -427,7 +429,9 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { case MTDIOC_GEOMETRY: { - FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + FAR struct mtd_geometry_s *geo = + (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) { /* Populate the geometry structure with information need to know @@ -438,7 +442,7 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) geo->erasesize = CONFIG_FILEMTD_ERASESIZE; geo->neraseblocks = priv->nblocks; ret = OK; - } + } } break; @@ -448,10 +452,10 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) case MTDIOC_BULKERASE: { - /* Erase the entire device */ + /* Erase the entire device */ - file_erase(dev, 0, priv->nblocks); - ret = OK; + file_erase(dev, 0, priv->nblocks); + ret = OK; } break; @@ -587,4 +591,3 @@ void filemtd_teardown(FAR struct mtd_dev_s *dev) kmm_free(priv); } - -- GitLab From e665b3dba8760022dd1e264bb7d79fd9c6e5b9b5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 15:41:43 -0600 Subject: [PATCH 370/858] Update TODO list --- TODO | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/TODO b/TODO index bc7a4bdb83..bc792e6236 100644 --- a/TODO +++ b/TODO @@ -448,6 +448,28 @@ o Kernel/Protected Build ifconfig netdev_foreach(), g_netstats ping icmp_ping() + The busybox mkfatfs does not involve any OS calls; it does + its job by simply opening the block driver (using open/xopen) + and modifying it with write operations. See: + + http://git.busybox.net/busybox/tree/util-linux/mkfs_vfat.c + + Here is how the Busybox/Linux losetup works: + + This is the busybox losetup(): + + http://git.busybox.net/busybox/tree/util-linux/losetup.c . + + You can see that it relies on query_loop(), set_loop(), and + del_loop() to do the really work. query_loop() and friends + are here: + + http://git.busybox.net/busybox/tree/libbb/loop.c. + + They each open a device and interface with it using ioctl calls. + That is probably how NuttX should do things as well. But that + is pretty much a redesign. + Status: Open Priority: Medium/High -- the kernel build configuration is not fully fielded yet. -- GitLab From b84da6e696eec2b63fbad5aacb147d90b557fcaf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 16:23:19 -0600 Subject: [PATCH 371/858] drivers/loop: Move drivers/loop.c to drivers/loop/losetup.c --- drivers/Kconfig | 8 +---- drivers/Makefile | 3 +- drivers/README.txt | 29 +++++++++------- drivers/loop/Kconfig | 11 ++++++ drivers/loop/Make.defs | 54 ++++++++++++++++++++++++++++++ drivers/{loop.c => loop/losetup.c} | 4 +-- 6 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 drivers/loop/Kconfig create mode 100644 drivers/loop/Make.defs rename drivers/{loop.c => loop/losetup.c} (99%) diff --git a/drivers/Kconfig b/drivers/Kconfig index 52f5b5a6f5..3ed0446dd3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -27,13 +27,7 @@ config DEV_RANDOM default n depends on ARCH_HAVE_RNG -config LOOP - bool "Enable loop device" - default n - ---help--- - Supports the standard loop device that can be used to export a - file (or character device) as a block device. See losetup() and - loteardown() in include/nuttx/fs/fs.h. +source drivers/loop/Kconfig menu "Buffering" diff --git a/drivers/Makefile b/drivers/Makefile index 80630ed5af..8f55200581 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -55,6 +55,7 @@ include bch$(DELIM)Make.defs include input$(DELIM)Make.defs include discrete$(DELIM)Make.defs include lcd$(DELIM)Make.defs +include loop$(DELIM)Make.defs include mmcsd$(DELIM)Make.defs include mtd$(DELIM)Make.defs include eeprom$(DELIM)Make.defs @@ -76,7 +77,7 @@ ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) CSRCS += dev_null.c dev_zero.c ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) - CSRCS += ramdisk.c loop.c + CSRCS += ramdisk.c ifeq ($(CONFIG_DRVR_WRITEBUFFER),y) CSRCS += rwbuffer.c else diff --git a/drivers/README.txt b/drivers/README.txt index 39b4610921..fb43d81305 100644 --- a/drivers/README.txt +++ b/drivers/README.txt @@ -21,11 +21,6 @@ dev_null.c and dev_zero.c want to register these devices (devnull_register() and devzero_register()). -loop.c - Supports the standard loop device that can be used to export a - file (or character device) as a block device. See losetup() and - loteardown() in include/nuttx/fs/fs.h. - pwm.c Provides the "upper half" of a pulse width modulation (PWM) driver. The "lower half" of the PWM driver is provided by device-specific @@ -36,18 +31,10 @@ ramdisk.c a block driver that can be mounted as a files system. See include/nuttx/fs/ramdisk.h. -timer.c - Provides the "upper half" for a generic timer driver. See - include/nuttx/timers/timer.h for more information. - rwbuffer.c A facility that can be use by any block driver in-order to add writing buffering and read-ahead buffering. -watchdog.c - Provides the "upper half" for a generic watchdog driver. See - include/nuttx/timers/watchdog.h for more information. - Subdirectories of this directory: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -94,6 +81,11 @@ lcd/ Drivers for parallel and serial LCD and OLED type devices. These drivers support interfaces as defined in include/nuttx/lcd/lcd.h +loop/ + Supports the standard loop device that can be used to export a + file (or character device) as a block device. See losetup() and + loteardown() in include/nuttx/fs/fs.h. + mmcsd/ Support for MMC/SD block drivers. MMC/SD block drivers based on SPI and SDIO/MCI interfaces are supported. See include/nuttx/mmcsd.h @@ -153,6 +145,17 @@ spi/ syslog/ System logging devices. See include/syslog.h and include/nuttx/syslog/syslog.h +timers/ + Includes support for various timer devices including: + + - An "upper half" for a generic timer driver. See + include/nuttx/timers/timer.h for more information. + + - An "upper half" for a generic watchdog driver. See + include/nuttx/timers/watchdog.h for more information. + + - RTC drivers + usbdev/ USB device drivers. See also include/nuttx/usb/usbdev.h diff --git a/drivers/loop/Kconfig b/drivers/loop/Kconfig new file mode 100644 index 0000000000..06fbd8ddea --- /dev/null +++ b/drivers/loop/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LOOP + bool "Enable loop device" + default n + ---help--- + Supports the standard loop device that can be used to export a + file (or character device) as a block device. diff --git a/drivers/loop/Make.defs b/drivers/loop/Make.defs new file mode 100644 index 0000000000..04c8f65103 --- /dev/null +++ b/drivers/loop/Make.defs @@ -0,0 +1,54 @@ +############################################################################ +# drivers/loop/Make.defs +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Loop device can only be used with mountpoint support + +ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) + +# Include loop device support + +ifneq ($(CONFIG_LOOP),y) +# CSRCS += loop.c +endif + +CSRCS += losetup.c + +# Add loop devicer build support + +DEPPATH += --dep-path loop +VPATH += :loop +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)loop} + +endif diff --git a/drivers/loop.c b/drivers/loop/losetup.c similarity index 99% rename from drivers/loop.c rename to drivers/loop/losetup.c index 9d51dd7465..a70bbe2fc5 100644 --- a/drivers/loop.c +++ b/drivers/loop/losetup.c @@ -1,7 +1,7 @@ /**************************************************************************** - * drivers/loop.c + * drivers/losetup.c * - * Copyright (C) 2008-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without -- GitLab From ed35eb0f8d892eae8b8f2a34ba30c793f3e73b29 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 17:13:56 -0600 Subject: [PATCH 372/858] drivers/loop: Add a loop character device that can be used to setup and teardown loop devices --- ChangeLog | 4 + TODO | 17 ---- arch | 2 +- configs | 2 +- drivers/loop/Kconfig | 2 +- drivers/loop/Make.defs | 4 +- drivers/loop/loop.c | 179 +++++++++++++++++++++++++++++++++++++++ drivers/loop/losetup.c | 3 +- include/nuttx/fs/fs.h | 23 ----- include/nuttx/fs/ioctl.h | 7 ++ include/nuttx/fs/loop.h | 145 +++++++++++++++++++++++++++++++ 11 files changed, 342 insertions(+), 46 deletions(-) create mode 100644 drivers/loop/loop.c create mode 100644 include/nuttx/fs/loop.h diff --git a/ChangeLog b/ChangeLog index 4dbe42cd16..4b97bd8dfe 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11159,3 +11159,7 @@ convert a regular file (or driver file) to an MTD device. This is useful for testing on the simulation using the hostfs. From Ken Petit (2015-11-25). + * drivers/loop: Add a loop character device. losetup() and + loteardown() should not be called directory from applications. + Rather, these functions are now available as IOCTL commands to the + loop driver (2015-11-25). diff --git a/TODO b/TODO index bc792e6236..822cec198c 100644 --- a/TODO +++ b/TODO @@ -439,7 +439,6 @@ o Kernel/Protected Build COMMAND KERNEL INTERFACE(s) -------- ---------------------------------------------- - losetup losetup(), loteardown() mkfatfs mkfatfs mkrd ramdisk_register() ps sched_foreach() @@ -454,22 +453,6 @@ o Kernel/Protected Build http://git.busybox.net/busybox/tree/util-linux/mkfs_vfat.c - Here is how the Busybox/Linux losetup works: - - This is the busybox losetup(): - - http://git.busybox.net/busybox/tree/util-linux/losetup.c . - - You can see that it relies on query_loop(), set_loop(), and - del_loop() to do the really work. query_loop() and friends - are here: - - http://git.busybox.net/busybox/tree/libbb/loop.c. - - They each open a device and interface with it using ioctl calls. - That is probably how NuttX should do things as well. But that - is pretty much a redesign. - Status: Open Priority: Medium/High -- the kernel build configuration is not fully fielded yet. diff --git a/arch b/arch index 6fa995b0aa..994be48b7d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6fa995b0aac7816b4250c41a737309417f6e2d1e +Subproject commit 994be48b7dfe1dffd1fa9fdfa8dd1468bf5d7b7b diff --git a/configs b/configs index bf0c883295..931d2ed279 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bf0c88329540d1e674e0c2bfeee2350e7898c5b5 +Subproject commit 931d2ed27909e6265eb2eefae1346b758c37a739 diff --git a/drivers/loop/Kconfig b/drivers/loop/Kconfig index 06fbd8ddea..eeeb139882 100644 --- a/drivers/loop/Kconfig +++ b/drivers/loop/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config LOOP +config EEV_LOOP bool "Enable loop device" default n ---help--- diff --git a/drivers/loop/Make.defs b/drivers/loop/Make.defs index 04c8f65103..a7c933667c 100644 --- a/drivers/loop/Make.defs +++ b/drivers/loop/Make.defs @@ -39,8 +39,8 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) # Include loop device support -ifneq ($(CONFIG_LOOP),y) -# CSRCS += loop.c +ifeq ($(CONFIG_DEV_LOOP),y) + CSRCS += loop.c endif CSRCS += losetup.c diff --git a/drivers/loop/loop.c b/drivers/loop/loop.c new file mode 100644 index 0000000000..1345b5417d --- /dev/null +++ b/drivers/loop/loop.c @@ -0,0 +1,179 @@ +/**************************************************************************** + * drivers/loop/loop.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#ifdef CONFIG_DEV_LOOP + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static ssize_t loop_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t loop_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations loop_fops = +{ + 0, /* open */ + 0, /* close */ + loop_read, /* read */ + loop_write, /* write */ + 0, /* seek */ + loop_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: loop_read + ****************************************************************************/ + +static ssize_t loop_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + return 0; /* Return EOF */ +} + +/**************************************************************************** + * Name: loop_write + ****************************************************************************/ + +static ssize_t loop_write(FAR struct file *filep, FAR const char *buffer, size_t len) +{ + return len; /* Say that everything was written */ +} + +/**************************************************************************** + * Name: loop_ioctl + ****************************************************************************/ + +static int loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + int ret; + + switch (cmd) + { + /* Command: LOOPIOC_SETUP + * Description: Setup the loop device + * Argument: A pointer to a read-only instance of struct losetup_s. + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + + case LOOPIOC_SETUP: + { + FAR struct losetup_s *setup = (FAR struct losetup_s *)((uintptr_t)arg); + + if (setup == NULL) + { + ret = -EINVAL; + } + else + { + ret = losetup(setup->devname, setup->filename, setup->sectsize, + setup->offset, setup->readonly); + } + } + break; + + /* Command: LOOPIOC_TEARDOWN + * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP + * Argument: A read-able pointer to the path of the device to be + * torn down + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + + case LOOPIOC_TEARDOWN: + { + FAR const char *devname = (FAR const char *)((uintptr_t)arg); + + if (devname == NULL) + { + ret = -EINVAL; + } + else + { + ret = loteardown(devname); + } + } + break; + + default: + ret = -ENOTTY; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: loop_register + * + * Description: + * Register /dev/null + * + ****************************************************************************/ + +void loop_register(void) +{ + (void)register_driver("/dev/loop", &loop_fops, 0666, NULL); +} + +#endif /* CONFIG_DEV_LOOP */ diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index a70bbe2fc5..dadd44891c 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/losetup.c + * drivers/loop/losetup.c * * Copyright (C) 2008-2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -58,6 +58,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index b55ba8b505..8de9a1b095 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -897,29 +897,6 @@ void devcrypto_register(void); void devzero_register(void); -/* drivers/loop.c ***********************************************************/ -/**************************************************************************** - * Name: losetup - * - * Description: - * Setup the loop device so that it exports the file referenced by 'filename' - * as a block device. - * - ****************************************************************************/ - -int losetup(FAR const char *devname, FAR const char *filename, - uint16_t sectsize, off_t offset, bool readonly); - -/**************************************************************************** - * Name: loteardown - * - * Description: - * Undo the setup performed by losetup - * - ****************************************************************************/ - -int loteardown(FAR const char *devname); - /* drivers/bch/bchdev_register.c ********************************************/ /**************************************************************************** * Name: bchdev_register diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 2e0d7a1aae..98b61a7eb5 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -80,6 +80,7 @@ #define _BTNBASE (0x1b00) /* Button ioctl commands */ #define _ULEDBASE (0x1c00) /* User LED ioctl commands */ #define _ZCBASE (0x1d00) /* Zero Cross ioctl commands */ +#define _LOOPBASE (0x1e00) /* Loop device commands */ /* boardctl commands share the same number space */ @@ -360,6 +361,12 @@ #define _ZCIOCVALID(c) (_IOC_TYPE(c)==_ZCBASE) #define _ZCIOC(nr) _IOC(_ZCBASE,nr) +/* Loop driver ioctl definitions ********************************************/ +/* (see nuttx/include/fs/loop.h */ + +#define _LOOPIOCVALID(c) (_IOC_TYPE(c)==_LOOPBASE) +#define _LOOPIOC(nr) _IOC(_LOOPBASE,nr) + /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/fs/loop.h b/include/nuttx/fs/loop.h new file mode 100644 index 0000000000..1a2a4aec6f --- /dev/null +++ b/include/nuttx/fs/loop.h @@ -0,0 +1,145 @@ +/**************************************************************************** + * include/nuttx/fs/loop.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_FS_LOOP_H +#define __INCLUDE_NUTTX_FS_LOOP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_DEV_LOOP +/* Loop device IOCTL commands */ + +/* Command: LOOPIOC_SETUP + * Description: Setup the loop device + * Argument: A pointer to a read-only instance of struct losetup_s. + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + +/* Command: LOOPIOC_TEARDOWN + * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP + * Argument: A read-able pointer to the path of the device to be + * torn down + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + +#define LOOPIOC_SETUP _LOOPIOC(0x0001) +#define LOOPIOC_TEARDOWN _LOOPIOC(0x0002) + +#endif + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +#ifdef CONFIG_DEV_LOOP +/* This is the structure referred to in the argument to the LOOPIOC_SETUP + * IOCTL command. + */ + +struct losetup_s +{ + FAR const char *devname; /* The loop block device to be created */ + FAR const char *filename; /* The file or character device to use */ + uint16_t sectsize; /* The sector size to use with the block device */ + off_t offset; /* An offset that may be applied to the device */ + bool readonly; /* True: Read access will be supported only */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: loop_register + * + * Description: + * Register /dev/loop + * + ****************************************************************************/ + +#ifdef CONFIG_DEV_LOOP +void loop_register(void); +#endif + +/**************************************************************************** + * Name: losetup + * + * Description: + * Setup the loop device so that it exports the file referenced by 'filename' + * as a block device. + * + ****************************************************************************/ + +int losetup(FAR const char *devname, FAR const char *filename, + uint16_t sectsize, off_t offset, bool readonly); + +/**************************************************************************** + * Name: loteardown + * + * Description: + * Undo the setup performed by losetup + * + ****************************************************************************/ + +int loteardown(FAR const char *devname); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_FS_LOOP_H */ -- GitLab From 603f3afd6d4a180981dcfbde193badb0bd6a39b8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 17:52:47 -0600 Subject: [PATCH 373/858] Some minor clean-up from last changes --- arch | 2 +- drivers/loop/Kconfig | 2 +- include/nuttx/fs/loop.h | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 994be48b7d..6d7ee8a1e9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 994be48b7dfe1dffd1fa9fdfa8dd1468bf5d7b7b +Subproject commit 6d7ee8a1e9445da89e4e6f96b019b535e96ec672 diff --git a/drivers/loop/Kconfig b/drivers/loop/Kconfig index eeeb139882..1a1dd2a189 100644 --- a/drivers/loop/Kconfig +++ b/drivers/loop/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config EEV_LOOP +config DEV_LOOP bool "Enable loop device" default n ---help--- diff --git a/include/nuttx/fs/loop.h b/include/nuttx/fs/loop.h index 1a2a4aec6f..ee1efd69f4 100644 --- a/include/nuttx/fs/loop.h +++ b/include/nuttx/fs/loop.h @@ -103,6 +103,9 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +#ifdef __KERNEL__ +/* These are internal OS interface and are not available to applications */ + /**************************************************************************** * Name: loop_register * @@ -136,6 +139,7 @@ int losetup(FAR const char *devname, FAR const char *filename, ****************************************************************************/ int loteardown(FAR const char *devname); +#endif /* __KERNEL __ */ #undef EXTERN #ifdef __cplusplus -- GitLab From 470784d8ca36418e1f0d7fe00196782eae014506 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 Nov 2015 18:36:29 -0600 Subject: [PATCH 374/858] Update submodules --- Documentation | 2 +- arch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index 1972785856..3d2cd73b92 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 197278585682ff0a7caee714f7706a0361b80144 +Subproject commit 3d2cd73b92c99a5880354fe11f5d7f29bc8775e8 diff --git a/arch b/arch index 6d7ee8a1e9..c4013ed789 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6d7ee8a1e9445da89e4e6f96b019b535e96ec672 +Subproject commit c4013ed78934974b2463cadb97db892bb1756bf0 -- GitLab From 2a93c66948008a05ee46efb95ced18ec59f7a3d7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Nov 2015 12:08:09 -0600 Subject: [PATCH 375/858] include/nuttx/net/netdev.h and several Ethernet drivers in arch/: Most network drivers to not support statistics. Those that do only support them when DEBUG is enabled. Each driver collects an architecture specific set of statistics and there is no mechanism in place to view those statistics. Thus, the driver feature was mostly useless. This change standardizes the driver statistics and puts the definition in the common network device structure defined in netdev.h where they can be accessed by network applications. All Ethernet drivers that collect statistics have been adapted to use these common statistics. --- ChangeLog | 10 ++ TODO | 29 +----- arch | 2 +- configs | 2 +- drivers/net/Kconfig | 37 ++++---- drivers/net/cs89x0.c | 51 +++++----- drivers/net/dm90x0.c | 164 ++++----------------------------- drivers/net/e1000.c | 6 -- drivers/net/enc28j60.c | 97 +++---------------- drivers/net/enc28j60.h | 2 +- drivers/net/encx24j600.c | 81 ++++------------ drivers/net/ftmac100.c | 11 +-- drivers/net/loopback.c | 7 ++ drivers/net/skeleton.c | 13 +++ drivers/net/slip.c | 33 ++----- drivers/net/tun.c | 13 +++ drivers/net/vnet.c | 8 +- include/nuttx/net/cs89x0.h | 31 +------ include/nuttx/net/enc28j60.h | 44 +-------- include/nuttx/net/encx24j600.h | 45 +-------- include/nuttx/net/netdev.h | 107 ++++++++++++++++++++- net/Kconfig | 33 ++++--- 22 files changed, 278 insertions(+), 548 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b97bd8dfe..55e099bcad 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11163,3 +11163,13 @@ loteardown() should not be called directory from applications. Rather, these functions are now available as IOCTL commands to the loop driver (2015-11-25). + * include/nuttx/net/netdev.h and several Ethernet drivers in arch/: + Most network drivers to not support statistics. Those that do only + support them when DEBUG is enabled. Each driver collects an + architecture specific set of statistics and there is no mechanism in + place to view those statistics. Thus, the driver feature was mostly + useless. This change standardizes the driver statistics and puts the + definition in the common network device structure defined in netdev.h + where they can be accessed by network applications. All Ethernet + drivers that collect statistics have been adapted to use these common + statistics (2015-11-26). \ No newline at end of file diff --git a/TODO b/TODO index 822cec198c..ff34eeb102 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated November 25, 2015) +NuttX TODO List (Last updated November 26, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -16,7 +16,7 @@ nuttx/ (0) Message Queues (sched/mqueue) (4) C++ Support (6) Binary loaders (binfmt/) - (12) Network (net/, drivers/net) + (11) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (11) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) @@ -829,25 +829,6 @@ o Network (net/, drivers/net) Status: Open Priority: Low - Title: STANDARDIZE ETHERNET DRIVER STATISTICS - Description: Need to standardize collection of statistics from network - drivers. Currently they are useless because they are not - accessible. The solution is to standardize the structure - that holds the drivers statistics. Then apps/nshlib - ifconfig command could present the driver statistics. - - Currently these drivers support non-standard statistics: - - arch/arm/src/kinetis/kinetis_enet.c - arch/arm/src/lpc17xx/lpc17_ethernet.c - arch/arm/src/tiva/lm3s_ethernet.c - arch/mips/src/pic32mx/pic32mx-ethernet.c - arch/z80/src/ez80/ez80_emac.c - - The other Ethernet drivers support no statistics. - Status: Open - Priority: Low. This is not a bug but an enhancement idea. - Title: CONCURRENT TCP SEND OPERATIONS Description: At present, there cannot be two concurrent active TCP send operations in progress using the same socket. This is because @@ -1728,9 +1709,9 @@ o ARM (arch/arm/) issues if, for example, floating point or perhaps long long operations were performed in an interrupt handler. - This issue exists for ARM7, ARM9, Cortex-M0, Cortex-M3, and - Cortex-M4 but has been addressed for the Cortex-A5. The fix - is really simple can cannot be incorporated without some + This issue exists for ARM7, ARM9, and Cortex-M0 but has been + addressed for the Cortex-M3/4/7 and Cortex-A5/8. The fix + is really simple but cannot be incorporated without some substantial testing. For ARM, the fix is the following logic arround each call into C code from assembly: diff --git a/arch b/arch index c4013ed789..ee23d9991d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c4013ed78934974b2463cadb97db892bb1756bf0 +Subproject commit ee23d9991d2fa2cb58a834dee03181558a03b855 diff --git a/configs b/configs index 931d2ed279..8fcf1ca2b7 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 931d2ed27909e6265eb2eefae1346b758c37a739 +Subproject commit 8fcf1ca2b7ec45e4c5bd29258b5e5adc5ed8fcdc diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index c28f600521..c1461e9153 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -10,6 +10,7 @@ config NETDEV_LOOPBACK default n if !NET_LOOPBACK default y if NET_LOOPBACK select NET_NOINTS + select ARCH_HAVE_NETDEV_STATISTICS ---help--- Add support for the local network loopback device, lo. Any additional networking devices that are enabled must be compatible with @@ -25,6 +26,17 @@ config NETDEV_MULTINIC is considered to be a a link layer driver so if local loopback support is used you probably need to select this option. +config ARCH_HAVE_NETDEV_STATISTICS + bool + default n + +config NETDEV_STATISTICS + bool "Network device driver statistics" + depends on NET_STATISTICS && ARCH_HAVE_NETDEV_STATISTICS + ---help--- + Enable to collect statistics from the network drivers (if supported + by the network driver). + config NETDEV_LATEINIT bool "Late driver initialization" default n @@ -68,6 +80,7 @@ comment "External Ethernet MAC Device Support" menuconfig NET_DM90x0 bool "Davicom dm9000/dm9010 support" default n + select ARCH_HAVE_NETDEV_STATISTICS ---help--- References: Davicom data sheets (DM9000-DS-F03-041906.pdf, DM9010-DS-F01-103006.pdf) and looking at lots of other DM90x0 @@ -132,23 +145,21 @@ config DM9X_NINTERFACES default 1 depends on EXPERIMENTAL -config DM9X_STATS - bool "DM90x0 statistics" - default n - -endif # NET_DM90x0 +endif # NET_DM90x0 config NET_CS89x0 bool "CS89x0 support" default n depends on EXPERIMENTAL + select ARCH_HAVE_NETDEV_STATISTICS ---help--- - Under construction -- do not use + Under construction -- do not use menuconfig ENC28J60 bool "Microchip ENC28J60 support" default n select SPI + select ARCH_HAVE_NETDEV_STATISTICS ---help--- References: ENC28J60 Data Sheet, Stand-Alone Ethernet Controller with SPI Interface, @@ -180,12 +191,6 @@ config ENC28J60_FREQUENCY ---help--- Define to use a different bus frequency -config ENC28J60_STATS - bool "Network statistics support" - default n - ---help--- - Collect network statistics - config ENC28J60_HALFDUPPLEX bool "Enable half dupplex" default n @@ -213,6 +218,7 @@ menuconfig ENCX24J600 default n select SPI select NET_RXAVAIL + select ARCH_HAVE_NETDEV_STATISTICS ---help--- References: ENC424J600/624J600 Data Sheet Stand-Alone 10/100 Ethernet Controller @@ -253,12 +259,6 @@ config ENCX24J600_NRXDESCR The ENC has a relative large packet buffer of 24kB which can be used to buffer multiple packets silmutaneously -config ENCX24J600_STATS - bool "Network statistics support" - default n - ---help--- - Collect network statistics - config ENCX24J600_DUMPPACKET bool "Dump Packets" default n @@ -298,6 +298,7 @@ endif # NET_E1000 menuconfig NET_SLIP bool "SLIP (serial line) support" default n + select ARCH_HAVE_NETDEV_STATISTICS ---help--- Reference: RFC 1055 diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index 8a9f181436..5adbe42135 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/cs89x0.c * - * Copyright (C) 2009-2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -408,31 +408,31 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) rxlength = cs89x0_getreg(PPR_RXLENGTH); if ((isq & RX_OK) == 0) { -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.rx_errors++; +#ifdef CONFIG_NETDEV_STATISTICS + NETDEV_RXERRORS(&cd89x0->cs_dev); + +#if 0 if ((isq & RX_RUNT) != 0) { - cd89x0->cs_stats.rx_lengtherrors++; } if ((isq & RX_EXTRA_DATA) != 0) { - cd89x0->cs_stats.rx_lengtherrors++; } if (isq & RX_CRC_ERROR) != 0) { if (!(isq & (RX_EXTRA_DATA | RX_RUNT))) { - cd89x0->cs_stats.rx_crcerrors++; } } if ((isq & RX_DRIBBLE) != 0) { - cd89x0->cs_stats.rx_frameerrors++; } #endif +#endif + return; } @@ -440,10 +440,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) if (rxlength > ???) { -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.rx_errors++; - cd89x0->cs_stats.rx_lengtherrors++; -#endif + NETDEV_RXERRORS(&cd89x0->cs_dev); return; } @@ -457,9 +454,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) *dest++ = cs89x0_getreg(PPR_RXFRAMELOCATION); } -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.rx_packets++; -#endif + NETDEV_RXPACKETS(&cd89x0->cs_dev); #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ @@ -473,6 +468,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->cs_dev); /* Handle ARP on input then give the IPv4 packet to the network * layer @@ -513,6 +509,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->cs_dev); /* Give the IPv6 packet to the network layer */ @@ -549,6 +546,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) #ifdef CONFIG_NET_ARP if (BUF->type == htons(ETHTYPE_ARP)) { + NETDEV_RXARP(&priv->cs_dev); arp_arpin(&cs89x0->cs_dev); /* If the above function invocation resulted in data that should be @@ -564,6 +562,7 @@ static void cs89x0_receive(FAR struct cs89x0_driver_s *cs89x0, uint16_t isq) #endif { nllvdbg("Unrecognized packet type %02x\n", BUF->type); + NETDEV_RXDROPPED(&priv->cs_dev); } } @@ -589,28 +588,30 @@ static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0, uint16_t isq) * hold the register address causing the interrupt. We got here because * those bits indicated */ -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.tx_packets++; +#ifdef CONFIG_NETDEV_STATISTICS + NETDEV_TXPACKETS(&cd89x0->cs_dev); if ((isq & ISQ_TXEVENT_TXOK) == 0) { - cd89x0->cs_stats.tx_errors++; + NETDEV_TXERRORS(&cd89x0->cs_dev); } + +#if 0 if ((isq & ISQ_TXEVENT_LOSSOFCRS) != 0) { - cd89x0->cs_stats.tx_carriererrors++; } + if ((isq & ISQ_TXEVENT_SQEERROR) != 0) { - cd89x0->cs_stats.tx_heartbeaterrors++; } + if (i(sq & ISQ_TXEVENT_OUTWINDOW) != 0) { - cd89x0->cs_stats.tx_windowerrors++; } + if (isq & TX_16_COL) { - cd89x0->cs_stats.tx_abortederrors++; } +#endif #endif /* If no further xmits are pending, then cancel the TX timeout */ @@ -719,15 +720,11 @@ static int cs89x0_interrupt(int irq, FAR void *context) break; case ISQ_RXMISSEVENT: -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.rx_missederrors += (isq >> 6); -#endif + NETDEV_RXERRORS(&cd89x0->cs_dev); break; case ISQ_TXCOLEVENT: -#ifdef CONFIG_C89x0_STATISTICS - cd89x0->cs_stats.collisions += (isq >> 6); -#endif + NETDEV_TXERRORS(&cd89x0->cs_dev); break; } } diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index fd785e9e77..e810c6b672 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/dm9x.c * - * Copyright (C) 2007-2010, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: Davicom data sheets (DM9000-DS-F03-041906.pdf, @@ -310,20 +310,6 @@ struct dm9x_driver_s void (*dm_write)(const uint8_t *ptr, int len); void (*dm_discard)(int len); -#if defined(CONFIG_DM9X_STATS) - uint32_t dm_ntxpackets; /* Count of packets sent */ - uint32_t dm_ntxbytes; /* Count of bytes sent */ - uint32_t dm_ntxerrors; /* Count of TX errors */ - uint32_t dm_nrxpackets; /* Count of packets received */ - uint32_t dm_nrxbytes; /* Count of bytes received */ - uint32_t dm_nrxfifoerrors; /* Count of RX FIFO overflow errors */ - uint32_t dm_nrxcrcerrors; /* Count of RX CRC errors */ - uint32_t dm_nrxlengtherrors; /* Count of RX length errors */ - uint32_t dm_nphyserrors; /* Count of physical layer errors */ - uint32_t dm_nresets; /* Counts number of resets */ - uint32_t dm_ntxtimeouts; /* Counts resets caused by TX timeouts */ -#endif - /* This holds the information visible to uIP/NuttX */ struct net_driver_s dm_dev; @@ -359,18 +345,6 @@ static void write32(const uint8_t *ptr, int len); static uint16_t dm9x_phyread(struct dm9x_driver_s *dm9x, int reg); static void dm9x_phywrite(struct dm9x_driver_s *dm9x, int reg, uint16_t value); -#if defined(CONFIG_DM9X_STATS) -static void dm9x_resetstatistics(struct dm9x_driver_s *dm9x); -#else -# define dm9x_resetstatistics(dm9x) -#endif - -#if defined(CONFIG_DM9X_STATS) && defined(CONFIG_DEBUG) -static void dm9x_dumpstatistics(struct dm9x_driver_s *dm9x); -#else -# define dm9x_dumpstatistics(dm9x) -#endif - #if defined(CONFIG_DM9X_CHECKSUM) static bool dm9x_rxchecksumready(uint8_t); #else @@ -665,72 +639,6 @@ static void dm9x_phywrite(struct dm9x_driver_s *dm9x, int reg, uint16_t value) putreg(DM9X_EEPHYC, 0x0); } -/**************************************************************************** - * Function: dm9x_resetstatistics - * - * Description: - * Reset all DM90x0 statistics - * - * Parameters: - * dm9x - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#if defined(CONFIG_DM9X_STATS) -static void dm9x_resetstatistics(struct dm9x_driver_s *dm9x) -{ - dm9x->dm_ntxpackets = 0; /* Count of packets sent */ - dm9x->dm_ntxbytes = 0; /* Count of bytes sent */ - dm9x->dm_ntxerrors = 0; /* Count of TX errors */ - dm9x->dm_nrxpackets = 0; /* Count of packets received */ - dm9x->dm_nrxbytes = 0; /* Count of bytes received */ - dm9x->dm_nrxfifoerrors = 0; /* Count of RX FIFO overflow errors */ - dm9x->dm_nrxcrcerrors = 0; /* Count of RX CRC errors */ - dm9x->dm_nrxlengtherrors = 0; /* Count of RX length errors */ - dm9x->dm_nphyserrors = 0; /* Count of physical layer errors */ - dm9x->dm_nresets = 0; /* Counts number of resets */ - dm9x->dm_ntxtimeouts = 0; /* Counts resets caused by TX timeouts */ -} -#endif - -/**************************************************************************** - * Function: dm9x_dumpstatistics - * - * Description: - * Print the current value of all DM90x0 statistics - * - * Parameters: - * dm9x - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#if defined(CONFIG_DM9X_STATS) && defined(CONFIG_DEBUG) -static void dm9x_dumpstatistics(struct dm9x_driver_s *dm9x) -{ - ndbg("TX packets: %d\n", dm9x->dm_ntxpackets); - ndbg(" bytes: %d\n", dm9x->dm_ntxbytes); - ndbg(" errors: %d\n", dm9x->dm_ntxerrors); - ndbg("RX packets: %d\n", dm9x->dm_nrxpackets); - ndbg(" bytes: %d\n", dm9x->dm_nrxbytes); - ndbg(" FIFO overflows: %d\n", dm9x->dm_nrxfifoerrors); - ndbg(" CRC errors: %d\n", dm9x->dm_nrxcrcerrors); - ndbg(" length errors: %d\n", dm9x->dm_nrxlengtherrors); - ndbg("Physical layer errors: %d\n", dm9x->dm_nphyserrors); - ndbg("Resets: %d\n", dm9x->dm_nresets); - ndbg("TX timeout resets: %d\n", dm9x->dm_ntxtimeouts); -} -#endif - /**************************************************************************** * Function: dm9x_rxchecksumready * @@ -787,10 +695,7 @@ static int dm9x_transmit(struct dm9x_driver_s *dm9x) /* Increment count of packets transmitted */ dm9x->dm_ntxpending++; -#if defined(CONFIG_DM9X_STATS) - dm9x->dm_ntxpackets++; - dm9x->dm_ntxbytes += dm9x->dm_dev.d_len; -#endif + NETDEV_TXPACKETS(&dm9x0->dm_dev); /* Disable all DM90x0 interrupts */ @@ -960,33 +865,9 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) { /* Bad RX packet... update statistics */ -#if defined(CONFIG_DM9X_STATS) - if (rx.desc.rx_status & 0x01) - { - dm9x->dm_nrxfifoerrors++; - ndbg("RX FIFO error: %d\n", dm9x->dm_nrxfifoerrors); - } - - if (rx.desc.rx_status & 0x02) - { - dm9x->dm_nrxcrcerrors++; - ndbg("RX CRC error: %d\n", dm9x->dm_nrxcrcerrors); - } - - if (rx.desc.rx_status & 0x80) - { - dm9x->dm_nrxlengtherrors++; - ndbg("RX length error: %d\n", dm9x->dm_nrxlengtherrors); - } - - if (rx.desc.rx_status & 0x08) - { - dm9x->dm_nphyserrors++; - ndbg("Physical Layer error: %d\n", dm9x->dm_nphyserrors); - } -#else ndbg("Received packet with errors: %02x\n", rx.desc.rx_status); -#endif + NETDEV_RXERRORS(&dm9x->dm_dev); + /* Drop this packet and continue to check the next packet */ dm9x->dm_discard(rx.desc.rx_len); @@ -996,10 +877,9 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) else if (rx.desc.rx_len < ETH_HDRLEN || rx.desc.rx_len > (CONFIG_NET_ETH_MTU + 2)) { -#if defined(CONFIG_DM9X_STATS) - dm9x->dm_nrxlengtherrors++; - ndbg("RX length error: %d\n", dm9x->dm_nrxlengtherrors); -#endif + ndbg("RX length error\n"); + NETDEV_RXERRORS(&dm9x->dm_dev); + /* Drop this packet and continue to check the next packet */ dm9x->dm_discard(rx.desc.rx_len); @@ -1023,6 +903,7 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->dm_dev); /* Handle ARP on input then give the IPv4 packet to the network * layer @@ -1063,6 +944,7 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->dm_dev); /* Give the IPv6 packet to the network layer */ @@ -1100,6 +982,7 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&dm9x->dm_dev); + NETDEV_RXARP(&priv->dm_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. @@ -1111,12 +994,13 @@ static void dm9x_receive(FAR struct dm9x_driver_s *dm9x) } } #endif + else + { + NETDEV_RXDROPPED(&priv->dm_dev); + } } -#if defined(CONFIG_DM9X_STATS) - dm9x->dm_nrxpackets++; - dm9x->dm_nrxbytes += rx.desc.rx_len; -#endif + NETDEV_RXPACKETS(&dm9x->dm_dev); dm9x->ncrxpackets++; } while ((rxbyte & 0x01) == DM9X_PKTRDY && dm9x->ncrxpackets < DM9X_CRXTHRES); @@ -1326,15 +1210,9 @@ static void dm9x_txtimeout(int argc, uint32_t arg, ...) /* Increment statistics and dump debug info */ -#if defined(CONFIG_DM9X_STATS) - dm9x->dm_ntxtimeouts++; - dm9x->dm_ntxerrors++; -#endif + NETDEV_TXTIMEOUTS(dm9x->dm_dev); ndbg(" TX packet count: %d\n", dm9x->dm_ntxpending); -#if defined(CONFIG_DM9X_STATS) - ndbg(" TX timeouts: %d\n", dm9x->dm_ntxtimeouts); -#endif ndbg(" TX read pointer address: 0x%02x:%02x\n", getreg(DM9X_TRPAH), getreg(DM9X_TRPAL)); ndbg(" Memory data write address: 0x%02x:%02x (DM9010)\n", @@ -1549,10 +1427,6 @@ static int dm9x_ifdown(struct net_driver_s *dev) dm9x->dm_bifup = false; irqrestore(flags); - - /* Dump statistics */ - - dm9x_dumpstatistics(dm9x); return OK; } @@ -1751,7 +1625,7 @@ static void dm9x_bringup(struct dm9x_driver_s *dm9x) dm9x->ncrxpackets = 0; /* Number of continuous RX packets */ dm9x->dm_ntxpending = 0; /* Number of pending TX packets */ - dm9x_resetstatistics(dm9x); + NETDEV_RESET_STATISTICS(&dm9x->dm_dev); /* Activate DM9000A/DM9010 */ @@ -1789,10 +1663,6 @@ static void dm9x_reset(struct dm9x_driver_s *dm9x) /* Save previous register address */ save = (uint8_t)DM9X_INDEX; - -#if defined(CONFIG_DM9X_STATS) - dm9x->dm_nresets++; -#endif dm9x_bringup(dm9x); /* Wait up to 1 second for the link to be OK */ diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index e707ff63cf..e0b063af1a 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -435,8 +435,6 @@ static int e1000_transmit(struct e1000_dev *e1000) return -1; } - /* Increment statistics */ - /* Send the packet: address=skel->sk_dev.d_buf, length=skel->sk_dev.d_len */ memcpy(cp, e1000->netdev.d_buf, e1000->netdev.d_len); @@ -564,8 +562,6 @@ static void e1000_receive(struct e1000_dev *e1000) while (e1000->rx_ring.desc[head].desc_status) { - /* Check for errors and update statistics */ - /* Here we do not handle packets that exceed packet-buffer size */ if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) @@ -728,8 +724,6 @@ static void e1000_txtimeout(int argc, uint32_t arg, ...) { struct e1000_dev *e1000 = (struct e1000_dev *)arg; - /* Increment statistics and dump debug info */ - /* Then reset the hardware */ e1000_init(e1000); diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 8c90f4c8e9..7df9597a82 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/enc28j60.c * - * Copyright (C) 2010-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2012, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -85,7 +85,6 @@ * CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency * CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60 * devices that will be supported. - * CONFIG_ENC28J60_STATS - Collect network statistics * CONFIG_ENC28J60_HALFDUPPLEX - Default is full duplex */ @@ -257,12 +256,6 @@ struct enc_driver_s /* This holds the information visible to uIP/NuttX */ struct net_driver_s dev; /* Interface understood by uIP */ - - /* Statistics */ - -#ifdef CONFIG_ENC28J60_STATS - struct enc_stats_s stats; -#endif }; /**************************************************************************** @@ -1113,9 +1106,7 @@ static int enc_transmit(FAR struct enc_driver_s *priv) /* Increment statistics */ nllvdbg("Sending packet, pktlen: %d\n", priv->dev.d_len); -#ifdef CONFIG_ENC28J60_STATS - priv->stats.txrequests++; -#endif + NETDEV_TXPACKETS(&priv->dev); /* Verify that the hardware is ready to send another packet. The driver * starts a transmission process by setting ECON1.TXRTS. When the packet is @@ -1290,13 +1281,7 @@ static void enc_txif(FAR struct enc_driver_s *priv) { /* Update statistics */ -#ifdef CONFIG_ENC28J60_STATS - priv->stats.txifs++; - if (enc_rdgreg(priv, ENC_ESTAT) & ESTAT_TXABRT) - { - priv->stats.txabrts++; - } -#endif + NETDEV_TXDONE(&priv->dev); /* Clear the request to send bit */ @@ -1331,9 +1316,7 @@ static void enc_txerif(FAR struct enc_driver_s *priv) { /* Update statistics */ -#ifdef CONFIG_ENC28J60_STATS - priv->stats.txerifs++; -#endif + NETDEV_TXERRORS(&priv->dev); /* Reset TX */ @@ -1375,11 +1358,7 @@ static void enc_txerif(FAR struct enc_driver_s *priv) static void enc_rxerif(FAR struct enc_driver_s *priv) { - /* Update statistics */ - -#ifdef CONFIG_ENC28J60_STATS - priv->stats.rxerifs++; -#endif + /* REVISIT: Update statistics */ } /**************************************************************************** @@ -1413,6 +1392,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->dev); /* Handle ARP on input then give the IPv4 packet to the network * layer @@ -1453,6 +1433,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->dev); /* Give the IPv6 packet to the network layer */ @@ -1490,6 +1471,8 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == htons(ETHTYPE_ARP)) { nllvdbg("ARP packet received (%02x)\n", BUF->type); + NETDEV_RXARP(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1505,6 +1488,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) #endif { nlldbg("Unsupported packet type dropped (%02x)\n", htons(BUF->type)); + NETDEV_RXDROPPED(&priv->dev); } } @@ -1533,9 +1517,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) /* Update statistics */ -#ifdef CONFIG_ENC28J60_STATS - priv->stats.pktifs++; -#endif + NETDEV_RXPACKETS(&priv->dev); /* Set the read pointer to the start of the received packet (ERDPT) */ @@ -1572,9 +1554,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) if ((rxstat & RXSTAT_OK) == 0) { nlldbg("ERROR: RXSTAT: %04x\n", rxstat); -#ifdef CONFIG_ENC28J60_STATS - priv->stats.rxnotok++; -#endif + NETDEV_RXERRORS(&priv->dev); } /* Check for a usable packet length (4 added for the CRC) */ @@ -1582,9 +1562,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) else if (pktlen > (CONFIG_NET_ETH_MTU + 4) || pktlen <= (ETH_HDRLEN + 4)) { nlldbg("Bad packet size dropped (%d)\n", pktlen); -#ifdef CONFIG_ENC28J60_STATS - priv->stats.rxpktlen++; -#endif + NETDEV_RXERRORS(&priv->dev); } /* Otherwise, read and process the packet */ @@ -1787,18 +1765,13 @@ static void enc_irqworker(FAR void *arg) /* Ignore PKTIF because is unreliable. Use EPKTCNT instead */ /* if ((eir & EIR_PKTIF) != 0) */ + { uint8_t pktcnt = enc_rdbreg(priv, ENC_EPKTCNT); if (pktcnt > 0) { nllvdbg("EPKTCNT: %02x\n", pktcnt); -#ifdef CONFIG_ENC28J60_STATS - if (pktcnt > priv->stats.maxpktcnt) - { - priv->stats.maxpktcnt = pktcnt; - } -#endif /* Handle packet receipt */ enc_pktif(priv); @@ -1917,9 +1890,7 @@ static void enc_toworker(FAR void *arg) /* Increment statistics and dump debug info */ -#ifdef CONFIG_ENC28J60_STATS - priv->stats.txtimeouts++; -#endif + NETDEV_TXTIMEOUTS(&priv->dev); /* Then reset the hardware: Take the interface down, then bring it * back up @@ -2693,42 +2664,4 @@ int enc_initialize(FAR struct spi_dev_s *spi, return netdev_register(&priv->dev, NET_LL_ETHERNET); } -/**************************************************************************** - * Function: enc_stats - * - * Description: - * Return accumulated ENC28J60 statistics. Statistics are cleared after - * being returned. - * - * Parameters: - * devno - If more than one ENC28J60 is supported, then this is the - * zero based number that identifies the ENC28J60; - * stats - The user-provided location to return the statistics. - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_ENC28J60_STATS -int enc_stats(unsigned int devno, struct enc_stats_s *stats) -{ - FAR struct enc_driver_s *priv ; - irqstate_t flags; - - DEBUGASSERT(devno < CONFIG_ENC28J60_NINTERFACES); - priv = &g_enc28j60[devno]; - - /* Disable the Ethernet interrupt */ - - flags = irqsave(); - memcpy(stats, &priv->stats, sizeof(struct enc_stats_s)); - memset(&priv->stats, 0, sizeof(struct enc_stats_s)); - irqrestore(flags); - return OK; -} -#endif #endif /* CONFIG_NET && CONFIG_ENC28J60_NET */ - diff --git a/drivers/net/enc28j60.h b/drivers/net/enc28j60.h index d717ff82a3..faa1546118 100644 --- a/drivers/net/enc28j60.h +++ b/drivers/net/enc28j60.h @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/enc28j60.h * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 18057f325f..4de0d694ca 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -91,7 +91,6 @@ * CONFIG_ENCX24J600_FREQUENCY - Define to use a different bus frequency * CONFIG_ENCX24J600_NINTERFACES - Specifies the number of physical ENCX24J600 * devices that will be supported. - * CONFIG_ENCX24J600_STATS - Collect network statistics */ /* The ENCX24J600 spec says that it supports SPI mode 0,0 only: "The @@ -272,12 +271,6 @@ struct enc_driver_s /* This holds the information visible to uIP/NuttX */ struct net_driver_s dev; /* Interface understood by uIP */ - - /* Statistics */ - -#ifdef CONFIG_ENCX24J600_STATS - struct enc_stats_s stats; -#endif }; /**************************************************************************** @@ -1143,9 +1136,7 @@ static int enc_txenqueue(FAR struct enc_driver_s *priv) /* Increment statistics */ -#ifdef CONFIG_ENCX24J600_STATS - priv->stats.txrequests++; -#endif + NETDEV_TXPACKETS(&priv->dev); descr = (FAR struct enc_descr_s *)sq_remfirst(&priv->txfreedescr); @@ -1330,6 +1321,8 @@ static void enc_linkstatus(FAR struct enc_driver_s *priv) static void enc_txif(FAR struct enc_driver_s *priv) { + NETDEV_TXDONE(&priv->dev); + if (sq_empty(&priv->txqueue)) { /* If no further xmits are pending, then cancel the TX timeout */ @@ -1342,7 +1335,7 @@ static void enc_txif(FAR struct enc_driver_s *priv) } else { - /* process txqueue */ + /* Process txqueue */ enc_transmit(priv); } @@ -1531,6 +1524,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->dev); /* Handle ARP on input then give the IPv4 packet to the network * layer @@ -1580,6 +1574,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->dev); /* Give the IPv6 packet to the network layer */ @@ -1626,6 +1621,8 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (BUF->type == htons(ETHTYPE_ARP)) { nllvdbg("ARP packet received (%02x)\n", BUF->type); + NETDEV_RXARP(&priv->dev); + arp_arpin(&priv->dev); /* ARP packets are freed immediately */ @@ -1649,6 +1646,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) enc_rxrmpkt(priv, descr); nlldbg("Unsupported packet type dropped (%02x)\n", htons(BUF->type)); + NETDEV_RXDROPPED(&priv->dev); } descr = next; @@ -1747,10 +1745,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) /* Discard packet */ enc_rxrmpkt(priv, descr); - -#ifdef CONFIG_ENCX24J600_STATS - priv->stats.rxnotok++; -#endif + NETDEV_RXERRORS(&priv->dev); } /* Check for a usable packet length (4 added for the CRC) */ @@ -1762,10 +1757,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) /* Discard packet */ enc_rxrmpkt(priv, descr); - -#ifdef CONFIG_ENCX24J600_STATS - priv->stats.rxpktlen++; -#endif + NETDEV_RXERRORS(&priv->dev); } /* Decrement PKTCNT */ @@ -1951,9 +1943,7 @@ static void enc_irqworker(FAR void *arg) if ((eir & EIR_RXABTIF) != 0) /* Receive Abort */ { -#ifdef CONFIG_ENCX24J600_STATS - priv->stats.rxerifs++; -#endif + NETDEV_RXERRORS(&priv->dev); enc_rxabtif(priv); enc_bfc(priv, ENC_EIR, EIR_RXABTIF); /* Clear the RXABTIF interrupt */ } @@ -1980,7 +1970,7 @@ static void enc_irqworker(FAR void *arg) */ } -#ifdef CONFIG_ENCX24J600_STATS +#ifdef CONFIG_NETDEV_STATISTICS /* The transmit abort interrupt occurs when the transmission of a frame * has been aborted. An abort can occur for any of the following reasons: * @@ -2004,7 +1994,7 @@ static void enc_irqworker(FAR void *arg) if ((eir & EIR_TXABTIF) != 0) /* Transmit Abort */ { - priv->stats.txerifs++; + NETDEV_TXERRORS(&priv->dev); enc_bfc(priv, ENC_EIR, EIR_TXABTIF); /* Clear the TXABTIF interrupt */ } #endif @@ -2095,9 +2085,7 @@ static void enc_toworker(FAR void *arg) /* Increment statistics and dump debug info */ -#ifdef CONFIG_ENCX24J600_STATS - priv->stats.txtimeouts++; -#endif + NETDEV_TXTIMEOUTS(&priv->dev); /* Then reset the hardware: Take the interface down, then bring it * back up @@ -2302,7 +2290,7 @@ static int enc_ifup(struct net_driver_s *dev) EIE_PKTIE | EIE_RXABTIE | EIE_TXIE); -#ifdef CONFIG_ENCX24J600_STATS +#ifdef CONFIG_NETDEV_STATISTICS enc_bfs(priv, ENC_EIE, EIE_TXABTIE); #endif @@ -2961,41 +2949,4 @@ int enc_initialize(FAR struct spi_dev_s *spi, return netdev_register(&priv->dev, NET_LL_ETHERNET); } -/**************************************************************************** - * Function: enc_stats - * - * Description: - * Return accumulated ENCX24J600 statistics. Statistics are cleared after - * being returned. - * - * Parameters: - * devno - If more than one ENCX24J600 is supported, then this is the - * zero based number that identifies the ENCX24J600; - * stats - The user-provided location to return the statistics. - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_ENCX24J600_STATS -int enc_stats(unsigned int devno, struct enc_stats_s *stats) -{ - FAR struct enc_driver_s *priv ; - irqstate_t flags; - - DEBUGASSERT(devno < CONFIG_ENCX24J600_NINTERFACES); - priv = &g_encx24j600[devno]; - - /* Disable the Ethernet interrupt */ - - flags = irqsave(); - memcpy(stats, &priv->stats, sizeof(struct enc_stats_s)); - memset(&priv->stats, 0, sizeof(struct enc_stats_s)); - irqrestore(flags); - return OK; -} -#endif #endif /* CONFIG_NET && CONFIG_ENCX24J600_NET */ diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 2a980ed5cc..eecc4c9615 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -163,6 +163,7 @@ struct ftmac100_driver_s uint32_t iobase; /* NuttX net data */ + bool ft_bifup; /* true:ifup false:ifdown */ WDOG_ID ft_txpoll; /* TX poll timer */ WDOG_ID ft_txtimeout; /* TX timeout timer */ @@ -294,8 +295,6 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) * must have assured that there is no transmission in progress. */ - /* Increment statistics */ - len = len < ETH_ZLEN ? ETH_ZLEN : len; /* Send the packet: address=priv->ft_dev.d_buf, length=priv->ft_dev.d_len */ @@ -669,10 +668,6 @@ static void ftmac100_receive(FAR struct ftmac100_driver_s *priv) nvdbg ("RX buffer %d (%08x), %x received (%d)\n", priv->rx_pointer, data, len, (rxdes->rxdes0 & FTMAC100_RXDES0_LRS)); - /* Check for errors and update statistics */ - - /* Check if the packet is a valid size for the uIP buffer configuration */ - /* Copy the data data from the hardware to priv->ft_dev.d_buf. Set * amount of data in priv->ft_dev.d_len */ @@ -810,7 +805,7 @@ static void ftmac100_txdone(FAR struct ftmac100_driver_s *priv) { FAR struct ftmac100_txdes_s *txdes; - /* Check for errors and update statistics */ + /* Check if a Tx was pending */ while (priv->tx_pending) { @@ -1081,8 +1076,6 @@ static int ftmac100_interrupt(int irq, FAR void *context) static inline void ftmac100_txtimeout_process(FAR struct ftmac100_driver_s *priv) { - /* Increment statistics and dump debug info */ - /* Then reset the hardware */ nvdbg("TXTIMEOUT\n"); diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 79b8bfc5bf..7bb99c1744 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -174,6 +174,9 @@ static int lo_txpoll(FAR struct net_driver_s *dev) while (priv->lo_dev.d_len > 0) { + NETDEV_TXPACKETS(&priv->lo_dev); + NETDEV_RXPACKETS(&priv->lo_dev); + #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ @@ -186,6 +189,7 @@ static int lo_txpoll(FAR struct net_driver_s *dev) if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->lo_dev); ipv4_input(&priv->lo_dev); } else @@ -194,16 +198,19 @@ static int lo_txpoll(FAR struct net_driver_s *dev) if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->lo_dev); ipv6_input(&priv->lo_dev); } else #endif { ndbg("WARNING: Unrecognized packet type dropped: %02x\n", IPv4BUF->vhl); + NETDEV_RXDROPPED(&priv->lo_dev); priv->lo_dev.d_len = 0; } priv->lo_txdone = true; + NETDEV_TXDONE(&priv->lo_dev); } return 0; diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index c59498e6bd..a395b2eda1 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -208,6 +208,8 @@ static int skel_transmit(FAR struct skel_driver_s *priv) /* Increment statistics */ + NETDEV_TXPACKETS(priv->sk_dev); + /* Send the packet: address=priv->sk_dev.d_buf, length=priv->sk_dev.d_len */ /* Enable Tx interrupts */ @@ -334,6 +336,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->sk_dev); /* Handle ARP on input then give the IPv4 packet to the network * layer @@ -374,6 +377,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->sk_dev); /* Give the IPv6 packet to the network layer */ @@ -411,6 +415,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&priv->sk_dev); + NETDEV_RXARP(&priv->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. @@ -422,6 +427,10 @@ static void skel_receive(FAR struct skel_driver_s *priv) } } #endif + else + { + NETDEV_RXDROPPED(&priv->sk_dev); + } } while (); /* While there are more packets to be processed */ } @@ -447,6 +456,8 @@ static void skel_txdone(FAR struct skel_driver_s *priv) { /* Check for errors and update statistics */ + NETDEV_TXDONE(priv->sk_dev); + /* If no further xmits are pending, then cancel the TX timeout and * disable further Tx interrupts. */ @@ -607,6 +618,8 @@ static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv) { /* Increment statistics and dump debug info */ + NETDEV_TXTIMEOUTS(priv->sk_dev); + /* Then reset the hardware */ /* Then poll the network for new XMIT data */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index a7db1780ce..6026ec3d5b 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -130,28 +130,10 @@ #define SLIP_WDDELAY (1*1000000) #define SLIP_POLLHSEC (1*2) -/* Statistics helper */ - -#ifdef CONFIG_NET_STATISTICS -# define SLIP_STAT(p,f) (p->stats.f)++ -#else -# define SLIP_STAT(p,f) -#endif - /**************************************************************************** * Private Types ****************************************************************************/ -/* Driver statistics */ - -#ifdef CONFIG_NET_STATISTICS -struct slip_statistics_s -{ - uint32_t transmitted; /* Number of packets transmitted */ - uint32_t received /* Number of packets received */ -}; -#endif - /* The slip_driver_s encapsulates all state information for a single hardware * interface */ @@ -166,12 +148,6 @@ struct slip_driver_s pid_t txpid; /* Transmitter thread ID */ sem_t waitsem; /* Mutually exclusive access to uIP */ - /* Driver statistics */ - -#ifdef CONFIG_NET_STATISTICS - struct slip_statistics_s stats; -#endif - /* This holds the information visible to uIP/NuttX */ struct net_driver_s dev; /* Interface understood by uIP */ @@ -312,7 +288,7 @@ static int slip_transmit(FAR struct slip_driver_s *priv) /* Increment statistics */ nvdbg("Sending packet size %d\n", priv->dev.d_len); - SLIP_STAT(priv, transmitted); + NETDEV_TXPACKETS(&priv->dev); /* Send an initial END character to flush out any data that may have * accumulated in the receiver due to line noise @@ -393,6 +369,7 @@ static int slip_transmit(FAR struct slip_driver_s *priv) /* And send the END token */ slip_putc(priv, SLIP_END); + NETDEV_TXDONE(&priv->dev); priv->txnodelay = true; return OK; } @@ -736,7 +713,7 @@ static int slip_rxtask(int argc, FAR char *argv[]) */ slip_receive(priv); - SLIP_STAT(priv, received); + NETDEV_RXPACKETS(&priv->dev); /* All packets are assumed to be IP packets (we don't have a choice.. * there is no Ethernet header containing the EtherType). So pass the @@ -746,6 +723,8 @@ static int slip_rxtask(int argc, FAR char *argv[]) if (priv->rxlen >= IPv4_HDRLEN) { + NETDEV_RXIPV4(&priv->dev); + /* Handle the IP input. Get exclusive access to uIP. */ slip_semtake(priv); @@ -770,7 +749,7 @@ static int slip_rxtask(int argc, FAR char *argv[]) } else { - SLIP_STAT(priv, rxsmallpacket); + NETDEV_RXERRORS(&priv->dev); } } diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 39f5266568..088e063ab1 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -325,6 +325,8 @@ static void tun_pollnotify(FAR struct tun_device_s *priv, pollevent_t eventset) static int tun_transmit(FAR struct tun_device_s *priv) { + NETDEV_TXPACKETS(&priv->dev); + /* Verify that the hardware is ready to send another packet. If we get * here, then we are committed to sending a packet; Higher level logic * must have assured that there is no transmission in progress. @@ -413,6 +415,8 @@ static void tun_receive(FAR struct tun_device_s *priv) * data in priv->dev.d_len */ + NETDEV_RXPACKETS(&priv->dev); + #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ @@ -424,6 +428,7 @@ static void tun_receive(FAR struct tun_device_s *priv) #ifdef CONFIG_NET_IPv4 { nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->dev); /* Give the IPv4 packet to the network layer */ @@ -444,6 +449,7 @@ static void tun_receive(FAR struct tun_device_s *priv) tun_pollnotify(priv, POLLOUT); } } + else #endif #if 0 @@ -451,6 +457,7 @@ static void tun_receive(FAR struct tun_device_s *priv) if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->dev); /* Give the IPv6 packet to the network layer */ @@ -482,7 +489,11 @@ static void tun_receive(FAR struct tun_device_s *priv) tun_transmit(priv); } } + else #endif + { + NETDEV_RXDROPPED(&priv->dev); + } #endif } @@ -507,6 +518,8 @@ static void tun_txdone(FAR struct tun_device_s *priv) { /* Check for errors and update statistics */ + NETDEV_TXDONE(&priv->dev); + /* Then poll uIP for new XMIT data */ priv->dev.d_buf = priv->read_buf; diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index abd08a3cae..d8849d8194 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -177,8 +177,6 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet) * must have assured that there is not transmission in progress. */ - /* Increment statistics */ - /* Send the packet: address=vnet->sk_dev.d_buf, length=vnet->sk_dev.d_len */ err = vnet_xmit(vnet->vnet, (char *)vnet->sk_dev.d_buf, vnet->sk_dev.d_len); @@ -476,11 +474,7 @@ static void vnet_txtimeout(int argc, uint32_t arg, ...) { FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg; - /* Increment statistics and dump debug info */ - - /* Then reset the hardware */ - - /* Then poll the network for new XMIT data */ + /* Poll the network for new XMIT data */ (void)devif_poll(&vnet->sk_dev, vnet_txpoll); } diff --git a/include/nuttx/net/cs89x0.h b/include/nuttx/net/cs89x0.h index 493a552a18..9d92a19311 100644 --- a/include/nuttx/net/cs89x0.h +++ b/include/nuttx/net/cs89x0.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/cs89x0.h * - * Copyright (C) 2009, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,29 +49,6 @@ * Public Types ****************************************************************************/ -/* This structure returns driver statistics (if enabled) */ - -#ifdef CONFIG_C89x0_STATISTICS -struct cs89x0_statistics_s -{ - uint32_t tx_packets; - uint32_t tx_errors; - uint32_t tx_carriererrors; - uint32_t tx_heartbeaterrors; - uint32_t tx_windowerrors; - uint32_t tx_abortederrors; - uint32_t rx_missederrors; - uint32_t rx_packets; - uint32_t rx_errors; - uint32_t rx_lengtherrors; - uint32_t rx_crcerrors; - uint32_t rx_frameerrors; - uint32_t rx_dropped; - uint32_t rx_missederrors; - uint32_t collisions; -}; -#endif - /* This structure encapsulates all state information for a single hardware * interface. It includes values that must be provided by the user to in * to describe details of the CS89x00 implementation on a particular board. @@ -112,12 +89,6 @@ struct cs89x0_driver_s /* This holds the information visible to uIP/NuttX */ struct net_driver_s cs_dev; /* Interface understood by uIP */ - - /* Driver statistics */ - -#ifdef CONFIG_C89x0_STATISTICS - struct cs89x0_statistics_s cs_stats; -#endif }; /**************************************************************************** diff --git a/include/nuttx/net/enc28j60.h b/include/nuttx/net/enc28j60.h index aeb8e51662..b5d31e4654 100644 --- a/include/nuttx/net/enc28j60.h +++ b/include/nuttx/net/enc28j60.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/enc28j60.h * - * Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,6 @@ * CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency * CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60 * devices that will be supported. - * CONFIG_ENC28J60_STATS - Collect network statistics * CONFIG_ENC28J60_HALFDUPPLEX - Default is full duplex */ @@ -64,24 +63,6 @@ * Public Types ****************************************************************************/ -/* This structure returns driver statistics (if enabled) */ - -#ifdef CONFIG_ENC28J60_STATS -struct enc_stats_s -{ - uint8_t maxpktcnt; /* Max. number of buffered RX packets */ - uint32_t txrequests; /* Number of TX packets queued */ - uint32_t txifs; /* TXIF completion events */ - uint32_t txabrts; /* TXIF completions with ESTAT.TXABRT */ - uint32_t txerifs; /* TXERIF error events */ - uint32_t txtimeouts; /* S/W detected TX timeouts */ - uint32_t pktifs; /* PKTIF RX completion events */ - uint32_t rxnotok; /* PKTIF without RXSTAT_OK */ - uint32_t rxpktlen; /* PKTIF with bad pktlen */ - uint32_t rxerifs; /* RXERIF error evernts */ -}; -#endif - /* The ENC28J60 normal provides interrupts to the MCU via a GPIO pin. The * following structure provides an MCU-independent mechanixm for controlling * the ENC28J60 GPIO interrupt. @@ -151,29 +132,6 @@ struct spi_dev_s; /* see nuttx/spi/spi.h */ int enc_initialize(FAR struct spi_dev_s *spi, FAR const struct enc_lower_s *lower, unsigned int devno); -/**************************************************************************** - * Function: enc_stats - * - * Description: - * Return accumulated ENC28J60 statistics. Statistics are cleared after - * being returned. - * - * Parameters: - * devno - If more than one ENC28J60 is supported, then this is the - * zero based number that identifies the ENC28J60; - * stats - The user-provided location to return the statistics. - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_ENC28J60_STATS -int enc_stats(unsigned int devno, struct enc_stats_s *stats); -#endif - #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/net/encx24j600.h b/include/nuttx/net/encx24j600.h index 0a39373a82..39ce6c8664 100644 --- a/include/nuttx/net/encx24j600.h +++ b/include/nuttx/net/encx24j600.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/encx24j600.h * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,6 @@ * CONFIG_ENCX24J600_FREQUENCY - Define to use a different bus frequency * CONFIG_ENCX24J600_NINTERFACES - Specifies the number of physical ENCX24J600 * devices that will be supported. - * CONFIG_ENCX24J600_STATS - Collect network statistics * CONFIG_ENCX24J600_HALFDUPPLEX - Default is full duplex */ @@ -64,24 +63,6 @@ * Public Types ****************************************************************************/ -/* This structure returns driver statistics (if enabled) */ - -#ifdef CONFIG_ENCX24J600_STATS -struct enc_stats_s -{ - uint8_t maxpktcnt; /* Max. number of buffered RX packets */ - uint32_t txrequests; /* Number of TX packets queued */ - uint32_t txifs; /* TXIF completion events */ - uint32_t txabrts; /* TXIF completions with ESTAT.TXABRT */ - uint32_t txerifs; /* TXERIF error events */ - uint32_t txtimeouts; /* S/W detected TX timeouts */ - uint32_t pktifs; /* PKTIF RX completion events */ - uint32_t rxnotok; /* PKTIF without RXSTAT_OK */ - uint32_t rxpktlen; /* PKTIF with bad pktlen */ - uint32_t rxerifs; /* RXERIF error evernts */ -}; -#endif - /* The ENCX24J600 normal provides interrupts to the MCU via a GPIO pin. The * following structure provides an MCU-independent mechanixm for controlling * the ENCX24J600 GPIO interrupt. @@ -150,30 +131,6 @@ extern "C" struct spi_dev_s; /* see nuttx/spi/spi.h */ int enc_initialize(FAR struct spi_dev_s *spi, FAR const struct enc_lower_s *lower, unsigned int devno); - -/**************************************************************************** - * Function: enc_stats - * - * Description: - * Return accumulated ENCX24J600 statistics. Statistics are cleared after - * being returned. - * - * Parameters: - * devno - If more than one ENCX24J600 is supported, then this is the - * zero based number that identifies the ENCX24J600; - * stats - The user-provided location to return the statistics. - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_ENCX24J600_STATS -int enc_stats(unsigned int devno, struct enc_stats_s *stats); -#endif - #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 2fada4fdbf..859e0e3e10 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -66,17 +66,113 @@ * Pre-processor Definitions ****************************************************************************/ +/* Helper macros for network device statistics */ + +#ifdef CONFIG_NETDEV_STATISTICS +# define NETDEV_RESET_STATISTICS(dev) \ + memset(&(dev)->d_statistics, 0, sizeof(struct netdev_statistics_s)) + +# define _NETDEV_STATISTIC(dev,name) ((dev)->d_statistics.name) +# define _NETDEV_ERROR(dev,name) \ + do \ + { \ + (dev)->d_statistics.name++; \ + (dev)->d_statistics.errors++; \ + } \ + while (0) + +# define NETDEV_RXPACKETS(dev) _NETDEV_STATISTIC(dev,rx_packets) +# define NETDEV_RXFRAGMENTS(dev) _NETDEV_STATISTIC(dev,rx_fragments) +# define NETDEV_RXERRORS(dev) _NETDEV_ERROR(dev,rx_errors) +# ifdef CONFIG_NET_IPv4 +# define NETDEV_RXIPV4(dev) _NETDEV_STATISTIC(dev,rx_ipv4) +# else +# define NETDEV_RXIPV4(dev) +# endif +# ifdef CONFIG_NET_IPv6 +# define NETDEV_RXIPV6(dev) _NETDEV_STATISTIC(dev,rx_ipv6) +# else +# define NETDEV_RXIPV6(dev) +# endif +# ifdef CONFIG_NET_ARP +# define NETDEV_RXARP(dev) _NETDEV_STATISTIC(dev,rx_arp) +# else +# define NETDEV_RXARP(dev) +# endif +# define NETDEV_RXDROPPED(dev) _NETDEV_STATISTIC(dev,rx_dropped) + +# define NETDEV_TXPACKETS(dev) _NETDEV_STATISTIC(dev,tx_packets) +# define NETDEV_TXDONE(dev) _NETDEV_STATISTIC(dev,tx_done) +# define NETDEV_TXERRORS(dev) _NETDEV_ERROR(dev,tx_errors) +# define NETDEV_TXTIMEOUTS(dev) _NETDEV_ERROR(dev,tx_timeouts) + +# define NETDEV_ERRORS(dev) _NETDEV_STATISTIC(dev,errors) + +#else +# define NETDEV_RXPACKETS(dev) +# define NETDEV_RXFRAGMENTS(dev) +# define NETDEV_RXERRORS(dev) +# define NETDEV_RXIPV4(dev) +# define NETDEV_RXIPV6(dev) +# define NETDEV_RXARP(dev) +# define NETDEV_RXDROPPED(dev) + +# define NETDEV_TXPACKETS(dev) +# define NETDEV_TXDONE(dev) +# define NETDEV_TXERRORS(dev) +# define NETDEV_TXTIMEOUTS(dev) + +# define NETDEV_ERRORS(dev) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ -struct devif_callback_s; /* Forward reference */ +#ifdef CONFIG_NETDEV_STATISTICS +/* If CONFIG_NETDEV_STATISTICS is enabled and if the driver supports + * statistics, then this structure holds the counts of network driver + * events. + */ + +struct netdev_statistics_s +{ + /* Rx Status */ + + uint32_t rx_packets; /* Number of packets received */ + uint32_t rx_fragments; /* Number of fragments received */ + uint32_t rx_errors; /* Number of receive errors */ +#ifdef CONFIG_NET_IPv4 + uint32_t rx_ipv4; /* Number of Rx IPv4 packets received */ +#endif +#ifdef CONFIG_NET_IPv6 + uint32_t rx_ipv6; /* Number of Rx IPv6 packets received */ +#endif +#ifdef CONFIG_NET_ARP + uint32_t rx_arp; /* Number of Rx ARP packets received */ +#endif + uint32_t rx_dropped; /* Unsupported Rx packets received */ + + /* Tx Status */ + + uint32_t tx_packets; /* Number of Tx packets queued */ + unit32_t tx_done; /* Number of packets completed */ + uint32_t tx_errors; /* Number of receive errors (incl timeouts) */ + uint32_t tx_timeouts; /* Number of Tx timeout errors */ + + /* Other status */ + + uint32_t errors; /* Total umber of errors */ +}; +#endif /* This structure collects information that is specific to a specific network * interface driver. If the hardware platform supports only a single instance * of this structure. */ +struct devif_callback_s; /* Forward reference */ + struct net_driver_s { /* This link is used to maintain a single-linked list of ethernet drivers. @@ -192,6 +288,15 @@ struct net_driver_s sq_queue_t grplist; #endif +#ifdef CONFIG_NETDEV_STATISTICS + /* If CONFIG_NETDEV_STATISTICS is enabled and if the driver supports + * statistics, then this structure holds the counts of network driver + * events. + */ + + struct netdev_statistics_s d_statistics; +#endif + /* Application callbacks: * * Network device event handlers are retained in a 'list' and are called diff --git a/net/Kconfig b/net/Kconfig index b13a38351c..9c0951e289 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -24,10 +24,12 @@ config NET_NOINTS bool "Not interrupt driven" default n ---help--- - NET_NOINT indicates that uIP is not called from the interrupt level. - If NET_NOINTS is defined, critical sections will be managed with semaphores; - Otherwise, it assumed that uIP will be called from interrupt level handling - and critical sections will be managed by enabling and disabling interrupts. + NET_NOINT indicates that network layer is not called from the + interrupt level. If NET_NOINTS is defined, critical sections + will be managed with semaphores; Otherwise, it assumed that + network layer will be called from interrupt level handling + and critical sections will be managed by enabling and disabling + interrupts. config NET_PROMISCUOUS bool "Promiscuous mode" @@ -42,12 +44,12 @@ config NET_MULTIBUFFER bool "Use multiple device-side I/O buffers" default n ---help--- - Traditionally, uIP has used a single buffer for all incoming and - outgoing traffic. If this configuration is selected, then the - driver can manage multiple I/O buffers and can, for example, - be filling one input buffer while sending another output buffer. - Or, as another example, the driver may support queuing of concurrent - input/ouput and output transfers for better performance. + Traditionally, the uIP stacl has used a single buffer for all + incoming and outgoing traffic. If this configuration is selected, + then the driver can manage multiple I/O buffers and can, for + example, be filling one input buffer while sending another output + buffer. Or, as another example, the driver may support queuing of + concurrent input/ouput and output transfers for better performance. config NET_ETH_MTU int "Ethernet packet buffer size (MTU)" @@ -184,10 +186,10 @@ config NET_SLIP network settings: NET_NOINTS and NET_MULTIBUFFER. SLIP supports point-to-point IP communications over a serial port. - The default data link layer for uIP is Ethernet. If NET_SLIP is - defined in the NuttX configuration file, then SLIP will be supported. - The basic differences between the SLIP and Ethernet configurations is - that when SLIP is selected: + The default data link layer for network layer is Ethernet. If + NET_SLIP is defined in the NuttX configuration file, then SLIP will + be supported. The basic differences between the SLIP and Ethernet + configurations is that when SLIP is selected: * The link level header (that comes before the IP header) is omitted. * All MAC address processing is suppressed. @@ -226,6 +228,7 @@ config NET_TUN default n select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_SLIP select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_SLIP + select ARCH_HAVE_NETDEV_STATISTICS if NET_TUN @@ -278,7 +281,7 @@ config NET_STATISTICS bool "Collect network statistics" default n ---help--- - uIP statistics on or off + Network layer statistics on or off source "net/route/Kconfig" -- GitLab From 8075a67803de2a6279ccf23941a1a619ca93a6d8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Nov 2015 12:51:45 -0600 Subject: [PATCH 376/858] include/nuttx/net/netdef.h: Add a missing macro --- arch | 2 +- configs | 2 +- include/nuttx/net/netdev.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ee23d9991d..26a3df8169 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ee23d9991d2fa2cb58a834dee03181558a03b855 +Subproject commit 26a3df81693aa11a487fda52ee001792ed4212a6 diff --git a/configs b/configs index 8fcf1ca2b7..28e45ddd60 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8fcf1ca2b7ec45e4c5bd29258b5e5adc5ed8fcdc +Subproject commit 28e45ddd60209c12e6e8cae0c3100ee06c9cc36b diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 859e0e3e10..73cc0798e8 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -109,6 +109,7 @@ # define NETDEV_ERRORS(dev) _NETDEV_STATISTIC(dev,errors) #else +# define NETDEV_RESET_STATISTICS(dev) # define NETDEV_RXPACKETS(dev) # define NETDEV_RXFRAGMENTS(dev) # define NETDEV_RXERRORS(dev) -- GitLab From edbb5ec3281b8cf91c2f216e4486bd29318dc1b1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Nov 2015 13:17:32 -0600 Subject: [PATCH 377/858] arch-specific build needs to include __KERNEL__ flags --- LibTargets.mk | 13 ++++++------- configs | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/LibTargets.mk b/LibTargets.mk index 757a9cb1b7..24a2627a9c 100755 --- a/LibTargets.mk +++ b/LibTargets.mk @@ -64,7 +64,6 @@ $(ARCH_SRC)$(DELIM)libkarch$(LIBEXT): context lib$(DELIM)libkarch$(LIBEXT): $(ARCH_SRC)$(DELIM)libkarch$(LIBEXT) $(Q) install $(ARCH_SRC)$(DELIM)libkarch$(LIBEXT) lib$(DELIM)libkarch$(LIBEXT) - sched$(DELIM)libsched$(LIBEXT): context $(Q) $(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) KERNEL=y EXTRADEFINES=$(KDEFINE) @@ -119,6 +118,12 @@ audio$(DELIM)libaudio$(LIBEXT): context lib$(DELIM)libaudio$(LIBEXT): audio$(DELIM)libaudio$(LIBEXT) $(Q) install audio$(DELIM)libaudio$(LIBEXT) lib$(DELIM)libaudio$(LIBEXT) +$(ARCH_SRC)$(DELIM)libarch$(LIBEXT): context + $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) KERNEL=y EXTRADEFINES=$(KDEFINE) + +lib$(DELIM)libarch$(LIBEXT): $(ARCH_SRC)$(DELIM)libarch$(LIBEXT) + $(Q) install $(ARCH_SRC)$(DELIM)libarch$(LIBEXT) lib$(DELIM)libarch$(LIBEXT) + # Special case syscall$(DELIM)libstubs$(LIBEXT): context @@ -190,9 +195,3 @@ mm$(DELIM)libmm$(LIBEXT): context lib$(DELIM)libmm$(LIBEXT): mm$(DELIM)libmm$(LIBEXT) $(Q) install mm$(DELIM)libmm$(LIBEXT) lib$(DELIM)libmm$(LIBEXT) - -$(ARCH_SRC)$(DELIM)libarch$(LIBEXT): context - $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) - -lib$(DELIM)libarch$(LIBEXT): $(ARCH_SRC)$(DELIM)libarch$(LIBEXT) - $(Q) install $(ARCH_SRC)$(DELIM)libarch$(LIBEXT) lib$(DELIM)libarch$(LIBEXT) diff --git a/configs b/configs index 28e45ddd60..b52f98b9c9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 28e45ddd60209c12e6e8cae0c3100ee06c9cc36b +Subproject commit b52f98b9c91f8d84e7484e818e065b1e63b1d469 -- GitLab From f41ad9caa143821146cd62a48eaf2584bef728d5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Nov 2015 13:41:57 -0600 Subject: [PATCH 378/858] netdev.h: Fix a typo in a type name --- include/nuttx/net/netdev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 73cc0798e8..b28d0371dc 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -157,7 +157,7 @@ struct netdev_statistics_s /* Tx Status */ uint32_t tx_packets; /* Number of Tx packets queued */ - unit32_t tx_done; /* Number of packets completed */ + uint32_t tx_done; /* Number of packets completed */ uint32_t tx_errors; /* Number of receive errors (incl timeouts) */ uint32_t tx_timeouts; /* Number of Tx timeout errors */ -- GitLab From 5d1557b28dabb8984037b7df1cf2e357e96b9cdc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Nov 2015 14:44:07 -0600 Subject: [PATCH 379/858] Fix an error in a network device statistics macro --- include/nuttx/net/netdev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index b28d0371dc..3182e7f80b 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -72,7 +72,7 @@ # define NETDEV_RESET_STATISTICS(dev) \ memset(&(dev)->d_statistics, 0, sizeof(struct netdev_statistics_s)) -# define _NETDEV_STATISTIC(dev,name) ((dev)->d_statistics.name) +# define _NETDEV_STATISTIC(dev,name) ((dev)->d_statistics.name++) # define _NETDEV_ERROR(dev,name) \ do \ { \ -- GitLab From e4236941c6a3d0d1c4742fd83692626fa7694a17 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 27 Nov 2015 12:33:58 -0600 Subject: [PATCH 380/858] net/net_procfs.c: Add basic support for networking procfs entries --- ChangeLog | 5 +- TODO | 6 +- arch | 2 +- configs | 2 +- fs/procfs/Kconfig | 5 + fs/procfs/fs_procfs.c | 20 +- fs/procfs/fs_procfsproc.c | 4 +- fs/procfs/fs_skeleton.c | 21 +- net/Makefile | 6 + net/net_procfs.c | 912 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 962 insertions(+), 21 deletions(-) create mode 100644 net/net_procfs.c diff --git a/ChangeLog b/ChangeLog index 55e099bcad..1fc07dc19b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11172,4 +11172,7 @@ definition in the common network device structure defined in netdev.h where they can be accessed by network applications. All Ethernet drivers that collect statistics have been adapted to use these common - statistics (2015-11-26). \ No newline at end of file + statistics (2015-11-26). + * net/net_procfs.c: Add basic support for networking entries in the + procfs (2015-11-27). + diff --git a/TODO b/TODO index ff34eeb102..b9ccb47afd 100644 --- a/TODO +++ b/TODO @@ -453,6 +453,9 @@ o Kernel/Protected Build http://git.busybox.net/busybox/tree/util-linux/mkfs_vfat.c + ps, ifup, ifdown, ifconfig should be implemented using + extensions to the procfs file system. + Status: Open Priority: Medium/High -- the kernel build configuration is not fully fielded yet. @@ -1553,6 +1556,7 @@ o Graphics subsystem (graphics/) Status: Open Priority: Low, not a serious issue but worth noting. There is no plan to change this behavior. + o Pascal Add-On (pcode/) ^^^^^^^^^^^^^^^^^^^^^^ @@ -1795,7 +1799,7 @@ o NuttShell (NSH) (apps/nshlib) show status for the single interface on the command line; it will still show status for all interfaces. Status: Open - Priority: Low (multiple network interfaces not fully supported yet anyway). + Priority: Low Title: ARP COMMAND Description: Add an ARP command so that we can see and modify the contents of diff --git a/arch b/arch index 26a3df8169..7a800cc36f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 26a3df81693aa11a487fda52ee001792ed4212a6 +Subproject commit 7a800cc36f9078f59f3f19c6eb400701952cfb7c diff --git a/configs b/configs index b52f98b9c9..18c27d6535 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b52f98b9c91f8d84e7484e818e065b1e63b1d469 +Subproject commit 18c27d653564ec78841d6912597155fde62467c7 diff --git a/fs/procfs/Kconfig b/fs/procfs/Kconfig index 9b6b433b10..2b4fe81af2 100644 --- a/fs/procfs/Kconfig +++ b/fs/procfs/Kconfig @@ -39,6 +39,11 @@ config FS_PROCFS_EXCLUDE_MOUNTS default n depends on !DISABLE_MOUNTPOINT +config FS_PROCFS_EXCLUDE_NET + bool "Exclude network" + depends on NET + default n + config FS_PROCFS_EXCLUDE_MTD bool "Exclude mtd" depends on MTD diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 5b6786b2e6..951f3caa5d 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -79,10 +79,13 @@ extern const struct procfs_operations proc_operations; extern const struct procfs_operations cpuload_operations; extern const struct procfs_operations uptime_operations; -/* This is not good. These are implemented in drivers/mtd. Having to - * deal with them here is not a good coupling. +/* This is not good. These are implemented in other sub-systems. Having to + * deal with them here is not a good coupling. What is really needed is a + * run-time procfs registration system vs. a build time, fixed procfs + * configuration. */ +extern const struct procfs_operations net_procfsoperations; extern const struct procfs_operations mtd_procfsoperations; extern const struct procfs_operations part_procfsoperations; extern const struct procfs_operations smartfs_procfsoperations; @@ -117,6 +120,11 @@ static const struct procfs_entry_s g_procfsentries[] = { "fs/smartfs**", &smartfs_procfsoperations }, #endif +#if defined(CONFIG_NET) && !defined(CONFIG_FS_PROCFS_EXCLUDE_NET) + { "net", &net_procfsoperations }, + { "net/**", &net_procfsoperations }, +#endif + #if defined(CONFIG_MTD) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MTD) { "mtd", &mtd_procfsoperations }, #endif @@ -483,7 +491,7 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, level0->base.nentries = 0; #endif - /* Initialze lastread entries */ + /* Initialize lastread entries */ level0->lastread = ""; level0->lastlen = 0; @@ -533,7 +541,7 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Doing an intermediate directory search */ - /* The path refers to the top level directory. Allocate the level0 + /* The path refers to the top level directory. Allocate the level1 * dirent structure. */ @@ -756,8 +764,8 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) */ if (strncmp(g_procfsentries[level1->base.index].pathpattern, - g_procfsentries[level1->firstindex].pathpattern, - level1->subdirlen) == 0) + g_procfsentries[level1->firstindex].pathpattern, + level1->subdirlen) == 0) { /* This entry matches. Report the subdir entry */ diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 62284797df..0d4f3b9945 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -125,9 +125,9 @@ struct proc_file_s struct proc_dir_s { - struct procfs_dir_priv_s base; /* Base directory private data */ + struct procfs_dir_priv_s base; /* Base directory private data */ FAR const struct proc_node_s *node; /* Directory node description */ - pid_t pid; /* ID of task/thread for attributes */ + pid_t pid; /* ID of task/thread for attributes */ }; /**************************************************************************** diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c index 99ba5b4f18..11bc567fd8 100644 --- a/fs/procfs/fs_skeleton.c +++ b/fs/procfs/fs_skeleton.c @@ -110,7 +110,8 @@ static ssize_t skel_read(FAR struct file *filep, FAR char *buffer, static int skel_dup(FAR const struct file *oldp, FAR struct file *newp); -static int skel_opendir(const char *relpath, FAR struct fs_dirent_s *dir); +static int skel_opendir(FAR const char *relpath, + FAR struct fs_dirent_s *dir); static int skel_closedir(FAR struct fs_dirent_s *dir); static int skel_readdir(FAR struct fs_dirent_s *dir); static int skel_rewinddir(FAR struct fs_dirent_s *dir); @@ -118,7 +119,7 @@ static int skel_rewinddir(FAR struct fs_dirent_s *dir); static int skel_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** @@ -158,7 +159,7 @@ const struct procfs_operations skel_procfsoperations = ****************************************************************************/ static int skel_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) + int oflags, mode_t mode) { FAR struct skel_file_s *priv; @@ -220,7 +221,7 @@ static int skel_close(FAR struct file *filep) ****************************************************************************/ static ssize_t skel_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) + size_t buflen) { FAR struct skel_file_s *priv; ssize_t ret; @@ -356,11 +357,12 @@ static int skel_closedir(FAR struct fs_dirent_s *dir) * ****************************************************************************/ -static int skel_readdir(struct fs_dirent_s *dir) +static int skel_readdir(FAR struct fs_dirent_s *dir) { FAR struct skel_level1_s *level1; char filename[16]; - int ret, index; + int index; + int ret; DEBUGASSERT(dir && dir->u.procfs); level1 = dir->u.procfs; @@ -396,12 +398,13 @@ static int skel_readdir(struct fs_dirent_s *dir) /* TODO: Specify the type of entry */ dir->fd_dir.d_type = DTYPE_FILE; - strncpy(dir->fd_dir.d_name, filename, NAME_MAX+1); + strncpy(dir->fd_dir.d_name, filename, NAME_MAX + 1); /* Set up the next directory entry offset. NOTE that we could use the * standard f_pos instead of our own private index. */ + level1->base.index = index + 1; ret = OK; } @@ -415,7 +418,7 @@ static int skel_readdir(struct fs_dirent_s *dir) * ****************************************************************************/ -static int skel_rewinddir(struct fs_dirent_s *dir) +static int skel_rewinddir(FAR struct fs_dirent_s *dir) { FAR struct skel_level1_s *priv; @@ -433,7 +436,7 @@ static int skel_rewinddir(struct fs_dirent_s *dir) * ****************************************************************************/ -static int skel_stat(const char *relpath, struct stat *buf) +static int skel_stat(FAR const char *relpath, FAR truct stat *buf) { int ret = -ENOENT; diff --git a/net/Makefile b/net/Makefile index 0b3aea0a29..30551d9c44 100644 --- a/net/Makefile +++ b/net/Makefile @@ -42,6 +42,12 @@ ifeq ($(CONFIG_NET),y) NET_ASRCS = NET_CSRCS = net_initialize.c +ifeq ($(CONFIG_FS_PROCFS),y) +ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_NET),y) +NET_CSRCS += net_procfs.c +endif +endif + # Socket support SOCK_ASRCS = diff --git a/net/net_procfs.c b/net/net_procfs.c new file mode 100644 index 0000000000..7b9ff3f48a --- /dev/null +++ b/net/net_procfs.c @@ -0,0 +1,912 @@ +/**************************************************************************** + * net/net_procfs.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Determines the size of an intermediate buffer that must be large enough + * to handle the longest line generated by this logic. + */ + +#define NET_LINELEN 64 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This enumeration identifies all of the thread attributes that can be + * accessed via the procfs file system. + */ + +/* This structure describes one open "file" */ + +struct netprocfs_file_s +{ + struct procfs_file_s base; /* Base open file structure */ + uint8_t lineno; /* Line number */ + uint8_t linesize; /* Number of valid characters in line[] */ + uint8_t offset; /* Offset to first valid character in line[] */ + char line[NET_LINELEN]; /* Pre-allocated buffer for formatted lines */ +}; + +/* Level 1 is the directory of attributes */ + +struct netprocfs_level1_s +{ + struct procfs_dir_priv_s base; /* Base directory private data */ +}; + +/* Line generating function type */ + +typedef int (*linegen_t)(FAR struct netprocfs_file_s *netfile); + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* Line generating functions */ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_header(FAR struct netprocfs_file_s *netfile); +static int netprocfs_received(FAR struct netprocfs_file_s *netfile); +static int netprocfs_dropped(FAR struct netprocfs_file_s *netfile); +#ifdef CONFIG_NET_IPv4 +static int netprocfs_ipv4_dropped(FAR struct netprocfs_file_s *netfile); +#endif /* CONFIG_NET_IPv4 */ +#ifdef CONFIG_NET_IPv6 +static int netprocfs_ipv6_dropped(FAR struct netprocfs_file_s *netfile); +#endif /* CONFIG_NET_IPv4 */ +static int netprocfs_checksum(FAR struct netprocfs_file_s *netfile); +#ifdef CONFIG_NET_TCP +static int netprocfs_tcp_dropped_1(FAR struct netprocfs_file_s *netfile); +static int netprocfs_tcp_dropped_2(FAR struct netprocfs_file_s *netfile); +#endif /* CONFIG_NET_TCP */ +static int netprocfs_prototype(FAR struct netprocfs_file_s *netfile); +static int netprocfs_sent(FAR struct netprocfs_file_s *netfile); +#ifdef CONFIG_NET_TCP +static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile); +#endif /* CONFIG_NET_TCP */ +#endif /* CONFIG_NET_STATISTICS */ + +/* File system methods */ + +static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int netprocfs_close(FAR struct file *filep); +static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); + +static int netprocfs_dup(FAR const struct file *oldp, + FAR struct file *newp); + +static int netprocfs_opendir(FAR const char *relpath, + FAR struct fs_dirent_s *dir); +static int netprocfs_closedir(FAR struct fs_dirent_s *dir); +static int netprocfs_readdir(FAR struct fs_dirent_s *dir); +static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir); + +static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Line generating functions */ + +#ifdef CONFIG_NET_STATISTICS +static const linegen_t g_linegen[] = +{ + netprocfs_header, + netprocfs_received, + netprocfs_dropped, + +#ifdef CONFIG_NET_IPv4 + netprocfs_ipv4_dropped, +#endif /* CONFIG_NET_IPv4 */ + +#ifdef CONFIG_NET_IPv6 + netprocfs_ipv6_dropped, +#endif /* CONFIG_NET_IPv4 */ + + netprocfs_checksum, + +#ifdef CONFIG_NET_TCP + netprocfs_tcp_dropped_1, + netprocfs_tcp_dropped_2, +#endif /* CONFIG_NET_TCP */ + + netprocfs_prototype, + netprocfs_sent + +#ifdef CONFIG_NET_TCP + , netprocfs_retransmissions +#endif /* CONFIG_NET_TCP */ +}; + +#define NSTAT_LINES (sizeof(g_linegen) / sizeof(linegen_t)) +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* See include/nutts/fs/procfs.h + * We use the old-fashioned kind of initializers so that this will compile + * with any compiler. + */ + +const struct procfs_operations net_procfsoperations = +{ + netprocfs_open, /* open */ + netprocfs_close, /* close */ + netprocfs_read, /* read */ + NULL, /* write */ + netprocfs_dup, /* dup */ + + netprocfs_opendir, /* opendir */ + netprocfs_closedir, /* closedir */ + netprocfs_readdir, /* readdir */ + netprocfs_rewinddir, /* rewinddir */ + + netprocfs_stat /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netprocfs_header + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_header(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, " "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " IPv4"); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " IPv6"); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " TCP"); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " UDP"); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ICMP"); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ICMPv6"); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_received + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_received(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "Received "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv4.recv); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv6.recv); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.tcp.recv); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.udp.recv); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmp.recv); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmpv6.recv); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_dropped + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_dropped(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "Dropped "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv4.drop); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv6.drop); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.tcp.drop); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.udp.drop); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmp.drop); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmpv6.drop); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_ipv4_dropped + ****************************************************************************/ + +#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_IPv4) +static int netprocfs_ipv4_dropped(FAR struct netprocfs_file_s *netfile) +{ + return snprintf(netfile->line, NET_LINELEN, + " IPv4 VHL: %04x Frg: %04x\n", + g_netstats.ipv4.vhlerr, g_netstats.ipv4.fragerr); +} +#endif /* CONFIG_NET_STATISTICS && CONFIG_NET_IPv4 */ + +/**************************************************************************** + * Name: netprocfs_ipv6_dropped + ****************************************************************************/ + +#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_IPv6) +static int netprocfs_ipv6_dropped(FAR struct netprocfs_file_s *netfile) +{ + return snprintf(netfile->line, NET_LINELEN, + " IPv6 VHL: %04x\n", + g_netstats.ipv6.vhlerr); +} +#endif /* CONFIG_NET_STATISTICS && CONFIG_NET_IPv6 */ + +/**************************************************************************** + * Name: netprocfs_checksum + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_checksum(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, " Checksum "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv4.chkerr); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.tcp.chkerr); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.udp.chkerr); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_tcp_dropped_1 + ****************************************************************************/ + +#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_TCP) +static int netprocfs_tcp_dropped_1(FAR struct netprocfs_file_s *netfile) +{ + return snprintf(netfile->line, NET_LINELEN, + " TCP ACK: %04x SYN: %04x\n", + g_netstats.tcp.ackerr, g_netstats.tcp.syndrop); +} +#endif /* CONFIG_NET_STATISTICS && CONFIG_NET_TCP */ + +/**************************************************************************** + * Name: netprocfs_tcp_dropped_2 + ****************************************************************************/ + +#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_TCP) +static int netprocfs_tcp_dropped_2(FAR struct netprocfs_file_s *netfile) +{ + return snprintf(netfile->line, NET_LINELEN, + " RST: %04x %04x\n", + g_netstats.tcp.rst, g_netstats.tcp.synrst); +} +#endif /* CONFIG_NET_STATISTICS && CONFIG_NET_TCP */ + +/**************************************************************************** + * Name: netprocfs_prototype + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_prototype(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, " Type "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv4.protoerr); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv6.protoerr); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmp.typeerr); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmpv6.typeerr); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_sent + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +static int netprocfs_sent(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "Sent "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv4.sent); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.ipv6.sent); +#endif +#ifdef CONFIG_NET_TCP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.tcp.sent); +#endif +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.udp.sent); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmp.sent); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.icmpv6.sent); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_retransmissions + ****************************************************************************/ + +#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_TCP) +static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile) +{ + int len = 0; + + len += snprintf(&netfile->line[len], NET_LINELEN - len, " Rexmit "); +#ifdef CONFIG_NET_IPv4 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_IPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif + len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x", + g_netstats.tcp.rexmit); +#ifdef CONFIG_NET_UDP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_ICMP + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif +#ifdef CONFIG_NET_ICMPv6 + len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----"); +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} +#endif /* CONFIG_NET_STATISTICS && CONFIG_NET_TCP */ + +/**************************************************************************** + * Name: netprocfs_open + ****************************************************************************/ + +static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode) +{ + FAR struct netprocfs_file_s *priv; + + fvdbg("Open '%s'\n", relpath); + + /* PROCFS is read-only. Any attempt to open with any kind of write + * access is not permitted. + * + * REVISIT: Write-able proc files could be quite useful. + */ + + if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && + (net_procfsoperations.write == NULL)) + { + fdbg("ERROR: Only O_RDONLY supported\n"); + return -EACCES; + } + + /* "net/stat" is the only acceptable value for the relpath */ + + if (strcmp(relpath, "net/stat") != 0) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* Allocate a container to hold the task and attribute selection */ + + priv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); + if (!priv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* Save the index as the open-specific state in filep->f_priv */ + + filep->f_priv = (FAR void *)priv; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_close + ****************************************************************************/ + +static int netprocfs_close(FAR struct file *filep) +{ + FAR struct netprocfs_file_s *priv; + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct netprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Release the file attributes structure */ + + kmm_free(priv); + filep->f_priv = NULL; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_read + ****************************************************************************/ + +static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ +#ifdef CONFIG_NET_STATISTICS + FAR struct netprocfs_file_s *priv; + size_t xfrsize; + ssize_t nreturned; + + fvdbg("buffer=%p buflen=%d\n", buffer, (int)buflen); + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct netprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Is there line data already buffered? */ + + nreturned = 0; + if (priv->linesize > 0) + { + /* Yes, how much can we transfer now? */ + + xfrsize = priv->linesize; + if (xfrsize > buflen) + { + xfrsize = buflen; + } + + /* Transfer the data to the user buffer */ + + memcpy(buffer, &priv->line[priv->offset], xfrsize); + + /* Update pointers, sizes, and offsets */ + + buffer += xfrsize; + buflen -= xfrsize; + + priv->linesize -= xfrsize; + priv->offset += xfrsize; + nreturned = xfrsize; + } + + /* Loop until the user buffer is full or until all of the network + * statistics have been transferred. At this point we know that + * either: + * + * 1. The user buffer is full, and/or + * 2. All of the current line data has been transferred. + */ + + while (buflen > 0 && priv->lineno < NSTAT_LINES) + { + int len; + + /* Read the next line into the working buffer */ + + len = g_linegen[priv->lineno](priv); + + /* Update line-related information */ + + priv->lineno++; + priv->linesize = len; + priv->offset = 0; + + /* Transfer data to the user buffer */ + + xfrsize = priv->linesize; + if (xfrsize > buflen) + { + xfrsize = buflen; + } + + memcpy(buffer, &priv->line[priv->offset], xfrsize); + + /* Update pointers, sizes, and offsets */ + + buffer += xfrsize; + buflen -= xfrsize; + + priv->linesize -= xfrsize; + priv->offset += xfrsize; + nreturned += xfrsize; + } + + /* Update the file offset */ + + if (nreturned > 0) + { + filep->f_pos += nreturned; + } + + return nreturned; +#else + return 0; +#endif +} + +/**************************************************************************** + * Name: netprocfs_dup + * + * Description: + * Duplicate open file data in the new file structure. + * + ****************************************************************************/ + +static int netprocfs_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + FAR struct netprocfs_file_s *oldpriv; + FAR struct netprocfs_file_s *newpriv; + + fvdbg("Dup %p->%p\n", oldp, newp); + + /* Recover our private data from the old struct file instance */ + + oldpriv = (FAR struct netprocfs_file_s *)oldp->f_priv; + DEBUGASSERT(oldpriv); + + /* Allocate a new container to hold the task and attribute selection */ + + newpriv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); + if (!newpriv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* The copy the file attribtes from the old attributes to the new */ + + memcpy(newpriv, oldpriv, sizeof(struct netprocfs_file_s)); + + /* Save the new attributes in the new file structure */ + + newp->f_priv = (FAR void *)newpriv; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_opendir + * + * Description: + * Open a directory for read access + * + ****************************************************************************/ + +static int netprocfs_opendir(FAR const char *relpath, + FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *level1; + + fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL"); + DEBUGASSERT(relpath && dir && !dir->u.procfs); + + /* The path refers to the 1st level sbdirectory. Allocate the level1 + * dirent structure. + */ + + level1 = (FAR struct netprocfs_level1_s *) + kmm_zalloc(sizeof(struct netprocfs_level1_s)); + + if (!level1) + { + fdbg("ERROR: Failed to allocate the level1 directory structure\n"); + return -ENOMEM; + } + + /* Initialze base structure components */ + + level1->base.level = 1; + level1->base.nentries = 1; + level1->base.index = 0; + + dir->u.procfs = (FAR void *) level1; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_closedir + * + * Description: Close the directory listing + * + ****************************************************************************/ + +static int netprocfs_closedir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *priv; + + DEBUGASSERT(dir && dir->u.procfs); + priv = dir->u.procfs; + + if (priv) + { + kmm_free(priv); + } + + dir->u.procfs = NULL; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_readdir + * + * Description: Read the next directory entry + * + ****************************************************************************/ + +static int netprocfs_readdir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *level1; + int index; + int ret; + + DEBUGASSERT(dir && dir->u.procfs); + level1 = dir->u.procfs; + + /* Have we reached the end of the directory */ + + index = level1->base.index; + if (index >= level1->base.nentries) + { + /* We signal the end of the directory by returning the special + * error -ENOENT + */ + + fvdbg("Entry %d: End of directory\n", index); + ret = -ENOENT; + } + + /* Currently only one element in the directory */ + + else + { + DEBUGASSERT(level1->base.level == 1); + DEBUGASSERT(level1->base.index <= 1); + + /* Copy the one supported directory entry */ + + dir->fd_dir.d_type = DTYPE_FILE; + strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1); + + /* Set up the next directory entry offset. NOTE that we could use the + * standard f_pos instead of our own private index. + */ + + level1->base.index = index + 1; + ret = OK; + } + + return ret; +} + +/**************************************************************************** + * Name: netprocfs_rewindir + * + * Description: Reset directory read to the first entry + * + ****************************************************************************/ + +static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *priv; + + DEBUGASSERT(dir && dir->u.procfs); + priv = dir->u.procfs; + + priv->base.index = 0; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_stat + * + * Description: Return information about a file or directory + * + ****************************************************************************/ + +static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf) +{ + /* "net" and "net/stat" are the only acceptable values for the relpath */ + + if (strcmp(relpath, "net") == 0) + { + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; + } + else if (strcmp(relpath, "net/stat") == 0) + { + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; + } + else + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* File/directory size, access block size */ + + buf->st_size = 0; + buf->st_blksize = 512; + buf->st_blocks = 0; + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */ -- GitLab From 9d8462aa2386e427ea26841470f05453a579ab0c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 27 Nov 2015 13:53:33 -0600 Subject: [PATCH 381/858] net/: Move net_procfs.c to net/procfs/. Partition logic a little better to make space to support net device procfs as well --- TODO | 2 +- net/Kconfig | 1 + net/Makefile | 7 +- net/procfs/Kconfig | 4 + net/procfs/Make.defs | 57 +++ net/procfs/net_procfs.c | 427 ++++++++++++++++++ net/{net_procfs.c => procfs/net_statistics.c} | 425 +---------------- net/procfs/procfs.h | 134 ++++++ 8 files changed, 650 insertions(+), 407 deletions(-) create mode 100644 net/procfs/Kconfig create mode 100644 net/procfs/Make.defs create mode 100644 net/procfs/net_procfs.c rename net/{net_procfs.c => procfs/net_statistics.c} (61%) create mode 100644 net/procfs/procfs.h diff --git a/TODO b/TODO index b9ccb47afd..63a10c29ba 100644 --- a/TODO +++ b/TODO @@ -444,7 +444,7 @@ o Kernel/Protected Build ps sched_foreach() ifup netdev_foreach() ifdown netdev_foreach() - ifconfig netdev_foreach(), g_netstats + ifconfig netdev_foreach() ping icmp_ping() The busybox mkfatfs does not involve any OS calls; it does diff --git a/net/Kconfig b/net/Kconfig index 9c0951e289..52a425900a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -275,6 +275,7 @@ source "net/igmp/Kconfig" source "net/arp/Kconfig" source "net/loopback/Kconfig" source "net/iob/Kconfig" +source "net/procfs/Kconfig" source "net/utils/Kconfig" config NET_STATISTICS diff --git a/net/Makefile b/net/Makefile index 30551d9c44..4d42b212b5 100644 --- a/net/Makefile +++ b/net/Makefile @@ -42,12 +42,6 @@ ifeq ($(CONFIG_NET),y) NET_ASRCS = NET_CSRCS = net_initialize.c -ifeq ($(CONFIG_FS_PROCFS),y) -ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_NET),y) -NET_CSRCS += net_procfs.c -endif -endif - # Socket support SOCK_ASRCS = @@ -76,6 +70,7 @@ include udp/Make.defs include devif/Make.defs include loopback/Make.defs include route/Make.defs +include procfs/Make.defs include utils/Make.defs endif diff --git a/net/procfs/Kconfig b/net/procfs/Kconfig new file mode 100644 index 0000000000..f72f3c094c --- /dev/null +++ b/net/procfs/Kconfig @@ -0,0 +1,4 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# diff --git a/net/procfs/Make.defs b/net/procfs/Make.defs new file mode 100644 index 0000000000..49cae7c730 --- /dev/null +++ b/net/procfs/Make.defs @@ -0,0 +1,57 @@ +############################################################################ +# net/procfs/Make.defs +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Network procfs support + +ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) +ifeq ($(CONFIG_FS_PROCFS),y) +ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_NET),y) + +NET_CSRCS += net_procfs.c + +# General network statistics + +ifeq ($(CONFIG_NET_STATISTICS),y) + NET_CSRCS += net_statistics.c +endif + +# Include packet socket build support + +DEPPATH += --dep-path procfs +VPATH += :procfs + +endif # CONFIG_FS_PROCFS_EXCLUDE_NET +endif # CONFIG_FS_PROCFS +endif # CONFIG_DISABLE_MOUNTPOINT diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c new file mode 100644 index 0000000000..0c2bd6025f --- /dev/null +++ b/net/procfs/net_procfs.c @@ -0,0 +1,427 @@ +/**************************************************************************** + * net/procfs/net_procfs.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "procfs/procfs.h" + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_NET) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* File system methods */ + +static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int netprocfs_close(FAR struct file *filep); +static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); + +static int netprocfs_dup(FAR const struct file *oldp, + FAR struct file *newp); + +static int netprocfs_opendir(FAR const char *relpath, + FAR struct fs_dirent_s *dir); +static int netprocfs_closedir(FAR struct fs_dirent_s *dir); +static int netprocfs_readdir(FAR struct fs_dirent_s *dir); +static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir); + +static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf); + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* See include/nutts/fs/procfs.h + * We use the old-fashioned kind of initializers so that this will compile + * with any compiler. + */ + +const struct procfs_operations net_procfsoperations = +{ + netprocfs_open, /* open */ + netprocfs_close, /* close */ + netprocfs_read, /* read */ + NULL, /* write */ + netprocfs_dup, /* dup */ + + netprocfs_opendir, /* opendir */ + netprocfs_closedir, /* closedir */ + netprocfs_readdir, /* readdir */ + netprocfs_rewinddir, /* rewinddir */ + + netprocfs_stat /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netprocfs_open + ****************************************************************************/ + +static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode) +{ + FAR struct netprocfs_file_s *priv; + + fvdbg("Open '%s'\n", relpath); + + /* PROCFS is read-only. Any attempt to open with any kind of write + * access is not permitted. + * + * REVISIT: Write-able proc files could be quite useful. + */ + + if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && + (net_procfsoperations.write == NULL)) + { + fdbg("ERROR: Only O_RDONLY supported\n"); + return -EACCES; + } + + /* "net/stat" is the only acceptable value for the relpath */ + + if (strcmp(relpath, "net/stat") != 0) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* Allocate a container to hold the task and attribute selection */ + + priv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); + if (!priv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* Save the index as the open-specific state in filep->f_priv */ + + filep->f_priv = (FAR void *)priv; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_close + ****************************************************************************/ + +static int netprocfs_close(FAR struct file *filep) +{ + FAR struct netprocfs_file_s *priv; + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct netprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Release the file attributes structure */ + + kmm_free(priv); + filep->f_priv = NULL; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_read + ****************************************************************************/ + +static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ +#ifdef CONFIG_NET_STATISTICS + FAR struct netprocfs_file_s *priv; + ssize_t nreturned; + + fvdbg("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen); + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct netprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Read the network layer statistics */ + + nreturned = net_readstats(priv, buffer, buflen); + + /* Update the file offset */ + + if (nreturned > 0) + { + filep->f_pos += nreturned; + } + + return nreturned; +#else + return 0; +#endif +} + +/**************************************************************************** + * Name: netprocfs_dup + * + * Description: + * Duplicate open file data in the new file structure. + * + ****************************************************************************/ + +static int netprocfs_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + FAR struct netprocfs_file_s *oldpriv; + FAR struct netprocfs_file_s *newpriv; + + fvdbg("Dup %p->%p\n", oldp, newp); + + /* Recover our private data from the old struct file instance */ + + oldpriv = (FAR struct netprocfs_file_s *)oldp->f_priv; + DEBUGASSERT(oldpriv); + + /* Allocate a new container to hold the task and attribute selection */ + + newpriv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); + if (!newpriv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* The copy the file attribtes from the old attributes to the new */ + + memcpy(newpriv, oldpriv, sizeof(struct netprocfs_file_s)); + + /* Save the new attributes in the new file structure */ + + newp->f_priv = (FAR void *)newpriv; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_opendir + * + * Description: + * Open a directory for read access + * + ****************************************************************************/ + +static int netprocfs_opendir(FAR const char *relpath, + FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *level1; + + fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL"); + DEBUGASSERT(relpath && dir && !dir->u.procfs); + + /* The path refers to the 1st level sbdirectory. Allocate the level1 + * dirent structure. + */ + + level1 = (FAR struct netprocfs_level1_s *) + kmm_zalloc(sizeof(struct netprocfs_level1_s)); + + if (!level1) + { + fdbg("ERROR: Failed to allocate the level1 directory structure\n"); + return -ENOMEM; + } + + /* Initialze base structure components */ + + level1->base.level = 1; + level1->base.nentries = 1; + level1->base.index = 0; + + dir->u.procfs = (FAR void *) level1; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_closedir + * + * Description: Close the directory listing + * + ****************************************************************************/ + +static int netprocfs_closedir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *priv; + + DEBUGASSERT(dir && dir->u.procfs); + priv = dir->u.procfs; + + if (priv) + { + kmm_free(priv); + } + + dir->u.procfs = NULL; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_readdir + * + * Description: Read the next directory entry + * + ****************************************************************************/ + +static int netprocfs_readdir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *level1; + int index; + int ret; + + DEBUGASSERT(dir && dir->u.procfs); + level1 = dir->u.procfs; + + /* Have we reached the end of the directory */ + + index = level1->base.index; + if (index >= level1->base.nentries) + { + /* We signal the end of the directory by returning the special + * error -ENOENT + */ + + fvdbg("Entry %d: End of directory\n", index); + ret = -ENOENT; + } + + /* Currently only one element in the directory */ + + else + { + DEBUGASSERT(level1->base.level == 1); + DEBUGASSERT(level1->base.index <= 1); + + /* Copy the one supported directory entry */ + + dir->fd_dir.d_type = DTYPE_FILE; + strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1); + + /* Set up the next directory entry offset. NOTE that we could use the + * standard f_pos instead of our own private index. + */ + + level1->base.index = index + 1; + ret = OK; + } + + return ret; +} + +/**************************************************************************** + * Name: netprocfs_rewindir + * + * Description: Reset directory read to the first entry + * + ****************************************************************************/ + +static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir) +{ + FAR struct netprocfs_level1_s *priv; + + DEBUGASSERT(dir && dir->u.procfs); + priv = dir->u.procfs; + + priv->base.index = 0; + return OK; +} + +/**************************************************************************** + * Name: netprocfs_stat + * + * Description: Return information about a file or directory + * + ****************************************************************************/ + +static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf) +{ + /* "net" and "net/stat" are the only acceptable values for the relpath */ + + if (strcmp(relpath, "net") == 0) + { + buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; + } + else if (strcmp(relpath, "net/stat") == 0) + { + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; + } + else + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* File/directory size, access block size */ + + buf->st_size = 0; + buf->st_blksize = 512; + buf->st_blocks = 0; + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && + * !CONFIG_FS_PROCFS_EXCLUDE_NET */ diff --git a/net/net_procfs.c b/net/procfs/net_statistics.c similarity index 61% rename from net/net_procfs.c rename to net/procfs/net_statistics.c index 7b9ff3f48a..e6e977474c 100644 --- a/net/net_procfs.c +++ b/net/procfs/net_statistics.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/net_procfs.c + * net/procfs/net_statisticsc * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -40,76 +40,22 @@ #include #include -#include -#include - -#include -#include #include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include #include -#include - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Determines the size of an intermediate buffer that must be large enough - * to handle the longest line generated by this logic. - */ - -#define NET_LINELEN 64 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This enumeration identifies all of the thread attributes that can be - * accessed via the procfs file system. - */ - -/* This structure describes one open "file" */ - -struct netprocfs_file_s -{ - struct procfs_file_s base; /* Base open file structure */ - uint8_t lineno; /* Line number */ - uint8_t linesize; /* Number of valid characters in line[] */ - uint8_t offset; /* Offset to first valid character in line[] */ - char line[NET_LINELEN]; /* Pre-allocated buffer for formatted lines */ -}; - -/* Level 1 is the directory of attributes */ - -struct netprocfs_level1_s -{ - struct procfs_dir_priv_s base; /* Base directory private data */ -}; +#include "procfs/procfs.h" -/* Line generating function type */ - -typedef int (*linegen_t)(FAR struct netprocfs_file_s *netfile); +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_NET) && defined(CONFIG_NET_STATISTICS) /**************************************************************************** * Private Function Prototypes ****************************************************************************/ /* Line generating functions */ -#ifdef CONFIG_NET_STATISTICS static int netprocfs_header(FAR struct netprocfs_file_s *netfile); static int netprocfs_received(FAR struct netprocfs_file_s *netfile); static int netprocfs_dropped(FAR struct netprocfs_file_s *netfile); @@ -129,26 +75,6 @@ static int netprocfs_sent(FAR struct netprocfs_file_s *netfile); #ifdef CONFIG_NET_TCP static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile); #endif /* CONFIG_NET_TCP */ -#endif /* CONFIG_NET_STATISTICS */ - -/* File system methods */ - -static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); -static int netprocfs_close(FAR struct file *filep); -static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); - -static int netprocfs_dup(FAR const struct file *oldp, - FAR struct file *newp); - -static int netprocfs_opendir(FAR const char *relpath, - FAR struct fs_dirent_s *dir); -static int netprocfs_closedir(FAR struct fs_dirent_s *dir); -static int netprocfs_readdir(FAR struct fs_dirent_s *dir); -static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir); - -static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** * Private Data @@ -156,7 +82,6 @@ static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf); /* Line generating functions */ -#ifdef CONFIG_NET_STATISTICS static const linegen_t g_linegen[] = { netprocfs_header, @@ -187,32 +112,6 @@ static const linegen_t g_linegen[] = }; #define NSTAT_LINES (sizeof(g_linegen) / sizeof(linegen_t)) -#endif /* CONFIG_NET_STATISTICS */ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* See include/nutts/fs/procfs.h - * We use the old-fashioned kind of initializers so that this will compile - * with any compiler. - */ - -const struct procfs_operations net_procfsoperations = -{ - netprocfs_open, /* open */ - netprocfs_close, /* close */ - netprocfs_read, /* read */ - NULL, /* write */ - netprocfs_dup, /* dup */ - - netprocfs_opendir, /* opendir */ - netprocfs_closedir, /* closedir */ - netprocfs_readdir, /* readdir */ - netprocfs_rewinddir, /* rewinddir */ - - netprocfs_stat /* stat */ -}; /**************************************************************************** * Private Functions @@ -533,90 +432,34 @@ static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile) #endif /* CONFIG_NET_STATISTICS && CONFIG_NET_TCP */ /**************************************************************************** - * Name: netprocfs_open - ****************************************************************************/ - -static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) -{ - FAR struct netprocfs_file_s *priv; - - fvdbg("Open '%s'\n", relpath); - - /* PROCFS is read-only. Any attempt to open with any kind of write - * access is not permitted. - * - * REVISIT: Write-able proc files could be quite useful. - */ - - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && - (net_procfsoperations.write == NULL)) - { - fdbg("ERROR: Only O_RDONLY supported\n"); - return -EACCES; - } - - /* "net/stat" is the only acceptable value for the relpath */ - - if (strcmp(relpath, "net/stat") != 0) - { - fdbg("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - /* Allocate a container to hold the task and attribute selection */ - - priv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); - if (!priv) - { - fdbg("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* Save the index as the open-specific state in filep->f_priv */ - - filep->f_priv = (FAR void *)priv; - return OK; -} - -/**************************************************************************** - * Name: netprocfs_close + * Public Functions ****************************************************************************/ -static int netprocfs_close(FAR struct file *filep) -{ - FAR struct netprocfs_file_s *priv; - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct netprocfs_file_s *)filep->f_priv; - DEBUGASSERT(priv); - - /* Release the file attributes structure */ - - kmm_free(priv); - filep->f_priv = NULL; - return OK; -} - /**************************************************************************** - * Name: netprocfs_read + * Name: net_readstats + * + * Description: + * Read and format network layer statistics. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which network status will be + * returned. + * bulen - The size in bytes of the user provided buffer. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * ****************************************************************************/ -static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) +ssize_t net_readstats(FAR struct netprocfs_file_s *priv, FAR char *buffer, + size_t buflen) { -#ifdef CONFIG_NET_STATISTICS - FAR struct netprocfs_file_s *priv; size_t xfrsize; ssize_t nreturned; - fvdbg("buffer=%p buflen=%d\n", buffer, (int)buflen); - - /* Recover our private data from the struct file instance */ - - priv = (FAR struct netprocfs_file_s *)filep->f_priv; - DEBUGASSERT(priv); + fvdbg("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen); /* Is there line data already buffered? */ @@ -687,226 +530,8 @@ static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, nreturned += xfrsize; } - /* Update the file offset */ - - if (nreturned > 0) - { - filep->f_pos += nreturned; - } - return nreturned; -#else - return 0; -#endif -} - -/**************************************************************************** - * Name: netprocfs_dup - * - * Description: - * Duplicate open file data in the new file structure. - * - ****************************************************************************/ - -static int netprocfs_dup(FAR const struct file *oldp, FAR struct file *newp) -{ - FAR struct netprocfs_file_s *oldpriv; - FAR struct netprocfs_file_s *newpriv; - - fvdbg("Dup %p->%p\n", oldp, newp); - - /* Recover our private data from the old struct file instance */ - - oldpriv = (FAR struct netprocfs_file_s *)oldp->f_priv; - DEBUGASSERT(oldpriv); - - /* Allocate a new container to hold the task and attribute selection */ - - newpriv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); - if (!newpriv) - { - fdbg("ERROR: Failed to allocate file attributes\n"); - return -ENOMEM; - } - - /* The copy the file attribtes from the old attributes to the new */ - - memcpy(newpriv, oldpriv, sizeof(struct netprocfs_file_s)); - - /* Save the new attributes in the new file structure */ - - newp->f_priv = (FAR void *)newpriv; - return OK; } -/**************************************************************************** - * Name: netprocfs_opendir - * - * Description: - * Open a directory for read access - * - ****************************************************************************/ - -static int netprocfs_opendir(FAR const char *relpath, - FAR struct fs_dirent_s *dir) -{ - FAR struct netprocfs_level1_s *level1; - - fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL"); - DEBUGASSERT(relpath && dir && !dir->u.procfs); - - /* The path refers to the 1st level sbdirectory. Allocate the level1 - * dirent structure. - */ - - level1 = (FAR struct netprocfs_level1_s *) - kmm_zalloc(sizeof(struct netprocfs_level1_s)); - - if (!level1) - { - fdbg("ERROR: Failed to allocate the level1 directory structure\n"); - return -ENOMEM; - } - - /* Initialze base structure components */ - - level1->base.level = 1; - level1->base.nentries = 1; - level1->base.index = 0; - - dir->u.procfs = (FAR void *) level1; - return OK; -} - -/**************************************************************************** - * Name: netprocfs_closedir - * - * Description: Close the directory listing - * - ****************************************************************************/ - -static int netprocfs_closedir(FAR struct fs_dirent_s *dir) -{ - FAR struct netprocfs_level1_s *priv; - - DEBUGASSERT(dir && dir->u.procfs); - priv = dir->u.procfs; - - if (priv) - { - kmm_free(priv); - } - - dir->u.procfs = NULL; - return OK; -} - -/**************************************************************************** - * Name: netprocfs_readdir - * - * Description: Read the next directory entry - * - ****************************************************************************/ - -static int netprocfs_readdir(FAR struct fs_dirent_s *dir) -{ - FAR struct netprocfs_level1_s *level1; - int index; - int ret; - - DEBUGASSERT(dir && dir->u.procfs); - level1 = dir->u.procfs; - - /* Have we reached the end of the directory */ - - index = level1->base.index; - if (index >= level1->base.nentries) - { - /* We signal the end of the directory by returning the special - * error -ENOENT - */ - - fvdbg("Entry %d: End of directory\n", index); - ret = -ENOENT; - } - - /* Currently only one element in the directory */ - - else - { - DEBUGASSERT(level1->base.level == 1); - DEBUGASSERT(level1->base.index <= 1); - - /* Copy the one supported directory entry */ - - dir->fd_dir.d_type = DTYPE_FILE; - strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1); - - /* Set up the next directory entry offset. NOTE that we could use the - * standard f_pos instead of our own private index. - */ - - level1->base.index = index + 1; - ret = OK; - } - - return ret; -} - -/**************************************************************************** - * Name: netprocfs_rewindir - * - * Description: Reset directory read to the first entry - * - ****************************************************************************/ - -static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir) -{ - FAR struct netprocfs_level1_s *priv; - - DEBUGASSERT(dir && dir->u.procfs); - priv = dir->u.procfs; - - priv->base.index = 0; - return OK; -} - -/**************************************************************************** - * Name: netprocfs_stat - * - * Description: Return information about a file or directory - * - ****************************************************************************/ - -static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf) -{ - /* "net" and "net/stat" are the only acceptable values for the relpath */ - - if (strcmp(relpath, "net") == 0) - { - buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; - } - else if (strcmp(relpath, "net/stat") == 0) - { - buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; - } - else - { - fdbg("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; - } - - /* File/directory size, access block size */ - - buf->st_size = 0; - buf->st_blksize = 512; - buf->st_blocks = 0; - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */ +#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && + * !CONFIG_FS_PROCFS_EXCLUDE_NET */ diff --git a/net/procfs/procfs.h b/net/procfs/procfs.h new file mode 100644 index 0000000000..c6f059fb8d --- /dev/null +++ b/net/procfs/procfs.h @@ -0,0 +1,134 @@ +/**************************************************************************** + * net/procfs/procfs.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NET_PROCFS_PROCFS_H +#define __NET_PROCFS_PROCFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_NET) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Determines the size of an intermediate buffer that must be large enough + * to handle the longest line generated by this logic. + */ + +#define NET_LINELEN 64 + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* This enumeration identifies all of the thread attributes that can be + * accessed via the procfs file system. + */ + +/* This structure describes one open "file" */ + +struct netprocfs_file_s +{ + struct procfs_file_s base; /* Base open file structure */ + uint8_t lineno; /* Line number */ + uint8_t linesize; /* Number of valid characters in line[] */ + uint8_t offset; /* Offset to first valid character in line[] */ + char line[NET_LINELEN]; /* Pre-allocated buffer for formatted lines */ +}; + +/* Level 1 is the directory of attributes */ + +struct netprocfs_level1_s +{ + struct procfs_dir_priv_s base; /* Base directory private data */ +}; + +/* Line generating function type */ + +typedef int (*linegen_t)(FAR struct netprocfs_file_s *netfile); + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: net_readstats + * + * Description: + * Read and format network layer statistics. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which network status will be + * returned. + * bulen - The size in bytes of the user provided buffer. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_STATISTICS +ssize_t net_readstats(FAR struct netprocfs_file_s *priv, FAR char *buffer, + size_t buflen); +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_NET */ +#endif /* __NET_PROCFS_PROCFS_H */ -- GitLab From eb8668b0f7a4041a2fe35856d399d50a9c229144 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 27 Nov 2015 16:39:14 -0600 Subject: [PATCH 382/858] net/: Add procfs support for network device status --- fs/procfs/fs_skeleton.c | 6 +- include/nuttx/net/net.h | 4 +- net/netdev/Make.defs | 6 +- net/netdev/netdev.h | 24 ++ net/netdev/netdev_findbyaddr.c | 16 -- net/netdev/netdev_findbyindex.c | 101 +++++++ net/netdev/netdev_findbyname.c | 20 -- net/procfs/Make.defs | 2 +- net/procfs/net_procfs.c | 292 ++++++++++++++++--- net/procfs/net_statistics.c | 84 +----- net/procfs/netdev_statistics.c | 481 ++++++++++++++++++++++++++++++++ net/procfs/procfs.h | 54 +++- 12 files changed, 931 insertions(+), 159 deletions(-) create mode 100644 net/netdev/netdev_findbyindex.c create mode 100644 net/procfs/netdev_statistics.c diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c index 11bc567fd8..052eb1f0f7 100644 --- a/fs/procfs/fs_skeleton.c +++ b/fs/procfs/fs_skeleton.c @@ -178,7 +178,7 @@ static int skel_open(FAR struct file *filep, FAR const char *relpath, return -EACCES; } - /* Allocate a container to hold the task and attribute selection */ + /* Allocate the open file structure */ priv = (FAR struct skel_file_s *)kmm_zalloc(sizeof(struct skel_file_s)); if (!priv) @@ -190,7 +190,9 @@ static int skel_open(FAR struct file *filep, FAR const char *relpath, /* TODO: Initialize the context specific data here */ - /* Save the index as the open-specific state in filep->f_priv */ + /* Save the open file structure as the open-specific state in + * filep->f_priv. + */ filep->f_priv = (FAR void *)priv; return OK; diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index e5995684cd..a5b2afc440 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -139,7 +139,7 @@ struct socketlist /* Callback from netdev_foreach() */ struct net_driver_s; /* Forward reference. Defined in nuttx/net/netdev.h */ -typedef int (*netdev_callback_t)(FAR struct net_driver_s *dev, void *arg); +typedef int (*netdev_callback_t)(FAR struct net_driver_s *dev, FAR void *arg); #ifdef CONFIG_NET_NOINTS /* Semaphore based locking for non-interrupt based logic. @@ -1130,7 +1130,7 @@ int netdev_unregister(FAR struct net_driver_s *dev); * ****************************************************************************/ -int netdev_foreach(netdev_callback_t callback, void *arg); +int netdev_foreach(netdev_callback_t callback, FAR void *arg); #undef EXTERN #ifdef __cplusplus diff --git a/net/netdev/Make.defs b/net/netdev/Make.defs index 955745945c..c5262a1aac 100644 --- a/net/netdev/Make.defs +++ b/net/netdev/Make.defs @@ -36,9 +36,9 @@ # Support for operations on network devices NETDEV_CSRCS += netdev_register.c netdev_ioctl.c netdev_txnotify.c -NETDEV_CSRCS += netdev_findbyname.c netdev_findbyaddr.c netdev_count.c -NETDEV_CSRCS += netdev_foreach.c netdev_unregister.c netdev_carrier.c -NETDEV_CSRCS += netdev_default.c netdev_verify.c +NETDEV_CSRCS += netdev_findbyname.c netdev_findbyaddr.c netdev_findbyindex.c +NETDEV_CSRCS += netdev_count.c netdev_foreach.c netdev_unregister.c +NETDEV_CSRCS += netdev_carrier.c netdev_default.c netdev_verify.c ifeq ($(CONFIG_NET_RXAVAIL),y) NETDEV_CSRCS += netdev_rxnotify.c diff --git a/net/netdev/netdev.h b/net/netdev/netdev.h index 9e055effd0..4289dc561a 100644 --- a/net/netdev/netdev.h +++ b/net/netdev/netdev.h @@ -188,6 +188,30 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t ripaddr); #endif #endif +/**************************************************************************** + * Function: netdev_findbyindex + * + * Description: + * Find a previously registered network device by its position in the + * list of registered devices. NOTE that this function is not a safe way + * to enumerate network devices: There could be changes to the list of + * registered device causing a given index to be meaningless (unless, of + * course, the caller keeps the network locked). + * + * Parameters: + * index - the index of the interface to file + * + * Returned Value: + * Pointer to driver on success; NULL on failure. This function can only + * fail if there are fewer registered interfaces than could be indexed. + * + * Assumptions: + * Called from normal user mode + * + ****************************************************************************/ + +FAR struct net_driver_s *netdev_findbyindex(int index); + /**************************************************************************** * Function: netdev_default * diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index 1f752a2c64..54cf1cee35 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -55,22 +55,6 @@ #include "route/route.h" #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/netdev/netdev_findbyindex.c b/net/netdev/netdev_findbyindex.c new file mode 100644 index 0000000000..74ccba04c8 --- /dev/null +++ b/net/netdev/netdev_findbyindex.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * net/netdev/netdev_findbyindex.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include + +#include + +#include "utils/utils.h" +#include "netdev/netdev.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: netdev_findbyindex + * + * Description: + * Find a previously registered network device by its position in the + * list of registered devices. NOTE that this function is not a safe way + * to enumerate network devices: There could be changes to the list of + * registered device causing a given index to be meaningless (unless, of + * course, the caller keeps the network locked). + * + * Parameters: + * index - the index of the interface to file + * + * Returned Value: + * Pointer to driver on success; NULL on failure. This function can only + * fail if there are fewer registered interfaces than could be indexed. + * + * Assumptions: + * Called from normal user mode + * + ****************************************************************************/ + +FAR struct net_driver_s *netdev_findbyindex(int index) +{ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct net_driver_s *dev; + net_lock_t save; + int i; + + save = net_lock(); + for (i = 0, dev = g_netdevices; dev; i++, dev = dev->flink) + { + if (i == index) + { + net_unlock(save); + return dev; + } + } + + net_unlock(save); + return NULL; +#else + return (index == 0) ? g_netdevices : NULL; +#endif +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/net/netdev/netdev_findbyname.c b/net/netdev/netdev_findbyname.c index 93f90a9aab..04c20b27c8 100644 --- a/net/netdev/netdev_findbyname.c +++ b/net/netdev/netdev_findbyname.c @@ -48,26 +48,6 @@ #include "utils/utils.h" #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/procfs/Make.defs b/net/procfs/Make.defs index 49cae7c730..90cef533d2 100644 --- a/net/procfs/Make.defs +++ b/net/procfs/Make.defs @@ -39,7 +39,7 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) ifeq ($(CONFIG_FS_PROCFS),y) ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_NET),y) -NET_CSRCS += net_procfs.c +NET_CSRCS += net_procfs.c netdev_statistics.c # General network statistics diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c index 0c2bd6025f..f65cf040df 100644 --- a/net/procfs/net_procfs.c +++ b/net/procfs/net_procfs.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,9 @@ #include #include #include +#include +#include "netdev/netdev.h" #include "procfs/procfs.h" #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ @@ -64,6 +67,7 @@ /**************************************************************************** * Private Function Prototypes ****************************************************************************/ + /* File system methods */ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, @@ -120,6 +124,7 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, int oflags, mode_t mode) { FAR struct netprocfs_file_s *priv; + FAR struct net_driver_s *dev; fvdbg("Open '%s'\n", relpath); @@ -136,15 +141,48 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, return -EACCES; } - /* "net/stat" is the only acceptable value for the relpath */ + /* "net/stat" is an acceptable value for the relpath only if network layer + * statistics are enabled. + */ - if (strcmp(relpath, "net/stat") != 0) +#ifdef CONFIG_NET_STATISTICS + if (strcmp(relpath, "net/stat") == 0) { - fdbg("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; + /* A NULL network device reference is a clue that we are processing + * the network statistics file. + */ + + dev = NULL; + } + else +#endif + { + FAR char *devname; + FAR char *copy; + + /* Otherwise, we need to search the list of registered network devices + * to determine if the name corresponds to a network device. + */ + + copy = strdup(relpath); + if (copy == NULL) + { + fdbg("ERROR: strdup failed\n"); + return -ENOMEM; + } + + devname = basename(copy); + dev = netdev_findbyname(devname); + kmm_free(copy); + + if (dev == NULL) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } } - /* Allocate a container to hold the task and attribute selection */ + /* Allocate the open file structure */ priv = (FAR struct netprocfs_file_s *)kmm_zalloc(sizeof(struct netprocfs_file_s)); if (!priv) @@ -153,7 +191,13 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, return -ENOMEM; } - /* Save the index as the open-specific state in filep->f_priv */ + /* Initialize the open-file structure */ + + priv->dev = dev; + + /* Save the open file structure as the open-specific state in + * filep->f_priv. + */ filep->f_priv = (FAR void *)priv; return OK; @@ -186,7 +230,6 @@ static int netprocfs_close(FAR struct file *filep) static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { -#ifdef CONFIG_NET_STATISTICS FAR struct netprocfs_file_s *priv; ssize_t nreturned; @@ -197,9 +240,24 @@ static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, priv = (FAR struct netprocfs_file_s *)filep->f_priv; DEBUGASSERT(priv); - /* Read the network layer statistics */ +#ifdef CONFIG_NET_STATISTICS + /* A NULL device structure reference is the key that we are showing the + * network statistics. + */ + + if (priv->dev == NULL) + { + /* Show the network layer statistics */ + + nreturned = netprocfs_read_netstats(priv, buffer, buflen); + } + else +#endif + { + /* Otherwise, we are showing device-specific statistics */ - nreturned = net_readstats(priv, buffer, buflen); + nreturned = netprocfs_read_devstats(priv, buffer, buflen); + } /* Update the file offset */ @@ -209,9 +267,6 @@ static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, } return nreturned; -#else - return 0; -#endif } /**************************************************************************** @@ -265,10 +320,24 @@ static int netprocfs_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir) { FAR struct netprocfs_level1_s *level1; + int ndevs; fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL"); DEBUGASSERT(relpath && dir && !dir->u.procfs); + /* "net" is the only value of relpath that is a directory */ + + if (strcmp(relpath, "net") != 0) + { + /* REVISIT: We really need to check if the relpath refers to a network + * device. In that case, we need to return -ENOTDIR. Otherwise, we + * should return -ENOENT. + */ + + fdbg("ERROR: Bad relpath: %s\n", relpath); + return -ENOTDIR; + } + /* The path refers to the 1st level sbdirectory. Allocate the level1 * dirent structure. */ @@ -282,10 +351,18 @@ static int netprocfs_opendir(FAR const char *relpath, return -ENOMEM; } + /* Count the number of network devices */ + + ndevs = netdev_count(); + /* Initialze base structure components */ level1->base.level = 1; - level1->base.nentries = 1; +#ifdef CONFIG_NET_STATISTICS + level1->base.nentries = ndevs + 1; +#else + level1->base.nentries = ndevs; +#endif level1->base.index = 0; dir->u.procfs = (FAR void *) level1; @@ -325,46 +402,65 @@ static int netprocfs_closedir(FAR struct fs_dirent_s *dir) static int netprocfs_readdir(FAR struct fs_dirent_s *dir) { FAR struct netprocfs_level1_s *level1; + FAR struct net_driver_s *dev; int index; - int ret; DEBUGASSERT(dir && dir->u.procfs); level1 = dir->u.procfs; + DEBUGASSERT(level1->base.level == 1); /* Have we reached the end of the directory */ index = level1->base.index; + DEBUGASSERT(index <= level1->base.nentries); + if (index >= level1->base.nentries) { /* We signal the end of the directory by returning the special - * error -ENOENT + * error -ENOENT. */ fvdbg("Entry %d: End of directory\n", index); - ret = -ENOENT; + return -ENOENT; } - /* Currently only one element in the directory */ - - else +#ifdef CONFIG_NET_STATISTICS + else if (index == 0) { - DEBUGASSERT(level1->base.level == 1); - DEBUGASSERT(level1->base.index <= 1); - - /* Copy the one supported directory entry */ + /* Copy the network statistics directory entry */ dir->fd_dir.d_type = DTYPE_FILE; strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1); + } + else +#endif + { + int devndx = index; - /* Set up the next directory entry offset. NOTE that we could use the - * standard f_pos instead of our own private index. +#ifdef CONFIG_NET_STATISTICS + /* Subtract one to account for index == 0 which is used for network + * status. */ - level1->base.index = index + 1; - ret = OK; + devndx--; +#endif + + /* Find the device corresponding to this device index */ + + dev = netdev_findbyindex(devndx); + + /* Copy the device statistics file entry */ + + dir->fd_dir.d_type = DTYPE_FILE; + strncpy(dir->fd_dir.d_name, dev->d_ifname, NAME_MAX + 1); } - return ret; + /* Set up the next directory entry offset. NOTE that we could use the + * standard f_pos instead of our own private index. + */ + + level1->base.index = index + 1; + return OK; } /**************************************************************************** @@ -394,26 +490,55 @@ static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir) static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf) { - /* "net" and "net/stat" are the only acceptable values for the relpath */ + /* Check for the directory "net" */ if (strcmp(relpath, "net") == 0) { buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR; } - else if (strcmp(relpath, "net/stat") == 0) + else +#ifdef CONFIG_NET_STATISTICS + /* Check for network statistics "net/stat" */ + + if (strcmp(relpath, "net/stat") == 0) { buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; } else +#endif { - fdbg("ERROR: relpath is '%s'\n", relpath); - return -ENOENT; + FAR struct net_driver_s *dev; + FAR char *devname; + FAR char *copy; + + /* Otherwise, we need to search the list of registered network devices + * to determine if the name corresponds to a network device. + */ + + copy = strdup(relpath); + if (copy == NULL) + { + fdbg("ERROR: strdup failed\n"); + return -ENOMEM; + } + + devname = basename(copy); + dev = netdev_findbyname(devname); + kmm_free(copy); + + if (dev == NULL) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; } /* File/directory size, access block size */ buf->st_size = 0; - buf->st_blksize = 512; + buf->st_blksize = 0; buf->st_blocks = 0; return OK; @@ -423,5 +548,106 @@ static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: netprocfs_read_linegen + * + * Description: + * Read and format procfs data using a line generation table. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which device status will be + * returned. + * buflen - The size in bytes of the user provided buffer. + * gentab - Table of line generation functions + * nelems - The number of elements in the table + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +ssize_t netprocfs_read_linegen(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen, + FAR const linegen_t *gentab, int nelems) +{ + size_t xfrsize; + ssize_t nreturned; + + fvdbg("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen); + + /* Is there line data already buffered? */ + + nreturned = 0; + if (priv->linesize > 0) + { + /* Yes, how much can we transfer now? */ + + xfrsize = priv->linesize; + if (xfrsize > buflen) + { + xfrsize = buflen; + } + + /* Transfer the data to the user buffer */ + + memcpy(buffer, &priv->line[priv->offset], xfrsize); + + /* Update pointers, sizes, and offsets */ + + buffer += xfrsize; + buflen -= xfrsize; + + priv->linesize -= xfrsize; + priv->offset += xfrsize; + nreturned = xfrsize; + } + + /* Loop until the user buffer is full or until all of the network + * statistics have been transferred. At this point we know that + * either: + * + * 1. The user buffer is full, and/or + * 2. All of the current line data has been transferred. + */ + + while (buflen > 0 && priv->lineno < nelems) + { + int len; + + /* Read the next line into the working buffer */ + + len = gentab[priv->lineno](priv); + + /* Update line-related information */ + + priv->lineno++; + priv->linesize = len; + priv->offset = 0; + + /* Transfer data to the user buffer */ + + xfrsize = priv->linesize; + if (xfrsize > buflen) + { + xfrsize = buflen; + } + + memcpy(buffer, &priv->line[priv->offset], xfrsize); + + /* Update pointers, sizes, and offsets */ + + buffer += xfrsize; + buflen -= xfrsize; + + priv->linesize -= xfrsize; + priv->offset += xfrsize; + nreturned += xfrsize; + } + + return nreturned; +} + #endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && * !CONFIG_FS_PROCFS_EXCLUDE_NET */ diff --git a/net/procfs/net_statistics.c b/net/procfs/net_statistics.c index e6e977474c..df35f4a165 100644 --- a/net/procfs/net_statistics.c +++ b/net/procfs/net_statistics.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/procfs/net_statisticsc + * net/procfs/net_statistics.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -436,7 +436,7 @@ static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile) ****************************************************************************/ /**************************************************************************** - * Name: net_readstats + * Name: netprocfs_read_netstats * * Description: * Read and format network layer statistics. @@ -453,84 +453,10 @@ static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile) * ****************************************************************************/ -ssize_t net_readstats(FAR struct netprocfs_file_s *priv, FAR char *buffer, - size_t buflen) +ssize_t netprocfs_read_netstats(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen) { - size_t xfrsize; - ssize_t nreturned; - - fvdbg("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen); - - /* Is there line data already buffered? */ - - nreturned = 0; - if (priv->linesize > 0) - { - /* Yes, how much can we transfer now? */ - - xfrsize = priv->linesize; - if (xfrsize > buflen) - { - xfrsize = buflen; - } - - /* Transfer the data to the user buffer */ - - memcpy(buffer, &priv->line[priv->offset], xfrsize); - - /* Update pointers, sizes, and offsets */ - - buffer += xfrsize; - buflen -= xfrsize; - - priv->linesize -= xfrsize; - priv->offset += xfrsize; - nreturned = xfrsize; - } - - /* Loop until the user buffer is full or until all of the network - * statistics have been transferred. At this point we know that - * either: - * - * 1. The user buffer is full, and/or - * 2. All of the current line data has been transferred. - */ - - while (buflen > 0 && priv->lineno < NSTAT_LINES) - { - int len; - - /* Read the next line into the working buffer */ - - len = g_linegen[priv->lineno](priv); - - /* Update line-related information */ - - priv->lineno++; - priv->linesize = len; - priv->offset = 0; - - /* Transfer data to the user buffer */ - - xfrsize = priv->linesize; - if (xfrsize > buflen) - { - xfrsize = buflen; - } - - memcpy(buffer, &priv->line[priv->offset], xfrsize); - - /* Update pointers, sizes, and offsets */ - - buffer += xfrsize; - buflen -= xfrsize; - - priv->linesize -= xfrsize; - priv->offset += xfrsize; - nreturned += xfrsize; - } - - return nreturned; + return netprocfs_read_linegen(priv, buffer, buflen, g_linegen, NSTAT_LINES); } #endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c new file mode 100644 index 0000000000..b81741a409 --- /dev/null +++ b/net/procfs/netdev_statistics.c @@ -0,0 +1,481 @@ +/**************************************************************************** + * net/procfs/netdev_statistics.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include + +#include "netdev/netdev.h" +#include "procfs/procfs.h" + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_NET) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile); +static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile); + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_rxstatistics_header(FAR struct netprocfs_file_s *netfile); +static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile); +static int netprocfs_rxpackets_header(FAR struct netprocfs_file_s *netfile); +static int netprocfs_rxpackets(FAR struct netprocfs_file_s *netfile); +static int netprocfs_txstatistics_header(FAR struct netprocfs_file_s *netfile); +static int netprocfs_txstatistics(FAR struct netprocfs_file_s *netfile); +static int netprocfs_errors(FAR struct netprocfs_file_s *netfile); +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Line generating functions */ + +static const linegen_t g_linegen[] = +{ + netprocfs_linklayer, + netprocfs_ipaddresses +#ifdef CONFIG_NETDEV_STATISTICS + , netprocfs_rxstatistics_header, + netprocfs_rxstatistics, + netprocfs_rxpackets_header, + netprocfs_rxpackets, + netprocfs_txstatistics_header, + netprocfs_txstatistics, + netprocfs_errors +#endif /* CONFIG_NETDEV_STATISTICS */ +}; + +#define NSTAT_LINES (sizeof(g_linegen) / sizeof(linegen_t)) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netprocfs_linklayer + ****************************************************************************/ + +static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) +{ + FAR struct net_driver_s *dev; + FAR const char *status; + int len = 0; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + + /* Get the interface status: RUNNING, UP, or DOWN */ + + if ((dev->d_flags & IFF_RUNNING) != 0) + { + status = "RUNNING"; + } + else if ((dev->d_flags & IFF_UP) != 0) + { + status = "UP"; + } + else + { + status = "DOWN"; + } + +#if defined(CONFIG_NET_MULTILINK) + /* If there are multiple link types being supported, then selected the + * output appropriate for the link type associated with this device. + */ + + switch (dev->d_lltype) + { +#ifdef CONFIG_NET_ETHERNET + case NET_LL_ETHERNET: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:Ethernet HWaddr %s", + dev->d_ifname, ether_ntoa(&dev->d_mac)); + break; +#endif + +#ifdef CONFIG_NET_LOOPBACK + case NET_LL_LOOPBACK: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:Local Loopback", + dev->d_ifname); + break; +#endif + +#ifdef CONFIG_NET_SLIP + case NET_LL_SLIP: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:SLIP", dev->d_ifname); + break; +#endif + +#ifdef CONFIG_NET_PPP + case NET_LL_PPP: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:P-t-P", dev->d_ifname); + break; +#endif + +#ifdef CONFIG_NET_TUN + case NET_LL_TUN: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:TUN", dev->d_ifname); + break; +#endif + + default: + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:UNSPEC", dev->d_ifname); + } + + len += snprintf(&netfile->line[len], NET_LINELEN - len, + " at %s\n", status); + +#elif defined(CONFIG_NET_ETHERNET) + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:Ethernet HWaddr %s at %s\n", + dev->d_ifname, ether_ntoa(&dev->d_mac), status); + +#elif defined(CONFIG_NET_LOOPBACK) + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:Local Loopback at %s\n", + dev->d_ifname, status); + +#elif defined(CONFIG_NET_SLIP) + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:SLIP at %s\n", + dev->d_ifname, status); + +#elif defined(CONFIG_NET_PPP) + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:P-t-P at %s\n", + dev->d_ifname, status); + +#elif defined(CONFIG_NET_TUN) + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:TUN at %s\n", + dev->d_ifname, status); +#endif + + return len; +} + +/**************************************************************************** + * Name: netprocfs_ipaddresses + ****************************************************************************/ + +static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) +{ + FAR struct net_driver_s *dev; +#ifdef CONFIG_NET_IPv4 + struct in_addr addr; +#endif +#ifdef CONFIG_NET_IPv6 + char addrstr[INET6_ADDRSTRLEN]; + uint8_t preflen; +#endif + int len = 0; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + +#ifdef CONFIG_NET_IPv4 + /* Show the IPv4 address */ + + addr.s_addr = dev->d_ipaddr; + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "\tinet addr:%s ", inet_ntoa(addr)); + + /* Show the IPv4 default router address */ + + addr.s_addr = dev->d_draddr; + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "DRaddr:%s ", inet_ntoa(addr)); + + /* Show the IPv4 network mask */ + + addr.s_addr = dev->d_netmask; + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "Mask:%s\n", inet_ntoa(addr)); + +#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) + netlib_get_ipv4dnsaddr(&addr); + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "\tDNSaddr:%s\n", inet_ntoa(addr)); +#endif +#endif + +#ifdef CONFIG_NET_IPv6 + /* Convert the 128 network mask to a human friendly prefix length */ + + preflen = netlib_ipv6netmask2prefix(dev->d_ipv6netmask); + + /* Show the assigned IPv6 address */ + + if (inet_ntop(AF_INET6, dev->d_ipv6addr, addrstr, INET6_ADDRSTRLEN)) + { + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "\tinet6 addr:%s/%d\n", addrstr, preflen); + } + + /* REVISIT: Show the IPv6 default router address */ + + if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN)) + { + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); + } + +#if defined(CONFIG_NSH_DHCPCv6) || defined(CONFIG_NSH_DNS) +# warning Missing logic +#endif +#endif + + len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); + return len; +} + +/**************************************************************************** + * Name: netprocfs_rxstatistics_header + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_rxstatistics_header(FAR struct netprocfs_file_s *netfile) +{ + DEBUGASSERT(netfile != NULL); + return snprintf(netfile->line, NET_LINELEN , "\tRX: %-8s %-8s %-8s\n", + "Received", "Fragment", "Errors"); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_rxstatistics + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile) +{ + FAR struct netdev_statistics_s *stats; + FAR struct net_driver_s *dev; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + stats = &dev->d_statistics; + + return snprintf(netfile->line, NET_LINELEN, "\t %08lx %08lx %08lx\n", + (unsigned long)stats->rx_packets, + (unsigned long)stats->rx_fragments, + (unsigned long)stats->rx_errors); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_rxpackets_header + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_rxpackets_header(FAR struct netprocfs_file_s *netfile) +{ + FAR char *fmt; + + DEBUGASSERT(netfile != NULL); + + fmt = "\t " +#ifdef CONFIG_NET_IPv4 + "%-8s " +#endif +#ifdef CONFIG_NET_IPv6 + "%-8s " +#endif +#ifdef CONFIG_NET_ARP + "%-8s " +#endif + "%-8s\n"; + + return snprintf(netfile->line, NET_LINELEN, fmt +#ifdef CONFIG_NET_IPv4 + , "IPv4" +#endif +#ifdef CONFIG_NET_IPv6 + , "IPv6" +#endif +#ifdef CONFIG_NET_ARP + , "ARP" +#endif + , "Dropped"); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_rxpackets + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_rxpackets(FAR struct netprocfs_file_s *netfile) +{ + FAR struct netdev_statistics_s *stats; + FAR struct net_driver_s *dev; + FAR char *fmt; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + stats = &dev->d_statistics; + + fmt = "\t " +#ifdef CONFIG_NET_IPv4 + "%08lx " +#endif +#ifdef CONFIG_NET_IPv6 + "%08lx " +#endif +#ifdef CONFIG_NET_ARP + "%08lx " +#endif + "%08lx\n"; + + return snprintf(netfile->line, NET_LINELEN, fmt +#ifdef CONFIG_NET_IPv4 + , (unsigned long)stats->rx_ipv4 +#endif +#ifdef CONFIG_NET_IPv6 + , (unsigned long)stats->rx_ipv6 +#endif +#ifdef CONFIG_NET_ARP + , (unsigned long)stats->rx_arp +#endif + , (unsigned long)stats->rx_dropped); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_txstatistics_header + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_txstatistics_header(FAR struct netprocfs_file_s *netfile) +{ + DEBUGASSERT(netfile != NULL); + + return snprintf(netfile->line, NET_LINELEN, "\tTX: %-8s %-8s %-8s %-8s\n", + "Queued", "Sent", "Erorts", "Timeouts"); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_txstatistics + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_txstatistics(FAR struct netprocfs_file_s *netfile) +{ + FAR struct netdev_statistics_s *stats; + FAR struct net_driver_s *dev; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + stats = &dev->d_statistics; + + return snprintf(netfile->line, NET_LINELEN, "\t %08lx %08lx %08lx %08lx\n", + (unsigned long)stats->tx_packets, + (unsigned long)stats->tx_done, + (unsigned long)stats->tx_errors, + (unsigned long)stats->tx_timeouts); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Name: netprocfs_errors + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_STATISTICS +static int netprocfs_errors(FAR struct netprocfs_file_s *netfile) +{ + FAR struct netdev_statistics_s *stats; + FAR struct net_driver_s *dev; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + stats = &dev->d_statistics; + + return snprintf(netfile->line, NET_LINELEN , "\tTotal Errors: %08x\n\n", + (unsigned long)stats->errors); +} +#endif /* CONFIG_NETDEV_STATISTICS */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netprocfs_read_devstats + * + * Description: + * Read and format network device statistics. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which device status will be + * returned. + * bulen - The size in bytes of the user provided buffer. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +ssize_t netprocfs_read_devstats(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen) +{ + return netprocfs_read_linegen(priv, buffer, buflen, g_linegen, NSTAT_LINES); +} + +#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && + * !CONFIG_FS_PROCFS_EXCLUDE_NET */ diff --git a/net/procfs/procfs.h b/net/procfs/procfs.h index c6f059fb8d..feba657a0d 100644 --- a/net/procfs/procfs.h +++ b/net/procfs/procfs.h @@ -66,9 +66,11 @@ /* This structure describes one open "file" */ +struct net_driver_s; /* Forward reference */ struct netprocfs_file_s { struct procfs_file_s base; /* Base open file structure */ + FAR struct net_driver_s *dev; /* Current network device */ uint8_t lineno; /* Line number */ uint8_t linesize; /* Number of valid characters in line[] */ uint8_t offset; /* Offset to first valid character in line[] */ @@ -80,6 +82,7 @@ struct netprocfs_file_s struct netprocfs_level1_s { struct procfs_dir_priv_s base; /* Base directory private data */ + char name[NAME_MAX + 1]; /* Name of last node visited */ }; /* Line generating function type */ @@ -103,7 +106,31 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: net_readstats + * Name: netprocfs_read_linegen + * + * Description: + * Read and format procfs data using a line generation table. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which device status will be + * returned. + * buflen - The size in bytes of the user provided buffer. + * gentab - Table of line generation functions + * nelems - The number of elements in the table + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +ssize_t netprocfs_read_linegen(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen, + FAR const linegen_t *gentab, int nelems); + +/**************************************************************************** + * Name: netprocfs_read_netstats * * Description: * Read and format network layer statistics. @@ -121,10 +148,31 @@ extern "C" ****************************************************************************/ #ifdef CONFIG_NET_STATISTICS -ssize_t net_readstats(FAR struct netprocfs_file_s *priv, FAR char *buffer, - size_t buflen); +ssize_t netprocfs_read_netstats(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen); #endif +/**************************************************************************** + * Name: netprocfs_read_devstats + * + * Description: + * Read and format network device statistics. + * + * Input Parameters: + * priv - A reference to the network procfs file structure + * buffer - The user-provided buffer into which device status will be + * returned. + * bulen - The size in bytes of the user provided buffer. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +ssize_t netprocfs_read_devstats(FAR struct netprocfs_file_s *priv, + FAR char *buffer, size_t buflen); + #undef EXTERN #ifdef __cplusplus } -- GitLab From 25f48e58293ed627eb703717e641ec9433fa343f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 27 Nov 2015 17:48:40 -0600 Subject: [PATCH 383/858] Update TODO file --- TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO b/TODO index 63a10c29ba..14b67dc896 100644 --- a/TODO +++ b/TODO @@ -442,9 +442,6 @@ o Kernel/Protected Build mkfatfs mkfatfs mkrd ramdisk_register() ps sched_foreach() - ifup netdev_foreach() - ifdown netdev_foreach() - ifconfig netdev_foreach() ping icmp_ping() The busybox mkfatfs does not involve any OS calls; it does -- GitLab From 1f8f09778317304171647965c9f49a0edf293eb8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 08:52:21 -0600 Subject: [PATCH 384/858] procfs: Use dirent.h macros when testing directory entry type --- Documentation | 2 +- configs | 2 +- fs/procfs/fs_procfsproc.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation b/Documentation index 3d2cd73b92..9a469c139e 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 3d2cd73b92c99a5880354fe11f5d7f29bc8775e8 +Subproject commit 9a469c139e90739c838009ca1e721e466ad42548 diff --git a/configs b/configs index 18c27d6535..60a36debd0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 18c27d653564ec78841d6912597155fde62467c7 +Subproject commit 60a36debd08e046a5e1768ebc5ba5fb17a337c83 diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 0d4f3b9945..a988227fd7 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -981,9 +981,9 @@ static int proc_open(FAR struct file *filep, FAR const char *relpath, /* The node must be a file, not a directory */ - if (node->dtype != DTYPE_FILE) + if (!DIRENT_ISFILE(node->dtype)) { - fdbg("ERROR: Path \"%s\" is a directory\n", relpath); + fdbg("ERROR: Path \"%s\" is not a regular file\n", relpath); return -EISDIR; } @@ -1238,7 +1238,7 @@ static int proc_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir) /* The node must be a directory, not a file */ - if (node->dtype != DTYPE_DIRECTORY) + if (!DIRENT_ISDIRECTORY(node->dtype)) { fdbg("ERROR: Path \"%s\" is not a directory\n", relpath); kmm_free(procdir); -- GitLab From 5821af1bbe405795ce646d966e750378a216c4df Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Sat, 28 Nov 2015 09:00:26 -0600 Subject: [PATCH 385/858] drivers/mtd: Add support for /dev/smart loop device. From Ken Petit --- ChangeLog | 3 +- drivers/mtd/Kconfig | 30 +++++ drivers/mtd/Make.defs | 4 + drivers/mtd/filemtd.c | 78 ++++++++++--- drivers/mtd/smart.c | 236 +++++++++++++++++++++++++++++++++++++++ include/nuttx/fs/smart.h | 38 +++++++ include/nuttx/mtd/mtd.h | 23 +++- 7 files changed, 393 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fc07dc19b..da0c769ba6 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11175,4 +11175,5 @@ statistics (2015-11-26). * net/net_procfs.c: Add basic support for networking entries in the procfs (2015-11-27). - + * mtd/filemtd.c and smart.c: Add support for a /dev/smart loop device. + From Ken Petit (2015-11-28). diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 03f08fd0e7..b3bd84d703 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -268,6 +268,28 @@ config RAMMTD_FLASHSIM endif +config FILEMTD + bool "File-based MTD driver" + default n + ---help--- + Build support for a File-based MTD driver. + +if FILEMTD + +config FILEMTD_BLOCKSIZE + int "File MTD block size" + default 512 + +config FILEMTD_ERASESIZE + int "File MTD erase block size" + default 4096 + +config FILEMTD_ERASESTATE + hex "Simulated erase state" + default 0xff + +endif + config MTD_AT24XX bool "I2C-based AT24xx eeprom" default n @@ -479,6 +501,14 @@ config MTD_SMART if MTD_SMART +config SMART_DEV_LOOP + bool "Enable SMART loop device" + select FILEMTD + default n + ---help--- + Supports a smart loop device that can be used to export a + file (or character device) as a SMART block device. + config MTD_SMART_SECTOR_SIZE int "SMART Device sector size" default 1024 diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs index bd284d6822..fdd77d3610 100644 --- a/drivers/mtd/Make.defs +++ b/drivers/mtd/Make.defs @@ -72,6 +72,10 @@ ifeq ($(CONFIG_RAMMTD),y) CSRCS += rammtd.c endif +ifeq ($(CONFIG_FILEMTD),y) +CSRCS += filemtd.c +endif + ifeq ($(CONFIG_MTD_AT24XX),y) CSRCS += at24xx.c endif diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index c4dee5db75..18b2e19e1a 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -95,10 +95,12 @@ struct file_dev_s { - struct mtd_dev_s mtd; /* MTD device */ - int fd; /* File descriptor of underlying file */ - size_t nblocks; /* Number of erase blocks */ - size_t offset; /* Offset from start of file */ + struct mtd_dev_s mtd; /* MTD device */ + int fd; /* File descriptor of underlying file */ + size_t nblocks; /* Number of erase blocks */ + size_t offset; /* Offset from start of file */ + size_t erasesize; /* Offset from start of file */ + size_t blocksize; /* Offset from start of file */ }; /**************************************************************************** @@ -270,8 +272,8 @@ static int file_erase(FAR struct mtd_dev_s *dev, off_t startblock, * corresponding to the number of blocks. */ - offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; - nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + offset = startblock * priv->blocksize; + nbytes = nblocks * priv->blocksize; /* Then erase the data in the file */ @@ -317,8 +319,8 @@ static ssize_t file_bread(FAR struct mtd_dev_s *dev, off_t startblock, * corresponding to the number of blocks. */ - offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; - nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + offset = startblock * priv->blocksize; + nbytes = nblocks * priv->blocksize; /* Then read the data from the file */ @@ -357,8 +359,8 @@ static ssize_t file_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, * corresponding to the number of blocks. */ - offset = startblock * CONFIG_FILEMTD_BLOCKSIZE; - nbytes = nblocks * CONFIG_FILEMTD_BLOCKSIZE; + offset = startblock * priv->blocksize; + nbytes = nblocks * priv->blocksize; /* Then write the data to the file */ @@ -379,7 +381,7 @@ static ssize_t file_byteread(FAR struct mtd_dev_s *dev, off_t offset, /* Don't let read read past end of buffer */ - if (offset + nbytes > priv->nblocks * CONFIG_FILEMTD_ERASESIZE) + if (offset + nbytes > priv->nblocks * priv->erasesize) { return 0; } @@ -403,7 +405,7 @@ static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, /* Don't let the write exceed the original size of the file */ - maxoffset = priv->nblocks * CONFIG_FILEMTD_ERASESIZE; + maxoffset = priv->nblocks * priv->erasesize; if (offset + nbytes > maxoffset) { return 0; @@ -438,8 +440,8 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * the capacity and how to access the device. */ - geo->blocksize = CONFIG_FILEMTD_BLOCKSIZE; - geo->erasesize = CONFIG_FILEMTD_ERASESIZE; + geo->blocksize = priv->blocksize; + geo->erasesize = priv->erasesize; geo->neraseblocks = priv->nblocks; ret = OK; } @@ -482,7 +484,8 @@ static int file_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ****************************************************************************/ -FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset) +FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset, + int16_t sectsize, int32_t erasesize) { FAR struct file_dev_s *priv; struct stat sb; @@ -527,9 +530,31 @@ FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset) return NULL; } + /* Set the block size based on the provided sectsize parameter */ + + if (sectsize <= 0) + { + priv->blocksize = CONFIG_FILEMTD_BLOCKSIZE; + } + else + { + priv->blocksize = sectsize; + } + + /* Set the erase size based on the provided erasesize parameter */ + + if (erasesize <= 0) + { + priv->erasesize = CONFIG_FILEMTD_ERASESIZE; + } + else + { + priv->erasesize = erasesize; + } + /* Force the size to be an even number of the erase block size */ - nblocks = (filelen - offset) / CONFIG_FILEMTD_ERASESIZE; + nblocks = (filelen - offset) / priv->erasesize; if (nblocks < 3) { fdbg("Need to provide at least three full erase block\n"); @@ -591,3 +616,24 @@ void filemtd_teardown(FAR struct mtd_dev_s *dev) kmm_free(priv); } + +/**************************************************************************** + * Name: filemtd_isfilemtd + * + * Description: + * Tests if the provided mtd is a filemtd device. + * + * Input Parameters: + * mtd - Pointer to the mtd. + * + ****************************************************************************/ + +bool filemtd_isfilemtd(FAR struct mtd_dev_s *dev) +{ + FAR struct file_dev_s *priv = (FAR struct file_dev_s *) dev; + + if (priv->mtd.erase == file_erase) + return 1; + + return 0; +} diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index c82a3af112..cb188c1854 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -43,6 +43,8 @@ #include #include +#include +#include #include #include #include @@ -385,6 +387,14 @@ static int smart_relocate_static_data(FAR struct smart_struct_s *dev, uint16_t b static int smart_relocate_sector(FAR struct smart_struct_s *dev, uint16_t oldsector, uint16_t newsector); +#ifdef CONFIG_SMART_DEV_LOOP +static ssize_t smart_loop_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t smart_loop_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int smart_loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +#endif /* CONFIG_SMART_DEV_LOOP */ + /**************************************************************************** * Private Data ****************************************************************************/ @@ -403,6 +413,21 @@ static const struct block_operations g_bops = smart_ioctl /* ioctl */ }; +#ifdef CONFIG_SMART_DEV_LOOP +static const struct file_operations g_fops = +{ + 0, /* open */ + 0, /* close */ + smart_loop_read, /* read */ + smart_loop_write, /* write */ + 0, /* seek */ + smart_loop_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; +#endif /* CONFIG_SMART_DEV_LOOP */ + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -5411,6 +5436,10 @@ int smart_initialize(int minor, FAR struct mtd_dev_s *mtd, FAR const char *partn smart_scan(dev); } +#ifdef CONFIG_SMART_DEV_LOOP + (void)register_driver("/dev/smart", &g_fops, 0666, NULL); +#endif + return OK; errout: @@ -5437,3 +5466,210 @@ errout: kmm_free(dev); return ret; } + + /**************************************************************************** + * Name: smart_losetup + * + * Description: Dynamically setups up a SMART enabled loop device that + * is backed by a file. The resulting loop device is a + * MTD type block device vs. a generic block device. + * + ****************************************************************************/ + +#ifdef CONFIG_SMART_DEV_LOOP +static int smart_losetup(int minor, FAR const char *filename, + int sectsize, int erasesize, off_t offset, bool readonly) +{ + FAR struct mtd_dev_s *mtd; + struct stat sb; + int x, ret; + char devpath[20]; + + /* Try to create a filemtd device using the filename provided */ + + mtd = filemtd_initialize(filename, offset, sectsize, erasesize); + if (mtd == NULL) + { + return -ENOENT; + } + + /* Check if we need to dynamically assign a minor number */ + + if (minor == -1) + { + /* Start at zero and stat /dev/smartX until no entry found. + * Searching 0 to 256 should be sufficient. + */ + + for (x = 0; x < 256; x++) + { + snprintf(devpath, sizeof(devpath), "/dev/smart%d", x); + ret = stat(devpath, &sb); + if (ret != 0) + { + /* We can use this minor number */ + + minor = x; + break; + } + } + } + + /* Now create a smart MTD using the filemtd backing it */ + + ret = smart_initialize(minor, mtd, NULL); + + if (ret != OK) + { + filemtd_teardown(mtd); + } + + return ret; +} +#endif /* CONFIG_SMART_DEV_LOOP */ + +/**************************************************************************** + * Name: loteardown + * + * Description: + * Undo the setup performed by losetup + * + ****************************************************************************/ + +#ifdef CONFIG_SMART_DEV_LOOP +static int smart_loteardown(FAR const char *devname) +{ + FAR struct smart_struct_s *dev; + FAR struct inode *inode; + int ret; + + /* Sanity check */ + +#ifdef CONFIG_DEBUG + if (!devname) + { + return -EINVAL; + } +#endif + + /* Open the block driver associated with devname so that we can get the inode + * reference. + */ + + ret = open_blockdriver(devname, MS_RDONLY, &inode); + if (ret < 0) + { + dbg("Failed to open %s: %d\n", devname, -ret); + return ret; + } + + /* Inode private data is a reference to the loop device structure */ + + dev = (FAR struct smart_struct_s *)inode->i_private; + + /* Validate this is a filemtd backended device */ + + if (!filemtd_isfilemtd(dev->mtd)) + { + fdbg("Device is not a SMART loop: %s\n", devname); + return -EINVAL; + } + + close_blockdriver(inode); + + /* Now teardown the filemtd */ + + filemtd_teardown(dev->mtd); + unregister_blockdriver(devname); + + kmm_free(dev); + + return OK; +} +#endif /* CONFIG_SMART_DEV_LOOP */ + +/**************************************************************************** + * Name: smart_loop_read + ****************************************************************************/ + +#ifdef CONFIG_SMART_DEV_LOOP +static ssize_t smart_loop_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + return 0; /* Return EOF */ +} +#endif /* CONFIG_SMART_DEV_LOOP */ + +/**************************************************************************** + * Name: smart_loop_write + ****************************************************************************/ + +#ifdef CONFIG_SMART_DEV_LOOP +static ssize_t smart_loop_write(FAR struct file *filep, FAR const char *buffer, size_t len) +{ + return len; /* Say that everything was written */ +} +#endif /* CONFIG_SMART_DEV_LOOP */ + +/**************************************************************************** + * Name: smart_loop_ioctl + ****************************************************************************/ + +#ifdef CONFIG_SMART_DEV_LOOP +static int smart_loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + int ret; + + switch (cmd) + { + /* Command: LOOPIOC_SETUP + * Description: Setup the loop device + * Argument: A pointer to a read-only instance of struct losetup_s. + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + + case SMART_LOOPIOC_SETUP: + { + FAR struct smart_losetup_s *setup = (FAR struct smart_losetup_s *)((uintptr_t)arg); + + if (setup == NULL) + { + ret = -EINVAL; + } + else + { + ret = smart_losetup(setup->minor, setup->filename, setup->sectsize, + setup->erasesize, setup->offset, setup->readonly); + } + } + break; + + /* Command: LOOPIOC_TEARDOWN + * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP + * Argument: A read-able pointer to the path of the device to be + * torn down + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + + case SMART_LOOPIOC_TEARDOWN: + { + FAR const char *devname = (FAR const char *)((uintptr_t)arg); + + if (devname == NULL) + { + ret = -EINVAL; + } + else + { + ret = smart_loteardown(devname); + } + } + break; + + default: + ret = -ENOTTY; + } + + return ret; +} +#endif /* CONFIG_SMART_DEV_LOOP */ + diff --git a/include/nuttx/fs/smart.h b/include/nuttx/fs/smart.h index f3bff10cb6..ec217466aa 100644 --- a/include/nuttx/fs/smart.h +++ b/include/nuttx/fs/smart.h @@ -45,6 +45,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -64,6 +65,27 @@ #define SMARTFS_SECTOR_TYPE_DIR 1 #define SMARTFS_SECTOR_TYPE_FILE 2 +#ifdef CONFIG_SMART_DEV_LOOP +/* Loop device IOCTL commands */ + +/* Command: SMART_LOOPIOC_SETUP + * Description: Setup the loop device + * Argument: A pointer to a read-only instance of struct losetup_s. + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + +/* Command: SMART_LOOPIOC_TEARDOWN + * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP + * Argument: A read-able pointer to the path of the device to be + * torn down + * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y) + */ + +#define SMART_LOOPIOC_SETUP _LOOPIOC(0x0001) +#define SMART_LOOPIOC_TEARDOWN _LOOPIOC(0x0002) + +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -112,6 +134,22 @@ struct smart_procfs_data_s }; #endif +#ifdef CONFIG_SMART_DEV_LOOP +/* This is the structure referred to in the argument to the LOOPIOC_SETUP + * IOCTL command. + */ + +struct smart_losetup_s +{ + FAR const char *filename; /* The file or character device to use */ + int minor; /* The minor number of thedevice */ + int erasesize; /* The erase size to use on the file */ + int sectsize; /* The sector / page size of the file */ + off_t offset; /* An offset that may be applied to the device */ + bool readonly; /* True: Read access will be supported only */ +}; +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 367fbad1b8..39803509f8 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -525,17 +525,36 @@ FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, FAR struct mtd_dev_s *up_flashinitialize(void); /**************************************************************************** - * Name: up_flashinitialize + * Name: filemtd_initialize * * Description: * Create a file backed MTD device. * ****************************************************************************/ -FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset); +FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset, + int16_t sectsize, int32_t erasesize); + +/**************************************************************************** + * Name: filemtd_teardown + * + * Description: + * Tear down a filemtd device. + * + ****************************************************************************/ void filemtd_teardown(FAR struct mtd_dev_s* mtd); +/**************************************************************************** + * Name: filemtd_isfilemtd + * + * Description: + * Test if MTD is a filemtd device. + * + ****************************************************************************/ + +bool filemtd_isfilemtd(FAR struct mtd_dev_s* mtd); + /**************************************************************************** * Name: mtd_register * -- GitLab From 48da5aa496e1ac1b1b456f559a8979b25349ac24 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 10:05:36 -0600 Subject: [PATCH 386/858] sched/pthread/: CRITICAL BUGFIX: Logic was wiping out the indication that of the type of a pthread. Hence, it could be confused as a task. Found because this was causing a crash when /proc/nnn/cmdline was printed. --- ChangeLog | 5 +++++ sched/pthread/pthread_create.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index da0c769ba6..65044a859e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11177,3 +11177,8 @@ procfs (2015-11-27). * mtd/filemtd.c and smart.c: Add support for a /dev/smart loop device. From Ken Petit (2015-11-28). + * sched/pthread/: CRITICAL BUGFIX: Logic was wiping out the indication + that of the type of a pthread. Hence, it could be confused as a + task. Found because this was causing a crash when /proc/nnn/cmdline + was printed (2015-11-29). + diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index c22cead9a9..41c2a85799 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -430,7 +430,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, /* Set the appropriate scheduling policy in the TCB */ - ptcb->cmn.flags &= TCB_FLAG_POLICY_MASK; + ptcb->cmn.flags &= ~TCB_FLAG_POLICY_MASK; switch (policy) { default: -- GitLab From 2e7d139cd386ba5d15308f7dc8b6687ddc71da4d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 14:58:56 -0600 Subject: [PATCH 387/858] fs/procfs: Process status now includes task flags. Some strings modified to improved 'ps' command output --- fs/procfs/fs_procfsproc.c | 49 ++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index a988227fd7..325c2286f2 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -303,17 +303,17 @@ static const struct proc_node_s * const g_groupinfo[] = static const char *g_statenames[] = { "Invalid", - "Pending unlock", + "Waiting,Unlock", "Ready", "Running", "Inactive", - "Semaphore wait", -#ifndef CONFIG_DISABLE_MQUEUE - "Signal wait", + "Waiting,Semaphore", +#ifndef CONFIG_DISABLE_SIGNALS + "Waiting,Signal", #endif #ifndef CONFIG_DISABLE_MQUEUE - "MQ not empty wait", - "MQ no full wait" + "Waiting,MQ empty", + "Waiting,MQ full" #endif }; @@ -321,8 +321,8 @@ static const char *g_ttypenames[4] = { "Task", "pthread", - "Kernel thread", - "--?--" + "Kthread", + "Invalid" }; /**************************************************************************** @@ -354,6 +354,21 @@ static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath) /**************************************************************************** * Name: proc_status + * + * Description: + * Format: + * + * 111111111122222222223 + * 123456789012345678901234567890 + * Name: xxxx... Task/thread name (See CONFIG_TASK_NAME_SIZE) + * Type: xxxxxxx {Task, pthread, Kthread, Invalid} + * State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running, Inactive}, + * {Unlock, Semaphore, Signal, MQ empty, MQ full} + * Flags: xxx N,P,X + * Priority: nnn Decimal, 0-255 + * Scheduler: xxxxxxxxxxxxxx {SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_OTHER} + * Sigmask: nnnnnnnn Hexadecimal, 32-bit + * ****************************************************************************/ static ssize_t proc_status(FAR struct proc_file_s *procfile, @@ -416,6 +431,24 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, buffer += copysize; remaining -= copysize; + if (totalsize >= buflen) + { + return totalsize; + } + + /* Show task flags */ + + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%c%c%c\n", "Flags:", + tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : '-', + tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : '-', + tcb->flags & TCB_FLAG_EXIT_PROCESSING ? 'P' : '-'); + + copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); + + totalsize += copysize; + buffer += copysize; + remaining -= copysize; + if (totalsize >= buflen) { return totalsize; -- GitLab From 64247fee157440ee65b1305357e8234fc4e0c0ff Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 15:04:11 -0600 Subject: [PATCH 388/858] Update TODO list --- TODO | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TODO b/TODO index 14b67dc896..3369e8ba7e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated November 26, 2015) +NuttX TODO List (Last updated November 28, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -441,7 +441,6 @@ o Kernel/Protected Build -------- ---------------------------------------------- mkfatfs mkfatfs mkrd ramdisk_register() - ps sched_foreach() ping icmp_ping() The busybox mkfatfs does not involve any OS calls; it does -- GitLab From 49a34656b276e2c87134f51454262cfbc041f54d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 15:06:35 -0600 Subject: [PATCH 389/858] Fix spelling of Ken's last name in ChangeLog --- ChangeLog | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 65044a859e..f5a1a02e8d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -9175,7 +9175,7 @@ build framework and skeleton files for Tiva I2C driver. Initial commit is just the STM32 I2C driver with name changes and STM32- specific logic removed (2014-12-9). - * fs/procfs/fs_procfs.c: Add procfs write support. From Ken Petit + * fs/procfs/fs_procfs.c: Add procfs write support. From Ken Pettit (2014-12-9). * include/crc8.h, libc/misc/lib_crc8.c, and Make.defs: Add CRC8 support. From Ken Pettit (2014-12-9). @@ -11106,11 +11106,11 @@ * drivers/sensors/ms58xx.c: Fix some issues with initialization and with CRC calculation. From Karim Keddam (2015-11-17). * drivers/mtd/w25.c: Fix W25 FLASH driver page read/write logic. From - Ken Petit (2015-11-18). - * drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit + Ken Pettit (2015-11-18). + * drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Pettit (2015-11-18). * arch/sim/src/up_spiflash.c: Add support for W25 FLASH simulation. - From Ken Petit (2015-11-18). + From Ken Pettit (2015-11-18). * configs/boardctl.h, Kconfig, include/sys/boardctl.h, and nuttx/board.h: Add a command to the boardctl() interface to obtain a board unique ID (2015-11-18). @@ -11123,11 +11123,11 @@ the logical sector size is too small to save all wear level status bytes in a single sector. Logical sectors 1 and 2 were simply not being allocated and then the read_sector and write_sector routinesi - were failing. From Ken Petit (2015-11-18). + were failing. From Ken Pettit (2015-11-18). * drivers/timers/ds3231.c: Untested support for DS1302 and DS3232. Also definitions for the DS3234, but that is an unsupported SPI RTC (2015-11-19). - * drivers/mtd/w25.c: Add support for byte write mode. From Ken Peit + * drivers/mtd/w25.c: Add support for byte write mode. From Ken Pettit (2015-11-20). * drivers/timers/pcf85263.c and include/nuttx/times/pcf85263.h: Add a driver for the NXP PCF85263 I2C RTC. Untested on initial commit @@ -11147,18 +11147,18 @@ been backed out. With these changes, the simulator builds without * fs/hostfs and arch/sim/src: Add a special file system for use with simulator that supports access to the host file system from the - simulation. From Ken Petit (2015-11-25). + simulation. From Ken Pettit (2015-11-25). * libc/time/lib_strftime.c: Add day-of-week support. (2015-11-25). * drivers/lcd/ili9432.c: Fixed errors in orientation. Portrait, RPortrait, and RLandscript should work correly now. They were displayed mirrored. From Marco Krahl (2015-11-25). * drivers/mtd/mtd/mtd_procfs/c and include/nuttx/mtd/mtd.h: Add an - interface to un-regiser an MTD procfs entry. From Ken Petit + interface to un-regiser an MTD procfs entry. From Ken Pettit (2015-11-25). * drivers/mtd/filemtd.c: New new MTD conversion layer that will convert a regular file (or driver file) to an MTD device. This is useful for testing on the simulation using the hostfs. From Ken - Petit (2015-11-25). + Pettit (2015-11-25). * drivers/loop: Add a loop character device. losetup() and loteardown() should not be called directory from applications. Rather, these functions are now available as IOCTL commands to the @@ -11176,7 +11176,7 @@ * net/net_procfs.c: Add basic support for networking entries in the procfs (2015-11-27). * mtd/filemtd.c and smart.c: Add support for a /dev/smart loop device. - From Ken Petit (2015-11-28). + From Ken Pettit (2015-11-28). * sched/pthread/: CRITICAL BUGFIX: Logic was wiping out the indication that of the type of a pthread. Hence, it could be confused as a task. Found because this was causing a crash when /proc/nnn/cmdline -- GitLab From 8ac588f602543b246dc470718dd7b22cec928e4d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Nov 2015 17:28:25 -0600 Subject: [PATCH 390/858] Update TODO --- Documentation | 2 +- TODO | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Documentation b/Documentation index 9a469c139e..35cdfcd8fa 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 9a469c139e90739c838009ca1e721e466ad42548 +Subproject commit 35cdfcd8fabebc2ec35979a2d19b9d52c345133f diff --git a/TODO b/TODO index 3369e8ba7e..9bfa1c79d4 100644 --- a/TODO +++ b/TODO @@ -449,9 +449,6 @@ o Kernel/Protected Build http://git.busybox.net/busybox/tree/util-linux/mkfs_vfat.c - ps, ifup, ifdown, ifconfig should be implemented using - extensions to the procfs file system. - Status: Open Priority: Medium/High -- the kernel build configuration is not fully fielded yet. -- GitLab From 11afff74dc5d138d1159af7f9db77b63232776a4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Nov 2015 12:13:24 -0600 Subject: [PATCH 391/858] Kconfig change for improved usability --- Documentation | 2 +- configs | 2 +- drivers/timers/Kconfig | 4 ++-- fs/fat/fs_fat32.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation b/Documentation index 35cdfcd8fa..7d0cbe27b2 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 35cdfcd8fabebc2ec35979a2d19b9d52c345133f +Subproject commit 7d0cbe27b2a41690f6c16dfda4ba03fdfa71726f diff --git a/configs b/configs index 60a36debd0..dbc1711c26 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 60a36debd08e046a5e1768ebc5ba5fb17a337c83 +Subproject commit dbc1711c26e0403acbe283f22aeddf5f00ff84e9 diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index af8b8a4a9e..7e053175ce 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -137,8 +137,8 @@ config RTC_DSXXXX default n select I2C select I2C_TRANSFER - select RTC_EXTERNAL select RTC_DATETIME + depends on RTC_EXTERNAL ---help--- Enables support for the Maxim Integrated DS3231 I2C RTC timer. @@ -190,8 +190,8 @@ config RTC_PCF85263 default n select I2C select I2C_TRANSFER - select RTC_EXTERNAL select RTC_DATETIME + depends on RTC_EXTERNAL ---help--- Enables support for the Maxim Integrated DS3231 I2C RTC timer. diff --git a/fs/fat/fs_fat32.h b/fs/fat/fs_fat32.h index c3581e78ef..6c4aa846fd 100644 --- a/fs/fat/fs_fat32.h +++ b/fs/fat/fs_fat32.h @@ -770,7 +770,7 @@ struct fat_file_s uint8_t *ff_buffer; /* File buffer (for partial sector accesses) */ }; -/* This structure holds the sequency of directory entries used by one +/* This structure holds the sequence of directory entries used by one * file element (directory or file). For short file names, this is * single diretory entry. But for long file names, the is a sequence * of directory entries. Long directory name entries appear in reverse -- GitLab From 5c9e05693e59e847da74c66f1c7dd5475286ce02 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Nov 2015 13:54:35 -0600 Subject: [PATCH 392/858] Upate submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 7a800cc36f..a5e2b41276 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7a800cc36f9078f59f3f19c6eb400701952cfb7c +Subproject commit a5e2b41276f61c0c635866d52e8db155d0290648 diff --git a/configs b/configs index dbc1711c26..ee8c7ecbcb 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dbc1711c26e0403acbe283f22aeddf5f00ff84e9 +Subproject commit ee8c7ecbcba5a420e39de92502f7649f8baff169 -- GitLab From fc0c775b6f0720a7e60e40a33f2ed7857ab98366 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Nov 2015 14:42:32 -0600 Subject: [PATCH 393/858] Extended tools/testbuild.sh to work with simulator builds which have no toolchain definition --- tools/testbuild.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tools/testbuild.sh b/tools/testbuild.sh index a441196e81..65d8e10f93 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -173,15 +173,17 @@ function configure { kconfig-tweak --file $nuttx/.config --disable CONFIG_CXX_NEWLONG fi - setting=`grep TOOLCHAIN $nuttx/.config | grep =y` - varname=`echo $setting | cut -d'=' -f1` - if [ ! -z "varname" ]; then - echo " Disabling $varname" - kconfig-tweak --file $nuttx/.config --disable $varname - fi + if [ "X$toolchain" != "X" ]; then + setting=`grep TOOLCHAIN $nuttx/.config | grep =y` + varname=`echo $setting | cut -d'=' -f1` + if [ ! -z "varname" ]; then + echo " Disabling $varname" + kconfig-tweak --file $nuttx/.config --disable $varname + fi - echo " Enabling $toolchain" - kconfig-tweak --file $nuttx/.config --enable $toolchain + echo " Enabling $toolchain" + kconfig-tweak --file $nuttx/.config --enable $toolchain + fi echo " Refreshing..." kconfig-conf --olddefconfig Kconfig 1>/dev/null @@ -232,10 +234,12 @@ for line in $testlist; do showusage fi - toolchain=`echo $line | cut -d',' -f2` - if [ -z "$toolchain" ]; then - echo "ERROR no tool configuration" - showusage + unset toolchain; + if [ "X$config" != "X$line" ]; then + toolchain=`echo $line | cut -d',' -f2` + if [ -z "$toolchain" ]; then + echo " Warning: no tool configuration" + fi fi # Perform the build test -- GitLab From 3af1def49aef73f3f762caacf77759ab63ca1e9e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Nov 2015 14:42:56 -0600 Subject: [PATCH 394/858] Fix an error in a function prototype --- drivers/mtd/mtd_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c index 674fd6ed56..d3cde69564 100644 --- a/drivers/mtd/mtd_config.c +++ b/drivers/mtd/mtd_config.c @@ -117,7 +117,7 @@ static int mtdconfig_open(FAR struct file *filep); static int mtdconfig_close(FAR struct file *filep); static ssize_t mtdconfig_read(FAR struct file *filep, FAR char *buffer, size_t buflen); -static ssize_t mtdconfig_ioctl(FAR struct file *filep, int cmd, +static int mtdconfig_ioctl(FAR struct file *filep, int cmd, unsigned long arg); #ifndef CONFIG_DISABLE_POLL static int mtdconfig_poll(FAR struct file *filep, FAR struct pollfd *fds, -- GitLab From 190772edc59464260721d2cdcfa79d94e9d388a2 Mon Sep 17 00:00:00 2001 From: Karim Keddam Date: Mon, 30 Nov 2015 03:50:58 -0500 Subject: [PATCH 395/858] Fixed error with temperature computation --- drivers/sensors/ms58xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 1a4352acdf..d7872b5c5e 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -589,7 +589,7 @@ static int ms58xx_measure(FAR struct ms58xx_dev_s *priv) return ret; } - diff = (int32_t)rawtemp - (int32_t)priv->c5 / ((int32_t)1 << 8); + diff = (int32_t)rawtemp - (int32_t)priv->c5 * ((int32_t)1 << 8); temp = (int32_t)((int64_t)2000 + (int64_t)diff * (int64_t)priv->c6 / ((int64_t)1 << 23)); -- GitLab From 1c8216a6cecf0b21294395c827dcf640e6ac8c0e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 30 Nov 2015 06:58:06 -0600 Subject: [PATCH 396/858] Add group ID or parent PID to procfs output (if available) --- fs/procfs/fs_procfsproc.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 325c2286f2..b01b2cbb8e 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -72,6 +72,18 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* See include/nuttx/sched.h: */ + +#undef HAVE_GROUPID + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) +# define HAVE_GROUPID 1 +#endif + +#ifdef CONFIG_DISABLE_PTHREAD +# undef HAVE_GROUPID +#endif + /* Determines the size of an intermediate buffer that must be large enough * to handle the longest line generated by this logic. */ @@ -362,6 +374,8 @@ static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath) * 123456789012345678901234567890 * Name: xxxx... Task/thread name (See CONFIG_TASK_NAME_SIZE) * Type: xxxxxxx {Task, pthread, Kthread, Invalid} + * PPID: xxxxx Parent thread ID + * Group: xxxxx Group ID * State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running, Inactive}, * {Unlock, Semaphore, Signal, MQ empty, MQ full} * Flags: xxx N,P,X @@ -375,6 +389,9 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen, off_t offset) { +#ifdef HAVE_GROUPID + FAR struct task_group_s *group; +#endif FAR const char *policy; FAR const char *name; size_t remaining; @@ -421,6 +438,30 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, return totalsize; } +#ifdef CONFIG_SCHED_HAVE_PARENT +#ifdef HAVE_GROUPID + group = tcb->group; + DEBUGASSERT(group); + + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "Group:", + group->tg_pgid); +#else + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:", + tcb->ppid); +#endif + + copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); + + totalsize += copysize; + buffer += copysize; + remaining -= copysize; + + if (totalsize >= buflen) + { + return totalsize; + } +#endif + /* Show the thread state */ linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%s\n", "State:", -- GitLab From 00e0ff54e80859b1fa13da96a8404e401facca4a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 30 Nov 2015 13:06:16 -0600 Subject: [PATCH 397/858] tools/testbuild.sh: Changes needed for testing the simulator under Cygwin --- configs | 2 +- tools/testbuild.sh | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/configs b/configs index ee8c7ecbcb..1c21c243d0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ee8c7ecbcba5a420e39de92502f7649f8baff169 +Subproject commit 1c21c243d0a4a426940a87b3519f9a8ff059302f diff --git a/tools/testbuild.sh b/tools/testbuild.sh index 65d8e10f93..594c58db2f 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -49,7 +49,7 @@ function showusage { echo "where" echo " -w|l selects Windows (w) or Linux (l). Default: Linux" echo " -c|n selects Windows native (n) or Cygwin (c). Default Cygwin" - echo " -s Use C++ long size_t in new operator. Default unsigned long" + echo " -s Use C++ unsigned long size_t in new operator. Default unsigned int" echo " -h will show this help test and terminate" echo " selects the list of configurations to test. No default" echo "" @@ -73,7 +73,7 @@ while [ ! -z "$1" ]; do wenv=cygwin ;; -n ) - wenv=n + wenv=native ;; -s ) sizet=long @@ -142,23 +142,30 @@ function configure { kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_MSYS kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_OTHER + kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_SYSTEMV + kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_X8664_MICROSOFT + kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_M32 else echo " Select CONFIG_HOST_WINDOWS=y" kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_WINDOWS kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_LINUX if [ "X$wenv" == "Xcygwin" ]; then - echo " Select CONFIG_HOST_CYGWIN=y" + echo " Select CONFIG_WINDOWS_CYGWIN=y" kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_CYGWIN kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_NATIVE else - echo " Select CONFIG_HOST_MSYS=y" + echo " Select CONFIG_WINDOWS_NATIVE=y" kconfig-tweak --file $nuttx/.config --enable CONFIG_WINDOWS_NATIVE kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_CYGWIN fi kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_MSYS kconfig-tweak --file $nuttx/.config --disable CONFIG_WINDOWS_OTHER + + kconfig-tweak --file $nuttx/.config --enable CONFIG_SIM_X8664_MICROSOFT + kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_X8664_SYSTEMV + kconfig-tweak --file $nuttx/.config --disable CONFIG_SIM_M32 fi kconfig-tweak --file $nuttx/.config --disable CONFIG_HOST_OSX @@ -166,7 +173,6 @@ function configure { if [ "X$sizet" == "Xlong" ]; then echo " Select CONFIG_CXX_NEWLONG=y" - kconfig-tweak --file $nuttx/.config --enable CONFIG_CXX_NEWLONG else echo " Disable CONFIG_CXX_NEWLONG" -- GitLab From 4c22aae14abe5aaec3631ae65893f9d13fd4dadc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 30 Nov 2015 16:06:10 -0600 Subject: [PATCH 398/858] Update ChangeLog --- ChangeLog | 4 +++- arch | 2 +- configs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5a1a02e8d..3506c602bb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11181,4 +11181,6 @@ that of the type of a pthread. Hence, it could be confused as a task. Found because this was causing a crash when /proc/nnn/cmdline was printed (2015-11-29). - + * configs/same70-xplained/nsh: The NSH configuration now seems fully + functional: serial console, LEDs, buttons, SDRAM, and HSMCI SD card + (2015-11-30). diff --git a/arch b/arch index a5e2b41276..93c52e9803 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a5e2b41276f61c0c635866d52e8db155d0290648 +Subproject commit 93c52e98030b3f596c0c93008cdeb0f9d2c4d0fc diff --git a/configs b/configs index 1c21c243d0..d91360e5ac 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 1c21c243d0a4a426940a87b3519f9a8ff059302f +Subproject commit d91360e5ac4ea53de1739c7cc5e92596dd2f8309 -- GitLab From 053aeb555c7397fec07eff448170052897265e4b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 30 Nov 2015 16:51:44 -0600 Subject: [PATCH 399/858] Update ChangeLog --- ChangeLog | 2 ++ configs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3506c602bb..891565ed1f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11184,3 +11184,5 @@ * configs/same70-xplained/nsh: The NSH configuration now seems fully functional: serial console, LEDs, buttons, SDRAM, and HSMCI SD card (2015-11-30). + * configs/same70-xplained/netnsh: Added and verified a network-enabled + NSH configuration for the SAME70-Xplained board (2015-11-20). diff --git a/configs b/configs index d91360e5ac..eadf9704c9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d91360e5ac4ea53de1739c7cc5e92596dd2f8309 +Subproject commit eadf9704c93f1a5cc0d90b78cf3cc9e5de26dbfc -- GitLab From 6af3ba78b9aa3fbd3ce59eb073dbfcaac83f8302 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 07:48:56 -0600 Subject: [PATCH 400/858] Remove CONFIG_NET_PINGADDRCONF. This was a uIP way of assigning IP addresses, but is not standard and not a appropriate feature in general. --- ChangeLog | 3 +++ arch | 2 +- configs | 2 +- net/devif/ipv4_input.c | 25 +++---------------------- net/devif/ipv6_input.c | 5 +---- net/icmp/Kconfig | 9 ++++----- net/icmp/icmp_input.c | 12 ------------ net/icmpv6/Kconfig | 5 +++++ 8 files changed, 18 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 891565ed1f..08adf37518 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11186,3 +11186,6 @@ (2015-11-30). * configs/same70-xplained/netnsh: Added and verified a network-enabled NSH configuration for the SAME70-Xplained board (2015-11-20). + * net/: Remove CONFIG_NET_PINGADDRCONF. This was a uIP way of assigning + IP addresses, but is not standard and not a appropriate feature in + general (2015-12-01). diff --git a/arch b/arch index 93c52e9803..350314f22d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 93c52e98030b3f596c0c93008cdeb0f9d2c4d0fc +Subproject commit 350314f22d2357cf4f67b384c89eaa92715758c3 diff --git a/configs b/configs index eadf9704c9..a2aa9788c8 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit eadf9704c93f1a5cc0d90b78cf3cc9e5de26dbfc +Subproject commit a2aa9788c844ebebb9da4276310b4bd6d0f7a54c diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index cb90e462e1..1b3caf5087 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -398,34 +398,15 @@ int ipv4_input(FAR struct net_driver_s *dev) return udp_ipv4_input(dev); } - /* In most other cases, the device must be assigned a non-zero IP - * address. Another exception is when CONFIG_NET_PINGADDRCONF is - * enabled... - */ + /* In other cases, the device must be assigned a non-zero IP address. */ else #endif #ifdef CONFIG_NET_ICMP if (net_ipv4addr_cmp(dev->d_ipaddr, INADDR_ANY)) { -#ifdef CONFIG_NET_PINGADDRCONF - /* If we are configured to use ping IP address configuration and - * hasn't been assigned an IP address yet, we accept all ICMP - * packets. - */ - - if (pbuf->proto == IP_PROTO_ICMP) - { - nlldbg("Possible ping config packet received\n"); - icmp_input(dev); - goto drop; - } - else -#endif - { - nlldbg("No IP address assigned\n"); - goto drop; - } + nlldbg("No IP address assigned\n"); + goto drop; } /* Check if the packet is destined for out IP address */ diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 19fdea6482..f5be1751f0 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -204,10 +204,7 @@ int ipv6_input(FAR struct net_driver_s *dev) return udp_ipv6_input(dev); } - /* In most other cases, the device must be assigned a non-zero IP - * address. Another exception is when CONFIG_NET_PINGADDRCONF is - * enabled... - */ + /* In other cases, the device must be assigned a non-zero IP address. */ else #endif diff --git a/net/icmp/Kconfig b/net/icmp/Kconfig index 7eb504267f..9f38cef29a 100644 --- a/net/icmp/Kconfig +++ b/net/icmp/Kconfig @@ -18,15 +18,14 @@ if NET_ICMP config NET_ICMP_PING bool "ICMP ping interfaces" default n + depends on BUILD_FLAT ---help--- Provide interfaces to support application level support for for sending ECHO (ping) requests and associating ECHO replies. -config NET_PINGADDRCONF - bool "Ping address configuration" - default n - ---help--- - Use "ping" packet for setting IP address + NOTE: Calling these interfaces from application space is a + violation of the OS/application interface but for historical + reasons, is permitted in the flat build. endif # NET_ICMP endmenu # ICMP Networking Support diff --git a/net/icmp/icmp_input.c b/net/icmp/icmp_input.c index 8afbc1e6f1..6cc688ab7c 100644 --- a/net/icmp/icmp_input.c +++ b/net/icmp/icmp_input.c @@ -117,18 +117,6 @@ void icmp_input(FAR struct net_driver_s *dev) if (picmp->type == ICMP_ECHO_REQUEST) { - /* If we are configured to use ping IP address assignment, we use - * the destination IP address of this ping packet and assign it to - * ourself. - */ - -#ifdef CONFIG_NET_PINGADDRCONF - if (dev->d_ipaddr == 0) - { - dev->d_ipaddr = picmp->destipaddr; - } -#endif - /* Change the ICMP type */ picmp->type = ICMP_ECHO_REPLY; diff --git a/net/icmpv6/Kconfig b/net/icmpv6/Kconfig index d75172713d..62f4ca8943 100644 --- a/net/icmpv6/Kconfig +++ b/net/icmpv6/Kconfig @@ -19,10 +19,15 @@ if NET_ICMPv6 config NET_ICMPv6_PING bool "ICMPv6 ping interfaces" default n + depends on BUILD_FLAT ---help--- Provide interfaces to support application level support for for sending ECHO (ping) requests and associating ECHO replies. + NOTE: Calling these interfaces from application space is a + violation of the OS/application interface but for historical + reasons, is permitted in the flat build. + config NET_ICMPv6_NEIGHBOR bool "Solicit destination addresses" default n -- GitLab From c16648b3fd65fc33d8603a869d27e65241774072 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 12:54:57 -0600 Subject: [PATCH 401/858] Most cosmetic but also includes a fix for a compile problem from Ken Pettit --- drivers/mtd/mtd_onfi.c | 12 +++--------- drivers/net/enc28j60.h | 3 ++- net/icmp/icmp_send.c | 12 ------------ sched/timer/timer_create.c | 6 +++--- sched/timer/timer_release.c | 12 ------------ sched/timer/timer_settime.c | 2 +- 6 files changed, 9 insertions(+), 38 deletions(-) diff --git a/drivers/mtd/mtd_onfi.c b/drivers/mtd/mtd_onfi.c index 9a6f6c312a..aa4c6a09c0 100644 --- a/drivers/mtd/mtd_onfi.c +++ b/drivers/mtd/mtd_onfi.c @@ -113,17 +113,10 @@ *(volatile uint8_t *)((uintptr_t)a) = (uint8_t)d; \ } while (0) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ + /**************************************************************************** * Name: onfi_readstatus * @@ -216,6 +209,7 @@ bool onfi_have_embeddedecc(FAR struct onfi_pgparam_s *onfi) /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Name: onfi_compatible * @@ -340,7 +334,7 @@ int onfi_read(uintptr_t cmdaddr, uintptr_t addraddr, uintptr_t dataaddr, /* Get number of spare bytes per page (bytes 84-85 in the param table) */ - onfi->sparesize = *(FAR uint16_t *)(FAR voidFAR *)(parmtab + 84); + onfi->sparesize = *(FAR uint16_t *)(FAR void *)(parmtab + 84); /* Number of pages per block. */ diff --git a/drivers/net/enc28j60.h b/drivers/net/enc28j60.h index faa1546118..324efa4bac 100644 --- a/drivers/net/enc28j60.h +++ b/drivers/net/enc28j60.h @@ -460,7 +460,8 @@ #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif diff --git a/net/icmp/icmp_send.c b/net/icmp/icmp_send.c index 076d598a0c..b92e992704 100644 --- a/net/icmp/icmp_send.c +++ b/net/icmp/icmp_send.c @@ -59,18 +59,6 @@ #define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index a750a879b4..bf6429e3bc 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -76,7 +76,7 @@ * ********************************************************************************/ -static struct posix_timer_s *timer_allocate(void) +static FAR struct posix_timer_s *timer_allocate(void) { FAR struct posix_timer_s *ret; irqstate_t flags; @@ -177,8 +177,8 @@ static struct posix_timer_s *timer_allocate(void) int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid) { - struct posix_timer_s *ret; - WDOG_ID wdog; + FAR struct posix_timer_s *ret; + WDOG_ID wdog; /* Sanity checks. Also, we support only CLOCK_REALTIME */ diff --git a/sched/timer/timer_release.c b/sched/timer/timer_release.c index 85e5b857c3..05de32cd9e 100644 --- a/sched/timer/timer_release.c +++ b/sched/timer/timer_release.c @@ -48,18 +48,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - /******************************************************************************** * Private Functions ********************************************************************************/ diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 01be3a28ae..4df42217ee 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -195,7 +195,7 @@ static void timer_timeout(int argc, wdparm_t itimer) if (timer_release(u.timer)) { - /* If this is a repetitive timer, the restart the watchdog */ + /* If this is a repetitive timer, then restart the watchdog */ timer_restart(u.timer, itimer); } -- GitLab From ad64c033e78bf24fcae67e45489ffac7468ad358 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 14:56:20 -0600 Subject: [PATCH 402/858] s/procfs: The procfs file system can now be configured so that it supports a runtime registration of procfs entries with CONFIG_FS_PROCFS_REGISTER=y --- ChangeLog | 6 ++ arch | 2 +- fs/procfs/Kconfig | 12 +-- fs/procfs/fs_procfs.c | 171 +++++++++++++++++++++++++++++++------- include/nuttx/fs/procfs.h | 18 ++++ 5 files changed, 172 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08adf37518..8921efdc04 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11189,3 +11189,9 @@ * net/: Remove CONFIG_NET_PINGADDRCONF. This was a uIP way of assigning IP addresses, but is not standard and not a appropriate feature in general (2015-12-01). + * fs/procfs: The procfs file system can now be configured so that it + supports a runtime registration of procfs entries with + CONFIG_FS_PROCFS_REGISTER=y (2015-12-01). + * arch/arm/src/stm32/stm32_ccm_procfs.c: Is no longer a part of the + 'base' procfs entries and can now only be supported via run time + registration with CONFIG_FS_PROCFS_REGISTER=y (2015-12-01). diff --git a/arch b/arch index 350314f22d..0dc110a8fa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 350314f22d2357cf4f67b384c89eaa92715758c3 +Subproject commit 0dc110a8fa020ed7c301fe0cdcb836ee8ea939e9 diff --git a/fs/procfs/Kconfig b/fs/procfs/Kconfig index 2b4fe81af2..39d5011842 100644 --- a/fs/procfs/Kconfig +++ b/fs/procfs/Kconfig @@ -15,6 +15,13 @@ config FS_PROCFS if FS_PROCFS +config FS_PROCFS_REGISTER + bool "Run-time registration" + default n + ---help--- + Support run-time registration of the new entries in the procfs file + system. + menu "Exclude individual procfs entries" config FS_PROCFS_EXCLUDE_PROCESS @@ -59,10 +66,5 @@ config FS_PROCFS_EXCLUDE_SMARTFS depends on FS_SMARTFS default n -config FS_PROCFS_EXCLUDE_CCM - bool "Exclude CCM memory usage" - depends on STM32_CCM_PROCFS - default n - endmenu # endif # FS_PROCFS diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 951f3caa5d..d96fabca9a 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -104,7 +104,11 @@ extern const struct procfs_operations ccm_procfsoperations; ****************************************************************************/ /* Table of all known / pre-registered procfs handlers / participants. */ -static const struct procfs_entry_s g_procfsentries[] = +#ifdef CONFIG_FS_PROCFS_REGISTER +static const struct procfs_entry_s g_base_entries[] = +#else +static const struct procfs_entry_s g_procfs_entries[] = +#endif { #ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS { "[0-9]*/**", &proc_operations }, @@ -136,14 +140,18 @@ static const struct procfs_entry_s g_procfsentries[] = #if !defined(CONFIG_FS_PROCFS_EXCLUDE_UPTIME) { "uptime", &uptime_operations }, #endif - -#if defined(CONFIG_STM32_CCM_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CCM) - { "ccm", &ccm_procfsoperations }, -#endif }; -static const uint8_t g_procfsentrycount = sizeof(g_procfsentries) / +#ifdef CONFIG_FS_PROCFS_REGISTER +static const uint8_t g_base_entrycount = sizeof(g_base_entries) / + sizeof(struct procfs_entry_s); + +static FAR struct procfs_entry_s *g_procfs_entries; +static uint8_t g_procfs_entrycount; +#else +static const uint8_t g_procfs_entrycount = sizeof(g_procfs_entries) / sizeof(struct procfs_entry_s); +#endif /**************************************************************************** * Private Function Prototypes @@ -186,6 +194,14 @@ static int procfs_statfs(FAR struct inode *mountpt, static int procfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf); +/* Initialization */ + +#ifdef CONFIG_FS_PROCFS_REGISTER +int procfs_initialize(void); +#else +# define procfs_initialize() +#endif + /**************************************************************************** * Private Variables ****************************************************************************/ @@ -301,25 +317,25 @@ static int procfs_open(FAR struct file *filep, FAR const char *relpath, /* Perform the stat based on the procfs_entry operations */ - for (x = 0; x < g_procfsentrycount; x++) + for (x = 0; x < g_procfs_entrycount; x++) { /* Test if the path matches this entry's specification */ - if (match(g_procfsentries[x].pathpattern, relpath)) + if (match(g_procfs_entries[x].pathpattern, relpath)) { /* Match found! Stat using this procfs entry */ - DEBUGASSERT(g_procfsentries[x].ops && - g_procfsentries[x].ops->open); + DEBUGASSERT(g_procfs_entries[x].ops && + g_procfs_entries[x].ops->open); - ret = g_procfsentries[x].ops->open(filep, relpath, oflags, mode); + ret = g_procfs_entries[x].ops->open(filep, relpath, oflags, mode); if (ret == OK) { DEBUGASSERT(filep->f_priv); ((struct procfs_file_s *) filep->f_priv)->procfsentry = - &g_procfsentries[x]; + &g_procfs_entries[x]; } } } @@ -506,19 +522,19 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Search the static array of procfs_entries */ - for (x = 0; x < g_procfsentrycount; x++) + for (x = 0; x < g_procfs_entrycount; x++) { /* Test if the path matches this entry's specification */ - if (match(g_procfsentries[x].pathpattern, relpath)) + if (match(g_procfs_entries[x].pathpattern, relpath)) { /* Match found! Call the handler's opendir routine. If successful, * this opendir routine will create an entry derived from struct * procfs_dir_priv_s as dir->u.procfs. */ - DEBUGASSERT(g_procfsentries[x].ops && g_procfsentries[x].ops->opendir); - ret = g_procfsentries[x].ops->opendir(relpath, dir); + DEBUGASSERT(g_procfs_entries[x].ops && g_procfs_entries[x].ops->opendir); + ret = g_procfs_entries[x].ops->opendir(relpath, dir); if (ret == OK) { @@ -527,7 +543,7 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Set the procfs_entry handler */ dirpriv = (FAR struct procfs_dir_priv_s *)dir->u.procfs; - dirpriv->procfsentry = &g_procfsentries[x]; + dirpriv->procfsentry = &g_procfs_entries[x]; } return ret; @@ -535,7 +551,7 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Test for a sub-string match (e.g. "ls /proc/fs") */ - else if (strncmp(g_procfsentries[x].pathpattern, relpath, len) == 0) + else if (strncmp(g_procfs_entries[x].pathpattern, relpath, len) == 0) { FAR struct procfs_level1_s *level1; @@ -635,9 +651,9 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) * directory name. */ - while (index < priv->nentries + g_procfsentrycount) + while (index < priv->nentries + g_procfs_entrycount) { - name = g_procfsentries[index - priv->nentries].pathpattern; + name = g_procfs_entries[index - priv->nentries].pathpattern; while (*name != '/' && *name != '\0') { if (*name == '*' || *name == '[' || *name == '?') @@ -665,7 +681,7 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) * fs/nxffs */ - name = g_procfsentries[index - priv->nentries].pathpattern; + name = g_procfs_entries[index - priv->nentries].pathpattern; if (!level0->lastlen || (strncmp(name, level0->lastread, level0->lastlen) != 0)) { @@ -686,7 +702,7 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) /* Test if we are at the end of the directory */ - if (index >= priv->nentries + g_procfsentrycount) + if (index >= priv->nentries + g_procfs_entrycount) { /* We signal the end of the directory by returning the special * error -ENOENT @@ -763,13 +779,13 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) * subdirectory are listed in order in the procfs_entry array. */ - if (strncmp(g_procfsentries[level1->base.index].pathpattern, - g_procfsentries[level1->firstindex].pathpattern, + if (strncmp(g_procfs_entries[level1->base.index].pathpattern, + g_procfs_entries[level1->firstindex].pathpattern, level1->subdirlen) == 0) { /* This entry matches. Report the subdir entry */ - name = &g_procfsentries[level1->base.index].pathpattern[ + name = &g_procfs_entries[level1->base.index].pathpattern[ level1->subdirlen + 1]; level1->lastlen = strcspn(name, "/"); level1->lastread = name; @@ -859,6 +875,9 @@ static int procfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir) static int procfs_bind(FAR struct inode *blkdriver, const void *data, void **handle) { + /* Make sure that we are properly initialized */ + + procfs_initialize(); return OK; } @@ -933,23 +952,23 @@ static int procfs_stat(struct inode *mountpt, const char *relpath, /* Perform the stat based on the procfs_entry operations */ - for (x = 0; x < g_procfsentrycount; x++) + for (x = 0; x < g_procfs_entrycount; x++) { /* Test if the path matches this entry's specification */ - if (match(g_procfsentries[x].pathpattern, relpath)) + if (match(g_procfs_entries[x].pathpattern, relpath)) { /* Match found! Stat using this procfs entry */ - DEBUGASSERT(g_procfsentries[x].ops && - g_procfsentries[x].ops->stat); + DEBUGASSERT(g_procfs_entries[x].ops && + g_procfs_entries[x].ops->stat); - return g_procfsentries[x].ops->stat(relpath, buf); + return g_procfs_entries[x].ops->stat(relpath, buf); } /* Test for an internal subdirectory stat */ - else if (strncmp(g_procfsentries[x].pathpattern, relpath, len) == 0) + else if (strncmp(g_procfs_entries[x].pathpattern, relpath, len) == 0) { /* It's an internal subdirectory */ @@ -968,8 +987,98 @@ static int procfs_stat(struct inode *mountpt, const char *relpath, return ret; } +/**************************************************************************** + * Name: procfs_initialize + * + * Description: + * Configure the initial set of entries in the procfs file system. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure + * + ****************************************************************************/ + +#ifdef CONFIG_FS_PROCFS_REGISTER +int procfs_initialize(void) +{ + /* Are we already initialized? */ + + if (g_procfs_entries == NULL) + { + /* No.. allocate a modifyable list of entries */ + + g_procfs_entries = (FAR struct procfs_entry_s *) + kmm_malloc(sizeof(g_base_entries)); + + if (g_procfs_entries == NULL) + { + return -ENOMEM; + } + + /* And copy the fixed entries into the allocated array */ + + memcpy(g_procfs_entries, g_base_entries, sizeof(g_base_entries)); + g_procfs_entrycount = g_base_entrycount; + } + + return OK; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: procfs_register + * + * Description: + * Add a new entry to the procfs file system. + * + * Input Parameters: + * entry - Describes the entry to be registered. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure + * + ****************************************************************************/ + +#ifdef CONFIG_FS_PROCFS_REGISTER +int procfs_register(FAR const struct procfs_file_s *entry) +{ + FAR struct procfs_entry_s *newtable; + unsigned int newcount; + size_t newsize; + int ret; + + /* Make sure that we are properly initialized */ + + procfs_initialize(); + + /* realloc the procfs entries */ + + newcount = g_procfs_entrycount + 1; + newsize = newcount * sizeof(struct procfs_entry_s); + + sched_lock(); + newtable = (FAR struct procfs_entry_s *)realloc(g_procfs_entries, newsize); + if (newtable == NULL) + { + ret = -ENOMEM; + } + else + { + memcpy(&newtable[g_procfs_entrycount], entry, sizeof(struct procfs_entry_s)); + g_procfs_entrycount = newcount; + ret = OK; + } + + sched_unlock(); + return ret; +} +#endif + #endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */ diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index 7dfb6da123..3188f6159a 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -180,6 +180,24 @@ size_t procfs_memcpy(FAR const char *src, size_t srclen, FAR char *dest, size_t destlen, off_t *offset); +/**************************************************************************** + * Name: procfs_register + * + * Description: + * Add a new entry to the procfs file system. + * + * Input Parameters: + * entry - Describes the entry to be registered. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure + * + ****************************************************************************/ + +#ifdef CONFIG_FS_PROCFS_REGISTER +int procfs_register(FAR const struct procfs_file_s *entry); +#endif + #undef EXTERN #ifdef __cplusplus } -- GitLab From 7a7a8f5835c289b5966161d27aa522269938eafa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 15:04:57 -0600 Subject: [PATCH 403/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 0dc110a8fa..0f2e62c732 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0dc110a8fa020ed7c301fe0cdcb836ee8ea939e9 +Subproject commit 0f2e62c732d17ca8fc5b9f3f90ab37b5502279fe diff --git a/configs b/configs index a2aa9788c8..78bded3f7c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a2aa9788c844ebebb9da4276310b4bd6d0f7a54c +Subproject commit 78bded3f7c49fd74338741d797066e7592c633ae -- GitLab From eaa113a284a850969903db8d77129f356d61d2d7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 16:21:11 -0600 Subject: [PATCH 404/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 0f2e62c732..72f0597a15 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0f2e62c732d17ca8fc5b9f3f90ab37b5502279fe +Subproject commit 72f0597a154dad90e05130c47f870e68376db0b8 -- GitLab From 7483ed38ce3af50d78761ee193ac6c0bb86a5b9b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 16:31:40 -0600 Subject: [PATCH 405/858] Fix some procfs registration typos --- arch | 2 +- fs/procfs/fs_procfs.c | 2 +- include/nuttx/fs/procfs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 72f0597a15..63bee79ab5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 72f0597a154dad90e05130c47f870e68376db0b8 +Subproject commit 63bee79ab5f692cde88209ec72e00ae14de7204d diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index d96fabca9a..ddcd7c8c0c 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -1047,7 +1047,7 @@ int procfs_initialize(void) ****************************************************************************/ #ifdef CONFIG_FS_PROCFS_REGISTER -int procfs_register(FAR const struct procfs_file_s *entry) +int procfs_register(FAR const struct procfs_entry_s *entry) { FAR struct procfs_entry_s *newtable; unsigned int newcount; diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index 3188f6159a..c48be86d2f 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -195,7 +195,7 @@ size_t procfs_memcpy(FAR const char *src, size_t srclen, ****************************************************************************/ #ifdef CONFIG_FS_PROCFS_REGISTER -int procfs_register(FAR const struct procfs_file_s *entry); +int procfs_register(FAR const struct procfs_entry_s *entry); #endif #undef EXTERN -- GitLab From db6eeed3a62a4935ca6b53df2615f0074186abff Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Dec 2015 17:06:40 -0600 Subject: [PATCH 406/858] procfs: Using wrong reallocator --- fs/procfs/fs_procfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index ddcd7c8c0c..753e48ce8b 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -1064,7 +1064,7 @@ int procfs_register(FAR const struct procfs_entry_s *entry) newsize = newcount * sizeof(struct procfs_entry_s); sched_lock(); - newtable = (FAR struct procfs_entry_s *)realloc(g_procfs_entries, newsize); + newtable = (FAR struct procfs_entry_s *)kmm_realloc(g_procfs_entries, newsize); if (newtable == NULL) { ret = -ENOMEM; -- GitLab From acd3b47def53db18b3cf425e0931b781a14221cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 05:20:02 -0600 Subject: [PATCH 407/858] Fix problem in last change to the procfs: Forgot to save the reallocated table pointer! Also added warnings: There are some concurrency issues in the current implementation if you try to modify the procfs data structures will the procfs is mounted and possibly busy. --- configs | 2 +- fs/procfs/fs_procfs.c | 24 +++++++++++++++++++++++- include/nuttx/fs/procfs.h | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/configs b/configs index 78bded3f7c..7e02a47bfd 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 78bded3f7c49fd74338741d797066e7592c633ae +Subproject commit 7e02a47bfd113b95136dafe75ce2a6551534b7e4 diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 753e48ce8b..c9032560e6 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -1038,6 +1038,10 @@ int procfs_initialize(void) * Description: * Add a new entry to the procfs file system. * + * NOTE: This function should be called *prior* to mounting the procfs + * file system to prevent concurrency problems with the modification of + * the procfs data set while it is in use. + * * Input Parameters: * entry - Describes the entry to be registered. * @@ -1058,7 +1062,17 @@ int procfs_register(FAR const struct procfs_entry_s *entry) procfs_initialize(); - /* realloc the procfs entries */ + /* realloc the table of procfs entries. + * + * REVISIT: This reallocation may free memory previously used for the + * procfs entry table. If that table were actively in use, then that + * could cause procfs logic to use a stale memory pointer! We avoid that + * problem by requiring that the procfs file be unmounted when the new + * entry is added. That requirment, however, is not enforced explicitly. + * + * Locking the scheduler as done below is insufficient. As would be just + * marking the entries as volatile. + */ newcount = g_procfs_entrycount + 1; newsize = newcount * sizeof(struct procfs_entry_s); @@ -1067,11 +1081,19 @@ int procfs_register(FAR const struct procfs_entry_s *entry) newtable = (FAR struct procfs_entry_s *)kmm_realloc(g_procfs_entries, newsize); if (newtable == NULL) { + /* Reallocation failed! */ + ret = -ENOMEM; } else { + /* Copy the new entry at the end of the reallocated table */ + memcpy(&newtable[g_procfs_entrycount], entry, sizeof(struct procfs_entry_s)); + + /* Instantiate the reallocated table */ + + g_procfs_entries = newtable; g_procfs_entrycount = newcount; ret = OK; } diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index c48be86d2f..f11046735e 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -186,6 +186,10 @@ size_t procfs_memcpy(FAR const char *src, size_t srclen, * Description: * Add a new entry to the procfs file system. * + * NOTE: This function should be called *prior* to mounting the procfs + * file system to prevent concurrency problems with the modification of + * the procfs data set while it is in use. + * * Input Parameters: * entry - Describes the entry to be registered. * -- GitLab From 08213f830db502f07316d2dd1851d1b02f1b1805 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 05:30:52 -0600 Subject: [PATCH 408/858] poll() and select() should not be built if poll() is disabled --- arch | 2 +- drivers/Kconfig | 3 +++ fs/vfs/Make.defs | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 63bee79ab5..5c2e57602f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 63bee79ab5f692cde88209ec72e00ae14de7204d +Subproject commit 5c2e57602f96c5df32d1251df89332869c02c5c2 diff --git a/drivers/Kconfig b/drivers/Kconfig index 3ed0446dd3..3a3bf176a3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -11,6 +11,9 @@ config DISABLE_POLL supported. If you do not use poll() or select(), then you can select DISABLE_POLL to reduce the code footprint by a small amount. + This selection disables the poll() interface as well as interfaces + the derive from poll() such as select(). + config DEV_NULL bool "Enable /dev/null" default y diff --git a/fs/vfs/Make.defs b/fs/vfs/Make.defs index 4c3fca0258..645e23f97e 100644 --- a/fs/vfs/Make.defs +++ b/fs/vfs/Make.defs @@ -41,7 +41,7 @@ ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) # Socket descriptor support -CSRCS += fs_close.c fs_read.c fs_write.c fs_ioctl.c fs_poll.c fs_select.c +CSRCS += fs_close.c fs_read.c fs_write.c fs_ioctl.c # Support for network access using streams @@ -49,6 +49,12 @@ ifneq ($(CONFIG_NFILE_STREAMS),0) CSRCS += fs_fdopen.c endif +# Support for poll() and select() (which derives from poll() + +ifneq ($(CONFIG_DISABLE_POLL),y) +CSRCS += fs_poll.c fs_select.c +endif + # Support for sendfile() ifeq ($(CONFIG_NET_SENDFILE),y) -- GitLab From f4978c12d55c3ee9f0adbac43efff2d1feefabb7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 07:19:36 -0600 Subject: [PATCH 409/858] Update ChangeLog --- ChangeLog | 3 +++ arch | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8921efdc04..6baf77ffa5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11195,3 +11195,6 @@ * arch/arm/src/stm32/stm32_ccm_procfs.c: Is no longer a part of the 'base' procfs entries and can now only be supported via run time registration with CONFIG_FS_PROCFS_REGISTER=y (2015-12-01). + * arch/arm/src/samv7/sam_tc.c: Port the SAMA5 timer/counter driver + to the SAMV7 (2015-12-02). + diff --git a/arch b/arch index 5c2e57602f..446bc602bb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5c2e57602f96c5df32d1251df89332869c02c5c2 +Subproject commit 446bc602bbe82a47907f6125779ce15507a0d527 -- GitLab From d166dda8f64f89e97f8611d060ac37fff8fff69d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 08:28:32 -0600 Subject: [PATCH 410/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6baf77ffa5..eeac48ce5d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11197,4 +11197,6 @@ registration with CONFIG_FS_PROCFS_REGISTER=y (2015-12-01). * arch/arm/src/samv7/sam_tc.c: Port the SAMA5 timer/counter driver to the SAMV7 (2015-12-02). + * arm/arm/src/samv7/sam_tickless.c: Port the SAMA5/SAM4CM tickless + logic to the SAMV7 (2015-12-02). diff --git a/arch b/arch index 446bc602bb..c61c3b4e89 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 446bc602bbe82a47907f6125779ce15507a0d527 +Subproject commit c61c3b4e896eb9471399cfb287b4d6ea965ba9b4 -- GitLab From 7d3d49e227cd3d545ba6c7b8fcb0a6aecc578ac1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 09:22:58 -0600 Subject: [PATCH 411/858] Upate submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index c61c3b4e89..eb10f4be29 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c61c3b4e896eb9471399cfb287b4d6ea965ba9b4 +Subproject commit eb10f4be2942467023c3ebaaf6165712df0b0611 diff --git a/configs b/configs index 7e02a47bfd..f0ddedf6ae 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7e02a47bfd113b95136dafe75ce2a6551534b7e4 +Subproject commit f0ddedf6ae17ffd389083134c3c34fd547d3a4e3 -- GitLab From 7be7579f591dee554c454ca8ba504d1139760c67 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 10:47:32 -0600 Subject: [PATCH 412/858] Back out 522f95abe87d71c7025f2f358a8f350134e284b2: What was I thinking? --- fs/inode/fs_inodebasename.c | 38 ++++++++++++++----------------------- include/nuttx/semaphore.h | 6 +++--- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/fs/inode/fs_inodebasename.c b/fs/inode/fs_inodebasename.c index 6398d9854c..13a4486ba5 100644 --- a/fs/inode/fs_inodebasename.c +++ b/fs/inode/fs_inodebasename.c @@ -41,32 +41,16 @@ #include "inode/inode.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: inode_nextname + * Name: inode_basename * * Description: - * Given a path with node names separated by '/', return the next node - * name. + * Given a path with node names separated by '/', return name of last + * segment in the path. "" * ****************************************************************************/ @@ -84,13 +68,19 @@ FAR const char *inode_basename(FAR const char *name) * previous name that we saved is the basename. */ - if (*name == '\0') + if (name == NULL || *name == '\0') { - return basename; + /* Break out of the loop with basename pointer to the final + * segment of the path. + */ + + break; } - } - /* We won't get here */ + /* Set basename to point to the remainder of the path */ + + basename = name; + } - return NULL; + return basename; } diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 2eb624bf70..cfd0feb19d 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -60,12 +60,12 @@ struct inode; struct nsem_inode_s { - /* Inode payload unique to named semaphores. ns_sem must appear first in - * this structure in order to support casting between type sem_t and + /* Inode payload unique to named semaphores. ns_inode must appear first + * in this structure in order to support casting between type sem_t and * types of struct nsem_inode_s. */ - sem_t ns_sem; /* The semaphore */ FAR struct inode *ns_inode; /* Containing inode */ + sem_t ns_sem; /* The semaphore */ }; #endif -- GitLab From a43c29465277d37f8bab97ffb34289da2ac3ff85 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 14:10:24 -0600 Subject: [PATCH 413/858] Update ChangeLog --- ChangeLog | 4 +++- arch | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index eeac48ce5d..7a91f015bc 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11199,4 +11199,6 @@ to the SAMV7 (2015-12-02). * arm/arm/src/samv7/sam_tickless.c: Port the SAMA5/SAM4CM tickless logic to the SAMV7 (2015-12-02). - + * fs/semaphore: Named semaphores: Back out "fix" of 2015-10-22. It was + correct before. The change of 2015-10-22 probably broke named + semaphores (2015-12-02). diff --git a/arch b/arch index eb10f4be29..cbda8e191e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit eb10f4be2942467023c3ebaaf6165712df0b0611 +Subproject commit cbda8e191eec3c4b5ebe5da531e9d34600beb8a7 -- GitLab From a77786ddf1491bf99aa1b5894f9238168fc5aa1a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Dec 2015 18:09:57 -0600 Subject: [PATCH 414/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index cbda8e191e..3e4fa2c1aa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cbda8e191eec3c4b5ebe5da531e9d34600beb8a7 +Subproject commit 3e4fa2c1aa35bce85321352033b62241db7ae398 diff --git a/configs b/configs index f0ddedf6ae..0e8e6abcaa 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f0ddedf6ae17ffd389083134c3c34fd547d3a4e3 +Subproject commit 0e8e6abcaa593103af40aaa33e1fc5e56cbfd91d -- GitLab From 98c401a1f4e2d27867b8a946196cab40d326f684 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 3 Dec 2015 10:23:32 -0600 Subject: [PATCH 415/858] Update ChangeLog --- ChangeLog | 3 +++ arch | 2 +- configs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a91f015bc..b43487d5ab 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11202,3 +11202,6 @@ * fs/semaphore: Named semaphores: Back out "fix" of 2015-10-22. It was correct before. The change of 2015-10-22 probably broke named semaphores (2015-12-02). + * arch/arm/src/samv7: Bring programmable clock logic from SAMA5 into + SAMV7 (2015-12-03). + diff --git a/arch b/arch index 3e4fa2c1aa..36be121ac4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3e4fa2c1aa35bce85321352033b62241db7ae398 +Subproject commit 36be121ac4338b771633610d95cb75e5ddc3f3fd diff --git a/configs b/configs index 0e8e6abcaa..cbfce044c8 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0e8e6abcaa593103af40aaa33e1fc5e56cbfd91d +Subproject commit cbfce044c83ea4a720467276ca03bc84efc5fe55 -- GitLab From 2726f0ac7c4b005354eb04360274f15778a78152 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 3 Dec 2015 14:17:41 -0600 Subject: [PATCH 416/858] USB serial driver Kconfig: Select default sizes for serial buffers so that the can hold even multiples of the max packet size. --- arch | 2 +- drivers/usbdev/Kconfig | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/arch b/arch index 36be121ac4..12ef9caf3f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 36be121ac4338b771633610d95cb75e5ddc3f3fd +Subproject commit 12ef9caf3f708d62be342a097191fa1741e0464c diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig index a08c85e07f..70e2cf08c1 100644 --- a/drivers/usbdev/Kconfig +++ b/drivers/usbdev/Kconfig @@ -246,15 +246,25 @@ config PL2303_BULKIN_REQLEN config PL2303_RXBUFSIZE int "Receive buffer size" - default 256 + default 513 if USBDEV_DUALSPEED + default 257 if !USBDEV_DUALSPEED ---help--- - Size of the serial receive/transmit buffers + Size of the serial receive buffers. The actual amount of data that + can be held in the buffer is this number minus one due to the way + that the circular buffer is managed. So an RX buffer size of 257 + will hold four full-speed, 64 byte packets; a buffer size of 513 + will hold one high-speed, 512 byte packet. config PL2303_TXBUFSIZE int "Transmit buffer size" - default 256 + default 513 if USBDEV_DUALSPEED + default 257 if !USBDEV_DUALSPEED ---help--- - Size of the serial receive/transmit buffers + Size of the serial transmit buffers. The actual amount of data that + can be held in the buffer is this number minus one due to the way + that the circular buffer is managed. So a TX buffer size of 257 + will hold four full-speed, 64 byte packets; a buffer size of 513 + will hold one high-speed, 512 byte packet. config PL2303_VENDORID hex "Vendor ID" @@ -421,15 +431,25 @@ config CDCACM_BULKIN_REQLEN config CDCACM_RXBUFSIZE int "Receive buffer size" - default 256 + default 513 if USBDEV_DUALSPEED + default 257 if !USBDEV_DUALSPEED ---help--- - Size of the serial receive/transmit buffers + Size of the serial receive buffers. The actual amount of data that + can be held in the buffer is this number minus one due to the way + that the circular buffer is managed. So an RX buffer size of 257 + will hold four full-speed, 64 byte packets; a buffer size of 513 + will hold one high-speed, 512 byte packet. config CDCACM_TXBUFSIZE int "Transmit buffer size" - default 256 - ---help--- - Size of the serial receive/transmit buffers + default 513 if USBDEV_DUALSPEED + default 257 if !USBDEV_DUALSPEED + ---help--- + Size of the serial transmit buffers. The actual amount of data that + can be held in the buffer is this number minus one due to the way + that the circular buffer is managed. So a TX buffer size of 257 + will hold four full-speed, 64 byte packets; a buffer size of 513 + will hold one high-speed, 512 byte packet. config CDCACM_VENDORID hex "Vendor ID" -- GitLab From 745a16db48d8deb7b0722781affb8be6742c2e21 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 4 Dec 2015 10:55:04 -0600 Subject: [PATCH 417/858] Update ChangeLog --- ChangeLog | 5 ++++- arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b43487d5ab..dc3b3c7321 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11204,4 +11204,7 @@ semaphores (2015-12-02). * arch/arm/src/samv7: Bring programmable clock logic from SAMA5 into SAMV7 (2015-12-03). - + * arch/arm/src/samv7: Add PCK6 as an optional source for the timer/ + counter clock (2015-12-04). + * configs/samv7-xult/: If Tickless mode is selected then enable PCK6i + as a timer/counter clock source diff --git a/arch b/arch index 12ef9caf3f..d4d2f2f588 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 12ef9caf3f708d62be342a097191fa1741e0464c +Subproject commit d4d2f2f588ab859dd6b1a73aa41187344f442c20 diff --git a/configs b/configs index cbfce044c8..ce0b4882db 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit cbfce044c83ea4a720467276ca03bc84efc5fe55 +Subproject commit ce0b4882db75aa011f48541c75149c0f050174c5 -- GitLab From d4e8e85a8593231d1a8ba45efb3e5074796e4918 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 4 Dec 2015 12:37:59 -0600 Subject: [PATCH 418/858] Upate submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index ce0b4882db..3afa4d70be 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ce0b4882db75aa011f48541c75149c0f050174c5 +Subproject commit 3afa4d70be78fc6a43aa7b05fe3d1d39884799aa -- GitLab From 7bcb86a15488021e1d95939946a1a73709cde5bd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Dec 2015 08:26:14 -0600 Subject: [PATCH 419/858] Prep for 7.13 release --- ChangeLog | 20 ++-- Documentation | 2 +- ReleaseNotes | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 290 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc3b3c7321..45b1b4af3c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11004,7 +11004,7 @@ sets the queued indication and the logic that does the actual queuing must be atomic (2015-09-20). -7.13 2015-xx-xx Gregory Nutt +7.13 2015-12-05 Gregory Nutt * libc/stdlib/lib_bsearch.c and include/stdlib.h: Add the bsearch() function from NetBSD (2015-10-02). @@ -11020,7 +11020,7 @@ * stm32 F4: Fix some TIM12 pin mappings. From Max Kriegleder (2015-10-9). * fs/tmpfs: TMPFS file system is code complete and bascially functional - although it has not been heavilay tested (2015-10-9). + although it has not been heavily tested (2015-10-9). * drivers/input/button_upper.c and include/nuttx/input/buttons.h: Add a driver to support application access to board buttons (2015-10-12). * drivers/input/button_lower.c: Add a generic lower half button driver. @@ -11097,7 +11097,7 @@ include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h (2015-11-16). * drivers/mtd/at24xx.c: Add support for multiple AT24xx EEPROM parts, - each with unique I2C addresses, but otherwise idential (2015-11-17). + each with unique I2C addresses, but otherwise identical (2015-11-17). * drivers/timers/ds3231.c: Add support for the DS3231 I2C RTC. Untested on the initial commit (2015-11-17). * arch/arm/src/stm32/stm32_tim_lowerhalf.c: Add a compatible lower-half @@ -11122,7 +11122,7 @@ * drivers/mtd/smart.c: Fixed SmartFS wear level error that occurs when the logical sector size is too small to save all wear level status bytes in a single sector. Logical sectors 1 and 2 were simply not - being allocated and then the read_sector and write_sector routinesi + being allocated and then the read_sector and write_sector routines were failing. From Ken Pettit (2015-11-18). * drivers/timers/ds3231.c: Untested support for DS1302 and DS3232. Also definitions for the DS3234, but that is an unsupported SPI RTC @@ -11153,9 +11153,9 @@ RPortrait, and RLandscript should work correly now. They were displayed mirrored. From Marco Krahl (2015-11-25). * drivers/mtd/mtd/mtd_procfs/c and include/nuttx/mtd/mtd.h: Add an - interface to un-regiser an MTD procfs entry. From Ken Pettit + interface to un-register an MTD procfs entry. From Ken Pettit (2015-11-25). - * drivers/mtd/filemtd.c: New new MTD conversion layer that will + * drivers/mtd/filemtd.c: A new MTD conversion layer that will convert a regular file (or driver file) to an MTD device. This is useful for testing on the simulation using the hostfs. From Ken Pettit (2015-11-25). @@ -11164,7 +11164,7 @@ Rather, these functions are now available as IOCTL commands to the loop driver (2015-11-25). * include/nuttx/net/netdev.h and several Ethernet drivers in arch/: - Most network drivers to not support statistics. Those that do only + Most network drivers do not support statistics. Those that do only support them when DEBUG is enabled. Each driver collects an architecture specific set of statistics and there is no mechanism in place to view those statistics. Thus, the driver feature was mostly @@ -11206,5 +11206,7 @@ SAMV7 (2015-12-03). * arch/arm/src/samv7: Add PCK6 as an optional source for the timer/ counter clock (2015-12-04). - * configs/samv7-xult/: If Tickless mode is selected then enable PCK6i - as a timer/counter clock source + * configs/samv7-xult/: If Tickless mode is selected then enable PCK6 + as a timer/counter clock source (2015-12-04). + +7.14 2015-xx-xx Gregory Nutt diff --git a/Documentation b/Documentation index 7d0cbe27b2..c344ebc453 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 7d0cbe27b2a41690f6c16dfda4ba03fdfa71726f +Subproject commit c344ebc4538d51ff0acc22122e42dbd8614f261c diff --git a/ReleaseNotes b/ReleaseNotes index 60634816ac..b68cdb7fa4 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -9913,3 +9913,281 @@ detailed bugfix information): - Macros PR_BEGIN_EXTERN_C and PR_END_EXTERN_C were not defined in all contexts. Replace with explicit expansion in all cases. From Stefan Kolb. + +NuttX-7.13 Release Notes +------------------------ + +The 113th release of NuttX, Version 7.13, was made on December 5, 2015, +and is available for download from the Bitbucket.org website. Note +that release consists of two tarballs: nuttx-7.13.tar.gz and +apps-7.13.tar.gz. These are available from: + + https://bitbucket.org/patacongo/nuttx/downloads + https://bitbucket.org/nuttx/apps/downloads + +Both may be needed (see the top-level nuttx/README.txt file for build +information). + +Additional new features and extended functionality: + + * Core OS: + + - External RTC: Added OS support for external RTC chips. + - boardctl(): Add a command to the boardctl() interface to obtain a + board unique ID. + + * File Systems: + + - TMPFS: Add support for a new TMPFS, RAM file system. The TMPFS + file system does not require any significant amount of memory + itself. It will grow dynamically as files are added and shrink back + when files are deleted. A very low overhead way to retain temporary + files. + - VFS: The VFS was extended to support standard file operations on + block drivers (open, close, read, write, etc.). The open() interface + accomplishes this by creating a temporary characer driver to mediate + the character oriented accesses to tje block driver. + - HOSTFS: Added a HOSTFS file system for use with the simulator. The + HOSTFS file system mounts in the simulated Nuttx context by provides + proxied access to the file system on the host PC. This is useful for + providing file system content and nonvolatile storage of files in the + simulation environment. From Ken Pettit. + - MTD/PROCFS: Add an interface to un-register an MTD procfs entry. + From Ken Pettit. + - filemtd: A new MTD conversion layer that will convert a regular file + (or driver file) to an MTD device. This is useful for testing on the + simulation using the HOSTFS. From Ken Pettit. + - PROCFS: Extended to include networking entries in the procfs. Device + status, device statistics, and network statistics are now available + from the PROCFS. + - PROCFS: The PROCFS file system can now be configured so that it + supports runtime registration of PROCFS entries with + CONFIG_FS_PROCFS_REGISTER=y. + + * Graphics/Graphic Drivers: + + - ST7565 Driver: Extend to include support for the ERC12864-3. From + Pierre-noel Bouteville. + + * Common Device Drivers: + + - User buttons: Added a character driver to support application access + to board buttons. Supports notification of button activity via + signals. + - User LEDs: Added a character driver to support application access + to on-board LEDs. + - Zero Cross: Added a Zero Cross device driver support. From Alan + Carvalho de Assis. + - MAX6675: Added support to Thermocouple-to-Digital converter MAX6675. + From Alan Carvalho de Assis. + - BCH: Block-to-character (BCH) driver should forward ioctl() calls + to the contained block driver. + - S25FL1xx: Added a S25FL1xx QuadSPI FLASH driver. + - On-Chip FLASH: Added an upper half MTD device that can use the + interfaces defined in included/nuttx/progmem.h to provide a + standard MTD driver. + - Serial: Implemented high level DMA infrastructure for serial + devices. From Max Neklyudov. + - AT24XX: Add support for multiple AT24xx EEPROM parts, each with + unique I2C addresses, but otherwise identical. + - External RTC: Added drivers for external I2C RTC chips: DS3102, + DS1307, DS3231, DS3232, and NXP PCF85263. + - W25: Added support for byte write mode to the W25 FLASH driver. From + Ken Pettit. + - dev/loop: Added a loop character device. losetup() and loteardown() + should not be called directory from applications. Rather, these + functions are now available as IOCTL commands to the loop driver. + - dev/smart: Added support for a /dev/smart loop device. From Ken + Pettit. + + * Networking: + + - Driver Statistics: Most network drivers do not support statistics. + Those that do only supported them when DEBUG is enabled. Each + driver collected an architecture specific set of statistics and + there was no common mechanism to view those statistics. Thus, + the driver feature was mostly useless. This release standardizes + the driver statistics and puts the definition in the common network + device structure defined in netdev.h where they can be accessed by + network applications. All Ethernet drivers that collect statistics + have been adapted to use these common statistics. + + * Simulation Platform: + + - W25 FLASH: Added support for W25 FLASH simulation. From Ken Pettit. + - HOSTFS: Added support for the HOSTFS file system (see "File Systems", + above). + + * Atmel SAMV7: + + - SAME70: Added support for the SAME70 family of chips. + - Tickless: SAMV7 now supports the tickless mode of operation. + + * Atmel SAMV7 Drivers: + + - MPU: Added MPU and protected build support. + - QSPI: Added a QuadSPI FLASH driver. This driver operates in the + memory-mapped, Serial Memory Mode (SMM). + - FLASH: Added support to write on-chip FLASH. + - Timer/Counter: TC driver ported to SAMV7 from the SAMA5. Free-running + and one-short timer logic also ported. + - PCK: Brought programmable clock (PCK) logic from SAMA5 into SAMV7. + - Timer/Counter: Support PCK6 as an optional source for the timer/ + counter clock. + + * Atmel SAMV7 Boards: + + - SAME70-Xplained: Add NSH and networking configurations for the + SAME70 Xplained board. Includes verified support for serial console, + LEDs, buttons, SDRAM, HSMCI SD card, and networking. + - SAMV7-XULT and SAME70-Xplained: If Tickless mode is selected then + enable PCK6 as a timer/counter clock source + + * STMicro STM32: + + - CCM PROCFS: Is no longer a part of the 'base' procfs entries and can + now only be supported via run time registration with + CONFIG_FS_PROCFS_REGISTER=y. + + * STMicro STM32 Drivers: + + - Timers: Add a compatible lower-half timer driver for use with the + common timer upper-half driver. From Wail Khemir. + + * STMicro STM32 Boards: + + - STM32F4-Discovery: Add low level support for the Zero Cross driver + for the STM32F4-Discovery. From Alan Carvalho de Assis. + - STM32F4-Discovery: Add board config to support for the MAX6675. From + Alan Carvalho de Assis. + + * C Library/Header Files: + + - bsearch(): Added the bsearch() function from NetBSD. + - freopen(): Added support for freopen(). + - strftime(): Added day-of-week support (when avaialable). + + * Tools: + + - nxstyle: Add crappy style checking tool nxstyle.c. See thee tools/ + README file for more info. + + * Applications: NSH + + - mksmartfs command: Add configuration option to supported multiple + rootdirectories. From Ken Pettit. + - Add support for 'basename' and 'dirname' commands. + - set command: Like bash, NSH set command now strips off any leading + or trailing whitespace. + - mount command: The mount commands now accepts mount options + (currently needed only for the hostfs file system). From Ken + Pettit. + - losetup command: NSH no longer calls losetup() and loteardown + directly. Now it opens /dev/loop and accomplishes these things + using ioctl() calls. + - ifconfig command: If CONFIG_NETDEV_STATISTICS=y, then print the + network driver statistics in the ifconfig. + - ifconfig, ifup, and ifdown: These commands now uses /proc/net/ + to view network device configuration and status and /proc/net/stat + to show network statistics. A consequence of this is that you + cannot view this network information if the procfs is not enabled + and mounted at /proc. + - losmart command: Added a new NSH losmart command. losmart setups + up a loop device for the smart MTD driver similar to losetup but + with different syntax. From Ken Pettit. + - ps command: The 'ps' command now uses /proc// to obtain task + status information. A consequence of this is that you cannot use + the 'ps' command if the procfs is not enabled and mounted at /proc. + + * Applications: apps/system: + + - apps/system/hexed: Port the hexed command line hexadeciamal editor + to Nuttx. See http://apps.venomdev.net/hexed/. + + * Applications: apps/fsutils: + + - apps/fsutils/smartfs: Move into apps/fsutils from kernel, now uses + only open and ioctl. From Ken Pettit. + + * Applications: apps/examples: + + - apps/examples/fstest: Add a generic file system test. This is + essentially the same as examples/smart, but has all of the SmartFS + specific logic ripped out. This was created for testing the new + TMPFS. + - apps/examples/zerocross: Add a Zero Cross application example. From + Alan Carvalho de Assis. + - apps/examples/media: Add a simple test for access of media via a + block driver or MTD driver. + +Bugfixes. Only the most critical bugfixes are listed here (see the +ChangeLog for the complete list of bugfixes and for additional, more +detailed bugfix information): + + * Core OS: + + - Fixed an error in clock_timespec_subtract(). Found by Lok. + - pthreads: CRITICAL BUGFIX: Logic was wiping out the indication that + of the type of a pthread. Hence, it could be confused as a task. + Found because this was causing a crash when /proc/nnn/cmdline was + printed. + + * File System/Block Drivers: + + - SMART MTD: Fix some Smart wear-leveling bugs. Fixed SmartFS wear + level error that occurs when the logical sector size is too small to + save all wear level status bytes in a single sector. Logical + sectors 1 and 2 were simply not being allocated and then the + read_sector and write_sector routines were failing. From Ken + Pettit. + + * Graphics/Graphic Drivers: + + - ILI9432: Fixed errors in orientation. Portrait, RPortrait, and + Landscript should work correly now. They were displayed mirrored. + From Marco Krahl. + + * Common Drivers: + + - CAN: Fix a problem in the CAN upper-half driver that occurs only + for CAN hardware that support a H/W FIFO of outgoing CAN messages. + In this case, there can be a hang condition if both the H/W and + S/W FIFOs are both full. In that case, there may be no event to + awaken the upper half driver. Add a new (conditional) CAN upper + half interface called can_txready() that can be used by the lower + half driver to avoid this hang condition. + - MS58xx: Fix some issues with initialization and with CRC + calculation. From Karim Keddam. + - W25: Fixed W25 FLASH driver page read/write logic. From Ken Pettit. + + * Atmel SAMV7 Drivers: + + - USART1 pin configuration: Reconfigure System I/O when using USART1. + From Frank Benkert. + - MCAN: Added a call to can_txready() to the MCAN driver. + + * STMicro STM32 Drivers: + + - stm32 F4: Fix some TIM12 pin mappings. From Max Kriegleder. + + * STMicro STM32 Boards: + + - STM32F429i-Disco: Calculated partition boundries based on page + block sizes but mtd_partition() is expecting calculations based on + erase block size. From Alan Carvalho de Assis. + + * C Library/Header Files: + + - sys/types.h: When building on a 64-bit machine, the size of size_t + should be 64-bits. In general, I believe that sizeof(size_t) should + be the same as sizeof(uinptr_t). mmsize_t should always be 32-bits + in any event. The last change to stddef has been backed out. With + these changes, the simulator builds without errors or warnings an a + 64-bit machine. + + * Applications: apps/nshlib: + + - The I/O buffer, g_iobuffer, should not be a global buffer. That + will not work in an environment where there are multiple NSH + sessions. The I/O buffer must, instead, be a part part of the + session-specific data defined in nsh_console.h. -- GitLab From 59b912477e4f0aa2debb46c454cf133706b469ec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Dec 2015 10:36:00 -0600 Subject: [PATCH 420/858] Fix some warnings: Mismatched prototypes --- arch | 2 +- drivers/rwbuffer.c | 17 ++++++++--------- net/arp/arp_timer.c | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch b/arch index d4d2f2f588..0d52e827d4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d4d2f2f588ab859dd6b1a73aa41187344f442c20 +Subproject commit 0d52e827d460d28409934e0a488266f9e036a46f diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index 9cd2a6d60d..46d6fbefda 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -747,10 +747,10 @@ void rwb_uninitialize(FAR struct rwbuffer_s *rwb) * Name: rwb_read ****************************************************************************/ -int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32_t nblocks, - FAR uint8_t *rdbuffer) +ssize_t rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, + size_t nblocks, FAR uint8_t *rdbuffer) { - uint32_t remaining; + size_t remaining; int ret = OK; fvdbg("startblock=%ld nblocks=%ld rdbuffer=%p\n", @@ -822,7 +822,7 @@ int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32_t nblocks, if (ret < 0) { fdbg("ERROR: Failed to fill the read-ahead buffer: %d\n", ret); - return ret; + return (ssize_t)ret; } } } @@ -846,15 +846,15 @@ int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32_t nblocks, } #endif - return ret; + return (ssize_t)ret; } /**************************************************************************** * Name: rwb_write ****************************************************************************/ -int rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock, - size_t nblocks, FAR const uint8_t *wrbuffer) +ssize_t rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock, + size_t nblocks, FAR const uint8_t *wrbuffer) { int ret = OK; @@ -917,10 +917,9 @@ int rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock, ret = rwb->wrflush(rwb->dev, wrbuffer, startblock, nblocks); } - #endif - return ret; + return (ssize_t)ret; } /**************************************************************************** diff --git a/net/arp/arp_timer.c b/net/arp/arp_timer.c index b610e7b8a5..cec202ae41 100644 --- a/net/arp/arp_timer.c +++ b/net/arp/arp_timer.c @@ -88,7 +88,7 @@ static WDOG_ID g_arptimer; /* ARP timer */ * ****************************************************************************/ -static void arptimer_poll(int argc, uint32_t arg, ...) +static void arptimer_poll(int argc, wdparm_t arg, ...) { /* Call the ARP timer function every 10 seconds. */ -- GitLab From cbd9de2421296fb3d2260a39da5c2e1e0a45ca05 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Dec 2015 08:56:23 -0600 Subject: [PATCH 421/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45b1b4af3c..2eb1b7dba9 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11210,3 +11210,7 @@ as a timer/counter clock source (2015-12-04). 7.14 2015-xx-xx Gregory Nutt + + * arch/arm/src/samv7: Port the TRNG driver from the SAMA5D3/4 to the + SAMV7 (2015-12-06). + diff --git a/arch b/arch index 0d52e827d4..189e549966 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0d52e827d460d28409934e0a488266f9e036a46f +Subproject commit 189e549966b8004b6e433bf3af5d4d9cf031f3ae diff --git a/configs b/configs index 3afa4d70be..72b5c56406 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3afa4d70be78fc6a43aa7b05fe3d1d39884799aa +Subproject commit 72b5c56406f3c60cb47a726efcfc7fb020ad8673 -- GitLab From d6a035d58158ed07a9c018257f3f016dd9b9a3ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Dec 2015 09:31:07 -0600 Subject: [PATCH 422/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2eb1b7dba9..7efbd87bde 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11213,4 +11213,6 @@ * arch/arm/src/samv7: Port the TRNG driver from the SAMA5D3/4 to the SAMV7 (2015-12-06). + * arch/arm/src/samv7: Port the WDT driver from the SAMA5D3/4 to the + SAMV7 (s015-12-06). diff --git a/arch b/arch index 189e549966..c4289026cc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 189e549966b8004b6e433bf3af5d4d9cf031f3ae +Subproject commit c4289026cc1be4d85accd4e3c7e672479e5189b1 -- GitLab From 3f0bb06c540cada09b758d1da8c64841dd9d795b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Dec 2015 16:41:50 -0600 Subject: [PATCH 423/858] Update ChangeLog --- ChangeLog | 1 + TODO | 1 + arch | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7efbd87bde..01cb1230ae 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11215,4 +11215,5 @@ SAMV7 (2015-12-06). * arch/arm/src/samv7: Port the WDT driver from the SAMA5D3/4 to the SAMV7 (s015-12-06). + * arch/arm/src/samv7: Add an RSWDT driver (2015-12-06). diff --git a/TODO b/TODO index 9bfa1c79d4..46882e7781 100644 --- a/TODO +++ b/TODO @@ -457,6 +457,7 @@ o Kernel/Protected Build Description: The NSH 'free' command only shows memory usage in the user heap only, not usage in the kernel heap. I am thinking that kernel heap memory usage should be available in /proc/memory. + Better /proc/kmm Status: Open Priority: Medium/High diff --git a/arch b/arch index c4289026cc..52b36cad74 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c4289026cc1be4d85accd4e3c7e672479e5189b1 +Subproject commit 52b36cad744faaef7e67eb25265268a808d9da59 -- GitLab From 057b6aef2c9ff26c625688c407686187b7fa388f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Dec 2015 09:26:57 -0600 Subject: [PATCH 424/858] drivers/net: Move the Telnet driver from apps/netutils/netnetd to drivers/net --- ChangeLog | 3 + drivers/net/Kconfig | 27 ++ drivers/net/Make.defs | 4 + drivers/net/telnet.c | 865 +++++++++++++++++++++++++++++++++++++ include/nuttx/net/telnet.h | 69 +++ 5 files changed, 968 insertions(+) create mode 100644 drivers/net/telnet.c create mode 100644 include/nuttx/net/telnet.h diff --git a/ChangeLog b/ChangeLog index 01cb1230ae..a0ce6054be 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11216,4 +11216,7 @@ * arch/arm/src/samv7: Port the WDT driver from the SAMA5D3/4 to the SAMV7 (s015-12-06). * arch/arm/src/samv7: Add an RSWDT driver (2015-12-06). + * drivers/net/telnet.c: Move the Telnet driver from apps/netutils/telnetd + to drivers/net. It is a driver a belongs in the OS. There are still + some interface related issues, however (2015-12-07). diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index c1461e9153..49ad8d710f 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -16,6 +16,33 @@ config NETDEV_LOOPBACK networking devices that are enabled must be compatible with CONFIG_NET_NOINTS. +config NETDEV_TELNET + bool "Telnet driver" + default n + depends on NET && NET_TCP + ---help--- + The Telnet driver generates a character driver instance to support a + Telnet session. This driver is used by the Telnet daemon. The + Telnet daeman will instantiate a new Telnet driver to support + standard I/O on the new Telnet session. + +if NETDEV_TELNET + +config TELNET_RXBUFFER_SIZE + int "Telnet RX buffer size" + default 256 + +config TELNET_TXBUFFER_SIZE + int "Telnet TX buffer size" + default 256 + +config TELNET_DUMPBUFFER + bool "Dump Telnet buffers" + default n + depends on DEBUG_NET + +endif # NETDEV_TELNET + config NETDEV_MULTINIC bool "Multiple network interface support" default n if !NETDEV_LOOPBACK diff --git a/drivers/net/Make.defs b/drivers/net/Make.defs index e09162c00c..fe68efb267 100644 --- a/drivers/net/Make.defs +++ b/drivers/net/Make.defs @@ -43,6 +43,10 @@ ifeq ($(CONFIG_NETDEV_LOOPBACK),y) CSRCS += loopback.c endif +ifeq ($(CONFIG_NETDEV_TELNET),y) + CSRCS += telnet.c +endif + ifeq ($(CONFIG_NET_DM90x0),y) CSRCS += dm90x0.c endif diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c new file mode 100644 index 0000000000..b935a5b457 --- /dev/null +++ b/drivers/net/telnet.c @@ -0,0 +1,865 @@ +/**************************************************************************** + * apps/netutils/telnet_driver.c + * + * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This is a leverage of similar logic from uIP which has a compatible BSD + * license: + * + * Author: Adam Dunkels + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute, NuttX nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_TELNET_RXBUFFER_SIZE +# define CONFIG_TELNET_RXBUFFER_SIZE 256 +#endif + +#ifndef CONFIG_TELNET_TXBUFFER_SIZE +# define CONFIG_TELNET_TXBUFFER_SIZE 256 +#endif + +/* Telnet protocol stuff ****************************************************/ + +#define ISO_nl 0x0a +#define ISO_cr 0x0d + +#define TELNET_IAC 255 +#define TELNET_WILL 251 +#define TELNET_WONT 252 +#define TELNET_DO 253 +#define TELNET_DONT 254 + +/* Device stuff *************************************************************/ + +#define TELNETD_DEVFMT "/dev/telnet%d" + +/**************************************************************************** + * Private Types + ****************************************************************************/ +/* The state of the telnet parser */ + +enum telnet_state_e +{ + STATE_NORMAL = 0, + STATE_IAC, + STATE_WILL, + STATE_WONT, + STATE_DO, + STATE_DONT +}; + +/* This structure describes the internal state of the driver */ + +struct telnet_dev_s +{ + sem_t td_exclsem; /* Enforces mutually exclusive access */ + uint8_t td_state; /* (See telnet_state_e) */ + uint8_t td_pending; /* Number of valid, pending bytes in the rxbuffer */ + uint8_t td_offset; /* Offset to the valid, pending bytes in the rxbuffer */ + uint8_t td_crefs; /* The number of open references to the session */ + int td_minor; /* Minor device number */ + FAR struct socket td_psock; /* A clone of the internal socket structure */ + char td_rxbuffer[CONFIG_TELNET_RXBUFFER_SIZE]; + char td_txbuffer[CONFIG_TELNET_TXBUFFER_SIZE]; +}; + +/* This structure contains global information visable to all telnet driver + * instances. + */ + +struct telnet_common_s +{ + sem_t tc_exclsem; /* Enforces exclusive access to 'minor' */ + int tc_minor; /* The next minor number to use */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* Support functions */ + +#ifdef CONFIG_TELNET_DUMPBUFFER +static inline void telnet_dumpbuffer(FAR const char *msg, + FAR const char *buffer, unsigned int nbytes); +#else +# define telnet_dumpbuffer(msg,buffer,nbytes) +#endif +static void telnet_getchar(FAR struct telnet_dev_s *priv, uint8_t ch, + FAR char *dest, int *nread); +static ssize_t telnet_receive(FAR struct telnet_dev_s *priv, + FAR const char *src, size_t srclen, FAR char *dest, + size_t destlen); +static bool telnet_putchar(FAR struct telnet_dev_s *priv, uint8_t ch, + int *nwritten); +static void telnet_sendopt(FAR struct telnet_dev_s *priv, uint8_t option, + uint8_t value); + +/* Character driver methods */ + +static int telnet_open(FAR struct file *filep); +static int telnet_close(FAR struct file *filep); +static ssize_t telnet_read(FAR struct file *, FAR char *, size_t); +static ssize_t telnet_write(FAR struct file *, FAR const char *, size_t); +static int telnet_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_telnet_fops = +{ + telnet_open, /* open */ + telnet_close, /* close */ + telnet_read, /* read */ + telnet_write, /* write */ + 0, /* seek */ + telnet_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +/* Global information shared amongst telnet driver instanaces. */ + +static struct telnet_common_s g_telnet_common = +{ + SEM_INITIALIZER(1), + 0 +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: telnet_dumpbuffer + * + * Description: + * Dump a buffer of data (debug only) + * + ****************************************************************************/ + +#ifdef CONFIG_TELNET_DUMPBUFFER +static inline void telnet_dumpbuffer(FAR const char *msg, + FAR const char *buffer, + unsigned int nbytes) +{ + /* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_NET have to be + * defined or the following does nothing. + */ + + nvdbgdumpbuffer(msg, (FAR const uint8_t*)buffer, nbytes); +} +#endif + +/**************************************************************************** + * Name: telnet_getchar + * + * Description: + * Get another character for the user received buffer from the RX buffer + * + ****************************************************************************/ + +static void telnet_getchar(FAR struct telnet_dev_s *priv, uint8_t ch, + FAR char *dest, int *nread) +{ + register int index; + + /* Ignore carriage returns */ + + if (ch != ISO_cr) + { + /* Add all other characters to the destination buffer */ + + index = *nread; + dest[index++] = ch; + *nread = index; + } +} + +/**************************************************************************** + * Name: telnet_receive + * + * Description: + * Process a received Telnet buffer + * + ****************************************************************************/ + +static ssize_t telnet_receive(FAR struct telnet_dev_s *priv, FAR const char *src, + size_t srclen, FAR char *dest, size_t destlen) +{ + int nread; + uint8_t ch; + + nllvdbg("srclen: %d destlen: %d\n", srclen, destlen); + + for (nread = 0; srclen > 0 && nread < destlen; srclen--) + { + ch = *src++; + nllvdbg("ch=%02x state=%d\n", ch, priv->td_state); + + switch (priv->td_state) + { + case STATE_IAC: + if (ch == TELNET_IAC) + { + telnet_getchar(priv, ch, dest, &nread); + priv->td_state = STATE_NORMAL; + } + else + { + switch (ch) + { + case TELNET_WILL: + priv->td_state = STATE_WILL; + break; + + case TELNET_WONT: + priv->td_state = STATE_WONT; + break; + + case TELNET_DO: + priv->td_state = STATE_DO; + break; + + case TELNET_DONT: + priv->td_state = STATE_DONT; + break; + + default: + priv->td_state = STATE_NORMAL; + break; + } + } + break; + + case STATE_WILL: + /* Reply with a DONT */ + + telnet_sendopt(priv, TELNET_DONT, ch); + priv->td_state = STATE_NORMAL; + break; + + case STATE_WONT: + /* Reply with a DONT */ + + telnet_sendopt(priv, TELNET_DONT, ch); + priv->td_state = STATE_NORMAL; + break; + + case STATE_DO: + /* Reply with a WONT */ + + telnet_sendopt(priv, TELNET_WONT, ch); + priv->td_state = STATE_NORMAL; + break; + + case STATE_DONT: + /* Reply with a WONT */ + + telnet_sendopt(priv, TELNET_WONT, ch); + priv->td_state = STATE_NORMAL; + break; + + case STATE_NORMAL: + if (ch == TELNET_IAC) + { + priv->td_state = STATE_IAC; + } + else + { + telnet_getchar(priv, ch, dest, &nread); + } + break; + } + } + + /* We get here if (1) all of the received bytes have been processed, or + * (2) if the user's buffer has become full. + */ + + if (srclen > 0) + { + /* Remember where we left off. These bytes will be returned the next + * time that telnet_read() is called. + */ + + priv->td_pending = srclen; + priv->td_offset = (src - priv->td_rxbuffer); + } + else + { + /* All of the received bytes were consumed */ + + priv->td_pending = 0; + priv->td_offset = 0; + } + + return nread; +} + +/**************************************************************************** + * Name: telnet_putchar + * + * Description: + * Put another character from the user buffer to the TX buffer. + * + ****************************************************************************/ + +static bool telnet_putchar(FAR struct telnet_dev_s *priv, uint8_t ch, + int *nread) +{ + register int index; + bool ret = false; + + /* Ignore carriage returns (we will put these in automatically as necesary) */ + + if (ch != ISO_cr) + { + /* Add all other characters to the destination buffer */ + + index = *nread; + priv->td_txbuffer[index++] = ch; + + /* Check for line feeds */ + + if (ch == ISO_nl) + { + /* Now add the carriage return */ + + priv->td_txbuffer[index++] = ISO_cr; + priv->td_txbuffer[index++] = '\0'; + + /* End of line */ + + ret = true; + } + + *nread = index; + } + + return ret; +} + +/**************************************************************************** + * Name: telnet_sendopt + * + * Description: + * Send the telnet option bytes + * + ****************************************************************************/ + +static void telnet_sendopt(FAR struct telnet_dev_s *priv, uint8_t option, + uint8_t value) +{ + uint8_t optbuf[4]; + optbuf[0] = TELNET_IAC; + optbuf[1] = option; + optbuf[2] = value; + optbuf[3] = 0; + + telnet_dumpbuffer("Send optbuf", optbuf, 4); + if (psock_send(&priv->td_psock, optbuf, 4, 0) < 0) + { + nlldbg("Failed to send TELNET_IAC\n"); + } +} + +/**************************************************************************** + * Name: telnet_open + ****************************************************************************/ + +static int telnet_open(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct telnet_dev_s *priv = inode->i_private; + int tmp; + int ret; + + nllvdbg("td_crefs: %d\n", priv->td_crefs); + + /* O_NONBLOCK is not supported */ + + if (filep->f_oflags & O_NONBLOCK) + { + ret = -ENOSYS; + goto errout; + } + + /* Get exclusive access to the device structures */ + + ret = sem_wait(&priv->td_exclsem); + if (ret < 0) + { + ret = -errno; + goto errout; + } + + /* Increment the count of references to the device. If this the first + * time that the driver has been opened for this device, then initialize + * the device. + */ + + tmp = priv->td_crefs + 1; + if (tmp > 255) + { + /* More than 255 opens; uint8_t would overflow to zero */ + + ret = -EMFILE; + goto errout_with_sem; + } + + /* Save the new open count on success */ + + priv->td_crefs = tmp; + ret = OK; + +errout_with_sem: + sem_post(&priv->td_exclsem); + +errout: + return ret; +} + +/**************************************************************************** + * Name: telnet_close + ****************************************************************************/ + +static int telnet_close(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct telnet_dev_s *priv = inode->i_private; + FAR char *devpath; + int ret; + + nllvdbg("td_crefs: %d\n", priv->td_crefs); + + /* Get exclusive access to the device structures */ + + ret = sem_wait(&priv->td_exclsem); + if (ret < 0) + { + ret = -errno; + goto errout; + } + + /* Decrement the references to the driver. If the reference count will + * decrement to 0, then uninitialize the driver. + */ + + if (priv->td_crefs > 1) + { + /* Just decrement the reference count and release the semaphore */ + + priv->td_crefs--; + sem_post(&priv->td_exclsem); + } + else + { + /* Re-create the path to the driver. */ + + sched_lock(); + ret = asprintf(&devpath, TELNETD_DEVFMT, priv->td_minor); + if (ret < 0) + { + nlldbg("ERROR: Failed to allocate the driver path\n"); + } + else + { + /* Un-register the character driver */ + + ret = unregister_driver(devpath); + if (ret < 0) + { + /* NOTE: a return value of -EBUSY is not an error, it simply + * means that the Telnet driver is busy now and cannot be + * registered now because there are other sessions using the + * connection. The driver will be properly unregistered when + * the final session terminates. + */ + + if (ret != -EBUSY) + { + nlldbg("Failed to unregister the driver %s: %d\n", + devpath, ret); + } + } + + free(devpath); + } + + /* Close the socket */ + + psock_close(&priv->td_psock); + + /* Release the driver memory. What if there are threads waiting on + * td_exclsem? They will never be awakened! How could this happen? + * crefs == 1 so there are no other open references to the driver. + * But this could have if someone were trying to re-open the driver + * after every other thread has closed it. That really should not + * happen in the intended usage model. + */ + + DEBUGASSERT(priv->td_exclsem.semcount == 0); + sem_destroy(&priv->td_exclsem); + free(priv); + sched_unlock(); + } + + ret = OK; + +errout: + return ret; +} + +/**************************************************************************** + * Name: telnet_read + ****************************************************************************/ + +static ssize_t telnet_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct telnet_dev_s *priv = inode->i_private; + ssize_t ret; + + nllvdbg("len: %d\n", len); + + /* First, handle the case where there are still valid bytes left in the + * I/O buffer from the last time that read was called. NOTE: Much of + * what we read may be protocol stuff and may not correspond to user + * data. Hence we need the loop and we need may need to call psock_recv() + * multiple times in order to get data that the client is interested in. + */ + + do + { + if (priv->td_pending > 0) + { + /* Process the buffered telnet data */ + + FAR const char *src = &priv->td_rxbuffer[priv->td_offset]; + ret = telnet_receive(priv, src, priv->td_pending, buffer, len); + } + + /* Read a buffer of data from the telnet client */ + + else + { + ret = psock_recv(&priv->td_psock, priv->td_rxbuffer, + CONFIG_TELNET_RXBUFFER_SIZE, 0); + + /* Did we receive anything? */ + + if (ret > 0) + { + /* Yes.. Process the newly received telnet data */ + + telnet_dumpbuffer("Received buffer", priv->td_rxbuffer, ret); + ret = telnet_receive(priv, priv->td_rxbuffer, ret, buffer, len); + } + + /* Otherwise the peer closed the connection (ret == 0) or an error + * occurred (ret < 0). + */ + + else + { + break; + } + } + } + while (ret == 0); + + /* Return: + * + * ret > 0: The number of characters copied into the user buffer by + * telnet_receive(). + * ret <= 0: Loss of connection or error events reported by recv(). + */ + + return ret; +} + +/**************************************************************************** + * Name: telnet_write + ****************************************************************************/ + +static ssize_t telnet_write(FAR struct file *filep, FAR const char *buffer, size_t len) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct telnet_dev_s *priv = inode->i_private; + FAR const char *src = buffer; + ssize_t nsent; + ssize_t ret; + int ncopied; + char ch; + bool eol; + + nllvdbg("len: %d\n", len); + + /* Process each character from the user buffer */ + + for (nsent = 0, ncopied = 0; nsent < len; nsent++) + { + /* Get the next character from the user buffer */ + + ch = *src++; + + /* Add the character to the TX buffer */ + + eol = telnet_putchar(priv, ch, &ncopied); + + /* Was that the end of a line? Or is the buffer too full to hold the + * next largest character sequence ("\r\n\0")? + */ + + if (eol || ncopied > CONFIG_TELNET_TXBUFFER_SIZE-3) + { + /* Yes... send the data now */ + + ret = psock_send(&priv->td_psock, priv->td_txbuffer, ncopied, 0); + if (ret < 0) + { + nlldbg("psock_send failed '%s': %d\n", priv->td_txbuffer, ret); + return ret; + } + + /* Reset the index to the beginning of the TX buffer. */ + + ncopied = 0; + } + } + + /* Send anything remaining in the TX buffer */ + + if (ncopied > 0) + { + ret = psock_send(&priv->td_psock, priv->td_txbuffer, ncopied, 0); + if (ret < 0) + { + nlldbg("psock_send failed '%s': %d\n", priv->td_txbuffer, ret); + return ret; + } + } + + /* Notice that we don't actually return the number of bytes sent, but + * rather, the number of bytes that the caller asked us to send. We may + * have sent more bytes (because of CR-LF expansion and because of NULL + * termination). But it confuses some logic if you report that you sent + * more than you were requested to. + */ + + return len; +} + +/**************************************************************************** + * Name: telnet_poll + ****************************************************************************/ + +static int telnet_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ +#if 0 /* No ioctl commands are yet supported */ + struct inode *inode = filep->f_inode; + struct cdcacm_dev_s *priv = inode->i_private; + int ret = OK; + + switch (cmd) + { + /* Add ioctl commands here */ + + default: + ret = -ENOTTY; + break; + } + + return ret; +#else + return -ENOTTY; +#endif +} + +/**************************************************************************** + * Name: telnet_poll + ****************************************************************************/ + +#if 0 /* Not used by this driver */ +static int telnet_poll(FAR struct file *filep, FAR struct pollfd *fds, + bool setup) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct telnet_dev_s *priv = inode->i_private; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: telnet_driver + * + * Description: + * Create a character driver to "wrap" the telnet session. This function + * will select and return a unique path for the new telnet device. + * + * Parameters: + * sd - The socket descriptor that represents the new telnet connection. + * + * Return: + * An allocated string represent the full path to the created driver. The + * receiver of the string must de-allocate this memory when it is no longer + * needed. NULL is returned on a failure. + * + ****************************************************************************/ + +FAR char *telnet_driver(int sd) +{ + FAR struct telnet_dev_s *priv; + FAR struct socket *psock; + FAR char *devpath = NULL; + int ret; + + /* Allocate instance data for this driver */ + + priv = (FAR struct telnet_dev_s*)malloc(sizeof(struct telnet_dev_s)); + if (!priv) + { + nlldbg("Failed to allocate the driver data structure\n"); + return NULL; + } + + /* Initialize the allocated driver instance */ + + sem_init(&priv->td_exclsem, 0, 1); + + priv->td_state = STATE_NORMAL; + priv->td_crefs = 0; + priv->td_pending = 0; + priv->td_offset = 0; + + /* Clone the internal socket structure. We do this so that it will be + * independent of threads and of socket descriptors (the original socket + * instance resided in the daemon's task group`). + */ + + psock = sockfd_socket(sd); + if (!psock) + { + nlldbg("Failed to convert sd=%d to a socket structure\n", sd); + goto errout_with_dev; + } + + ret = net_clone(psock, &priv->td_psock); + if (ret < 0) + { + nlldbg("net_clone failed: %d\n", ret); + goto errout_with_dev; + } + + /* And close the original */ + + psock_close(psock); + + /* Allocate a unique minor device number of the telnet drvier */ + + do + { + ret = sem_wait(&g_telnet_common.tc_exclsem); + if (ret < 0 && errno != -EINTR) + { + goto errout_with_dev; + } + } + while (ret < 0); + + priv->td_minor = g_telnet_common.tc_minor; + g_telnet_common.tc_minor++; + sem_post(&g_telnet_common.tc_exclsem); + + /* Create a path and name for the driver. */ + + ret = asprintf(&devpath, TELNETD_DEVFMT, priv->td_minor); + if (ret < 0) + { + nlldbg("Failed to allocate the driver path\n"); + goto errout_with_dev; + } + + /* Register the driver */ + + ret = register_driver(devpath, &g_telnet_fops, 0666, priv); + if (ret < 0) + { + nlldbg("Failed to register the driver %s: %d\n", devpath, ret); + goto errout_with_devpath; + } + + /* Return the path to the new telnet driver */ + + return devpath; + +errout_with_devpath: + free(devpath); +errout_with_dev: + free(priv); + return NULL; +} diff --git a/include/nuttx/net/telnet.h b/include/nuttx/net/telnet.h new file mode 100644 index 0000000000..6820260fad --- /dev/null +++ b/include/nuttx/net/telnet.h @@ -0,0 +1,69 @@ +/**************************************************************************** + * include/nuttx/net/telnet.h + * + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_TELNET_H +#define __INCLUDE_NUTTX_NET_TELNET_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: telnet_driver + * + * Description: + * Create a character driver to "wrap" the telnet session. This function + * will select and return a unique path for the new telnet device. + * + * Parameters: + * sd - The socket descriptor that represents the new telnet connection. + * + * Return: + * An allocated string represent the full path to the created driver. The + * receiver of the string must de-allocate this memory when it is no longer + * needed. NULL is returned on a failure. + * + ****************************************************************************/ + +FAR char *telnet_driver(int sd); + +#endif /* __INCLUDE_NUTTX_NET_TELNET_H */ + -- GitLab From 3bd5f60a6230a31317e41d283dd73cf674b6d1ca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Dec 2015 10:02:26 -0600 Subject: [PATCH 425/858] Update ChangeLog --- ChangeLog | 3 +++ configs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a0ce6054be..62d48e9351 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11219,4 +11219,7 @@ * drivers/net/telnet.c: Move the Telnet driver from apps/netutils/telnetd to drivers/net. It is a driver a belongs in the OS. There are still some interface related issues, however (2015-12-07). + * configs/: Update all configurations that use the Telnet daemon; those + configurations now need to separately enable the Telnet drvier + (2015-12-07). diff --git a/configs b/configs index 72b5c56406..35ccaa2c6f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 72b5c56406f3c60cb47a726efcfc7fb020ad8673 +Subproject commit 35ccaa2c6f22b1a4b528cd159ba522f1a19e6d50 -- GitLab From 8fdb1730902ad5ecb690719884467e9a2ed57b0a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Dec 2015 13:48:06 -0600 Subject: [PATCH 426/858] drivers/net/telnet.c: Now works like the loop device. A new interface called telnet_initialize() registers a telnet session "factory" device at /dev/telnet. Via ioctl, the factory device can create instances of the telnet character devices at /dev/telnetN to support Telnet sessions. --- ChangeLog | 5 + TODO | 11 +- arch | 2 +- drivers/loop/loop.c | 5 +- drivers/net/telnet.c | 261 +++++++++++++++++++++++++------------ include/nuttx/net/ioctl.h | 5 + include/nuttx/net/telnet.h | 47 +++++-- 7 files changed, 230 insertions(+), 106 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62d48e9351..72b4ddf0c8 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11222,4 +11222,9 @@ * configs/: Update all configurations that use the Telnet daemon; those configurations now need to separately enable the Telnet drvier (2015-12-07). + * drivers/net/telnet.c: Now works like the loop device. A new interface + called telnet_initialize() registers a telnet session "factory" + device at /dev/telnet. Via ioctl, the factory device can create + instances of the telnet character devices at /dev/telnetN to support + Telnet sessions (2015-12-07). diff --git a/TODO b/TODO index 46882e7781..98ea6fe312 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated November 28, 2015) +NuttX TODO List (Last updated December 7, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -14,6 +14,7 @@ nuttx/ (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) + (7) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) (11) Network (net/, drivers/net) @@ -461,14 +462,6 @@ o Kernel/Protected Build Status: Open Priority: Medium/High - Title: TELNETD PARTITIONING. - Description: Telnetd is implemented as a driver that resides in the apps/ - directory. In the kernel/protected build modes, the driver - logic must be moved into the kernel part of the build (nuttx/, - although the application level interfaces must stay in apps/). - Status: Open - Priority: Medium - Title: NxTERM PARTITIONING. Description: NxTerm is implemented (correctly) as a driver that resides in the nuttx/ directory. However, the user interfaces must be diff --git a/arch b/arch index 52b36cad74..9d2cde8987 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 52b36cad744faaef7e67eb25265268a808d9da59 +Subproject commit 9d2cde898788481cdd24f92f11fc9617428bcf14 diff --git a/drivers/loop/loop.c b/drivers/loop/loop.c index 1345b5417d..19cd75d62c 100644 --- a/drivers/loop/loop.c +++ b/drivers/loop/loop.c @@ -63,7 +63,7 @@ static int loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg); * Private Data ****************************************************************************/ -static const struct file_operations loop_fops = +static const struct file_operations g_loop_fops = { 0, /* open */ 0, /* close */ @@ -154,6 +154,7 @@ static int loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg) default: ret = -ENOTTY; + break; } return ret; @@ -173,7 +174,7 @@ static int loop_ioctl(FAR struct file *filep, int cmd, unsigned long arg) void loop_register(void) { - (void)register_driver("/dev/loop", &loop_fops, 0666, NULL); + (void)register_driver("/dev/loop", &g_loop_fops, 0666, NULL); } #endif /* CONFIG_DEV_LOOP */ diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c index b935a5b457..505a01cb94 100644 --- a/drivers/net/telnet.c +++ b/drivers/net/telnet.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/netutils/telnet_driver.c + * drivers/net/telnet.c * * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -63,6 +64,8 @@ #include #include +#ifdef CONFIG_NETDEV_TELNET + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -128,7 +131,7 @@ struct telnet_dev_s struct telnet_common_s { sem_t tc_exclsem; /* Enforces exclusive access to 'minor' */ - int tc_minor; /* The next minor number to use */ + uint16_t tc_minor; /* The next minor number to use */ }; /**************************************************************************** @@ -152,13 +155,24 @@ static bool telnet_putchar(FAR struct telnet_dev_s *priv, uint8_t ch, static void telnet_sendopt(FAR struct telnet_dev_s *priv, uint8_t option, uint8_t value); -/* Character driver methods */ +/* Telnet character driver methods */ static int telnet_open(FAR struct file *filep); static int telnet_close(FAR struct file *filep); static ssize_t telnet_read(FAR struct file *, FAR char *, size_t); static ssize_t telnet_write(FAR struct file *, FAR const char *, size_t); -static int telnet_ioctl(FAR struct file *filep, int cmd, + +/* Telnet session creation */ + +static int telnet_session(FAR struct telnet_session_s *session); + +/* Telnet factory driver methods */ + +static ssize_t factory_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t factory_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int common_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** @@ -167,14 +181,27 @@ static int telnet_ioctl(FAR struct file *filep, int cmd, static const struct file_operations g_telnet_fops = { - telnet_open, /* open */ - telnet_close, /* close */ - telnet_read, /* read */ - telnet_write, /* write */ - 0, /* seek */ - telnet_ioctl /* ioctl */ + telnet_open, /* open */ + telnet_close, /* close */ + telnet_read, /* read */ + telnet_write, /* write */ + 0, /* seek */ + common_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +static const struct file_operations g_factory_fops = +{ + 0, /* open */ + 0, /* close */ + factory_read, /* read */ + factory_write, /* write */ + 0, /* seek */ + common_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , 0 /* poll */ + , 0 /* poll */ #endif }; @@ -712,70 +739,27 @@ static ssize_t telnet_write(FAR struct file *filep, FAR const char *buffer, size } /**************************************************************************** - * Name: telnet_poll - ****************************************************************************/ - -static int telnet_ioctl(FAR struct file *filep, int cmd, unsigned long arg) -{ -#if 0 /* No ioctl commands are yet supported */ - struct inode *inode = filep->f_inode; - struct cdcacm_dev_s *priv = inode->i_private; - int ret = OK; - - switch (cmd) - { - /* Add ioctl commands here */ - - default: - ret = -ENOTTY; - break; - } - - return ret; -#else - return -ENOTTY; -#endif -} - -/**************************************************************************** - * Name: telnet_poll - ****************************************************************************/ - -#if 0 /* Not used by this driver */ -static int telnet_poll(FAR struct file *filep, FAR struct pollfd *fds, - bool setup) -{ - FAR struct inode *inode = filep->f_inode; - FAR struct telnet_dev_s *priv = inode->i_private; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: telnet_driver + * Name: telnet_session * * Description: * Create a character driver to "wrap" the telnet session. This function * will select and return a unique path for the new telnet device. * * Parameters: - * sd - The socket descriptor that represents the new telnet connection. + * session - On input, contains the socket descriptor that represents the + * new telnet connection. On output, it holds the path to the new Telnet driver. * * Return: - * An allocated string represent the full path to the created driver. The - * receiver of the string must de-allocate this memory when it is no longer - * needed. NULL is returned on a failure. + * Zero (OK) on success; a negated errno value on failure. * ****************************************************************************/ -FAR char *telnet_driver(int sd) +static int telnet_session(FAR struct telnet_session_s *session) { FAR struct telnet_dev_s *priv; FAR struct socket *psock; - FAR char *devpath = NULL; + struct stat statbuf; + uint16_t start; int ret; /* Allocate instance data for this driver */ @@ -784,7 +768,7 @@ FAR char *telnet_driver(int sd) if (!priv) { nlldbg("Failed to allocate the driver data structure\n"); - return NULL; + return -ENOMEM; } /* Initialize the allocated driver instance */ @@ -801,10 +785,11 @@ FAR char *telnet_driver(int sd) * instance resided in the daemon's task group`). */ - psock = sockfd_socket(sd); + psock = sockfd_socket(session->ts_sd); if (!psock) { - nlldbg("Failed to convert sd=%d to a socket structure\n", sd); + nlldbg("Failed to convert sd=%d to a socket structure\n", session->ts_sd); + ret = -EINVAL; goto errout_with_dev; } @@ -815,51 +800,157 @@ FAR char *telnet_driver(int sd) goto errout_with_dev; } - /* And close the original */ - - psock_close(psock); - - /* Allocate a unique minor device number of the telnet drvier */ + /* Allocate a unique minor device number of the telnet drvier. + * Get exclusive access to the minor counter. + */ do { ret = sem_wait(&g_telnet_common.tc_exclsem); if (ret < 0 && errno != -EINTR) { - goto errout_with_dev; + goto errout_with_clone; } } while (ret < 0); - priv->td_minor = g_telnet_common.tc_minor; - g_telnet_common.tc_minor++; - sem_post(&g_telnet_common.tc_exclsem); + /* Loop until the device name is verified to be unique. */ - /* Create a path and name for the driver. */ + start = g_telnet_common.tc_minor; + do + { + /* Get the next candiate minor number */ - ret = asprintf(&devpath, TELNETD_DEVFMT, priv->td_minor); - if (ret < 0) + priv->td_minor = g_telnet_common.tc_minor; + g_telnet_common.tc_minor++; + + snprintf(session->ts_devpath, TELNET_DEVPATH_MAX, TELNETD_DEVFMT, + priv->td_minor); + + ret = stat(session->ts_devpath, &statbuf); + DEBUGASSERT(ret >= 0 || errno == ENOENT); + } + while (ret >= 0 && start != g_telnet_common.tc_minor); + + if (ret >= 0) { - nlldbg("Failed to allocate the driver path\n"); - goto errout_with_dev; + nlldbg("ERROR: Too many sessions\n"); + ret = -ENFILE; + goto errout_with_semaphore; } /* Register the driver */ - ret = register_driver(devpath, &g_telnet_fops, 0666, priv); + ret = register_driver(session->ts_devpath, &g_telnet_fops, 0666, priv); if (ret < 0) { - nlldbg("Failed to register the driver %s: %d\n", devpath, ret); - goto errout_with_devpath; + nlldbg("ERROR: Failed to register the driver %s: %d\n", + session->ts_devpath, ret); + goto errout_with_semaphore; } + /* Close the original psoock (keeping the clone) */ + + psock_close(psock); + /* Return the path to the new telnet driver */ - return devpath; + sem_post(&g_telnet_common.tc_exclsem); + return OK; + +errout_with_semaphore: + sem_post(&g_telnet_common.tc_exclsem); + +errout_with_clone: + psock_close(&priv->td_psock); -errout_with_devpath: - free(devpath); errout_with_dev: free(priv); - return NULL; + return ret; +} + +/**************************************************************************** + * Name: factory_read + ****************************************************************************/ + +static ssize_t factory_read(FAR struct file *filep, FAR char *buffer, + size_t len) +{ + return 0; /* Return EOF */ +} + +/**************************************************************************** + * Name: factory_write + ****************************************************************************/ + +static ssize_t factory_write(FAR struct file *filep, FAR const char *buffer, + size_t len) +{ + return len; /* Say that everything was written */ +} + +/**************************************************************************** + * Name: common_ioctl + ****************************************************************************/ + +static int common_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + int ret; + + switch (cmd) + { + /* Command: SIOCTELNET + * Description: Create a Telnet sessions. + * Argument: A pointer to a write-able instance of struct + * telnet_session_s. + * Dependencies: CONFIG_NETDEV_TELNET + */ + + case SIOCTELNET: + { + FAR struct telnet_session_s *session = + (FAR struct telnet_session_s *)((uintptr_t)arg); + + if (session == NULL) + { + ret = -EINVAL; + } + else + { + ret = telnet_session(session); + } + } + break; + + default: + ret = -ENOTTY; + break; + } + + return ret; } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: telnet_initialize + * + * Description: + * Create the Telnet factory at /dev/telnet. + * + * Parameters: + * None + * + * Return: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int telnet_initialize(void) +{ + return register_driver("/dev/telnet", &g_factory_fops, 0666, NULL); +} + +#endif /* CONFIG_NETDEV_TELNET */ diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h index 5b617314d7..4a13ed523f 100644 --- a/include/nuttx/net/ioctl.h +++ b/include/nuttx/net/ioctl.h @@ -175,6 +175,11 @@ #define SIOCINQ _SIOC(0x004f) /* Returns the amount of queued unread * data in the receive */ +/* Telnet driver ************************************************************/ + +#define SIOCTELNET _SIOC(0x0050) /* Create a Telnet sessions. + * See include/nuttx/net/telnet.h */ + /**************************************************************************** * Type Definitions ****************************************************************************/ diff --git a/include/nuttx/net/telnet.h b/include/nuttx/net/telnet.h index 6820260fad..c7184c6d6b 100644 --- a/include/nuttx/net/telnet.h +++ b/include/nuttx/net/telnet.h @@ -42,28 +42,57 @@ #include +#include + +#ifdef CONFIG_NETDEV_TELNET + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The minimum size of a device name. Big enough to hold /dev/telnet65535. */ + +#define TELNET_DEVPATH_MAX 18 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* NETDEV ioctl command: + * + * Command: SIOCTELNET + * Description: Create a Telnet sessions. + * Argument: A pointer to a write-able instance of struct telnet_session_s. + * Dependencies: CONFIG_NETDEV_TELNET + */ + +struct telnet_session_s +{ + int ts_sd; /* Socket descriptor for session. */ + char ts_devpath[TELNET_DEVPATH_MAX]; /* Path to new session driver */ +}; + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: telnet_driver + * Name: telnet_initialize * * Description: - * Create a character driver to "wrap" the telnet session. This function - * will select and return a unique path for the new telnet device. + * Create the Telnet factory at /dev/telnet. * * Parameters: - * sd - The socket descriptor that represents the new telnet connection. + * None * * Return: - * An allocated string represent the full path to the created driver. The - * receiver of the string must de-allocate this memory when it is no longer - * needed. NULL is returned on a failure. + * Zero (OK) on success; a negated errno value on failure. * ****************************************************************************/ -FAR char *telnet_driver(int sd); +#ifdef __KERNEL__ +int telnet_initialize(void); +#endif +#endif /* CONFIG_NETDEV_TELNET */ #endif /* __INCLUDE_NUTTX_NET_TELNET_H */ - -- GitLab From 513cc08c7fe687ba300d3b25863ca666ee3f8bd8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Dec 2015 17:18:14 -0600 Subject: [PATCH 427/858] change default size of CDC/ACM serial buffer sizes --- drivers/usbdev/Kconfig | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig index 70e2cf08c1..2857e59843 100644 --- a/drivers/usbdev/Kconfig +++ b/drivers/usbdev/Kconfig @@ -244,6 +244,10 @@ config PL2303_BULKIN_REQLEN on the other hand, request buffer size is always the same as the maxpacket size. + There is also no reason from PL2303_BULKIN_REQLEN to be greater + than PL2303_TXBUFSIZE-1, since a request larger than the TX + buffer can never be sent. + config PL2303_RXBUFSIZE int "Receive buffer size" default 513 if USBDEV_DUALSPEED @@ -257,14 +261,14 @@ config PL2303_RXBUFSIZE config PL2303_TXBUFSIZE int "Transmit buffer size" - default 513 if USBDEV_DUALSPEED - default 257 if !USBDEV_DUALSPEED + default 767 if USBDEV_DUALSPEED + default 193 if !USBDEV_DUALSPEED ---help--- Size of the serial transmit buffers. The actual amount of data that can be held in the buffer is this number minus one due to the way - that the circular buffer is managed. So a TX buffer size of 257 - will hold four full-speed, 64 byte packets; a buffer size of 513 - will hold one high-speed, 512 byte packet. + that the circular buffer is managed. So a TX buffer size of 767 + will hold one request of size 768; a buffer size of 193 will hold + two requests of size 96 bytes. config PL2303_VENDORID hex "Vendor ID" @@ -429,6 +433,10 @@ config CDCACM_BULKIN_REQLEN on the other hand, request buffer size is always the same as the maxpacket size. + There is also no reason from CDCACM_BULKIN_REQLEN to be greater + than CDCACM_TXBUFSIZE-1, since a request larger than the TX + buffer can never be sent. + config CDCACM_RXBUFSIZE int "Receive buffer size" default 513 if USBDEV_DUALSPEED @@ -442,14 +450,14 @@ config CDCACM_RXBUFSIZE config CDCACM_TXBUFSIZE int "Transmit buffer size" - default 513 if USBDEV_DUALSPEED - default 257 if !USBDEV_DUALSPEED + default 767 if USBDEV_DUALSPEED + default 193 if !USBDEV_DUALSPEED ---help--- Size of the serial transmit buffers. The actual amount of data that can be held in the buffer is this number minus one due to the way - that the circular buffer is managed. So a TX buffer size of 257 - will hold four full-speed, 64 byte packets; a buffer size of 513 - will hold one high-speed, 512 byte packet. + that the circular buffer is managed. So a TX buffer size of 767 + will hold one request of size 768; a buffer size of 193 will hold + two requests of size 96 bytes. config CDCACM_VENDORID hex "Vendor ID" -- GitLab From 4a7e28ba960dbf66c9fa6a8f8f93dca48dfcd9e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Dec 2015 07:33:49 -0600 Subject: [PATCH 428/858] CDC/ACM: Fix a bad default value in last commit --- configs | 2 +- drivers/usbdev/Kconfig | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs b/configs index 35ccaa2c6f..c5d86a886c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 35ccaa2c6f22b1a4b528cd159ba522f1a19e6d50 +Subproject commit c5d86a886c2f384f427b2dab78de610e8076c680 diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig index 2857e59843..427091d799 100644 --- a/drivers/usbdev/Kconfig +++ b/drivers/usbdev/Kconfig @@ -261,12 +261,12 @@ config PL2303_RXBUFSIZE config PL2303_TXBUFSIZE int "Transmit buffer size" - default 767 if USBDEV_DUALSPEED + default 769 if USBDEV_DUALSPEED default 193 if !USBDEV_DUALSPEED ---help--- Size of the serial transmit buffers. The actual amount of data that can be held in the buffer is this number minus one due to the way - that the circular buffer is managed. So a TX buffer size of 767 + that the circular buffer is managed. So a TX buffer size of 769 will hold one request of size 768; a buffer size of 193 will hold two requests of size 96 bytes. @@ -450,12 +450,12 @@ config CDCACM_RXBUFSIZE config CDCACM_TXBUFSIZE int "Transmit buffer size" - default 767 if USBDEV_DUALSPEED + default 769 if USBDEV_DUALSPEED default 193 if !USBDEV_DUALSPEED ---help--- Size of the serial transmit buffers. The actual amount of data that can be held in the buffer is this number minus one due to the way - that the circular buffer is managed. So a TX buffer size of 767 + that the circular buffer is managed. So a TX buffer size of 769 will hold one request of size 768; a buffer size of 193 will hold two requests of size 96 bytes. -- GitLab From b669d080dbcf9212cd61e99f2fc427764af8b315 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 8 Dec 2015 11:09:30 -0500 Subject: [PATCH 429/858] Top-level Makefiles: Check if CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH is enabled --- Makefile.unix | 8 ++++++-- Makefile.win | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile.unix b/Makefile.unix index 7d02fed717..28d0df608d 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -72,9 +72,13 @@ ARCH_SRC = $(ARCH_DIR)/src ARCH_INC = $(ARCH_DIR)/include ifeq ($(CONFIG_ARCH_BOARD_CUSTOM),y) - BOARD_DIR = $(CONFIG_ARCH_BOARD_CUSTOM_DIR) +ifeq ($(CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH),y) +BOARD_DIR = $(TOPDIR)$(DELIM)$(CONFIG_ARCH_BOARD_CUSTOM_DIR) else - BOARD_DIR = $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD) +BOARD_DIR = $(CONFIG_ARCH_BOARD_CUSTOM_DIR) +endif +else +BOARD_DIR = $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD) endif # CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file. diff --git a/Makefile.win b/Makefile.win index 4db50470a9..4988b43ab0 100644 --- a/Makefile.win +++ b/Makefile.win @@ -65,9 +65,13 @@ ARCH_SRC = $(ARCH_DIR)\src ARCH_INC = $(ARCH_DIR)\include ifeq ($(CONFIG_ARCH_BOARD_CUSTOM),y) - BOARD_DIR = $(CONFIG_ARCH_BOARD_CUSTOM_DIR) +ifeq ($(CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH),y) +BOARD_DIR = $(TOPDIR)$(DELIM)$(CONFIG_ARCH_BOARD_CUSTOM_DIR) else - BOARD_DIR = $(TOPDIR)${DELIM}configs$(DELIM)$(CONFIG_ARCH_BOARD) +BOARD_DIR = $(CONFIG_ARCH_BOARD_CUSTOM_DIR) +endif +else +BOARD_DIR = $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD) endif # CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file. -- GitLab From d1a3c3aa3b3fed38e6338dbc685dc144e5950945 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Dec 2015 10:13:27 -0600 Subject: [PATCH 430/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 72b4ddf0c8..ad625c0ffa 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11227,4 +11227,6 @@ device at /dev/telnet. Via ioctl, the factory device can create instances of the telnet character devices at /dev/telnetN to support Telnet sessions (2015-12-07). + * arch/arm/src/samv7: In USBHS device driver, fix check if zero length + packet is needed (2015-12-08). diff --git a/arch b/arch index 9d2cde8987..a0b76fdf50 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9d2cde898788481cdd24f92f11fc9617428bcf14 +Subproject commit a0b76fdf50882bb8d1afe6e89dda28039252952b -- GitLab From e00bab70b708ddabea22f4812a3eed0979f2ae6a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Dec 2015 13:14:28 -0600 Subject: [PATCH 431/858] Refresh all configurations that have Telnetd enabled; those configurations now also need the telnet driver --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index a0b76fdf50..4523cfd49b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a0b76fdf50882bb8d1afe6e89dda28039252952b +Subproject commit 4523cfd49bd39e506586f3e4f28aa4cefb8729b7 -- GitLab From 208b4643ce727e25625bc29883eb89ea702b59ca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Dec 2015 13:22:38 -0600 Subject: [PATCH 432/858] Sync submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 4523cfd49b..e942051057 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4523cfd49bd39e506586f3e4f28aa4cefb8729b7 +Subproject commit e942051057f9e7e71e0adb29b2d9a67f98fc205b -- GitLab From c9925305b5c5699073395403de686ff9c932fe12 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Dec 2015 10:17:33 -0600 Subject: [PATCH 433/858] Same important bug as c623af03a0ee8ac041fc22051781047d6cb9cc75, but in a different location --- arch | 2 +- configs | 2 +- sched/sched/sched_setscheduler.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index e942051057..b025eeaa21 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e942051057f9e7e71e0adb29b2d9a67f98fc205b +Subproject commit b025eeaa21ef4cf9e1fc0279183b02d45790bb7f diff --git a/configs b/configs index c5d86a886c..a619d39802 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c5d86a886c2f384f427b2dab78de610e8076c680 +Subproject commit a619d398029baac7d2246f9beaa0b3c6fe9b1d2c diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index d3650374bb..89fa9095aa 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -132,7 +132,7 @@ int sched_setscheduler(pid_t pid, int policy, /* Further, disable timer interrupts while we set up scheduling policy. */ saved_state = irqsave(); - tcb->flags &= TCB_FLAG_POLICY_MASK; + tcb->flags &= ~TCB_FLAG_POLICY_MASK; switch (policy) { default: -- GitLab From 4e3b7e3358d6ac6c9797817aae429c323040b93d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Dec 2015 06:33:14 -0600 Subject: [PATCH 434/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ad625c0ffa..c9407d6344 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11229,4 +11229,8 @@ Telnet sessions (2015-12-07). * arch/arm/src/samv7: In USBHS device driver, fix check if zero length packet is needed (2015-12-08). + * sched/pthread/: CRITICAL BUGFIX: Logic was wiping out the indication + that of the type of a pthread. Hence, it could be confused as a + task. Same problem as fixed on 2015-11-29, but in different location + (2015-12-09). diff --git a/arch b/arch index b025eeaa21..c8448d662d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b025eeaa21ef4cf9e1fc0279183b02d45790bb7f +Subproject commit c8448d662d63fecbbd8c603ab54cfbe2de200fe1 -- GitLab From f9f19d867b1042ddf74423facf3a49ffa1746ffb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Dec 2015 09:47:58 -0600 Subject: [PATCH 435/858] Trivial change to TODO list --- TODO | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 98ea6fe312..d7702ab3a6 100644 --- a/TODO +++ b/TODO @@ -1306,8 +1306,8 @@ o File system / Generic drivers (fs/, drivers/) NOTE: The NXFFS file system has its own TODO list at nuttx/fs/nxffs/README.txt - Title: CHMOD() AND TRUNCATE() - Description: Implement chmod(), truncate(). + Title: CHMOD(), TRUNCATE(), AND FSTAT() + Description: Implement chmod(), truncate(), and fstat(). Status: Open Priority: Low -- GitLab From 8bcf35ff391266bfd178d2f202246281935cd47a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Dec 2015 09:53:31 -0600 Subject: [PATCH 436/858] binfmt/libmodule: Add support for kernel modules. Initial commit is just the ELF module support with name changes --- ChangeLog | 2 + binfmt/libmodule/Kconfig | 52 ++++ binfmt/libmodule/Make.defs | 59 ++++ binfmt/libmodule/gnu-elf.ld | 129 +++++++++ binfmt/libmodule/libmodule.h | 266 +++++++++++++++++++ binfmt/libmodule/libmodule_bind.c | 332 +++++++++++++++++++++++ binfmt/libmodule/libmodule_ctors.c | 216 +++++++++++++++ binfmt/libmodule/libmodule_dtors.c | 216 +++++++++++++++ binfmt/libmodule/libmodule_init.c | 202 ++++++++++++++ binfmt/libmodule/libmodule_iobuffer.c | 136 ++++++++++ binfmt/libmodule/libmodule_load.c | 333 +++++++++++++++++++++++ binfmt/libmodule/libmodule_read.c | 163 ++++++++++++ binfmt/libmodule/libmodule_sections.c | 287 ++++++++++++++++++++ binfmt/libmodule/libmodule_symbols.c | 346 ++++++++++++++++++++++++ binfmt/libmodule/libmodule_uninit.c | 126 +++++++++ binfmt/libmodule/libmodule_unload.c | 124 +++++++++ binfmt/libmodule/libmodule_verify.c | 123 +++++++++ binfmt/module.c | 368 +++++++++++++++++++++++++ include/nuttx/binfmt/module.h | 369 ++++++++++++++++++++++++++ 19 files changed, 3849 insertions(+) create mode 100644 binfmt/libmodule/Kconfig create mode 100644 binfmt/libmodule/Make.defs create mode 100644 binfmt/libmodule/gnu-elf.ld create mode 100644 binfmt/libmodule/libmodule.h create mode 100644 binfmt/libmodule/libmodule_bind.c create mode 100644 binfmt/libmodule/libmodule_ctors.c create mode 100644 binfmt/libmodule/libmodule_dtors.c create mode 100644 binfmt/libmodule/libmodule_init.c create mode 100644 binfmt/libmodule/libmodule_iobuffer.c create mode 100644 binfmt/libmodule/libmodule_load.c create mode 100644 binfmt/libmodule/libmodule_read.c create mode 100644 binfmt/libmodule/libmodule_sections.c create mode 100644 binfmt/libmodule/libmodule_symbols.c create mode 100644 binfmt/libmodule/libmodule_uninit.c create mode 100644 binfmt/libmodule/libmodule_unload.c create mode 100644 binfmt/libmodule/libmodule_verify.c create mode 100644 binfmt/module.c create mode 100644 include/nuttx/binfmt/module.h diff --git a/ChangeLog b/ChangeLog index c9407d6344..96a49dff89 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11233,4 +11233,6 @@ that of the type of a pthread. Hence, it could be confused as a task. Same problem as fixed on 2015-11-29, but in different location (2015-12-09). + * binfmt/libmodule: Add support for kernel modules. Initial commit is + just the ELF module support with name changes (2015-12-10). diff --git a/binfmt/libmodule/Kconfig b/binfmt/libmodule/Kconfig new file mode 100644 index 0000000000..feb42b68e5 --- /dev/null +++ b/binfmt/libmodule/Kconfig @@ -0,0 +1,52 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config MODULE_ALIGN_LOG2 + int "Log2 Section Alignment" + default 2 + ---help--- + Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc. + +config MODULE_STACKSIZE + int "Module Stack Size" + default 2048 + ---help--- + This is the default stack size that will be used when starting + module initialization tasks. + +config MODULE_BUFFERSIZE + int "Module I/O Buffer Size" + default 128 + ---help--- + This is an I/O buffer that is used to access the module file. + Variable length items will need to be read (such as symbol names). + This is really just this initial size of the buffer; it will be + reallocated as necessary to hold large symbol names). Default: 128 + +config MODULE_BUFFERINCR + int "Module I/O Buffer Realloc Increment" + default 32 + ---help--- + This is an I/O buffer that is used to access the module file. + Variable length items will need to be read (such as symbol names). + This value specifies the size increment to use each time the + buffer is reallocated. Default: 32 + +config MODULE_DUMPBUFFER + bool "Dump module buffers" + default n + depends on DEBUG && DEBUG_VERBOSE + ---help--- + Dump various module buffers for debug purposes + +config MODULE_EXIDX_SECTNAME + string "Module Section Name for Exception Index" + default ".ARM.exidx" + depends on UCLIBCXX_EXCEPTION + ---help--- + Set the name string for the exception index section on the modules to + be loaded by the module binary loader. + + This is needed to support exception handling on loadable modules. diff --git a/binfmt/libmodule/Make.defs b/binfmt/libmodule/Make.defs new file mode 100644 index 0000000000..e610aec6a3 --- /dev/null +++ b/binfmt/libmodule/Make.defs @@ -0,0 +1,59 @@ +############################################################################ +# binfmt/libmodule/Make.defs +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_ELF),y) + +# ELF application interfaces + +BINFMT_CSRCS += module.c + +# ELF library + +BINFMT_CSRCS += libmodule_bind.c libmodule_init.c libmodule_iobuffer.c +BINFMT_CSRCS += libmodule_load.c libmodule_read.c libmodule_sections.c +BINFMT_CSRCS += libmodule_symbols.c libmodule_uninit.c libmodule_unload.c +BINFMT_CSRCS += libmodule_verify.c + +ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y) +BINFMT_CSRCS += libmodule_ctors.c libmodule_dtors.c +endif + +# Hook the libmodule subdirectory into the build + +VPATH += libmodule +SUBDIRS += libmodule +DEPPATH += --dep-path libmodule + +endif diff --git a/binfmt/libmodule/gnu-elf.ld b/binfmt/libmodule/gnu-elf.ld new file mode 100644 index 0000000000..8b79f8d45a --- /dev/null +++ b/binfmt/libmodule/gnu-elf.ld @@ -0,0 +1,129 @@ +/**************************************************************************** + * binfmt/libmodule/gnu-elf.ld + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +SECTIONS +{ + .text 0x00000000 : + { + _stext = . ; + *(.text) + *(.text.*) + *(.gnu.warning) + *(.stub) + *(.glue_7) + *(.glue_7t) + *(.jcr) + + /* C++ support: The .init and .fini sections contain specific logic + * to manage static constructors and destructors. + */ + + *(.gnu.linkonce.t.*) + *(.init) /* Old ABI */ + *(.fini) /* Old ABI */ + _etext = . ; + } + + .rodata : + { + _srodata = . ; + *(.rodata) + *(.rodata1) + *(.rodata.*) + *(.gnu.linkonce.r*) + _erodata = . ; + } + + .data : + { + _sdata = . ; + *(.data) + *(.data1) + *(.data.*) + *(.gnu.linkonce.d*) + _edata = . ; + } + + /* C++ support. For each global and static local C++ object, + * GCC creates a small subroutine to construct the object. Pointers + * to these routines (not the routines themselves) are stored as + * simple, linear arrays in the .ctors section of the object file. + * Similarly, pointers to global/static destructor routines are + * stored in .dtors. + */ + + .ctors : + { + _sctors = . ; + *(.ctors) /* Old ABI: Unallocated */ + *(.init_array) /* New ABI: Allocated */ + _ectors = . ; + } + + .dtors : + { + _sdtors = . ; + *(.dtors) /* Old ABI: Unallocated */ + *(.fini_array) /* New ABI: Allocated */ + _edtors = . ; + } + + .bss : + { + _sbss = . ; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.b*) + *(COMMON) + _ebss = . ; + } + + /* Stabs debugging sections. */ + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/binfmt/libmodule/libmodule.h b/binfmt/libmodule/libmodule.h new file mode 100644 index 0000000000..eeed0498df --- /dev/null +++ b/binfmt/libmodule/libmodule.h @@ -0,0 +1,266 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule.h + * + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __BINFMT_LIBELF_LIBELF_H +#define __BINFMT_LIBELF_LIBELF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_verifyheader + * + * Description: + * Given the header from a possible ELF executable, verify that it is + * an ELF executable. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_verifyheader(FAR const Elf32_Ehdr *header); + +/**************************************************************************** + * Name: mod_read + * + * Description: + * Read 'readsize' bytes from the object file at 'offset'. The data is + * read into 'buffer.' + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset); + +/**************************************************************************** + * Name: mod_loadshdrs + * + * Description: + * Loads section headers into memory. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_findsection + * + * Description: + * A section by its name. + * + * Input Parameters: + * loadinfo - Load state information + * sectname - Name of the section to find + * + * Returned Value: + * On success, the index to the section is returned; A negated errno value + * is returned on failure. + * + ****************************************************************************/ + +int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname); + +/**************************************************************************** + * Name: mod_findsymtab + * + * Description: + * Find the symbol table section. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_readsym + * + * Description: + * Read the ELFT symbol structure at the specfied index into memory. + * + * Input Parameters: + * loadinfo - Load state information + * index - Symbol table index + * sym - Location to return the table entry + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym); + +/**************************************************************************** + * Name: mod_symvalue + * + * Description: + * Get the value of a symbol. The updated value of the symbol is returned + * in the st_value field of the symbol table entry. + * + * Input Parameters: + * loadinfo - Load state information + * sym - Symbol table entry (value might be undefined) + * exports - The symbol table to use for resolving undefined symbols. + * nexports - Number of symbols in the symbol table. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + * EINVAL - There is something inconsistent in the symbol table (should only + * happen if the file is corrupted) + * ENOSYS - Symbol lies in common + * ESRCH - Symbol has no name + * ENOENT - Symbol undefined and not provided via a symbol table + * + ****************************************************************************/ + +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: mod_freebuffers + * + * Description: + * Release all working buffers. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_allocbuffer + * + * Description: + * Perform the initial allocation of the I/O buffer, if it has not already + * been allocated. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_reallocbuffer + * + * Description: + * Increase the size of I/O buffer by the specified buffer increment. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); + +/**************************************************************************** + * Name: mod_findctors + * + * Description: + * Find C++ static constructors. + * + * Input Parameters: + * loadinfo - Load state information + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS +int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo); +#endif + +/**************************************************************************** + * Name: mod_loaddtors + * + * Description: + * Load pointers to static destructors into an in-memory array. + * + * Input Parameters: + * loadinfo - Load state information + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS +int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo); +#endif + +#endif /* __BINFMT_LIBELF_LIBELF_H */ diff --git a/binfmt/libmodule/libmodule_bind.c b/binfmt/libmodule/libmodule_bind.c new file mode 100644 index 0000000000..8b5b680c8b --- /dev/null +++ b/binfmt/libmodule/libmodule_bind.c @@ -0,0 +1,332 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_bind.c + * + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be + * defined or CONFIG_ELF_DUMPBUFFER does nothing. + */ + +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) +# undef CONFIG_ELF_DUMPBUFFER +#endif + +#ifndef CONFIG_ELF_BUFFERSIZE +# define CONFIG_ELF_BUFFERSIZE 128 +#endif + +#ifdef CONFIG_ELF_DUMPBUFFER +# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +#else +# define mod_dumpbuffer(m,b,n) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_readrel + * + * Description: + * Read the ELF32_Rel structure into memory. + * + ****************************************************************************/ + +static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *relsec, + int index, FAR Elf32_Rel *rel) +{ + off_t offset; + + /* Verify that the symbol table index lies within symbol table */ + + if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel))) + { + bdbg("Bad relocation symbol index: %d\n", index); + return -EINVAL; + } + + /* Get the file offset to the symbol table entry */ + + offset = relsec->sh_offset + sizeof(Elf32_Rel) * index; + + /* And, finally, read the symbol table entry into memory */ + + return mod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); +} + +/**************************************************************************** + * Name: mod_relocate and mod_relocateadd + * + * Description: + * Perform all relocations associated with a section. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) + +{ + FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx]; + FAR Elf32_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info]; + Elf32_Rel rel; + Elf32_Sym sym; + FAR Elf32_Sym *psym; + uintptr_t addr; + int symidx; + int ret; + int i; + + /* Examine each relocation in the section. 'relsec' is the section + * containing the relations. 'dstsec' is the section containing the data + * to be relocated. + */ + + for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++) + { + psym = &sym; + + /* Read the relocation entry into memory */ + + ret = mod_readrel(loadinfo, relsec, i, &rel); + if (ret < 0) + { + bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n", + relidx, i, ret); + return ret; + } + + /* Get the symbol table index for the relocation. This is contained + * in a bit-field within the r_info element. + */ + + symidx = ELF32_R_SYM(rel.r_info); + + /* Read the symbol table entry into memory */ + + ret = mod_readsym(loadinfo, symidx, &sym); + if (ret < 0) + { + bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n", + relidx, i, symidx, ret); + return ret; + } + + /* Get the value of the symbol (in sym.st_value) */ + + ret = mod_symvalue(loadinfo, &sym, exports, nexports); + if (ret < 0) + { + /* The special error -ESRCH is returned only in one condition: The + * symbol has no name. + * + * There are a few relocations for a few architectures that do + * no depend upon a named symbol. We don't know if that is the + * case here, but we will use a NULL symbol pointer to indicate + * that case to up_relocate(). That function can then do what + * is best. + */ + + if (ret == -ESRCH) + { + bdbg("Section %d reloc %d: Undefined symbol[%d] has no name: %d\n", + relidx, i, symidx, ret); + psym = NULL; + } + else + { + bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n", + relidx, i, symidx, ret); + return ret; + } + } + + /* Calculate the relocation address. */ + + if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t)) + { + bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n", + relidx, i, rel.r_offset, dstsec->sh_size); + return -EINVAL; + } + + addr = dstsec->sh_addr + rel.r_offset; + + /* Now perform the architecture-specific relocation */ + + ret = up_relocate(&rel, psym, addr); + if (ret < 0) + { + bdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", relidx, i, ret); + return ret; + } + } + + return OK; +} + +static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) +{ + bdbg("Not implemented\n"); + return -ENOSYS; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_bind + * + * Description: + * Bind the imported symbol names in the loaded module described by + * 'loadinfo' using the exported symbol values provided by 'symtab'. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_bind(FAR struct mod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports) +{ + int ret; + int i; + + /* Find the symbol and string tables */ + + ret = mod_findsymtab(loadinfo); + if (ret < 0) + { + return ret; + } + + /* Allocate an I/O buffer. This buffer is used by mod_symname() to + * accumulate the variable length symbol name. + */ + + ret = mod_allocbuffer(loadinfo); + if (ret < 0) + { + bdbg("mod_allocbuffer failed: %d\n", ret); + return -ENOMEM; + } + + /* Process relocations in every allocated section */ + + for (i = 1; i < loadinfo->ehdr.e_shnum; i++) + { + /* Get the index to the relocation section */ + + int infosec = loadinfo->shdr[i].sh_info; + if (infosec >= loadinfo->ehdr.e_shnum) + { + continue; + } + + /* Make sure that the section is allocated. We can't relocated + * sections that were not loaded into memory. + */ + + if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0) + { + continue; + } + + /* Process the relocations by type */ + + if (loadinfo->shdr[i].sh_type == SHT_REL) + { + ret = mod_relocate(loadinfo, i, exports, nexports); + } + else if (loadinfo->shdr[i].sh_type == SHT_RELA) + { + ret = mod_relocateadd(loadinfo, i, exports, nexports); + } + + if (ret < 0) + { + break; + } + } + +#if defined(CONFIG_ARCH_HAVE_COHERENT_DCACHE) + /* Ensure that the I and D caches are coherent before starting the newly + * loaded module by cleaning the D cache (i.e., flushing the D cache + * contents to memory and invalidating the I cache). + */ + + up_coherent_dcache(loadinfo->textalloc, loadinfo->textsize); + up_coherent_dcache(loadinfo->dataalloc, loadinfo->datasize); + +#endif + + return ret; +} diff --git a/binfmt/libmodule/libmodule_ctors.c b/binfmt/libmodule/libmodule_ctors.c new file mode 100644 index 0000000000..e89d310fbe --- /dev/null +++ b/binfmt/libmodule/libmodule_ctors.c @@ -0,0 +1,216 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_ctors.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_loadctors + * + * Description: + * Load pointers to static constructors into an in-memory array. + * + * Input Parameters: + * loadinfo - Load state information + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) +{ + FAR Elf32_Shdr *shdr; + size_t ctorsize; + int ctoridx; + int ret; + int i; + + DEBUGASSERT(loadinfo->ctors == NULL); + + /* Allocate an I/O buffer if necessary. This buffer is used by + * mod_sectname() to accumulate the variable length symbol name. + */ + + ret = mod_allocbuffer(loadinfo); + if (ret < 0) + { + bdbg("mod_allocbuffer failed: %d\n", ret); + return -ENOMEM; + } + + /* Find the index to the section named ".ctors." NOTE: On old ABI system, + * .ctors is the name of the section containing the list of constructors; + * On newer systems, the similar section is called .init_array. It is + * expected that the linker script will force the section name to be ".ctors" + * in either case. + */ + + ctoridx = mod_findsection(loadinfo, ".ctors"); + if (ctoridx < 0) + { + /* This may not be a failure. -ENOENT indicates that the file has no + * static constructor section. + */ + + bvdbg("mod_findsection .ctors section failed: %d\n", ctoridx); + return ret == -ENOENT ? OK : ret; + } + + /* Now we can get a pointer to the .ctor section in the section header + * table. + */ + + shdr = &loadinfo->shdr[ctoridx]; + + /* Get the size of the .ctor section and the number of constructors that + * will need to be called. + */ + + ctorsize = shdr->sh_size; + loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t); + + bvdbg("ctoridx=%d ctorsize=%d sizeof(binfmt_ctor_t)=%d nctors=%d\n", + ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors); + + /* Check if there are any constructors. It is not an error if there + * are none. + */ + + if (loadinfo->nctors > 0) + { + /* Check an assumption that we made above */ + + DEBUGASSERT(shdr->sh_size == loadinfo->nctors * sizeof(binfmt_ctor_t)); + + /* In the old ABI, the .ctors section is not allocated. In that case, + * we need to allocate memory to hold the .ctors and then copy the + * from the file into the allocated memory. + * + * SHF_ALLOC indicates that the section requires memory during + * execution. + */ + + if ((shdr->sh_flags & SHF_ALLOC) == 0) + { + /* Allocate memory to hold a copy of the .ctor section */ + + loadinfo->ctoralloc = (binfmt_ctor_t *)kmm_malloc(ctorsize); + if (!loadinfo->ctoralloc) + { + bdbg("Failed to allocate memory for .ctors\n"); + return -ENOMEM; + } + + loadinfo->ctors = (binfmt_ctor_t *)loadinfo->ctoralloc; + + /* Read the section header table into memory */ + + ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, + shdr->sh_offset); + if (ret < 0) + { + bdbg("Failed to allocate .ctors: %d\n", ret); + return ret; + } + + /* Fix up all of the .ctor addresses. Since the addresses + * do not lie in allocated memory, there will be no relocation + * section for them. + */ + + for (i = 0; i < loadinfo->nctors; i++) + { + FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->ctors)[i]); + + bvdbg("ctor %d: %08lx + %08lx = %08lx\n", + i, *ptr, (unsigned long)loadinfo->textalloc, + (unsigned long)(*ptr + loadinfo->textalloc)); + + *ptr += loadinfo->textalloc; + } + } + else + { + + /* Save the address of the .ctors (actually, .init_array) where it was + * loaded into memory. Since the .ctors lie in allocated memory, they + * will be relocated via the normal mechanism. + */ + + loadinfo->ctors = (binfmt_ctor_t *)shdr->sh_addr; + } + } + + return OK; +} + +#endif /* CONFIG_BINFMT_CONSTRUCTORS */ diff --git a/binfmt/libmodule/libmodule_dtors.c b/binfmt/libmodule/libmodule_dtors.c new file mode 100644 index 0000000000..d94c341ed7 --- /dev/null +++ b/binfmt/libmodule/libmodule_dtors.c @@ -0,0 +1,216 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_dtors.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_loaddtors + * + * Description: + * Load pointers to static destructors into an in-memory array. + * + * Input Parameters: + * loadinfo - Load state information + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) +{ + FAR Elf32_Shdr *shdr; + size_t dtorsize; + int dtoridx; + int ret; + int i; + + DEBUGASSERT(loadinfo->dtors == NULL); + + /* Allocate an I/O buffer if necessary. This buffer is used by + * mod_sectname() to accumulate the variable length symbol name. + */ + + ret = mod_allocbuffer(loadinfo); + if (ret < 0) + { + bdbg("mod_allocbuffer failed: %d\n", ret); + return -ENOMEM; + } + + /* Find the index to the section named ".dtors." NOTE: On old ABI system, + * .dtors is the name of the section containing the list of destructors; + * On newer systems, the similar section is called .fini_array. It is + * expected that the linker script will force the section name to be ".dtors" + * in either case. + */ + + dtoridx = mod_findsection(loadinfo, ".dtors"); + if (dtoridx < 0) + { + /* This may not be a failure. -ENOENT indicates that the file has no + * static destructor section. + */ + + bvdbg("mod_findsection .dtors section failed: %d\n", dtoridx); + return ret == -ENOENT ? OK : ret; + } + + /* Now we can get a pointer to the .dtor section in the section header + * table. + */ + + shdr = &loadinfo->shdr[dtoridx]; + + /* Get the size of the .dtor section and the number of destructors that + * will need to be called. + */ + + dtorsize = shdr->sh_size; + loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t); + + bvdbg("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n", + dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors); + + /* Check if there are any destructors. It is not an error if there + * are none. + */ + + if (loadinfo->ndtors > 0) + { + /* Check an assumption that we made above */ + + DEBUGASSERT(shdr->sh_size == loadinfo->ndtors * sizeof(binfmt_dtor_t)); + + /* In the old ABI, the .dtors section is not allocated. In that case, + * we need to allocate memory to hold the .dtors and then copy the + * from the file into the allocated memory. + * + * SHF_ALLOC indicates that the section requires memory during + * execution. + */ + + if ((shdr->sh_flags & SHF_ALLOC) == 0) + { + /* Allocate memory to hold a copy of the .dtor section */ + + loadinfo->ctoralloc = (binfmt_dtor_t *)kmm_malloc(dtorsize); + if (!loadinfo->ctoralloc) + { + bdbg("Failed to allocate memory for .dtors\n"); + return -ENOMEM; + } + + loadinfo->dtors = (binfmt_dtor_t *)loadinfo->ctoralloc; + + /* Read the section header table into memory */ + + ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, + shdr->sh_offset); + if (ret < 0) + { + bdbg("Failed to allocate .dtors: %d\n", ret); + return ret; + } + + /* Fix up all of the .dtor addresses. Since the addresses + * do not lie in allocated memory, there will be no relocation + * section for them. + */ + + for (i = 0; i < loadinfo->ndtors; i++) + { + FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->dtors)[i]); + + bvdbg("dtor %d: %08lx + %08lx = %08lx\n", + i, *ptr, (unsigned long)loadinfo->textalloc, + (unsigned long)(*ptr + loadinfo->textalloc)); + + *ptr += loadinfo->textalloc; + } + } + else + { + + /* Save the address of the .dtors (actually, .init_array) where it was + * loaded into memory. Since the .dtors lie in allocated memory, they + * will be relocated via the normal mechanism. + */ + + loadinfo->dtors = (binfmt_dtor_t *)shdr->sh_addr; + } + } + + return OK; +} + +#endif /* CONFIG_BINFMT_CONSTRUCTORS */ diff --git a/binfmt/libmodule/libmodule_init.c b/binfmt/libmodule/libmodule_init.c new file mode 100644 index 0000000000..a1ba9b0859 --- /dev/null +++ b/binfmt/libmodule/libmodule_init.c @@ -0,0 +1,202 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_init.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be + * defined or CONFIG_ELF_DUMPBUFFER does nothing. + */ + +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) +# undef CONFIG_ELF_DUMPBUFFER +#endif + +#ifdef CONFIG_ELF_DUMPBUFFER +# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +#else +# define mod_dumpbuffer(m,b,n) +#endif + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_filelen + * + * Description: + * Get the size of the ELF file + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *filename) +{ + struct stat buf; + int ret; + + /* Get the file stats */ + + ret = stat(filename, &buf); + if (ret < 0) + { + int errval = errno; + bdbg("Failed to stat file: %d\n", errval); + return -errval; + } + + /* Verify that it is a regular file */ + + if (!S_ISREG(buf.st_mode)) + { + bdbg("Not a regular file. mode: %d\n", buf.st_mode); + return -ENOENT; + } + + /* TODO: Verify that the file is readable. Not really important because + * we will detect this when we try to open the file read-only. + */ + + /* Return the size of the file in the loadinfo structure */ + + loadinfo->filelen = buf.st_size; + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_initialize + * + * Description: + * This function is called to configure the library to process an ELF + * program binary. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo) +{ + int ret; + + bvdbg("filename: %s loadinfo: %p\n", filename, loadinfo); + + /* Clear the load info structure */ + + memset(loadinfo, 0, sizeof(struct mod_loadinfo_s)); + + /* Get the length of the file. */ + + ret = mod_filelen(loadinfo, filename); + if (ret < 0) + { + bdbg("mod_filelen failed: %d\n", ret); + return ret; + } + + /* Open the binary file for reading (only) */ + + loadinfo->filfd = open(filename, O_RDONLY); + if (loadinfo->filfd < 0) + { + int errval = errno; + bdbg("Failed to open ELF binary %s: %d\n", filename, errval); + return -errval; + } + + /* Read the ELF ehdr from offset 0 */ + + ret = mod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); + if (ret < 0) + { + bdbg("Failed to read ELF header: %d\n", ret); + return ret; + } + + mod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); + + /* Verify the ELF header */ + + ret = mod_verifyheader(&loadinfo->ehdr); + if (ret < 0) + { + /* This may not be an error because we will be called to attempt loading + * EVERY binary. If mod_verifyheader() does not recognize the ELF header, + * it will -ENOEXEC whcih simply informs the system that the file is not an + * ELF file. mod_verifyheader() will return other errors if the ELF header + * is not correctly formed. + */ + + bdbg("Bad ELF header: %d\n", ret); + return ret; + } + + return OK; +} + diff --git a/binfmt/libmodule/libmodule_iobuffer.c b/binfmt/libmodule/libmodule_iobuffer.c new file mode 100644 index 0000000000..17f8da4c5c --- /dev/null +++ b/binfmt/libmodule/libmodule_iobuffer.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * binfmt/libmodule/mod_iobuffer.c + * + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_allocbuffer + * + * Description: + * Perform the initial allocation of the I/O buffer, if it has not already + * been allocated. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) +{ + /* Has a buffer been allocated> */ + + if (!loadinfo->iobuffer) + { + /* No.. allocate one now */ + + loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_ELF_BUFFERSIZE); + if (!loadinfo->iobuffer) + { + bdbg("Failed to allocate an I/O buffer\n"); + return -ENOMEM; + } + + loadinfo->buflen = CONFIG_ELF_BUFFERSIZE; + } + + return OK; +} + +/**************************************************************************** + * Name: mod_reallocbuffer + * + * Description: + * Increase the size of I/O buffer by the specified buffer increment. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) +{ + FAR void *buffer; + size_t newsize; + + /* Get the new size of the allocation */ + + newsize = loadinfo->buflen + increment; + + /* And perform the reallocation */ + + buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize); + if (!buffer) + { + bdbg("Failed to reallocate the I/O buffer\n"); + return -ENOMEM; + } + + /* Save the new buffer info */ + + loadinfo->iobuffer = buffer; + loadinfo->buflen = newsize; + return OK; +} + diff --git a/binfmt/libmodule/libmodule_load.c b/binfmt/libmodule/libmodule_load.c new file mode 100644 index 0000000000..af89d3ff63 --- /dev/null +++ b/binfmt/libmodule/libmodule_load.c @@ -0,0 +1,333 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_load.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1) +#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK) +#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK) + +#ifndef MAX +# define MAX(x,y) ((x) > (y) ? (x) : (y)) +#endif + +#ifndef MIN +# define MIN(x,y) ((x) < (y) ? (x) : (y)) +#endif + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_elfsize + * + * Description: + * Calculate total memory allocation for the ELF file. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +static void mod_elfsize(struct mod_loadinfo_s *loadinfo) +{ + size_t textsize; + size_t datasize; + int i; + + /* Accumulate the size each section into memory that is marked SHF_ALLOC */ + + textsize = 0; + datasize = 0; + + for (i = 0; i < loadinfo->ehdr.e_shnum; i++) + { + FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; + + /* SHF_ALLOC indicates that the section requires memory during + * execution. + */ + + if ((shdr->sh_flags & SHF_ALLOC) != 0) + { + /* SHF_WRITE indicates that the section address space is write- + * able + */ + + if ((shdr->sh_flags & SHF_WRITE) != 0) + { + datasize += ELF_ALIGNUP(shdr->sh_size); + } + else + { + textsize += ELF_ALIGNUP(shdr->sh_size); + } + } + } + + /* Save the allocation size */ + + loadinfo->textsize = textsize; + loadinfo->datasize = datasize; +} + +/**************************************************************************** + * Name: mod_loadfile + * + * Description: + * Read the section data into memory. Section addresses in the shdr[] are + * updated to point to the corresponding position in the memory. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) +{ + FAR uint8_t *text; + FAR uint8_t *data; + FAR uint8_t **pptr; + int ret; + int i; + + /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */ + + bvdbg("Loaded sections:\n"); + text = (FAR uint8_t *)loadinfo->textalloc; + data = (FAR uint8_t *)loadinfo->dataalloc; + + for (i = 0; i < loadinfo->ehdr.e_shnum; i++) + { + FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; + + /* SHF_ALLOC indicates that the section requires memory during + * execution */ + + if ((shdr->sh_flags & SHF_ALLOC) == 0) + { + continue; + } + + /* SHF_WRITE indicates that the section address space is write- + * able + */ + + if ((shdr->sh_flags & SHF_WRITE) != 0) + { + pptr = &data; + } + else + { + pptr = &text; + } + + /* SHT_NOBITS indicates that there is no data in the file for the + * section. + */ + + if (shdr->sh_type != SHT_NOBITS) + { + /* Read the section data from sh_offset to the memory region */ + + ret = mod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); + if (ret < 0) + { + bdbg("ERROR: Failed to read section %d: %d\n", i, ret); + return ret; + } + } + + /* If there is no data in an allocated section, then the allocated + * section must be cleared. + */ + + else + { + memset(*pptr, 0, shdr->sh_size); + } + + /* Update sh_addr to point to copy in memory */ + + bvdbg("%d. %08lx->%08lx\n", i, + (unsigned long)shdr->sh_addr, (unsigned long)*pptr); + + shdr->sh_addr = (uintptr_t)*pptr; + + /* Setup the memory pointer for the next time through the loop */ + + *pptr += ELF_ALIGNUP(shdr->sh_size); + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_load + * + * Description: + * Loads the binary into memory, allocating memory, performing relocations + * and initializing the data and bss segments. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_load(FAR struct mod_loadinfo_s *loadinfo) +{ + size_t heapsize; +#ifdef CONFIG_UCLIBCXX_EXCEPTION + int exidx; +#endif + int ret; + + bvdbg("loadinfo: %p\n", loadinfo); + DEBUGASSERT(loadinfo && loadinfo->filfd >= 0); + + /* Load section headers into memory */ + + ret = mod_loadshdrs(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_loadshdrs failed: %d\n", ret); + goto errout_with_buffers; + } + + /* Determine total size to allocate */ + + mod_elfsize(loadinfo); + + /* Determine the heapsize to allocate. */ + + heapsize = 0; + + /* Allocate (and zero) memory for the ELF file. */ + + /* Allocate memory to hold the ELF image */ + + loadinfo->textalloc = (uintptr_t)kmm_zalloc(textsize + datasize); + if (!loadinfo->textalloc) + { + bdbg("ERROR: Failed to allocate memory for the module\n"); + ret = -ENOMEM; + goto errout_with_buffers; + } + + loadinfo->dataalloc = loadinfo->textalloc + textsize; + + /* Load ELF section data into memory */ + + ret = mod_loadfile(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_loadfile failed: %d\n", ret); + goto errout_with_buffers; + } + + /* Load static constructors and destructors. */ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + ret = mod_loadctors(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_loadctors failed: %d\n", ret); + goto errout_with_buffers; + } + + ret = mod_loaddtors(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_loaddtors failed: %d\n", ret); + goto errout_with_buffers; + } +#endif + +#ifdef CONFIG_UCLIBCXX_EXCEPTION + exidx = mod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); + if (exidx < 0) + { + bvdbg("mod_findsection: Exception Index section not found: %d\n", exidx); + } + else + { + up_init_exidx(loadinfo->shdr[exidx].sh_addr, loadinfo->shdr[exidx].sh_size); + } +#endif + + return OK; + + /* Error exits */ + +errout_with_buffers: + mod_unload(loadinfo); + return ret; +} + diff --git a/binfmt/libmodule/libmodule_read.c b/binfmt/libmodule/libmodule_read.c new file mode 100644 index 0000000000..60f3c37c03 --- /dev/null +++ b/binfmt/libmodule/libmodule_read.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_read.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#undef ELF_DUMP_READDATA /* Define to dump all file data read */ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_dumpreaddata + ****************************************************************************/ + +#if defined(ELF_DUMP_READDATA) +static inline void mod_dumpreaddata(FAR char *buffer, int buflen) +{ + FAR uint32_t *buf32 = (FAR uint32_t *)buffer; + int i; + int j; + + for (i = 0; i < buflen; i += 32) + { + syslog(LOG_DEBUG, "%04x:", i); + for (j = 0; j < 32; j += sizeof(uint32_t)) + { + syslog(LOG_DEBUG, " %08x", *buf32++); + } + + syslog(LOG_DEBUG, "\n"); + } +} +#else +# define mod_dumpreaddata(b,n) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_read + * + * Description: + * Read 'readsize' bytes from the object file at 'offset'. The data is + * read into 'buffer.' + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset) +{ + ssize_t nbytes; /* Number of bytes read */ + off_t rpos; /* Position returned by lseek */ + + bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset); + + /* Loop until all of the requested data has been read. */ + + while (readsize > 0) + { + /* Seek to the next read position */ + + rpos = lseek(loadinfo->filfd, offset, SEEK_SET); + if (rpos != offset) + { + int errval = errno; + bdbg("Failed to seek to position %lu: %d\n", + (unsigned long)offset, errval); + return -errval; + } + + /* Read the file data at offset into the user buffer */ + + nbytes = read(loadinfo->filfd, buffer, readsize); + if (nbytes < 0) + { + int errval = errno; + + /* EINTR just means that we received a signal */ + + if (errval != EINTR) + { + bdbg("Read from offset %lu failed: %d\n", + (unsigned long)offset, errval); + return -errval; + } + } + else if (nbytes == 0) + { + bdbg("Unexpected end of file\n"); + return -ENODATA; + } + else + { + readsize -= nbytes; + buffer += nbytes; + offset += nbytes; + } + } + + mod_dumpreaddata(buffer, readsize); + return OK; +} diff --git a/binfmt/libmodule/libmodule_sections.c b/binfmt/libmodule/libmodule_sections.c new file mode 100644 index 0000000000..183d014141 --- /dev/null +++ b/binfmt/libmodule/libmodule_sections.c @@ -0,0 +1,287 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_sections.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_sectname + * + * Description: + * Get the symbol name in loadinfo->iobuffer[]. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *shdr) +{ + FAR Elf32_Shdr *shstr; + FAR uint8_t *buffer; + off_t offset; + size_t readlen; + size_t bytesread; + int shstrndx; + int ret; + + /* Get the section header table index of the entry associated with the + * section name string table. If the file has no section name string table, + * this member holds the value SH_UNDEF. + */ + + shstrndx = loadinfo->ehdr.e_shstrndx; + if (shstrndx == SHN_UNDEF) + { + bdbg("No section header string table\n"); + return -EINVAL; + } + + /* Get the section name string table section header */ + + shstr = &loadinfo->shdr[shstrndx]; + + /* Get the file offset to the string that is the name of the section. This + * is the sum of: + * + * shstr->sh_offset: The file offset to the first byte of the section + * header string table data. + * shdr->sh_name: The offset to the name of the section in the section + * name table + */ + + offset = shstr->sh_offset + shdr->sh_name; + + /* Loop until we get the entire section name into memory */ + + buffer = loadinfo->iobuffer; + bytesread = 0; + + for (; ; ) + { + /* Get the number of bytes to read */ + + readlen = loadinfo->buflen - bytesread; + if (offset + readlen > loadinfo->filelen) + { + if (loadinfo->filelen <= offset) + { + bdbg("At end of file\n"); + return -EINVAL; + } + + readlen = loadinfo->filelen - offset; + } + + /* Read that number of bytes into the array */ + + buffer = &loadinfo->iobuffer[bytesread]; + ret = mod_read(loadinfo, buffer, readlen, offset); + if (ret < 0) + { + bdbg("Failed to read section name\n"); + return ret; + } + + bytesread += readlen; + + /* Did we read the NUL terminator? */ + + if (memchr(buffer, '\0', readlen) != NULL) + { + /* Yes, the buffer contains a NUL terminator. */ + + return OK; + } + + /* No.. then we have to read more */ + + ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + if (ret < 0) + { + bdbg("mod_reallocbuffer failed: %d\n", ret); + return ret; + } + } + + /* We will not get here */ + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_loadshdrs + * + * Description: + * Loads section headers into memory. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) +{ + size_t shdrsize; + int ret; + + DEBUGASSERT(loadinfo->shdr == NULL); + + /* Verify that there are sections */ + + if (loadinfo->ehdr.e_shnum < 1) + { + bdbg("No sections(?)\n"); + return -EINVAL; + } + + /* Get the total size of the section header table */ + + shdrsize = (size_t)loadinfo->ehdr.e_shentsize * (size_t)loadinfo->ehdr.e_shnum; + if (loadinfo->ehdr.e_shoff + shdrsize > loadinfo->filelen) + { + bdbg("Insufficent space in file for section header table\n"); + return -ESPIPE; + } + + /* Allocate memory to hold a working copy of the sector header table */ + + loadinfo->shdr = (FAR FAR Elf32_Shdr *)kmm_malloc(shdrsize); + if (!loadinfo->shdr) + { + bdbg("Failed to allocate the section header table. Size: %ld\n", + (long)shdrsize); + return -ENOMEM; + } + + /* Read the section header table into memory */ + + ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + loadinfo->ehdr.e_shoff); + if (ret < 0) + { + bdbg("Failed to read section header table: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: mod_findsection + * + * Description: + * A section by its name. + * + * Input Parameters: + * loadinfo - Load state information + * sectname - Name of the section to find + * + * Returned Value: + * On success, the index to the section is returned; A negated errno value + * is returned on failure. + * + ****************************************************************************/ + +int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname) +{ + FAR const Elf32_Shdr *shdr; + int ret; + int i; + + /* Search through the shdr[] array in loadinfo for a section named 'sectname' */ + + for (i = 0; i < loadinfo->ehdr.e_shnum; i++) + { + /* Get the name of this section */ + + shdr = &loadinfo->shdr[i]; + ret = mod_sectname(loadinfo, shdr); + if (ret < 0) + { + bdbg("mod_sectname failed: %d\n", ret); + return ret; + } + + /* Check if the name of this section is 'sectname' */ + + bvdbg("%d. Comparing \"%s\" and .\"%s\"\n", + i, loadinfo->iobuffer, sectname); + + if (strcmp((FAR const char *)loadinfo->iobuffer, sectname) == 0) + { + /* We found it... return the index */ + + return i; + } + } + + /* We failed to find a section with this name. */ + + return -ENOENT; +} diff --git a/binfmt/libmodule/libmodule_symbols.c b/binfmt/libmodule/libmodule_symbols.c new file mode 100644 index 0000000000..9e9de001d7 --- /dev/null +++ b/binfmt/libmodule/libmodule_symbols.c @@ -0,0 +1,346 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_symbols.c + * + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_ELF_BUFFERINCR +# define CONFIG_ELF_BUFFERINCR 32 +#endif + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_symname + * + * Description: + * Get the symbol name in loadinfo->iobuffer[]. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + * EINVAL - There is something inconsistent in the symbol table (should only + * happen if the file is corrupted). + * ESRCH - Symbol has no name + * + ****************************************************************************/ + +static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Sym *sym) +{ + FAR uint8_t *buffer; + off_t offset; + size_t readlen; + size_t bytesread; + int ret; + + /* Get the file offset to the string that is the name of the symbol. The + * st_name member holds an offset into the file's symbol string table. + */ + + if (sym->st_name == 0) + { + bdbg("Symbol has no name\n"); + return -ESRCH; + } + + offset = loadinfo->shdr[loadinfo->strtabidx].sh_offset + sym->st_name; + + /* Loop until we get the entire symbol name into memory */ + + bytesread = 0; + + for (; ; ) + { + /* Get the number of bytes to read */ + + readlen = loadinfo->buflen - bytesread; + if (offset + readlen > loadinfo->filelen) + { + if (loadinfo->filelen <= offset) + { + bdbg("At end of file\n"); + return -EINVAL; + } + + readlen = loadinfo->filelen - offset; + } + + /* Read that number of bytes into the array */ + + buffer = &loadinfo->iobuffer[bytesread]; + ret = mod_read(loadinfo, buffer, readlen, offset); + if (ret < 0) + { + bdbg("mod_read failed: %d\n", ret); + return ret; + } + + bytesread += readlen; + + /* Did we read the NUL terminator? */ + + if (memchr(buffer, '\0', readlen) != NULL) + { + /* Yes, the buffer contains a NUL terminator. */ + + return OK; + } + + /* No.. then we have to read more */ + + ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + if (ret < 0) + { + bdbg("mod_reallocbuffer failed: %d\n", ret); + return ret; + } + } + + /* We will not get here */ + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_findsymtab + * + * Description: + * Find the symbol table section. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) +{ + int i; + + /* Find the symbol table section header and its associated string table */ + + for (i = 1; i < loadinfo->ehdr.e_shnum; i++) + { + if (loadinfo->shdr[i].sh_type == SHT_SYMTAB) + { + loadinfo->symtabidx = i; + loadinfo->strtabidx = loadinfo->shdr[i].sh_link; + break; + } + } + + /* Verify that there is a symbol and string table */ + + if (loadinfo->symtabidx == 0) + { + bdbg("No symbols in ELF file\n"); + return -EINVAL; + } + + return OK; +} + +/**************************************************************************** + * Name: mod_readsym + * + * Description: + * Read the ELFT symbol structure at the specfied index into memory. + * + * Input Parameters: + * loadinfo - Load state information + * index - Symbol table index + * sym - Location to return the table entry + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym) +{ + FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; + off_t offset; + + /* Verify that the symbol table index lies within symbol table */ + + if (index < 0 || index > (symtab->sh_size / sizeof(Elf32_Sym))) + { + bdbg("Bad relocation symbol index: %d\n", index); + return -EINVAL; + } + + /* Get the file offset to the symbol table entry */ + + offset = symtab->sh_offset + sizeof(Elf32_Sym) * index; + + /* And, finally, read the symbol table entry into memory */ + + return mod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); +} + +/**************************************************************************** + * Name: mod_symvalue + * + * Description: + * Get the value of a symbol. The updated value of the symbol is returned + * in the st_value field of the symbol table entry. + * + * Input Parameters: + * loadinfo - Load state information + * sym - Symbol table entry (value might be undefined) + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + * EINVAL - There is something inconsistent in the symbol table (should only + * happen if the file is corrupted). + * ENOSYS - Symbol lies in common + * ESRCH - Symbol has no name + * ENOENT - Symbol undefined and not provided via a symbol table + * + ****************************************************************************/ + +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports) +{ + FAR const struct symtab_s *symbol; + uintptr_t secbase; + int ret; + + switch (sym->st_shndx) + { + case SHN_COMMON: + { + /* NuttX ELF modules should be compiled with -fno-common. */ + + bdbg("SHN_COMMON: Re-compile with -fno-common\n"); + return -ENOSYS; + } + + case SHN_ABS: + { + /* st_value already holds the correct value */ + + bvdbg("SHN_ABS: st_value=%08lx\n", (long)sym->st_value); + return OK; + } + + case SHN_UNDEF: + { + /* Get the name of the undefined symbol */ + + ret = mod_symname(loadinfo, sym); + if (ret < 0) + { + /* There are a few relocations for a few architectures that do + * no depend upon a named symbol. We don't know if that is the + * case here, but return and special error to the caller to + * indicate the nameless symbol. + */ + + bdbg("SHN_UNDEF: Failed to get symbol name: %d\n", ret); + return ret; + } + + /* Check if the base code exports a symbol of this name */ + +#ifdef CONFIG_SYMTAB_ORDEREDBYNAME + symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports); +#else + symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports); +#endif + if (!symbol) + { + bdbg("SHN_UNDEF: Exported symbol \"%s\" not found\n", loadinfo->iobuffer); + return -ENOENT; + } + + /* Yes... add the exported symbol value to the ELF symbol table entry */ + + bvdbg("SHN_ABS: name=%s %08x+%08x=%08x\n", + loadinfo->iobuffer, sym->st_value, symbol->sym_value, + sym->st_value + symbol->sym_value); + + sym->st_value += (Elf32_Word)((uintptr_t)symbol->sym_value); + } + break; + + default: + { + secbase = loadinfo->shdr[sym->st_shndx].sh_addr; + + bvdbg("Other: %08x+%08x=%08x\n", + sym->st_value, secbase, sym->st_value + secbase); + + sym->st_value += secbase; + } + break; + } + + return OK; +} diff --git a/binfmt/libmodule/libmodule_uninit.c b/binfmt/libmodule/libmodule_uninit.c new file mode 100644 index 0000000000..9ca3684ce3 --- /dev/null +++ b/binfmt/libmodule/libmodule_uninit.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_uninit.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_uninit + * + * Description: + * Releases any resources committed by mod_initialize(). This essentially + * undoes the actions of mod_initialize. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_uninit(struct mod_loadinfo_s *loadinfo) +{ + /* Free all working buffers */ + + mod_freebuffers(loadinfo); + + /* Close the ELF file */ + + if (loadinfo->filfd >= 0) + { + close(loadinfo->filfd); + } + + return OK; +} + +/**************************************************************************** + * Name: mod_freebuffers + * + * Description: + * Release all working buffers. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_freebuffers(struct mod_loadinfo_s *loadinfo) +{ + /* Release all working allocations */ + + if (loadinfo->shdr) + { + kmm_free((FAR void *)loadinfo->shdr); + loadinfo->shdr = NULL; + } + + if (loadinfo->iobuffer) + { + kmm_free((FAR void *)loadinfo->iobuffer); + loadinfo->iobuffer = NULL; + loadinfo->buflen = 0; + } + + return OK; +} diff --git a/binfmt/libmodule/libmodule_unload.c b/binfmt/libmodule/libmodule_unload.c new file mode 100644 index 0000000000..c424a8686b --- /dev/null +++ b/binfmt/libmodule/libmodule_unload.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * binfmt/libmodule/libmodule_unload.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "libmodule.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_unload + * + * Description: + * This function unloads the object from memory. This essentially undoes + * the actions of mod_load. It is called only under certain error + * conditions after the module has been loaded but not yet started. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_unload(struct mod_loadinfo_s *loadinfo) +{ + /* Free all working buffers */ + + mod_freebuffers(loadinfo); + + /* Release memory holding the relocated ELF image */ + + if (loadinfo->textalloc != 0) + { + kmm_free((FAR void *)loadinfo->textalloc); + } + + /* Clear out all indications of the allocated address environment */ + + loadinfo->textalloc = 0; + loadinfo->dataalloc = 0; + loadinfo->textsize = 0; + loadinfo->datasize = 0; + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + /* Release memory used to hold static constructors and destructors */ + + if (loadinfo->ctoralloc != 0) + { + kmm_free(loadinfo->ctoralloc); + loadinfo->ctoralloc = NULL; + } + + loadinfo->ctors = NULL; + loadinfo->nctors = 0; + + if (loadinfo->dtoralloc != 0) + { + kmm_free(loadinfo->dtoralloc); + loadinfo->dtoralloc = NULL; + } + + loadinfo->dtors = NULL; + loadinfo->ndtors = 0; +#endif + + return OK; +} + diff --git a/binfmt/libmodule/libmodule_verify.c b/binfmt/libmodule/libmodule_verify.c new file mode 100644 index 0000000000..9d207180b3 --- /dev/null +++ b/binfmt/libmodule/libmodule_verify.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * binfmt/libmodule/mod_verify.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +static const char g_modmagic[EI_MAGIC_SIZE] = +{ + 0x7f, 'E', 'L', 'F' +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_verifyheader + * + * Description: + * Given the header from a possible ELF executable, verify that it + * is an ELF executable. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + * -ENOEXEC : Not an ELF file + * -EINVAL : Not a relocatable ELF file or not supported by the current, + * configured architecture. + * + ****************************************************************************/ + +int mod_verifyheader(FAR const Elf32_Ehdr *ehdr) +{ + if (!ehdr) + { + bdbg("NULL ELF header!"); + return -ENOEXEC; + } + + /* Verify that the magic number indicates an ELF file */ + + if (memcmp(ehdr->e_ident, g_modmagic, EI_MAGIC_SIZE) != 0) + { + bvdbg("Not ELF magic {%02x, %02x, %02x, %02x}\n", + ehdr->e_ident[0], ehdr->e_ident[1], ehdr->e_ident[2], ehdr->e_ident[3]); + return -ENOEXEC; + } + + /* Verify that this is a relocatable file */ + + if (ehdr->e_type != ET_REL) + { + bdbg("Not a relocatable file: e_type=%d\n", ehdr->e_type); + return -EINVAL; + } + + /* Verify that this file works with the currently configured architecture */ + + if (up_checkarch(ehdr)) + { + bdbg("Not a supported architecture\n"); + return -ENOEXEC; + } + + /* Looks good so far... we still might find some problems later. */ + + return OK; +} + diff --git a/binfmt/module.c b/binfmt/module.c new file mode 100644 index 0000000000..79f63df7c7 --- /dev/null +++ b/binfmt/module.c @@ -0,0 +1,368 @@ +/**************************************************************************** + * binfmt/module.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "libmodule/libmodule.h" + +#ifdef CONFIG_MODULE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be + * defined or CONFIG_MODULE_DUMPBUFFER does nothing. + */ + +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) +# undef CONFIG_MODULE_DUMPBUFFER +#endif + +#ifndef CONFIG_MODULE_STACKSIZE +# define CONFIG_MODULE_STACKSIZE 2048 +#endif + +#ifdef CONFIG_MODULE_DUMPBUFFER +# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +#else +# define mod_dumpbuffer(m,b,n) +#endif + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int mod_loadbinary(FAR struct binary_s *binp); +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) +static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct binfmt_s g_modbinfmt = +{ + NULL, /* next */ + mod_loadbinary, /* load */ + NULL, /* unload */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_dumploadinfo + ****************************************************************************/ + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) +static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) +{ + int i; + + bdbg("LOAD_INFO:\n"); + bdbg(" textalloc: %08lx\n", (long)loadinfo->textalloc); + bdbg(" dataalloc: %08lx\n", (long)loadinfo->dataalloc); + bdbg(" textsize: %ld\n", (long)loadinfo->textsize); + bdbg(" datasize: %ld\n", (long)loadinfo->datasize); + bdbg(" filelen: %ld\n", (long)loadinfo->filelen); +#ifdef CONFIG_BINFMT_CONSTRUCTORS + bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc); + bdbg(" ctors: %08lx\n", (long)loadinfo->ctors); + bdbg(" nctors: %d\n", loadinfo->nctors); + bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc); + bdbg(" dtors: %08lx\n", (long)loadinfo->dtors); + bdbg(" ndtors: %d\n", loadinfo->ndtors); +#endif + bdbg(" filfd: %d\n", loadinfo->filfd); + bdbg(" symtabidx: %d\n", loadinfo->symtabidx); + bdbg(" strtabidx: %d\n", loadinfo->strtabidx); + + bdbg("ELF Header:\n"); + bdbg(" e_ident: %02x %02x %02x %02x\n", + loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1], + loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]); + bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type); + bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine); + bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version); + bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); + bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); + bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); + bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); + bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); + bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); + bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); + bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); + bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); + bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); + + if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0) + { + for (i = 0; i < loadinfo->ehdr.e_shnum; i++) + { + FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; + bdbg("Sections %d:\n", i); + bdbg(" sh_name: %08x\n", shdr->sh_name); + bdbg(" sh_type: %08x\n", shdr->sh_type); + bdbg(" sh_flags: %08x\n", shdr->sh_flags); + bdbg(" sh_addr: %08x\n", shdr->sh_addr); + bdbg(" sh_offset: %d\n", shdr->sh_offset); + bdbg(" sh_size: %d\n", shdr->sh_size); + bdbg(" sh_link: %d\n", shdr->sh_link); + bdbg(" sh_info: %d\n", shdr->sh_info); + bdbg(" sh_addralign: %d\n", shdr->sh_addralign); + bdbg(" sh_entsize: %d\n", shdr->sh_entsize); + } + } +} +#else +# define mod_dumploadinfo(i) +#endif + +/**************************************************************************** + * Name: mod_dumpentrypt + ****************************************************************************/ + +#ifdef CONFIG_MODULE_DUMPBUFFER +static void mod_dumpentrypt(FAR struct binary_s *binp, + FAR struct mod_loadinfo_s *loadinfo) +{ +#ifdef CONFIG_ARCH_ADDRENV + int ret; + + /* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address + * space that may not be in place now. mod_addrenv_select() will + * temporarily instantiate that address space. + */ + + ret = mod_addrenv_select(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_addrenv_select() failed: %d\n", ret); + return; + } +#endif + + mod_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, + MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); + +#ifdef CONFIG_ARCH_ADDRENV + /* Restore the original address environment */ + + ret = mod_addrenv_restore(loadinfo); + if (ret < 0) + { + bdbg("ERROR: mod_addrenv_restore() failed: %d\n", ret); + } +#endif +} +#else +# define mod_dumpentrypt(b,l) +#endif + +/**************************************************************************** + * Name: mod_loadbinary + * + * Description: + * Verify that the file is an ELF binary and, if so, load the ELF + * binary into memory + * + ****************************************************************************/ + +static int mod_loadbinary(FAR struct binary_s *binp) +{ + struct mod_loadinfo_s loadinfo; /* Contains globals for libmodule */ + int ret; + + bvdbg("Loading file: %s\n", binp->filename); + + /* Initialize the ELF library to load the program binary. */ + + ret = mod_init(binp->filename, &loadinfo); + mod_dumploadinfo(&loadinfo); + if (ret != 0) + { + bdbg("Failed to initialize for load of ELF program: %d\n", ret); + goto errout; + } + + /* Load the program binary */ + + ret = mod_load(&loadinfo); + mod_dumploadinfo(&loadinfo); + if (ret != 0) + { + bdbg("Failed to load ELF program binary: %d\n", ret); + goto errout_with_init; + } + + /* Bind the program to the exported symbol table */ + + ret = mod_bind(&loadinfo, binp->exports, binp->nexports); + if (ret != 0) + { + bdbg("Failed to bind symbols program binary: %d\n", ret); + goto errout_with_load; + } + + /* Return the load information */ + + binp->entrypt = (main_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); + binp->stacksize = CONFIG_MODULE_STACKSIZE; + + /* Add the ELF allocation to the alloc[] only if there is no address + * environment. If there is an address environment, it will automatically + * be freed when the function exits + * + * REVISIT: If the module is loaded then unloaded, wouldn't this cause + * a memory leak? + */ + +#ifdef CONFIG_ARCH_ADDRENV +# warning "REVISIT" +#else + binp->alloc[0] = (FAR void *)loadinfo.textalloc; +#endif + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + /* Save information about constructors. NOTE: destructors are not + * yet supported. + */ + + binp->alloc[1] = loadinfo.ctoralloc; + binp->ctors = loadinfo.ctors; + binp->nctors = loadinfo.nctors; + + binp->alloc[2] = loadinfo.dtoralloc; + binp->dtors = loadinfo.dtors; + binp->ndtors = loadinfo.ndtors; +#endif + +#ifdef CONFIG_ARCH_ADDRENV + /* Save the address environment in the binfmt structure. This will be + * needed when the module is executed. + */ + + up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv); +#endif + + mod_dumpentrypt(binp, &loadinfo); + mod_uninit(&loadinfo); + return OK; + +errout_with_load: + mod_unload(&loadinfo); +errout_with_init: + mod_uninit(&loadinfo); +errout: + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_initialize + * + * Description: + * ELF support is built unconditionally. However, in order to + * use this binary format, this function must be called during system + * initialization in order to register the ELF binary format. + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_initialize(void) +{ + int ret; + + /* Register ourselves as a binfmt loader */ + + bvdbg("Registering ELF\n"); + + ret = register_binfmt(&g_modbinfmt); + if (ret != 0) + { + bdbg("Failed to register binfmt: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: mod_uninitialize + * + * Description: + * Unregister the ELF binary loader + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_uninitialize(void) +{ + unregister_binfmt(&g_modbinfmt); +} + +#endif /* CONFIG_MODULE */ diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/binfmt/module.h new file mode 100644 index 0000000000..811921f14f --- /dev/null +++ b/include/nuttx/binfmt/module.h @@ -0,0 +1,369 @@ +/**************************************************************************** + * include/nuttx/binfmt/module.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_MODULE_H +#define __INCLUDE_NUTTX_BINFMT_MODULE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_MODULE_ALIGN_LOG2 +# define CONFIG_MODULE_ALIGN_LOG2 2 +#endif + +#ifndef CONFIG_MODULE_STACKSIZE +# define CONFIG_MODULE_STACKSIZE 2048 +#endif + +#ifndef CONFIG_MODULE_BUFFERSIZE +# define CONFIG_MODULE_BUFFERSIZE 128 +#endif + +#ifndef CONFIG_MODULE_BUFFERINCR +# define CONFIG_MODULE_BUFFERINCR 32 +#endif + +/* Allocation array size and indices */ + +#define LIBMODULE_MODULE_ALLOC 0 +#ifdef CONFIG_BINFMT_CONSTRUCTORS +# define LIBMODULE_CTORS_ALLOC 1 +# define LIBMODULE_CTPRS_ALLOC 2 +# define LIBMODULE_NALLOC 3 +#else +# define LIBMODULE_NALLOC 1 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This struct provides a description of the currently loaded instantiation + * of the kernel module. + */ + +struct mod_loadinfo_s +{ + /* elfalloc is the base address of the memory that is allocated to hold the + * module image. + * + * If CONFIG_ARCH_ADDRENV=n, elfalloc will be allocated using kmm_malloc() (or + * kmm_zalloc()). If CONFIG_ARCH_ADDRENV-y, then elfalloc will be allocated using + * up_addrenv_create(). In either case, there will be a unique instance + * of elfalloc (and stack) for each instance of a process. + * + * The alloc[] array in struct binary_s will hold memory that persists after + * the module has been loaded. + */ + + uintptr_t textalloc; /* .text memory allocated when module was loaded */ + uintptr_t dataalloc; /* .bss/.data memory allocated when module was loaded */ + size_t textsize; /* Size of the module .text memory allocation */ + size_t datasize; /* Size of the module .bss/.data memory allocation */ + off_t filelen; /* Length of the entire module file */ + Elf32_Ehdr ehdr; /* Buffered module file header */ + FAR Elf32_Shdr *shdr; /* Buffered module section headers */ + uint8_t *iobuffer; /* File I/O buffer */ + + /* Constructors and destructors */ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + FAR void *ctoralloc; /* Memory allocated for ctors */ + FAR void *dtoralloc; /* Memory allocated dtors */ + FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */ + FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */ + uint16_t nctors; /* Number of constructors */ + uint16_t ndtors; /* Number of destructors */ +#endif + + /* Address environment. + * + * addrenv - This is the handle created by up_addrenv_create() that can be + * used to manage the tasks address space. + * oldenv - This is a value returned by up_addrenv_select() that must be + * used to restore the current address environment. + */ + +#ifdef CONFIG_ARCH_ADDRENV + group_addrenv_t addrenv; /* Task group address environment */ + save_addrenv_t oldenv; /* Saved address environment */ +#endif + + uint16_t symtabidx; /* Symbol table section index */ + uint16_t strtabidx; /* String table section index */ + uint16_t buflen; /* size of iobuffer[] */ + int filfd; /* Descriptor for the file being loaded */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * These are APIs exported by libelf (but are used only by the binfmt logic): + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_init + * + * Description: + * This function is called to configure the library to process an kernel + * module. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_init(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_uninit + * + * Description: + * Releases any resources committed by mod_init(). This essentially + * undoes the actions of mod_init. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_uninit(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_load + * + * Description: + * Loads the binary into memory, allocating memory, performing relocations + * and initializing the data and bss segments. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_load(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: mod_bind + * + * Description: + * Bind the imported symbol names in the loaded module described by + * 'loadinfo' using the exported symbol values provided by 'symtab'. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +struct symtab_s; +int mod_bind(FAR struct mod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: mod_unload + * + * Description: + * This function unloads the object from memory. This essentially undoes + * the actions of mod_load. It is called only under certain error + * conditions after the module has been loaded but not yet started. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_unload(struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * These are APIs used outside of binfmt by NuttX: + ****************************************************************************/ +/**************************************************************************** + * Name: mod_initialize + * + * Description: + * Module support is built unconditionally. However, in order to + * use this binary format, this function must be called during system + * initialization in order to register the module binary format. + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int mod_initialize(void); + +/**************************************************************************** + * Name: mod_uninitialize + * + * Description: + * Unregister the module loader + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_uninitialize(void); + +/**************************************************************************** + * These are APIs must be provided by architecture-specific logic. + * (These really belong in include/nuttx/arch.h): + ****************************************************************************/ +/**************************************************************************** + * Name: up_checkarch + * + * Description: + * Given the ELF header in 'hdr', verify that the module is appropriate + * for the current, configured architecture. Every architecture that uses + * the module loader must provide this function. + * + * Input Parameters: + * hdr - The ELF header read from the module file. + * + * Returned Value: + * True if the architecture supports this module file. + * + ****************************************************************************/ + +bool up_checkarch(FAR const Elf32_Ehdr *hdr); + +/**************************************************************************** + * Name: up_relocate and up_relocateadd + * + * Description: + * Perform on architecture-specific ELF relocation. Every architecture + * that uses the module loader must provide this function. + * + * Input Parameters: + * rel - The relocation type + * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. + * addr - The address that requires the relocation. + * + * Returned Value: + * Zero (OK) if the relocation was successful. Otherwise, a negated errno + * value indicating the cause of the relocation failure. + * + ****************************************************************************/ + +int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, + uintptr_t addr); +int up_relocateadd(FAR const Elf32_Rela *rel, + FAR const Elf32_Sym *sym, uintptr_t addr); + +#ifdef CONFIG_UCLIBCXX_EXCEPTION +/**************************************************************************** + * Name: up_init_exidx + * + * Description: + * Load the boundaries of the Exception Index ELF section in order to + * support exception handling for loaded modules. + * + * Input Parameters: + * address - The ELF section address for the Exception Index + * size - The size of the ELF section. + * + * Returned Value: + * Always returns Zero (OK). + * + ****************************************************************************/ +int up_init_exidx(Elf32_Addr address, Elf32_Word size); +#endif + +/**************************************************************************** + * Name: up_coherent_dcache + * + * Description: + * Ensure that the I and D caches are coherent within specified region + * by cleaning the D cache (i.e., flushing the D cache contents to memory + * and invalidating the I cache. This is typically used when code has been + * written to a memory region, and will be executed. + * + * Input Parameters: + * addr - virtual start address of region + * len - Size of the address region in bytes + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE +void up_coherent_dcache(uintptr_t addr, size_t len); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_MODULE_H */ -- GitLab From 251e8395c7b00e1d0ab79a17f6ff7fa169dc35ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Dec 2015 16:56:10 -0600 Subject: [PATCH 437/858] Mostly cosmetic renaming to straighten out namespace --- binfmt/libmodule/libmodule.h | 56 +++++++++++++-------------- binfmt/libmodule/libmodule_bind.c | 48 +++++++++++------------ binfmt/libmodule/libmodule_ctors.c | 16 ++++---- binfmt/libmodule/libmodule_dtors.c | 16 ++++---- binfmt/libmodule/libmodule_init.c | 33 +++++++++------- binfmt/libmodule/libmodule_iobuffer.c | 10 ++--- binfmt/libmodule/libmodule_load.c | 38 +++++++++--------- binfmt/libmodule/libmodule_read.c | 14 +++---- binfmt/libmodule/libmodule_sections.c | 30 +++++++------- binfmt/libmodule/libmodule_symbols.c | 34 ++++++++-------- binfmt/libmodule/libmodule_uninit.c | 14 +++---- binfmt/libmodule/libmodule_unload.c | 8 ++-- binfmt/libmodule/libmodule_verify.c | 6 +-- binfmt/module.c | 50 +++--------------------- include/nuttx/binfmt/elf.h | 1 + include/nuttx/binfmt/module.h | 10 +++-- 16 files changed, 176 insertions(+), 208 deletions(-) diff --git a/binfmt/libmodule/libmodule.h b/binfmt/libmodule/libmodule.h index eeed0498df..fb003a7ac9 100644 --- a/binfmt/libmodule/libmodule.h +++ b/binfmt/libmodule/libmodule.h @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_verifyheader + * Name: libmod_verifyheader * * Description: * Given the header from a possible ELF executable, verify that it is @@ -69,10 +69,10 @@ * ****************************************************************************/ -int mod_verifyheader(FAR const Elf32_Ehdr *header); +int libmod_verifyheader(FAR const Elf32_Ehdr *header); /**************************************************************************** - * Name: mod_read + * Name: libmod_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -84,11 +84,11 @@ int mod_verifyheader(FAR const Elf32_Ehdr *header); * ****************************************************************************/ -int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset); +int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset); /**************************************************************************** - * Name: mod_loadshdrs + * Name: libmod_loadshdrs * * Description: * Loads section headers into memory. @@ -99,10 +99,10 @@ int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, * ****************************************************************************/ -int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); +int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_findsection + * Name: libmod_findsection * * Description: * A section by its name. @@ -117,11 +117,11 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *sectname); +int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *sectname); /**************************************************************************** - * Name: mod_findsymtab + * Name: libmod_findsymtab * * Description: * Find the symbol table section. @@ -132,10 +132,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); +int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_readsym + * Name: libmod_readsym * * Description: * Read the ELFT symbol structure at the specfied index into memory. @@ -151,11 +151,11 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym); +int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym); /**************************************************************************** - * Name: mod_symvalue + * Name: libmod_symvalue * * Description: * Get the value of a symbol. The updated value of the symbol is returned @@ -179,11 +179,11 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports); +int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports); /**************************************************************************** - * Name: mod_freebuffers + * Name: libmod_freebuffers * * Description: * Release all working buffers. @@ -194,10 +194,10 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, * ****************************************************************************/ -int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); +int libmod_freebuffers(FAR struct libmod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_allocbuffer + * Name: libmod_allocbuffer * * Description: * Perform the initial allocation of the I/O buffer, if it has not already @@ -209,10 +209,10 @@ int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); +int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_reallocbuffer + * Name: libmod_reallocbuffer * * Description: * Increase the size of I/O buffer by the specified buffer increment. @@ -223,10 +223,10 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); +int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment); /**************************************************************************** - * Name: mod_findctors + * Name: libmod_findctors * * Description: * Find C++ static constructors. @@ -241,11 +241,11 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); ****************************************************************************/ #ifdef CONFIG_BINFMT_CONSTRUCTORS -int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo); +int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo); #endif /**************************************************************************** - * Name: mod_loaddtors + * Name: libmod_loaddtors * * Description: * Load pointers to static destructors into an in-memory array. @@ -260,7 +260,7 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo); ****************************************************************************/ #ifdef CONFIG_BINFMT_CONSTRUCTORS -int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo); +int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo); #endif #endif /* __BINFMT_LIBELF_LIBELF_H */ diff --git a/binfmt/libmodule/libmodule_bind.c b/binfmt/libmodule/libmodule_bind.c index 8b5b680c8b..199be22faa 100644 --- a/binfmt/libmodule/libmodule_bind.c +++ b/binfmt/libmodule/libmodule_bind.c @@ -68,9 +68,9 @@ #endif #ifdef CONFIG_ELF_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) #else -# define mod_dumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -86,16 +86,16 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_readrel + * Name: libmod_readrel * * Description: * Read the ELF32_Rel structure into memory. * ****************************************************************************/ -static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *relsec, - int index, FAR Elf32_Rel *rel) +static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *relsec, + int index, FAR Elf32_Rel *rel) { off_t offset; @@ -113,11 +113,11 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, /* And, finally, read the symbol table entry into memory */ - return mod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); + return libmod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); } /**************************************************************************** - * Name: mod_relocate and mod_relocateadd + * Name: libmod_relocate and libmod_relocateadd * * Description: * Perform all relocations associated with a section. @@ -128,8 +128,8 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) { FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx]; @@ -153,7 +153,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, /* Read the relocation entry into memory */ - ret = mod_readrel(loadinfo, relsec, i, &rel); + ret = libmod_readrel(loadinfo, relsec, i, &rel); if (ret < 0) { bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n", @@ -169,7 +169,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, /* Read the symbol table entry into memory */ - ret = mod_readsym(loadinfo, symidx, &sym); + ret = libmod_readsym(loadinfo, symidx, &sym); if (ret < 0) { bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n", @@ -179,7 +179,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, /* Get the value of the symbol (in sym.st_value) */ - ret = mod_symvalue(loadinfo, &sym, exports, nexports); + ret = libmod_symvalue(loadinfo, &sym, exports, nexports); if (ret < 0) { /* The special error -ESRCH is returned only in one condition: The @@ -230,8 +230,8 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, return OK; } -static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) { bdbg("Not implemented\n"); return -ENOSYS; @@ -242,7 +242,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, ****************************************************************************/ /**************************************************************************** - * Name: mod_bind + * Name: libmod_bind * * Description: * Bind the imported symbol names in the loaded module described by @@ -254,28 +254,28 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, * ****************************************************************************/ -int mod_bind(FAR struct mod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports) +int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports) { int ret; int i; /* Find the symbol and string tables */ - ret = mod_findsymtab(loadinfo); + ret = libmod_findsymtab(loadinfo); if (ret < 0) { return ret; } - /* Allocate an I/O buffer. This buffer is used by mod_symname() to + /* Allocate an I/O buffer. This buffer is used by libmod_symname() to * accumulate the variable length symbol name. */ - ret = mod_allocbuffer(loadinfo); + ret = libmod_allocbuffer(loadinfo); if (ret < 0) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -304,11 +304,11 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo, if (loadinfo->shdr[i].sh_type == SHT_REL) { - ret = mod_relocate(loadinfo, i, exports, nexports); + ret = libmod_relocate(loadinfo, i, exports, nexports); } else if (loadinfo->shdr[i].sh_type == SHT_RELA) { - ret = mod_relocateadd(loadinfo, i, exports, nexports); + ret = libmod_relocateadd(loadinfo, i, exports, nexports); } if (ret < 0) diff --git a/binfmt/libmodule/libmodule_ctors.c b/binfmt/libmodule/libmodule_ctors.c index e89d310fbe..ea79cac7ee 100644 --- a/binfmt/libmodule/libmodule_ctors.c +++ b/binfmt/libmodule/libmodule_ctors.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_loadctors + * Name: libmod_loadctors * * Description: * Load pointers to static constructors into an in-memory array. @@ -86,7 +86,7 @@ * ****************************************************************************/ -int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) +int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo) { FAR Elf32_Shdr *shdr; size_t ctorsize; @@ -97,13 +97,13 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) DEBUGASSERT(loadinfo->ctors == NULL); /* Allocate an I/O buffer if necessary. This buffer is used by - * mod_sectname() to accumulate the variable length symbol name. + * libmod_sectname() to accumulate the variable length symbol name. */ - ret = mod_allocbuffer(loadinfo); + ret = libmod_allocbuffer(loadinfo); if (ret < 0) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -114,14 +114,14 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) * in either case. */ - ctoridx = mod_findsection(loadinfo, ".ctors"); + ctoridx = libmod_findsection(loadinfo, ".ctors"); if (ctoridx < 0) { /* This may not be a failure. -ENOENT indicates that the file has no * static constructor section. */ - bvdbg("mod_findsection .ctors section failed: %d\n", ctoridx); + bvdbg("libmod_findsection .ctors section failed: %d\n", ctoridx); return ret == -ENOENT ? OK : ret; } @@ -174,7 +174,7 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, + ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, shdr->sh_offset); if (ret < 0) { diff --git a/binfmt/libmodule/libmodule_dtors.c b/binfmt/libmodule/libmodule_dtors.c index d94c341ed7..9102ceaac0 100644 --- a/binfmt/libmodule/libmodule_dtors.c +++ b/binfmt/libmodule/libmodule_dtors.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_loaddtors + * Name: libmod_loaddtors * * Description: * Load pointers to static destructors into an in-memory array. @@ -86,7 +86,7 @@ * ****************************************************************************/ -int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) +int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo) { FAR Elf32_Shdr *shdr; size_t dtorsize; @@ -97,13 +97,13 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) DEBUGASSERT(loadinfo->dtors == NULL); /* Allocate an I/O buffer if necessary. This buffer is used by - * mod_sectname() to accumulate the variable length symbol name. + * libmod_sectname() to accumulate the variable length symbol name. */ - ret = mod_allocbuffer(loadinfo); + ret = libmod_allocbuffer(loadinfo); if (ret < 0) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -114,14 +114,14 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) * in either case. */ - dtoridx = mod_findsection(loadinfo, ".dtors"); + dtoridx = libmod_findsection(loadinfo, ".dtors"); if (dtoridx < 0) { /* This may not be a failure. -ENOENT indicates that the file has no * static destructor section. */ - bvdbg("mod_findsection .dtors section failed: %d\n", dtoridx); + bvdbg("libmod_findsection .dtors section failed: %d\n", dtoridx); return ret == -ENOENT ? OK : ret; } @@ -174,7 +174,7 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, + ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, shdr->sh_offset); if (ret < 0) { diff --git a/binfmt/libmodule/libmodule_init.c b/binfmt/libmodule/libmodule_init.c index a1ba9b0859..c5f737e36f 100644 --- a/binfmt/libmodule/libmodule_init.c +++ b/binfmt/libmodule/libmodule_init.c @@ -65,9 +65,9 @@ #endif #ifdef CONFIG_ELF_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) #else -# define mod_dumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_filelen + * Name: libmod_filelen * * Description: * Get the size of the ELF file @@ -90,8 +90,8 @@ * ****************************************************************************/ -static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *filename) +static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *filename) { struct stat buf; int ret; @@ -129,7 +129,7 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_initialize + * Name: libmod_initialize * * Description: * This function is called to configure the library to process an ELF @@ -141,7 +141,8 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo) +int libmod_initialize(FAR const char *filename, + FAR struct libmod_loadinfo_s *loadinfo) { int ret; @@ -149,14 +150,14 @@ int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo /* Clear the load info structure */ - memset(loadinfo, 0, sizeof(struct mod_loadinfo_s)); + memset(loadinfo, 0, sizeof(struct libmod_loadinfo_s)); /* Get the length of the file. */ - ret = mod_filelen(loadinfo, filename); + ret = libmod_filelen(loadinfo, filename); if (ret < 0) { - bdbg("mod_filelen failed: %d\n", ret); + bdbg("libmod_filelen failed: %d\n", ret); return ret; } @@ -172,24 +173,26 @@ int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo /* Read the ELF ehdr from offset 0 */ - ret = mod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); + ret = libmod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, + sizeof(Elf32_Ehdr), 0); if (ret < 0) { bdbg("Failed to read ELF header: %d\n", ret); return ret; } - mod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); + libmod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, + sizeof(Elf32_Ehdr)); /* Verify the ELF header */ - ret = mod_verifyheader(&loadinfo->ehdr); + ret = libmod_verifyheader(&loadinfo->ehdr); if (ret < 0) { /* This may not be an error because we will be called to attempt loading - * EVERY binary. If mod_verifyheader() does not recognize the ELF header, + * EVERY binary. If libmod_verifyheader() does not recognize the ELF header, * it will -ENOEXEC whcih simply informs the system that the file is not an - * ELF file. mod_verifyheader() will return other errors if the ELF header + * ELF file. libmod_verifyheader() will return other errors if the ELF header * is not correctly formed. */ diff --git a/binfmt/libmodule/libmodule_iobuffer.c b/binfmt/libmodule/libmodule_iobuffer.c index 17f8da4c5c..296c8c2c94 100644 --- a/binfmt/libmodule/libmodule_iobuffer.c +++ b/binfmt/libmodule/libmodule_iobuffer.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/mod_iobuffer.c + * binfmt/libmodule/libmodule_iobuffer.c * * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_allocbuffer + * Name: libmod_allocbuffer * * Description: * Perform the initial allocation of the I/O buffer, if it has not already @@ -76,7 +76,7 @@ * ****************************************************************************/ -int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) +int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) { /* Has a buffer been allocated> */ @@ -98,7 +98,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_reallocbuffer + * Name: libmod_reallocbuffer * * Description: * Increase the size of I/O buffer by the specified buffer increment. @@ -109,7 +109,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) +int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment) { FAR void *buffer; size_t newsize; diff --git a/binfmt/libmodule/libmodule_load.c b/binfmt/libmodule/libmodule_load.c index af89d3ff63..6c55f853de 100644 --- a/binfmt/libmodule/libmodule_load.c +++ b/binfmt/libmodule/libmodule_load.c @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_elfsize + * Name: libmod_elfsize * * Description: * Calculate total memory allocation for the ELF file. @@ -90,7 +90,7 @@ * ****************************************************************************/ -static void mod_elfsize(struct mod_loadinfo_s *loadinfo) +static void libmod_elfsize(struct libmod_loadinfo_s *loadinfo) { size_t textsize; size_t datasize; @@ -133,7 +133,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_loadfile + * Name: libmod_loadfile * * Description: * Read the section data into memory. Section addresses in the shdr[] are @@ -145,7 +145,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) +static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) { FAR uint8_t *text; FAR uint8_t *data; @@ -192,7 +192,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) { /* Read the section data from sh_offset to the memory region */ - ret = mod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); + ret = libmod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); if (ret < 0) { bdbg("ERROR: Failed to read section %d: %d\n", i, ret); @@ -229,7 +229,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) ****************************************************************************/ /**************************************************************************** - * Name: mod_load + * Name: libmod_load * * Description: * Loads the binary into memory, allocating memory, performing relocations @@ -241,7 +241,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_load(FAR struct mod_loadinfo_s *loadinfo) +int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) { size_t heapsize; #ifdef CONFIG_UCLIBCXX_EXCEPTION @@ -254,16 +254,16 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load section headers into memory */ - ret = mod_loadshdrs(loadinfo); + ret = libmod_loadshdrs(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadshdrs failed: %d\n", ret); + bdbg("ERROR: libmod_loadshdrs failed: %d\n", ret); goto errout_with_buffers; } /* Determine total size to allocate */ - mod_elfsize(loadinfo); + libmod_elfsize(loadinfo); /* Determine the heapsize to allocate. */ @@ -285,36 +285,36 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load ELF section data into memory */ - ret = mod_loadfile(loadinfo); + ret = libmod_loadfile(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadfile failed: %d\n", ret); + bdbg("ERROR: libmod_loadfile failed: %d\n", ret); goto errout_with_buffers; } /* Load static constructors and destructors. */ #ifdef CONFIG_BINFMT_CONSTRUCTORS - ret = mod_loadctors(loadinfo); + ret = libmod_loadctors(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadctors failed: %d\n", ret); + bdbg("ERROR: libmod_loadctors failed: %d\n", ret); goto errout_with_buffers; } - ret = mod_loaddtors(loadinfo); + ret = libmod_loaddtors(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loaddtors failed: %d\n", ret); + bdbg("ERROR: libmod_loaddtors failed: %d\n", ret); goto errout_with_buffers; } #endif #ifdef CONFIG_UCLIBCXX_EXCEPTION - exidx = mod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); + exidx = libmod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); if (exidx < 0) { - bvdbg("mod_findsection: Exception Index section not found: %d\n", exidx); + bvdbg("libmod_findsection: Exception Index section not found: %d\n", exidx); } else { @@ -327,7 +327,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Error exits */ errout_with_buffers: - mod_unload(loadinfo); + libmod_unload(loadinfo); return ret; } diff --git a/binfmt/libmodule/libmodule_read.c b/binfmt/libmodule/libmodule_read.c index 60f3c37c03..effa0510e0 100644 --- a/binfmt/libmodule/libmodule_read.c +++ b/binfmt/libmodule/libmodule_read.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_dumpreaddata + * Name: libmod_dumpreaddata ****************************************************************************/ #if defined(ELF_DUMP_READDATA) -static inline void mod_dumpreaddata(FAR char *buffer, int buflen) +static inline void libmod_dumpreaddata(FAR char *buffer, int buflen) { FAR uint32_t *buf32 = (FAR uint32_t *)buffer; int i; @@ -86,7 +86,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) } } #else -# define mod_dumpreaddata(b,n) +# define libmod_dumpreaddata(b,n) #endif /**************************************************************************** @@ -94,7 +94,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) ****************************************************************************/ /**************************************************************************** - * Name: mod_read + * Name: libmod_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -106,8 +106,8 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) * ****************************************************************************/ -int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset) +int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset) { ssize_t nbytes; /* Number of bytes read */ off_t rpos; /* Position returned by lseek */ @@ -158,6 +158,6 @@ int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, } } - mod_dumpreaddata(buffer, readsize); + libmod_dumpreaddata(buffer, readsize); return OK; } diff --git a/binfmt/libmodule/libmodule_sections.c b/binfmt/libmodule/libmodule_sections.c index 183d014141..699b3e4f75 100644 --- a/binfmt/libmodule/libmodule_sections.c +++ b/binfmt/libmodule/libmodule_sections.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_sectname + * Name: libmod_sectname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -74,8 +74,8 @@ * ****************************************************************************/ -static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *shdr) +static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *shdr) { FAR Elf32_Shdr *shstr; FAR uint8_t *buffer; @@ -136,7 +136,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = libmod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { bdbg("Failed to read section name\n"); @@ -156,10 +156,10 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); if (ret < 0) { - bdbg("mod_reallocbuffer failed: %d\n", ret); + bdbg("libmod_reallocbuffer failed: %d\n", ret); return ret; } } @@ -174,7 +174,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_loadshdrs + * Name: libmod_loadshdrs * * Description: * Loads section headers into memory. @@ -185,7 +185,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) +int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) { size_t shdrsize; int ret; @@ -221,8 +221,8 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, - loadinfo->ehdr.e_shoff); + ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + loadinfo->ehdr.e_shoff); if (ret < 0) { bdbg("Failed to read section header table: %d\n", ret); @@ -232,7 +232,7 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_findsection + * Name: libmod_findsection * * Description: * A section by its name. @@ -247,8 +247,8 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *sectname) +int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *sectname) { FAR const Elf32_Shdr *shdr; int ret; @@ -261,10 +261,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, /* Get the name of this section */ shdr = &loadinfo->shdr[i]; - ret = mod_sectname(loadinfo, shdr); + ret = libmod_sectname(loadinfo, shdr); if (ret < 0) { - bdbg("mod_sectname failed: %d\n", ret); + bdbg("libmod_sectname failed: %d\n", ret); return ret; } diff --git a/binfmt/libmodule/libmodule_symbols.c b/binfmt/libmodule/libmodule_symbols.c index 9e9de001d7..6482e389e1 100644 --- a/binfmt/libmodule/libmodule_symbols.c +++ b/binfmt/libmodule/libmodule_symbols.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_symname + * Name: libmod_symname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -82,8 +82,8 @@ * ****************************************************************************/ -static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Sym *sym) +static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Sym *sym) { FAR uint8_t *buffer; off_t offset; @@ -126,10 +126,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = libmod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { - bdbg("mod_read failed: %d\n", ret); + bdbg("libmod_read failed: %d\n", ret); return ret; } @@ -146,10 +146,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); if (ret < 0) { - bdbg("mod_reallocbuffer failed: %d\n", ret); + bdbg("libmod_reallocbuffer failed: %d\n", ret); return ret; } } @@ -164,7 +164,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_findsymtab + * Name: libmod_findsymtab * * Description: * Find the symbol table section. @@ -175,7 +175,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) +int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo) { int i; @@ -203,7 +203,7 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_readsym + * Name: libmod_readsym * * Description: * Read the ELFT symbol structure at the specfied index into memory. @@ -219,8 +219,8 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym) +int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym) { FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; off_t offset; @@ -239,11 +239,11 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, /* And, finally, read the symbol table entry into memory */ - return mod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); + return libmod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); } /**************************************************************************** - * Name: mod_symvalue + * Name: libmod_symvalue * * Description: * Get the value of a symbol. The updated value of the symbol is returned @@ -265,8 +265,8 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports) +int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports) { FAR const struct symtab_s *symbol; uintptr_t secbase; @@ -294,7 +294,7 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, { /* Get the name of the undefined symbol */ - ret = mod_symname(loadinfo, sym); + ret = libmod_symname(loadinfo, sym); if (ret < 0) { /* There are a few relocations for a few architectures that do diff --git a/binfmt/libmodule/libmodule_uninit.c b/binfmt/libmodule/libmodule_uninit.c index 9ca3684ce3..13932bcc54 100644 --- a/binfmt/libmodule/libmodule_uninit.c +++ b/binfmt/libmodule/libmodule_uninit.c @@ -65,11 +65,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_uninit + * Name: libmod_uninitialize * * Description: - * Releases any resources committed by mod_initialize(). This essentially - * undoes the actions of mod_initialize. + * Releases any resources committed by libmod_initialize(). This essentially + * undoes the actions of libmod_initialize. * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -77,11 +77,11 @@ * ****************************************************************************/ -int mod_uninit(struct mod_loadinfo_s *loadinfo) +int libmod_uninitialize(struct libmod_loadinfo_s *loadinfo) { /* Free all working buffers */ - mod_freebuffers(loadinfo); + libmod_freebuffers(loadinfo); /* Close the ELF file */ @@ -94,7 +94,7 @@ int mod_uninit(struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_freebuffers + * Name: libmod_freebuffers * * Description: * Release all working buffers. @@ -105,7 +105,7 @@ int mod_uninit(struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_freebuffers(struct mod_loadinfo_s *loadinfo) +int libmod_freebuffers(struct libmod_loadinfo_s *loadinfo) { /* Release all working allocations */ diff --git a/binfmt/libmodule/libmodule_unload.c b/binfmt/libmodule/libmodule_unload.c index c424a8686b..73822b59c6 100644 --- a/binfmt/libmodule/libmodule_unload.c +++ b/binfmt/libmodule/libmodule_unload.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_unload + * Name: libmod_unload * * Description: * This function unloads the object from memory. This essentially undoes - * the actions of mod_load. It is called only under certain error + * the actions of libmod_load. It is called only under certain error * conditions after the module has been loaded but not yet started. * * Returned Value: @@ -77,11 +77,11 @@ * ****************************************************************************/ -int mod_unload(struct mod_loadinfo_s *loadinfo) +int libmod_unload(struct libmod_loadinfo_s *loadinfo) { /* Free all working buffers */ - mod_freebuffers(loadinfo); + libmod_freebuffers(loadinfo); /* Release memory holding the relocated ELF image */ diff --git a/binfmt/libmodule/libmodule_verify.c b/binfmt/libmodule/libmodule_verify.c index 9d207180b3..82ab35ae4d 100644 --- a/binfmt/libmodule/libmodule_verify.c +++ b/binfmt/libmodule/libmodule_verify.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/mod_verify.c + * binfmt/libmodule/libmodule_verify.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -67,7 +67,7 @@ static const char g_modmagic[EI_MAGIC_SIZE] = ****************************************************************************/ /**************************************************************************** - * Name: mod_verifyheader + * Name: libmod_verifyheader * * Description: * Given the header from a possible ELF executable, verify that it @@ -83,7 +83,7 @@ static const char g_modmagic[EI_MAGIC_SIZE] = * ****************************************************************************/ -int mod_verifyheader(FAR const Elf32_Ehdr *ehdr) +int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) { if (!ehdr) { diff --git a/binfmt/module.c b/binfmt/module.c index 79f63df7c7..4f727d4f6f 100644 --- a/binfmt/module.c +++ b/binfmt/module.c @@ -182,34 +182,8 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) static void mod_dumpentrypt(FAR struct binary_s *binp, FAR struct mod_loadinfo_s *loadinfo) { -#ifdef CONFIG_ARCH_ADDRENV - int ret; - - /* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address - * space that may not be in place now. mod_addrenv_select() will - * temporarily instantiate that address space. - */ - - ret = mod_addrenv_select(loadinfo); - if (ret < 0) - { - bdbg("ERROR: mod_addrenv_select() failed: %d\n", ret); - return; - } -#endif - mod_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); - -#ifdef CONFIG_ARCH_ADDRENV - /* Restore the original address environment */ - - ret = mod_addrenv_restore(loadinfo); - if (ret < 0) - { - bdbg("ERROR: mod_addrenv_restore() failed: %d\n", ret); - } -#endif } #else # define mod_dumpentrypt(b,l) @@ -233,7 +207,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Initialize the ELF library to load the program binary. */ - ret = mod_init(binp->filename, &loadinfo); + ret = libmod_initialize(binp->filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -243,7 +217,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Load the program binary */ - ret = mod_load(&loadinfo); + ret = libmod_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -253,7 +227,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Bind the program to the exported symbol table */ - ret = mod_bind(&loadinfo, binp->exports, binp->nexports); + ret = libmod_bind(&loadinfo, binp->exports, binp->nexports); if (ret != 0) { bdbg("Failed to bind symbols program binary: %d\n", ret); @@ -273,11 +247,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) * a memory leak? */ -#ifdef CONFIG_ARCH_ADDRENV -# warning "REVISIT" -#else binp->alloc[0] = (FAR void *)loadinfo.textalloc; -#endif #ifdef CONFIG_BINFMT_CONSTRUCTORS /* Save information about constructors. NOTE: destructors are not @@ -293,22 +263,14 @@ static int mod_loadbinary(FAR struct binary_s *binp) binp->ndtors = loadinfo.ndtors; #endif -#ifdef CONFIG_ARCH_ADDRENV - /* Save the address environment in the binfmt structure. This will be - * needed when the module is executed. - */ - - up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv); -#endif - mod_dumpentrypt(binp, &loadinfo); - mod_uninit(&loadinfo); + libmod_uninitialize(&loadinfo); return OK; errout_with_load: - mod_unload(&loadinfo); + libmod_unload(&loadinfo); errout_with_init: - mod_uninit(&loadinfo); + libmod_uninitialize(&loadinfo); errout: return ret; } diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h index 982fc4462d..ba5c31325a 100644 --- a/include/nuttx/binfmt/elf.h +++ b/include/nuttx/binfmt/elf.h @@ -336,6 +336,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel, * Always returns Zero (OK). * ****************************************************************************/ + int up_init_exidx(Elf32_Addr address, Elf32_Word size); #endif diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/binfmt/module.h index 811921f14f..acf26df0dd 100644 --- a/include/nuttx/binfmt/module.h +++ b/include/nuttx/binfmt/module.h @@ -161,7 +161,7 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: mod_init + * Name: libmod_initialize * * Description: * This function is called to configure the library to process an kernel @@ -173,10 +173,11 @@ extern "C" * ****************************************************************************/ -int mod_init(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo); +int libmod_initalize(FAR const char *filename, + FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_uninit + * Name: libmod_uninitialize * * Description: * Releases any resources committed by mod_init(). This essentially @@ -188,7 +189,7 @@ int mod_init(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_uninit(FAR struct mod_loadinfo_s *loadinfo); +int libmod_uninitialize(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** * Name: mod_load @@ -336,6 +337,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel, * Always returns Zero (OK). * ****************************************************************************/ + int up_init_exidx(Elf32_Addr address, Elf32_Word size); #endif -- GitLab From 05cb7a9043a2f32b352addc4ae47a138f8211628 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Dec 2015 07:27:45 -0600 Subject: [PATCH 438/858] Call initializer entry point on start-up; do not create a task --- binfmt/libelf/libelf.h | 6 +----- binfmt/libmodule/Kconfig | 7 ------- binfmt/libmodule/gnu-elf.ld | 2 +- binfmt/libmodule/libmodule.h | 4 ++++ binfmt/module.c | 37 +++++++++++++++++++++++----------- include/nuttx/binfmt/module.h | 38 ++++++++++++++++++----------------- 6 files changed, 51 insertions(+), 43 deletions(-) diff --git a/binfmt/libelf/libelf.h b/binfmt/libelf/libelf.h index 58ec757b8d..a61f38017a 100644 --- a/binfmt/libelf/libelf.h +++ b/binfmt/libelf/libelf.h @@ -49,11 +49,7 @@ #include /**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** diff --git a/binfmt/libmodule/Kconfig b/binfmt/libmodule/Kconfig index feb42b68e5..dd91584ec8 100644 --- a/binfmt/libmodule/Kconfig +++ b/binfmt/libmodule/Kconfig @@ -9,13 +9,6 @@ config MODULE_ALIGN_LOG2 ---help--- Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc. -config MODULE_STACKSIZE - int "Module Stack Size" - default 2048 - ---help--- - This is the default stack size that will be used when starting - module initialization tasks. - config MODULE_BUFFERSIZE int "Module I/O Buffer Size" default 128 diff --git a/binfmt/libmodule/gnu-elf.ld b/binfmt/libmodule/gnu-elf.ld index 8b79f8d45a..a471c4f097 100644 --- a/binfmt/libmodule/gnu-elf.ld +++ b/binfmt/libmodule/gnu-elf.ld @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/libmodule/gnu-elf.ld * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/binfmt/libmodule/libmodule.h b/binfmt/libmodule/libmodule.h index fb003a7ac9..7636f2ff07 100644 --- a/binfmt/libmodule/libmodule.h +++ b/binfmt/libmodule/libmodule.h @@ -56,6 +56,10 @@ * Public Types ****************************************************************************/ +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + /**************************************************************************** * Name: libmod_verifyheader * diff --git a/binfmt/module.c b/binfmt/module.c index 4f727d4f6f..cbc4941fc5 100644 --- a/binfmt/module.c +++ b/binfmt/module.c @@ -68,10 +68,6 @@ # undef CONFIG_MODULE_DUMPBUFFER #endif -#ifndef CONFIG_MODULE_STACKSIZE -# define CONFIG_MODULE_STACKSIZE 2048 -#endif - #ifdef CONFIG_MODULE_DUMPBUFFER # define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) #else @@ -175,18 +171,18 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) #endif /**************************************************************************** - * Name: mod_dumpentrypt + * Name: mod_dumpinitializer ****************************************************************************/ #ifdef CONFIG_MODULE_DUMPBUFFER -static void mod_dumpentrypt(FAR struct binary_s *binp, - FAR struct mod_loadinfo_s *loadinfo) +static void mod_dumpinitializer(mod_initializer_t initializer, + FAR struct mod_loadinfo_s *loadinfo) { - mod_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, + mod_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer, MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); } #else -# define mod_dumpentrypt(b,l) +# define mod_dumpinitializer(b,l) #endif /**************************************************************************** @@ -201,6 +197,7 @@ static void mod_dumpentrypt(FAR struct binary_s *binp, static int mod_loadbinary(FAR struct binary_s *binp) { struct mod_loadinfo_s loadinfo; /* Contains globals for libmodule */ + mod_initializer_t initializer; int ret; bvdbg("Loading file: %s\n", binp->filename); @@ -236,8 +233,8 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Return the load information */ - binp->entrypt = (main_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); - binp->stacksize = CONFIG_MODULE_STACKSIZE; + binp->entrypt = NULL; + binp->stacksize = 0; /* Add the ELF allocation to the alloc[] only if there is no address * environment. If there is an address environment, it will automatically @@ -263,7 +260,23 @@ static int mod_loadbinary(FAR struct binary_s *binp) binp->ndtors = loadinfo.ndtors; #endif - mod_dumpentrypt(binp, &loadinfo); + /* Get the module initializer entry point */ + + initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); + if (initialize) + { + mod_dumpinitializer(initializer, &loadinfo); + + /* Call the module initializer */ + + ret = initializer(); + if (ret < 0) + { + bdbg("Failed to initialize the module: %d\n", ret); + goto errout_with_load; + } + } + libmod_uninitialize(&loadinfo); return OK; diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/binfmt/module.h index acf26df0dd..11931f20f2 100644 --- a/include/nuttx/binfmt/module.h +++ b/include/nuttx/binfmt/module.h @@ -95,11 +95,6 @@ struct mod_loadinfo_s /* elfalloc is the base address of the memory that is allocated to hold the * module image. * - * If CONFIG_ARCH_ADDRENV=n, elfalloc will be allocated using kmm_malloc() (or - * kmm_zalloc()). If CONFIG_ARCH_ADDRENV-y, then elfalloc will be allocated using - * up_addrenv_create(). In either case, there will be a unique instance - * of elfalloc (and stack) for each instance of a process. - * * The alloc[] array in struct binary_s will hold memory that persists after * the module has been loaded. */ @@ -124,25 +119,32 @@ struct mod_loadinfo_s uint16_t ndtors; /* Number of destructors */ #endif - /* Address environment. - * - * addrenv - This is the handle created by up_addrenv_create() that can be - * used to manage the tasks address space. - * oldenv - This is a value returned by up_addrenv_select() that must be - * used to restore the current address environment. - */ - -#ifdef CONFIG_ARCH_ADDRENV - group_addrenv_t addrenv; /* Task group address environment */ - save_addrenv_t oldenv; /* Saved address environment */ -#endif - uint16_t symtabidx; /* Symbol table section index */ uint16_t strtabidx; /* String table section index */ uint16_t buflen; /* size of iobuffer[] */ int filfd; /* Descriptor for the file being loaded */ }; +/* A NuttX module is expected to export a function called module_initialize() + * that has the following function prototype. This function should appear as + * the entry point in the ELF module file and will be called bythe binfmt + * logic after the module has been loaded into kernel memory. + * + * As an alternative using GCC, the module may mark a function with the + * "constructor" attribute and the module initializer will be called along + * with any other C++ constructors. The "destructor" attribute may also + * be used to mark an module uninitialization function. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) on success; a negated errno value on any failure to + * initialize the module. + */ + +typedef CODE int (*mod_initializer_t)(void); + /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From f45e2a247e74e6cb7e66c573772203bec7aba583 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Dec 2015 10:06:40 -0600 Subject: [PATCH 439/858] Cosmetic fix to comment --- arch | 2 +- sched/signal/sig_dispatch.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch b/arch index c8448d662d..ca979759a7 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c8448d662d63fecbbd8c603ab54cfbe2de200fe1 +Subproject commit ca979759a701c3c5e7acb8fc8c604ee112c45601 diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 9027fddddb..b6027c9b7e 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -165,7 +165,8 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) } /* If we were not called from an interrupt handler, then we are - * free to allocate pending action structures if necessary. */ + * free to allocate pending action structures if necessary. + */ else { -- GitLab From 44e45f0f91fd13cc13409e00fe44275ce9de3251 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Dec 2015 10:55:21 -0600 Subject: [PATCH 440/858] insmod is code complete and ready for test --- arch | 2 +- binfmt/Kconfig | 10 ++ binfmt/Makefile | 1 + binfmt/{module.c => insmod.c} | 143 +++-------------- binfmt/libmodule/Kconfig | 10 -- binfmt/libmodule/Make.defs | 12 +- binfmt/libmodule/gnu-elf.ld | 32 ---- binfmt/libmodule/libmodule.h | 153 +++++++++++++----- binfmt/libmodule/libmodule_bind.c | 10 +- binfmt/libmodule/libmodule_ctors.c | 216 -------------------------- binfmt/libmodule/libmodule_dtors.c | 216 -------------------------- binfmt/libmodule/libmodule_init.c | 6 +- binfmt/libmodule/libmodule_iobuffer.c | 4 +- binfmt/libmodule/libmodule_load.c | 47 +----- binfmt/libmodule/libmodule_read.c | 2 + binfmt/libmodule/libmodule_sections.c | 2 +- binfmt/libmodule/libmodule_symbols.c | 6 +- binfmt/libmodule/libmodule_unload.c | 24 +-- include/nuttx/binfmt/module.h | 200 ++++-------------------- 19 files changed, 200 insertions(+), 896 deletions(-) rename binfmt/{module.c => insmod.c} (66%) delete mode 100644 binfmt/libmodule/libmodule_ctors.c delete mode 100644 binfmt/libmodule/libmodule_dtors.c diff --git a/arch b/arch index c8448d662d..ca979759a7 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c8448d662d63fecbbd8c603ab54cfbe2de200fe1 +Subproject commit ca979759a701c3c5e7acb8fc8c604ee112c45601 diff --git a/binfmt/Kconfig b/binfmt/Kconfig index fc2b457f89..b9263becae 100644 --- a/binfmt/Kconfig +++ b/binfmt/Kconfig @@ -12,6 +12,16 @@ config BINFMT_DISABLE if !BINFMT_DISABLE +config MODULE + bool "Enable loadable OS modules" + default n + ---help--- + Enable support for loadable OS modules. Default: n + +if MODULE +source binfmt/libmodule/Kconfig +endif + config BINFMT_EXEPATH bool "Support PATH variable" default n diff --git a/binfmt/Makefile b/binfmt/Makefile index 9da55ea973..ef329e6c38 100644 --- a/binfmt/Makefile +++ b/binfmt/Makefile @@ -71,6 +71,7 @@ VPATH = SUBDIRS = DEPPATH = --dep-path . +include libmodule$(DELIM)Make.defs include libnxflat$(DELIM)Make.defs include libelf$(DELIM)Make.defs include libbuiltin$(DELIM)Make.defs diff --git a/binfmt/module.c b/binfmt/insmod.c similarity index 66% rename from binfmt/module.c rename to binfmt/insmod.c index cbc4941fc5..b2f5094d72 100644 --- a/binfmt/module.c +++ b/binfmt/insmod.c @@ -49,7 +49,6 @@ #include #include -#include #include #include "libmodule/libmodule.h" @@ -78,26 +77,6 @@ # define MIN(a,b) (a < b ? a : b) #endif -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int mod_loadbinary(FAR struct binary_s *binp); -#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) -static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo); -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct binfmt_s g_modbinfmt = -{ - NULL, /* next */ - mod_loadbinary, /* load */ - NULL, /* unload */ -}; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -107,24 +86,16 @@ static struct binfmt_s g_modbinfmt = ****************************************************************************/ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) -static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) +static void mod_dumploadinfo(FAR struct libmod_loadinfo_s *loadinfo) { int i; bdbg("LOAD_INFO:\n"); bdbg(" textalloc: %08lx\n", (long)loadinfo->textalloc); - bdbg(" dataalloc: %08lx\n", (long)loadinfo->dataalloc); + bdbg(" datastart: %08lx\n", (long)loadinfo->datastart); bdbg(" textsize: %ld\n", (long)loadinfo->textsize); bdbg(" datasize: %ld\n", (long)loadinfo->datasize); bdbg(" filelen: %ld\n", (long)loadinfo->filelen); -#ifdef CONFIG_BINFMT_CONSTRUCTORS - bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc); - bdbg(" ctors: %08lx\n", (long)loadinfo->ctors); - bdbg(" nctors: %d\n", loadinfo->nctors); - bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc); - bdbg(" dtors: %08lx\n", (long)loadinfo->dtors); - bdbg(" ndtors: %d\n", loadinfo->ndtors); -#endif bdbg(" filfd: %d\n", loadinfo->filfd); bdbg(" symtabidx: %d\n", loadinfo->symtabidx); bdbg(" strtabidx: %d\n", loadinfo->strtabidx); @@ -186,25 +157,28 @@ static void mod_dumpinitializer(mod_initializer_t initializer, #endif /**************************************************************************** - * Name: mod_loadbinary + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: insmod * * Description: - * Verify that the file is an ELF binary and, if so, load the ELF - * binary into memory + * Verify that the file is an ELF module binary and, if so, load the + * module into kernel memory and initialize it for use. * ****************************************************************************/ -static int mod_loadbinary(FAR struct binary_s *binp) +int insmod(FAR struct module_s *modp) { - struct mod_loadinfo_s loadinfo; /* Contains globals for libmodule */ - mod_initializer_t initializer; - int ret; + struct libmod_loadinfo_s loadinfo; /* Contains globals for libmodule */ + int ret; - bvdbg("Loading file: %s\n", binp->filename); + bvdbg("Loading file: %s\n", modp->filename); /* Initialize the ELF library to load the program binary. */ - ret = libmod_initialize(binp->filename, &loadinfo); + ret = libmod_initialize(modp->filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -224,7 +198,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Bind the program to the exported symbol table */ - ret = libmod_bind(&loadinfo, binp->exports, binp->nexports); + ret = libmod_bind(&loadinfo, modp->exports, modp->nexports); if (ret != 0) { bdbg("Failed to bind symbols program binary: %d\n", ret); @@ -233,43 +207,18 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Return the load information */ - binp->entrypt = NULL; - binp->stacksize = 0; - - /* Add the ELF allocation to the alloc[] only if there is no address - * environment. If there is an address environment, it will automatically - * be freed when the function exits - * - * REVISIT: If the module is loaded then unloaded, wouldn't this cause - * a memory leak? - */ - - binp->alloc[0] = (FAR void *)loadinfo.textalloc; - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - /* Save information about constructors. NOTE: destructors are not - * yet supported. - */ - - binp->alloc[1] = loadinfo.ctoralloc; - binp->ctors = loadinfo.ctors; - binp->nctors = loadinfo.nctors; - - binp->alloc[2] = loadinfo.dtoralloc; - binp->dtors = loadinfo.dtors; - binp->ndtors = loadinfo.ndtors; -#endif + modp->initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); + modp->alloc = (FAR void *)loadinfo.textalloc; /* Get the module initializer entry point */ - initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); - if (initialize) + if (modp->initializer) { - mod_dumpinitializer(initializer, &loadinfo); + mod_dumpinitializer(modp->initializer, &loadinfo); /* Call the module initializer */ - ret = initializer(); + ret = modp->initializer(); if (ret < 0) { bdbg("Failed to initialize the module: %d\n", ret); @@ -288,56 +237,4 @@ errout: return ret; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mod_initialize - * - * Description: - * ELF support is built unconditionally. However, in order to - * use this binary format, this function must be called during system - * initialization in order to register the ELF binary format. - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_initialize(void) -{ - int ret; - - /* Register ourselves as a binfmt loader */ - - bvdbg("Registering ELF\n"); - - ret = register_binfmt(&g_modbinfmt); - if (ret != 0) - { - bdbg("Failed to register binfmt: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: mod_uninitialize - * - * Description: - * Unregister the ELF binary loader - * - * Returned Value: - * None - * - ****************************************************************************/ - -void mod_uninitialize(void) -{ - unregister_binfmt(&g_modbinfmt); -} - #endif /* CONFIG_MODULE */ diff --git a/binfmt/libmodule/Kconfig b/binfmt/libmodule/Kconfig index dd91584ec8..0e8ab2efa3 100644 --- a/binfmt/libmodule/Kconfig +++ b/binfmt/libmodule/Kconfig @@ -33,13 +33,3 @@ config MODULE_DUMPBUFFER depends on DEBUG && DEBUG_VERBOSE ---help--- Dump various module buffers for debug purposes - -config MODULE_EXIDX_SECTNAME - string "Module Section Name for Exception Index" - default ".ARM.exidx" - depends on UCLIBCXX_EXCEPTION - ---help--- - Set the name string for the exception index section on the modules to - be loaded by the module binary loader. - - This is needed to support exception handling on loadable modules. diff --git a/binfmt/libmodule/Make.defs b/binfmt/libmodule/Make.defs index e610aec6a3..2de76e6eef 100644 --- a/binfmt/libmodule/Make.defs +++ b/binfmt/libmodule/Make.defs @@ -33,23 +33,19 @@ # ############################################################################ -ifeq ($(CONFIG_ELF),y) +ifeq ($(CONFIG_MODULE),y) -# ELF application interfaces +# OS module interfaces -BINFMT_CSRCS += module.c +BINFMT_CSRCS += insmod.c -# ELF library +# loadable module library BINFMT_CSRCS += libmodule_bind.c libmodule_init.c libmodule_iobuffer.c BINFMT_CSRCS += libmodule_load.c libmodule_read.c libmodule_sections.c BINFMT_CSRCS += libmodule_symbols.c libmodule_uninit.c libmodule_unload.c BINFMT_CSRCS += libmodule_verify.c -ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y) -BINFMT_CSRCS += libmodule_ctors.c libmodule_dtors.c -endif - # Hook the libmodule subdirectory into the build VPATH += libmodule diff --git a/binfmt/libmodule/gnu-elf.ld b/binfmt/libmodule/gnu-elf.ld index a471c4f097..9addca41fb 100644 --- a/binfmt/libmodule/gnu-elf.ld +++ b/binfmt/libmodule/gnu-elf.ld @@ -45,14 +45,6 @@ SECTIONS *(.glue_7) *(.glue_7t) *(.jcr) - - /* C++ support: The .init and .fini sections contain specific logic - * to manage static constructors and destructors. - */ - - *(.gnu.linkonce.t.*) - *(.init) /* Old ABI */ - *(.fini) /* Old ABI */ _etext = . ; } @@ -76,30 +68,6 @@ SECTIONS _edata = . ; } - /* C++ support. For each global and static local C++ object, - * GCC creates a small subroutine to construct the object. Pointers - * to these routines (not the routines themselves) are stored as - * simple, linear arrays in the .ctors section of the object file. - * Similarly, pointers to global/static destructor routines are - * stored in .dtors. - */ - - .ctors : - { - _sctors = . ; - *(.ctors) /* Old ABI: Unallocated */ - *(.init_array) /* New ABI: Allocated */ - _ectors = . ; - } - - .dtors : - { - _sdtors = . ; - *(.dtors) /* Old ABI: Unallocated */ - *(.fini_array) /* New ABI: Allocated */ - _edtors = . ; - } - .bss : { _sbss = . ; diff --git a/binfmt/libmodule/libmodule.h b/binfmt/libmodule/libmodule.h index 7636f2ff07..427e5b13aa 100644 --- a/binfmt/libmodule/libmodule.h +++ b/binfmt/libmodule/libmodule.h @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/libmodule/libmodule.h * - * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,17 +49,124 @@ #include /**************************************************************************** - * Pre-processor Definitions + * Public Types ****************************************************************************/ +/* This struct provides a description of the currently loaded instantiation + * of the kernel module. + */ + +struct libmod_loadinfo_s +{ + /* elfalloc is the base address of the memory that is allocated to hold the + * module image. + * + * The alloc[] array in struct module_s will hold memory that persists after + * the module has been loaded. + */ + + uintptr_t textalloc; /* .text memory allocated when module was loaded */ + uintptr_t datastart; /* Start of.bss/.data memory in .text allocation */ + size_t textsize; /* Size of the module .text memory allocation */ + size_t datasize; /* Size of the module .bss/.data memory allocation */ + off_t filelen; /* Length of the entire module file */ + Elf32_Ehdr ehdr; /* Buffered module file header */ + FAR Elf32_Shdr *shdr; /* Buffered module section headers */ + uint8_t *iobuffer; /* File I/O buffer */ + + uint16_t symtabidx; /* Symbol table section index */ + uint16_t strtabidx; /* String table section index */ + uint16_t buflen; /* size of iobuffer[] */ + int filfd; /* Descriptor for the file being loaded */ +}; + /**************************************************************************** - * Public Types + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Public Function Prototypes + * These are APIs exported by libmodule and used by insmod + ****************************************************************************/ + +/**************************************************************************** + * Name: libmod_initialize + * + * Description: + * This function is called to configure the library to process an kernel + * module. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int libmod_initialize(FAR const char *filename, + FAR struct libmod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: libmod_uninitialize + * + * Description: + * Releases any resources committed by mod_init(). This essentially + * undoes the actions of libmod_initialize. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int libmod_uninitialize(FAR struct libmod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: libmod_load + * + * Description: + * Loads the binary into memory, allocating memory, performing relocations + * and initializing the data and bss segments. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int libmod_load(FAR struct libmod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: libmod_bind + * + * Description: + * Bind the imported symbol names in the loaded module described by + * 'loadinfo' using the exported symbol values provided by 'symtab'. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +struct symtab_s; +int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: libmod_unload + * + * Description: + * This function unloads the object from memory. This essentially undoes + * the actions of mod_load. It is called only under certain error + * conditions after the module has been loaded but not yet started. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * ****************************************************************************/ +int libmod_unload(struct libmod_loadinfo_s *loadinfo); + /**************************************************************************** * Name: libmod_verifyheader * @@ -229,42 +336,4 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo); int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment); -/**************************************************************************** - * Name: libmod_findctors - * - * Description: - * Find C++ static constructors. - * - * Input Parameters: - * loadinfo - Load state information - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -#ifdef CONFIG_BINFMT_CONSTRUCTORS -int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo); -#endif - -/**************************************************************************** - * Name: libmod_loaddtors - * - * Description: - * Load pointers to static destructors into an in-memory array. - * - * Input Parameters: - * loadinfo - Load state information - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -#ifdef CONFIG_BINFMT_CONSTRUCTORS -int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo); -#endif - #endif /* __BINFMT_LIBELF_LIBELF_H */ diff --git a/binfmt/libmodule/libmodule_bind.c b/binfmt/libmodule/libmodule_bind.c index 199be22faa..0f6a09e409 100644 --- a/binfmt/libmodule/libmodule_bind.c +++ b/binfmt/libmodule/libmodule_bind.c @@ -56,18 +56,18 @@ ****************************************************************************/ /* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be - * defined or CONFIG_ELF_DUMPBUFFER does nothing. + * defined or CONFIG_MODULE_DUMPBUFFER does nothing. */ #if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) -# undef CONFIG_ELF_DUMPBUFFER +# undef CONFIG_MODULE_DUMPBUFFER #endif -#ifndef CONFIG_ELF_BUFFERSIZE -# define CONFIG_ELF_BUFFERSIZE 128 +#ifndef CONFIG_MODULE_BUFFERSIZE +# define CONFIG_MODULE_BUFFERSIZE 128 #endif -#ifdef CONFIG_ELF_DUMPBUFFER +#ifdef CONFIG_MODULE_DUMPBUFFER # define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) #else # define libmod_dumpbuffer(m,b,n) diff --git a/binfmt/libmodule/libmodule_ctors.c b/binfmt/libmodule/libmodule_ctors.c deleted file mode 100644 index ea79cac7ee..0000000000 --- a/binfmt/libmodule/libmodule_ctors.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** - * binfmt/libmodule/libmodule_ctors.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "libmodule.h" - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: libmod_loadctors - * - * Description: - * Load pointers to static constructors into an in-memory array. - * - * Input Parameters: - * loadinfo - Load state information - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo) -{ - FAR Elf32_Shdr *shdr; - size_t ctorsize; - int ctoridx; - int ret; - int i; - - DEBUGASSERT(loadinfo->ctors == NULL); - - /* Allocate an I/O buffer if necessary. This buffer is used by - * libmod_sectname() to accumulate the variable length symbol name. - */ - - ret = libmod_allocbuffer(loadinfo); - if (ret < 0) - { - bdbg("libmod_allocbuffer failed: %d\n", ret); - return -ENOMEM; - } - - /* Find the index to the section named ".ctors." NOTE: On old ABI system, - * .ctors is the name of the section containing the list of constructors; - * On newer systems, the similar section is called .init_array. It is - * expected that the linker script will force the section name to be ".ctors" - * in either case. - */ - - ctoridx = libmod_findsection(loadinfo, ".ctors"); - if (ctoridx < 0) - { - /* This may not be a failure. -ENOENT indicates that the file has no - * static constructor section. - */ - - bvdbg("libmod_findsection .ctors section failed: %d\n", ctoridx); - return ret == -ENOENT ? OK : ret; - } - - /* Now we can get a pointer to the .ctor section in the section header - * table. - */ - - shdr = &loadinfo->shdr[ctoridx]; - - /* Get the size of the .ctor section and the number of constructors that - * will need to be called. - */ - - ctorsize = shdr->sh_size; - loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t); - - bvdbg("ctoridx=%d ctorsize=%d sizeof(binfmt_ctor_t)=%d nctors=%d\n", - ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors); - - /* Check if there are any constructors. It is not an error if there - * are none. - */ - - if (loadinfo->nctors > 0) - { - /* Check an assumption that we made above */ - - DEBUGASSERT(shdr->sh_size == loadinfo->nctors * sizeof(binfmt_ctor_t)); - - /* In the old ABI, the .ctors section is not allocated. In that case, - * we need to allocate memory to hold the .ctors and then copy the - * from the file into the allocated memory. - * - * SHF_ALLOC indicates that the section requires memory during - * execution. - */ - - if ((shdr->sh_flags & SHF_ALLOC) == 0) - { - /* Allocate memory to hold a copy of the .ctor section */ - - loadinfo->ctoralloc = (binfmt_ctor_t *)kmm_malloc(ctorsize); - if (!loadinfo->ctoralloc) - { - bdbg("Failed to allocate memory for .ctors\n"); - return -ENOMEM; - } - - loadinfo->ctors = (binfmt_ctor_t *)loadinfo->ctoralloc; - - /* Read the section header table into memory */ - - ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, - shdr->sh_offset); - if (ret < 0) - { - bdbg("Failed to allocate .ctors: %d\n", ret); - return ret; - } - - /* Fix up all of the .ctor addresses. Since the addresses - * do not lie in allocated memory, there will be no relocation - * section for them. - */ - - for (i = 0; i < loadinfo->nctors; i++) - { - FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->ctors)[i]); - - bvdbg("ctor %d: %08lx + %08lx = %08lx\n", - i, *ptr, (unsigned long)loadinfo->textalloc, - (unsigned long)(*ptr + loadinfo->textalloc)); - - *ptr += loadinfo->textalloc; - } - } - else - { - - /* Save the address of the .ctors (actually, .init_array) where it was - * loaded into memory. Since the .ctors lie in allocated memory, they - * will be relocated via the normal mechanism. - */ - - loadinfo->ctors = (binfmt_ctor_t *)shdr->sh_addr; - } - } - - return OK; -} - -#endif /* CONFIG_BINFMT_CONSTRUCTORS */ diff --git a/binfmt/libmodule/libmodule_dtors.c b/binfmt/libmodule/libmodule_dtors.c deleted file mode 100644 index 9102ceaac0..0000000000 --- a/binfmt/libmodule/libmodule_dtors.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** - * binfmt/libmodule/libmodule_dtors.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "libmodule.h" - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: libmod_loaddtors - * - * Description: - * Load pointers to static destructors into an in-memory array. - * - * Input Parameters: - * loadinfo - Load state information - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo) -{ - FAR Elf32_Shdr *shdr; - size_t dtorsize; - int dtoridx; - int ret; - int i; - - DEBUGASSERT(loadinfo->dtors == NULL); - - /* Allocate an I/O buffer if necessary. This buffer is used by - * libmod_sectname() to accumulate the variable length symbol name. - */ - - ret = libmod_allocbuffer(loadinfo); - if (ret < 0) - { - bdbg("libmod_allocbuffer failed: %d\n", ret); - return -ENOMEM; - } - - /* Find the index to the section named ".dtors." NOTE: On old ABI system, - * .dtors is the name of the section containing the list of destructors; - * On newer systems, the similar section is called .fini_array. It is - * expected that the linker script will force the section name to be ".dtors" - * in either case. - */ - - dtoridx = libmod_findsection(loadinfo, ".dtors"); - if (dtoridx < 0) - { - /* This may not be a failure. -ENOENT indicates that the file has no - * static destructor section. - */ - - bvdbg("libmod_findsection .dtors section failed: %d\n", dtoridx); - return ret == -ENOENT ? OK : ret; - } - - /* Now we can get a pointer to the .dtor section in the section header - * table. - */ - - shdr = &loadinfo->shdr[dtoridx]; - - /* Get the size of the .dtor section and the number of destructors that - * will need to be called. - */ - - dtorsize = shdr->sh_size; - loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t); - - bvdbg("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n", - dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors); - - /* Check if there are any destructors. It is not an error if there - * are none. - */ - - if (loadinfo->ndtors > 0) - { - /* Check an assumption that we made above */ - - DEBUGASSERT(shdr->sh_size == loadinfo->ndtors * sizeof(binfmt_dtor_t)); - - /* In the old ABI, the .dtors section is not allocated. In that case, - * we need to allocate memory to hold the .dtors and then copy the - * from the file into the allocated memory. - * - * SHF_ALLOC indicates that the section requires memory during - * execution. - */ - - if ((shdr->sh_flags & SHF_ALLOC) == 0) - { - /* Allocate memory to hold a copy of the .dtor section */ - - loadinfo->ctoralloc = (binfmt_dtor_t *)kmm_malloc(dtorsize); - if (!loadinfo->ctoralloc) - { - bdbg("Failed to allocate memory for .dtors\n"); - return -ENOMEM; - } - - loadinfo->dtors = (binfmt_dtor_t *)loadinfo->ctoralloc; - - /* Read the section header table into memory */ - - ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, - shdr->sh_offset); - if (ret < 0) - { - bdbg("Failed to allocate .dtors: %d\n", ret); - return ret; - } - - /* Fix up all of the .dtor addresses. Since the addresses - * do not lie in allocated memory, there will be no relocation - * section for them. - */ - - for (i = 0; i < loadinfo->ndtors; i++) - { - FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->dtors)[i]); - - bvdbg("dtor %d: %08lx + %08lx = %08lx\n", - i, *ptr, (unsigned long)loadinfo->textalloc, - (unsigned long)(*ptr + loadinfo->textalloc)); - - *ptr += loadinfo->textalloc; - } - } - else - { - - /* Save the address of the .dtors (actually, .init_array) where it was - * loaded into memory. Since the .dtors lie in allocated memory, they - * will be relocated via the normal mechanism. - */ - - loadinfo->dtors = (binfmt_dtor_t *)shdr->sh_addr; - } - } - - return OK; -} - -#endif /* CONFIG_BINFMT_CONSTRUCTORS */ diff --git a/binfmt/libmodule/libmodule_init.c b/binfmt/libmodule/libmodule_init.c index c5f737e36f..0d3c75b6c7 100644 --- a/binfmt/libmodule/libmodule_init.c +++ b/binfmt/libmodule/libmodule_init.c @@ -57,14 +57,14 @@ ****************************************************************************/ /* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be - * defined or CONFIG_ELF_DUMPBUFFER does nothing. + * defined or CONFIG_MODULE_DUMPBUFFER does nothing. */ #if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) -# undef CONFIG_ELF_DUMPBUFFER +# undef CONFIG_MODULE_DUMPBUFFER #endif -#ifdef CONFIG_ELF_DUMPBUFFER +#ifdef CONFIG_MODULE_DUMPBUFFER # define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) #else # define libmod_dumpbuffer(m,b,n) diff --git a/binfmt/libmodule/libmodule_iobuffer.c b/binfmt/libmodule/libmodule_iobuffer.c index 296c8c2c94..cc3d16863c 100644 --- a/binfmt/libmodule/libmodule_iobuffer.c +++ b/binfmt/libmodule/libmodule_iobuffer.c @@ -84,14 +84,14 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) { /* No.. allocate one now */ - loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_ELF_BUFFERSIZE); + loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_MODULE_BUFFERSIZE); if (!loadinfo->iobuffer) { bdbg("Failed to allocate an I/O buffer\n"); return -ENOMEM; } - loadinfo->buflen = CONFIG_ELF_BUFFERSIZE; + loadinfo->buflen = CONFIG_MODULE_BUFFERSIZE; } return OK; diff --git a/binfmt/libmodule/libmodule_load.c b/binfmt/libmodule/libmodule_load.c index 6c55f853de..d1869d5901 100644 --- a/binfmt/libmodule/libmodule_load.c +++ b/binfmt/libmodule/libmodule_load.c @@ -50,6 +50,7 @@ #include #include +#include #include #include "libmodule.h" @@ -58,7 +59,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1) +#define ELF_ALIGN_MASK ((1 << CONFIG_MODULE_ALIGN_LOG2) - 1) #define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK) #define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK) @@ -157,7 +158,7 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) bvdbg("Loaded sections:\n"); text = (FAR uint8_t *)loadinfo->textalloc; - data = (FAR uint8_t *)loadinfo->dataalloc; + data = (FAR uint8_t *)loadinfo->datastart; for (i = 0; i < loadinfo->ehdr.e_shnum; i++) { @@ -243,10 +244,6 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) { - size_t heapsize; -#ifdef CONFIG_UCLIBCXX_EXCEPTION - int exidx; -#endif int ret; bvdbg("loadinfo: %p\n", loadinfo); @@ -265,15 +262,11 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) libmod_elfsize(loadinfo); - /* Determine the heapsize to allocate. */ - - heapsize = 0; - /* Allocate (and zero) memory for the ELF file. */ /* Allocate memory to hold the ELF image */ - loadinfo->textalloc = (uintptr_t)kmm_zalloc(textsize + datasize); + loadinfo->textalloc = (uintptr_t)kmm_zalloc(loadinfo->textsize + loadinfo->datasize); if (!loadinfo->textalloc) { bdbg("ERROR: Failed to allocate memory for the module\n"); @@ -281,7 +274,7 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) goto errout_with_buffers; } - loadinfo->dataalloc = loadinfo->textalloc + textsize; + loadinfo->datastart = loadinfo->textalloc + loadinfo->textsize; /* Load ELF section data into memory */ @@ -292,36 +285,6 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) goto errout_with_buffers; } - /* Load static constructors and destructors. */ - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - ret = libmod_loadctors(loadinfo); - if (ret < 0) - { - bdbg("ERROR: libmod_loadctors failed: %d\n", ret); - goto errout_with_buffers; - } - - ret = libmod_loaddtors(loadinfo); - if (ret < 0) - { - bdbg("ERROR: libmod_loaddtors failed: %d\n", ret); - goto errout_with_buffers; - } -#endif - -#ifdef CONFIG_UCLIBCXX_EXCEPTION - exidx = libmod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); - if (exidx < 0) - { - bvdbg("libmod_findsection: Exception Index section not found: %d\n", exidx); - } - else - { - up_init_exidx(loadinfo->shdr[exidx].sh_addr, loadinfo->shdr[exidx].sh_size); - } -#endif - return OK; /* Error exits */ diff --git a/binfmt/libmodule/libmodule_read.c b/binfmt/libmodule/libmodule_read.c index effa0510e0..13cfc7fc93 100644 --- a/binfmt/libmodule/libmodule_read.c +++ b/binfmt/libmodule/libmodule_read.c @@ -49,6 +49,8 @@ #include +#include "libmodule.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/binfmt/libmodule/libmodule_sections.c b/binfmt/libmodule/libmodule_sections.c index 699b3e4f75..95bc414d84 100644 --- a/binfmt/libmodule/libmodule_sections.c +++ b/binfmt/libmodule/libmodule_sections.c @@ -156,7 +156,7 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); if (ret < 0) { bdbg("libmod_reallocbuffer failed: %d\n", ret); diff --git a/binfmt/libmodule/libmodule_symbols.c b/binfmt/libmodule/libmodule_symbols.c index 6482e389e1..a9b3eb8d5c 100644 --- a/binfmt/libmodule/libmodule_symbols.c +++ b/binfmt/libmodule/libmodule_symbols.c @@ -54,8 +54,8 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef CONFIG_ELF_BUFFERINCR -# define CONFIG_ELF_BUFFERINCR 32 +#ifndef CONFIG_MODULE_BUFFERINCR +# define CONFIG_MODULE_BUFFERINCR 32 #endif /**************************************************************************** @@ -146,7 +146,7 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); if (ret < 0) { bdbg("libmod_reallocbuffer failed: %d\n", ret); diff --git a/binfmt/libmodule/libmodule_unload.c b/binfmt/libmodule/libmodule_unload.c index 73822b59c6..e524dbe197 100644 --- a/binfmt/libmodule/libmodule_unload.c +++ b/binfmt/libmodule/libmodule_unload.c @@ -93,32 +93,10 @@ int libmod_unload(struct libmod_loadinfo_s *loadinfo) /* Clear out all indications of the allocated address environment */ loadinfo->textalloc = 0; - loadinfo->dataalloc = 0; + loadinfo->datastart = 0; loadinfo->textsize = 0; loadinfo->datasize = 0; -#ifdef CONFIG_BINFMT_CONSTRUCTORS - /* Release memory used to hold static constructors and destructors */ - - if (loadinfo->ctoralloc != 0) - { - kmm_free(loadinfo->ctoralloc); - loadinfo->ctoralloc = NULL; - } - - loadinfo->ctors = NULL; - loadinfo->nctors = 0; - - if (loadinfo->dtoralloc != 0) - { - kmm_free(loadinfo->dtoralloc); - loadinfo->dtoralloc = NULL; - } - - loadinfo->dtors = NULL; - loadinfo->ndtors = 0; -#endif - return OK; } diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/binfmt/module.h index 11931f20f2..bf3a8a5fe0 100644 --- a/include/nuttx/binfmt/module.h +++ b/include/nuttx/binfmt/module.h @@ -86,45 +86,6 @@ * Public Types ****************************************************************************/ -/* This struct provides a description of the currently loaded instantiation - * of the kernel module. - */ - -struct mod_loadinfo_s -{ - /* elfalloc is the base address of the memory that is allocated to hold the - * module image. - * - * The alloc[] array in struct binary_s will hold memory that persists after - * the module has been loaded. - */ - - uintptr_t textalloc; /* .text memory allocated when module was loaded */ - uintptr_t dataalloc; /* .bss/.data memory allocated when module was loaded */ - size_t textsize; /* Size of the module .text memory allocation */ - size_t datasize; /* Size of the module .bss/.data memory allocation */ - off_t filelen; /* Length of the entire module file */ - Elf32_Ehdr ehdr; /* Buffered module file header */ - FAR Elf32_Shdr *shdr; /* Buffered module section headers */ - uint8_t *iobuffer; /* File I/O buffer */ - - /* Constructors and destructors */ - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - FAR void *ctoralloc; /* Memory allocated for ctors */ - FAR void *dtoralloc; /* Memory allocated dtors */ - FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */ - FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */ - uint16_t nctors; /* Number of constructors */ - uint16_t ndtors; /* Number of destructors */ -#endif - - uint16_t symtabidx; /* Symbol table section index */ - uint16_t strtabidx; /* String table section index */ - uint16_t buflen; /* size of iobuffer[] */ - int filfd; /* Descriptor for the file being loaded */ -}; - /* A NuttX module is expected to export a function called module_initialize() * that has the following function prototype. This function should appear as * the entry point in the ELF module file and will be called bythe binfmt @@ -145,8 +106,34 @@ struct mod_loadinfo_s typedef CODE int (*mod_initializer_t)(void); +/* This describes the file to be loaded. + * + * NOTE 1: The 'filename' must be the full, absolute path to the file to be + * executed unless CONFIG_BINFMT_EXEPATH is defined. In that case, + * 'filename' may be a relative path; a set of candidate absolute paths + * will be generated using the PATH environment variable and load_module() + * will attempt to load each file that is found at those absolute paths. + */ + +struct symtab_s; +struct module_s +{ + /* Information provided to insmod by the caller */ + + FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */ + FAR const struct symtab_s *exports; /* Table of exported symbols */ + int nexports; /* The number of symbols in exports[] */ + + /* Information provided from insmod (if successful) describing the + * resources used by the loaded module. + */ + + mod_initializer_t initializer; /* Module initializer function */ + FAR void *alloc; /* Allocated kernel memory */ +}; + /**************************************************************************** - * Public Functions + * Public Function Prototypes ****************************************************************************/ #undef EXTERN @@ -159,120 +146,15 @@ extern "C" #endif /**************************************************************************** - * These are APIs exported by libelf (but are used only by the binfmt logic): - ****************************************************************************/ - -/**************************************************************************** - * Name: libmod_initialize - * - * Description: - * This function is called to configure the library to process an kernel - * module. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int libmod_initalize(FAR const char *filename, - FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: libmod_uninitialize - * - * Description: - * Releases any resources committed by mod_init(). This essentially - * undoes the actions of mod_init. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int libmod_uninitialize(FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: mod_load - * - * Description: - * Loads the binary into memory, allocating memory, performing relocations - * and initializing the data and bss segments. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_load(FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: mod_bind + * Name: insmod * * Description: - * Bind the imported symbol names in the loaded module described by - * 'loadinfo' using the exported symbol values provided by 'symtab'. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. + * Verify that the file is an ELF module binary and, if so, load the + * module into kernel memory and initialize it for use. * ****************************************************************************/ -struct symtab_s; -int mod_bind(FAR struct mod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports); - -/**************************************************************************** - * Name: mod_unload - * - * Description: - * This function unloads the object from memory. This essentially undoes - * the actions of mod_load. It is called only under certain error - * conditions after the module has been loaded but not yet started. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_unload(struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * These are APIs used outside of binfmt by NuttX: - ****************************************************************************/ -/**************************************************************************** - * Name: mod_initialize - * - * Description: - * Module support is built unconditionally. However, in order to - * use this binary format, this function must be called during system - * initialization in order to register the module binary format. - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_initialize(void); - -/**************************************************************************** - * Name: mod_uninitialize - * - * Description: - * Unregister the module loader - * - * Returned Value: - * None - * - ****************************************************************************/ - -void mod_uninitialize(void); +int insmod(FAR struct module_s *modp); /**************************************************************************** * These are APIs must be provided by architecture-specific logic. @@ -323,26 +205,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, int up_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, uintptr_t addr); -#ifdef CONFIG_UCLIBCXX_EXCEPTION -/**************************************************************************** - * Name: up_init_exidx - * - * Description: - * Load the boundaries of the Exception Index ELF section in order to - * support exception handling for loaded modules. - * - * Input Parameters: - * address - The ELF section address for the Exception Index - * size - The size of the ELF section. - * - * Returned Value: - * Always returns Zero (OK). - * - ****************************************************************************/ - -int up_init_exidx(Elf32_Addr address, Elf32_Word size); -#endif - /**************************************************************************** * Name: up_coherent_dcache * -- GitLab From 49554fe4fc27202e628c441b7b693c65e0c22a28 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 07:09:17 -0600 Subject: [PATCH 441/858] Move module support from binfmt/ to sched/ so that it can be configured and built independently from binfmt features --- binfmt/Kconfig | 10 -- binfmt/Makefile | 1 - binfmt/libmodule/Kconfig | 35 ------ include/nuttx/arch.h | 78 ++++++++++++++ include/nuttx/binfmt/elf.h | 92 +--------------- include/nuttx/{binfmt => }/module.h | 102 ++---------------- sched/Kconfig | 43 +++++++- sched/Makefile | 1 + {binfmt/libmodule => sched/module}/Make.defs | 21 ++-- {binfmt/libmodule => sched/module}/gnu-elf.ld | 2 +- .../module/mod_bind.c | 84 +++++++-------- .../module/mod_init.c | 59 +++++----- binfmt/insmod.c => sched/module/mod_insmod.c | 22 ++-- .../module/mod_iobuffer.c | 32 ++---- .../module/mod_load.c | 49 ++++----- .../module/mod_read.c | 30 +++--- .../module/mod_sections.c | 60 +++++------ .../module/mod_symbols.c | 66 ++++++------ .../module/mod_uninit.c | 34 ++---- .../module/mod_unload.c | 29 ++--- .../module/mod_verify.c | 27 ++--- .../libmodule.h => sched/module/module.h | 90 ++++++++-------- 22 files changed, 393 insertions(+), 574 deletions(-) delete mode 100644 binfmt/libmodule/Kconfig rename include/nuttx/{binfmt => }/module.h (57%) rename {binfmt/libmodule => sched/module}/Make.defs (78%) rename {binfmt/libmodule => sched/module}/gnu-elf.ld (98%) rename binfmt/libmodule/libmodule_bind.c => sched/module/mod_bind.c (76%) rename binfmt/libmodule/libmodule_init.c => sched/module/mod_init.c (75%) rename binfmt/insmod.c => sched/module/mod_insmod.c (94%) rename binfmt/libmodule/libmodule_iobuffer.c => sched/module/mod_iobuffer.c (78%) rename binfmt/libmodule/libmodule_load.c => sched/module/mod_load.c (86%) rename binfmt/libmodule/libmodule_read.c => sched/module/mod_read.c (87%) rename binfmt/libmodule/libmodule_sections.c => sched/module/mod_sections.c (80%) rename binfmt/libmodule/libmodule_symbols.c => sched/module/mod_symbols.c (83%) rename binfmt/libmodule/libmodule_uninit.c => sched/module/mod_uninit.c (75%) rename binfmt/libmodule/libmodule_unload.c => sched/module/mod_unload.c (77%) rename binfmt/libmodule/libmodule_verify.c => sched/module/mod_verify.c (82%) rename binfmt/libmodule/libmodule.h => sched/module/module.h (82%) diff --git a/binfmt/Kconfig b/binfmt/Kconfig index b9263becae..fc2b457f89 100644 --- a/binfmt/Kconfig +++ b/binfmt/Kconfig @@ -12,16 +12,6 @@ config BINFMT_DISABLE if !BINFMT_DISABLE -config MODULE - bool "Enable loadable OS modules" - default n - ---help--- - Enable support for loadable OS modules. Default: n - -if MODULE -source binfmt/libmodule/Kconfig -endif - config BINFMT_EXEPATH bool "Support PATH variable" default n diff --git a/binfmt/Makefile b/binfmt/Makefile index ef329e6c38..9da55ea973 100644 --- a/binfmt/Makefile +++ b/binfmt/Makefile @@ -71,7 +71,6 @@ VPATH = SUBDIRS = DEPPATH = --dep-path . -include libmodule$(DELIM)Make.defs include libnxflat$(DELIM)Make.defs include libelf$(DELIM)Make.defs include libbuiltin$(DELIM)Make.defs diff --git a/binfmt/libmodule/Kconfig b/binfmt/libmodule/Kconfig deleted file mode 100644 index 0e8ab2efa3..0000000000 --- a/binfmt/libmodule/Kconfig +++ /dev/null @@ -1,35 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config MODULE_ALIGN_LOG2 - int "Log2 Section Alignment" - default 2 - ---help--- - Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc. - -config MODULE_BUFFERSIZE - int "Module I/O Buffer Size" - default 128 - ---help--- - This is an I/O buffer that is used to access the module file. - Variable length items will need to be read (such as symbol names). - This is really just this initial size of the buffer; it will be - reallocated as necessary to hold large symbol names). Default: 128 - -config MODULE_BUFFERINCR - int "Module I/O Buffer Realloc Increment" - default 32 - ---help--- - This is an I/O buffer that is used to access the module file. - Variable length items will need to be read (such as symbol names). - This value specifies the size increment to use each time the - buffer is reallocated. Default: 32 - -config MODULE_DUMPBUFFER - bool "Dump module buffers" - default n - depends on DEBUG && DEBUG_VERBOSE - ---help--- - Dump various module buffers for debug purposes diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index b3aa8d6631..a28e7767ba 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -106,6 +106,10 @@ #include #include +#if defined(CONFIG_ELF) || defined(CONFIG_MODULE) +# include +#endif + #include /**************************************************************************** @@ -1251,6 +1255,80 @@ int up_shmat(FAR uintptr_t *pages, unsigned int npages, uintptr_t vaddr); int up_shmdt(uintptr_t vaddr, unsigned int npages); #endif +/**************************************************************************** + * Interfaces required for ELF module support + ****************************************************************************/ +/**************************************************************************** + * Name: up_checkarch + * + * Description: + * Given the ELF header in 'hdr', verify that the module is appropriate + * for the current, configured architecture. Every architecture that uses + * the module loader must provide this function. + * + * Input Parameters: + * hdr - The ELF header read from the module file. + * + * Returned Value: + * True if the architecture supports this module file. + * + ****************************************************************************/ + +#if defined(CONFIG_ELF) || defined(CONFIG_MODULE) +bool up_checkarch(FAR const Elf32_Ehdr *hdr); +#endif + +/**************************************************************************** + * Name: up_relocate and up_relocateadd + * + * Description: + * Perform on architecture-specific ELF relocation. Every architecture + * that uses the module loader must provide this function. + * + * Input Parameters: + * rel - The relocation type + * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. + * addr - The address that requires the relocation. + * + * Returned Value: + * Zero (OK) if the relocation was successful. Otherwise, a negated errno + * value indicating the cause of the relocation failure. + * + ****************************************************************************/ + +#if defined(CONFIG_ELF) || defined(CONFIG_MODULE) +int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, + uintptr_t addr); +int up_relocateadd(FAR const Elf32_Rela *rel, + FAR const Elf32_Sym *sym, uintptr_t addr); +#endif + +/**************************************************************************** + * Name: up_coherent_dcache + * + * Description: + * Ensure that the I and D caches are coherent within specified region + * by cleaning the D cache (i.e., flushing the D cache contents to memory + * and invalidating the I cache. This is typically used when code has been + * written to a memory region, and will be executed. + * + * Input Parameters: + * addr - virtual start address of region + * len - Size of the address region in bytes + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE +void up_coherent_dcache(uintptr_t addr, size_t len); +#endif + /**************************************************************************** * Name: up_interrupt_context * diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h index ba5c31325a..f687bbd071 100644 --- a/include/nuttx/binfmt/elf.h +++ b/include/nuttx/binfmt/elf.h @@ -48,6 +48,7 @@ #include #include +#include #include /**************************************************************************** @@ -271,97 +272,6 @@ int elf_initialize(void); void elf_uninitialize(void); -/**************************************************************************** - * These are APIs must be provided by architecture-specific logic. - * (These really belong in include/nuttx/arch.h): - ****************************************************************************/ -/**************************************************************************** - * Name: up_checkarch - * - * Description: - * Given the ELF header in 'hdr', verify that the ELF file is appropriate - * for the current, configured architecture. Every architecture that uses - * the ELF loader must provide this function. - * - * Input Parameters: - * hdr - The ELF header read from the ELF file. - * - * Returned Value: - * True if the architecture supports this ELF file. - * - ****************************************************************************/ - -bool up_checkarch(FAR const Elf32_Ehdr *hdr); - -/**************************************************************************** - * Name: up_relocate and up_relocateadd - * - * Description: - * Perform on architecture-specific ELF relocation. Every architecture - * that uses the ELF loader must provide this function. - * - * Input Parameters: - * rel - The relocation type - * sym - The ELF symbol structure containing the fully resolved value. - * There are a few relocation types for a few architectures that do - * not require symbol information. For those, this value will be - * NULL. Implementations of these functions must be able to handle - * that case. - * addr - The address that requires the relocation. - * - * Returned Value: - * Zero (OK) if the relocation was successful. Otherwise, a negated errno - * value indicating the cause of the relocation failure. - * - ****************************************************************************/ - -int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, - uintptr_t addr); -int up_relocateadd(FAR const Elf32_Rela *rel, - FAR const Elf32_Sym *sym, uintptr_t addr); - -#ifdef CONFIG_UCLIBCXX_EXCEPTION -/**************************************************************************** - * Name: up_init_exidx - * - * Description: - * Load the boundaries of the Exception Index ELF section in order to - * support exception handling for loaded ELF modules. - * - * Input Parameters: - * address - The ELF section address for the Exception Index - * size - The size of the ELF section. - * - * Returned Value: - * Always returns Zero (OK). - * - ****************************************************************************/ - -int up_init_exidx(Elf32_Addr address, Elf32_Word size); -#endif - -/**************************************************************************** - * Name: up_coherent_dcache - * - * Description: - * Ensure that the I and D caches are coherent within specified region - * by cleaning the D cache (i.e., flushing the D cache contents to memory - * and invalidating the I cache. This is typically used when code has been - * written to a memory region, and will be executed. - * - * Input Parameters: - * addr - virtual start address of region - * len - Size of the address region in bytes - * - * Returned Value: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE -void up_coherent_dcache(uintptr_t addr, size_t len); -#endif - #undef EXTERN #if defined(__cplusplus) } diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/module.h similarity index 57% rename from include/nuttx/binfmt/module.h rename to include/nuttx/module.h index bf3a8a5fe0..3e4c028a30 100644 --- a/include/nuttx/binfmt/module.h +++ b/include/nuttx/module.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/binfmt/module.h + * include/nuttx/module.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_BINFMT_MODULE_H -#define __INCLUDE_NUTTX_BINFMT_MODULE_H +#ifndef __INCLUDE_NUTTX_MODULE_H +#define __INCLUDE_NUTTX_MODULE_H /**************************************************************************** * Included Files @@ -48,6 +48,7 @@ #include #include +#include #include /**************************************************************************** @@ -71,17 +72,6 @@ # define CONFIG_MODULE_BUFFERINCR 32 #endif -/* Allocation array size and indices */ - -#define LIBMODULE_MODULE_ALLOC 0 -#ifdef CONFIG_BINFMT_CONSTRUCTORS -# define LIBMODULE_CTORS_ALLOC 1 -# define LIBMODULE_CTPRS_ALLOC 2 -# define LIBMODULE_NALLOC 3 -#else -# define LIBMODULE_NALLOC 1 -#endif - /**************************************************************************** * Public Types ****************************************************************************/ @@ -106,21 +96,14 @@ typedef CODE int (*mod_initializer_t)(void); -/* This describes the file to be loaded. - * - * NOTE 1: The 'filename' must be the full, absolute path to the file to be - * executed unless CONFIG_BINFMT_EXEPATH is defined. In that case, - * 'filename' may be a relative path; a set of candidate absolute paths - * will be generated using the PATH environment variable and load_module() - * will attempt to load each file that is found at those absolute paths. - */ +/* This describes the file to be loaded. */ struct symtab_s; struct module_s { /* Information provided to insmod by the caller */ - FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */ + FAR const char *filename; /* Full path to the binary to be loaded */ FAR const struct symtab_s *exports; /* Table of exported symbols */ int nexports; /* The number of symbols in exports[] */ @@ -156,80 +139,9 @@ extern "C" int insmod(FAR struct module_s *modp); -/**************************************************************************** - * These are APIs must be provided by architecture-specific logic. - * (These really belong in include/nuttx/arch.h): - ****************************************************************************/ -/**************************************************************************** - * Name: up_checkarch - * - * Description: - * Given the ELF header in 'hdr', verify that the module is appropriate - * for the current, configured architecture. Every architecture that uses - * the module loader must provide this function. - * - * Input Parameters: - * hdr - The ELF header read from the module file. - * - * Returned Value: - * True if the architecture supports this module file. - * - ****************************************************************************/ - -bool up_checkarch(FAR const Elf32_Ehdr *hdr); - -/**************************************************************************** - * Name: up_relocate and up_relocateadd - * - * Description: - * Perform on architecture-specific ELF relocation. Every architecture - * that uses the module loader must provide this function. - * - * Input Parameters: - * rel - The relocation type - * sym - The ELF symbol structure containing the fully resolved value. - * There are a few relocation types for a few architectures that do - * not require symbol information. For those, this value will be - * NULL. Implementations of these functions must be able to handle - * that case. - * addr - The address that requires the relocation. - * - * Returned Value: - * Zero (OK) if the relocation was successful. Otherwise, a negated errno - * value indicating the cause of the relocation failure. - * - ****************************************************************************/ - -int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, - uintptr_t addr); -int up_relocateadd(FAR const Elf32_Rela *rel, - FAR const Elf32_Sym *sym, uintptr_t addr); - -/**************************************************************************** - * Name: up_coherent_dcache - * - * Description: - * Ensure that the I and D caches are coherent within specified region - * by cleaning the D cache (i.e., flushing the D cache contents to memory - * and invalidating the I cache. This is typically used when code has been - * written to a memory region, and will be executed. - * - * Input Parameters: - * addr - virtual start address of region - * len - Size of the address region in bytes - * - * Returned Value: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE -void up_coherent_dcache(uintptr_t addr, size_t len); -#endif - #undef EXTERN #if defined(__cplusplus) } #endif -#endif /* __INCLUDE_NUTTX_BINFMT_MODULE_H */ +#endif /* __INCLUDE_NUTTX_MODULE_H */ diff --git a/sched/Kconfig b/sched/Kconfig index 941026ffa1..5aefa848c0 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -852,7 +852,48 @@ config MQ_MAXMSGSIZE endmenu # POSIX Message Queue Options -menu "Work Queue Support" +menuconfig MODULE + bool "Enable loadable OS modules" + default n + ---help--- + Enable support for loadable OS modules. Default: n + +if MODULE + +config MODULE_ALIGN_LOG2 + int "Log2 Section Alignment" + default 2 + ---help--- + Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc. + +config MODULE_BUFFERSIZE + int "Module I/O Buffer Size" + default 128 + ---help--- + This is an I/O buffer that is used to access the module file. + Variable length items will need to be read (such as symbol names). + This is really just this initial size of the buffer; it will be + reallocated as necessary to hold large symbol names). Default: 128 + +config MODULE_BUFFERINCR + int "Module I/O Buffer Realloc Increment" + default 32 + ---help--- + This is an I/O buffer that is used to access the module file. + Variable length items will need to be read (such as symbol names). + This value specifies the size increment to use each time the + buffer is reallocated. Default: 32 + +config MODULE_DUMPBUFFER + bool "Dump module buffers" + default n + depends on DEBUG && DEBUG_VERBOSE + ---help--- + Dump various module buffers for debug purposes + +endif + +menu "Work queue support" config SCHED_WORKQUEUE # bool "Enable worker thread" diff --git a/sched/Makefile b/sched/Makefile index 64d243a896..066c84d904 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -56,6 +56,7 @@ include mqueue/Make.defs include clock/Make.defs include timer/Make.defs include environ/Make.defs +include module/Make.defs include wqueue/Make.defs AOBJS = $(ASRCS:.S=$(OBJEXT)) diff --git a/binfmt/libmodule/Make.defs b/sched/module/Make.defs similarity index 78% rename from binfmt/libmodule/Make.defs rename to sched/module/Make.defs index 2de76e6eef..9a0bee5498 100644 --- a/binfmt/libmodule/Make.defs +++ b/sched/module/Make.defs @@ -1,7 +1,7 @@ ############################################################################ -# binfmt/libmodule/Make.defs +# sched/module/Make.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,19 +37,18 @@ ifeq ($(CONFIG_MODULE),y) # OS module interfaces -BINFMT_CSRCS += insmod.c +CSRCS += mod_insmod.c # loadable module library -BINFMT_CSRCS += libmodule_bind.c libmodule_init.c libmodule_iobuffer.c -BINFMT_CSRCS += libmodule_load.c libmodule_read.c libmodule_sections.c -BINFMT_CSRCS += libmodule_symbols.c libmodule_uninit.c libmodule_unload.c -BINFMT_CSRCS += libmodule_verify.c +CSRCS += mod_bind.c mod_init.c mod_iobuffer.c mod_load.c mod_read.c +CSRCS += mod_sections.c mod_symbols.c mod_uninit.c mod_unload.c +CSRCS += mod_verify.c -# Hook the libmodule subdirectory into the build +# Hook the module subdirectory into the build -VPATH += libmodule -SUBDIRS += libmodule -DEPPATH += --dep-path libmodule +VPATH += module +SUBDIRS += module +DEPPATH += --dep-path module endif diff --git a/binfmt/libmodule/gnu-elf.ld b/sched/module/gnu-elf.ld similarity index 98% rename from binfmt/libmodule/gnu-elf.ld rename to sched/module/gnu-elf.ld index 9addca41fb..0bf39b9649 100644 --- a/binfmt/libmodule/gnu-elf.ld +++ b/sched/module/gnu-elf.ld @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/gnu-elf.ld + * sched/module/gnu-elf.ld * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/binfmt/libmodule/libmodule_bind.c b/sched/module/mod_bind.c similarity index 76% rename from binfmt/libmodule/libmodule_bind.c rename to sched/module/mod_bind.c index 0f6a09e409..18e48c8541 100644 --- a/binfmt/libmodule/libmodule_bind.c +++ b/sched/module/mod_bind.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_bind.c + * sched/module/mod_bind.c * - * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,20 +46,20 @@ #include #include -#include +#include #include -#include "libmodule.h" +#include "module.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be - * defined or CONFIG_MODULE_DUMPBUFFER does nothing. +/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_MODULE_DUMPBUFFER have to + * be defined or CONFIG_MODULE_DUMPBUFFER does nothing. */ -#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_MODULE_DUMPBUFFER) # undef CONFIG_MODULE_DUMPBUFFER #endif @@ -68,34 +68,26 @@ #endif #ifdef CONFIG_MODULE_DUMPBUFFER -# define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +# define mod_dumpbuffer(m,b,n) svdbgdumpbuffer(m,b,n) #else -# define libmod_dumpbuffer(m,b,n) +# define mod_dumpbuffer(m,b,n) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_readrel + * Name: mod_readrel * * Description: * Read the ELF32_Rel structure into memory. * ****************************************************************************/ -static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *relsec, - int index, FAR Elf32_Rel *rel) +static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *relsec, + int index, FAR Elf32_Rel *rel) { off_t offset; @@ -103,7 +95,7 @@ static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel))) { - bdbg("Bad relocation symbol index: %d\n", index); + sdbg("Bad relocation symbol index: %d\n", index); return -EINVAL; } @@ -113,11 +105,11 @@ static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, /* And, finally, read the symbol table entry into memory */ - return libmod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); + return mod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); } /**************************************************************************** - * Name: libmod_relocate and libmod_relocateadd + * Name: mod_relocate and mod_relocateadd * * Description: * Perform all relocations associated with a section. @@ -128,8 +120,8 @@ static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) { FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx]; @@ -153,10 +145,10 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, /* Read the relocation entry into memory */ - ret = libmod_readrel(loadinfo, relsec, i, &rel); + ret = mod_readrel(loadinfo, relsec, i, &rel); if (ret < 0) { - bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n", + sdbg("Section %d reloc %d: Failed to read relocation entry: %d\n", relidx, i, ret); return ret; } @@ -169,17 +161,17 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, /* Read the symbol table entry into memory */ - ret = libmod_readsym(loadinfo, symidx, &sym); + ret = mod_readsym(loadinfo, symidx, &sym); if (ret < 0) { - bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n", + sdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n", relidx, i, symidx, ret); return ret; } /* Get the value of the symbol (in sym.st_value) */ - ret = libmod_symvalue(loadinfo, &sym, exports, nexports); + ret = mod_symvalue(loadinfo, &sym, exports, nexports); if (ret < 0) { /* The special error -ESRCH is returned only in one condition: The @@ -194,13 +186,13 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, if (ret == -ESRCH) { - bdbg("Section %d reloc %d: Undefined symbol[%d] has no name: %d\n", + sdbg("Section %d reloc %d: Undefined symbol[%d] has no name: %d\n", relidx, i, symidx, ret); psym = NULL; } else { - bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n", + sdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n", relidx, i, symidx, ret); return ret; } @@ -210,7 +202,7 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t)) { - bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n", + sdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n", relidx, i, rel.r_offset, dstsec->sh_size); return -EINVAL; } @@ -222,7 +214,7 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, ret = up_relocate(&rel, psym, addr); if (ret < 0) { - bdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", relidx, i, ret); + sdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", relidx, i, ret); return ret; } } @@ -230,10 +222,10 @@ static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, return OK; } -static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx, +static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, FAR const struct symtab_s *exports, int nexports) { - bdbg("Not implemented\n"); + sdbg("Not implemented\n"); return -ENOSYS; } @@ -242,7 +234,7 @@ static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx ****************************************************************************/ /**************************************************************************** - * Name: libmod_bind + * Name: mod_bind * * Description: * Bind the imported symbol names in the loaded module described by @@ -254,28 +246,28 @@ static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx * ****************************************************************************/ -int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports) +int mod_bind(FAR struct mod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports) { int ret; int i; /* Find the symbol and string tables */ - ret = libmod_findsymtab(loadinfo); + ret = mod_findsymtab(loadinfo); if (ret < 0) { return ret; } - /* Allocate an I/O buffer. This buffer is used by libmod_symname() to + /* Allocate an I/O buffer. This buffer is used by mod_symname() to * accumulate the variable length symbol name. */ - ret = libmod_allocbuffer(loadinfo); + ret = mod_allocbuffer(loadinfo); if (ret < 0) { - bdbg("libmod_allocbuffer failed: %d\n", ret); + sdbg("mod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -304,11 +296,11 @@ int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, if (loadinfo->shdr[i].sh_type == SHT_REL) { - ret = libmod_relocate(loadinfo, i, exports, nexports); + ret = mod_relocate(loadinfo, i, exports, nexports); } else if (loadinfo->shdr[i].sh_type == SHT_RELA) { - ret = libmod_relocateadd(loadinfo, i, exports, nexports); + ret = mod_relocateadd(loadinfo, i, exports, nexports); } if (ret < 0) diff --git a/binfmt/libmodule/libmodule_init.c b/sched/module/mod_init.c similarity index 75% rename from binfmt/libmodule/libmodule_init.c rename to sched/module/mod_init.c index 0d3c75b6c7..c16069caf5 100644 --- a/binfmt/libmodule/libmodule_init.c +++ b/sched/module/mod_init.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_init.c + * sched/module/mod_init.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,26 +48,26 @@ #include #include -#include +#include -#include "libmodule.h" +#include "module.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be - * defined or CONFIG_MODULE_DUMPBUFFER does nothing. +/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_MODULE_DUMPBUFFER have to + * be defined or CONFIG_MODULE_DUMPBUFFER does nothing. */ -#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT) +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_MODULE_DUMPBUFFER) # undef CONFIG_MODULE_DUMPBUFFER #endif #ifdef CONFIG_MODULE_DUMPBUFFER -# define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +# define mod_dumpbuffer(m,b,n) svdbgdumpbuffer(m,b,n) #else -# define libmod_dumpbuffer(m,b,n) +# define mod_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: libmod_filelen + * Name: mod_filelen * * Description: * Get the size of the ELF file @@ -90,8 +90,8 @@ * ****************************************************************************/ -static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, - FAR const char *filename) +static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *filename) { struct stat buf; int ret; @@ -102,7 +102,7 @@ static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, if (ret < 0) { int errval = errno; - bdbg("Failed to stat file: %d\n", errval); + sdbg("Failed to stat file: %d\n", errval); return -errval; } @@ -110,7 +110,7 @@ static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, if (!S_ISREG(buf.st_mode)) { - bdbg("Not a regular file. mode: %d\n", buf.st_mode); + sdbg("Not a regular file. mode: %d\n", buf.st_mode); return -ENOENT; } @@ -129,7 +129,7 @@ static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: libmod_initialize + * Name: mod_initialize * * Description: * This function is called to configure the library to process an ELF @@ -141,23 +141,23 @@ static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -int libmod_initialize(FAR const char *filename, - FAR struct libmod_loadinfo_s *loadinfo) +int mod_initialize(FAR const char *filename, + FAR struct mod_loadinfo_s *loadinfo) { int ret; - bvdbg("filename: %s loadinfo: %p\n", filename, loadinfo); + svdbg("filename: %s loadinfo: %p\n", filename, loadinfo); /* Clear the load info structure */ - memset(loadinfo, 0, sizeof(struct libmod_loadinfo_s)); + memset(loadinfo, 0, sizeof(struct mod_loadinfo_s)); /* Get the length of the file. */ - ret = libmod_filelen(loadinfo, filename); + ret = mod_filelen(loadinfo, filename); if (ret < 0) { - bdbg("libmod_filelen failed: %d\n", ret); + sdbg("mod_filelen failed: %d\n", ret); return ret; } @@ -167,39 +167,38 @@ int libmod_initialize(FAR const char *filename, if (loadinfo->filfd < 0) { int errval = errno; - bdbg("Failed to open ELF binary %s: %d\n", filename, errval); + sdbg("Failed to open ELF binary %s: %d\n", filename, errval); return -errval; } /* Read the ELF ehdr from offset 0 */ - ret = libmod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, + ret = mod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); if (ret < 0) { - bdbg("Failed to read ELF header: %d\n", ret); + sdbg("Failed to read ELF header: %d\n", ret); return ret; } - libmod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, + mod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); /* Verify the ELF header */ - ret = libmod_verifyheader(&loadinfo->ehdr); + ret = mod_verifyheader(&loadinfo->ehdr); if (ret < 0) { /* This may not be an error because we will be called to attempt loading - * EVERY binary. If libmod_verifyheader() does not recognize the ELF header, + * EVERY binary. If mod_verifyheader() does not recognize the ELF header, * it will -ENOEXEC whcih simply informs the system that the file is not an - * ELF file. libmod_verifyheader() will return other errors if the ELF header + * ELF file. mod_verifyheader() will return other errors if the ELF header * is not correctly formed. */ - bdbg("Bad ELF header: %d\n", ret); + sdbg("Bad ELF header: %d\n", ret); return ret; } return OK; } - diff --git a/binfmt/insmod.c b/sched/module/mod_insmod.c similarity index 94% rename from binfmt/insmod.c rename to sched/module/mod_insmod.c index b2f5094d72..f06961811f 100644 --- a/binfmt/insmod.c +++ b/sched/module/mod_insmod.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/module.c + * sched/module/module.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -49,9 +49,9 @@ #include #include -#include +#include -#include "libmodule/libmodule.h" +#include "module/module.h" #ifdef CONFIG_MODULE @@ -86,7 +86,7 @@ ****************************************************************************/ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) -static void mod_dumploadinfo(FAR struct libmod_loadinfo_s *loadinfo) +static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) { int i; @@ -171,14 +171,14 @@ static void mod_dumpinitializer(mod_initializer_t initializer, int insmod(FAR struct module_s *modp) { - struct libmod_loadinfo_s loadinfo; /* Contains globals for libmodule */ + struct mod_loadinfo_s loadinfo; int ret; bvdbg("Loading file: %s\n", modp->filename); /* Initialize the ELF library to load the program binary. */ - ret = libmod_initialize(modp->filename, &loadinfo); + ret = mod_initialize(modp->filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -188,7 +188,7 @@ int insmod(FAR struct module_s *modp) /* Load the program binary */ - ret = libmod_load(&loadinfo); + ret = mod_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -198,7 +198,7 @@ int insmod(FAR struct module_s *modp) /* Bind the program to the exported symbol table */ - ret = libmod_bind(&loadinfo, modp->exports, modp->nexports); + ret = mod_bind(&loadinfo, modp->exports, modp->nexports); if (ret != 0) { bdbg("Failed to bind symbols program binary: %d\n", ret); @@ -226,13 +226,13 @@ int insmod(FAR struct module_s *modp) } } - libmod_uninitialize(&loadinfo); + mod_uninitialize(&loadinfo); return OK; errout_with_load: - libmod_unload(&loadinfo); + mod_unload(&loadinfo); errout_with_init: - libmod_uninitialize(&loadinfo); + mod_uninitialize(&loadinfo); errout: return ret; } diff --git a/binfmt/libmodule/libmodule_iobuffer.c b/sched/module/mod_iobuffer.c similarity index 78% rename from binfmt/libmodule/libmodule_iobuffer.c rename to sched/module/mod_iobuffer.c index cc3d16863c..0a8c4bc4ef 100644 --- a/binfmt/libmodule/libmodule_iobuffer.c +++ b/sched/module/mod_iobuffer.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_iobuffer.c + * sched/module/mod_iobuffer.c * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,28 +43,16 @@ #include #include -#include +#include -#include "libmodule.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include "module.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_allocbuffer + * Name: mod_allocbuffer * * Description: * Perform the initial allocation of the I/O buffer, if it has not already @@ -76,7 +64,7 @@ * ****************************************************************************/ -int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) +int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) { /* Has a buffer been allocated> */ @@ -87,7 +75,7 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_MODULE_BUFFERSIZE); if (!loadinfo->iobuffer) { - bdbg("Failed to allocate an I/O buffer\n"); + sdbg("Failed to allocate an I/O buffer\n"); return -ENOMEM; } @@ -98,7 +86,7 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: libmod_reallocbuffer + * Name: mod_reallocbuffer * * Description: * Increase the size of I/O buffer by the specified buffer increment. @@ -109,7 +97,7 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment) +int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) { FAR void *buffer; size_t newsize; @@ -123,7 +111,7 @@ int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t incremen buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize); if (!buffer) { - bdbg("Failed to reallocate the I/O buffer\n"); + sdbg("Failed to reallocate the I/O buffer\n"); return -ENOMEM; } diff --git a/binfmt/libmodule/libmodule_load.c b/sched/module/mod_load.c similarity index 86% rename from binfmt/libmodule/libmodule_load.c rename to sched/module/mod_load.c index d1869d5901..cce6ac0cb2 100644 --- a/binfmt/libmodule/libmodule_load.c +++ b/sched/module/mod_load.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_load.c + * sched/module/mod_load.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,9 +51,9 @@ #include #include -#include +#include -#include "libmodule.h" +#include "module.h" /**************************************************************************** * Pre-processor Definitions @@ -71,16 +71,12 @@ # define MIN(x,y) ((x) < (y) ? (x) : (y)) #endif -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_elfsize + * Name: mod_elfsize * * Description: * Calculate total memory allocation for the ELF file. @@ -91,7 +87,7 @@ * ****************************************************************************/ -static void libmod_elfsize(struct libmod_loadinfo_s *loadinfo) +static void mod_elfsize(struct mod_loadinfo_s *loadinfo) { size_t textsize; size_t datasize; @@ -134,7 +130,7 @@ static void libmod_elfsize(struct libmod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: libmod_loadfile + * Name: mod_loadfile * * Description: * Read the section data into memory. Section addresses in the shdr[] are @@ -146,7 +142,7 @@ static void libmod_elfsize(struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) +static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) { FAR uint8_t *text; FAR uint8_t *data; @@ -156,7 +152,7 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */ - bvdbg("Loaded sections:\n"); + svdbg("Loaded sections:\n"); text = (FAR uint8_t *)loadinfo->textalloc; data = (FAR uint8_t *)loadinfo->datastart; @@ -193,10 +189,10 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) { /* Read the section data from sh_offset to the memory region */ - ret = libmod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); + ret = mod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); if (ret < 0) { - bdbg("ERROR: Failed to read section %d: %d\n", i, ret); + sdbg("ERROR: Failed to read section %d: %d\n", i, ret); return ret; } } @@ -212,7 +208,7 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) /* Update sh_addr to point to copy in memory */ - bvdbg("%d. %08lx->%08lx\n", i, + svdbg("%d. %08lx->%08lx\n", i, (unsigned long)shdr->sh_addr, (unsigned long)*pptr); shdr->sh_addr = (uintptr_t)*pptr; @@ -230,7 +226,7 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) ****************************************************************************/ /**************************************************************************** - * Name: libmod_load + * Name: mod_load * * Description: * Loads the binary into memory, allocating memory, performing relocations @@ -242,25 +238,25 @@ static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) +int mod_load(FAR struct mod_loadinfo_s *loadinfo) { int ret; - bvdbg("loadinfo: %p\n", loadinfo); + svdbg("loadinfo: %p\n", loadinfo); DEBUGASSERT(loadinfo && loadinfo->filfd >= 0); /* Load section headers into memory */ - ret = libmod_loadshdrs(loadinfo); + ret = mod_loadshdrs(loadinfo); if (ret < 0) { - bdbg("ERROR: libmod_loadshdrs failed: %d\n", ret); + sdbg("ERROR: mod_loadshdrs failed: %d\n", ret); goto errout_with_buffers; } /* Determine total size to allocate */ - libmod_elfsize(loadinfo); + mod_elfsize(loadinfo); /* Allocate (and zero) memory for the ELF file. */ @@ -269,7 +265,7 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) loadinfo->textalloc = (uintptr_t)kmm_zalloc(loadinfo->textsize + loadinfo->datasize); if (!loadinfo->textalloc) { - bdbg("ERROR: Failed to allocate memory for the module\n"); + sdbg("ERROR: Failed to allocate memory for the module\n"); ret = -ENOMEM; goto errout_with_buffers; } @@ -278,10 +274,10 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) /* Load ELF section data into memory */ - ret = libmod_loadfile(loadinfo); + ret = mod_loadfile(loadinfo); if (ret < 0) { - bdbg("ERROR: libmod_loadfile failed: %d\n", ret); + sdbg("ERROR: mod_loadfile failed: %d\n", ret); goto errout_with_buffers; } @@ -290,7 +286,6 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo) /* Error exits */ errout_with_buffers: - libmod_unload(loadinfo); + mod_unload(loadinfo); return ret; } - diff --git a/binfmt/libmodule/libmodule_read.c b/sched/module/mod_read.c similarity index 87% rename from binfmt/libmodule/libmodule_read.c rename to sched/module/mod_read.c index 13cfc7fc93..8cad4adb89 100644 --- a/binfmt/libmodule/libmodule_read.c +++ b/sched/module/mod_read.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_read.c + * sched/module/mod_read.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,9 +47,9 @@ #include #include -#include +#include -#include "libmodule.h" +#include "module.h" /**************************************************************************** * Pre-processor Definitions @@ -66,11 +66,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: libmod_dumpreaddata + * Name: mod_dumpreaddata ****************************************************************************/ #if defined(ELF_DUMP_READDATA) -static inline void libmod_dumpreaddata(FAR char *buffer, int buflen) +static inline void mod_dumpreaddata(FAR char *buffer, int buflen) { FAR uint32_t *buf32 = (FAR uint32_t *)buffer; int i; @@ -88,7 +88,7 @@ static inline void libmod_dumpreaddata(FAR char *buffer, int buflen) } } #else -# define libmod_dumpreaddata(b,n) +# define mod_dumpreaddata(b,n) #endif /**************************************************************************** @@ -96,7 +96,7 @@ static inline void libmod_dumpreaddata(FAR char *buffer, int buflen) ****************************************************************************/ /**************************************************************************** - * Name: libmod_read + * Name: mod_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -108,13 +108,13 @@ static inline void libmod_dumpreaddata(FAR char *buffer, int buflen) * ****************************************************************************/ -int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset) +int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset) { ssize_t nbytes; /* Number of bytes read */ off_t rpos; /* Position returned by lseek */ - bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset); + svdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset); /* Loop until all of the requested data has been read. */ @@ -126,7 +126,7 @@ int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, if (rpos != offset) { int errval = errno; - bdbg("Failed to seek to position %lu: %d\n", + sdbg("Failed to seek to position %lu: %d\n", (unsigned long)offset, errval); return -errval; } @@ -142,14 +142,14 @@ int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, if (errval != EINTR) { - bdbg("Read from offset %lu failed: %d\n", + sdbg("Read from offset %lu failed: %d\n", (unsigned long)offset, errval); return -errval; } } else if (nbytes == 0) { - bdbg("Unexpected end of file\n"); + sdbg("Unexpected end of file\n"); return -ENODATA; } else @@ -160,6 +160,6 @@ int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, } } - libmod_dumpreaddata(buffer, readsize); + mod_dumpreaddata(buffer, readsize); return OK; } diff --git a/binfmt/libmodule/libmodule_sections.c b/sched/module/mod_sections.c similarity index 80% rename from binfmt/libmodule/libmodule_sections.c rename to sched/module/mod_sections.c index 95bc414d84..dcdb4de991 100644 --- a/binfmt/libmodule/libmodule_sections.c +++ b/sched/module/mod_sections.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_sections.c + * sched/module/mod_sections.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,24 +46,16 @@ #include #include -#include +#include -#include "libmodule.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ +#include "module.h" /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_sectname + * Name: mod_sectname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -74,8 +66,8 @@ * ****************************************************************************/ -static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *shdr) +static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *shdr) { FAR Elf32_Shdr *shstr; FAR uint8_t *buffer; @@ -93,7 +85,7 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, shstrndx = loadinfo->ehdr.e_shstrndx; if (shstrndx == SHN_UNDEF) { - bdbg("No section header string table\n"); + sdbg("No section header string table\n"); return -EINVAL; } @@ -126,7 +118,7 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, { if (loadinfo->filelen <= offset) { - bdbg("At end of file\n"); + sdbg("At end of file\n"); return -EINVAL; } @@ -136,10 +128,10 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = libmod_read(loadinfo, buffer, readlen, offset); + ret = mod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { - bdbg("Failed to read section name\n"); + sdbg("Failed to read section name\n"); return ret; } @@ -156,10 +148,10 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = libmod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); + ret = mod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); if (ret < 0) { - bdbg("libmod_reallocbuffer failed: %d\n", ret); + sdbg("mod_reallocbuffer failed: %d\n", ret); return ret; } } @@ -174,7 +166,7 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: libmod_loadshdrs + * Name: mod_loadshdrs * * Description: * Loads section headers into memory. @@ -185,7 +177,7 @@ static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) +int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) { size_t shdrsize; int ret; @@ -196,7 +188,7 @@ int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) if (loadinfo->ehdr.e_shnum < 1) { - bdbg("No sections(?)\n"); + sdbg("No sections(?)\n"); return -EINVAL; } @@ -205,7 +197,7 @@ int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) shdrsize = (size_t)loadinfo->ehdr.e_shentsize * (size_t)loadinfo->ehdr.e_shnum; if (loadinfo->ehdr.e_shoff + shdrsize > loadinfo->filelen) { - bdbg("Insufficent space in file for section header table\n"); + sdbg("Insufficent space in file for section header table\n"); return -ESPIPE; } @@ -214,25 +206,25 @@ int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) loadinfo->shdr = (FAR FAR Elf32_Shdr *)kmm_malloc(shdrsize); if (!loadinfo->shdr) { - bdbg("Failed to allocate the section header table. Size: %ld\n", + sdbg("Failed to allocate the section header table. Size: %ld\n", (long)shdrsize); return -ENOMEM; } /* Read the section header table into memory */ - ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff); if (ret < 0) { - bdbg("Failed to read section header table: %d\n", ret); + sdbg("Failed to read section header table: %d\n", ret); } return ret; } /**************************************************************************** - * Name: libmod_findsection + * Name: mod_findsection * * Description: * A section by its name. @@ -247,8 +239,8 @@ int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, - FAR const char *sectname) +int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname) { FAR const Elf32_Shdr *shdr; int ret; @@ -261,16 +253,16 @@ int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, /* Get the name of this section */ shdr = &loadinfo->shdr[i]; - ret = libmod_sectname(loadinfo, shdr); + ret = mod_sectname(loadinfo, shdr); if (ret < 0) { - bdbg("libmod_sectname failed: %d\n", ret); + sdbg("mod_sectname failed: %d\n", ret); return ret; } /* Check if the name of this section is 'sectname' */ - bvdbg("%d. Comparing \"%s\" and .\"%s\"\n", + svdbg("%d. Comparing \"%s\" and .\"%s\"\n", i, loadinfo->iobuffer, sectname); if (strcmp((FAR const char *)loadinfo->iobuffer, sectname) == 0) diff --git a/binfmt/libmodule/libmodule_symbols.c b/sched/module/mod_symbols.c similarity index 83% rename from binfmt/libmodule/libmodule_symbols.c rename to sched/module/mod_symbols.c index a9b3eb8d5c..0c60bbf981 100644 --- a/binfmt/libmodule/libmodule_symbols.c +++ b/sched/module/mod_symbols.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_symbols.c + * sched/module/mod_symbols.c * - * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,10 +45,10 @@ #include #include -#include +#include #include -#include "libmodule.h" +#include "module.h" /**************************************************************************** * Pre-processor Definitions @@ -58,16 +58,12 @@ # define CONFIG_MODULE_BUFFERINCR 32 #endif -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_symname + * Name: mod_symname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -82,8 +78,8 @@ * ****************************************************************************/ -static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, - FAR const Elf32_Sym *sym) +static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Sym *sym) { FAR uint8_t *buffer; off_t offset; @@ -97,7 +93,7 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, if (sym->st_name == 0) { - bdbg("Symbol has no name\n"); + sdbg("Symbol has no name\n"); return -ESRCH; } @@ -116,7 +112,7 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, { if (loadinfo->filelen <= offset) { - bdbg("At end of file\n"); + sdbg("At end of file\n"); return -EINVAL; } @@ -126,10 +122,10 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = libmod_read(loadinfo, buffer, readlen, offset); + ret = mod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { - bdbg("libmod_read failed: %d\n", ret); + sdbg("mod_read failed: %d\n", ret); return ret; } @@ -146,10 +142,10 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = libmod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); + ret = mod_reallocbuffer(loadinfo, CONFIG_MODULE_BUFFERINCR); if (ret < 0) { - bdbg("libmod_reallocbuffer failed: %d\n", ret); + sdbg("mod_reallocbuffer failed: %d\n", ret); return ret; } } @@ -164,7 +160,7 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: libmod_findsymtab + * Name: mod_findsymtab * * Description: * Find the symbol table section. @@ -175,7 +171,7 @@ static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo) +int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) { int i; @@ -195,7 +191,7 @@ int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo) if (loadinfo->symtabidx == 0) { - bdbg("No symbols in ELF file\n"); + sdbg("No symbols in ELF file\n"); return -EINVAL; } @@ -203,7 +199,7 @@ int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: libmod_readsym + * Name: mod_readsym * * Description: * Read the ELFT symbol structure at the specfied index into memory. @@ -219,8 +215,8 @@ int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym) +int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym) { FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; off_t offset; @@ -229,7 +225,7 @@ int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, if (index < 0 || index > (symtab->sh_size / sizeof(Elf32_Sym))) { - bdbg("Bad relocation symbol index: %d\n", index); + sdbg("Bad relocation symbol index: %d\n", index); return -EINVAL; } @@ -239,11 +235,11 @@ int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, /* And, finally, read the symbol table entry into memory */ - return libmod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); + return mod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); } /**************************************************************************** - * Name: libmod_symvalue + * Name: mod_symvalue * * Description: * Get the value of a symbol. The updated value of the symbol is returned @@ -265,8 +261,8 @@ int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports) +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports) { FAR const struct symtab_s *symbol; uintptr_t secbase; @@ -278,7 +274,7 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, { /* NuttX ELF modules should be compiled with -fno-common. */ - bdbg("SHN_COMMON: Re-compile with -fno-common\n"); + sdbg("SHN_COMMON: Re-compile with -fno-common\n"); return -ENOSYS; } @@ -286,7 +282,7 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, { /* st_value already holds the correct value */ - bvdbg("SHN_ABS: st_value=%08lx\n", (long)sym->st_value); + svdbg("SHN_ABS: st_value=%08lx\n", (long)sym->st_value); return OK; } @@ -294,7 +290,7 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, { /* Get the name of the undefined symbol */ - ret = libmod_symname(loadinfo, sym); + ret = mod_symname(loadinfo, sym); if (ret < 0) { /* There are a few relocations for a few architectures that do @@ -303,7 +299,7 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, * indicate the nameless symbol. */ - bdbg("SHN_UNDEF: Failed to get symbol name: %d\n", ret); + sdbg("SHN_UNDEF: Failed to get symbol name: %d\n", ret); return ret; } @@ -316,13 +312,13 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, #endif if (!symbol) { - bdbg("SHN_UNDEF: Exported symbol \"%s\" not found\n", loadinfo->iobuffer); + sdbg("SHN_UNDEF: Exported symbol \"%s\" not found\n", loadinfo->iobuffer); return -ENOENT; } /* Yes... add the exported symbol value to the ELF symbol table entry */ - bvdbg("SHN_ABS: name=%s %08x+%08x=%08x\n", + svdbg("SHN_ABS: name=%s %08x+%08x=%08x\n", loadinfo->iobuffer, sym->st_value, symbol->sym_value, sym->st_value + symbol->sym_value); @@ -334,7 +330,7 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, { secbase = loadinfo->shdr[sym->st_shndx].sh_addr; - bvdbg("Other: %08x+%08x=%08x\n", + svdbg("Other: %08x+%08x=%08x\n", sym->st_value, secbase, sym->st_value + secbase); sym->st_value += secbase; diff --git a/binfmt/libmodule/libmodule_uninit.c b/sched/module/mod_uninit.c similarity index 75% rename from binfmt/libmodule/libmodule_uninit.c rename to sched/module/mod_uninit.c index 13932bcc54..dcb4bfa658 100644 --- a/binfmt/libmodule/libmodule_uninit.c +++ b/sched/module/mod_uninit.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_uninit.c + * sched/module/mod_uninit.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,32 +44,20 @@ #include #include -#include +#include -#include "libmodule.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include "module.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_uninitialize + * Name: mod_uninitialize * * Description: - * Releases any resources committed by libmod_initialize(). This essentially - * undoes the actions of libmod_initialize. + * Releases any resources committed by mod_initialize(). This essentially + * undoes the actions of mod_initialize. * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -77,11 +65,11 @@ * ****************************************************************************/ -int libmod_uninitialize(struct libmod_loadinfo_s *loadinfo) +int mod_uninitialize(struct mod_loadinfo_s *loadinfo) { /* Free all working buffers */ - libmod_freebuffers(loadinfo); + mod_freebuffers(loadinfo); /* Close the ELF file */ @@ -94,7 +82,7 @@ int libmod_uninitialize(struct libmod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: libmod_freebuffers + * Name: mod_freebuffers * * Description: * Release all working buffers. @@ -105,7 +93,7 @@ int libmod_uninitialize(struct libmod_loadinfo_s *loadinfo) * ****************************************************************************/ -int libmod_freebuffers(struct libmod_loadinfo_s *loadinfo) +int mod_freebuffers(struct mod_loadinfo_s *loadinfo) { /* Release all working allocations */ diff --git a/binfmt/libmodule/libmodule_unload.c b/sched/module/mod_unload.c similarity index 77% rename from binfmt/libmodule/libmodule_unload.c rename to sched/module/mod_unload.c index e524dbe197..f44e3f4da1 100644 --- a/binfmt/libmodule/libmodule_unload.c +++ b/sched/module/mod_unload.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_unload.c + * sched/module/mod_unload.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,32 +43,20 @@ #include #include -#include +#include -#include "libmodule.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include "module.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_unload + * Name: mod_unload * * Description: * This function unloads the object from memory. This essentially undoes - * the actions of libmod_load. It is called only under certain error + * the actions of mod_load. It is called only under certain error * conditions after the module has been loaded but not yet started. * * Returned Value: @@ -77,11 +65,11 @@ * ****************************************************************************/ -int libmod_unload(struct libmod_loadinfo_s *loadinfo) +int mod_unload(struct mod_loadinfo_s *loadinfo) { /* Free all working buffers */ - libmod_freebuffers(loadinfo); + mod_freebuffers(loadinfo); /* Release memory holding the relocated ELF image */ @@ -99,4 +87,3 @@ int libmod_unload(struct libmod_loadinfo_s *loadinfo) return OK; } - diff --git a/binfmt/libmodule/libmodule_verify.c b/sched/module/mod_verify.c similarity index 82% rename from binfmt/libmodule/libmodule_verify.c rename to sched/module/mod_verify.c index 82ab35ae4d..a46d96f73d 100644 --- a/binfmt/libmodule/libmodule_verify.c +++ b/sched/module/mod_verify.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/libmodule/libmodule_verify.c + * sched/module/mod_verify.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,11 +43,7 @@ #include #include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +#include /**************************************************************************** * Private Constant Data @@ -58,16 +54,12 @@ static const char g_modmagic[EI_MAGIC_SIZE] = 0x7f, 'E', 'L', 'F' }; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: libmod_verifyheader + * Name: mod_verifyheader * * Description: * Given the header from a possible ELF executable, verify that it @@ -83,11 +75,11 @@ static const char g_modmagic[EI_MAGIC_SIZE] = * ****************************************************************************/ -int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) +int mod_verifyheader(FAR const Elf32_Ehdr *ehdr) { if (!ehdr) { - bdbg("NULL ELF header!"); + sdbg("NULL ELF header!"); return -ENOEXEC; } @@ -95,7 +87,7 @@ int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) if (memcmp(ehdr->e_ident, g_modmagic, EI_MAGIC_SIZE) != 0) { - bvdbg("Not ELF magic {%02x, %02x, %02x, %02x}\n", + svdbg("Not ELF magic {%02x, %02x, %02x, %02x}\n", ehdr->e_ident[0], ehdr->e_ident[1], ehdr->e_ident[2], ehdr->e_ident[3]); return -ENOEXEC; } @@ -104,7 +96,7 @@ int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) if (ehdr->e_type != ET_REL) { - bdbg("Not a relocatable file: e_type=%d\n", ehdr->e_type); + sdbg("Not a relocatable file: e_type=%d\n", ehdr->e_type); return -EINVAL; } @@ -112,7 +104,7 @@ int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) if (up_checkarch(ehdr)) { - bdbg("Not a supported architecture\n"); + sdbg("Not a supported architecture\n"); return -ENOEXEC; } @@ -120,4 +112,3 @@ int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr) return OK; } - diff --git a/binfmt/libmodule/libmodule.h b/sched/module/module.h similarity index 82% rename from binfmt/libmodule/libmodule.h rename to sched/module/module.h index 427e5b13aa..7f96df366d 100644 --- a/binfmt/libmodule/libmodule.h +++ b/sched/module/module.h @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/libmodule.h + * sched/module/module.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __BINFMT_LIBELF_LIBELF_H -#define __BINFMT_LIBELF_LIBELF_H +#ifndef __SCHED_MODULE_MODULE_H +#define __SCHED_MODULE_MODULE_H /**************************************************************************** * Included Files @@ -46,7 +46,7 @@ #include #include -#include +#include /**************************************************************************** * Public Types @@ -56,7 +56,7 @@ * of the kernel module. */ -struct libmod_loadinfo_s +struct mod_loadinfo_s { /* elfalloc is the base address of the memory that is allocated to hold the * module image. @@ -85,11 +85,7 @@ struct libmod_loadinfo_s ****************************************************************************/ /**************************************************************************** - * These are APIs exported by libmodule and used by insmod - ****************************************************************************/ - -/**************************************************************************** - * Name: libmod_initialize + * Name: mod_initialize * * Description: * This function is called to configure the library to process an kernel @@ -101,15 +97,15 @@ struct libmod_loadinfo_s * ****************************************************************************/ -int libmod_initialize(FAR const char *filename, - FAR struct libmod_loadinfo_s *loadinfo); +int mod_initialize(FAR const char *filename, + FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_uninitialize + * Name: mod_uninitialize * * Description: * Releases any resources committed by mod_init(). This essentially - * undoes the actions of libmod_initialize. + * undoes the actions of mod_initialize. * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -117,10 +113,10 @@ int libmod_initialize(FAR const char *filename, * ****************************************************************************/ -int libmod_uninitialize(FAR struct libmod_loadinfo_s *loadinfo); +int mod_uninitialize(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_load + * Name: mod_load * * Description: * Loads the binary into memory, allocating memory, performing relocations @@ -132,10 +128,10 @@ int libmod_uninitialize(FAR struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_load(FAR struct libmod_loadinfo_s *loadinfo); +int mod_load(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_bind + * Name: mod_bind * * Description: * Bind the imported symbol names in the loaded module described by @@ -148,11 +144,11 @@ int libmod_load(FAR struct libmod_loadinfo_s *loadinfo); ****************************************************************************/ struct symtab_s; -int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports); +int mod_bind(FAR struct mod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports); /**************************************************************************** - * Name: libmod_unload + * Name: mod_unload * * Description: * This function unloads the object from memory. This essentially undoes @@ -165,10 +161,10 @@ int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -int libmod_unload(struct libmod_loadinfo_s *loadinfo); +int mod_unload(struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_verifyheader + * Name: mod_verifyheader * * Description: * Given the header from a possible ELF executable, verify that it is @@ -180,10 +176,10 @@ int libmod_unload(struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_verifyheader(FAR const Elf32_Ehdr *header); +int mod_verifyheader(FAR const Elf32_Ehdr *header); /**************************************************************************** - * Name: libmod_read + * Name: mod_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -195,11 +191,11 @@ int libmod_verifyheader(FAR const Elf32_Ehdr *header); * ****************************************************************************/ -int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset); +int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset); /**************************************************************************** - * Name: libmod_loadshdrs + * Name: mod_loadshdrs * * Description: * Loads section headers into memory. @@ -210,10 +206,10 @@ int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, * ****************************************************************************/ -int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo); +int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_findsection + * Name: mod_findsection * * Description: * A section by its name. @@ -228,11 +224,11 @@ int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, - FAR const char *sectname); +int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname); /**************************************************************************** - * Name: libmod_findsymtab + * Name: mod_findsymtab * * Description: * Find the symbol table section. @@ -243,10 +239,10 @@ int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, * ****************************************************************************/ -int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo); +int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_readsym + * Name: mod_readsym * * Description: * Read the ELFT symbol structure at the specfied index into memory. @@ -262,11 +258,11 @@ int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym); +int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym); /**************************************************************************** - * Name: libmod_symvalue + * Name: mod_symvalue * * Description: * Get the value of a symbol. The updated value of the symbol is returned @@ -290,11 +286,11 @@ int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports); +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports); /**************************************************************************** - * Name: libmod_freebuffers + * Name: mod_freebuffers * * Description: * Release all working buffers. @@ -305,10 +301,10 @@ int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, * ****************************************************************************/ -int libmod_freebuffers(FAR struct libmod_loadinfo_s *loadinfo); +int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_allocbuffer + * Name: mod_allocbuffer * * Description: * Perform the initial allocation of the I/O buffer, if it has not already @@ -320,10 +316,10 @@ int libmod_freebuffers(FAR struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo); +int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: libmod_reallocbuffer + * Name: mod_reallocbuffer * * Description: * Increase the size of I/O buffer by the specified buffer increment. @@ -334,6 +330,6 @@ int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo); * ****************************************************************************/ -int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment); +int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); -#endif /* __BINFMT_LIBELF_LIBELF_H */ +#endif /* __SCHED_MODULE_MODULE_H */ -- GitLab From 0efcb5445b43436a089545dabd39d93b43b5df83 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 09:38:06 -0600 Subject: [PATCH 442/858] Fix compile error when cache coherency logic is enabled --- arch | 2 +- configs | 2 +- sched/module/mod_bind.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index ca979759a7..fb81d9d623 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ca979759a701c3c5e7acb8fc8c604ee112c45601 +Subproject commit fb81d9d623c311e42128cfb026077db89bdec182 diff --git a/configs b/configs index a619d39802..7a90dc6162 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a619d398029baac7d2246f9beaa0b3c6fe9b1d2c +Subproject commit 7a90dc61627c97dc6e6b4cfd252288a91a821a09 diff --git a/sched/module/mod_bind.c b/sched/module/mod_bind.c index 18e48c8541..2fa71779ed 100644 --- a/sched/module/mod_bind.c +++ b/sched/module/mod_bind.c @@ -316,7 +316,7 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo, */ up_coherent_dcache(loadinfo->textalloc, loadinfo->textsize); - up_coherent_dcache(loadinfo->dataalloc, loadinfo->datasize); + up_coherent_dcache(loadinfo->datastart, loadinfo->datasize); #endif -- GitLab From 658a2a627586a915c8de1f17ffd091f7f21439ec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 09:41:47 -0600 Subject: [PATCH 443/858] Update ChangeLog --- ChangeLog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 96a49dff89..509efaf51e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11233,6 +11233,8 @@ that of the type of a pthread. Hence, it could be confused as a task. Same problem as fixed on 2015-11-29, but in different location (2015-12-09). - * binfmt/libmodule: Add support for kernel modules. Initial commit is + * sched/module: Add support for kernel modules. Initial commit is just the ELF module support with name changes (2015-12-10). + * configs/samv71-xult/module: Add configuration for testing OS + modules (2015-12-12). -- GitLab From 040835de00ab16b1a23594d8e4b6b2438d0ff018 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 10:51:54 -0600 Subject: [PATCH 444/858] Add an implementation of rmmod --- ChangeLog | 1 + include/nuttx/module.h | 45 ++++++++++++++--- sched/module/Make.defs | 2 +- sched/module/mod_insmod.c | 25 +++++----- sched/module/mod_rmmod.c | 100 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 23 deletions(-) create mode 100644 sched/module/mod_rmmod.c diff --git a/ChangeLog b/ChangeLog index 509efaf51e..b79a3add18 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11237,4 +11237,5 @@ just the ELF module support with name changes (2015-12-10). * configs/samv71-xult/module: Add configuration for testing OS modules (2015-12-12). + * sched/module: Add an implementation of rmmod() (2015-11-12). diff --git a/include/nuttx/module.h b/include/nuttx/module.h index 3e4c028a30..e08c92e592 100644 --- a/include/nuttx/module.h +++ b/include/nuttx/module.h @@ -76,25 +76,43 @@ * Public Types ****************************************************************************/ +/* This is the type of the function that is called to uninitialize the + * the loaded module. This may mean, for example, un-registering a device + * driver. If the module is successfully initialized, its memory will be + * deallocated. + * + * Input Parameters: + * arg - An opaque argument that was previously returned by the initializer + * function. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on any failure to + * initialize the module. If zero is returned, then the module memory + * will be deallocated. If the module is still in use (for example with + * open driver instances), the uninitialization function should fail with + * -EBUSY + */ + +typedef CODE int (*mod_uninitializer_t)(FAR void *arg); + /* A NuttX module is expected to export a function called module_initialize() * that has the following function prototype. This function should appear as * the entry point in the ELF module file and will be called bythe binfmt * logic after the module has been loaded into kernel memory. * - * As an alternative using GCC, the module may mark a function with the - * "constructor" attribute and the module initializer will be called along - * with any other C++ constructors. The "destructor" attribute may also - * be used to mark an module uninitialization function. - * * Input Parameters: - * None + * uninitializer - The pointer to the uninitialization function. NULL may + * be returned if no uninitialization is needed (i.e, the the module + * memory can be deallocated at any time). + * arg - An argument that will be passed to the uninitialization function. * * Returned Value: * Zero (OK) on success; a negated errno value on any failure to * initialize the module. */ -typedef CODE int (*mod_initializer_t)(void); +typedef CODE int (*mod_initializer_t)(mod_uninitializer_t *uninitializer, + FAR void **arg); /* This describes the file to be loaded. */ @@ -111,7 +129,8 @@ struct module_s * resources used by the loaded module. */ - mod_initializer_t initializer; /* Module initializer function */ + mod_uninitializer_t uninitializer; /* Module initializer function */ + FAR void *arg; /* Uninitializer argument */ FAR void *alloc; /* Allocated kernel memory */ }; @@ -139,6 +158,16 @@ extern "C" int insmod(FAR struct module_s *modp); +/**************************************************************************** + * Name: rmmod + * + * Description: + * Remove a previously installed module from memory. + * + ****************************************************************************/ + +int rmmod(FAR struct module_s *modp); + #undef EXTERN #if defined(__cplusplus) } diff --git a/sched/module/Make.defs b/sched/module/Make.defs index 9a0bee5498..fbe5fffca6 100644 --- a/sched/module/Make.defs +++ b/sched/module/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_MODULE),y) # OS module interfaces -CSRCS += mod_insmod.c +CSRCS += mod_insmod.c mod_rmmod.c # loadable module library diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index f06961811f..e27cfe3848 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/module/module.c + * sched/module/mod_insmod.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -46,8 +46,6 @@ #include #include -#include - #include #include @@ -172,8 +170,10 @@ static void mod_dumpinitializer(mod_initializer_t initializer, int insmod(FAR struct module_s *modp) { struct mod_loadinfo_s loadinfo; + mod_initializer_t initializer; int ret; + DEBUGASSERT(modp != NULL && modp->filename != NULL); bvdbg("Loading file: %s\n", modp->filename); /* Initialize the ELF library to load the program binary. */ @@ -207,23 +207,20 @@ int insmod(FAR struct module_s *modp) /* Return the load information */ - modp->initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); modp->alloc = (FAR void *)loadinfo.textalloc; /* Get the module initializer entry point */ - if (modp->initializer) - { - mod_dumpinitializer(modp->initializer, &loadinfo); + initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); + mod_dumpinitializer(initializer, &loadinfo); - /* Call the module initializer */ + /* Call the module initializer */ - ret = modp->initializer(); - if (ret < 0) - { - bdbg("Failed to initialize the module: %d\n", ret); - goto errout_with_load; - } + ret = initializer(&modp->uninitializer, &modp->arg); + if (ret < 0) + { + bdbg("Failed to initialize the module: %d\n", ret); + goto errout_with_load; } mod_uninitialize(&loadinfo); diff --git a/sched/module/mod_rmmod.c b/sched/module/mod_rmmod.c new file mode 100644 index 0000000000..6918b3fde6 --- /dev/null +++ b/sched/module/mod_rmmod.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * sched/module/module.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "module/module.h" + +#ifdef CONFIG_MODULE + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rmmod + * + * Description: + * Remove a previously installed module from memory. + * + ****************************************************************************/ + +int rmmod(FAR struct module_s *modp) +{ + int ret = OK; + + DEBUGASSERT(modp != NULL); + + /* Is there an uninitializer? */ + + if (modp->uninitializer != NULL) + { + /* Try to uninitializer the module */ + + ret = modp->uninitializer(modp->arg); + + /* Did the module sucessfully uninitialize? */ + + if (ret < 0) + { + sdbg("ERROR: Failed to uninitialize the module: %d\n", ret); + return ret; + } + } + + /* Free the module memory */ + + /* Release memory holding the relocated ELF image */ + + if (modp->alloc != 0) + { + kmm_free((FAR void *)modp->alloc); + } + + return ret; +} + +#endif /* CONFIG_MODULE */ -- GitLab From 303123deb9c142a3e3332f4b2a6a174496d768f0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 11:11:09 -0600 Subject: [PATCH 445/858] Add syscall support for insmod and rmmod --- include/sys/syscall.h | 18 +++++++++++++++--- sched/module/mod_rmmod.c | 15 ++++++++++++--- syscall/syscall.csv | 2 ++ syscall/syscall_lookup.h | 9 +++++++++ syscall/syscall_stublookup.c | 9 +++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 835f40e085..c7d9b086c4 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -152,12 +152,24 @@ # ifdef CONFIG_SCHED_HAVE_PARENT # define SYS_wait (__SYS_waitpid+1) # define SYS_waitid (__SYS_waitpid+2) -# define __SYS_posix_spawn (__SYS_waitpid+3) +# define __SYS_insmod (__SYS_waitpid+3) # else -# define __SYS_posix_spawn (__SYS_waitpid+1) +# define __SYS_insmod (__SYS_waitpid+1) #endif #else -# define __SYS_posix_spawn __SYS_waitpid +# define __SYS_insmod __SYS_waitpid +#endif + +/* The following can only be defined if we are configured to load + * OS modules from a file system. + */ + +#ifdef CONFIG_MODULE +# define SYS_insmod __SYS_insmod +# define SYS_rmmod (__SYS_insmod+1) +# define __SYS_posix_spawn (__SYS_insmod+2) +#else +# define __SYS_posix_spawn __SYS_insmod #endif /* The following can only be defined if we are configured to execute diff --git a/sched/module/mod_rmmod.c b/sched/module/mod_rmmod.c index 6918b3fde6..339ef808a3 100644 --- a/sched/module/mod_rmmod.c +++ b/sched/module/mod_rmmod.c @@ -83,15 +83,24 @@ int rmmod(FAR struct module_s *modp) sdbg("ERROR: Failed to uninitialize the module: %d\n", ret); return ret; } - } - /* Free the module memory */ + /* Nullify so that the uninitializer cannot be called again */ + + modp->uninitializer = NULL; + modp->arg = NULL; + } - /* Release memory holding the relocated ELF image */ + /* Release resources held by the module */ if (modp->alloc != 0) { + /* Free the module memory */ + kmm_free((FAR void *)modp->alloc); + + /* Nullify so that the memory cannot be freed again */ + + modp->alloc = NULL; } return ret; diff --git a/syscall/syscall.csv b/syscall/syscall.csv index f9ea9285a6..50ebab9612 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -28,6 +28,7 @@ "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char*","FAR const char*" "getpid","unistd.h","","pid_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" +"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR struct module_s *" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" @@ -97,6 +98,7 @@ "rename","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","FAR const char*" "rewinddir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","void","FAR DIR*" "rmdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*" +"rmmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR struct module_s *" "sched_getparam","sched.h","","int","pid_t","struct sched_param*" "sched_getscheduler","sched.h","","int","pid_t" "sched_getstreams","nuttx/sched.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR struct streamlist*" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index db52304592..62ccbd2d5f 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -106,6 +106,15 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) # endif #endif +/* The following can only be defined if we are configured to load + * OS modules from a file system. + */ + +#ifdef CONFIG_MODULE + SYSCALL_LOOKUP(insmod, 1, STUB_insmod) + SYSCALL_LOOKUP(rmmod, 1, STUB_rmmod) +#endif + /* The following can only be defined if we are configured to execute * programs from a file system. */ diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 9991192feb..e23e801f19 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -107,6 +107,15 @@ uintptr_t STUB_wait(int nbr, uintptr_t parm1); uintptr_t STUB_waitid(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4); +/* The following can only be defined if we are configured to load + * OS modules from a file system. + */ + +#ifdef CONFIG_MODULE +uintptr_t STUB_insmod(int nbr, uintptr_t parm1); +uintptr_t STUB_rmmod(int nbr, uintptr_t parm1); +#endif + /* The following can only be defined if we are configured to execute * programs from a file system. */ -- GitLab From a908a61c5a582fc4e5f9903967b201f4069d0210 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 12:55:50 -0600 Subject: [PATCH 446/858] Various module-related cosmetic changes --- arch | 2 +- configs | 2 +- include/nuttx/module.h | 2 +- sched/module/mod_bind.c | 22 ---------------------- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/arch b/arch index fb81d9d623..982356fab5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fb81d9d623c311e42128cfb026077db89bdec182 +Subproject commit 982356fab5364d3f70f54483394cec9cfe9b9199 diff --git a/configs b/configs index 7a90dc6162..050dca048e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7a90dc61627c97dc6e6b4cfd252288a91a821a09 +Subproject commit 050dca048e92cec8f8d04075553d75025a31f2d4 diff --git a/include/nuttx/module.h b/include/nuttx/module.h index e08c92e592..be8859ec63 100644 --- a/include/nuttx/module.h +++ b/include/nuttx/module.h @@ -129,7 +129,7 @@ struct module_s * resources used by the loaded module. */ - mod_uninitializer_t uninitializer; /* Module initializer function */ + mod_uninitializer_t uninitializer; /* Module uninitializer function */ FAR void *arg; /* Uninitializer argument */ FAR void *alloc; /* Allocated kernel memory */ }; diff --git a/sched/module/mod_bind.c b/sched/module/mod_bind.c index 2fa71779ed..a2979664b7 100644 --- a/sched/module/mod_bind.c +++ b/sched/module/mod_bind.c @@ -51,28 +51,6 @@ #include "module.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_MODULE_DUMPBUFFER have to - * be defined or CONFIG_MODULE_DUMPBUFFER does nothing. - */ - -#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_MODULE_DUMPBUFFER) -# undef CONFIG_MODULE_DUMPBUFFER -#endif - -#ifndef CONFIG_MODULE_BUFFERSIZE -# define CONFIG_MODULE_BUFFERSIZE 128 -#endif - -#ifdef CONFIG_MODULE_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) svdbgdumpbuffer(m,b,n) -#else -# define mod_dumpbuffer(m,b,n) -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ -- GitLab From 795ddd7e80183ba903eddbe4e933fbf4d981e1aa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 17:42:25 -0600 Subject: [PATCH 447/858] OS modules: Add basic procfs support. A module registry that will eventually be used to support lsmod --- ChangeLog | 5 +- configs | 2 +- fs/procfs/Kconfig | 7 + fs/procfs/fs_procfs.c | 5 + include/nuttx/module.h | 81 ++++++--- net/procfs/procfs.h | 4 - sched/module/Make.defs | 12 +- sched/module/mod_insmod.c | 153 +++++++++++------ sched/module/mod_procfs.c | 320 +++++++++++++++++++++++++++++++++++ sched/module/mod_registry.c | 247 +++++++++++++++++++++++++++ sched/module/mod_rmmod.c | 55 +++++- sched/module/module.h | 104 ++++++++++++ syscall/syscall.csv | 4 +- syscall/syscall_lookup.h | 2 +- syscall/syscall_stublookup.c | 3 +- 15 files changed, 911 insertions(+), 93 deletions(-) create mode 100644 sched/module/mod_procfs.c create mode 100644 sched/module/mod_registry.c diff --git a/ChangeLog b/ChangeLog index b79a3add18..2595cd0f84 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11237,5 +11237,6 @@ just the ELF module support with name changes (2015-12-10). * configs/samv71-xult/module: Add configuration for testing OS modules (2015-12-12). - * sched/module: Add an implementation of rmmod() (2015-11-12). - + * sched/module: Add an implementation of rmmod() (2015-12-12). + * sched/module and fs/procfs: Add some basic module procfs support + (2015-12-12), diff --git a/configs b/configs index 050dca048e..4a56b7ba64 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 050dca048e92cec8f8d04075553d75025a31f2d4 +Subproject commit 4a56b7ba643607bbfadaef3628a7322b642ffa3f diff --git a/fs/procfs/Kconfig b/fs/procfs/Kconfig index 39d5011842..7f3620f9c8 100644 --- a/fs/procfs/Kconfig +++ b/fs/procfs/Kconfig @@ -32,6 +32,13 @@ config FS_PROCFS_EXCLUDE_PROCESS This will reduce code space, but then giving access to process info was kinda the whole point of procfs, but hey, whatever. +config FS_PROCFS_EXCLUDE_MODULE + bool "Exclude module information" + depends on MODULE + default n + ---help--- + Causes the module information to be excluded from the procfs system. + config FS_PROCFS_EXCLUDE_UPTIME bool "Exclude uptime" default n diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index c9032560e6..8da8842fb4 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -77,6 +77,7 @@ extern const struct procfs_operations proc_operations; extern const struct procfs_operations cpuload_operations; +extern const struct procfs_operations module_operations; extern const struct procfs_operations uptime_operations; /* This is not good. These are implemented in other sub-systems. Having to @@ -119,6 +120,10 @@ static const struct procfs_entry_s g_procfs_entries[] = { "cpuload", &cpuload_operations }, #endif +#if defined(CONFIG_MODULE) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + { "modules", &module_operations }, +#endif + #if defined(CONFIG_FS_SMARTFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS) //{ "fs/smartfs", &smartfs_procfsoperations }, { "fs/smartfs**", &smartfs_procfsoperations }, diff --git a/include/nuttx/module.h b/include/nuttx/module.h index be8859ec63..8b9c2cfc8e 100644 --- a/include/nuttx/module.h +++ b/include/nuttx/module.h @@ -60,10 +60,6 @@ # define CONFIG_MODULE_ALIGN_LOG2 2 #endif -#ifndef CONFIG_MODULE_STACKSIZE -# define CONFIG_MODULE_STACKSIZE 2048 -#endif - #ifndef CONFIG_MODULE_BUFFERSIZE # define CONFIG_MODULE_BUFFERSIZE 128 #endif @@ -72,6 +68,8 @@ # define CONFIG_MODULE_BUFFERINCR 32 #endif +#define MODULENAME_MAX 16 + /**************************************************************************** * Public Types ****************************************************************************/ @@ -114,25 +112,12 @@ typedef CODE int (*mod_uninitializer_t)(FAR void *arg); typedef CODE int (*mod_initializer_t)(mod_uninitializer_t *uninitializer, FAR void **arg); -/* This describes the file to be loaded. */ - -struct symtab_s; -struct module_s -{ - /* Information provided to insmod by the caller */ - - FAR const char *filename; /* Full path to the binary to be loaded */ - FAR const struct symtab_s *exports; /* Table of exported symbols */ - int nexports; /* The number of symbols in exports[] */ +#ifdef __KERNEL__ +/* This is the type of the callback function used by mod_registry_foreach() */ - /* Information provided from insmod (if successful) describing the - * resources used by the loaded module. - */ - - mod_uninitializer_t uninitializer; /* Module uninitializer function */ - FAR void *arg; /* Uninitializer argument */ - FAR void *alloc; /* Allocated kernel memory */ -}; +struct module_s; +typedef CODE int (*mod_callback_t)(FAR struct module_s *modp, FAR void *arg); +#endif /**************************************************************************** * Public Function Prototypes @@ -154,9 +139,22 @@ extern "C" * Verify that the file is an ELF module binary and, if so, load the * module into kernel memory and initialize it for use. * + * Input Parameters: + * + * filename - Full path to the module binary to be loaded + * modulename - The name that can be used to refer to the module after + * it has been loaded. + * exports - Table of exported symbols + * nexports - The number of symbols in exports[] + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * ****************************************************************************/ -int insmod(FAR struct module_s *modp); +int insmod(FAR const char *filename, FAR const char *modulename, + FAR const struct symtab_s *exports, int nexports); /**************************************************************************** * Name: rmmod @@ -164,9 +162,44 @@ int insmod(FAR struct module_s *modp); * Description: * Remove a previously installed module from memory. * + * Input Parameters: + * + * modulename - The module name. This is the name module name that was + * provided to insmod when the module was loaded. + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * ****************************************************************************/ -int rmmod(FAR struct module_s *modp); +int rmmod(FAR const char *modulename); + +/**************************************************************************** + * Name: mod_registry_foreach + * + * Description: + * Visit each module in the registry. This is an internal OS interface and + * not available for use by applications. + * + * Input Parameters: + * callback - This callback function was be called for each entry in the + * registry. + * arg - This opaque argument will be passed to the callback function. + * + * Returned Value: + * This function normally returns zero (OK). If, however, any callback + * function returns a non-zero value, the traversal will be terminated and + * that non-zero value will be returned. + * + * Assumptions: + * The caller does NOT hold the lock on the module registry. + * + ****************************************************************************/ + +#ifdef __KERNEL__ +int mod_registry_foreach(mod_callback_t callback, FAR void *arg); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/net/procfs/procfs.h b/net/procfs/procfs.h index feba657a0d..889f350725 100644 --- a/net/procfs/procfs.h +++ b/net/procfs/procfs.h @@ -60,10 +60,6 @@ * Public Type Definitions ****************************************************************************/ -/* This enumeration identifies all of the thread attributes that can be - * accessed via the procfs file system. - */ - /* This structure describes one open "file" */ struct net_driver_s; /* Forward reference */ diff --git a/sched/module/Make.defs b/sched/module/Make.defs index fbe5fffca6..ec60760c8a 100644 --- a/sched/module/Make.defs +++ b/sched/module/Make.defs @@ -42,8 +42,16 @@ CSRCS += mod_insmod.c mod_rmmod.c # loadable module library CSRCS += mod_bind.c mod_init.c mod_iobuffer.c mod_load.c mod_read.c -CSRCS += mod_sections.c mod_symbols.c mod_uninit.c mod_unload.c -CSRCS += mod_verify.c +CSRCS += mod_registry.c mod_sections.c mod_symbols.c mod_uninit.c +CSRCS += mod_unload.c mod_verify.c + +# procfs support + +ifeq ($(CONFIG_FS_PROCFS),y) +ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_MODULE),y) +CSRCS += mod_procfs.c +endif +endif # Hook the module subdirectory into the build diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index e27cfe3848..82c3e591dc 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -47,6 +47,7 @@ #include #include +#include #include #include "module/module.h" @@ -66,7 +67,7 @@ #endif #ifdef CONFIG_MODULE_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) +# define mod_dumpbuffer(m,b,n) svdbgdumpbuffer(m,b,n) #else # define mod_dumpbuffer(m,b,n) #endif @@ -88,50 +89,50 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) { int i; - bdbg("LOAD_INFO:\n"); - bdbg(" textalloc: %08lx\n", (long)loadinfo->textalloc); - bdbg(" datastart: %08lx\n", (long)loadinfo->datastart); - bdbg(" textsize: %ld\n", (long)loadinfo->textsize); - bdbg(" datasize: %ld\n", (long)loadinfo->datasize); - bdbg(" filelen: %ld\n", (long)loadinfo->filelen); - bdbg(" filfd: %d\n", loadinfo->filfd); - bdbg(" symtabidx: %d\n", loadinfo->symtabidx); - bdbg(" strtabidx: %d\n", loadinfo->strtabidx); - - bdbg("ELF Header:\n"); - bdbg(" e_ident: %02x %02x %02x %02x\n", + sdbg("LOAD_INFO:\n"); + sdbg(" textalloc: %08lx\n", (long)loadinfo->textalloc); + sdbg(" datastart: %08lx\n", (long)loadinfo->datastart); + sdbg(" textsize: %ld\n", (long)loadinfo->textsize); + sdbg(" datasize: %ld\n", (long)loadinfo->datasize); + sdbg(" filelen: %ld\n", (long)loadinfo->filelen); + sdbg(" filfd: %d\n", loadinfo->filfd); + sdbg(" symtabidx: %d\n", loadinfo->symtabidx); + sdbg(" strtabidx: %d\n", loadinfo->strtabidx); + + sdbg("ELF Header:\n"); + sdbg(" e_ident: %02x %02x %02x %02x\n", loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1], loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]); - bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type); - bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine); - bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version); - bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); - bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); - bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); - bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); - bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); - bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); - bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); - bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); - bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); - bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); + sdbg(" e_type: %04x\n", loadinfo->ehdr.e_type); + sdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine); + sdbg(" e_version: %08x\n", loadinfo->ehdr.e_version); + sdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); + sdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); + sdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); + sdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); + sdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); + sdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); + sdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); + sdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); + sdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); + sdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0) { for (i = 0; i < loadinfo->ehdr.e_shnum; i++) { FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; - bdbg("Sections %d:\n", i); - bdbg(" sh_name: %08x\n", shdr->sh_name); - bdbg(" sh_type: %08x\n", shdr->sh_type); - bdbg(" sh_flags: %08x\n", shdr->sh_flags); - bdbg(" sh_addr: %08x\n", shdr->sh_addr); - bdbg(" sh_offset: %d\n", shdr->sh_offset); - bdbg(" sh_size: %d\n", shdr->sh_size); - bdbg(" sh_link: %d\n", shdr->sh_link); - bdbg(" sh_info: %d\n", shdr->sh_info); - bdbg(" sh_addralign: %d\n", shdr->sh_addralign); - bdbg(" sh_entsize: %d\n", shdr->sh_entsize); + sdbg("Sections %d:\n", i); + sdbg(" sh_name: %08x\n", shdr->sh_name); + sdbg(" sh_type: %08x\n", shdr->sh_type); + sdbg(" sh_flags: %08x\n", shdr->sh_flags); + sdbg(" sh_addr: %08x\n", shdr->sh_addr); + sdbg(" sh_offset: %d\n", shdr->sh_offset); + sdbg(" sh_size: %d\n", shdr->sh_size); + sdbg(" sh_link: %d\n", shdr->sh_link); + sdbg(" sh_info: %d\n", shdr->sh_info); + sdbg(" sh_addralign: %d\n", shdr->sh_addralign); + sdbg(" sh_entsize: %d\n", shdr->sh_entsize); } } } @@ -165,49 +166,90 @@ static void mod_dumpinitializer(mod_initializer_t initializer, * Verify that the file is an ELF module binary and, if so, load the * module into kernel memory and initialize it for use. * + * Input Parameters: + * + * filename - Full path to the module binary to be loaded + * modulename - The name that can be used to refer to the module after + * it has been loaded. + * exports - Table of exported symbols + * nexports - The number of symbols in exports[] + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * ****************************************************************************/ -int insmod(FAR struct module_s *modp) +int insmod(FAR const char *filename, FAR const char *modulename, + FAR const struct symtab_s *exports, int nexports) { struct mod_loadinfo_s loadinfo; + FAR struct module_s *modp; mod_initializer_t initializer; int ret; - DEBUGASSERT(modp != NULL && modp->filename != NULL); - bvdbg("Loading file: %s\n", modp->filename); + DEBUGASSERT(filename != NULL && modulename != NULL); + svdbg("Loading file: %s\n", filename); + + /* Get exclusive access to the module registry */ + + mod_registry_lock(); + + /* Check if this module is already installed */ + + if (mod_registry_find(modulename) != NULL) + { + mod_registry_unlock(); + ret = -EEXIST; + goto errout_with_lock; + } /* Initialize the ELF library to load the program binary. */ - ret = mod_initialize(modp->filename, &loadinfo); + ret = mod_initialize(filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { - bdbg("Failed to initialize for load of ELF program: %d\n", ret); - goto errout; + sdbg("ERROR: Failed to initialize to load module: %d\n", ret); + goto errout_with_lock; } + /* Allocate a module registry entry to hold the module data */ + + modp = (FAR struct module_s *)kmm_zalloc(sizeof(struct module_s)); + if (ret != 0) + { + sdbg("Failed to initialize for load of ELF program: %d\n", ret); + goto errout_with_loadinfo; + } + + /* Save the module name in the registry entry */ + + strncpy(modp->modulename, modulename, MODULENAME_MAX); + /* Load the program binary */ ret = mod_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { - bdbg("Failed to load ELF program binary: %d\n", ret); - goto errout_with_init; + sdbg("Failed to load ELF program binary: %d\n", ret); + goto errout_with_registry_entry; } /* Bind the program to the exported symbol table */ - ret = mod_bind(&loadinfo, modp->exports, modp->nexports); + ret = mod_bind(&loadinfo, exports, nexports); if (ret != 0) { - bdbg("Failed to bind symbols program binary: %d\n", ret); + sdbg("Failed to bind symbols program binary: %d\n", ret); goto errout_with_load; } /* Return the load information */ modp->alloc = (FAR void *)loadinfo.textalloc; + modp->size = loadinfo.textsize + loadinfo.datasize; /* Get the module initializer entry point */ @@ -219,19 +261,28 @@ int insmod(FAR struct module_s *modp) ret = initializer(&modp->uninitializer, &modp->arg); if (ret < 0) { - bdbg("Failed to initialize the module: %d\n", ret); + sdbg("Failed to initialize the module: %d\n", ret); goto errout_with_load; } + /* Add the new module entry to the registry */ + + mod_registry_add(modp); + mod_uninitialize(&loadinfo); + mod_registry_unlock(); return OK; errout_with_load: mod_unload(&loadinfo); -errout_with_init: +errout_with_registry_entry: + kmm_free(modp); +errout_with_loadinfo: mod_uninitialize(&loadinfo); -errout: - return ret; +errout_with_lock: + mod_registry_unlock(); + set_errno(-ret); + return ERROR; } #endif /* CONFIG_MODULE */ diff --git a/sched/module/mod_procfs.c b/sched/module/mod_procfs.c new file mode 100644 index 0000000000..dca2db91b5 --- /dev/null +++ b/sched/module/mod_procfs.c @@ -0,0 +1,320 @@ +/**************************************************************************** + * sched/module/mod_procfs.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "module.h" + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Determines the size of an intermediate buffer that must be large enough + * to handle the longest line generated by this logic. + */ + +#define MOD_LINELEN 64 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure describes one open "file" */ + +struct modprocfs_file_s +{ + struct procfs_file_s base; /* Base open file structure */ + + /* Read helpers */ + + FAR char *buffer; /* User buffer pointer */ + size_t buflen; /* Size of the user buffer */ + size_t remaining; /* Space remaining in user buffer */ + size_t totalsize; /* Total size returned by read() */ + off_t offset; /* Offset skip on output */ + + /* Line buffer */ + + uint8_t lineno; /* Line number */ + uint8_t linesize; /* Number of valid characters in line[] */ + char line[MOD_LINELEN]; /* Pre-allocated buffer for formatted lines */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* File system methods */ + +static int modprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int modprocfs_close(FAR struct file *filep); +static ssize_t modprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static int modprocfs_dup(FAR const struct file *oldp, + FAR struct file *newp); +static int modprocfs_stat(FAR const char *relpath, FAR struct stat *buf); + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* See include/nutts/fs/procfs.h + * We use the old-fashioned kind of initializers so that this will compile + * with any compiler. + */ + +const struct procfs_operations module_operations = +{ + modprocfs_open, /* open */ + modprocfs_close, /* close */ + modprocfs_read, /* read */ + NULL, /* write */ + modprocfs_dup, /* dup */ + + NULL, /* opendir */ + NULL, /* closedir */ + NULL, /* readdir */ + NULL, /* rewinddir */ + + modprocfs_stat /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: modprocfs_callback + ****************************************************************************/ + +static int modprocfs_callback(FAR struct module_s *modp, FAR void *arg) +{ + FAR struct modprocfs_file_s *priv; + size_t linesize; + size_t copysize; + + DEBUGASSERT(modp != NULL && arg != NULL); + priv = (FAR struct modprocfs_file_s *)arg; + + linesize = snprintf(priv->line, MOD_LINELEN, "%s,%p,%p,%p,%lu\n", + modp->modulename, modp->uninitializer, modp->arg, + modp->alloc, (unsigned long)modp->size); + copysize = procfs_memcpy(priv->line, linesize, priv->buffer, + priv->remaining, &priv->offset); + priv->totalsize += copysize; + priv->buffer += copysize; + priv->remaining -= copysize; + + return (priv->totalsize >= priv->buflen) ? 1 : 0; +} + +/**************************************************************************** + * Name: modprocfs_open + ****************************************************************************/ + +static int modprocfs_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode) +{ + FAR struct modprocfs_file_s *priv; + + fvdbg("Open '%s'\n", relpath); + + /* PROCFS is read-only. Any attempt to open with any kind of write + * access is not permitted. + * + * REVISIT: Write-able proc files could be quite useful. + */ + + if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)) + { + fdbg("ERROR: Only O_RDONLY supported\n"); + return -EACCES; + } + + /* Allocate the open file structure */ + + priv = (FAR struct modprocfs_file_s *)kmm_zalloc(sizeof(struct modprocfs_file_s)); + if (!priv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* Save the open file structure as the open-specific state in + * filep->f_priv. + */ + + filep->f_priv = (FAR void *)priv; + return OK; +} + +/**************************************************************************** + * Name: modprocfs_close + ****************************************************************************/ + +static int modprocfs_close(FAR struct file *filep) +{ + FAR struct modprocfs_file_s *priv; + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct modprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Release the file attributes structure */ + + kmm_free(priv); + filep->f_priv = NULL; + return OK; +} + +/**************************************************************************** + * Name: modprocfs_read + ****************************************************************************/ + +static ssize_t modprocfs_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + FAR struct modprocfs_file_s *priv; + int ret; + + fvdbg("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen); + + /* Recover our private data from the struct file instance */ + + priv = (FAR struct modprocfs_file_s *)filep->f_priv; + DEBUGASSERT(priv); + + /* Traverse all installed modules */ + + priv->remaining = buflen; + priv->totalsize = 0; + priv->buffer = buffer; + priv->buflen = buflen; + priv->offset = filep->f_pos; + + ret = mod_registry_foreach(modprocfs_callback, priv); + if (ret >= 0) + { + filep->f_pos += priv->totalsize; + return priv->totalsize; + } + + return ret; +} + +/**************************************************************************** + * Name: modprocfs_dup + * + * Description: + * Duplicate open file data in the new file structure. + * + ****************************************************************************/ + +static int modprocfs_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + FAR struct modprocfs_file_s *oldpriv; + FAR struct modprocfs_file_s *newpriv; + + fvdbg("Dup %p->%p\n", oldp, newp); + + /* Recover our private data from the old struct file instance */ + + oldpriv = (FAR struct modprocfs_file_s *)oldp->f_priv; + DEBUGASSERT(oldpriv); + + /* Allocate a new container to hold the task and attribute selection */ + + newpriv = (FAR struct modprocfs_file_s *)kmm_zalloc(sizeof(struct modprocfs_file_s)); + if (!newpriv) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* The copy the file attribtes from the old attributes to the new */ + + memcpy(newpriv, oldpriv, sizeof(struct modprocfs_file_s)); + + /* Save the new attributes in the new file structure */ + + newp->f_priv = (FAR void *)newpriv; + return OK; +} + +/**************************************************************************** + * Name: modprocfs_stat + * + * Description: Return information about a file or directory + * + ****************************************************************************/ + +static int modprocfs_stat(FAR const char *relpath, FAR struct stat *buf) +{ + memset(buf, 0, sizeof(struct stat)); + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS && + * !CONFIG_FS_PROCFS_EXCLUDE_MODULE */ diff --git a/sched/module/mod_registry.c b/sched/module/mod_registry.c new file mode 100644 index 0000000000..7df1168b35 --- /dev/null +++ b/sched/module/mod_registry.c @@ -0,0 +1,247 @@ +/**************************************************************************** + * sched/module/mod_registry.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "module.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static sem_t g_mod_lock = SEM_INITIALIZER(1); +static FAR struct module_s *g_mod_registry; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_registry_lock + * + * Description: + * Get exclusive access to the module registry. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_registry_lock(void) +{ + while (sem_post(&g_mod_lock) < 0) + { + DEBUGASSERT(errno == EINTR); + } +} + +/**************************************************************************** + * Name: mod_registry_unlock + * + * Description: + * Relinquish the lock on the module registry + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_registry_unlock(void) +{ + sem_post(&g_mod_lock); +} + +/**************************************************************************** + * Name: mod_registry_add + * + * Description: + * Add a new entry to the module registry. + * + * Input Parameters: + * modp - The module data structure to be registered. + * + * Returned Value: + * None + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +void mod_registry_add(FAR struct module_s *modp) +{ + DEBUGASSERT(modp); + modp->flink = g_mod_registry; + g_mod_registry = modp; +} + +/**************************************************************************** + * Name: mod_registry_del + * + * Description: + * Remove a module entry from the registry + * + * Input Parameters: + * modp - The registry entry to be removed. + * + * Returned Value: + * Zero (OK) is returned if the registry entry was deleted. Otherwise, + * a negated errno value is returned. + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +int mod_registry_del(FAR struct module_s *modp) +{ + FAR struct module_s *prev; + FAR struct module_s *curr; + + for (prev = NULL, curr = g_mod_registry; + curr != NULL && curr != modp; + prev = curr, curr = curr->flink); + + if (curr == NULL) + { + sdbg("ERROR: Could not find module entry\n"); + return -ENOENT; + } + + if (prev == NULL) + { + g_mod_registry = modp->flink; + } + else + { + prev->flink = modp->flink; + } + + modp->flink = NULL; + return OK; +} + +/**************************************************************************** + * Name: mod_registry_find + * + * Description: + * Find an entry in the module registry using the name of the module. + * + * Input Parameters: + * modulename - The name of the module to be found + * + * Returned Value: + * If the registry entry is found, a pointer to the module entry is + * returned. NULL is returned if the they entry is not found. + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +FAR struct module_s *mod_registry_find(FAR const char *modulename) +{ + FAR struct module_s *modp; + + for (modp = g_mod_registry; + modp != NULL && strncmp(modp->modulename, modulename, MODULENAME_MAX) != 0; + modp = modp->flink); + + return modp; +} + +/**************************************************************************** + * Name: mod_registry_foreach + * + * Description: + * Visit each module in the registry + * + * Input Parameters: + * callback - This callback function was be called for each entry in the + * registry. + * arg - This opaque argument will be passed to the callback function. + * + * Returned Value: + * This function normally returns zero (OK). If, however, any callback + * function returns a non-zero value, the traversal will be terminated and + * that non-zero value will be returned. + * + * Assumptions: + * The caller does *NOT* hold the lock on the module registry. + * + ****************************************************************************/ + +int mod_registry_foreach(mod_callback_t callback, FAR void *arg) +{ + FAR struct module_s *modp; + int ret; + + /* Get exclusive access to the module registry */ + + mod_registry_lock(); + + /* Visit each installed module */ + + for (modp = g_mod_registry; modp != NULL; modp = modp->flink) + { + /* Perform the callback */ + + ret = callback(modp, arg); + if (ret != 0) + { + return ret; + } + } + + mod_registry_unlock(); + return OK; +} \ No newline at end of file diff --git a/sched/module/mod_rmmod.c b/sched/module/mod_rmmod.c index 339ef808a3..c9ac15b0ec 100644 --- a/sched/module/mod_rmmod.c +++ b/sched/module/mod_rmmod.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -60,13 +61,37 @@ * Description: * Remove a previously installed module from memory. * + * Input Parameters: + * + * modulename - The module name. This is the name module name that was + * provided to insmod when the module was loaded. + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * ****************************************************************************/ -int rmmod(FAR struct module_s *modp) +int rmmod(FAR const char *modulename) { + FAR struct module_s *modp; int ret = OK; - DEBUGASSERT(modp != NULL); + DEBUGASSERT(modulename != NULL); + + /* Get exclusive access to the module registry */ + + mod_registry_lock(); + + /* Find the module entry for this modulename in the registry */ + + modp = mod_registry_find(modulename); + if (modp == NULL) + { + sdbg("ERROR: Failed to find module %s: %d\n", modulename, ret); + ret = -ENOENT; + goto errout_with_lock; + } /* Is there an uninitializer? */ @@ -81,7 +106,7 @@ int rmmod(FAR struct module_s *modp) if (ret < 0) { sdbg("ERROR: Failed to uninitialize the module: %d\n", ret); - return ret; + goto errout_with_lock; } /* Nullify so that the uninitializer cannot be called again */ @@ -92,7 +117,7 @@ int rmmod(FAR struct module_s *modp) /* Release resources held by the module */ - if (modp->alloc != 0) + if (modp->alloc != NULL) { /* Free the module memory */ @@ -101,9 +126,29 @@ int rmmod(FAR struct module_s *modp) /* Nullify so that the memory cannot be freed again */ modp->alloc = NULL; + modp->size = 0; + } + + /* Remove the module from the registry */ + + ret = mod_registry_del(modp); + if (ret < 0) + { + sdbg("ERROR: Failed to remove the module from the registry: %d\n", ret); + goto errout_with_lock; } - return ret; + mod_registry_unlock(); + + /* And free the registry entry */ + + kmm_free(modp); + return OK; + +errout_with_lock: + mod_registry_unlock(); + set_errno(-ret); + return ERROR; } #endif /* CONFIG_MODULE */ diff --git a/sched/module/module.h b/sched/module/module.h index 7f96df366d..db04560959 100644 --- a/sched/module/module.h +++ b/sched/module/module.h @@ -52,6 +52,19 @@ * Public Types ****************************************************************************/ +/* This describes the file to be loaded. */ + +struct symtab_s; +struct module_s +{ + FAR struct module_s *flink; /* Supports a singly linked list */ + FAR char modulename[MODULENAME_MAX]; /* Module name */ + mod_uninitializer_t uninitializer; /* Module uninitializer function */ + FAR void *arg; /* Uninitializer argument */ + FAR void *alloc; /* Allocated kernel memory */ + size_t size; /* Size of the kernel memory allocation */ +}; + /* This struct provides a description of the currently loaded instantiation * of the kernel module. */ @@ -332,4 +345,95 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); +/**************************************************************************** + * Name: mod_registry_lock + * + * Description: + * Get exclusive access to the module registry. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_registry_lock(void); + +/**************************************************************************** + * Name: mod_registry_unlock + * + * Description: + * Relinquish the lock on the module registry + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_registry_unlock(void); + +/**************************************************************************** + * Name: mod_registry_add + * + * Description: + * Add a new entry to the module registry. + * + * Input Parameters: + * modp - The module data structure to be registered. + * + * Returned Value: + * None + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +void mod_registry_add(FAR struct module_s *modp); + +/**************************************************************************** + * Name: mod_registry_del + * + * Description: + * Remove a module entry from the registry + * + * Input Parameters: + * modp - The registry entry to be removed. + * + * Returned Value: + * Zero (OK) is returned if the registry entry was deleted. Otherwise, + * a negated errno value is returned. + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +int mod_registry_del(FAR struct module_s *modp); + +/**************************************************************************** + * Name: mod_registry_find + * + * Description: + * Find an entry in the module registry using the name of the module. + * + * Input Parameters: + * modulename - The name of the module to be found + * + * Returned Value: + * If the registry entry is found, a pointer to the module entry is + * returned. NULL is returned if the they entry is not found. + * + * Assumptions: + * The caller holds the lock on the module registry. + * + ****************************************************************************/ + +FAR struct module_s *mod_registry_find(FAR const char *modulename); + #endif /* __SCHED_MODULE_MODULE_H */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 50ebab9612..6cde8e6996 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -28,7 +28,7 @@ "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char*","FAR const char*" "getpid","unistd.h","","pid_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" -"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR struct module_s *" +"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *","FAR const struct symtab_s *","int" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" @@ -98,7 +98,7 @@ "rename","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","FAR const char*" "rewinddir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","void","FAR DIR*" "rmdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*" -"rmmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR struct module_s *" +"rmmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *" "sched_getparam","sched.h","","int","pid_t","struct sched_param*" "sched_getscheduler","sched.h","","int","pid_t" "sched_getstreams","nuttx/sched.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR struct streamlist*" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 62ccbd2d5f..d97852872c 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -111,7 +111,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) */ #ifdef CONFIG_MODULE - SYSCALL_LOOKUP(insmod, 1, STUB_insmod) + SYSCALL_LOOKUP(insmod, 3, STUB_insmod) SYSCALL_LOOKUP(rmmod, 1, STUB_rmmod) #endif diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index e23e801f19..6a49cd227c 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -112,7 +112,8 @@ uintptr_t STUB_waitid(int nbr, uintptr_t parm1, uintptr_t parm2, */ #ifdef CONFIG_MODULE -uintptr_t STUB_insmod(int nbr, uintptr_t parm1); +uintptr_t STUB_insmod(int nbr, uintptr_t parm1, uintptr_t parm2, + uintptr_t parm3); uintptr_t STUB_rmmod(int nbr, uintptr_t parm1); #endif -- GitLab From 917dbc85404be5e0eae0bb065df44dd629d349ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Dec 2015 18:56:32 -0600 Subject: [PATCH 448/858] modules: Add more information to registry just for procfs --- sched/module/mod_insmod.c | 8 +++++++- sched/module/mod_procfs.c | 9 ++++++--- sched/module/mod_rmmod.c | 8 +++++++- sched/module/module.h | 8 +++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index 82c3e591dc..f0a96dabdb 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -249,11 +249,17 @@ int insmod(FAR const char *filename, FAR const char *modulename, /* Return the load information */ modp->alloc = (FAR void *)loadinfo.textalloc; - modp->size = loadinfo.textsize + loadinfo.datasize; +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->textsize = loadinfo.textsize; + modp->datasize = loadinfo.datasize; +#endif /* Get the module initializer entry point */ initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->initializer = initializer; +#endif mod_dumpinitializer(initializer, &loadinfo); /* Call the module initializer */ diff --git a/sched/module/mod_procfs.c b/sched/module/mod_procfs.c index dca2db91b5..b430bc8fe0 100644 --- a/sched/module/mod_procfs.c +++ b/sched/module/mod_procfs.c @@ -152,9 +152,12 @@ static int modprocfs_callback(FAR struct module_s *modp, FAR void *arg) DEBUGASSERT(modp != NULL && arg != NULL); priv = (FAR struct modprocfs_file_s *)arg; - linesize = snprintf(priv->line, MOD_LINELEN, "%s,%p,%p,%p,%lu\n", - modp->modulename, modp->uninitializer, modp->arg, - modp->alloc, (unsigned long)modp->size); + linesize = snprintf(priv->line, MOD_LINELEN, "%s,%p,%p,%p,%p,%lu,%p,%lu\n", + modp->modulename, modp->initializer, + modp->uninitializer, modp->arg, + modp->alloc, (unsigned long)modp->textsize, + (FAR uint8_t *)modp->alloc + modp->textsize, + (unsigned long)modp->datasize); copysize = procfs_memcpy(priv->line, linesize, priv->buffer, priv->remaining, &priv->offset); priv->totalsize += copysize; diff --git a/sched/module/mod_rmmod.c b/sched/module/mod_rmmod.c index c9ac15b0ec..76fff1c7aa 100644 --- a/sched/module/mod_rmmod.c +++ b/sched/module/mod_rmmod.c @@ -111,6 +111,9 @@ int rmmod(FAR const char *modulename) /* Nullify so that the uninitializer cannot be called again */ +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->initializer = NULL; +#endif modp->uninitializer = NULL; modp->arg = NULL; } @@ -126,7 +129,10 @@ int rmmod(FAR const char *modulename) /* Nullify so that the memory cannot be freed again */ modp->alloc = NULL; - modp->size = 0; +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->textsize = 0; + modp->datasize = 0; +#endif } /* Remove the module from the registry */ diff --git a/sched/module/module.h b/sched/module/module.h index db04560959..6c9b6813b0 100644 --- a/sched/module/module.h +++ b/sched/module/module.h @@ -59,10 +59,16 @@ struct module_s { FAR struct module_s *flink; /* Supports a singly linked list */ FAR char modulename[MODULENAME_MAX]; /* Module name */ +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + mod_initializer_t initializer; /* Module initializer function */ +#endif mod_uninitializer_t uninitializer; /* Module uninitializer function */ FAR void *arg; /* Uninitializer argument */ FAR void *alloc; /* Allocated kernel memory */ - size_t size; /* Size of the kernel memory allocation */ +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + size_t textsize; /* Size of the kernel .text memory allocation */ + size_t datasize; /* Size of the kernel .bss/.data memory allocation */ +#endif }; /* This struct provides a description of the currently loaded instantiation -- GitLab From 076f382f795fe9e2377e90e134659d8ffbc4cdb8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Dec 2015 06:48:30 -0600 Subject: [PATCH 449/858] Module: Remove some unused members of a structure --- configs | 2 +- sched/module/mod_procfs.c | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/configs b/configs index 4a56b7ba64..2d03a7241a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4a56b7ba643607bbfadaef3628a7322b642ffa3f +Subproject commit 2d03a7241ae1347d12f69005c3fc3d98c52fffbf diff --git a/sched/module/mod_procfs.c b/sched/module/mod_procfs.c index b430bc8fe0..411cb1eccd 100644 --- a/sched/module/mod_procfs.c +++ b/sched/module/mod_procfs.c @@ -87,12 +87,7 @@ struct modprocfs_file_s size_t remaining; /* Space remaining in user buffer */ size_t totalsize; /* Total size returned by read() */ off_t offset; /* Offset skip on output */ - - /* Line buffer */ - - uint8_t lineno; /* Line number */ - uint8_t linesize; /* Number of valid characters in line[] */ - char line[MOD_LINELEN]; /* Pre-allocated buffer for formatted lines */ + char line[MOD_LINELEN]; /* Buffer for line formatting */ }; /**************************************************************************** -- GitLab From e8d0f85c8bfe415a093c571ff0bbd01a2769fa8f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Dec 2015 08:10:01 -0600 Subject: [PATCH 450/858] Modules: Add mod_setsymtab to set global symtol table once. Now we can remove symbol table parameters from the insmod call. This will make implementing an NSH insmod command much easier --- binfmt/Makefile | 7 +- include/nuttx/binfmt/symtab.h | 113 +----------- include/nuttx/module.h | 49 +++++- include/nuttx/symtab.h | 164 ++++++++++++++++++ include/sys/boardctl.h | 33 ++-- libc/Makefile | 1 + libc/symtab/Make.defs | 44 +++++ {binfmt => libc/symtab}/symtab_findbyname.c | 23 +-- {binfmt => libc/symtab}/symtab_findbyvalue.c | 23 +-- .../symtab}/symtab_findorderedbyname.c | 22 +-- .../symtab}/symtab_findorderedbyvalue.c | 23 +-- sched/module/Make.defs | 4 +- sched/module/mod_bind.c | 17 +- sched/module/mod_insmod.c | 14 +- sched/module/mod_symbols.c | 11 +- sched/module/mod_symtab.c | 110 ++++++++++++ sched/module/module.h | 18 +- 17 files changed, 437 insertions(+), 239 deletions(-) create mode 100644 include/nuttx/symtab.h create mode 100644 libc/symtab/Make.defs rename {binfmt => libc/symtab}/symtab_findbyname.c (78%) rename {binfmt => libc/symtab}/symtab_findbyvalue.c (81%) rename {binfmt => libc/symtab}/symtab_findorderedbyname.c (83%) rename {binfmt => libc/symtab}/symtab_findorderedbyvalue.c (82%) create mode 100644 sched/module/mod_symtab.c diff --git a/binfmt/Makefile b/binfmt/Makefile index 9da55ea973..5c5244d89b 100644 --- a/binfmt/Makefile +++ b/binfmt/Makefile @@ -1,7 +1,7 @@ ############################################################################ # nxflat/Makefile # -# Copyright (C) 2007-2009, 2012-2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2009, 2012-2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -56,11 +56,6 @@ ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) BINFMT_CSRCS += binfmt_schedunload.c endif -# Symbol table source files - -BINFMT_CSRCS += symtab_findbyname.c symtab_findbyvalue.c -BINFMT_CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c - ifeq ($(CONFIG_LIBC_EXECFUNCS),y) BINFMT_CSRCS += binfmt_execsymtab.c endif diff --git a/include/nuttx/binfmt/symtab.h b/include/nuttx/binfmt/symtab.h index c6cdeffe44..9e51ca3539 100644 --- a/include/nuttx/binfmt/symtab.h +++ b/include/nuttx/binfmt/symtab.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/binfmt/symtab.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,34 +41,7 @@ ****************************************************************************/ #include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* struct symbtab_s describes one entry in the symbol table. A symbol table - * is a fixed size array of struct symtab_s. The information is intentionally - * minimal and supports only: - * - * 1. Function pointers as sym_values. Of other kinds of values need to be - * supported, then typing information would also need to be included in - * the structure. - * - * 2. Fixed size arrays. There is no explicit provisional for dyanamically - * adding or removing entries from the symbol table (realloc might be - * used for that purpose if needed). The intention is to support only - * fixed size arrays completely defined at compilation or link time. - */ - -struct symtab_s -{ - FAR const char *sym_name; /* A pointer to the symbol name string */ - FAR const void *sym_value; /* The value associated witht the string */ -}; +#include /**************************************************************************** * Public Functions @@ -87,7 +60,7 @@ extern "C" * Name: exec_getsymtab * * Description: - * Get the current symbol table selection as an atomic operation. + * Get the current application symbol table selection as an atomic operation. * * Input Parameters: * symtab - The location to store the symbol table. @@ -104,7 +77,7 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols); * Name: exec_setsymtab * * Description: - * Select a new symbol table selection as an atomic operation. + * Select a new application symbol table selection as an atomic operation. * * Input Parameters: * symtab - The new symbol table. @@ -117,82 +90,4 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols); void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols); -/**************************************************************************** - * Name: symtab_findbyname - * - * Description: - * Find the symbol in the symbol table with the matching name. - * This version assumes that table is not ordered with respect to symbol - * name and, hence, access time will be linear with respect to nsyms. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -FAR const struct symtab_s * -symtab_findbyname(FAR const struct symtab_s *symtab, - FAR const char *name, int nsyms); - -/**************************************************************************** - * Name: symtab_findorderedbyname - * - * Description: - * Find the symbol in the symbol table with the matching name. - * This version assumes that table ordered with respect to symbol name. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -FAR const struct symtab_s * -symtab_findorderedbyname(FAR const struct symtab_s *symtab, - FAR const char *name, int nsyms); - -/**************************************************************************** - * Name: symtab_findbyvalue - * - * Description: - * Find the symbol in the symbol table whose value closest (but not greater - * than), the provided value. This version assumes that table is not ordered - * with respect to symbol name and, hence, access time will be linear with - * respect to nsyms. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -FAR const struct symtab_s * -symtab_findbyvalue(FAR const struct symtab_s *symtab, - FAR void *value, int nsyms); - -/**************************************************************************** - * Name: symtab_findorderedbyvalue - * - * Description: - * Find the symbol in the symbol table whose value closest (but not greater - * than), the provided value. This version assumes that table is ordered - * with respect to symbol name. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -FAR const struct symtab_s * -symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, - FAR void *value, int nsyms); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - #endif /* __INCLUDE_NUTTX_BINFMT_SYMTAB_H */ - diff --git a/include/nuttx/module.h b/include/nuttx/module.h index 8b9c2cfc8e..7ce8b80447 100644 --- a/include/nuttx/module.h +++ b/include/nuttx/module.h @@ -49,6 +49,7 @@ #include #include +#include #include /**************************************************************************** @@ -132,6 +133,44 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Name: mod_getsymtab + * + * Description: + * Get the current kernel symbol table selection as an atomic operation. + * + * Input Parameters: + * symtab - The location to store the symbol table. + * nsymbols - The location to store the number of symbols in the symbol table. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef __KERNEL__ +void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols); +#endif + +/**************************************************************************** + * Name: mod_setsymtab + * + * Description: + * Select a new kernel symbol table selection as an atomic operation. + * + * Input Parameters: + * symtab - The new symbol table. + * nsymbols - The number of symbols in the symbol table. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef __KERNEL__ +void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols); +#endif + /**************************************************************************** * Name: insmod * @@ -139,13 +178,16 @@ extern "C" * Verify that the file is an ELF module binary and, if so, load the * module into kernel memory and initialize it for use. * + * NOTE: mod_setsymtab had to have been called in board-specific OS logic + * prior to calling this function from application logic (perhaps via + * boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to + * resolve symbols in the OS module. + * * Input Parameters: * * filename - Full path to the module binary to be loaded * modulename - The name that can be used to refer to the module after * it has been loaded. - * exports - Table of exported symbols - * nexports - The number of symbols in exports[] * * Returned Value: * Zero (OK) on success. On any failure, -1 (ERROR) is returned the @@ -153,8 +195,7 @@ extern "C" * ****************************************************************************/ -int insmod(FAR const char *filename, FAR const char *modulename, - FAR const struct symtab_s *exports, int nexports); +int insmod(FAR const char *filename, FAR const char *modulename); /**************************************************************************** * Name: rmmod diff --git a/include/nuttx/symtab.h b/include/nuttx/symtab.h new file mode 100644 index 0000000000..d835a17b0d --- /dev/null +++ b/include/nuttx/symtab.h @@ -0,0 +1,164 @@ +/**************************************************************************** + * include/nuttx/binfmt/symtab.h + * + * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SYMTAB_H +#define __INCLUDE_NUTTX_SYMTAB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* struct symbtab_s describes one entry in the symbol table. A symbol table + * is a fixed size array of struct symtab_s. The information is intentionally + * minimal and supports only: + * + * 1. Function pointers as sym_values. Of other kinds of values need to be + * supported, then typing information would also need to be included in + * the structure. + * + * 2. Fixed size arrays. There is no explicit provisional for dyanamically + * adding or removing entries from the symbol table (realloc might be + * used for that purpose if needed). The intention is to support only + * fixed size arrays completely defined at compilation or link time. + */ + +struct symtab_s +{ + FAR const char *sym_name; /* A pointer to the symbol name string */ + FAR const void *sym_value; /* The value associated witht the string */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: symtab_findbyname + * + * Description: + * Find the symbol in the symbol table with the matching name. + * This version assumes that table is not ordered with respect to symbol + * name and, hence, access time will be linear with respect to nsyms. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +FAR const struct symtab_s * +symtab_findbyname(FAR const struct symtab_s *symtab, + FAR const char *name, int nsyms); + +/**************************************************************************** + * Name: symtab_findorderedbyname + * + * Description: + * Find the symbol in the symbol table with the matching name. + * This version assumes that table ordered with respect to symbol name. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +FAR const struct symtab_s * +symtab_findorderedbyname(FAR const struct symtab_s *symtab, + FAR const char *name, int nsyms); + +/**************************************************************************** + * Name: symtab_findbyvalue + * + * Description: + * Find the symbol in the symbol table whose value closest (but not greater + * than), the provided value. This version assumes that table is not ordered + * with respect to symbol name and, hence, access time will be linear with + * respect to nsyms. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +FAR const struct symtab_s * +symtab_findbyvalue(FAR const struct symtab_s *symtab, + FAR void *value, int nsyms); + +/**************************************************************************** + * Name: symtab_findorderedbyvalue + * + * Description: + * Find the symbol in the symbol table whose value closest (but not greater + * than), the provided value. This version assumes that table is ordered + * with respect to symbol name. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +FAR const struct symtab_s * +symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, + FAR void *value, int nsyms); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_SYMTAB_H */ + diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index 81b511bb5b..ac7989b922 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -77,10 +77,20 @@ * which to receive the board unique ID. * DEPENDENCIES: Board logic must provide the board_uniqueid() interface. * - * CMD: BOARDIOC_SYMTAB - * DESCRIPTION: Select a symbol table + * CMD: BOARDIOC_APP_SYMTAB + * DESCRIPTION: Select the application symbol table. This symbol table + * provides the symbol definitions exported to application + * code from application space. * ARG: A pointer to an instance of struct boardioc_symtab_s - * CONFIGURATION: CONFIG_BOARDCTL_SYMTAB + * CONFIGURATION: CONFIG_BOARDCTL_APP_SYMTAB + * DEPENDENCIES: None + * + * CMD: BOARDIOC_OS_SYMTAB + * DESCRIPTION: Select the OS symbol table. This symbol table provides + * the symbol definitions exported by the OS to kernel + * modules. + * ARG: A pointer to an instance of struct boardioc_symtab_s + * CONFIGURATION: CONFIG_BOARDCTL_OS_SYMTAB * DEPENDENCIES: None * * CMD: BOARDIOC_TSCTEST_SETUP @@ -125,13 +135,14 @@ #define BOARDIOC_POWEROFF _BOARDIOC(0x0002) #define BOARDIOC_RESET _BOARDIOC(0x0003) #define BOARDIOC_UNIQUEID _BOARDIOC(0x0004) -#define BOARDIOC_SYMTAB _BOARDIOC(0x0005) -#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0006) -#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0007) -#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0008) -#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0009) -#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000a) -#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000b) +#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0005) +#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0006) +#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0007) +#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0008) +#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0009) +#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x000a) +#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000b) +#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000c) /* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support. * In this case, all commands not recognized by boardctl() will be forwarded @@ -140,7 +151,7 @@ * User defined board commands may begin with this value: */ -#define BOARDIOC_USER _BOARDIOC(0x000c) +#define BOARDIOC_USER _BOARDIOC(0x000d) /**************************************************************************** * Public Type Definitions diff --git a/libc/Makefile b/libc/Makefile index 76d3e473aa..d83957a95c 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -81,6 +81,7 @@ include dirent/Make.defs include termios/Make.defs include spawn/Make.defs include queue/Make.defs +include symtab/Make.defs include wqueue/Make.defs include misc/Make.defs include audio/Make.defs diff --git a/libc/symtab/Make.defs b/libc/symtab/Make.defs new file mode 100644 index 0000000000..84f2ed23f8 --- /dev/null +++ b/libc/symtab/Make.defs @@ -0,0 +1,44 @@ +############################################################################ +# libc/symtab/Make.defs +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Symbol table source files + +CSRCS += symtab_findbyname.c symtab_findbyvalue.c +CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c + +# Add the symtab directory to the build + +DEPPATH += --dep-path symtab +VPATH += :symtab diff --git a/binfmt/symtab_findbyname.c b/libc/symtab/symtab_findbyname.c similarity index 78% rename from binfmt/symtab_findbyname.c rename to libc/symtab/symtab_findbyname.c index ecbd1bd7ee..e84e5eb527 100644 --- a/binfmt/symtab_findbyname.c +++ b/libc/symtab/symtab_findbyname.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/symtab_findbyname.c + * libc/symtab/symtab_findbyname.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,23 +44,7 @@ #include #include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include /**************************************************************************** * Public Functions @@ -94,4 +78,3 @@ symtab_findbyname(FAR const struct symtab_s *symtab, } return NULL; } - diff --git a/binfmt/symtab_findbyvalue.c b/libc/symtab/symtab_findbyvalue.c similarity index 81% rename from binfmt/symtab_findbyvalue.c rename to libc/symtab/symtab_findbyvalue.c index 600614a1e3..d3a12105d1 100644 --- a/binfmt/symtab_findbyvalue.c +++ b/libc/symtab/symtab_findbyvalue.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/symtab_findbyvalue.c + * libc/symtab/symtab_findbyvalue.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,23 +44,7 @@ #include #include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include /**************************************************************************** * Public Functions @@ -118,4 +102,3 @@ symtab_findbyvalue(FAR const struct symtab_s *symtab, return retval; } - diff --git a/binfmt/symtab_findorderedbyname.c b/libc/symtab/symtab_findorderedbyname.c similarity index 83% rename from binfmt/symtab_findorderedbyname.c rename to libc/symtab/symtab_findorderedbyname.c index 2771400194..40d6e883a2 100644 --- a/binfmt/symtab_findorderedbyname.c +++ b/libc/symtab/symtab_findorderedbyname.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/symtab_findorderedbyname.c + * libc/symtab/symtab_findorderedbyname.c * - * Copyright (C) 2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,23 +44,7 @@ #include #include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include /**************************************************************************** * Public Functions diff --git a/binfmt/symtab_findorderedbyvalue.c b/libc/symtab/symtab_findorderedbyvalue.c similarity index 82% rename from binfmt/symtab_findorderedbyvalue.c rename to libc/symtab/symtab_findorderedbyvalue.c index ba731be965..253ec2cc5f 100644 --- a/binfmt/symtab_findorderedbyvalue.c +++ b/libc/symtab/symtab_findorderedbyvalue.c @@ -1,7 +1,7 @@ /**************************************************************************** - * binfmt/symtab_findorderedbyvalue.c + * libc/symtab/symtab_findorderedbyvalue.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,23 +44,7 @@ #include #include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include /**************************************************************************** * Public Functions @@ -124,4 +108,3 @@ symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, return value == symtab[low].sym_value ? &symtab[low] : NULL; } - diff --git a/sched/module/Make.defs b/sched/module/Make.defs index ec60760c8a..00f8467560 100644 --- a/sched/module/Make.defs +++ b/sched/module/Make.defs @@ -42,8 +42,8 @@ CSRCS += mod_insmod.c mod_rmmod.c # loadable module library CSRCS += mod_bind.c mod_init.c mod_iobuffer.c mod_load.c mod_read.c -CSRCS += mod_registry.c mod_sections.c mod_symbols.c mod_uninit.c -CSRCS += mod_unload.c mod_verify.c +CSRCS += mod_registry.c mod_sections.c mod_symbols.c mod_symtab.c +CSRCS += mod_uninit.c mod_unload.c mod_verify.c # procfs support diff --git a/sched/module/mod_bind.c b/sched/module/mod_bind.c index a2979664b7..75d8e1b56a 100644 --- a/sched/module/mod_bind.c +++ b/sched/module/mod_bind.c @@ -98,8 +98,7 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx) { FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx]; @@ -149,7 +148,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, /* Get the value of the symbol (in sym.st_value) */ - ret = mod_symvalue(loadinfo, &sym, exports, nexports); + ret = mod_symvalue(loadinfo, &sym); if (ret < 0) { /* The special error -ESRCH is returned only in one condition: The @@ -200,8 +199,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, return OK; } -static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx) { sdbg("Not implemented\n"); return -ENOSYS; @@ -216,7 +214,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, * * Description: * Bind the imported symbol names in the loaded module described by - * 'loadinfo' using the exported symbol values provided by 'symtab'. + * 'loadinfo' using the exported symbol values provided by mod_setsymtab(). * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -224,8 +222,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, * ****************************************************************************/ -int mod_bind(FAR struct mod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports) +int mod_bind(FAR struct mod_loadinfo_s *loadinfo) { int ret; int i; @@ -274,11 +271,11 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo, if (loadinfo->shdr[i].sh_type == SHT_REL) { - ret = mod_relocate(loadinfo, i, exports, nexports); + ret = mod_relocate(loadinfo, i); } else if (loadinfo->shdr[i].sh_type == SHT_RELA) { - ret = mod_relocateadd(loadinfo, i, exports, nexports); + ret = mod_relocateadd(loadinfo, i); } if (ret < 0) diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index f0a96dabdb..9242c5419e 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -166,13 +166,16 @@ static void mod_dumpinitializer(mod_initializer_t initializer, * Verify that the file is an ELF module binary and, if so, load the * module into kernel memory and initialize it for use. * + * NOTE: mod_setsymtab had to have been called in board-specific OS logic + * prior to calling this function from application logic (perhaps via + * boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to + * resolve symbols in the OS module. + * * Input Parameters: * * filename - Full path to the module binary to be loaded * modulename - The name that can be used to refer to the module after * it has been loaded. - * exports - Table of exported symbols - * nexports - The number of symbols in exports[] * * Returned Value: * Zero (OK) on success. On any failure, -1 (ERROR) is returned the @@ -180,8 +183,7 @@ static void mod_dumpinitializer(mod_initializer_t initializer, * ****************************************************************************/ -int insmod(FAR const char *filename, FAR const char *modulename, - FAR const struct symtab_s *exports, int nexports) +int insmod(FAR const char *filename, FAR const char *modulename) { struct mod_loadinfo_s loadinfo; FAR struct module_s *modp; @@ -237,9 +239,9 @@ int insmod(FAR const char *filename, FAR const char *modulename, goto errout_with_registry_entry; } - /* Bind the program to the exported symbol table */ + /* Bind the program to the kernel symbol table */ - ret = mod_bind(&loadinfo, exports, nexports); + ret = mod_bind(&loadinfo); if (ret != 0) { sdbg("Failed to bind symbols program binary: %d\n", ret); diff --git a/sched/module/mod_symbols.c b/sched/module/mod_symbols.c index 0c60bbf981..bc91a426e3 100644 --- a/sched/module/mod_symbols.c +++ b/sched/module/mod_symbols.c @@ -261,8 +261,7 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports) +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym) { FAR const struct symtab_s *symbol; uintptr_t secbase; @@ -306,9 +305,13 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, /* Check if the base code exports a symbol of this name */ #ifdef CONFIG_SYMTAB_ORDEREDBYNAME - symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports); + symbol = symtab_findorderedbyname(g_mod_symtab, + (FAR char *)loadinfo->iobuffer, + g_mod_nsymbols); #else - symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports); + symbol = symtab_findbyname(g_mod_symtab, + (FAR char *)loadinfo->iobuffer, + g_mod_nsymbols); #endif if (!symbol) { diff --git a/sched/module/mod_symtab.c b/sched/module/mod_symtab.c new file mode 100644 index 0000000000..0c0648f294 --- /dev/null +++ b/sched/module/mod_symtab.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * sched/module/mod_symtab.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include "module.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +FAR const struct symtab_s *g_mod_symtab; +FAR int g_mod_nsymbols; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mod_getsymtab + * + * Description: + * Get the current kernel symbol table selection as an atomic operation. + * + * Input Parameters: + * symtab - The location to store the symbol table. + * nsymbols - The location to store the number of symbols in the symbol table. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols) +{ + DEBUGASSERT(symtab != NULL && nsymbols != NULL); + + /* Borrow the registry lock to assure atomic access */ + + mod_registry_lock(); + *symtab = g_mod_symtab; + *nsymbols = g_mod_nsymbols; + mod_registry_lock(); +} + +/**************************************************************************** + * Name: mod_setsymtab + * + * Description: + * Select a new kernel symbol table selection as an atomic operation. + * + * Input Parameters: + * symtab - The new symbol table. + * nsymbols - The number of symbols in the symbol table. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols) +{ + /* Borrow the registry lock to assure atomic access */ + + mod_registry_lock(); + g_mod_symtab = symtab; + g_mod_nsymbols = nsymbols; + mod_registry_lock(); +} diff --git a/sched/module/module.h b/sched/module/module.h index 6c9b6813b0..9bccc0c6e1 100644 --- a/sched/module/module.h +++ b/sched/module/module.h @@ -99,6 +99,13 @@ struct mod_loadinfo_s int filfd; /* Descriptor for the file being loaded */ }; +/**************************************************************************** + * Public Data + ****************************************************************************/ + +FAR const struct symtab_s *g_mod_symtab; +FAR int g_mod_nsymbols; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -154,7 +161,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo); * * Description: * Bind the imported symbol names in the loaded module described by - * 'loadinfo' using the exported symbol values provided by 'symtab'. + * 'loadinfo' using the exported symbol values provided by mod_setsymtab(). * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -162,9 +169,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -struct symtab_s; -int mod_bind(FAR struct mod_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports); +int mod_bind(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** * Name: mod_unload @@ -290,8 +295,6 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, * Input Parameters: * loadinfo - Load state information * sym - Symbol table entry (value might be undefined) - * exports - The symbol table to use for resolving undefined symbols. - * nexports - Number of symbols in the symbol table. * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -305,8 +308,7 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, * ****************************************************************************/ -int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, - FAR const struct symtab_s *exports, int nexports); +int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym); /**************************************************************************** * Name: mod_freebuffers -- GitLab From 3beff9568e970f13f5447b4cd2feec8b92c5b043 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Dec 2015 08:12:28 -0600 Subject: [PATCH 451/858] Module: Fix up system calls for changes to insmod prototype --- syscall/syscall.csv | 2 +- syscall/syscall_lookup.h | 2 +- syscall/syscall_stublookup.c | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 6cde8e6996..34dee8ca36 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -28,7 +28,7 @@ "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char*","FAR const char*" "getpid","unistd.h","","pid_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" -"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *","FAR const struct symtab_s *","int" +"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *","FAR const char *" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index d97852872c..6ad246ba5b 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -111,7 +111,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) */ #ifdef CONFIG_MODULE - SYSCALL_LOOKUP(insmod, 3, STUB_insmod) + SYSCALL_LOOKUP(insmod, 2, STUB_insmod) SYSCALL_LOOKUP(rmmod, 1, STUB_rmmod) #endif diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 6a49cd227c..ed151d246b 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -112,8 +112,7 @@ uintptr_t STUB_waitid(int nbr, uintptr_t parm1, uintptr_t parm2, */ #ifdef CONFIG_MODULE -uintptr_t STUB_insmod(int nbr, uintptr_t parm1, uintptr_t parm2, - uintptr_t parm3); +uintptr_t STUB_insmod(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_rmmod(int nbr, uintptr_t parm1); #endif -- GitLab From 28af090508fb3a8011568c8f58b0eda734aaef4a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Dec 2015 08:13:46 -0600 Subject: [PATCH 452/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 2d03a7241a..c7d59900d8 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2d03a7241ae1347d12f69005c3fc3d98c52fffbf +Subproject commit c7d59900d8cfefa53d6c9be92ddf03bf4cc0e803 -- GitLab From 09f236aea49498fc70475f583b4b2e1feca1c039 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 14 Dec 2015 13:20:47 -0600 Subject: [PATCH 453/858] Update ChangeLog --- ChangeLog | 3 +++ Documentation | 2 +- arch | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2595cd0f84..d9846672f2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11240,3 +11240,6 @@ * sched/module: Add an implementation of rmmod() (2015-12-12). * sched/module and fs/procfs: Add some basic module procfs support (2015-12-12), + * arch/arm/src/armv7-r: Add basic architecture support for the ARMv7-R + processor family (2015-12-13). + diff --git a/Documentation b/Documentation index c344ebc453..37c9f22b0c 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit c344ebc4538d51ff0acc22122e42dbd8614f261c +Subproject commit 37c9f22b0cc785c3120efd6041a9b7233dde51bc diff --git a/arch b/arch index 982356fab5..ca35a76083 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 982356fab5364d3f70f54483394cec9cfe9b9199 +Subproject commit ca35a760835dc6eac4cf67a1976c6f4673d11a32 -- GitLab From ebfead6f0d1e5b409c0f82fac1676fc8b4d44d7e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 14 Dec 2015 15:42:02 -0600 Subject: [PATCH 454/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ca35a76083..42f1034f27 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ca35a760835dc6eac4cf67a1976c6f4673d11a32 +Subproject commit 42f1034f2722b51eaacc08389558405404eb5074 diff --git a/configs b/configs index c7d59900d8..d271d51724 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c7d59900d8cfefa53d6c9be92ddf03bf4cc0e803 +Subproject commit d271d51724a61c70487bf8887f2efe5aab231b7c -- GitLab From d62a626703951d94305ab6a6e5db4d683830e0e1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 08:05:10 -0600 Subject: [PATCH 455/858] Adds a driver for the PCA9635PW I2C LED driver IC which can be used to control the intensity of up to 16 LEDs. From Alexander Entinger --- ChangeLog | 3 + arch | 2 +- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/README.txt | 4 + drivers/leds/Kconfig | 16 ++ drivers/leds/Make.defs | 51 +++++ drivers/leds/pca9635pw.c | 392 +++++++++++++++++++++++++++++++++ drivers/timers/Make.defs | 2 +- include/nuttx/leds/pca9635pw.h | 201 +++++++++++++++++ 10 files changed, 672 insertions(+), 2 deletions(-) create mode 100644 drivers/leds/Kconfig create mode 100644 drivers/leds/Make.defs create mode 100644 drivers/leds/pca9635pw.c create mode 100644 include/nuttx/leds/pca9635pw.h diff --git a/ChangeLog b/ChangeLog index d9846672f2..74f8a4bd60 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11242,4 +11242,7 @@ (2015-12-12), * arch/arm/src/armv7-r: Add basic architecture support for the ARMv7-R processor family (2015-12-13). + * drivers/led: Adds a driver for the PCA9635PW I2C LED driver IC which + can be used to control the intensity of up to 16 LEDs. From Alexander + Entinger (2015-12-15). diff --git a/arch b/arch index 42f1034f27..c2384128a3 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 42f1034f2722b51eaacc08389558405404eb5074 +Subproject commit c2384128a314987c0076f01435923de22ebbe785 diff --git a/drivers/Kconfig b/drivers/Kconfig index 3a3bf176a3..ca64c11fd2 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -405,6 +405,8 @@ if LCD source drivers/lcd/Kconfig endif # LCD +source drivers/leds/Kconfig + menuconfig MMCSD bool "MMC/SD Driver Support" default n diff --git a/drivers/Makefile b/drivers/Makefile index 8f55200581..5616cf3e2f 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -55,6 +55,7 @@ include bch$(DELIM)Make.defs include input$(DELIM)Make.defs include discrete$(DELIM)Make.defs include lcd$(DELIM)Make.defs +include leds$(DELIM)Make.defs include loop$(DELIM)Make.defs include mmcsd$(DELIM)Make.defs include mtd$(DELIM)Make.defs diff --git a/drivers/README.txt b/drivers/README.txt index fb43d81305..82334c923c 100644 --- a/drivers/README.txt +++ b/drivers/README.txt @@ -81,6 +81,10 @@ lcd/ Drivers for parallel and serial LCD and OLED type devices. These drivers support interfaces as defined in include/nuttx/lcd/lcd.h +leds/ + Various LED-related drivers including discrete as well as PWM- + driven LEDs. + loop/ Supports the standard loop device that can be used to export a file (or character device) as a block device. See losetup() and diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig new file mode 100644 index 0000000000..3dc3adccff --- /dev/null +++ b/drivers/leds/Kconfig @@ -0,0 +1,16 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menu "LED Support" + +config PCA9635PW + bool "PCA9635PW I2C LED Driver" + default n + select I2C + ---help--- + Enable support for the NXP PCA9635PW LED driver which can be + utilized to drive up to 16 LED's. + +endmenu # LED Support diff --git a/drivers/leds/Make.defs b/drivers/leds/Make.defs new file mode 100644 index 0000000000..a8af1586f5 --- /dev/null +++ b/drivers/leds/Make.defs @@ -0,0 +1,51 @@ +############################################################################ +# drivers/leds/Make.defs +# Various LED-related drivers +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Include LED drivers + +LEDDEPATH = +LEDVPATH = + +ifeq ($(CONFIG_PCA9635PW),y) + CSRCS += pca9635pw.c + LEDDEPATH = --dep-path leds + LEDVPATH = :leds +endif + +# Include LED build support (if any LED drivers were selected) + +DEPPATH += $(LEDDEPATH) +VPATH += $(LEDVPATH) diff --git a/drivers/leds/pca9635pw.c b/drivers/leds/pca9635pw.c new file mode 100644 index 0000000000..fc0d413c34 --- /dev/null +++ b/drivers/leds/pca9635pw.c @@ -0,0 +1,392 @@ +/**************************************************************************** + * drivers/leds/pca9635pw.c + * + * Copyright (C) 2015 DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_PCA9635PW) + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +struct pca9635pw_dev_s +{ + FAR struct i2c_dev_s *i2c; + uint8_t i2c_addr; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv, + uint8_t const reg_addr, + uint8_t const reg_val); +static int pca9635pw_set_led_mode(FAR struct pca9635pw_dev_s *priv, + uint8_t const led_out_x_mode); + +static int pca9635pw_open(FAR struct file *filep); +static int pca9635pw_close(FAR struct file *filep); +static int pca9635pw_ioctl(FAR struct file *filep, int cmd, unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_pca9635pw_fileops = +{ + pca9635pw_open, /* open */ + pca9635pw_close, /* close */ + 0, /* read */ + 0, /* write */ + 0, /* seek */ + pca9635pw_ioctl, /* ioctl */ + 0 /* poll */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pca9635pw_i2c_write_byte + * + * Description: + * Write a single byte to one of the PCA9635PW configuration registers. + * + ****************************************************************************/ + +static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv, + uint8_t const reg_addr, + uint8_t const reg_val) +{ + dbg("pca9635pw_i2c_write_byte\n"); + + /* assemble the 2 byte message comprised of reg_addr and reg_val */ + + uint8_t const BUFFER_SIZE = 2; + uint8_t buffer[BUFFER_SIZE]; + + buffer[0] = reg_addr; + buffer[1] = reg_val; + + /* Write the register address followed by the data (no RESTART) */ + + uint8_t const NUMBER_OF_I2C_ADDRESS_BITS = 7; + + dbg("i2c addr: 0x%02X reg addr: 0x%02X value: 0x%02X\n", priv->i2c_addr, + buffer[0], buffer[1]); + + int ret = I2C_SETADDRESS(priv->i2c, priv->i2c_addr, + NUMBER_OF_I2C_ADDRESS_BITS); + if (ret != OK) + { + dbg("I2C_SETADDRESS returned error code %d\n", ret); + return ret; + } + + ret = I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE); + if (ret != OK) + { + dbg("I2C_WRITE returned error code %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: pca9635pw_set_led_mode + * + * Description: + * Set the led output mode (see PCA9635PW_LED_OUT_x register value definitions) + * + ****************************************************************************/ + +static int pca9635pw_set_led_mode(FAR struct pca9635pw_dev_s *priv, + uint8_t const led_out_x_mode) +{ + uint8_t current_ledout_reg = PCA9635PW_LED_OUT_0; + + for (; current_ledout_reg <= PCA9635PW_LED_OUT_3; current_ledout_reg++) + { + int const ret = pca9635pw_i2c_write_byte(priv, current_ledout_reg, + led_out_x_mode); + if (ret != OK) + { + return ret; + } + } + + return OK; +} + +/**************************************************************************** + * Name: pca9635pw_open + * + * Description: + * This function is called whenever a PCA9635PW device is opened. + * + ****************************************************************************/ + +static int pca9635pw_open(FAR struct file *filep) +{ + dbg("pca9635pw_open\n"); + + FAR struct inode *inode = filep->f_inode; + FAR struct pca9635pw_dev_s *priv = inode->i_private; + + int ret = -1; + + /* Wake up the PCA9635PW (sleep bit PCA9635PW_MODE_1_SLEEP is set to zero + * and enable register auto increment - this way we can write to multiple + * consecutive I2C registers without having to always write first the + * address and then the data byte. + */ + + uint8_t const PCA9635PW_MODE_1_INITIAL_VALUE = PCA9635PW_MODE_1_AI2; + + ret = pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_1, + PCA9635PW_MODE_1_INITIAL_VALUE); + if (ret != OK) + { + dbg("Could not set initial config for PCA9635PW_MODE_1\n"); + return ret; + } + + /* Configure the PCA9635PW output drivers for totem-pole structure since + * the output of the PCA9635PW are coupled with the Gates of MOSFET's + * which then drive the LED's. Since we have this kind of schematic + * structure we also need to invert the output. + */ + + uint8_t const PCA9635PW_MODE_2_INITIAL_VALUE = + PCA9635PW_MODE_2_INVRT | PCA9635PW_MODE_2_OUTDRV; + + ret = pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_2, + PCA9635PW_MODE_2_INITIAL_VALUE); + if (ret != OK) + { + dbg("Could not set initial config for PCA9635PW_MODE_2\n"); + return ret; + } + + /* A delay of 500 us is necessary since this is the maximum time which the + * oscillator of the PCA9635PW needs to be up and running once sleep mode was + * left. + */ + + usleep(500); + + /* Turn all led drivers to mode 2 in which the led brightness is controlled + * by the indiviual pwm registers. + */ + + ret = pca9635pw_set_led_mode(priv, PCA9635PW_LED_OUT_x_MODE_2); + if (ret != OK) + { + dbg("Could not set led driver outputs to MODE2 (LED's brightness are " + "controlled by pwm registers)\n"); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: pca9635pw_close + * + * Description: + * This function is called whenever a PCA9635PW device is closed. + * + ****************************************************************************/ + +static int pca9635pw_close(FAR struct file *filep) +{ + dbg("pca9635pw_close\n"); + + FAR struct inode *inode = filep->f_inode; + FAR struct pca9635pw_dev_s *priv = inode->i_private; + + int ret = -1; + + /* Turn all led drivers off */ + + ret = pca9635pw_set_led_mode(priv, PCA9635PW_LED_OUT_x_MODE_0); + if (ret != OK) + { + dbg("Could not set led driver outputs to MODE0 (LED's are off)\n"); + return ret; + } + + /* Send the PCA9635PW back to sleep mode */ + + uint8_t const PCA9635PW_MODE_1_FINAL_VALUE = PCA9635PW_MODE_1_SLEEP; + + ret =pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_1, + PCA9635PW_MODE_1_FINAL_VALUE); + if (ret != OK) + { + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: pca9635pw_close + * + * Description: + * This function is called whenever an ioctl call to a PCA9635PW is performed. + * + ****************************************************************************/ + +static int pca9635pw_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + dbg("pca9635pw_ioctl\n"); + + FAR struct inode *inode = filep->f_inode; + FAR struct pca9635pw_dev_s *priv = inode->i_private; + + int ret = OK; + + dbg("cmd: %d arg: %ld\n", cmd, arg); + + switch (cmd) + { + /* Set the brightness of an indivual LED. Arg: pca9635pw_led_brightness_s + * pointer. + */ + + case PWMIOC_SETLED_BRIGHTNESS: + { + /* Retrieve the information handed over as argument for this ioctl */ + + FAR const struct pca9635pw_setled_brightness_arg_s *ptr = + (FAR const struct pca9635pw_setled_brightness_arg_s *)((uintptr_t)arg); + + DEBUGASSERT(ptr != NULL); + + /* Set the brighntess of the led */ + + ret = pca9635pw_i2c_write_byte(priv, ptr->led, ptr->brightness); + } + break; + + /* The used ioctl command was invalid */ + + default: + { + dbg("Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + } + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pca9635pw_register + * + * Description: + * Register the PCA9635PW device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/leddrv0". + * i2c - An instance of the I2C interface to use to communicate + * with the LM92. + * pca9635pw_i2c_addr + * - The I2C address of the PCA9635PW. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t const pca9635pw_i2c_addr) +{ + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + + /* Initialize the PCA9635PW device structure */ + + FAR struct pca9635pw_dev_s *priv = + (FAR struct pca9635pw_dev_s *)kmm_malloc(sizeof(struct pca9635pw_dev_s)); + + if (priv == NULL) + { + dbg("Failed to allocate instance of pca9635pw_dev_s\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->i2c_addr = pca9635pw_i2c_addr; + + /* Register the character driver */ + + int const ret = register_driver(devpath, &g_pca9635pw_fileops, 666, priv); + if (ret != OK) + { + dbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + return ret; + } + + /* setup i2c frequency */ + + I2C_SETFREQUENCY(priv->i2c, I2C_BUS_FREQ_HZ); + + return OK; +} + +#endif /* CONFIG_I2C && CONFIG_I2C_PCA9635PW */ diff --git a/drivers/timers/Make.defs b/drivers/timers/Make.defs index 7e3073d324..61c7a9764f 100644 --- a/drivers/timers/Make.defs +++ b/drivers/timers/Make.defs @@ -2,7 +2,7 @@ # drivers/timers/Make.defs # These drivers support various timer devices # -# Copyright (C) 20125Gregory Nutt. All rights reserved. +# Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/include/nuttx/leds/pca9635pw.h b/include/nuttx/leds/pca9635pw.h new file mode 100644 index 0000000000..a65610ca15 --- /dev/null +++ b/include/nuttx/leds/pca9635pw.h @@ -0,0 +1,201 @@ +/**************************************************************************** + * include/nuttx/leds/pca9635pw.h + * + * Copyright (C) 2015 DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_LEDS_PCA9635PW_H +#define __INCLUDE_NUTTX_LEDS_PCA9635PW_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/* Configuration + * CONFIG_I2C - Enables support for I2C drivers + * CONFIG_PCA9635PW - Enables support for the PCA9635PW driver + */ + +#if defined(CONFIG_I2C) && defined(CONFIG_PCA9635PW) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* I2C definitions */ + +#define I2C_BUS_FREQ_HZ (1000000) + +/* PCA9635PW register addresses */ + +#define PCA9635PW_MODE_1 (0x00) /* Mode register 1 */ +#define PCA9635PW_MODE_2 (0x01) /* Mode register 2 */ +#define PCA9635PW_LED_0 (0x02) /* LED 0 brightness control */ +#define PCA9635PW_LED_1 (PCA9635PW_LED_0 + 1) /* LED 1 brightness control */ +#define PCA9635PW_LED_2 (PCA9635PW_LED_0 + 2) /* LED 2 brightness control */ +#define PCA9635PW_LED_3 (PCA9635PW_LED_0 + 3) /* LED 3 brightness control */ +#define PCA9635PW_LED_4 (PCA9635PW_LED_0 + 4) /* LED 4 brightness control */ +#define PCA9635PW_LED_5 (PCA9635PW_LED_0 + 5) /* LED 5 brightness control */ +#define PCA9635PW_LED_6 (PCA9635PW_LED_0 + 6) /* LED 6 brightness control */ +#define PCA9635PW_LED_7 (PCA9635PW_LED_0 + 7) /* LED 7 brightness control */ +#define PCA9635PW_LED_8 (PCA9635PW_LED_0 + 8) /* LED 8 brightness control */ +#define PCA9635PW_LED_9 (PCA9635PW_LED_0 + 9) /* LED 9 brightness control */ +#define PCA9635PW_LED_10 (PCA9635PW_LED_0 + 10) /* LED 10 brightness control */ +#define PCA9635PW_LED_11 (PCA9635PW_LED_0 + 11) /* LED 11 brightness control */ +#define PCA9635PW_LED_12 (PCA9635PW_LED_0 + 12) /* LED 12 brightness control */ +#define PCA9635PW_LED_13 (PCA9635PW_LED_0 + 13) /* LED 13 brightness control */ +#define PCA9635PW_LED_14 (PCA9635PW_LED_0 + 14) /* LED 14 brightness control */ +#define PCA9635PW_LED_15 (PCA9635PW_LED_0 + 15) /* LED 15 brightness control */ +#define PCA9635PW_GRPPWM (0x12) /* Group duty cycle control */ +#define PCA9635PW_GRPFREQ (0x13) /* group frequency */ +#define PCA9635PW_LED_OUT_0 (0x14) /* LED output state 0 */ +#define PCA9635PW_LED_OUT_1 (PCA9635PW_LED_OUT_0 + 1) /* LED output state 1 */ +#define PCA9635PW_LED_OUT_2 (PCA9635PW_LED_OUT_0 + 2) /* LED output state 2 */ +#define PCA9635PW_LED_OUT_3 (PCA9635PW_LED_OUT_0 + 3) /* LED output state 3 */ + +/* PCA9635PW_MODE_1 bit definitions */ + +#define PCA9635PW_MODE_1_AI2 (1<<7) /* auto increment enable/disable */ +#define PCA9635PW_MODE_1_AI1 (1<<6) /* auto increment bit 1 */ +#define PCA9635PW_MODE_1_AI0 (1<<5) /* auto increment bit 0 */ +#define PCA9635PW_MODE_1_SLEEP (1<<4) /* low power mode/sleep enable/disable */ +#define PCA9635PW_MODE_1_SUB1 (1<<3) /* PCA9635PW reponds to I2C subaddress 1 enable/disable */ +#define PCA9635PW_MODE_1_SUB2 (1<<2) /* PCA9635PW reponds to I2C subaddress 2 enable/disable */ +#define PCA9635PW_MODE_1_SUB3 (1<<1) /* PCA9635PW reponds to I2C subaddress 3 enable/disable */ +#define PCA9635PW_MODE_1_ALLCALL (1<<0) /* PCA9635PW reponds to led all call I2C address enable/disable */ + +/* PCA9635PW_MODE_2 bit definitions */ + +#define PCA9635PW_MODE_2_DMBLNK (1<<5) /* group control dimming/blinking */ +#define PCA9635PW_MODE_2_INVRT (1<<4) /* output logic state inverted/not inverted */ +#define PCA9635PW_MODE_2_OCH (1<<3) /* output change on stop command/on ACK */ +#define PCA9635PW_MODE_2_OUTDRV (1<<2) /* outputs are configured with an open-drain-structure/totem-pole-structure */ +#define PCA9635PW_MODE_2_OUTNE1 (1<<1) /* handling of outputs in dependency of !OE pin */ +#define PCA9635PW_MODE_2_OUTNE0 (1<<0) /* handling of outputs in dependency of !OE pin */ + +/* PCA9635PW_LED_OUT_x register value definitions */ + +#define PCA9635PW_LED_OUT_x_MODE_0 (0x00) /* all led drivers are turned off */ +#define PCA9635PW_LED_OUT_x_MODE_1 (0x55) /* all led drivers are fully turned on */ +#define PCA9635PW_LED_OUT_x_MODE_2 (0xAA) /* all led drivers individual brightness can be controlled by their individual pwm registers */ +#define PCA9635PW_LED_OUT_x_MODE_3 (0xFF) /* all led drivers individual brightness and group dimming/blinking can be controlled by their individual pwm registers and the GRPPWM register */ + +/* IOCTL commands */ + +#define PWMIOC_SETLED_BRIGHTNESS _PWMIOC(1) /* Arg: pca9635pw_setled_brightness_arg_s * pointer */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum led_select_e +{ + LED_0 = PCA9635PW_LED_0, + LED_1 = PCA9635PW_LED_1, + LED_2 = PCA9635PW_LED_2, + LED_3 = PCA9635PW_LED_3, + LED_4 = PCA9635PW_LED_4, + LED_5 = PCA9635PW_LED_5, + LED_6 = PCA9635PW_LED_6, + LED_7 = PCA9635PW_LED_7, + LED_8 = PCA9635PW_LED_8, + LED_9 = PCA9635PW_LED_9, + LED_10 = PCA9635PW_LED_10, + LED_11 = PCA9635PW_LED_11, + LED_12 = PCA9635PW_LED_12, + LED_13 = PCA9635PW_LED_13, + LED_14 = PCA9635PW_LED_14, + LED_15 = PCA9635PW_LED_15 +}; + +/* This structure is used in an IOCTL command for setting the PWM of an individual + * LED. The desired LED is selected by setting the 'led' parameter accordingly + * whereas the 'led_pwm' field governs the brightness of the selected LED. A value + * of 0 (0x00) leads to a duty cycle of 0 % = LED off while a value of 255 (0xFF) + * leads to a duty cycle of 99.6 % = Maximum brightness. + */ + +struct pca9635pw_setled_brightness_arg_s +{ + enum led_select_e led; + uint8_t brightness; +}; + +/**************************************************************************** + * Forward declarations + ****************************************************************************/ + +struct i2c_dev_s; + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: pca9635pw_register + * + * Description: + * Register the PCA9635PW device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/leddrv0". + * i2c - An instance of the I2C interface to use to communicate + * with the LM92. + * pca9635pw_i2c_addr + * - The I2C address of the PCA9635PW. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t const pca9635pw_i2c_addr); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_I2C_PCA9635PW */ +#endif /* __INCLUDE_NUTTX_LEDS_PCA9635PW_H */ -- GitLab From 78f2ce05f8b8adc38c96504815293dc83083f7f1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 08:23:53 -0600 Subject: [PATCH 456/858] drivers: Move discrete user LED drivrs from drivers/discrete to drivers/leds --- ChangeLog | 8 ++--- drivers/discrete/Kconfig | 36 ---------------------- drivers/discrete/Make.defs | 9 ------ drivers/leds/Kconfig | 36 ++++++++++++++++++++++ drivers/leds/Make.defs | 11 +++++++ drivers/{discrete => leds}/userled_lower.c | 5 +-- drivers/{discrete => leds}/userled_upper.c | 4 +-- include/nuttx/fs/ioctl.h | 2 +- include/nuttx/{discrete => leds}/userled.h | 8 ++--- 9 files changed, 59 insertions(+), 60 deletions(-) rename drivers/{discrete => leds}/userled_lower.c (97%) rename drivers/{discrete => leds}/userled_upper.c (99%) rename include/nuttx/{discrete => leds}/userled.h (97%) diff --git a/ChangeLog b/ChangeLog index 74f8a4bd60..1525783a38 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11049,13 +11049,10 @@ * Many files: Standardize naming of the user LED interface functions. The new user LED interface functions are now prototyped in only in include/nuttx/board.h and have name like board_userled_* (2015-11-01). - * Rename ioexpander/ directories to discrete/. This expands the - namespace so that other discrete I/O drivers can reside there as - well (2015-11-01). - * drivers/discrete/userled_upper.c and include/discrete/userled.h: Add + * drivers/leds/usersled_upper.c and include/leds/usersled.h: Add a generic character driver that may be used by applications to write to board LEDs (2015-11-01). - * drivers/discrete/userled_lower.c: Add a generic lower-half user LED + * drivers/leds/usersled_lower.c: Add a generic lower-half user LED driver that may be used by any board that supports the standard board user LED interfaces (2015-11-01). * sched/clock: Fix error in clock_timespec_subtract(). Found by Lok @@ -11245,4 +11242,3 @@ * drivers/led: Adds a driver for the PCA9635PW I2C LED driver IC which can be used to control the intensity of up to 16 LEDs. From Alexander Entinger (2015-12-15). - diff --git a/drivers/discrete/Kconfig b/drivers/discrete/Kconfig index 4a25c72703..360689f314 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/discrete/Kconfig @@ -50,39 +50,3 @@ config IOEXPANDER_MULTIPIN optimized simultaneous access to multiple pins. endif # IOEXPANDER - -config USERLED - bool "LED driver" - default n - depends on ARCH_HAVE_LEDS - ---help--- - Enable standard user LED upper half driver. - -if USERLED - -config USERLED_LOWER - bool "Generic Lower Half LED Driver" - default n - ---help--- - If the board supports the standard LED interfaces as - defined in include/nuttx/board.h header file, then this - standard LED lower half driver might be usable. - - In order for this generic driver to be usable: - - 1. The board implementation must provide the LED - interfaces as defined in include/nuttx/board.h - 2. The board.h header file must provide the definition - BOARD_NLEDS, and - 3. The board.h header file must not include any other - header files that are not accessibble in this context - (such as those in arch//src/) UNLESS those - inclusions are conditioned on __KERNEL__. button_lower.c - will undefine __KERNEL__ before included board.h. - - If your board does not meet these requirements, then the - userled_lower.c file can still be copied to your your - board src/ directory and modified for your specific board - requirements. - -endif # USERLED diff --git a/drivers/discrete/Make.defs b/drivers/discrete/Make.defs index c45b869f54..26b17d15dc 100644 --- a/drivers/discrete/Make.defs +++ b/drivers/discrete/Make.defs @@ -37,15 +37,6 @@ ifeq ($(CONFIG_DISCRETE_IO),y) -# Include user LED driver - -ifeq ($(CONFIG_USERLED),y) - CSRCS += userled_upper.c -ifeq ($(CONFIG_USERLED_LOWER),y) - CSRCS += userled_lower.c -endif -endif - # Include buttion driver # Although it makes sense for button drivers to be in the discrete driver # directory, the button drivers current reside in the input dirver directory. diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 3dc3adccff..4a12d3eb12 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -5,6 +5,42 @@ menu "LED Support" +config USERLED + bool "LED driver" + default n + depends on ARCH_HAVE_LEDS + ---help--- + Enable standard user LED upper half driver. + +if USERLED + +config USERLED_LOWER + bool "Generic Lower Half LED Driver" + default n + ---help--- + If the board supports the standard LED interfaces as + defined in include/nuttx/board.h header file, then this + standard LED lower half driver might be usable. + + In order for this generic driver to be usable: + + 1. The board implementation must provide the LED + interfaces as defined in include/nuttx/board.h + 2. The board.h header file must provide the definition + BOARD_NLEDS, and + 3. The board.h header file must not include any other + header files that are not accessibble in this context + (such as those in arch//src/) UNLESS those + inclusions are conditioned on __KERNEL__. button_lower.c + will undefine __KERNEL__ before included board.h. + + If your board does not meet these requirements, then the + userled_lower.c file can still be copied to your your + board src/ directory and modified for your specific board + requirements. + +endif # USERLED + config PCA9635PW bool "PCA9635PW I2C LED Driver" default n diff --git a/drivers/leds/Make.defs b/drivers/leds/Make.defs index a8af1586f5..a10f7b5ea0 100644 --- a/drivers/leds/Make.defs +++ b/drivers/leds/Make.defs @@ -39,6 +39,17 @@ LEDDEPATH = LEDVPATH = +# Include user LED driver + +ifeq ($(CONFIG_USERLED),y) + CSRCS += userled_upper.c +ifeq ($(CONFIG_USERLED_LOWER),y) + CSRCS += userled_lower.c +endif + LEDDEPATH = --dep-path leds + LEDVPATH = :leds +endif + ifeq ($(CONFIG_PCA9635PW),y) CSRCS += pca9635pw.c LEDDEPATH = --dep-path leds diff --git a/drivers/discrete/userled_lower.c b/drivers/leds/userled_lower.c similarity index 97% rename from drivers/discrete/userled_lower.c rename to drivers/leds/userled_lower.c index 52a0daa275..69e349f64d 100644 --- a/drivers/discrete/userled_lower.c +++ b/drivers/leds/userled_lower.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/discrete/userled_lower.c + * drivers/leds/userled_lower.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -44,7 +44,7 @@ #include #include -#include +#include #undef __KERNEL__ #include @@ -57,6 +57,7 @@ static userled_set_t userled_supported(FAR const struct userled_lowerhalf_s *lower); static void userled_led(FAR const struct userled_lowerhalf_s *lower, + int led, bool ledon); static void userled_ledset(FAR const struct userled_lowerhalf_s *lower, userled_set_t ledset); diff --git a/drivers/discrete/userled_upper.c b/drivers/leds/userled_upper.c similarity index 99% rename from drivers/discrete/userled_upper.c rename to drivers/leds/userled_upper.c index 49c3188f97..64dfab48c7 100644 --- a/drivers/discrete/userled_upper.c +++ b/drivers/leds/userled_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/discrete/userled_upper.c + * drivers/leds/userled_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -54,7 +54,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 98b61a7eb5..46fbdbf8ab 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -350,7 +350,7 @@ #define _BTNIOC(nr) _IOC(_BTNBASE,nr) /* User LED driver ioctl definitions ****************************************/ -/* (see nuttx/discrete/userled.h */ +/* (see nuttx/leds/usersled.h */ #define _ULEDIOCVALID(c) (_IOC_TYPE(c)==_ULEDBASE) #define _ULEDIOC(nr) _IOC(_ULEDBASE,nr) diff --git a/include/nuttx/discrete/userled.h b/include/nuttx/leds/userled.h similarity index 97% rename from include/nuttx/discrete/userled.h rename to include/nuttx/leds/userled.h index c14fa609de..093c3b5b9a 100644 --- a/include/nuttx/discrete/userled.h +++ b/include/nuttx/leds/userled.h @@ -1,5 +1,5 @@ /************************************************************************************ - * include/nuttx/input/userled.h + * include/nuttx/leds/userled.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ************************************************************************************/ -#ifndef __INCLUDE_NUTTX_DISCRETE_USERLED_H -#define __INCLUDE_NUTTX_DISCRETE_USERLED_H +#ifndef __INCLUDE_NUTTX_LEDS_USERLED_H +#define __INCLUDE_NUTTX_LEDS_USERLED_H /**************************************************************************** * Included Files @@ -198,4 +198,4 @@ int userled_lower_initialize(FAR const char *devname); #endif #endif /* CONFIG_ARCH_HAVE_LEDS */ -#endif /* __INCLUDE_NUTTX_DISCRETE_USERLED_H */ +#endif /* __INCLUDE_NUTTX_LEDS_USERLED_H */ -- GitLab From 8ab93fdf980db8a0261ecefbb57e30552939169e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 08:40:34 -0600 Subject: [PATCH 457/858] Change name of drivers/discrete back to drivers/ioexpander --- drivers/Kconfig | 14 +++++----- drivers/Makefile | 2 +- drivers/{discrete => ioexpander}/Kconfig | 11 -------- drivers/{discrete => ioexpander}/Make.defs | 19 ++++--------- drivers/{discrete => ioexpander}/pca9555.c | 28 +++++++++++-------- drivers/{discrete => ioexpander}/pca9555.h | 12 ++++---- .../{discrete => ioexpander}/ioexpander.h | 8 +++--- .../nuttx/{discrete => ioexpander}/pca9555.h | 8 +++--- 8 files changed, 44 insertions(+), 58 deletions(-) rename drivers/{discrete => ioexpander}/Kconfig (79%) rename drivers/{discrete => ioexpander}/Make.defs (81%) rename drivers/{discrete => ioexpander}/pca9555.c (96%) rename drivers/{discrete => ioexpander}/pca9555.h (95%) rename include/nuttx/{discrete => ioexpander}/ioexpander.h (98%) rename include/nuttx/{discrete => ioexpander}/pca9555.h (96%) diff --git a/drivers/Kconfig b/drivers/Kconfig index ca64c11fd2..7c51e486cd 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -378,16 +378,16 @@ if INPUT source drivers/input/Kconfig endif # INPUT -menuconfig DISCRETE_IO - bool "Discrete I/O" +menuconfig IOEXPANDER + bool "IO Expander Support" default n ---help--- - This directory holds implementations of IO expander and other - discrete I/O drivers. + This directory holds implementations of IO expander drivers. + See include/nuttx/discrete/ioexpander.h for registration information. -if DISCRETE_IO -source drivers/discrete/Kconfig -endif # DISCRETE_IO +if IOEXPANDER +source drivers/ioexpander/Kconfig +endif # IOEXPANDER menuconfig LCD bool "LCD Driver Support" diff --git a/drivers/Makefile b/drivers/Makefile index 5616cf3e2f..c508b353dd 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -53,7 +53,7 @@ include analog$(DELIM)Make.defs include audio$(DELIM)Make.defs include bch$(DELIM)Make.defs include input$(DELIM)Make.defs -include discrete$(DELIM)Make.defs +include ioexpander$(DELIM)Make.defs include lcd$(DELIM)Make.defs include leds$(DELIM)Make.defs include loop$(DELIM)Make.defs diff --git a/drivers/discrete/Kconfig b/drivers/ioexpander/Kconfig similarity index 79% rename from drivers/discrete/Kconfig rename to drivers/ioexpander/Kconfig index 360689f314..f4b1694e97 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/ioexpander/Kconfig @@ -3,15 +3,6 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -menuconfig IOEXPANDER - bool "IO Expander Support" - default n - ---help--- - This directory holds implementations of IO expander drivers. - See include/nuttx/discrete/ioexpander.h for registration information. - -if IOEXPANDER - config IOEXPANDER_PCA9555 bool "PCA9555 I2C IO expander" default n @@ -48,5 +39,3 @@ config IOEXPANDER_MULTIPIN ---help--- This settings enable the definition of routines for optimized simultaneous access to multiple pins. - -endif # IOEXPANDER diff --git a/drivers/discrete/Make.defs b/drivers/ioexpander/Make.defs similarity index 81% rename from drivers/discrete/Make.defs rename to drivers/ioexpander/Make.defs index 26b17d15dc..aea59aea51 100644 --- a/drivers/discrete/Make.defs +++ b/drivers/ioexpander/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# drivers/discrete/Make.defs +# drivers/ioexpander/Make.defs # # Copyright (C) 2015 Gregory Nutt. All rights reserved. # Author: Sebastien Lorquet @@ -33,14 +33,6 @@ # ############################################################################ -# Don't build anything if there is no support for discrete devices - -ifeq ($(CONFIG_DISCRETE_IO),y) - -# Include buttion driver -# Although it makes sense for button drivers to be in the discrete driver -# directory, the button drivers current reside in the input dirver directory. - # Check if I/O expander support is enabled ifeq ($(CONFIG_IOEXPANDER),y) @@ -50,12 +42,11 @@ ifeq ($(CONFIG_IOEXPANDER),y) ifeq ($(CONFIG_IOEXPANDER_PCA9555),y) CSRCS += pca9555.c endif -endif -# Include discrete I/O device driver build support +# Include ioexpander I/O device driver build support -DEPPATH += --dep-path discrete -VPATH += :discrete -CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)discrete} +DEPPATH += --dep-path ioexpander +VPATH += :ioexpander +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)ioexpander} endif diff --git a/drivers/discrete/pca9555.c b/drivers/ioexpander/pca9555.c similarity index 96% rename from drivers/discrete/pca9555.c rename to drivers/ioexpander/pca9555.c index 106942b69d..cc11416662 100644 --- a/drivers/discrete/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/discrete/pca9555.c + * drivers/ioexpander/pca9555.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include "pca9555.h" @@ -210,7 +210,7 @@ static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, * Name: pca9555_direction * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -226,7 +226,7 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_option * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -248,7 +248,7 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_write * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -263,7 +263,7 @@ static int pca9555_write(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_readpin * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -278,7 +278,7 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, * Name: pca9555_readbuf * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -342,7 +342,7 @@ static int pca9555_getmultibits(FAR struct i2c_dev_s *i2c, uint8_t addr, * Name: pca9555_multiwrite * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -404,7 +404,7 @@ static int pca9555_multiwrite(FAR struct ioexpander_dev_s *dev, * Name: pca9555_multireadpin * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -421,7 +421,7 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, * Name: pca9555_multireadbuf * * Description: - * See include/nuttx/discrete/ioexpander.h + * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ @@ -499,10 +499,16 @@ static void pca9555_irqworker(void *arg) static int pca9555_interrupt(int irq, FAR void *context) { +#ifdef CONFIG_PCA9555_MULTIPLE /* To support multiple devices, - * retrieve the priv structure using the irq number */ + * retrieve the priv structure using the irq number. + */ + +# warning Missing logic +#else register FAR struct pca9555_dev_s *pca = &g_pca9555; +#endif /* In complex environments, we cannot do I2C transfers from the interrupt * handler because semaphores are probably used to lock the I2C bus. In diff --git a/drivers/discrete/pca9555.h b/drivers/ioexpander/pca9555.h similarity index 95% rename from drivers/discrete/pca9555.h rename to drivers/ioexpander/pca9555.h index 638180e291..5a8e1b69df 100644 --- a/drivers/discrete/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -1,5 +1,5 @@ /******************************************************************************************** - * drivers/discrete/pca9555.h + * drivers/ioexpander/pca9555.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -37,8 +37,8 @@ * ********************************************************************************************/ -#ifndef __DRIVERS_DISCRETE_PCA9555_H -#define __DRIVERS_DISCRETE_PCA9555_H +#ifndef __DRIVERS_IOEXPANDER_PCA9555_H +#define __DRIVERS_IOEXPANDER_PCA9555_H /******************************************************************************************** * Included Files @@ -48,8 +48,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -128,4 +128,4 @@ struct pca9555_dev_s }; #endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9555 */ -#endif /* __DRIVERS_DISCRETE_PCA9555_H */ +#endif /* __DRIVERS_IOEXPANDER_PCA9555_H */ diff --git a/include/nuttx/discrete/ioexpander.h b/include/nuttx/ioexpander/ioexpander.h similarity index 98% rename from include/nuttx/discrete/ioexpander.h rename to include/nuttx/ioexpander/ioexpander.h index 9adbb065d3..72df8b5f37 100644 --- a/include/nuttx/discrete/ioexpander.h +++ b/include/nuttx/ioexpander/ioexpander.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/discrete/ioexpander.h + * include/nuttx/ioexpander/ioexpander.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H -#define __INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H +#ifndef __INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H +#define __INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H /**************************************************************************** * Included Files @@ -264,5 +264,5 @@ struct ioexpander_dev_s }; #endif //CONFIG_IOEXPANDER -#endif //__INCLUDE_NUTTX_DISCRETE_IOEXPANDER_H +#endif //__INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H diff --git a/include/nuttx/discrete/pca9555.h b/include/nuttx/ioexpander/pca9555.h similarity index 96% rename from include/nuttx/discrete/pca9555.h rename to include/nuttx/ioexpander/pca9555.h index 5f71c02dbd..581528c531 100644 --- a/include/nuttx/discrete/pca9555.h +++ b/include/nuttx/ioexpander/pca9555.h @@ -1,5 +1,5 @@ /******************************************************************************************** - * include/nuttx/discrete/pca9555.h + * include/nuttx/ioexpander/pca9555.h * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet @@ -37,8 +37,8 @@ * ********************************************************************************************/ -#ifndef __INCLUDE_NUTTX_DISCRETE_PCA9555_H -#define __INCLUDE_NUTTX_DISCRETE_PCA9555_H +#ifndef __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H +#define __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H #include @@ -117,4 +117,4 @@ FAR struct ioexpander_dev_s* pca9555_initialize(FAR struct i2c_dev_s *dev, } #endif -#endif /* __INCLUDE_NUTTX_DISCRETE_PCA9555_H */ +#endif /* __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H */ -- GitLab From b1a0171d0ff62664b9677b890e257a6359037928 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 08:43:18 -0600 Subject: [PATCH 458/858] Fix a missed name change in a Kconfig file --- configs | 2 +- drivers/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs b/configs index d271d51724..8d42d87cd6 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d271d51724a61c70487bf8887f2efe5aab231b7c +Subproject commit 8d42d87cd6698ce5cf380db0b2c8626010c487f8 diff --git a/drivers/Kconfig b/drivers/Kconfig index 7c51e486cd..4d7d813edd 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -383,7 +383,7 @@ menuconfig IOEXPANDER default n ---help--- This directory holds implementations of IO expander drivers. - See include/nuttx/discrete/ioexpander.h for registration information. + See include/nuttx/ioexpander/ioexpander.h for registration information. if IOEXPANDER source drivers/ioexpander/Kconfig -- GitLab From 797798d4ea1b47cb5172cddcff607459e3cb240f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 17:21:34 -0600 Subject: [PATCH 459/858] Update ChangeLog --- ChangeLog | 3 +++ arch | 2 +- configs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1525783a38..88315935f4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11242,3 +11242,6 @@ * drivers/led: Adds a driver for the PCA9635PW I2C LED driver IC which can be used to control the intensity of up to 16 LEDs. From Alexander Entinger (2015-12-15). + * configs/launchxl-tms57004: Add basic board support for TI LaunchXL- + TMS57004. Not much to see there yet (2015-12-15). + diff --git a/arch b/arch index c2384128a3..ee07a0a24a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c2384128a314987c0076f01435923de22ebbe785 +Subproject commit ee07a0a24aef8cf81feba7bf91d08e2c75ab72d6 diff --git a/configs b/configs index 8d42d87cd6..d77e1f4f41 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8d42d87cd6698ce5cf380db0b2c8626010c487f8 +Subproject commit d77e1f4f41065a7b857c7a4643ca727241894aa7 -- GitLab From 435d7597cf0c072e6ae8b126b5a42e98e066fb06 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 15 Dec 2015 17:49:07 -0600 Subject: [PATCH 460/858] sycalls: Fix some missing quotes in the syscall CSV file --- arch | 2 +- configs | 2 +- syscall/syscall.csv | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch b/arch index ee07a0a24a..ea60c050d0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ee07a0a24aef8cf81feba7bf91d08e2c75ab72d6 +Subproject commit ea60c050d01309ac9710cd2a48a0b5fb6f43a819 diff --git a/configs b/configs index d77e1f4f41..0c91f48852 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d77e1f4f41065a7b857c7a4643ca727241894aa7 +Subproject commit 0c91f48852432080a802c8e876008e78e640e431 diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 34dee8ca36..647ee8f4c4 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -28,7 +28,7 @@ "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char*","FAR const char*" "getpid","unistd.h","","pid_t" "getsockopt","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int","FAR void*","FAR socklen_t*" -"insmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *","FAR const char *" +"insmod","nuttx/module.h","defined(CONFIG_MODULE)","int","FAR const char *","FAR const char *" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" @@ -98,7 +98,7 @@ "rename","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","FAR const char*" "rewinddir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","void","FAR DIR*" "rmdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*" -"rmmod","nuttx/module.h",defined(CONFIG_MODULE),"int","FAR const char *" +"rmmod","nuttx/module.h","defined(CONFIG_MODULE)","int","FAR const char *" "sched_getparam","sched.h","","int","pid_t","struct sched_param*" "sched_getscheduler","sched.h","","int","pid_t" "sched_getstreams","nuttx/sched.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR struct streamlist*" -- GitLab From dc30bb5a545d97e796469780626b59137e15772c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 16 Dec 2015 09:06:24 -0600 Subject: [PATCH 461/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ea60c050d0..4de5388363 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ea60c050d01309ac9710cd2a48a0b5fb6f43a819 +Subproject commit 4de538836393ac0583343d6bcc23f1d1a40b872c diff --git a/configs b/configs index 0c91f48852..2b22cb45dc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0c91f48852432080a802c8e876008e78e640e431 +Subproject commit 2b22cb45dc7d1d5e398c43722fa3773343e284fc -- GitLab From cc48a12464ff6007de7e4b70ca756b7f17d4bd6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 16 Dec 2015 12:47:14 -0600 Subject: [PATCH 462/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 4de5388363..d11de58b7f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4de538836393ac0583343d6bcc23f1d1a40b872c +Subproject commit d11de58b7fc4252b9338c1b422366a84a9471e46 diff --git a/configs b/configs index 2b22cb45dc..d633a3fcc0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2b22cb45dc7d1d5e398c43722fa3773343e284fc +Subproject commit d633a3fcc0582dd0a35240c4c5e0e9b9b6b65342 -- GitLab From a12eeaf899451da3a97b1eef13e82d05b6ba0335 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Dec 2015 15:32:25 -0600 Subject: [PATCH 463/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index d11de58b7f..ad4e459722 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d11de58b7fc4252b9338c1b422366a84a9471e46 +Subproject commit ad4e459722172ffa8f0bb83edc3167c085021f6b diff --git a/configs b/configs index d633a3fcc0..774fd598cc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d633a3fcc0582dd0a35240c4c5e0e9b9b6b65342 +Subproject commit 774fd598cc41ee029bbde876603ac99abdf95f3c -- GitLab From 2c0770a4b6fe9210f75239e64e8ac819d571b277 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 19 Dec 2015 16:34:28 -0600 Subject: [PATCH 464/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ad4e459722..d943c5e304 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ad4e459722172ffa8f0bb83edc3167c085021f6b +Subproject commit d943c5e3049299c271d185701710166d7f20a4d4 diff --git a/configs b/configs index 774fd598cc..f27e7ff4e9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 774fd598cc41ee029bbde876603ac99abdf95f3c +Subproject commit f27e7ff4e9d21c92f272bd613d4d147b25b1a09e -- GitLab From 1e96a0734674ca36df42b9d9aaf6577666b31e58 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 21 Dec 2015 10:58:59 -0600 Subject: [PATCH 465/858] Kconfig: CONFIG_BUILD_KERNEL should not be experimental --- Kconfig | 2 +- arch | 2 +- configs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index ce0bfa5b13..03a2a872a5 100644 --- a/Kconfig +++ b/Kconfig @@ -165,7 +165,7 @@ config BUILD_PROTECTED config BUILD_KERNEL bool "NuttX kernel build" - depends on ARCH_USE_MMU && ARCH_ADDRENV && EXPERIMENTAL + depends on ARCH_USE_MMU && ARCH_ADDRENV select LIB_SYSCALL ---help--- Builds NuttX as a separately compiled kernel. No applications are diff --git a/arch b/arch index d943c5e304..f9a3a1463b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d943c5e3049299c271d185701710166d7f20a4d4 +Subproject commit f9a3a1463b24b8da63f2a7577d0b4ce0131a1069 diff --git a/configs b/configs index f27e7ff4e9..196f9f3f3f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f27e7ff4e9d21c92f272bd613d4d147b25b1a09e +Subproject commit 196f9f3f3f067ccb3c285078a704a2a5eb37b7ea -- GitLab From a696b807fb2a896bf503dea5b0dffb2002b29fae Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 21 Dec 2015 14:00:25 -0600 Subject: [PATCH 466/858] PCF65263: Correct readback verification of seconds register --- arch | 2 +- drivers/timers/pcf85263.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch b/arch index f9a3a1463b..a8666b5bb6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f9a3a1463b24b8da63f2a7577d0b4ce0131a1069 +Subproject commit a8666b5bb6841d514d1fccedb0071df38d78217a diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 8d5db98e6d..ab89fd4715 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -408,6 +408,7 @@ int up_rtc_settime(FAR const struct timespec *tp) struct tm newtm; time_t newtime; uint8_t buffer[9]; + uint8_t cmd; uint8_t seconds; int ret; @@ -449,7 +450,7 @@ int up_rtc_settime(FAR const struct timespec *tp) rtc_dumptime(&tm, "New time"); /* Construct the message */ - /* Write starting with the seconds regiser */ + /* Write starting with the 100ths of seconds register */ buffer[0] = PCF85263_RTC_100TH_SECONDS; @@ -498,9 +499,11 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Read back the seconds register */ + cmd = PCF85263_RTC_SECONDS; + msg[1].addr = PCF85263_I2C_ADDRESS; msg[1].flags = 0; - msg[1].buffer = buffer; + msg[1].buffer = &cmd; msg[1].length = 1; msg[2].addr = PCF85263_I2C_ADDRESS; -- GitLab From a2e1ece87399fb180ec224a73f7d7e806d1bc410 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 21 Dec 2015 14:39:40 -0600 Subject: [PATCH 467/858] RTC: Handle RTC failures. If mktime is called with garbage, it may crash --- drivers/timers/pcf85263.c | 4 ++-- sched/clock/clock_initialize.c | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index ab89fd4715..9fa04887cb 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -241,8 +241,8 @@ int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c) { /* Remember the i2c device and claim that the RTC is enabled */ - g_pcf85263.i2c = i2c; - g_rtc_enabled = true; + g_pcf85263.i2c = i2c; + g_rtc_enabled = true; return OK; } diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 507d61c772..e9923db1f1 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -110,47 +110,53 @@ struct timespec g_basetime; #if defined(CONFIG_RTC_DATETIME) /* Initialize the system time using a broken out date/time structure */ -static inline void clock_basetime(FAR struct timespec *tp) +static inline int clock_basetime(FAR struct timespec *tp) { struct tm rtctime; + int ret; /* Get the broken-out time from the date/time RTC. */ - (void)up_rtc_getdatetime(&rtctime); + ret = up_rtc_getdatetime(&rtctime); + if (ret >= 0) + { + /* And use the broken-out time to initialize the system time */ - /* And use the broken-out time to initialize the system time */ + tp->tv_sec = mktime(&rtctime); + tp->tv_nsec = 0; + } - tp->tv_sec = mktime(&rtctime); - tp->tv_nsec = 0; + return ret; } #elif defined(CONFIG_RTC_HIRES) /* Initialize the system time using a high-resolution structure */ -static inline void clock_basetime(FAR struct timespec *tp) +static inline int clock_basetime(FAR struct timespec *tp) { /* Get the complete time from the hi-res RTC. */ - (void)up_rtc_gettime(tp); + return up_rtc_gettime(tp); } #else /* Initialize the system time using seconds only */ -static inline void clock_basetime(FAR struct timespec *tp) +static inline int clock_basetime(FAR struct timespec *tp) { /* Get the seconds (only) from the lo-resolution RTC */ tp->tv_sec = up_rtc_time(); tp->tv_nsec = 0; + return OK; } #endif /* CONFIG_RTC_HIRES */ #else /* CONFIG_RTC */ -static inline void clock_basetime(FAR struct timespec *tp) +static inline int clock_basetime(FAR struct timespec *tp) { time_t jdn = 0; @@ -165,6 +171,7 @@ static inline void clock_basetime(FAR struct timespec *tp) tp->tv_sec = jdn * SEC_PER_DAY; tp->tv_nsec = 0; + return OK; } #endif /* CONFIG_RTC */ @@ -181,7 +188,7 @@ static void clock_inittime(void) { /* (Re-)initialize the time value to match the RTC */ - clock_basetime(&g_basetime); + (void)clock_basetime(&g_basetime); #ifndef CONFIG_SCHED_TICKLESS g_system_timer = 0; #endif -- GitLab From 8f540fd81a9f5b2fd992db5308a24ddd3dba5ca0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 21 Dec 2015 22:24:43 -0600 Subject: [PATCH 468/858] Trivial fix to typo in a comment --- sched/sched/sched_waitpid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index e6d4ff96ce..371df3f767 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -212,7 +212,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) goto errout_with_errno; } - /* The the task group corresponding to this PID */ + /* Then the task group corresponding to this PID */ group = ctcb->group; DEBUGASSERT(group); -- GitLab From b90da3f27b4c307c77ceecea7ba225f7fede5c20 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 22 Dec 2015 11:48:17 -0600 Subject: [PATCH 469/858] waitpid: CRITICAL BUGFIX. Add a reference counting mechansim to prevent wait from using stale memory that was freed by the exiting task --- ChangeLog | 3 +++ arch | 2 +- configs | 2 +- include/nuttx/sched.h | 2 ++ mm/mm_heap/mm_free.c | 8 -------- mm/mm_heap/mm_zalloc.c | 4 ---- sched/group/Make.defs | 4 ++++ sched/group/group.h | 6 +++++- sched/group/group_free.c | 24 ++---------------------- sched/group/group_leave.c | 32 +++++++++++++++++--------------- sched/sched/sched_waitpid.c | 12 ++++++++---- sched/semaphore/sem_holder.c | 10 +--------- sched/semaphore/sem_wait.c | 20 -------------------- 13 files changed, 44 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88315935f4..091fc549ce 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11244,4 +11244,7 @@ Entinger (2015-12-15). * configs/launchxl-tms57004: Add basic board support for TI LaunchXL- TMS57004. Not much to see there yet (2015-12-15). + * waitpid: CRITICAL BUGFIX. Add a reference count to prevent waitpid + from using stale memory released by the waited-for task group + (2015-12-22). diff --git a/arch b/arch index a8666b5bb6..1519d53e18 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a8666b5bb6841d514d1fccedb0071df38d78217a +Subproject commit 1519d53e182663632e4b115baa1b3b15ce9840a3 diff --git a/configs b/configs index 196f9f3f3f..b30cbace6a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 196f9f3f3f067ccb3c285078a704a2a5eb37b7ea +Subproject commit b30cbace6afab3caed2dcfec09071af60a2b0d7f diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 4eaacbd229..07ec74cd82 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -154,6 +154,7 @@ #define GROUP_FLAG_NOCLDWAIT (1 << 0) /* Bit 0: Do not retain child exit status */ #define GROUP_FLAG_ADDRENV (1 << 1) /* Bit 1: Group has an address environment */ #define GROUP_FLAG_PRIVILEGED (1 << 2) /* Bit 2: Group is privileged */ +#define GROUP_FLAG_DELETED (1 << 3) /* Bit 3: Group has been deleted but not yet freed */ /* Values for struct child_status_s ch_flags */ @@ -418,6 +419,7 @@ struct task_group_s /* waitpid support ************************************************************/ /* Simple mechanism used only when there is no support for SIGCHLD */ + uint8_t tg_nwaiters; /* Number of waiters */ sem_t tg_exitsem; /* Support for waitpid */ int *tg_statloc; /* Location to return exit status */ #endif diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c index a08682676d..57cb867f8d 100644 --- a/mm/mm_heap/mm_free.c +++ b/mm/mm_heap/mm_free.c @@ -44,14 +44,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_zalloc.c b/mm/mm_heap/mm_zalloc.c index deb3408d67..a9d5af9525 100644 --- a/mm/mm_heap/mm_zalloc.c +++ b/mm/mm_heap/mm_zalloc.c @@ -43,10 +43,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/Make.defs b/sched/group/Make.defs index e3b4cba93b..91a025e1fd 100644 --- a/sched/group/Make.defs +++ b/sched/group/Make.defs @@ -42,6 +42,10 @@ CSRCS += task_reparent.c ifeq ($(CONFIG_SCHED_CHILD_STATUS),y) CSRCS += group_childstatus.c endif +else +ifeq ($(CONFIG_SCHED_WAITPID),y) +CSRCS += group_waiter.c +endif endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/sched/group/group.h b/sched/group/group.h index 2dc74e709a..a508d5d462 100644 --- a/sched/group/group.h +++ b/sched/group/group.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group.h * - * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -102,6 +102,10 @@ int group_bind(FAR struct pthread_tcb_s *tcb); int group_join(FAR struct pthread_tcb_s *tcb); #endif void group_leave(FAR struct tcb_s *tcb); +#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT) +void group_addwaiter(FAR struct task_group_s *group); +void group_delwaiter(FAR struct task_group_s *group); +#endif #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) FAR struct task_group_s *group_findbygid(gid_t gid); diff --git a/sched/group/group_free.c b/sched/group/group_free.c index 2a4f309739..c7b0342adb 100644 --- a/sched/group/group_free.c +++ b/sched/group/group_free.c @@ -50,26 +50,6 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -100,7 +80,7 @@ void group_free(FAR struct task_group_s *group, FAR void *mem) { /* It is a privileged group... use the kernel mode memory allocator */ - return kmm_free(mem); + kmm_free(mem); } else { @@ -108,7 +88,7 @@ void group_free(FAR struct task_group_s *group, FAR void *mem) * allocator. */ - return kumm_free(mem); + kumm_free(mem); } } diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 276617c2bb..c22c0aee48 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_leave.c * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,18 +56,6 @@ #ifdef HAVE_TASK_GROUP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -271,9 +259,23 @@ static inline void group_release(FAR struct task_group_s *group) # endif #endif - /* Release the group container itself */ +#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT) + /* If there are threads waiting for this group to be freed, then we cannot + * yet free the memory resources. Instead just mark the group deleted + * and wait for those threads complete their waits. + */ + + if (group->tg_nwaiters > 0) + { + group->tg_flags |= GROUP_FLAG_DELETED; + } + else +#endif + { + /* Release the group container itself */ - sched_kfree(group); + sched_kfree(group); + } } /**************************************************************************** diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 371df3f767..84e197a288 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -51,10 +51,6 @@ #ifdef CONFIG_SCHED_WAITPID -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -217,6 +213,10 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) group = ctcb->group; DEBUGASSERT(group); + /* Lock this group so that it cannot be deleted until the wait completes */ + + group_addwaiter(group); + /* "If more than one thread is suspended in waitpid() awaiting termination of * the same process, exactly one thread will return the process status at the * time of the target process termination." Hmmm.. what do we return to the @@ -236,6 +236,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Don't wait if status is not available */ ret = sem_trywait(&group->tg_exitsem); + group_delwaiter(group); + if (ret < 0) { pid = 0; @@ -246,6 +248,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Wait if necessary for status to become available */ ret = sem_wait(&group->tg_exitsem); + group_delwaiter(group); + if (ret < 0) { /* Unlock pre-emption and return the ERROR (sem_wait has already set diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 7a2db8d0b4..3b5b2b7286 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -68,11 +68,7 @@ typedef int (*holderhandler_t)(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg); /**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* Preallocated holder structures */ @@ -82,10 +78,6 @@ static struct semholder_s g_holderalloc[CONFIG_SEM_PREALLOCHOLDERS]; static FAR struct semholder_s *g_freeholders; #endif -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Name: sem_allocholder ****************************************************************************/ diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index 5804fac1c5..b7d5378295 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From 198cfd02244749b4b8cb5d20b5e55598023999e6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 22 Dec 2015 12:06:05 -0600 Subject: [PATCH 470/858] Forgot to add a file needed in the last commit --- sched/group/group_waiter.c | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 sched/group/group_waiter.c diff --git a/sched/group/group_waiter.c b/sched/group/group_waiter.c new file mode 100644 index 0000000000..9baa5cd65b --- /dev/null +++ b/sched/group/group_waiter.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * sched/group/group_waiter.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "nuttx/sched.h" +#include "group/group.h" + +#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_addwaiter + * + * Description: + * Increment the number of instances of waitpid that are waiting for this + * group to exit. + * + * Assumptions: + * Caller has assured mutually exclusive access to the group. + * + ****************************************************************************/ + +void group_addwaiter(FAR struct task_group_s *group) +{ + group->tg_nwaiters++; + DEBUGASSERT(group->tg_nwaiters > 0); +} + +/**************************************************************************** + * Name: group_addwaiter + * + * Description: + * Decrement the number of instances of waitpid that are waiting for this + * group to exit. If the count goes to zero and deletion is pending, the + * call group_free to release the dangling resources. + * + * Assumptions: + * Caller has assured mutually exclusive access to the group. + * + ****************************************************************************/ + +void group_delwaiter(FAR struct task_group_s *group) +{ + DEBUGASSERT(group->tg_nwaiters > 0); + group->tg_nwaiters--; + if (group->tg_nwaiters == 0 && (group->tg_flags & GROUP_FLAG_DELETED) != 0) + { + /* Release the group container (all other resources have already been + * freed). + */ + + sched_kfree(group); + } +} + +#endif /* CONFIG_SCHED_WAITPID && !CONFIG_SCHED_HAVE_PARENT */ -- GitLab From 3036e53be4f9a52cb233a533f5196d2db6273f0c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Dec 2015 08:19:13 -0600 Subject: [PATCH 471/858] Update TODO list --- TODO | 14 ++++++++++++-- arch | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index d7702ab3a6..3e11ed34b2 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated December 7, 2015) +NuttX TODO List (Last updated December 23, 2015) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -14,7 +14,7 @@ nuttx/ (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) - (7) Kernel/Protected Build + (8) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) (11) Network (net/, drivers/net) @@ -471,6 +471,16 @@ o Kernel/Protected Build Status: Open Priority: Medium + Title: I2C TOOL PATITIONING + Description: The tool at apps/system/i2c makes direct calls into MCU level + I2C logic within the OS and, hence, violates the OS/application + interface. An I2C character driver will need to be developed + to perform the I2C interactions within the OS; the I2C tools + will need to be modified to use that driver to perform the + I2C accesses. + Status: Open + Priority: Medium. Until this change is made, the I2C tool will not be + availabel in protected or kernel builds. Title: C++ CONSTRUCTORS HAVE TOO MANY PRIVILEGES (PROTECTED MODE) Description: When a C++ ELF module is loaded, its C++ constructors are called via sched/task_starthook.c logic. This logic runs in protected mode. diff --git a/arch b/arch index 1519d53e18..2270b10d5a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1519d53e182663632e4b115baa1b3b15ce9840a3 +Subproject commit 2270b10d5a3b4bb0abd971664a4a6370c30efc52 -- GitLab From 86935ca2dcd290d8ff6593c60ca7a459ff67e717 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Dec 2015 09:49:58 -0600 Subject: [PATCH 472/858] Update README --- Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index 37c9f22b0c..fad904fdf9 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 37c9f22b0cc785c3120efd6041a9b7233dde51bc +Subproject commit fad904fdf955e20b9c96d51abe10df13eafc645d diff --git a/README.txt b/README.txt index df625bcb75..da9540d0d6 100644 --- a/README.txt +++ b/README.txt @@ -1309,6 +1309,8 @@ nuttx/ | | `- README.txt | |- kwikstik-k40/ | | `- README.txt + | |- launchxl-tms57004/ + | | `- README.txt | |- lincoln60/ | | `- README.txt | |- lm3s6432-s2e/ diff --git a/arch b/arch index 2270b10d5a..362ac0b7d7 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 2270b10d5a3b4bb0abd971664a4a6370c30efc52 +Subproject commit 362ac0b7d75cabd5f2b1d4c051759a1bc748726b diff --git a/configs b/configs index b30cbace6a..1396fd342e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b30cbace6afab3caed2dcfec09071af60a2b0d7f +Subproject commit 1396fd342ee0f6430de37047a7cbdf227b51eec3 -- GitLab From 3002023798a3a72187790005ecf09f9adb0c9049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20St=C3=BChn?= Date: Wed, 23 Dec 2015 15:13:01 -0600 Subject: [PATCH 473/858] =?UTF-8?q?time.h:=20Add=20timeradd(),=20timersub(?= =?UTF-8?q?),=20timerclear(),=20timerisset(),=20and=20timercmp()=20as=20ma?= =?UTF-8?q?cros.=20These=20are=20non-POSIX=20interfaces,=20but=20included?= =?UTF-8?q?=20in=20most=20BSD=20deriviatives,=20included=20Linux.=20=20Fro?= =?UTF-8?q?m=20Manuel=20St=C3=BChn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 4 ++++ arch | 2 +- configs | 2 +- include/time.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 091fc549ce..44ef649360 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11247,4 +11247,8 @@ * waitpid: CRITICAL BUGFIX. Add a reference count to prevent waitpid from using stale memory released by the waited-for task group (2015-12-22). + * time.h: Add timeradd(), timersub(), timerclear(), timerisset(), + and timercmp() as macros. These are non-POSIX interfaces, but + included in most BSD deriviatives, included Linux. From Manuel Stühn + (2015-12-23). diff --git a/arch b/arch index 362ac0b7d7..27b79f79b0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 362ac0b7d75cabd5f2b1d4c051759a1bc748726b +Subproject commit 27b79f79b0f9a1929a21921fbb97a553d87886c9 diff --git a/configs b/configs index 1396fd342e..3042534b17 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 1396fd342ee0f6430de37047a7cbdf227b51eec3 +Subproject commit 3042534b17f48c84cf556ad691afe6f29e7e55bd diff --git a/include/time.h b/include/time.h index 0fd4b7611b..2e85f8e51c 100644 --- a/include/time.h +++ b/include/time.h @@ -100,6 +100,63 @@ # define localtime_r(c,r) gmtime_r(c,r) #endif +/* The following are non-standard interfaces in the sense that they are not + * in POSIX.1-2001. These interfaces are present on most BSD derivatives, + * however, including Linux. + */ + +/* void timeradd(struct timeval *a, struct timeval *b, struct timeval *res); */ + +#define timeradd(tvp, uvp, vvp) \ + do \ + { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) \ + { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } \ + while (0) + +/* void timersub(struct timeval *a, struct timeval *b, struct timeval *res); */ + +#define timersub(tvp, uvp, vvp) \ + do \ + { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) \ + { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } \ + while (0) + +/* void timerclear(struct timeval *tvp); */ + +#define timerclear(tvp) \ + do \ + { \ + tvp)->tv_sec = 0; \ + tvp)->tv_usec = 0; \ + } \ + while (0) + +/* int timerisset(struct timeval *tvp); */ + +#define timerisset(tvp) \ + ((tvp)->tv_sec != 0 || (tvp)->tv_usec != 0) + +/* int timercmp(struct timeval *a, struct timeval *b, CMP); */ + +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + /******************************************************************************** * Public Types ********************************************************************************/ -- GitLab From 5d84cd5d1187ff7bcbaa1c21ddfe2e659ee97653 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Dec 2015 15:17:16 -0600 Subject: [PATCH 474/858] Improve a few comments --- include/time.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/time.h b/include/time.h index 2e85f8e51c..a20bf92509 100644 --- a/include/time.h +++ b/include/time.h @@ -101,11 +101,13 @@ #endif /* The following are non-standard interfaces in the sense that they are not - * in POSIX.1-2001. These interfaces are present on most BSD derivatives, - * however, including Linux. + * in POSIX.1-2001 nor are the specifed at OpenGroup.org. These interfaces + * are present on most BSD derivatives, however, including Linux. */ -/* void timeradd(struct timeval *a, struct timeval *b, struct timeval *res); */ +/* void timeradd(FAR struct timeval *a, FAR struct timeval *b, + * FAR struct timeval *res); + */ #define timeradd(tvp, uvp, vvp) \ do \ @@ -120,7 +122,9 @@ } \ while (0) -/* void timersub(struct timeval *a, struct timeval *b, struct timeval *res); */ +/* void timersub(FAR struct timeval *a, FAR struct timeval *b, + * FAR struct timeval *res); + */ #define timersub(tvp, uvp, vvp) \ do \ @@ -135,7 +139,7 @@ } \ while (0) -/* void timerclear(struct timeval *tvp); */ +/* void timerclear(FAR struct timeval *tvp); */ #define timerclear(tvp) \ do \ @@ -145,12 +149,12 @@ } \ while (0) -/* int timerisset(struct timeval *tvp); */ +/* int timerisset(FAR struct timeval *tvp); */ #define timerisset(tvp) \ ((tvp)->tv_sec != 0 || (tvp)->tv_usec != 0) -/* int timercmp(struct timeval *a, struct timeval *b, CMP); */ +/* int timercmp(FAR struct timeval *a, FAR struct timeval *b, CMP); */ #define timercmp(tvp, uvp, cmp) \ (((tvp)->tv_sec == (uvp)->tv_sec) ? \ -- GitLab From 7110634a386006e96520b6e5dafcf991f79a4ebf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Dec 2015 16:09:49 -0600 Subject: [PATCH 475/858] Trivial typo fix in a comment --- arch | 2 +- include/time.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 27b79f79b0..9775903683 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 27b79f79b0f9a1929a21921fbb97a553d87886c9 +Subproject commit 977590368311be209b384ccf611b4c00136472d2 diff --git a/include/time.h b/include/time.h index a20bf92509..2c2fe1da2b 100644 --- a/include/time.h +++ b/include/time.h @@ -101,7 +101,7 @@ #endif /* The following are non-standard interfaces in the sense that they are not - * in POSIX.1-2001 nor are the specifed at OpenGroup.org. These interfaces + * in POSIX.1-2001 nor are they specified at OpenGroup.org. These interfaces * are present on most BSD derivatives, however, including Linux. */ -- GitLab From 4350b0ba0cc56b3b18025fffd90556a5209d2d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20St=C3=BChn?= Date: Thu, 24 Dec 2015 07:09:39 -0600 Subject: [PATCH 476/858] Move macros timeradd() and friends from time.h to sys/time.h. --- ChangeLog | 2 +- arch | 2 +- include/sys/time.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++ include/time.h | 61 ---------------------------------------------- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44ef649360..c5deead972 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11247,7 +11247,7 @@ * waitpid: CRITICAL BUGFIX. Add a reference count to prevent waitpid from using stale memory released by the waited-for task group (2015-12-22). - * time.h: Add timeradd(), timersub(), timerclear(), timerisset(), + * sys/time.h: Add timeradd(), timersub(), timerclear(), timerisset(), and timercmp() as macros. These are non-POSIX interfaces, but included in most BSD deriviatives, included Linux. From Manuel Stühn (2015-12-23). diff --git a/arch b/arch index 9775903683..623c2bd99d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 977590368311be209b384ccf611b4c00136472d2 +Subproject commit 623c2bd99d8ad753f87ce4db271ffddf4bb1fd68 diff --git a/include/sys/time.h b/include/sys/time.h index 20ff459e1b..ecc2fc8401 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -48,6 +48,67 @@ * Pre-processor Definitions ****************************************************************************/ +/* The following are non-standard interfaces in the sense that they are not + * in POSIX.1-2001 nor are they specified at OpenGroup.org. These interfaces + * are present on most BSD derivatives, however, including Linux. + */ + +/* void timeradd(FAR struct timeval *a, FAR struct timeval *b, + * FAR struct timeval *res); + */ + +#define timeradd(tvp, uvp, vvp) \ + do \ + { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) \ + { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } \ + while (0) + +/* void timersub(FAR struct timeval *a, FAR struct timeval *b, + * FAR struct timeval *res); + */ + +#define timersub(tvp, uvp, vvp) \ + do \ + { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) \ + { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } \ + while (0) + +/* void timerclear(FAR struct timeval *tvp); */ + +#define timerclear(tvp) \ + do \ + { \ + tvp)->tv_sec = 0; \ + tvp)->tv_usec = 0; \ + } \ + while (0) + +/* int timerisset(FAR struct timeval *tvp); */ + +#define timerisset(tvp) \ + ((tvp)->tv_sec != 0 || (tvp)->tv_usec != 0) + +/* int timercmp(FAR struct timeval *a, FAR struct timeval *b, CMP); */ + +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/include/time.h b/include/time.h index 2c2fe1da2b..0fd4b7611b 100644 --- a/include/time.h +++ b/include/time.h @@ -100,67 +100,6 @@ # define localtime_r(c,r) gmtime_r(c,r) #endif -/* The following are non-standard interfaces in the sense that they are not - * in POSIX.1-2001 nor are they specified at OpenGroup.org. These interfaces - * are present on most BSD derivatives, however, including Linux. - */ - -/* void timeradd(FAR struct timeval *a, FAR struct timeval *b, - * FAR struct timeval *res); - */ - -#define timeradd(tvp, uvp, vvp) \ - do \ - { \ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ - if ((vvp)->tv_usec >= 1000000) \ - { \ - (vvp)->tv_sec++; \ - (vvp)->tv_usec -= 1000000; \ - } \ - } \ - while (0) - -/* void timersub(FAR struct timeval *a, FAR struct timeval *b, - * FAR struct timeval *res); - */ - -#define timersub(tvp, uvp, vvp) \ - do \ - { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) \ - { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } \ - while (0) - -/* void timerclear(FAR struct timeval *tvp); */ - -#define timerclear(tvp) \ - do \ - { \ - tvp)->tv_sec = 0; \ - tvp)->tv_usec = 0; \ - } \ - while (0) - -/* int timerisset(FAR struct timeval *tvp); */ - -#define timerisset(tvp) \ - ((tvp)->tv_sec != 0 || (tvp)->tv_usec != 0) - -/* int timercmp(FAR struct timeval *a, FAR struct timeval *b, CMP); */ - -#define timercmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) - /******************************************************************************** * Public Types ********************************************************************************/ -- GitLab From 4832de4022a360719d53bb0798b0097186508072 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Dec 2015 07:40:16 -0600 Subject: [PATCH 477/858] Update ChangeLog --- ChangeLog | 3 ++- arch | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5deead972..ba3080c428 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11251,4 +11251,5 @@ and timercmp() as macros. These are non-POSIX interfaces, but included in most BSD deriviatives, included Linux. From Manuel Stühn (2015-12-23). - + * arch/arm/src/stm32: Add timer input capture driver. From Pierre-Noel + Bouteville (2015-12-24). diff --git a/arch b/arch index 623c2bd99d..4045ca3c75 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 623c2bd99d8ad753f87ce4db271ffddf4bb1fd68 +Subproject commit 4045ca3c75a109d253137f1fae70017d2cdd64cf -- GitLab From 239c92ec2b0579ea6c3ac7690271355a40a992ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Dec 2015 13:47:53 -0600 Subject: [PATCH 478/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 4045ca3c75..d7d9c92a8f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4045ca3c75a109d253137f1fae70017d2cdd64cf +Subproject commit d7d9c92a8fdf84a14d03b6e1e7c099d4ad623400 diff --git a/configs b/configs index 3042534b17..7bd42035e0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3042534b17f48c84cf556ad691afe6f29e7e55bd +Subproject commit 7bd42035e04fcc31e13b1a0e15e643395a591a69 -- GitLab From 0f2a48f6405c1492d19b68a0e8311344bdba5b25 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Dec 2015 15:19:38 -0600 Subject: [PATCH 479/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index d7d9c92a8f..8f74422447 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d7d9c92a8fdf84a14d03b6e1e7c099d4ad623400 +Subproject commit 8f744224475db38ca6403d6c1fb39326ebca6061 diff --git a/configs b/configs index 7bd42035e0..c1419c8491 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7bd42035e04fcc31e13b1a0e15e643395a591a69 +Subproject commit c1419c849126f8dc841b74e8103339d32edb85c0 -- GitLab From 5d95abc679de2e8fd64dffe6812335187f2ce2f5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Dec 2015 12:06:05 -0600 Subject: [PATCH 480/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 8f74422447..0003134259 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8f744224475db38ca6403d6c1fb39326ebca6061 +Subproject commit 00031342595b03ead4fbf56debee2668e7a5369c diff --git a/configs b/configs index c1419c8491..c8b73b65e5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c1419c849126f8dc841b74e8103339d32edb85c0 +Subproject commit c8b73b65e56ababde5cb4eabb272d370fc880ba4 -- GitLab From 658272bbbf34784ee063bdccd8594af64720b808 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Dec 2015 14:49:40 -0600 Subject: [PATCH 481/858] FAT: Fix some duplicate definition warnings when big-endian is enabled --- arch | 2 +- configs | 2 +- fs/fat/fs_fat32.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 0003134259..bc376e7024 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 00031342595b03ead4fbf56debee2668e7a5369c +Subproject commit bc376e70244b491bb8150f15fe9acad0770df703 diff --git a/configs b/configs index c8b73b65e5..77dd18490e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c8b73b65e56ababde5cb4eabb272d370fc880ba4 +Subproject commit 77dd18490ec36d463577878c6c79b694395089f2 diff --git a/fs/fat/fs_fat32.h b/fs/fat/fs_fat32.h index 6c4aa846fd..5b13b0a6c2 100644 --- a/fs/fat/fs_fat32.h +++ b/fs/fat/fs_fat32.h @@ -495,7 +495,7 @@ # define LDIR_GETWCHAR6(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11)) # define LDIR_GETWCHAR7(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+2)) # define LDIR_GETWCHAR8(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+4)) -# define LDIR_GETWCHAR8(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+6)) +# define LDIR_GETWCHAR9(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+6)) # define LDIR_GETWCHAR10(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+8)) # define LDIR_GETWCHAR11(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+10)) # define LDIR_GETWCHAR12(p) fat_getuint16(UBYTE_PTR(p,LDIR_WCHAR12_13)) @@ -550,7 +550,7 @@ # define LDIR_PUTWCHAR6(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11),v) # define LDIR_PUTWCHAR7(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+2),v) # define LDIR_PUTWCHAR8(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+4),v) -# define LDIR_PUTWCHAR8(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+6),v) +# define LDIR_PUTWCHAR9(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+6),v) # define LDIR_PUTWCHAR10(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+8),v) # define LDIR_PUTWCHAR11(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR6_11+10),v) # define LDIR_PUTWCHAR12(p) fat_putuint16(UBYTE_PTR(p,LDIR_WCHAR12_13),v) -- GitLab From 5206f8430ff79b025f936eca0bdb8e3db72c6e9e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Dec 2015 18:13:25 -0600 Subject: [PATCH 482/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index bc376e7024..126fdebf23 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bc376e70244b491bb8150f15fe9acad0770df703 +Subproject commit 126fdebf23f1357342a60269719040d214f59b96 diff --git a/configs b/configs index 77dd18490e..806cc18a73 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 77dd18490ec36d463577878c6c79b694395089f2 +Subproject commit 806cc18a73ca00d153fe992e211ccf0193dbc3f2 -- GitLab From e7c753801d4f2c1f083a8a071153a51822e3d675 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 28 Dec 2015 16:22:04 -0600 Subject: [PATCH 483/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 126fdebf23..b4b388d0c2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 126fdebf23f1357342a60269719040d214f59b96 +Subproject commit b4b388d0c280ebe5790a6137871269b01f41bf81 diff --git a/configs b/configs index 806cc18a73..0c2dacaf63 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 806cc18a73ca00d153fe992e211ccf0193dbc3f2 +Subproject commit 0c2dacaf636ddbc33f33823ff068e7f6320a78fc -- GitLab From fc30b31ed39066e67f39018027847dc3d17fec66 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Dec 2015 13:05:34 -0600 Subject: [PATCH 484/858] Update ChangeLog --- ChangeLog | 5 +++++ Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba3080c428..80e9b51499 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11253,3 +11253,8 @@ (2015-12-23). * arch/arm/src/stm32: Add timer input capture driver. From Pierre-Noel Bouteville (2015-12-24). + * arch/avr: Add support for the Atmega2560. From Dimitry Kloper + (2015-12-19). + * configs/arduino-mega2560: Add support for the Arduino-Mega2560. From + Dimitry Koper (2015-12-29). + diff --git a/Documentation b/Documentation index fad904fdf9..601bc2284c 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit fad904fdf955e20b9c96d51abe10df13eafc645d +Subproject commit 601bc2284cb4ff212ae6f1bb09cb9e0733bd1b38 diff --git a/README.txt b/README.txt index da9540d0d6..48fcea6396 100644 --- a/README.txt +++ b/README.txt @@ -1256,6 +1256,8 @@ nuttx/ |- configs/ | |- amber/ | | `- README.txt + | |- arduino-mega2560/ + | | `- README.txt | |- arduino-due/ | | `- README.txt | |- avr32dev1/ diff --git a/arch b/arch index b4b388d0c2..230f8d050f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b4b388d0c280ebe5790a6137871269b01f41bf81 +Subproject commit 230f8d050f4cb535b4047ba2e5fbea8b50b70671 diff --git a/configs b/configs index 0c2dacaf63..9ab677b8e1 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0c2dacaf636ddbc33f33823ff068e7f6320a78fc +Subproject commit 9ab677b8e16ab2d2d1a7ac25893503ce0fadabde -- GitLab From b682190f52c906616556a47f8ab74f5ef1087230 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Dec 2015 17:31:17 -0600 Subject: [PATCH 485/858] Rename all head files in main NuttX repository with names like *internal.h, removing the internal --- ChangeLog | 2 +- Documentation | 2 +- configs | 2 +- drivers/mmcsd/{mmcsd_internal.h => mmcsd.h} | 8 ++++---- drivers/mmcsd/mmcsd_debug.c | 2 +- drivers/mmcsd/mmcsd_sdio.c | 2 +- drivers/mmcsd/mmcsd_spi.c | 2 +- libc/aio/lio_listio.c | 2 +- libc/audio/lib_buffer.c | 2 +- libc/{lib_internal.h => libc.h} | 8 ++++---- libc/math/lib_exp.c | 2 +- libc/math/lib_expf.c | 2 +- libc/math/lib_expl.c | 2 +- libc/math/lib_sqrt.c | 2 +- libc/math/lib_sqrtf.c | 2 +- libc/math/lib_sqrtl.c | 2 +- libc/misc/lib_dbg.c | 2 +- libc/misc/lib_filesem.c | 2 +- libc/misc/lib_ioctl.c | 2 +- libc/misc/lib_sendfile.c | 2 +- libc/misc/lib_stream.c | 2 +- libc/misc/lib_streamsem.c | 2 +- libc/netdb/lib_gethostbyaddr.c | 2 +- libc/netdb/lib_gethostbyaddrr.c | 2 +- libc/netdb/lib_gethostbyname.c | 2 +- libc/netdb/lib_gethostbynamer.c | 2 +- libc/netdb/lib_parsehostfile.c | 2 +- libc/spawn/lib_psfa_addclose.c | 2 +- libc/spawn/lib_psfa_adddup2.c | 2 +- libc/spawn/lib_psfa_addopen.c | 2 +- libc/spawn/lib_psfa_destroy.c | 2 +- libc/stdio/lib_asprintf.c | 2 +- libc/stdio/lib_dtoa.c | 2 +- libc/stdio/lib_fclose.c | 2 +- libc/stdio/lib_fflush.c | 2 +- libc/stdio/lib_fgetc.c | 2 +- libc/stdio/lib_fgetpos.c | 2 +- libc/stdio/lib_fgets.c | 2 +- libc/stdio/lib_fopen.c | 2 +- libc/stdio/lib_fputc.c | 2 +- libc/stdio/lib_fputs.c | 2 +- libc/stdio/lib_fread.c | 2 +- libc/stdio/lib_freopen.c | 2 +- libc/stdio/lib_fseek.c | 2 +- libc/stdio/lib_fsetpos.c | 2 +- libc/stdio/lib_ftell.c | 2 +- libc/stdio/lib_fwrite.c | 2 +- libc/stdio/lib_gets.c | 2 +- libc/stdio/lib_gets_s.c | 2 +- libc/stdio/lib_libdtoa.c | 2 +- libc/stdio/lib_libfflush.c | 2 +- libc/stdio/lib_libfgets.c | 2 +- libc/stdio/lib_libflushall.c | 2 +- libc/stdio/lib_libfread.c | 2 +- libc/stdio/lib_libfwrite.c | 2 +- libc/stdio/lib_libnoflush.c | 2 +- libc/stdio/lib_libsnoflush.c | 2 +- libc/stdio/lib_libsprintf.c | 2 +- libc/stdio/lib_libvsprintf.c | 2 +- libc/stdio/lib_lowinstream.c | 2 +- libc/stdio/lib_lowoutstream.c | 2 +- libc/stdio/lib_meminstream.c | 2 +- libc/stdio/lib_memoutstream.c | 2 +- libc/stdio/lib_memsistream.c | 2 +- libc/stdio/lib_memsostream.c | 2 +- libc/stdio/lib_nullinstream.c | 2 +- libc/stdio/lib_nulloutstream.c | 2 +- libc/stdio/lib_printf.c | 2 +- libc/stdio/lib_puts.c | 2 +- libc/stdio/lib_rawinstream.c | 2 +- libc/stdio/lib_rawoutstream.c | 2 +- libc/stdio/lib_rawsistream.c | 2 +- libc/stdio/lib_rawsostream.c | 2 +- libc/stdio/lib_rdflush.c | 2 +- libc/stdio/lib_snprintf.c | 2 +- libc/stdio/lib_sprintf.c | 2 +- libc/stdio/lib_stdinstream.c | 2 +- libc/stdio/lib_stdoutstream.c | 2 +- libc/stdio/lib_stdsistream.c | 2 +- libc/stdio/lib_stdsostream.c | 2 +- libc/stdio/lib_ungetc.c | 2 +- libc/stdio/lib_vasprintf.c | 2 +- libc/stdio/lib_vdprintf.c | 2 +- libc/stdio/lib_vfprintf.c | 2 +- libc/stdio/lib_vsnprintf.c | 2 +- libc/stdio/lib_vsprintf.c | 2 +- libc/stdio/lib_wrflush.c | 2 +- libc/stdio/lib_zeroinstream.c | 2 +- libc/stdlib/lib_checkbase.c | 2 +- libc/stdlib/lib_strtol.c | 2 +- libc/stdlib/lib_strtoll.c | 2 +- libc/stdlib/lib_strtoul.c | 2 +- libc/stdlib/lib_strtoull.c | 2 +- libc/string/lib_isbasedigit.c | 2 +- libc/string/lib_skipspace.c | 2 +- libc/string/lib_strdup.c | 2 +- libc/string/lib_strndup.c | 2 +- libc/unistd/lib_chdir.c | 2 +- libc/unistd/lib_getcwd.c | 2 +- libnx/nxfonts/{nxfonts_internal.h => nxfonts.h} | 8 ++++---- libnx/nxfonts/nxfonts_bitmaps.c | 2 +- libnx/nxfonts/nxfonts_convert.c | 2 +- libnx/nxfonts/nxfonts_getfont.c | 2 +- libnx/nxtk/{nxtk_internal.h => nxtk.h} | 8 ++++---- libnx/nxtk/nxtk_bitmaptoolbar.c | 2 +- libnx/nxtk/nxtk_bitmapwindow.c | 2 +- libnx/nxtk/nxtk_closetoolbar.c | 2 +- libnx/nxtk/nxtk_closewindow.c | 2 +- libnx/nxtk/nxtk_containerclip.c | 2 +- libnx/nxtk/nxtk_drawframe.c | 2 +- libnx/nxtk/nxtk_events.c | 2 +- libnx/nxtk/nxtk_filltoolbar.c | 2 +- libnx/nxtk/nxtk_filltraptoolbar.c | 2 +- libnx/nxtk/nxtk_filltrapwindow.c | 2 +- libnx/nxtk/nxtk_fillwindow.c | 2 +- libnx/nxtk/nxtk_getposition.c | 2 +- libnx/nxtk/nxtk_gettoolbar.c | 2 +- libnx/nxtk/nxtk_getwindow.c | 2 +- libnx/nxtk/nxtk_lower.c | 2 +- libnx/nxtk/nxtk_movetoolbar.c | 2 +- libnx/nxtk/nxtk_movewindow.c | 2 +- libnx/nxtk/nxtk_opentoolbar.c | 2 +- libnx/nxtk/nxtk_openwindow.c | 2 +- libnx/nxtk/nxtk_raise.c | 2 +- libnx/nxtk/nxtk_setposition.c | 2 +- libnx/nxtk/nxtk_setsize.c | 2 +- libnx/nxtk/nxtk_setsubwindows.c | 2 +- libnx/nxtk/nxtk_subwindowclip.c | 2 +- libnx/nxtk/nxtk_subwindowmove.c | 2 +- libnx/nxtk/nxtk_toolbarbounds.c | 2 +- 130 files changed, 142 insertions(+), 142 deletions(-) rename drivers/mmcsd/{mmcsd_internal.h => mmcsd.h} (96%) rename libc/{lib_internal.h => libc.h} (98%) rename libnx/nxfonts/{nxfonts_internal.h => nxfonts.h} (94%) rename libnx/nxtk/{nxtk_internal.h => nxtk.h} (98%) diff --git a/ChangeLog b/ChangeLog index 80e9b51499..1dd1bee589 100755 --- a/ChangeLog +++ b/ChangeLog @@ -2741,7 +2741,7 @@ the worker thread, disabling interrupts does not provide protected; Need to disable pre-emption. (2) Fix handling of touch ID and (2) add some logic to prevent certain kinds of data overrun. - * include/nx/nxtk.h and graphics/nx/nxtk/nxtk_internal.h: Move setting + * include/nx/nxtk.h and graphics/nx/nxtk/nxtk.h: Move setting of configuration defaults from the internal header file to a place where other logic can use the defaults. * graphics/nxtk/nxtk_events.c: Fixed an important but in the logic that diff --git a/Documentation b/Documentation index 601bc2284c..c825944849 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 601bc2284cb4ff212ae6f1bb09cb9e0733bd1b38 +Subproject commit c82594484958132e9267cd7bacb47579874a12ba diff --git a/configs b/configs index 9ab677b8e1..f6782b7548 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 9ab677b8e16ab2d2d1a7ac25893503ce0fadabde +Subproject commit f6782b75481a49e19709a7e1593d40346716f5e4 diff --git a/drivers/mmcsd/mmcsd_internal.h b/drivers/mmcsd/mmcsd.h similarity index 96% rename from drivers/mmcsd/mmcsd_internal.h rename to drivers/mmcsd/mmcsd.h index 36843685d8..06d91348d0 100644 --- a/drivers/mmcsd/mmcsd_internal.h +++ b/drivers/mmcsd/mmcsd.h @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/mmcsd/mmcsd_internal.h + * drivers/mmcsd/mmcsd.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __DRIVERS_MMCSD_MMCSD_INTERNAL_H -#define __DRIVERS_MMCSD_MMCSD_INTERNAL_H +#ifndef __DRIVERS_MMCSD_MMCSD_H +#define __DRIVERS_MMCSD_MMCSD_H /**************************************************************************** * Included Files @@ -102,4 +102,4 @@ EXTERN void mmcsd_dmpcsd(FAR const uint8_t *csd, uint8_t cardtype); #if defined(__cplusplus) } #endif -#endif /* __DRIVERS_MMCSD_MMCSD_INTERNAL_H */ +#endif /* __DRIVERS_MMCSD_MMCSD_H */ diff --git a/drivers/mmcsd/mmcsd_debug.c b/drivers/mmcsd/mmcsd_debug.c index ea3788a29b..e28b985a02 100644 --- a/drivers/mmcsd/mmcsd_debug.c +++ b/drivers/mmcsd/mmcsd_debug.c @@ -47,7 +47,7 @@ #include #include "mmcsd_csd.h" -#include "mmcsd_internal.h" +#include "mmcsd.h" /**************************************************************************** * Pre-processor Definitions diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 2a1be9595d..d8ae4561af 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -65,7 +65,7 @@ #include #include -#include "mmcsd_internal.h" +#include "mmcsd.h" #include "mmcsd_sdio.h" /**************************************************************************** diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index 64f67a797d..7219648845 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -59,7 +59,7 @@ #include "mmcsd_spi.h" #include "mmcsd_csd.h" -#include "mmcsd_internal.h" +#include "mmcsd.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index 0889fd9b14..b552817e09 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #include "aio/aio.h" #ifdef CONFIG_FS_AIO diff --git a/libc/audio/lib_buffer.c b/libc/audio/lib_buffer.c index f69a2066ed..f7e29dd033 100644 --- a/libc/audio/lib_buffer.c +++ b/libc/audio/lib_buffer.c @@ -52,7 +52,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if defined(CONFIG_AUDIO) diff --git a/libc/lib_internal.h b/libc/libc.h similarity index 98% rename from libc/lib_internal.h rename to libc/libc.h index 29bbd136f5..9cb1974fa9 100644 --- a/libc/lib_internal.h +++ b/libc/libc.h @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/lib_internal.h + * libc/libc.h * * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __LIBC_LIB_INTERNAL_H -#define __LIBC_LIB_INTERNAL_H +#ifndef __LIBC_LIBC_H +#define __LIBC_LIBC_H /**************************************************************************** * Included Files @@ -233,4 +233,4 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host, } #endif -#endif /* __LIBC_LIB_INTERNAL_H */ +#endif /* __LIBC_LIBC_H */ diff --git a/libc/math/lib_exp.c b/libc/math/lib_exp.c index 738bd3f76b..211b23bf95 100644 --- a/libc/math/lib_exp.c +++ b/libc/math/lib_exp.c @@ -35,7 +35,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_HAVE_DOUBLE diff --git a/libc/math/lib_expf.c b/libc/math/lib_expf.c index 36788b60ad..4ce5208607 100644 --- a/libc/math/lib_expf.c +++ b/libc/math/lib_expf.c @@ -32,7 +32,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Data diff --git a/libc/math/lib_expl.c b/libc/math/lib_expl.c index 29f30ecd13..1021017ca3 100644 --- a/libc/math/lib_expl.c +++ b/libc/math/lib_expl.c @@ -35,7 +35,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_HAVE_LONG_DOUBLE diff --git a/libc/math/lib_sqrt.c b/libc/math/lib_sqrt.c index 7a3af561c6..8540744d21 100644 --- a/libc/math/lib_sqrt.c +++ b/libc/math/lib_sqrt.c @@ -35,7 +35,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/math/lib_sqrtf.c b/libc/math/lib_sqrtf.c index 0e9a55ac24..e1a107eb8b 100644 --- a/libc/math/lib_sqrtf.c +++ b/libc/math/lib_sqrtf.c @@ -35,7 +35,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/math/lib_sqrtl.c b/libc/math/lib_sqrtl.c index 15280a83f9..03a564f72d 100644 --- a/libc/math/lib_sqrtl.c +++ b/libc/math/lib_sqrtl.c @@ -35,7 +35,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/misc/lib_dbg.c b/libc/misc/lib_dbg.c index aa0b857bb1..14044175b7 100644 --- a/libc/misc/lib_dbg.c +++ b/libc/misc/lib_dbg.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #ifndef CONFIG_CPP_HAVE_VARARGS diff --git a/libc/misc/lib_filesem.c b/libc/misc/lib_filesem.c index da52b5ae36..2fd5d1c9eb 100644 --- a/libc/misc/lib_filesem.c +++ b/libc/misc/lib_filesem.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if CONFIG_STDIO_BUFFER_SIZE > 0 diff --git a/libc/misc/lib_ioctl.c b/libc/misc/lib_ioctl.c index fa0d908042..0e7ca015d3 100644 --- a/libc/misc/lib_ioctl.c +++ b/libc/misc/lib_ioctl.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" #if defined(CONFIG_LIBC_IOCTL_VARIADIC) && CONFIG_NFILE_DESCRIPTORS > 0 diff --git a/libc/misc/lib_sendfile.c b/libc/misc/lib_sendfile.c index 4fa19b66a7..2313833dc7 100644 --- a/libc/misc/lib_sendfile.c +++ b/libc/misc/lib_sendfile.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 diff --git a/libc/misc/lib_stream.c b/libc/misc/lib_stream.c index 2ad3cd740e..f42b040cbb 100644 --- a/libc/misc/lib_stream.c +++ b/libc/misc/lib_stream.c @@ -48,7 +48,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if (!defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL)) || \ defined(__KERNEL__) diff --git a/libc/misc/lib_streamsem.c b/libc/misc/lib_streamsem.c index a403b71028..9f26d96a72 100644 --- a/libc/misc/lib_streamsem.c +++ b/libc/misc/lib_streamsem.c @@ -46,7 +46,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private types diff --git a/libc/netdb/lib_gethostbyaddr.c b/libc/netdb/lib_gethostbyaddr.c index 46c4d6dd56..c06f165404 100644 --- a/libc/netdb/lib_gethostbyaddr.c +++ b/libc/netdb/lib_gethostbyaddr.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #include "netdb/lib_netdb.h" #ifdef CONFIG_NETDB_HOSTFILE diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index 812b1fedb9..6dcb8e8ab1 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -48,7 +48,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #include "netdb/lib_netdb.h" #ifdef CONFIG_NETDB_HOSTFILE diff --git a/libc/netdb/lib_gethostbyname.c b/libc/netdb/lib_gethostbyname.c index 4aae74a204..aa492db779 100644 --- a/libc/netdb/lib_gethostbyname.c +++ b/libc/netdb/lib_gethostbyname.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #include "netdb/lib_netdb.h" #ifdef CONFIG_LIBC_NETDB diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 6b005743cf..747cf6a0c5 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -53,7 +53,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #include "netdb/lib_dns.h" #ifdef CONFIG_LIBC_NETDB diff --git a/libc/netdb/lib_parsehostfile.c b/libc/netdb/lib_parsehostfile.c index 177c00a3f3..0e2c5bdeff 100644 --- a/libc/netdb/lib_parsehostfile.c +++ b/libc/netdb/lib_parsehostfile.c @@ -50,7 +50,7 @@ #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_NETDB_HOSTFILE diff --git a/libc/spawn/lib_psfa_addclose.c b/libc/spawn/lib_psfa_addclose.c index eaf3e08892..3ee6f19083 100644 --- a/libc/spawn/lib_psfa_addclose.c +++ b/libc/spawn/lib_psfa_addclose.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/spawn/lib_psfa_adddup2.c b/libc/spawn/lib_psfa_adddup2.c index 5b4833c5b0..6473476275 100644 --- a/libc/spawn/lib_psfa_adddup2.c +++ b/libc/spawn/lib_psfa_adddup2.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/spawn/lib_psfa_addopen.c b/libc/spawn/lib_psfa_addopen.c index 4bb096efb7..7f22c06af8 100644 --- a/libc/spawn/lib_psfa_addopen.c +++ b/libc/spawn/lib_psfa_addopen.c @@ -47,7 +47,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/spawn/lib_psfa_destroy.c b/libc/spawn/lib_psfa_destroy.c index e4020304b1..73a5ea25f5 100644 --- a/libc/spawn/lib_psfa_destroy.c +++ b/libc/spawn/lib_psfa_destroy.c @@ -45,7 +45,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/stdio/lib_asprintf.c b/libc/stdio/lib_asprintf.c index 09e6f42e93..d61059f5b5 100644 --- a/libc/stdio/lib_asprintf.c +++ b/libc/stdio/lib_asprintf.c @@ -40,7 +40,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_dtoa.c b/libc/stdio/lib_dtoa.c index 68ae7b2098..e3452126d8 100644 --- a/libc/stdio/lib_dtoa.c +++ b/libc/stdio/lib_dtoa.c @@ -48,7 +48,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fclose.c b/libc/stdio/lib_fclose.c index ff54efba4c..35301fc6bb 100644 --- a/libc/stdio/lib_fclose.c +++ b/libc/stdio/lib_fclose.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/stdio/lib_fflush.c b/libc/stdio/lib_fflush.c index bb3d0313cd..d56f8fb75c 100644 --- a/libc/stdio/lib_fflush.c +++ b/libc/stdio/lib_fflush.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fgetc.c b/libc/stdio/lib_fgetc.c index 022aed1dcc..15ccb893dd 100644 --- a/libc/stdio/lib_fgetc.c +++ b/libc/stdio/lib_fgetc.c @@ -42,7 +42,7 @@ ****************************************************************************/ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fgetpos.c b/libc/stdio/lib_fgetpos.c index e2c4d0c696..ea49abb2ce 100644 --- a/libc/stdio/lib_fgetpos.c +++ b/libc/stdio/lib_fgetpos.c @@ -47,7 +47,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fgets.c b/libc/stdio/lib_fgets.c index 88dfca3ad1..bce8261e6e 100644 --- a/libc/stdio/lib_fgets.c +++ b/libc/stdio/lib_fgets.c @@ -41,7 +41,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fopen.c b/libc/stdio/lib_fopen.c index 957e439b19..b7208dba5f 100644 --- a/libc/stdio/lib_fopen.c +++ b/libc/stdio/lib_fopen.c @@ -47,7 +47,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fputc.c b/libc/stdio/lib_fputc.c index f434d442e2..9ba40a6e7d 100644 --- a/libc/stdio/lib_fputc.c +++ b/libc/stdio/lib_fputc.c @@ -42,7 +42,7 @@ ****************************************************************************/ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fputs.c b/libc/stdio/lib_fputs.c index a1bcd89c3d..033ff3b9b3 100644 --- a/libc/stdio/lib_fputs.c +++ b/libc/stdio/lib_fputs.c @@ -49,7 +49,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fread.c b/libc/stdio/lib_fread.c index 9c8b2d378a..6acb9d7e77 100644 --- a/libc/stdio/lib_fread.c +++ b/libc/stdio/lib_fread.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_freopen.c b/libc/stdio/lib_freopen.c index f90546067e..830ea9a78f 100644 --- a/libc/stdio/lib_freopen.c +++ b/libc/stdio/lib_freopen.c @@ -43,7 +43,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/stdio/lib_fseek.c b/libc/stdio/lib_fseek.c index f09155dc0a..1016d8b37f 100644 --- a/libc/stdio/lib_fseek.c +++ b/libc/stdio/lib_fseek.c @@ -49,7 +49,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fsetpos.c b/libc/stdio/lib_fsetpos.c index 71093d4ce8..681aa514f9 100644 --- a/libc/stdio/lib_fsetpos.c +++ b/libc/stdio/lib_fsetpos.c @@ -49,7 +49,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_ftell.c b/libc/stdio/lib_ftell.c index c72e4e1b85..c13e64c9ae 100644 --- a/libc/stdio/lib_ftell.c +++ b/libc/stdio/lib_ftell.c @@ -49,7 +49,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_fwrite.c b/libc/stdio/lib_fwrite.c index ed2dce16d8..941120ae6d 100644 --- a/libc/stdio/lib_fwrite.c +++ b/libc/stdio/lib_fwrite.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_gets.c b/libc/stdio/lib_gets.c index f793fbc445..e8573edca9 100644 --- a/libc/stdio/lib_gets.c +++ b/libc/stdio/lib_gets.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_gets_s.c b/libc/stdio/lib_gets_s.c index a5a4c50059..d811bdfcfc 100644 --- a/libc/stdio/lib_gets_s.c +++ b/libc/stdio/lib_gets_s.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libdtoa.c b/libc/stdio/lib_libdtoa.c index 95a5dcc70b..995b0d72c4 100644 --- a/libc/stdio/lib_libdtoa.c +++ b/libc/stdio/lib_libdtoa.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index ff9aaece4b..4eebac409d 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -47,7 +47,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libfgets.c b/libc/stdio/lib_libfgets.c index 884cc1f535..4c3c41db05 100644 --- a/libc/stdio/lib_libfgets.c +++ b/libc/stdio/lib_libfgets.c @@ -47,7 +47,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libflushall.c b/libc/stdio/lib_libflushall.c index 85e807a9ea..e040d2deb6 100644 --- a/libc/stdio/lib_libflushall.c +++ b/libc/stdio/lib_libflushall.c @@ -45,7 +45,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index 48ab4ad4cf..e4ad730e26 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -46,7 +46,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index 76c8d72797..12bfd033c8 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -46,7 +46,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libnoflush.c b/libc/stdio/lib_libnoflush.c index 63e4d52950..6ad372a653 100644 --- a/libc/stdio/lib_libnoflush.c +++ b/libc/stdio/lib_libnoflush.c @@ -47,7 +47,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_STDIO_LINEBUFFER diff --git a/libc/stdio/lib_libsnoflush.c b/libc/stdio/lib_libsnoflush.c index 1e5af1474b..809356f144 100644 --- a/libc/stdio/lib_libsnoflush.c +++ b/libc/stdio/lib_libsnoflush.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_STDIO_LINEBUFFER diff --git a/libc/stdio/lib_libsprintf.c b/libc/stdio/lib_libsprintf.c index 1d8abbced7..baa493c7a7 100644 --- a/libc/stdio/lib_libsprintf.c +++ b/libc/stdio/lib_libsprintf.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index 634b172ad0..6c1b295811 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -46,7 +46,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_lowinstream.c b/libc/stdio/lib_lowinstream.c index 8c11fee907..8964b56749 100644 --- a/libc/stdio/lib_lowinstream.c +++ b/libc/stdio/lib_lowinstream.c @@ -45,7 +45,7 @@ #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_ARCH_LOWGETC diff --git a/libc/stdio/lib_lowoutstream.c b/libc/stdio/lib_lowoutstream.c index f600bc614a..91604c90c4 100644 --- a/libc/stdio/lib_lowoutstream.c +++ b/libc/stdio/lib_lowoutstream.c @@ -46,7 +46,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_meminstream.c b/libc/stdio/lib_meminstream.c index 195b294e4d..c975419499 100644 --- a/libc/stdio/lib_meminstream.c +++ b/libc/stdio/lib_meminstream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_memoutstream.c b/libc/stdio/lib_memoutstream.c index 492661e68a..1c658512ea 100644 --- a/libc/stdio/lib_memoutstream.c +++ b/libc/stdio/lib_memoutstream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_memsistream.c b/libc/stdio/lib_memsistream.c index d258c7fde1..af241b4c2e 100644 --- a/libc/stdio/lib_memsistream.c +++ b/libc/stdio/lib_memsistream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_memsostream.c b/libc/stdio/lib_memsostream.c index 8726ea187e..6570ef8942 100644 --- a/libc/stdio/lib_memsostream.c +++ b/libc/stdio/lib_memsostream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_nullinstream.c b/libc/stdio/lib_nullinstream.c index aeb0af3790..9ca50d6379 100644 --- a/libc/stdio/lib_nullinstream.c +++ b/libc/stdio/lib_nullinstream.c @@ -40,7 +40,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_nulloutstream.c b/libc/stdio/lib_nulloutstream.c index 5742953448..89a5a2524d 100644 --- a/libc/stdio/lib_nulloutstream.c +++ b/libc/stdio/lib_nulloutstream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index b38257f230..f4289c9b57 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -44,7 +44,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_puts.c b/libc/stdio/lib_puts.c index 4d2ab4c4ed..c30c92aaf4 100644 --- a/libc/stdio/lib_puts.c +++ b/libc/stdio/lib_puts.c @@ -42,7 +42,7 @@ ****************************************************************************/ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_rawinstream.c b/libc/stdio/lib_rawinstream.c index 19a980787d..913a413bff 100644 --- a/libc/stdio/lib_rawinstream.c +++ b/libc/stdio/lib_rawinstream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_rawoutstream.c b/libc/stdio/lib_rawoutstream.c index 7f2c522474..aed1fc5272 100644 --- a/libc/stdio/lib_rawoutstream.c +++ b/libc/stdio/lib_rawoutstream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_rawsistream.c b/libc/stdio/lib_rawsistream.c index b013e43a80..d52fad1daf 100644 --- a/libc/stdio/lib_rawsistream.c +++ b/libc/stdio/lib_rawsistream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_rawsostream.c b/libc/stdio/lib_rawsostream.c index 82db850f78..3c0b96dfa8 100644 --- a/libc/stdio/lib_rawsostream.c +++ b/libc/stdio/lib_rawsostream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_rdflush.c b/libc/stdio/lib_rdflush.c index 65d37ac356..27bd25f6fd 100644 --- a/libc/stdio/lib_rdflush.c +++ b/libc/stdio/lib_rdflush.c @@ -48,7 +48,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_snprintf.c b/libc/stdio/lib_snprintf.c index 63d0b2a5df..53e9a2cbcc 100644 --- a/libc/stdio/lib_snprintf.c +++ b/libc/stdio/lib_snprintf.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_sprintf.c b/libc/stdio/lib_sprintf.c index a0b3321bb1..5420e1e539 100644 --- a/libc/stdio/lib_sprintf.c +++ b/libc/stdio/lib_sprintf.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_stdinstream.c b/libc/stdio/lib_stdinstream.c index 240763613f..f1b5f3da99 100644 --- a/libc/stdio/lib_stdinstream.c +++ b/libc/stdio/lib_stdinstream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_stdoutstream.c b/libc/stdio/lib_stdoutstream.c index 73321c7fdb..b30e815160 100644 --- a/libc/stdio/lib_stdoutstream.c +++ b/libc/stdio/lib_stdoutstream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_stdsistream.c b/libc/stdio/lib_stdsistream.c index 0999f85132..b569bb4122 100644 --- a/libc/stdio/lib_stdsistream.c +++ b/libc/stdio/lib_stdsistream.c @@ -39,7 +39,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_stdsostream.c b/libc/stdio/lib_stdsostream.c index ade6369c51..4e196b1a22 100644 --- a/libc/stdio/lib_stdsostream.c +++ b/libc/stdio/lib_stdsostream.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdio/lib_ungetc.c b/libc/stdio/lib_ungetc.c index c8baf9a266..4ae4bc69b1 100644 --- a/libc/stdio/lib_ungetc.c +++ b/libc/stdio/lib_ungetc.c @@ -46,7 +46,7 @@ #include #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_vasprintf.c b/libc/stdio/lib_vasprintf.c index f7b2402712..53e0a15706 100644 --- a/libc/stdio/lib_vasprintf.c +++ b/libc/stdio/lib_vasprintf.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_vdprintf.c b/libc/stdio/lib_vdprintf.c index d96ca40f88..26959b5de8 100644 --- a/libc/stdio/lib_vdprintf.c +++ b/libc/stdio/lib_vdprintf.c @@ -42,7 +42,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/stdio/lib_vfprintf.c b/libc/stdio/lib_vfprintf.c index 8681b2151d..328fc42f82 100644 --- a/libc/stdio/lib_vfprintf.c +++ b/libc/stdio/lib_vfprintf.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_vsnprintf.c b/libc/stdio/lib_vsnprintf.c index 5fd300f7fe..ad329e173e 100644 --- a/libc/stdio/lib_vsnprintf.c +++ b/libc/stdio/lib_vsnprintf.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_vsprintf.c b/libc/stdio/lib_vsprintf.c index 57589cef56..0ad85086bf 100644 --- a/libc/stdio/lib_vsprintf.c +++ b/libc/stdio/lib_vsprintf.c @@ -41,7 +41,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_wrflush.c b/libc/stdio/lib_wrflush.c index 0587e417eb..0ccd007c6b 100644 --- a/libc/stdio/lib_wrflush.c +++ b/libc/stdio/lib_wrflush.c @@ -43,7 +43,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/stdio/lib_zeroinstream.c b/libc/stdio/lib_zeroinstream.c index a52ecc1d06..506d005871 100644 --- a/libc/stdio/lib_zeroinstream.c +++ b/libc/stdio/lib_zeroinstream.c @@ -39,7 +39,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdlib/lib_checkbase.c b/libc/stdlib/lib_checkbase.c index 83199bcfae..05abe7b896 100644 --- a/libc/stdlib/lib_checkbase.c +++ b/libc/stdlib/lib_checkbase.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdlib/lib_strtol.c b/libc/stdlib/lib_strtol.c index 5518172949..8c7f639901 100644 --- a/libc/stdlib/lib_strtol.c +++ b/libc/stdlib/lib_strtol.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdlib/lib_strtoll.c b/libc/stdlib/lib_strtoll.c index 7ed5ecab20..bc8cc2eb6f 100644 --- a/libc/stdlib/lib_strtoll.c +++ b/libc/stdlib/lib_strtoll.c @@ -42,7 +42,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_HAVE_LONG_LONG diff --git a/libc/stdlib/lib_strtoul.c b/libc/stdlib/lib_strtoul.c index 712a658e26..3dfe5a5e60 100644 --- a/libc/stdlib/lib_strtoul.c +++ b/libc/stdlib/lib_strtoul.c @@ -41,7 +41,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/stdlib/lib_strtoull.c b/libc/stdlib/lib_strtoull.c index 169058128a..82adc0450a 100644 --- a/libc/stdlib/lib_strtoull.c +++ b/libc/stdlib/lib_strtoull.c @@ -42,7 +42,7 @@ #include -#include "lib_internal.h" +#include "libc.h" #ifdef CONFIG_HAVE_LONG_LONG diff --git a/libc/string/lib_isbasedigit.c b/libc/string/lib_isbasedigit.c index dff8138811..e72e33de5c 100644 --- a/libc/string/lib_isbasedigit.c +++ b/libc/string/lib_isbasedigit.c @@ -43,7 +43,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/string/lib_skipspace.c b/libc/string/lib_skipspace.c index 4b72b1ec37..602c03a274 100644 --- a/libc/string/lib_skipspace.c +++ b/libc/string/lib_skipspace.c @@ -41,7 +41,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Private Functions diff --git a/libc/string/lib_strdup.c b/libc/string/lib_strdup.c index ab5c620a12..4da233d163 100644 --- a/libc/string/lib_strdup.c +++ b/libc/string/lib_strdup.c @@ -41,7 +41,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/string/lib_strndup.c b/libc/string/lib_strndup.c index 984b363944..1c097de81a 100644 --- a/libc/string/lib_strndup.c +++ b/libc/string/lib_strndup.c @@ -41,7 +41,7 @@ #include -#include "lib_internal.h" +#include "libc.h" /**************************************************************************** * Public Functions diff --git a/libc/unistd/lib_chdir.c b/libc/unistd/lib_chdir.c index 87353b546d..4780a6b72e 100644 --- a/libc/unistd/lib_chdir.c +++ b/libc/unistd/lib_chdir.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) diff --git a/libc/unistd/lib_getcwd.c b/libc/unistd/lib_getcwd.c index 9a25399996..851d380fb6 100644 --- a/libc/unistd/lib_getcwd.c +++ b/libc/unistd/lib_getcwd.c @@ -45,7 +45,7 @@ #include #include -#include "lib_internal.h" +#include "libc.h" #if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) diff --git a/libnx/nxfonts/nxfonts_internal.h b/libnx/nxfonts/nxfonts.h similarity index 94% rename from libnx/nxfonts/nxfonts_internal.h rename to libnx/nxfonts/nxfonts.h index 7fccd5ab4e..1e3fa18bb3 100644 --- a/libnx/nxfonts/nxfonts_internal.h +++ b/libnx/nxfonts/nxfonts.h @@ -1,5 +1,5 @@ /**************************************************************************** - * libnx/nxfonts/nxfonts_internal.h + * libnx/nxfonts/nxfonts.h * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __LIBNX_NXFONTS_NXFONTS_INTERNAL_H -#define __LIBNX_NXFONTS_NXFONTS_INTERNAL_H +#ifndef __LIBNX_NXFONTS_NXFONTS_H +#define __LIBNX_NXFONTS_NXFONTS_H /**************************************************************************** * Included Files @@ -85,4 +85,4 @@ EXTERN struct nx_font_s g_fonts; } #endif -#endif /* __LIBNX_NXFONTS_NXFONTS_INTERNAL_H */ +#endif /* __LIBNX_NXFONTS_NXFONTS_H */ diff --git a/libnx/nxfonts/nxfonts_bitmaps.c b/libnx/nxfonts/nxfonts_bitmaps.c index 0a71faacfe..28e6aa18dc 100644 --- a/libnx/nxfonts/nxfonts_bitmaps.c +++ b/libnx/nxfonts/nxfonts_bitmaps.c @@ -42,7 +42,7 @@ #include #include -#include "nxfonts_internal.h" +#include "nxfonts.h" /* Pick the fontset */ diff --git a/libnx/nxfonts/nxfonts_convert.c b/libnx/nxfonts/nxfonts_convert.c index a223c7f0a9..6d3b5a71e2 100644 --- a/libnx/nxfonts/nxfonts_convert.c +++ b/libnx/nxfonts/nxfonts_convert.c @@ -46,7 +46,7 @@ #include #include -#include "nxfonts_internal.h" +#include "nxfonts.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxfonts/nxfonts_getfont.c b/libnx/nxfonts/nxfonts_getfont.c index fe443138df..c52c082281 100644 --- a/libnx/nxfonts/nxfonts_getfont.c +++ b/libnx/nxfonts/nxfonts_getfont.c @@ -46,7 +46,7 @@ #include #include -#include "nxfonts_internal.h" +#include "nxfonts.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_internal.h b/libnx/nxtk/nxtk.h similarity index 98% rename from libnx/nxtk/nxtk_internal.h rename to libnx/nxtk/nxtk.h index 7a62293413..44d507ee01 100644 --- a/libnx/nxtk/nxtk_internal.h +++ b/libnx/nxtk/nxtk.h @@ -1,5 +1,5 @@ /**************************************************************************** - * libnx/nxtk/nxtk_internal.h + * libnx/nxtk/nxtk.h * * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __LIBNX_NXTK_NXTK_INTERNAL_H -#define __LIBNX_NXTK_NXTK_INTERNAL_H +#ifndef __LIBNX_NXTK_NXTK_H +#define __LIBNX_NXTK_NXTK_H /**************************************************************************** * Included Files @@ -222,4 +222,4 @@ int nxtk_drawframe(FAR struct nxtk_framedwindow_s *fwnd, } #endif -#endif /* __LIBNX_NXTK_NXTK_INTERNAL_H */ +#endif /* __LIBNX_NXTK_NXTK_H */ diff --git a/libnx/nxtk/nxtk_bitmaptoolbar.c b/libnx/nxtk/nxtk_bitmaptoolbar.c index abeb14d184..abc1815b8f 100644 --- a/libnx/nxtk/nxtk_bitmaptoolbar.c +++ b/libnx/nxtk/nxtk_bitmaptoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_bitmapwindow.c b/libnx/nxtk/nxtk_bitmapwindow.c index da814fe10a..59a8776b62 100644 --- a/libnx/nxtk/nxtk_bitmapwindow.c +++ b/libnx/nxtk/nxtk_bitmapwindow.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_closetoolbar.c b/libnx/nxtk/nxtk_closetoolbar.c index 8f65a75a84..7be217d18d 100644 --- a/libnx/nxtk/nxtk_closetoolbar.c +++ b/libnx/nxtk/nxtk_closetoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_closewindow.c b/libnx/nxtk/nxtk_closewindow.c index 7bda3ff06b..5485752130 100644 --- a/libnx/nxtk/nxtk_closewindow.c +++ b/libnx/nxtk/nxtk_closewindow.c @@ -47,7 +47,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_containerclip.c b/libnx/nxtk/nxtk_containerclip.c index 12dc4987b3..67ed6cb17b 100644 --- a/libnx/nxtk/nxtk_containerclip.c +++ b/libnx/nxtk/nxtk_containerclip.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_drawframe.c b/libnx/nxtk/nxtk_drawframe.c index ae0be64425..adafccc574 100644 --- a/libnx/nxtk/nxtk_drawframe.c +++ b/libnx/nxtk/nxtk_drawframe.c @@ -47,7 +47,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_events.c b/libnx/nxtk/nxtk_events.c index 33d496e19a..d7f33e6ebe 100644 --- a/libnx/nxtk/nxtk_events.c +++ b/libnx/nxtk/nxtk_events.c @@ -48,7 +48,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libnx/nxtk/nxtk_filltoolbar.c b/libnx/nxtk/nxtk_filltoolbar.c index 13de372498..0d62eaaf84 100644 --- a/libnx/nxtk/nxtk_filltoolbar.c +++ b/libnx/nxtk/nxtk_filltoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_filltraptoolbar.c b/libnx/nxtk/nxtk_filltraptoolbar.c index a55d05e7e9..1b7ae27277 100644 --- a/libnx/nxtk/nxtk_filltraptoolbar.c +++ b/libnx/nxtk/nxtk_filltraptoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_filltrapwindow.c b/libnx/nxtk/nxtk_filltrapwindow.c index 66aef4184f..bbfba26599 100644 --- a/libnx/nxtk/nxtk_filltrapwindow.c +++ b/libnx/nxtk/nxtk_filltrapwindow.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_fillwindow.c b/libnx/nxtk/nxtk_fillwindow.c index 77f043391c..fa0fd8d8f2 100644 --- a/libnx/nxtk/nxtk_fillwindow.c +++ b/libnx/nxtk/nxtk_fillwindow.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_getposition.c b/libnx/nxtk/nxtk_getposition.c index a0b21bedba..1f0bdceeef 100644 --- a/libnx/nxtk/nxtk_getposition.c +++ b/libnx/nxtk/nxtk_getposition.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_gettoolbar.c b/libnx/nxtk/nxtk_gettoolbar.c index a83a1aa3e6..593fcb09a6 100644 --- a/libnx/nxtk/nxtk_gettoolbar.c +++ b/libnx/nxtk/nxtk_gettoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_getwindow.c b/libnx/nxtk/nxtk_getwindow.c index a91ad05fc6..b229459973 100644 --- a/libnx/nxtk/nxtk_getwindow.c +++ b/libnx/nxtk/nxtk_getwindow.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_lower.c b/libnx/nxtk/nxtk_lower.c index de26ac509b..08a588897d 100644 --- a/libnx/nxtk/nxtk_lower.c +++ b/libnx/nxtk/nxtk_lower.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_movetoolbar.c b/libnx/nxtk/nxtk_movetoolbar.c index 275bb46e66..62d14e7bf8 100644 --- a/libnx/nxtk/nxtk_movetoolbar.c +++ b/libnx/nxtk/nxtk_movetoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_movewindow.c b/libnx/nxtk/nxtk_movewindow.c index 66aed9d16a..2b34f44a8b 100644 --- a/libnx/nxtk/nxtk_movewindow.c +++ b/libnx/nxtk/nxtk_movewindow.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_opentoolbar.c b/libnx/nxtk/nxtk_opentoolbar.c index ffdf629013..26aa4c504f 100644 --- a/libnx/nxtk/nxtk_opentoolbar.c +++ b/libnx/nxtk/nxtk_opentoolbar.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_openwindow.c b/libnx/nxtk/nxtk_openwindow.c index c7c050b8da..796a57d3b7 100644 --- a/libnx/nxtk/nxtk_openwindow.c +++ b/libnx/nxtk/nxtk_openwindow.c @@ -46,7 +46,7 @@ #include #include "nxcontext.h" -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_raise.c b/libnx/nxtk/nxtk_raise.c index 2b54f81cb6..d0273fe704 100644 --- a/libnx/nxtk/nxtk_raise.c +++ b/libnx/nxtk/nxtk_raise.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_setposition.c b/libnx/nxtk/nxtk_setposition.c index f3ba118726..ed85625272 100644 --- a/libnx/nxtk/nxtk_setposition.c +++ b/libnx/nxtk/nxtk_setposition.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_setsize.c b/libnx/nxtk/nxtk_setsize.c index 671aa80540..8848c71720 100644 --- a/libnx/nxtk/nxtk_setsize.c +++ b/libnx/nxtk/nxtk_setsize.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_setsubwindows.c b/libnx/nxtk/nxtk_setsubwindows.c index 5ebd5f2be7..943825a8b0 100644 --- a/libnx/nxtk/nxtk_setsubwindows.c +++ b/libnx/nxtk/nxtk_setsubwindows.c @@ -45,7 +45,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libnx/nxtk/nxtk_subwindowclip.c b/libnx/nxtk/nxtk_subwindowclip.c index b2688a543d..b1b4024ee7 100644 --- a/libnx/nxtk/nxtk_subwindowclip.c +++ b/libnx/nxtk/nxtk_subwindowclip.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_subwindowmove.c b/libnx/nxtk/nxtk_subwindowmove.c index 6ae737b580..6b80609d3d 100644 --- a/libnx/nxtk/nxtk_subwindowmove.c +++ b/libnx/nxtk/nxtk_subwindowmove.c @@ -46,7 +46,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/libnx/nxtk/nxtk_toolbarbounds.c b/libnx/nxtk/nxtk_toolbarbounds.c index 6303b4d20d..eacaf90573 100644 --- a/libnx/nxtk/nxtk_toolbarbounds.c +++ b/libnx/nxtk/nxtk_toolbarbounds.c @@ -45,7 +45,7 @@ #include #include -#include "nxtk_internal.h" +#include "nxtk.h" /**************************************************************************** * Pre-Processor Definitions -- GitLab From 695a8890a6ab9af24f34132ebc46d16ac427985c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Dec 2015 18:19:03 -0600 Subject: [PATCH 486/858] Rename pm_internal.h to pm.h --- ChangeLog | 2 +- arch | 2 +- configs | 2 +- drivers/power/{pm_internal.h => pm.h} | 8 ++++---- drivers/power/pm_activity.c | 2 +- drivers/power/pm_changestate.c | 2 +- drivers/power/pm_checkstate.c | 2 +- drivers/power/pm_initialize.c | 2 +- drivers/power/pm_register.c | 2 +- drivers/power/pm_update.c | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) rename drivers/power/{pm_internal.h => pm.h} (97%) diff --git a/ChangeLog b/ChangeLog index 1dd1bee589..a110b5a06c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -4680,7 +4680,7 @@ * arch/arm/src/kl/kl_gpio.c and .h, configs/freedom-kl25z/src/freedom-kl25z.h, and configs/freedom-kl25z/src/kl_led.c: Fixes LEDs on the Freedom KL25Z board (2013-5-6). - * arch/arm/src/kinetis/kinetis_pin.c and arch/arm/src/kinetis/kinetis_internal.h: + * arch/arm/src/kinetis/kinetis_pin.c and arch/arm/src/kinetis/kinetis.h: The Kinetis GPIO logic had some of the same issues as did the Kinetis L (2013-5-6). * arch/arm/src/stm32/stm32_idle.c: Add an option to conditionally disable diff --git a/arch b/arch index 230f8d050f..4e962ff8a0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 230f8d050f4cb535b4047ba2e5fbea8b50b70671 +Subproject commit 4e962ff8a0a2f15247232d7e9aef89032c9b2898 diff --git a/configs b/configs index f6782b7548..05b3084913 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f6782b75481a49e19709a7e1593d40346716f5e4 +Subproject commit 05b30849130f836b352cc84196b2369679fbe5ec diff --git a/drivers/power/pm_internal.h b/drivers/power/pm.h similarity index 97% rename from drivers/power/pm_internal.h rename to drivers/power/pm.h index 6499c65eaf..8ed66d3d30 100644 --- a/drivers/power/pm_internal.h +++ b/drivers/power/pm.h @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/power/pm_internal.h + * drivers/power/pm * * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __DRIVERS_POWER_PM_INTERNAL_H -#define __DRIVERS_POWER_PM_INTERNAL_H +#ifndef __DRIVERS_POWER_PM_H +#define __DRIVERS_POWER_PM_H /**************************************************************************** * Included Files @@ -207,4 +207,4 @@ EXTERN void pm_update(int16_t accum); #endif #endif /* CONFIG_PM */ -#endif /* #define __DRIVERS_POWER_PM_INTERNAL_H */ +#endif /* #define __DRIVERS_POWER_PM_H */ diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c index f6dceeea37..d80315605c 100644 --- a/drivers/power/pm_activity.c +++ b/drivers/power/pm_activity.c @@ -43,7 +43,7 @@ #include #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM diff --git a/drivers/power/pm_changestate.c b/drivers/power/pm_changestate.c index f64760f55b..ee47405260 100644 --- a/drivers/power/pm_changestate.c +++ b/drivers/power/pm_changestate.c @@ -42,7 +42,7 @@ #include #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index 13adc5d5ce..37ea02ca04 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -43,7 +43,7 @@ #include #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM diff --git a/drivers/power/pm_initialize.c b/drivers/power/pm_initialize.c index b4f7458779..1fc5ff479f 100644 --- a/drivers/power/pm_initialize.c +++ b/drivers/power/pm_initialize.c @@ -43,7 +43,7 @@ #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM diff --git a/drivers/power/pm_register.c b/drivers/power/pm_register.c index 19f94cb026..c7a61f88cc 100644 --- a/drivers/power/pm_register.c +++ b/drivers/power/pm_register.c @@ -44,7 +44,7 @@ #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM diff --git a/drivers/power/pm_update.c b/drivers/power/pm_update.c index 7392029935..0909836065 100644 --- a/drivers/power/pm_update.c +++ b/drivers/power/pm_update.c @@ -44,7 +44,7 @@ #include #include -#include "pm_internal.h" +#include "pm" #ifdef CONFIG_PM -- GitLab From 426eb61e4772edab5f7ed4509b31e94020949a0d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 29 Dec 2015 18:29:24 -0600 Subject: [PATCH 487/858] Fix an error introduced in the last big set of header file renaming --- drivers/power/pm_activity.c | 5 +++-- drivers/power/pm_changestate.c | 2 +- drivers/power/pm_checkstate.c | 2 +- drivers/power/pm_initialize.c | 5 +++-- drivers/power/pm_register.c | 5 +++-- drivers/power/pm_update.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c index d80315605c..e15cc78b1e 100644 --- a/drivers/power/pm_activity.c +++ b/drivers/power/pm_activity.c @@ -43,7 +43,7 @@ #include #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM @@ -163,4 +163,5 @@ void pm_activity(int priority) } } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ + diff --git a/drivers/power/pm_changestate.c b/drivers/power/pm_changestate.c index ee47405260..50aa8a07d5 100644 --- a/drivers/power/pm_changestate.c +++ b/drivers/power/pm_changestate.c @@ -42,7 +42,7 @@ #include #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index 37ea02ca04..85f4415323 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -43,7 +43,7 @@ #include #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM diff --git a/drivers/power/pm_initialize.c b/drivers/power/pm_initialize.c index 1fc5ff479f..298448974f 100644 --- a/drivers/power/pm_initialize.c +++ b/drivers/power/pm_initialize.c @@ -43,7 +43,7 @@ #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM @@ -109,4 +109,5 @@ void pm_initialize(void) sem_init(&g_pmglobals.regsem, 0, 1); } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ + diff --git a/drivers/power/pm_register.c b/drivers/power/pm_register.c index c7a61f88cc..f8776acee2 100644 --- a/drivers/power/pm_register.c +++ b/drivers/power/pm_register.c @@ -44,7 +44,7 @@ #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM @@ -109,4 +109,5 @@ int pm_register(FAR struct pm_callback_s *callbacks) return ret; } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ + diff --git a/drivers/power/pm_update.c b/drivers/power/pm_update.c index 0909836065..1d5a64bfff 100644 --- a/drivers/power/pm_update.c +++ b/drivers/power/pm_update.c @@ -44,7 +44,7 @@ #include #include -#include "pm" +#include "pm.h" #ifdef CONFIG_PM -- GitLab From 40659d12df6b2fe644801e4bda41327e34dcf5c0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 07:56:56 -0600 Subject: [PATCH 488/858] Rename libxx_internal.h to libxx.h --- configs | 2 +- libxx/{libxx_internal.hxx => libxx.h} | 2 +- libxx/libxx_cxa_atexit.cxx | 2 +- libxx/libxx_delete.cxx | 2 +- libxx/libxx_deletea.cxx | 2 +- libxx/libxx_eabi_atexit.cxx | 2 +- libxx/libxx_new.cxx | 2 +- libxx/libxx_newa.cxx | 2 +- mm/README.txt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename libxx/{libxx_internal.hxx => libxx.h} (99%) diff --git a/configs b/configs index 05b3084913..bf83eb388a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 05b30849130f836b352cc84196b2369679fbe5ec +Subproject commit bf83eb388aea59fb76651ba22c86f22a0da5d6dc diff --git a/libxx/libxx_internal.hxx b/libxx/libxx.h similarity index 99% rename from libxx/libxx_internal.hxx rename to libxx/libxx.h index 6669e90052..0fcdfedb02 100644 --- a/libxx/libxx_internal.hxx +++ b/libxx/libxx.h @@ -1,5 +1,5 @@ //*************************************************************************** -// lib/libxx_internal.h +// lib/libxx.h // // Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. // Author: Gregory Nutt diff --git a/libxx/libxx_cxa_atexit.cxx b/libxx/libxx_cxa_atexit.cxx index 5e01f99f27..cb60e1c7e2 100644 --- a/libxx/libxx_cxa_atexit.cxx +++ b/libxx/libxx_cxa_atexit.cxx @@ -41,7 +41,7 @@ #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/libxx/libxx_delete.cxx b/libxx/libxx_delete.cxx index 9eb46a0100..dec28a85c2 100644 --- a/libxx/libxx_delete.cxx +++ b/libxx/libxx_delete.cxx @@ -39,7 +39,7 @@ #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/libxx/libxx_deletea.cxx b/libxx/libxx_deletea.cxx index c99c18dfde..174049efc2 100644 --- a/libxx/libxx_deletea.cxx +++ b/libxx/libxx_deletea.cxx @@ -39,7 +39,7 @@ #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/libxx/libxx_eabi_atexit.cxx b/libxx/libxx_eabi_atexit.cxx index 25f8306a84..eea296c696 100644 --- a/libxx/libxx_eabi_atexit.cxx +++ b/libxx/libxx_eabi_atexit.cxx @@ -40,7 +40,7 @@ #include #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/libxx/libxx_new.cxx b/libxx/libxx_new.cxx index 710528abe3..a4575519ab 100644 --- a/libxx/libxx_new.cxx +++ b/libxx/libxx_new.cxx @@ -41,7 +41,7 @@ #include #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/libxx/libxx_newa.cxx b/libxx/libxx_newa.cxx index 8d42c628c7..c1e4dfa95d 100644 --- a/libxx/libxx_newa.cxx +++ b/libxx/libxx_newa.cxx @@ -41,7 +41,7 @@ #include #include -#include "libxx_internal.hxx" +#include "libxx.hxx" //*************************************************************************** // Pre-processor Definitions diff --git a/mm/README.txt b/mm/README.txt index 0e9a4e7d22..f33cf49c80 100644 --- a/mm/README.txt +++ b/mm/README.txt @@ -15,7 +15,7 @@ This directory contains the NuttX memory management logic. This include: mm_memalign.c, mm_free.c o Less-Standard Interfaces: mm_zalloc.c, mm_mallinfo.c o Internal Implementation: mm_initialize.c mm_sem.c mm_addfreechunk.c - mm_size2ndx.c mm_shrinkchunk.c, mm_internal.h + mm_size2ndx.c mm_shrinkchunk.c o Build and Configuration files: Kconfig, Makefile Memory Models: -- GitLab From e76e8f41c62de22bb4d3ccaf23e6e5a9ab497c35 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 12:18:24 -0600 Subject: [PATCH 489/858] pthread: Correct default schedule policy --- include/nuttx/pthread.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index 7528bbda85..ffd0d29fb8 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -51,11 +51,17 @@ /* Default pthread attribute initializer */ +#if CONFIG_RR_INTERVAL == 0 +# define PTHREAD_DEFAULT_POLICY SCHED_FIFO +#else +# define PTHREAD_DEFAULT_POLICY SCHED_RR +#endif + #ifdef CONFIG_SCHED_SPORADIC # define PTHREAD_ATTR_INITIALIZER \ { \ PTHREAD_DEFAULT_PRIORITY, /* priority */ \ - SCHED_RR, /* policy */ \ + PTHREAD_DEFAULT_POLICY, /* policy */ \ PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \ 0, /* low_priority */ \ 0, /* max_repl */ \ @@ -67,7 +73,7 @@ # define PTHREAD_ATTR_INITIALIZER \ { \ PTHREAD_DEFAULT_PRIORITY, /* priority */ \ - SCHED_RR, /* policy */ \ + PTHREAD_DEFAULT_POLICY, /* policy */ \ PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \ PTHREAD_STACK_DEFAULT, /* stacksize */ \ } -- GitLab From 9835eeb181ebc9b2c9119803b3263191ab08c165 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 13:20:31 -0600 Subject: [PATCH 490/858] signals: Basic framework to support SIGEV_THREAD --- TODO | 7 +-- arch | 2 +- configs | 2 +- fs/aio/aio_signal.c | 34 ++++++------- include/nuttx/mqueue.h | 5 +- include/pthread.h | 93 ++++++++++++++++++++++++++++++++++- include/signal.h | 38 ++++++++++++-- libc/aio/lio_listio.c | 18 +++++++ sched/Kconfig | 9 ++++ sched/mqueue/mq_desclose.c | 4 +- sched/mqueue/mq_notify.c | 19 +++---- sched/mqueue/mq_sndinternal.c | 44 +++++++++++------ sched/timer/timer.h | 5 +- sched/timer/timer_create.c | 10 +--- sched/timer/timer_settime.c | 46 +++++++++++------ 15 files changed, 252 insertions(+), 84 deletions(-) diff --git a/TODO b/TODO index 3e11ed34b2..43e5bef9e7 100644 --- a/TODO +++ b/TODO @@ -340,9 +340,10 @@ o Signals (sched/signal, arch/) embedded system. Title: SIGEV_THREAD - Description: sig_notify() logic does not support SIGEV_THREAD; structure - struct sigevent does not provide required members sigev_notify_function - or sigev_notify_attributes. + Description: Implementation of support for support for SIGEV_THREAD is incomplete; + The internal OS functin sig_notification has not been implemented (and + will be tricky!). There are also some unimplemented function call logic + in libc/aio Status: Low, there are alternative designs. However, these features are required by the POSIX standard. Priority: Low for now diff --git a/arch b/arch index 4e962ff8a0..08f9810f59 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4e962ff8a0a2f15247232d7e9aef89032c9b2898 +Subproject commit 08f9810f5922c627fd378ea3727faa0ba4eb0d74 diff --git a/configs b/configs index bf83eb388a..d4540c0f83 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bf83eb388aea59fb76651ba22c86f22a0da5d6dc +Subproject commit d4540c0f83378a6680ffd792ff1e4a8ca0ddd8b8 diff --git a/fs/aio/aio_signal.c b/fs/aio/aio_signal.c index 9545a86227..57e37dfe71 100644 --- a/fs/aio/aio_signal.c +++ b/fs/aio/aio_signal.c @@ -51,29 +51,10 @@ #ifdef CONFIG_FS_AIO -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Name: aio_signal * @@ -126,6 +107,19 @@ int aio_signal(pid_t pid, FAR struct aiocb *aiocbp) } } +#ifdef CONFIG_SIG_EVTHREAD + /* Notify the client via a function call */ + + else if (aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD) + { + ret = sig_notification(pid, &aiocbp->aio_sigevent); + if (ret < 0) + { + fdbg("ERROR: sig_notification failed: %d\n", ret); + } + } +#endif + /* Send the poll signal in any event in case the caller is waiting * on sig_suspend(); */ diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 68f7b1b2bf..53fa3af9f8 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/mqueue.h * - * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -80,8 +80,7 @@ struct mqueue_inode_s #ifndef CONFIG_DISABLE_SIGNALS FAR struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */ pid_t ntpid; /* Notification: Receiving Task's PID */ - int ntsigno; /* Notification: Signal number */ - union sigval ntvalue; /* Notification: Signal value */ + struct sigevent ntevent; /* Notification description */ #endif }; diff --git a/include/pthread.h b/include/pthread.h index 4de07d62a2..5a380bafbc 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -158,8 +158,11 @@ extern "C" /* pthread-specific types */ -typedef int pthread_key_t; -typedef FAR void *pthread_addr_t; +typedef int pthread_key_t; +#define __PTHREAD_KEY_T_DEFINED 1 + +typedef FAR void *pthread_addr_t; +#define __PTHREAD_ADDR_T_DEFINED 1 typedef pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t); typedef pthread_startroutine_t pthread_func_t; @@ -182,17 +185,24 @@ struct pthread_attr_s struct timespec budget; /* Initial budget */ #endif }; + typedef struct pthread_attr_s pthread_attr_t; +#define __PTHREAD_ATTR_T_DEFINED 1 typedef pid_t pthread_t; +#define __PTHREAD_T_DEFINED 1 typedef int pthread_condattr_t; +#define __PTHREAD_CONDATTR_T_DEFINED 1 struct pthread_cond_s { sem_t sem; }; + typedef struct pthread_cond_s pthread_cond_t; +#define __PTHREAD_COND_T_DEFINED 1 + #define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0)} struct pthread_mutexattr_s @@ -202,7 +212,9 @@ struct pthread_mutexattr_s uint8_t type; /* Type of the mutex. See PTHREAD_MUTEX_* definitions */ #endif }; + typedef struct pthread_mutexattr_s pthread_mutexattr_t; +#define __PTHREAD_MUTEXATTR_T_DEFINED 1 struct pthread_mutex_s { @@ -213,7 +225,9 @@ struct pthread_mutex_s int nlocks; /* The number of recursive locks held */ #endif }; + typedef struct pthread_mutex_s pthread_mutex_t; +#define __PTHREAD_MUTEX_T_DEFINED 1 #ifdef CONFIG_MUTEX_TYPES # define PTHREAD_MUTEX_INITIALIZER {-1, SEM_INITIALIZER(1), PTHREAD_MUTEX_DEFAULT, 0} @@ -225,16 +239,21 @@ struct pthread_barrierattr_s { int pshared; }; + typedef struct pthread_barrierattr_s pthread_barrierattr_t; +#define __PTHREAD_BARRIERATTR_T_DEFINED 1 struct pthread_barrier_s { sem_t sem; unsigned int count; }; + typedef struct pthread_barrier_s pthread_barrier_t; +#define __PTHREAD_BARRIER_T_DEFINED 1 typedef bool pthread_once_t; +#define __PTHREAD_ONCE_T_DEFINED 1 /* Forware references */ @@ -413,4 +432,74 @@ int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); } #endif +#else /* __INCLUDE_PTHREAD_H */ + +#include +#include + +/* Avoid a circular dependencies by assuring that simple type definitions + * are avaiable in any inclusion ordering. + */ + +#ifndef __PTHREAD_KEY_T_DEFINED +typedef int pthread_key_t; +# define __PTHREAD_KEY_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_ADDR_T_DEFINED +typedef FAR void *pthread_addr_t; +# define __PTHREAD_ADDR_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_ATTR_T_DEFINED +struct pthread_attr_s; +typedef struct pthread_attr_s pthread_attr_t; +# define __PTHREAD_ATTR_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_T_DEFINED +typedef pid_t pthread_t; +# define __PTHREAD_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_CONDATTR_T_DEFINED +typedef int pthread_condattr_t; +# define __PTHREAD_CONDATTR_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_COND_T_DEFINED +struct pthread_cond_s; +typedef struct pthread_cond_s pthread_cond_t; +# define __PTHREAD_COND_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_MUTEXATTR_T_DEFINED +struct pthread_mutexattr_s; +typedef struct pthread_mutexattr_s pthread_mutexattr_t; +# define __PTHREAD_MUTEXATTR_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_MUTEX_T_DEFINED +struct pthread_mutex_s; +typedef struct pthread_mutex_s pthread_mutex_t; +# define __PTHREAD_MUTEX_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_BARRIERATTR_T_DEFINED +struct pthread_barrierattr_s; +typedef struct pthread_barrierattr_s pthread_barrierattr_t; +# define __PTHREAD_BARRIERATTR_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_BARRIER_T_DEFINED +struct pthread_barrier_s; +typedef struct pthread_barrier_s pthread_barrier_t; +# define __PTHREAD_BARRIER_T_DEFINED 1 +#endif + +#ifndef __PTHREAD_ONCE_T_DEFINED +typedef bool pthread_once_t; +# define __PTHREAD_ONCE_T_DEFINED 1 +#endif + #endif /* __INCLUDE_PTHREAD_H */ diff --git a/include/signal.h b/include/signal.h index 18ab6b85c1..50d6ea9f01 100644 --- a/include/signal.h +++ b/include/signal.h @@ -45,6 +45,9 @@ #include #include +#ifdef CONFIG_SIG_EVTHREAD +# include /* Needed for pthread_attr_t */ +#endif /******************************************************************************** * Pre-processor Definitions @@ -162,8 +165,11 @@ /* Values for the sigev_notify field of struct sigevent */ -#define SIGEV_NONE 0 /* No notification desired */ -#define SIGEV_SIGNAL 1 /* Notify via signal */ +#define SIGEV_NONE 0 /* No asynchronous notification is delivered */ +#define SIGEV_SIGNAL 1 /* Notify via signal,with an application-defined value */ +#ifdef CONFIG_SIG_EVTHREAD +# define SIGEV_THREAD 3 /* A notification function is called */ +#endif /* Special values of of sa_handler used by sigaction and sigset. They are all * treated like NULL for now. This is okay for SIG_DFL and SIG_IGN because @@ -189,6 +195,7 @@ /* This defines a set of 32 signals (numbered 0 through 31). */ typedef uint32_t sigset_t; /* Bit set of 32 signals */ +#define __SIGSET_T_DEFINED 1 /* This defines the type of the siginfo si_value field */ @@ -205,9 +212,14 @@ union sigval struct sigevent { - uint8_t sigev_notify; /* Notification method: SIGEV_SIGNAL or SIGEV_NONE */ + uint8_t sigev_notify; /* Notification method: SIGEV_SIGNAL, SIGEV_NONE, or SIGEV_THREAD */ uint8_t sigev_signo; /* Notification signal */ union sigval sigev_value; /* Data passed with notification */ + +#ifdef CONFIG_SIG_EVTHREAD + CODE void (*sigev_notify_function)(union sigval); /* Notification function */ + FAR pthread_attr_t *sigev_notify_attributes; /* Notification attributes (not used) */ +#endif }; /* The following types is used to pass parameters to/from signal handlers */ @@ -225,6 +237,7 @@ struct siginfo }; typedef struct siginfo siginfo_t; +#define __SIGINFO_T_DEFINED 1 /* Non-standard convenience definition of signal handling function types. * These should be used only internally within the NuttX signal logic. @@ -297,4 +310,23 @@ int sigqueue(int pid, int signo, FAR void *sival_ptr); } #endif +#else /* __INCLUDE_SIGNAL_H */ + +#include + +/* Avoid a circular dependencies by assuring that simple type definitions + * are avaiable in any inclusion ordering. + */ + +#ifndef __SIGSET_T_DEFINED +typedef uint32_t sigset_t; +# define __SIGSET_T_DEFINED 1 +#endif + +#ifndef __SIGINFO_T_DEFINED +struct siginfo; +typedef struct siginfo siginfo_t; +# define __SIGINFO_T_DEFINED 1 +#endif + #endif /* __INCLUDE_SIGNAL_H */ diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index b552817e09..38efad0019 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -213,6 +213,15 @@ static void lio_sighandler(int signo, siginfo_t *info, void *ucontext) #endif } +#ifdef CONFIG_SIG_EVTHREAD + /* Notify the client via a function call */ + + else if (ighand->sig->sigev_notify == SIGEV_THREAD) + { +#warning Missing SIGEV_THREAD logic + } +#endif + /* And free the container */ lib_free(sighand); @@ -711,6 +720,15 @@ int lio_listio(int mode, FAR struct aiocb *const list[], int nent, } } +#ifdef CONFIG_SIG_EVTHREAD + /* Notify the client via a function call */ + + else if (sig && sig->sigev_notify == SIGEV_THREAD) + { +#warning Missing SIGEV_THREAD logic + } +#endif + /* Case 3: mode == LIO_NOWAIT and sig == NULL * * Just return now. diff --git a/sched/Kconfig b/sched/Kconfig index 5aefa848c0..301558ec8d 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -775,6 +775,15 @@ config SCHED_ONEXIT_MAX endmenu # RTOS hooks +config SIG_EVTHREAD + bool "Support SIGEV_THHREAD" + default n + depends on EXPERIMENTAL + ---help--- + Built in support for the SIGEV_THREAD signal deliver method. + + NOTE: Only partially implemented as of this writing. + menu "Signal Numbers" depends on !DISABLE_SIGNALS diff --git a/sched/mqueue/mq_desclose.c b/sched/mqueue/mq_desclose.c index ca7bfc5b8a..881ce5499a 100644 --- a/sched/mqueue/mq_desclose.c +++ b/sched/mqueue/mq_desclose.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -128,9 +129,8 @@ void mq_desclose(mqd_t mqdes) #ifndef CONFIG_DISABLE_SIGNALS if (msgq->ntmqdes == mqdes) { + memset(&msgq->ntevent, 0, sizeof(struct sigevent)); msgq->ntpid = INVALID_PROCESS_ID; - msgq->ntsigno = 0; - msgq->ntvalue.sival_int = 0; msgq->ntmqdes = NULL; } #endif diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index c9836715fe..d87c413b3e 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -93,7 +94,7 @@ * Parameters: * mqdes - Message queue descriptor * notification - Real-time signal structure containing: - * sigev_notify - Should be SIGEV_SIGNAL (but actually ignored) + * sigev_notify - Should be SIGEV_SIGNAL or SIGEV_THREAD * sigev_signo - The signo to use for the notification * sigev_value - Value associated with the signal * @@ -171,10 +172,11 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification) /* Yes... Assign it to the current task. */ - msgq->ntvalue.sival_ptr = notification->sigev_value.sival_ptr; - msgq->ntsigno = notification->sigev_signo; - msgq->ntpid = rtcb->pid; - msgq->ntmqdes = mqdes; + memcpy(&msgq->ntevent, ¬ification->sigev_value, + sizeof(struct sigevent)); + + msgq->ntpid = rtcb->pid; + msgq->ntmqdes = mqdes; } } @@ -197,10 +199,9 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification) * thread to detach the notification. */ - msgq->ntpid = INVALID_PROCESS_ID; - msgq->ntsigno = 0; - msgq->ntvalue.sival_ptr = NULL; - msgq->ntmqdes = NULL; + memset(&msgq->ntevent, 0, sizeof(struct sigevent)); + msgq->ntpid = INVALID_PROCESS_ID; + msgq->ntmqdes = NULL; } sched_unlock(); diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index f2a312f8ef..43abe64e1f 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -51,6 +51,8 @@ #include #include #include +#include + #include "sched/sched.h" #ifndef CONFIG_DISABLE_SIGNALS # include "signal/signal.h" @@ -384,30 +386,44 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, #ifndef CONFIG_DISABLE_SIGNALS if (msgq->ntmqdes) { + struct sigevent event; + pid_t pid; + /* Remove the message notification data from the message queue. */ -#ifdef CONFIG_CAN_PASS_STRUCTS - union sigval value = msgq->ntvalue; -#else - void *sival_ptr = msgq->ntvalue.sival_ptr; -#endif - int signo = msgq->ntsigno; - int pid = msgq->ntpid; + memcpy(&event, &msgq->ntevent, sizeof(struct sigevent)); + pid = msgq->ntpid; /* Detach the notification */ - msgq->ntpid = INVALID_PROCESS_ID; - msgq->ntsigno = 0; - msgq->ntvalue.sival_int = 0; - msgq->ntmqdes = NULL; + memset(&msgq->ntevent, 0, sizeof(struct sigevent)); + msgq->ntpid = INVALID_PROCESS_ID; + msgq->ntmqdes = NULL; + + /* Notification the client via signal? */ - /* Queue the signal -- What if this returns an error? */ + if (event.sigev_notify == SIGEV_SIGNAL) + { + /* Yes... Queue the signal -- What if this returns an error? */ #ifdef CONFIG_CAN_PASS_STRUCTS - sig_mqnotempty(pid, signo, value); + DEBUGVERIFY(sig_mqnotempty(pid, event.sigev_signo, + event.sigev_value)); #else - sig_mqnotempty(pid, signo, sival_ptr); + DEBUGVERIFY(sig_mqnotempty(pid, event.sigev_signo, + event.sigev_value.sival_ptr)); #endif + } + +#ifdef CONFIG_SIG_EVTHREAD + /* Notify the client via a function call */ + + else if (event.sigev_notify == SIGEV_THREAD) + { + DEBUGVERIFY(sig_notification(pid, &event)); + } +#endif + } #endif diff --git a/sched/timer/timer.h b/sched/timer/timer.h index 1f139a1f42..6165d9e847 100644 --- a/sched/timer/timer.h +++ b/sched/timer/timer.h @@ -1,7 +1,7 @@ /******************************************************************************** * sched/timer/timer.h * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,12 +67,11 @@ struct posix_timer_s uint8_t pt_flags; /* See PT_FLAGS_* definitions */ uint8_t pt_crefs; /* Reference count */ - uint8_t pt_signo; /* Notification signal */ pid_t pt_owner; /* Creator of timer */ int pt_delay; /* If non-zero, used to reset repetitive timers */ int pt_last; /* Last value used to set watchdog */ WDOG_ID pt_wdog; /* The watchdog that provides the timing */ - union sigval pt_value; /* Data passed with notification */ + struct sigevent pt_event; /* Notification information */ }; /******************************************************************************** diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index bf6429e3bc..27b2b0fe2b 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -215,17 +215,11 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer if (evp) { - ret->pt_signo = evp->sigev_signo; -#ifdef CONFIG_CAN_PASS_STRUCTS - ret->pt_value = evp->sigev_value; -#else - ret->pt_value.sival_ptr = evp->sigev_value.sival_ptr; -#endif + memcpy(&ret->pt_event, evp, sizeof(struct sigevent)); } else { - ret->pt_signo = SIGALRM; - ret->pt_value.sival_ptr = ret; + memset(&ret->pt_event, 0, sizeof(struct sigevent)); } /* Return the timer */ diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 4df42217ee..de8eda47e8 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -44,6 +44,8 @@ #include #include +#include + #include "clock/clock.h" #include "signal/signal.h" #include "timer/timer.h" @@ -66,7 +68,7 @@ * Private Function Prototypes ********************************************************************************/ -static inline void timer_sigqueue(FAR struct posix_timer_s *timer); +static inline void timer_signotify(FAR struct posix_timer_s *timer); static inline void timer_restart(FAR struct posix_timer_s *timer, wdparm_t itimer); static void timer_timeout(int argc, wdparm_t itimer); @@ -75,7 +77,7 @@ static void timer_timeout(int argc, wdparm_t itimer); ********************************************************************************/ /******************************************************************************** - * Name: timer_sigqueue + * Name: timer_signotify * * Description: * This function basically reimplements sigqueue() so that the si_code can @@ -92,28 +94,42 @@ static void timer_timeout(int argc, wdparm_t itimer); * ********************************************************************************/ -static inline void timer_sigqueue(FAR struct posix_timer_s *timer) +static inline void timer_signotify(FAR struct posix_timer_s *timer) { siginfo_t info; - /* Create the siginfo structure */ + /* Notify client via a signal? */ + + if (timer->pt_event.sigev_notify == SIGEV_SIGNAL) + { + /* Yes.. Create the siginfo structure */ - info.si_signo = timer->pt_signo; - info.si_code = SI_TIMER; - info.si_errno = OK; + info.si_signo = timer->pt_event.sigev_signo; + info.si_code = SI_TIMER; + info.si_errno = OK; #ifdef CONFIG_CAN_PASS_STRUCTS - info.si_value = timer->pt_value; + info.si_value = timer->pt_event.sigev_value; #else - info.si_value.sival_ptr = timer->pt_value.sival_ptr; + info.si_value.sival_ptr = timer->pt_event.sigev_value.sival_ptr; #endif #ifdef CONFIG_SCHED_HAVE_PARENT - info.si_pid = 0; /* Not applicable */ - info.si_status = OK; + info.si_pid = 0; /* Not applicable */ + info.si_status = OK; #endif - /* Send the signal */ + /* Send the signal */ + + DEBUGVERIFY(sig_dispatch(timer->pt_owner, &info)); + } - (void)sig_dispatch(timer->pt_owner, &info); +#ifdef CONFIG_SIG_EVTHREAD + /* Notify the client via a function call */ + + else if (timer->pt_event.sigev_notify == SIGEV_THREAD) + { + DEBUGVERIFY(sig_notification(timer->pt_owner, &timer->pt_event)); + } +#endif } /******************************************************************************** @@ -187,7 +203,7 @@ static void timer_timeout(int argc, wdparm_t itimer) */ u.timer->pt_crefs++; - timer_sigqueue(u.timer); + timer_signotify(u.timer); /* Release the reference. timer_release will return nonzero if the timer * was not deleted. @@ -208,7 +224,7 @@ static void timer_timeout(int argc, wdparm_t itimer) */ timer->pt_crefs++; - timer_sigqueue(timer); + timer_signotify(timer); /* Release the reference. timer_release will return nonzero if the timer * was not deleted. -- GitLab From 849df03d226f5860fcb7b2b267f0169f5eec154e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 13:28:39 -0600 Subject: [PATCH 491/858] Update dates on files modified for SIGEV_THREAD support --- fs/aio/aio_signal.c | 2 +- include/nuttx/pthread.h | 2 +- include/nuttx/signal.h | 76 +++++++++++++++++++++++++++++++++++ sched/mqueue/mq_desclose.c | 2 +- sched/mqueue/mq_notify.c | 2 +- sched/mqueue/mq_sndinternal.c | 2 +- sched/timer/timer_create.c | 2 +- 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 include/nuttx/signal.h diff --git a/fs/aio/aio_signal.c b/fs/aio/aio_signal.c index 57e37dfe71..5a279044c8 100644 --- a/fs/aio/aio_signal.c +++ b/fs/aio/aio_signal.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/aio/aio_signal.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index ffd0d29fb8..eff079be74 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -2,7 +2,7 @@ * include/nuttx/pthread.h * Non-standard, NuttX-specific pthread-related declarations. * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h new file mode 100644 index 0000000000..56c708ec86 --- /dev/null +++ b/include/nuttx/signal.h @@ -0,0 +1,76 @@ +/**************************************************************************** + * include/nuttx/signal.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SIGNAL_H +#define __INCLUDE_NUTTX_SIGNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#if defined(CONFIG_SIG_EVTHREAD) && defined(__KERNEL__) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: sig_notification + * + * Description: + * Notify a client a signal event via a function call. This function is + * an internal OS interface that implements the common logic for signal + * event notification for the case of SIGEV_THREAD. + * + * Input Parameters: + * pid - The task/thread ID a the client thread to be signaled. + * event - The instance of struct sigevent that describes how to signal + * the client. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int sig_notification(pid_t pid, FAR struct sigevent *event); + +#endif /* CONFIG_SIG_EVTHREAD && __KERNEL__ */ +#endif /* __INCLUDE_NUTTX_SIGNAL_H */ diff --git a/sched/mqueue/mq_desclose.c b/sched/mqueue/mq_desclose.c index 881ce5499a..812059e0ff 100644 --- a/sched/mqueue/mq_desclose.c +++ b/sched/mqueue/mq_desclose.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_desclose.c * - * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index d87c413b3e..cb7a3aaffc 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_notify.c * - * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index 43abe64e1f..b6580d25bb 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_send.c * - * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 27b2b0fe2b..0d5ce1b1e1 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -1,7 +1,7 @@ /******************************************************************************** * sched/timer/timer_create.c * - * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without -- GitLab From 9852932dcc845d6b0ec2ad2ff73518cdca905733 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 13:48:29 -0600 Subject: [PATCH 492/858] Fix another error from the last set of header file renaming --- libxx/{libxx.h => libxx.hxx} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename libxx/{libxx.h => libxx.hxx} (96%) diff --git a/libxx/libxx.h b/libxx/libxx.hxx similarity index 96% rename from libxx/libxx.h rename to libxx/libxx.hxx index 0fcdfedb02..f8c1eada4a 100644 --- a/libxx/libxx.h +++ b/libxx/libxx.hxx @@ -1,5 +1,5 @@ //*************************************************************************** -// lib/libxx.h +// lib/libxx.hxx // // Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. // Author: Gregory Nutt @@ -33,8 +33,8 @@ // //*************************************************************************** -#ifndef __LIBXX_LIBXX_INTERNAL_HXX -#define __LIBXX_LIBXX_INTERNAL_HXX +#ifndef __LIBXX_LIBXX_HXX +#define __LIBXX_LIBXX__HXX //*************************************************************************** // Included Files @@ -85,4 +85,4 @@ extern "C" FAR void *__dso_handle; extern "C" int __cxa_atexit(__cxa_exitfunc_t func, void *arg, void *dso_handle); -#endif // __LIBXX_LIBXX_INTERNAL_HXX +#endif // __LIBXX_LIBXX_HXX -- GitLab From c1fff4706c640b0959bf2d4b9c3ea98abeb7a015 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 15:01:14 -0600 Subject: [PATCH 493/858] signals: Adds a very limited, minimal implementation for SIGEV_THREAD --- include/nuttx/signal.h | 4 +- include/pthread.h | 4 + include/signal.h | 18 ++-- libc/aio/lio_listio.c | 43 ++++---- sched/Kconfig | 7 +- sched/signal/Make.defs | 4 + sched/signal/sig_notification.c | 172 ++++++++++++++++++++++++++++++++ 7 files changed, 219 insertions(+), 33 deletions(-) create mode 100644 sched/signal/sig_notification.c diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index 56c708ec86..3f4adb5021 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -45,7 +45,7 @@ #include #include -#if defined(CONFIG_SIG_EVTHREAD) && defined(__KERNEL__) +#if defined(CONFIG_SIG_EVTHREAD) && defined(CONFIG_BUILD_FLAT) /**************************************************************************** * Public Function Prototypes @@ -72,5 +72,5 @@ int sig_notification(pid_t pid, FAR struct sigevent *event); -#endif /* CONFIG_SIG_EVTHREAD && __KERNEL__ */ +#endif /* CONFIG_SIG_EVTHREAD && CONFIG_BUILD_FLAT */ #endif /* __INCLUDE_NUTTX_SIGNAL_H */ diff --git a/include/pthread.h b/include/pthread.h index 5a380bafbc..9cc2b44a41 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -432,6 +432,10 @@ int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); } #endif +/******************************************************************************** + * Minimal Type Definitions + ********************************************************************************/ + #else /* __INCLUDE_PTHREAD_H */ #include diff --git a/include/signal.h b/include/signal.h index 50d6ea9f01..742720cf6b 100644 --- a/include/signal.h +++ b/include/signal.h @@ -210,6 +210,12 @@ union sigval * available on a queue */ +#ifdef CONFIG_CAN_PASS_STRUCTS +typedef CODE void (*sigev_notify_function_t)(union sigval value); +#else +typedef CODE void (*sigev_notify_function_t)(FAR void *sival_ptr); +#endif + struct sigevent { uint8_t sigev_notify; /* Notification method: SIGEV_SIGNAL, SIGEV_NONE, or SIGEV_THREAD */ @@ -217,8 +223,8 @@ struct sigevent union sigval sigev_value; /* Data passed with notification */ #ifdef CONFIG_SIG_EVTHREAD - CODE void (*sigev_notify_function)(union sigval); /* Notification function */ - FAR pthread_attr_t *sigev_notify_attributes; /* Notification attributes (not used) */ + sigev_notify_function_t sigev_notify_function; /* Notification function */ + FAR pthread_attr_t *sigev_notify_attributes; /* Notification attributes (not used) */ #endif }; @@ -264,10 +270,6 @@ struct sigaction #define sa_handler sa_u._sa_handler #define sa_sigaction sa_u._sa_sigaction -/******************************************************************************** - * Public Data - ********************************************************************************/ - /******************************************************************************** * Public Function Prototypes ********************************************************************************/ @@ -310,6 +312,10 @@ int sigqueue(int pid, int signo, FAR void *sival_ptr); } #endif +/******************************************************************************** + * Minimal Type Definitions + ********************************************************************************/ + #else /* __INCLUDE_SIGNAL_H */ #include diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index 38efad0019..b123a4e735 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -45,16 +45,13 @@ #include #include +#include + #include "libc.h" #include "aio/aio.h" #ifdef CONFIG_FS_AIO -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -69,14 +66,6 @@ struct lio_sighand_s struct sigaction oact; /* Signal handler to restore */ }; -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -205,11 +194,11 @@ static void lio_sighandler(int signo, siginfo_t *info, void *ucontext) if (sighand->sig->sigev_notify == SIGEV_SIGNAL) { #ifdef CONFIG_CAN_PASS_STRUCTS - (void)sigqueue(sighand->pid, sighand->sig->sigev_signo, - sighand->sig->sigev_value); + DEBUGASSERT(sigqueue(sighand->pid, sighand->sig->sigev_signo, + sighand->sig->sigev_value)); #else - (void)sigqueue(sighand->pid, sighand->sig->sigev_signo, - sighand->sig->sigev_value.sival_ptr); + DEBUGASSERT(sigqueue(sighand->pid, sighand->sig->sigev_signo, + sighand->sig->sigev_value.sival_ptr)); #endif } @@ -218,7 +207,7 @@ static void lio_sighandler(int signo, siginfo_t *info, void *ucontext) else if (ighand->sig->sigev_notify == SIGEV_THREAD) { -#warning Missing SIGEV_THREAD logic + DEBUGASSERT(sig_notification(sighand->pid, &sighand->sig)); } #endif @@ -660,7 +649,7 @@ int lio_listio(int mode, FAR struct aiocb *const list[], int nent, */ status = lio_waitall(list, nent); - if (status < 0 && ret != OK) + if (status < 0 && ret == OK) { /* Something bad happened while waiting and this is the first * error to be reported. @@ -688,7 +677,7 @@ int lio_listio(int mode, FAR struct aiocb *const list[], int nent, /* Setup a signal handler to detect when until all I/O completes. */ status = lio_sigsetup(list, nent, sig); - if (status < 0 && ret != OK) + if (status < 0 && ret == OK) { /* Something bad happened while setting up the signal and this * is the first error to be reported. @@ -707,8 +696,7 @@ int lio_listio(int mode, FAR struct aiocb *const list[], int nent, status = sigqueue(getpid(), sig->sigev_signo, sig->sigev_value.sival_ptr); #endif - - if (status < 0 && ret != OK) + if (status < 0 && ret == OK) { /* Something bad happened while signalling ourself and this is * the first error to be reported. @@ -725,7 +713,16 @@ int lio_listio(int mode, FAR struct aiocb *const list[], int nent, else if (sig && sig->sigev_notify == SIGEV_THREAD) { -#warning Missing SIGEV_THREAD logic + status = sig_notification(sighand->pid, &sighand->sig); + if (status < 0 && ret == OK) + { + /* Something bad happened while performing the notification + * and this is the first error to be reported. + */ + + retcode = -status; + ret = ERROR; + } } #endif diff --git a/sched/Kconfig b/sched/Kconfig index 301558ec8d..d1e72a30e8 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -778,11 +778,14 @@ endmenu # RTOS hooks config SIG_EVTHREAD bool "Support SIGEV_THHREAD" default n - depends on EXPERIMENTAL + depends on BUILD_FLAT && SCHED_WORKQUEUE ---help--- Built in support for the SIGEV_THREAD signal deliver method. - NOTE: Only partially implemented as of this writing. + NOTE: The current implementation uses a work queue to notify the + client. This, however, would only work in the FLAT build. A + different mechanism would need to be development to support this + feature on the PROTECTED or KERNEL build. menu "Signal Numbers" depends on !DISABLE_SIGNALS diff --git a/sched/signal/Make.defs b/sched/signal/Make.defs index 8521b644aa..9d6ddda3a6 100644 --- a/sched/signal/Make.defs +++ b/sched/signal/Make.defs @@ -44,6 +44,10 @@ CSRCS += sig_removependingsignal.c sig_releasependingsignal.c sig_lowest.c CSRCS += sig_mqnotempty.c sig_cleanup.c sig_dispatch.c sig_deliver.c CSRCS += sig_pause.c sig_nanosleep.c +ifeq ($(CONFIG_SIG_EVTHREAD),y) +CSRCS += sig_notification.c +endif + # Include signal build support DEPPATH += --dep-path signal diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c new file mode 100644 index 0000000000..f9a0710fbe --- /dev/null +++ b/sched/signal/sig_notification.c @@ -0,0 +1,172 @@ +/**************************************************************************** + * sched/signal/sig_notification.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#ifdef CONFIG_SIG_EVTHREAD + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Use the low-prioriry work queue is it is available */ + +#if defined(CONFIG_SCHED_LPWORK) +# define NTWORK LPWORK +#elif defined(CONFIG_SCHED_HPWORK) +# define NTWORK HPWORK +#else +# error Work queue is not enabled +#endif + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/* This structure retains all that is necessary to perform the notification */ + +struct sig_notify_s +{ + struct work_s nt_work; /* Work queue structure */ + union sigval nt_value; /* Data passed with notification */ + sigev_notify_function_t nt_func; /* Notification function */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sig_ntworker + * + * Description: + * Perform the callback from the context of the worker thread. + * + * Input Parameters: + * arg - Work argument. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static void sig_ntworker(FAR void *arg) +{ + FAR struct sig_notify_s *notify = (FAR struct sig_notify_s *)arg; + + DEBUGASSERT(notify != NULL); + + /* Perform the callback */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + notify->nt_func(notify->nt_value); +#else + notify->nt_func(notify->nt_value.sival_ptr); +#endif + + /* Free the alloated notification parameters */ + + kmm_free(notify); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sig_notification + * + * Description: + * Notify a client a signal event via a function call. This function is + * an internal OS interface that implements the common logic for signal + * event notification for the case of SIGEV_THREAD. + * + * Input Parameters: + * pid - The task/thread ID a the client thread to be signaled. + * event - The instance of struct sigevent that describes how to signal + * the client. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int sig_notification(pid_t pid, FAR struct sigevent *event) +{ + FAR struct sig_notify_s *notify; + DEBUGASSERT(event != NULL && event->sigev_notify_function != NULL); + int ret; + + /* Allocate a structure to hold the notification information */ + + notify = kmm_zalloc(sizeof(struct sig_notify_s)); + if (notify == NULL) + { + return -ENOMEM; + } + + /* Initialize the notification information */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + notify->nt_value = event->sigev_value; +#else + notify->nt_value.sival_ptr = event->sigev_value.sival_ptr; +#endif + notify->nt_func = event->sigev_notify_function; + + /* Then queue the work */ + + ret = work_queue(NTWORK, ¬ify->nt_work, sig_ntworker, notify, 0); + if (ret < 0) + { + kmm_free(notify); + } + + return ret; +} + +#endif /* CONFIG_SIG_EVTHREAD */ -- GitLab From c33724fc93e38c4a6b910d9ff3e2ba3c7175df3c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 15:26:30 -0600 Subject: [PATCH 494/858] Update TODO list --- TODO | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 43e5bef9e7..43b4954171 100644 --- a/TODO +++ b/TODO @@ -340,10 +340,17 @@ o Signals (sched/signal, arch/) embedded system. Title: SIGEV_THREAD - Description: Implementation of support for support for SIGEV_THREAD is incomplete; - The internal OS functin sig_notification has not been implemented (and - will be tricky!). There are also some unimplemented function call logic - in libc/aio + Description: Implementation of support for support for SIGEV_THREAD is available + only in the FLAT build mode because it uses the OS work queues to + perform the callback. The alternative for the PROTECTED and KERNEL + builds would be to create pthreads in the user space to perform the + callbacks. That is not a very attractive solution due to performance + issues. It would also require some additional logic to specify the + TCB of the parent so that the pthread could be bound to the correct + group. + + There is also some user-space logic in libc/aio/lio_listio.c. That + logic could use the user-space work queue for the callbacks. Status: Low, there are alternative designs. However, these features are required by the POSIX standard. Priority: Low for now -- GitLab From 05d16f15da81cec53a1adbe5418b650ec3521408 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Dec 2015 16:33:27 -0600 Subject: [PATCH 495/858] Update ChangeLog --- ChangeLog | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a110b5a06c..519fc28770 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11257,4 +11257,9 @@ (2015-12-19). * configs/arduino-mega2560: Add support for the Arduino-Mega2560. From Dimitry Koper (2015-12-29). - + * sched/signal, sched/mqueue, sched/timer, include/signal.h, + include/nuttx/signal, fs/aio, libc/aio, and probably other + directories: Add support for the SIGEV_THREAD notification method in + struct sigevent. This initial implementation will only work in the + FLAT build. See the top-level TODO file for additional details + (2015-12-30). -- GitLab From b73a7515b63cb8c665ae4c647839eba69a076975 Mon Sep 17 00:00:00 2001 From: Chris Croswhite Date: Wed, 30 Dec 2015 19:12:42 -0600 Subject: [PATCH 496/858] Small compilation issue when selecting localtime, this patch adds the correct ifdef. --- libc/time/lib_strftime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/time/lib_strftime.c b/libc/time/lib_strftime.c index fafdedc6b4..6af9220297 100644 --- a/libc/time/lib_strftime.c +++ b/libc/time/lib_strftime.c @@ -70,7 +70,7 @@ * Private Data ****************************************************************************/ -#ifdef CONFIG_TIME_EXTENDED +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) static const char * const g_abbrev_wdayname[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -- GitLab From b1938c065da507482339fd5194589d06718d50de Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 31 Dec 2015 09:05:35 -0600 Subject: [PATCH 497/858] sys/time.h: Fix timersub macro; time_t is unsigned --- ChangeLog | 1 + include/pthread.h | 6 +++--- include/signal.h | 7 ++++--- include/sys/time.h | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 519fc28770..b23a599c80 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11263,3 +11263,4 @@ struct sigevent. This initial implementation will only work in the FLAT build. See the top-level TODO file for additional details (2015-12-30). + diff --git a/include/pthread.h b/include/pthread.h index 9cc2b44a41..00cd95772d 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -50,7 +50,7 @@ #include /* C99 boolean types */ #include /* For getpid */ #include /* Needed for sem_t */ -#include /* Needed for sigset_t */ +#include /* Needed for sigset_t, includes this file */ #include /* Needed for struct timespec */ /******************************************************************************** @@ -441,8 +441,8 @@ int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); #include #include -/* Avoid a circular dependencies by assuring that simple type definitions - * are avaiable in any inclusion ordering. +/* Avoid circular dependencies by assuring that simple type definitions are + * available in any inclusion ordering. */ #ifndef __PTHREAD_KEY_T_DEFINED diff --git a/include/signal.h b/include/signal.h index 742720cf6b..57c5742d83 100644 --- a/include/signal.h +++ b/include/signal.h @@ -45,8 +45,9 @@ #include #include + #ifdef CONFIG_SIG_EVTHREAD -# include /* Needed for pthread_attr_t */ +# include /* Needed for pthread_attr_t, includes this file */ #endif /******************************************************************************** @@ -320,8 +321,8 @@ int sigqueue(int pid, int signo, FAR void *sival_ptr); #include -/* Avoid a circular dependencies by assuring that simple type definitions - * are avaiable in any inclusion ordering. +/* Avoid circular dependencies by assuring that simple type definitions are + * available in any inclusion ordering. */ #ifndef __SIGSET_T_DEFINED diff --git a/include/sys/time.h b/include/sys/time.h index ecc2fc8401..b36e30fca9 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -78,12 +78,12 @@ do \ { \ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) \ + if ((uvp)->tv_usec > (tvp)->tv_usec) \ { \ (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ + (tvp)->tv_usec += 1000000; \ } \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ } \ while (0) -- GitLab From efd5a63cf3d8777e4bcfc3bffc4b38f797e25c76 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 1 Jan 2016 12:18:04 -0600 Subject: [PATCH 498/858] Update submodules --- Documentation | 2 +- arch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index c825944849..92c4a17b04 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit c82594484958132e9267cd7bacb47579874a12ba +Subproject commit 92c4a17b043e87524a926ad86b6170407c5b3ec0 diff --git a/arch b/arch index 08f9810f59..3d8815cc4c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 08f9810f5922c627fd378ea3727faa0ba4eb0d74 +Subproject commit 3d8815cc4ce2870c2774cc54c6240f7e5c6e33e1 -- GitLab From 63f13283de0d63c1df37e8ed3a04f943391d40d2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 3 Jan 2016 11:59:43 -0600 Subject: [PATCH 499/858] Upate TODO list --- TODO | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 43b4954171..84ee69a066 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated December 23, 2015) +NuttX TODO List (Last updated January 3, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -19,6 +19,7 @@ nuttx/ (6) Binary loaders (binfmt/) (11) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) + (1) Other drivers (drivers/) (11) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) (8) Graphics subsystem (graphics/) @@ -1608,6 +1609,28 @@ o Build system Status: Open Priority: Low. +o Other drivers (drivers/) + ^^^^^^^^^^^^^^^^^^^^^^^^ + + Title: I2C NOT THREAD SAFE + Description: Unlike the SPI interface, the I2C interface has no method to lock + the interface. This is a problem for all non-atomic I2C operations + in a multi-tasking I2C environment: + - I2C_SETFREQUENCY: Frequency setting can be overwritten by other + I2C usage. + - I2C_SETADDRESS used with I2C_READ, I2C_WRITE, and I2C_WRITEREAD: + Similarly, address can and will be changed by other I2C usage. + - I2C_TRANSFER: This is the only interface that is properly self + contained and protected from most mult-tasking issues. But even + this interface can suffer if there are differing frequency settings. + Status: Open + Priority: Medium-High. The fix is easy but effects a lot of software. There + are two ways to fix theses problems: (1) Add a locking method such + as is provided with the SPI interface, or (2) make each interface + self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS + methods; Add frequency to all interfaces and add the address to + I2C_READ, I2C_WRITE, and I2C_WRITEREAD. + o Linux/Cywgin simulation (arch/sim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- GitLab From b48ca00cd5aa48799cf97c6f9edab35c8954a82a Mon Sep 17 00:00:00 2001 From: Dimitry Kloper Date: Tue, 5 Jan 2016 07:58:04 -0600 Subject: [PATCH 500/858] The delay parameter has 'int' type while explicit int32_t is used in sigtimedwait() (sig_timedwait.c) This can lead to wrong argument for systems that have default int size different than int32 (namely AVR). --- Documentation | 2 +- include/nuttx/wdog.h | 2 +- sched/wdog/wd_start.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index 92c4a17b04..b4e33ca73c 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 92c4a17b043e87524a926ad86b6170407c5b3ec0 +Subproject commit b4e33ca73c44aaca5f6986650e6d215a4d5adcab diff --git a/include/nuttx/wdog.h b/include/nuttx/wdog.h index a5e6945d5b..beb1388093 100644 --- a/include/nuttx/wdog.h +++ b/include/nuttx/wdog.h @@ -167,7 +167,7 @@ extern "C" WDOG_ID wd_create(void); int wd_delete(WDOG_ID wdog); -int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...); +int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...); int wd_cancel(WDOG_ID wdog); int wd_gettime(WDOG_ID wdog); diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index de3b05603e..f69a4d649c 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -225,7 +225,7 @@ static inline void wd_expiration(void) * ****************************************************************************/ -int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) +int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...) { va_list ap; FAR struct wdog_s *curr; -- GitLab From 06d83c62610f6a56a535d796afa53ec3f5cbcbc1 Mon Sep 17 00:00:00 2001 From: Dimitry Kloper Date: Tue, 5 Jan 2016 10:29:29 -0600 Subject: [PATCH 501/858] Introduce support for Atmel toolchain in-flash strings Atmel toolchain AVR compiler provides a transparent in-flash object support using __flash and __memx symbols. The former indicates to compiler that this is a flash-based object. The later used with pointer indicates that the referenced object may reside either in flash or in RAM. The compiler automatically makes 32-bit pointer with flag indicating whether referenced object is in flash or RAM and generates code to access either in run-time. Thus, any function that accepts __memx object can transparently work with RAM and flash objects. For platforms with a Harvard architecture and a very small RAM like AVR this allows to move all constant strings used in trace messages to flash in the instruction address space, releasing resources for other things. This change introduces IOBJ and IPTR type qualifiers. The 'I' indicates that the object may like in instruction space on a Harvard architecture machine. For platforms that do not have __flash and __memx or similar symbols IOBJ and IPTR are empty, making the types equivalent to, for example, 'const char' and 'const char*'. For Atmel compiler these will become 'const __flash char' and 'const __memx char*'. All printf() functions and syslog() functions are changed so that the qualifier is used with the format parameter. From: Dimitry Kloper --- ChangeLog | 23 +++++++++++++++++++- arch | 2 +- include/nuttx/compiler.h | 35 +++++++++++++++++++++++++----- include/nuttx/streams.h | 7 +++--- include/stdio.h | 33 +++++++++++++++++------------ include/syslog.h | 9 ++++---- libc/stdio/lib_asprintf.c | 2 +- libc/stdio/lib_dprintf.c | 2 +- libc/stdio/lib_fprintf.c | 2 +- libc/stdio/lib_libsprintf.c | 3 ++- libc/stdio/lib_libvsprintf.c | 41 +++++++++++++++++++++++------------- libc/stdio/lib_printf.c | 2 +- libc/stdio/lib_snprintf.c | 2 +- libc/stdio/lib_sprintf.c | 2 +- libc/stdio/lib_vasprintf.c | 2 +- libc/stdio/lib_vdprintf.c | 2 +- libc/stdio/lib_vfprintf.c | 2 +- libc/stdio/lib_vprintf.c | 2 +- libc/stdio/lib_vsnprintf.c | 3 ++- libc/stdio/lib_vsprintf.c | 2 +- libc/syslog/lib_lowsyslog.c | 6 +++--- libc/syslog/lib_syslog.c | 6 +++--- 22 files changed, 128 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index b23a599c80..2d1113ba38 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11263,4 +11263,25 @@ struct sigevent. This initial implementation will only work in the FLAT build. See the top-level TODO file for additional details (2015-12-30). - + * include/nuttx/compiler.h, include/nuttx/streams.h include/stdio.h + include/syslog.h libc/stdio/, and libc/syslog: ntroduce support for + Atmel toolchain in-flash strings. Atmel toolchain AVR compiler + provides a transparent in-flash object support using __flash and + __memx symbols. The former indicates to compiler that this is a flash- + based object. The later used with pointer indicates that the referenced + object may reside either in flash or in RAM. The compiler automatically + makes 32-bit pointer with flag indicating whether referenced object is + in flash or RAM and generates code to access either in run-time. Thus, + any function that accepts __memx object can transparently work with RAM + and flash objects. + For platforms with a Harvard architecture and a very small RAM like AVR + this allows to move all constant strings used in trace messages to flash + in the instruction address space, releasing resources for other things. + This change introduces IOBJ and IPTR type qualifiers. The 'I' indicates + that the object may lie in instruction space on a Harvard architecture + machine. For platforms that do not have __flash and __memx or similar + symbols IOBJ and IPTR are empty, making the types equivalent to, for + example, 'const char' and 'const char*'. For Atmel compiler these will + become 'const __flash char' and 'const __memx char*'. All printf() + functions and syslog() functions are changed so that the qualifier is + used with the format parameter. From Dimitry Kloper. diff --git a/arch b/arch index 3d8815cc4c..0761b677ef 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3d8815cc4ce2870c2774cc54c6240f7e5c6e33e1 +Subproject commit 0761b677efa861b6369cea195968a59e4a6e6860 diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index f43de0b671..4ad2400456 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -40,6 +40,8 @@ * Included Files ****************************************************************************/ +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -127,6 +129,11 @@ */ #if defined(__m32c__) +/* No I-space access qualifiers */ + +# define IOBJ +# define IPTR + /* Select the small, 16-bit addressing model */ # define CONFIG_SMALL_MEMORY 1 @@ -140,6 +147,14 @@ # undef CONFIG_PTR_IS_NOT_INT #elif defined(__AVR__) + + /* I-space access qualifiers needed by Harvard architecture */ + +# if defined(CONFIG_AVR_HAS_MEMX_PTR) +# define IOBJ __flash +# define IPTR __memx +# endif + /* Select the small, 16-bit addressing model */ # define CONFIG_SMALL_MEMORY 1 @@ -159,6 +174,11 @@ # define CONFIG_HAVE_FARPOINTER 1 #elif defined(__mc68hc1x__) +/* No I-space access qualifiers */ + +# define IOBJ +# define IPTR + /* Select the small, 16-bit addressing model */ # define CONFIG_SMALL_MEMORY 1 @@ -173,20 +193,26 @@ # define CONFIG_LONG_IS_NOT_INT 1 -/* Pointers and int are the same size (16-bits) */ +/* Pointers and int are the same size (16-bits) */ # undef CONFIG_PTR_IS_NOT_INT -#else +# else /* int and long are both 32-bits */ # undef CONFIG_LONG_IS_NOT_INT -/* Pointers and int are NOT the same size */ +/* Pointers and int are NOT the same size */ # define CONFIG_PTR_IS_NOT_INT 1 -#endif +# endif #else + +/* No I-space access qualifiers */ + +# define IOBJ +# define IPTR + /* Select the large, 32-bit addressing model */ # undef CONFIG_SMALL_MEMORY @@ -491,7 +517,6 @@ extern "C" #define EXTERN extern #endif - #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index 3358765bed..ab57b33b35 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/streams.h * - * Copyright (C) 2009, 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -413,9 +413,10 @@ int lib_snoflush(FAR struct lib_sostream_s *this); * ****************************************************************************/ -int lib_sprintf(FAR struct lib_outstream_s *obj, FAR const char *fmt, ...); +int lib_sprintf(FAR struct lib_outstream_s *obj, + FAR const IPTR char *fmt, ...); int lib_vsprintf(FAR struct lib_outstream_s *obj, - FAR const char *src, va_list ap); + FAR const IPTR char *src, va_list ap); #undef EXTERN #if defined(__cplusplus) diff --git a/include/stdio.h b/include/stdio.h index d8f0c3479a..20994e22ff 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -143,35 +143,40 @@ int fgetc(FAR FILE *stream); int fgetpos(FAR FILE *stream, FAR fpos_t *pos); char *fgets(FAR char *s, int n, FAR FILE *stream); FAR FILE *fopen(FAR const char *path, FAR const char *type); -int fprintf(FAR FILE *stream, FAR const char *format, ...); +int fprintf(FAR FILE *stream, FAR const IPTR char *format, ...); int fputc(int c, FAR FILE *stream); int fputs(FAR const char *s, FAR FILE *stream); size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream); -FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream); +FAR FILE *freopen(FAR const char *path, FAR const char *mode, + FAR FILE *stream); int fseek(FAR FILE *stream, long int offset, int whence); int fsetpos(FAR FILE *stream, FAR fpos_t *pos); long ftell(FAR FILE *stream); -size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream); +size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, + FAR FILE *stream); FAR char *gets(FAR char *s); FAR char *gets_s(FAR char *s, rsize_t n); int ungetc(int c, FAR FILE *stream); /* Operations on the stdout stream, buffers, paths, and the whole printf-family */ -int printf(FAR const char *format, ...); +int printf(FAR const IPTR char *format, ...); int puts(FAR const char *s); int rename(FAR const char *oldpath, FAR const char *newpath); -int sprintf(FAR char *buf, FAR const char *format, ...); -int asprintf (FAR char **ptr, FAR const char *fmt, ...); -int snprintf(FAR char *buf, size_t size, FAR const char *format, ...); +int sprintf(FAR char *buf, FAR const IPTR char *format, ...); +int asprintf (FAR char **ptr, FAR const IPTR char *fmt, ...); +int snprintf(FAR char *buf, size_t size, + FAR const IPTR char *format, ...); int sscanf(FAR const char *buf, FAR const char *fmt, ...); void perror(FAR const char *s); -int vprintf(FAR const char *format, va_list ap); -int vfprintf(FAR FILE *stream, const char *format, va_list ap); -int vsprintf(FAR char *buf, const char *format, va_list ap); -int vasprintf(FAR char **ptr, const char *fmt, va_list ap); -int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap); +int vprintf(FAR const IPTR FAR char *format, va_list ap); +int vfprintf(FAR FILE *stream, FAR const IPTR char *format, + va_list ap); +int vsprintf(FAR char *buf, FAR const IPTR char *format, va_list ap); +int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap); +int vsnprintf(FAR char *buf, size_t size, FAR const IPTR char *format, + va_list ap); int vsscanf(FAR const char *buf, FAR const char *s, va_list ap); /* Operations on file descriptors including: @@ -182,8 +187,8 @@ int vsscanf(FAR const char *buf, FAR const char *s, va_list ap); */ FAR FILE *fdopen(int fd, FAR const char *type); -int dprintf(int fd, FAR const char *fmt, ...); -int vdprintf(int fd, FAR const char *fmt, va_list ap); +int dprintf(int fd, FAR const IPTR char *fmt, ...); +int vdprintf(int fd, FAR const IPTR char *fmt, va_list ap); /* Operations on paths */ diff --git a/include/syslog.h b/include/syslog.h index 2dfef54b24..6c1316a7e6 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -41,6 +41,7 @@ ****************************************************************************/ #include +#include #include #include @@ -167,8 +168,8 @@ void closelog(void); * ****************************************************************************/ -int syslog(int priority, FAR const char *format, ...); -int vsyslog(int priority, FAR const char *src, va_list ap); +int syslog(int priority, FAR const IPTR char *format, ...); +int vsyslog(int priority, FAR const IPTR char *src, va_list ap); /**************************************************************************** * Name: lowsyslog and lowvsyslog @@ -198,8 +199,8 @@ int vsyslog(int priority, FAR const char *src, va_list ap); #ifdef CONFIG_ARCH_LOWPUTC -int lowsyslog(int priority, FAR const char *format, ...); -int lowvsyslog(int priority, FAR const char *format, va_list ap); +int lowsyslog(int priority, FAR const IPTR char *format, ...); +int lowvsyslog(int priority, FAR const IPTR char *format, va_list ap); #else diff --git a/libc/stdio/lib_asprintf.c b/libc/stdio/lib_asprintf.c index d61059f5b5..4c3f85760a 100644 --- a/libc/stdio/lib_asprintf.c +++ b/libc/stdio/lib_asprintf.c @@ -92,7 +92,7 @@ * ****************************************************************************/ -int asprintf (FAR char **ptr, const char *fmt, ...) +int asprintf (FAR char **ptr, FAR const IPTR char *fmt, ...) { va_list ap; int ret; diff --git a/libc/stdio/lib_dprintf.c b/libc/stdio/lib_dprintf.c index f3f9de8ee5..0b8f676145 100644 --- a/libc/stdio/lib_dprintf.c +++ b/libc/stdio/lib_dprintf.c @@ -47,7 +47,7 @@ * Name: dprintf ****************************************************************************/ -int dprintf(int fd, FAR const char *fmt, ...) +int dprintf(int fd, FAR const IPTR char *fmt, ...) { va_list ap; int ret; diff --git a/libc/stdio/lib_fprintf.c b/libc/stdio/lib_fprintf.c index d4420ada23..a0169972eb 100644 --- a/libc/stdio/lib_fprintf.c +++ b/libc/stdio/lib_fprintf.c @@ -79,7 +79,7 @@ * Name: fprintf ****************************************************************************/ -int fprintf(FAR FILE *stream, FAR const char *fmt, ...) +int fprintf(FAR FILE *stream, FAR const IPTR char *fmt, ...) { va_list ap; int n; diff --git a/libc/stdio/lib_libsprintf.c b/libc/stdio/lib_libsprintf.c index baa493c7a7..8668a54674 100644 --- a/libc/stdio/lib_libsprintf.c +++ b/libc/stdio/lib_libsprintf.c @@ -76,7 +76,8 @@ * Name: lib_sprintf ****************************************************************************/ -int lib_sprintf(FAR struct lib_outstream_s *obj, const char *fmt, ...) +int lib_sprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *fmt, + ...) { va_list ap; int n; diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index 6c1b295811..c81e55617f 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -145,7 +145,8 @@ enum /* Pointer to ASCII conversion */ #ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p); +static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, + FAR void *p); #ifndef CONFIG_NOPRINTF_FIELDWIDTH static int getsizesize(uint8_t fmt, uint8_t flags, FAR void *p) #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -154,7 +155,8 @@ static int getsizesize(uint8_t fmt, uint8_t flags, FAR void *p) /* Unsigned int to ASCII conversion */ static void utodec(FAR struct lib_outstream_s *obj, unsigned int n); -static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a); +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, + uint8_t a); static void utooct(FAR struct lib_outstream_s *obj, unsigned int n); static void utobin(FAR struct lib_outstream_s *obj, unsigned int n); static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, @@ -169,7 +171,8 @@ static int getusize(uint8_t fmt, uint8_t flags, unsigned int lln); #ifdef CONFIG_LONG_IS_NOT_INT static void lutodec(FAR struct lib_outstream_s *obj, unsigned long ln); -static void lutohex(FAR struct lib_outstream_s *obj, unsigned long ln, uint8_t a); +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long ln, + uint8_t a); static void lutooct(FAR struct lib_outstream_s *obj, unsigned long ln); static void lutobin(FAR struct lib_outstream_s *obj, unsigned long ln); static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, @@ -184,14 +187,16 @@ static int getlusize(uint8_t fmt, FAR uint8_t flags, unsigned long ln); #if defined(CONFIG_HAVE_LONG_LONG) && defined(CONFIG_LIBC_LONG_LONG) static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, uint8_t a); +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, + uint8_t a); static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long lln); static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long lln); static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long long lln); #ifndef CONFIG_NOPRINTF_FIELDWIDTH static void llfixup(uint8_t fmt, FAR uint8_t *flags, FAR long long *lln); -static int getllusize(uint8_t fmt, FAR uint8_t flags, FAR unsigned long long lln); +static int getllusize(uint8_t fmt, FAR uint8_t flags, + FAR unsigned long long lln); #endif #endif @@ -235,7 +240,8 @@ static const char g_nullstring[] = "(null)"; ****************************************************************************/ #ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p) +static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, + FAR void *p) { union { @@ -309,7 +315,8 @@ static void utodec(FAR struct lib_outstream_s *obj, unsigned int n) * Name: utohex ****************************************************************************/ -static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a) +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, + uint8_t a) { bool nonzero = false; uint8_t bits; @@ -376,7 +383,8 @@ static void utobin(FAR struct lib_outstream_s *obj, unsigned int n) * Name: utoascii ****************************************************************************/ -static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned int n) +static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned int n) { /* Perform the integer conversion according to the format specifier */ @@ -577,7 +585,8 @@ static void lutodec(FAR struct lib_outstream_s *obj, unsigned long n) * Name: lutohex ****************************************************************************/ -static void lutohex(FAR struct lib_outstream_s *obj, unsigned long n, uint8_t a) +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long n, + uint8_t a) { bool nonzero = false; uint8_t bits; @@ -644,7 +653,8 @@ static void lutobin(FAR struct lib_outstream_s *obj, unsigned long n) * Name: lutoascii ****************************************************************************/ -static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long ln) +static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned long ln) { /* Perform the integer conversion according to the format specifier */ @@ -827,7 +837,8 @@ static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long n) * Name: llutohex ****************************************************************************/ -static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long n, uint8_t a) +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long n, + uint8_t a) { bool nonzero = false; uint8_t bits; @@ -894,7 +905,8 @@ static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long n) * Name: llutoascii ****************************************************************************/ -static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long long lln) +static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned long long lln) { /* Perform the integer conversion according to the format specifier */ @@ -1164,7 +1176,8 @@ static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, * libc/stdio/lib_vsprintf ****************************************************************************/ -int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list ap) +int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *src, + va_list ap) { FAR char *ptmp; #ifndef CONFIG_NOPRINTF_FIELDWIDTH @@ -1616,5 +1629,3 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a return obj->nput; } - - diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index f4289c9b57..7088452393 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -86,7 +86,7 @@ * Name: printf ****************************************************************************/ -int printf(FAR const char *fmt, ...) +int printf(FAR const IPTR char *fmt, ...) { va_list ap; int ret; diff --git a/libc/stdio/lib_snprintf.c b/libc/stdio/lib_snprintf.c index 53e9a2cbcc..ca27bb0b46 100644 --- a/libc/stdio/lib_snprintf.c +++ b/libc/stdio/lib_snprintf.c @@ -80,7 +80,7 @@ * sprintf ****************************************************************************/ -int snprintf(FAR char *buf, size_t size, const char *format, ...) +int snprintf(FAR char *buf, size_t size, FAR const IPTR char *format, ...) { union { diff --git a/libc/stdio/lib_sprintf.c b/libc/stdio/lib_sprintf.c index 5420e1e539..e857c79cab 100644 --- a/libc/stdio/lib_sprintf.c +++ b/libc/stdio/lib_sprintf.c @@ -76,7 +76,7 @@ * sprintf ****************************************************************************/ -int sprintf (FAR char *buf, const char *fmt, ...) +int sprintf (FAR char *buf, FAR const IPTR char *fmt, ...) { struct lib_memoutstream_s memoutstream; va_list ap; diff --git a/libc/stdio/lib_vasprintf.c b/libc/stdio/lib_vasprintf.c index 53e0a15706..e74cce46cc 100644 --- a/libc/stdio/lib_vasprintf.c +++ b/libc/stdio/lib_vasprintf.c @@ -112,7 +112,7 @@ * ****************************************************************************/ -int vasprintf(FAR char **ptr, FAR const char *fmt, va_list ap) +int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap) { struct lib_outstream_s nulloutstream; struct lib_memoutstream_s memoutstream; diff --git a/libc/stdio/lib_vdprintf.c b/libc/stdio/lib_vdprintf.c index 26959b5de8..9c76078d6e 100644 --- a/libc/stdio/lib_vdprintf.c +++ b/libc/stdio/lib_vdprintf.c @@ -48,7 +48,7 @@ * Public Functions ****************************************************************************/ -int vdprintf(int fd, FAR const char *fmt, va_list ap) +int vdprintf(int fd, FAR const IPTR char *fmt, va_list ap) { struct lib_rawoutstream_s rawoutstream; diff --git a/libc/stdio/lib_vfprintf.c b/libc/stdio/lib_vfprintf.c index 328fc42f82..783dc8b916 100644 --- a/libc/stdio/lib_vfprintf.c +++ b/libc/stdio/lib_vfprintf.c @@ -76,7 +76,7 @@ * Public Functions ****************************************************************************/ -int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) +int vfprintf(FAR FILE *stream, FAR const IPTR char *fmt, va_list ap) { struct lib_stdoutstream_s stdoutstream; int n = ERROR; diff --git a/libc/stdio/lib_vprintf.c b/libc/stdio/lib_vprintf.c index 52e6fc9107..ee9a227c01 100644 --- a/libc/stdio/lib_vprintf.c +++ b/libc/stdio/lib_vprintf.c @@ -83,7 +83,7 @@ * Name: vprintf ****************************************************************************/ -int vprintf(FAR const char *fmt, va_list ap) +int vprintf(FAR const IPTR char *fmt, va_list ap) { /* vfprintf into stdout */ diff --git a/libc/stdio/lib_vsnprintf.c b/libc/stdio/lib_vsnprintf.c index ad329e173e..6952ed5ad6 100644 --- a/libc/stdio/lib_vsnprintf.c +++ b/libc/stdio/lib_vsnprintf.c @@ -80,7 +80,8 @@ * Name: vsnprintf ****************************************************************************/ -int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap) +int vsnprintf(FAR char *buf, size_t size, FAR const IPTR char *format, + va_list ap) { struct lib_memoutstream_s memoutstream; int n; diff --git a/libc/stdio/lib_vsprintf.c b/libc/stdio/lib_vsprintf.c index 0ad85086bf..f919de0887 100644 --- a/libc/stdio/lib_vsprintf.c +++ b/libc/stdio/lib_vsprintf.c @@ -79,7 +79,7 @@ * Name: vsprintf ****************************************************************************/ -int vsprintf(FAR char *dest, const char *src, va_list ap) +int vsprintf(FAR char *dest, FAR const IPTR char *src, va_list ap) { struct lib_memoutstream_s memoutstream; diff --git a/libc/syslog/lib_lowsyslog.c b/libc/syslog/lib_lowsyslog.c index 7cbc59180b..1ea8540781 100644 --- a/libc/syslog/lib_lowsyslog.c +++ b/libc/syslog/lib_lowsyslog.c @@ -93,7 +93,7 @@ * ****************************************************************************/ -static inline int lowvsyslog_internal(FAR const char *fmt, va_list ap) +static inline int lowvsyslog_internal(FAR const IPTR char *fmt, va_list ap) { struct lib_outstream_s stream; @@ -121,7 +121,7 @@ static inline int lowvsyslog_internal(FAR const char *fmt, va_list ap) * ****************************************************************************/ -int lowvsyslog(int priority, FAR const char *fmt, va_list ap) +int lowvsyslog(int priority, FAR const IPTR char *fmt, va_list ap) { int ret = 0; @@ -154,7 +154,7 @@ int lowvsyslog(int priority, FAR const char *fmt, va_list ap) * ****************************************************************************/ -int lowsyslog(int priority, FAR const char *fmt, ...) +int lowsyslog(int priority, FAR const IPTR char *fmt, ...) { va_list ap; int ret; diff --git a/libc/syslog/lib_syslog.c b/libc/syslog/lib_syslog.c index 533f61bec5..ca9ee014fc 100644 --- a/libc/syslog/lib_syslog.c +++ b/libc/syslog/lib_syslog.c @@ -92,7 +92,7 @@ * ****************************************************************************/ -static inline int vsyslog_internal(FAR const char *fmt, va_list ap) +static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap) { #if defined(CONFIG_SYSLOG) struct lib_outstream_s stream; @@ -190,7 +190,7 @@ static inline int vsyslog_internal(FAR const char *fmt, va_list ap) * ****************************************************************************/ -int vsyslog(int priority, FAR const char *fmt, va_list ap) +int vsyslog(int priority, FAR const IPTR char *fmt, va_list ap) { int ret = 0; @@ -220,7 +220,7 @@ int vsyslog(int priority, FAR const char *fmt, va_list ap) * ****************************************************************************/ -int syslog(int priority, FAR const char *fmt, ...) +int syslog(int priority, FAR const IPTR char *fmt, ...) { va_list ap; int ret; -- GitLab From ae71c9b4473443cc0d11a1ad3779b538427466fb Mon Sep 17 00:00:00 2001 From: Vladimir Komendantskiy Date: Tue, 5 Jan 2016 10:58:58 -0600 Subject: [PATCH 502/858] Fix a compile time error in drivers/net/tun.c. --- ChangeLog | 5 ++- drivers/net/tun.c | 85 ++++++++++++++++++----------------------------- 2 files changed, 36 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d1113ba38..b7c3f724d2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11284,4 +11284,7 @@ example, 'const char' and 'const char*'. For Atmel compiler these will become 'const __flash char' and 'const __memx char*'. All printf() functions and syslog() functions are changed so that the qualifier is - used with the format parameter. From Dimitry Kloper. + used with the format parameter. From Dimitry Kloper (2016-01-05). + * drivers/net/tun.c: Fix a compile time error in the TUN driver. From + Vladimir Komendantskiy (2016-01-05). + diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 088e063ab1..97a4fd7d26 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -425,75 +425,54 @@ static void tun_receive(FAR struct tun_device_s *priv) /* We only accept IP packets of the configured type and ARP packets */ -#ifdef CONFIG_NET_IPv4 - { - nllvdbg("IPv4 frame\n"); - NETDEV_RXIPV4(&priv->dev); +#if defined(CONFIG_NET_IPv4) + nllvdbg("IPv4 frame\n"); + NETDEV_RXIPV4(&priv->dev); - /* Give the IPv4 packet to the network layer */ + /* Give the IPv4 packet to the network layer */ - ipv4_input(&priv->dev); + ipv4_input(&priv->dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ - if (priv->dev.d_len > 0) - { - priv->write_d_len = priv->dev.d_len; - tun_transmit(priv); - } - else - { - priv->write_d_len = 0; - tun_pollnotify(priv, POLLOUT); - } + if (priv->dev.d_len > 0) + { + priv->write_d_len = priv->dev.d_len; + tun_transmit(priv); } else -#endif - -#if 0 -#ifdef CONFIG_NET_IPv6 - if (BUF->type == HTONS(ETHTYPE_IP6)) { - nllvdbg("Iv6 frame\n"); - NETDEV_RXIPV6(&priv->dev); - - /* Give the IPv6 packet to the network layer */ - - ipv6_input(&priv->dev); + priv->write_d_len = 0; + tun_pollnotify(priv, POLLOUT); + } - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ +#elif defined(CONFIG_NET_IPv6) + nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->dev); - if (priv->dev.d_len > 0) - { - /* Update the Ethernet header with the correct MAC address */ + /* Give the IPv6 packet to the network layer */ -#ifdef CONFIG_NET_IPv4 - if (IFF_IS_IPv4(priv->dev.d_flags)) - { - arp_out(&priv->dev); - } - else -#endif -#ifdef CONFIG_NET_IPv6 - { - neighbor_out(&priv->dev); - } -#endif + ipv6_input(&priv->dev); - /* And send the packet */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ - tun_transmit(priv); - } + if (priv->dev.d_len > 0) + { + priv->write_d_len = priv->dev.d_len; + tun_transmit(priv); } else -#endif { - NETDEV_RXDROPPED(&priv->dev); + priv->write_d_len = 0; + tun_pollnotify(priv, POLLOUT); } + +#else + NETDEV_RXDROPPED(&priv->dev); #endif } -- GitLab From 06438b0dcc59ba29328a7b199d697975ab8ea96d Mon Sep 17 00:00:00 2001 From: Dimitry Kloper Date: Mon, 4 Jan 2016 22:01:47 +0200 Subject: [PATCH 503/858] Fix 64-bit clock-related constant value evaluation for AVR compiler This may be specific for Atmel AVR8 toolchain compiler. The problem is that despite of being 8-bit architecture avr-gcc supports uint64_t, but the following code uint64_t value = 10000 * 1000; produces a wrong negative value in the final code (tested both with and without optimization). The work-around is simple: uint64_t value = 10000 * 1000L; The code is a reduced part from sched/signal/sig_timedwait.c where waitticks64 is calculated using NSEC_PER_TICK. This one is defined as USEC_PER_TICK * NSEC_PER_USEC which leads to the example above. --- include/nuttx/clock.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index c091300dbb..49659f04cb 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -98,16 +98,16 @@ /* Timing constants *********************************************************/ -#define NSEC_PER_SEC 1000000000 -#define USEC_PER_SEC 1000000 -#define MSEC_PER_SEC 1000 -#define DSEC_PER_SEC 10 -#define NSEC_PER_DSEC 100000000 -#define USEC_PER_DSEC 100000 -#define MSEC_PER_DSEC 100 -#define NSEC_PER_MSEC 1000000 -#define USEC_PER_MSEC 1000 -#define NSEC_PER_USEC 1000 +#define NSEC_PER_SEC 1000000000L +#define USEC_PER_SEC 1000000L +#define MSEC_PER_SEC 1000L +#define DSEC_PER_SEC 10L +#define NSEC_PER_DSEC 100000000L +#define USEC_PER_DSEC 100000L +#define MSEC_PER_DSEC 100L +#define NSEC_PER_MSEC 1000000L +#define USEC_PER_MSEC 1000L +#define NSEC_PER_USEC 1000L /* If CONFIG_SCHED_TICKLESS is not defined, then the interrupt interval of * the system timer is given by USEC_PER_TICK. This is the expected number -- GitLab From 670ac9fb2f4bd6de7b43918eafc5ac590ac7a21d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 5 Jan 2016 14:46:49 -0600 Subject: [PATCH 504/858] Fix an ommission in compiler.h --- configs | 2 +- include/nuttx/compiler.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/configs b/configs index d4540c0f83..16d7a0dab2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d4540c0f83378a6680ffd792ff1e4a8ca0ddd8b8 +Subproject commit 16d7a0dab2c4a48583d40bcf1dbf8e9a74316e91 diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 4ad2400456..f14d55c152 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -147,12 +147,17 @@ # undef CONFIG_PTR_IS_NOT_INT #elif defined(__AVR__) - +# if defined(CONFIG_AVR_HAS_MEMX_PTR) /* I-space access qualifiers needed by Harvard architecture */ -# if defined(CONFIG_AVR_HAS_MEMX_PTR) # define IOBJ __flash # define IPTR __memx + +# else +/* No I-space access qualifiers */ + +# define IOBJ +# define IPTR # endif /* Select the small, 16-bit addressing model */ -- GitLab From b28bf55fb0b1a27ba80e8f02fe1ae9f396e26309 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 5 Jan 2016 14:52:09 -0600 Subject: [PATCH 505/858] Cosmetic spacing change --- include/nuttx/compiler.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index f14d55c152..858902f696 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -136,11 +136,11 @@ /* Select the small, 16-bit addressing model */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Long and int are not the same size */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size */ @@ -156,17 +156,17 @@ # else /* No I-space access qualifiers */ -# define IOBJ -# define IPTR +# define IOBJ +# define IPTR # endif -/* Select the small, 16-bit addressing model */ +/* Select the small, 16-bit addressing model (for D-Space) */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Long and int are not the same size */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size */ @@ -186,7 +186,7 @@ /* Select the small, 16-bit addressing model */ -# define CONFIG_SMALL_MEMORY 1 +# define CONFIG_SMALL_MEMORY 1 /* Normally, mc68hc1x code is compiled with the -mshort option * which results in a 16-bit integer. If -mnoshort is defined @@ -196,7 +196,7 @@ # if __INT__ == 16 /* int is 16-bits, long is 32-bits */ -# define CONFIG_LONG_IS_NOT_INT 1 +# define CONFIG_LONG_IS_NOT_INT 1 /* Pointers and int are the same size (16-bits) */ @@ -208,7 +208,7 @@ /* Pointers and int are NOT the same size */ -# define CONFIG_PTR_IS_NOT_INT 1 +# define CONFIG_PTR_IS_NOT_INT 1 # endif #else -- GitLab From ce2a0b6b51c44858547470fe192fe90c7d2a5994 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 6 Jan 2016 10:05:39 -0600 Subject: [PATCH 506/858] Eliminate a warning --- arch | 2 +- configs | 2 +- drivers/serial/serial.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 0761b677ef..2b89cb7d76 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0761b677efa861b6369cea195968a59e4a6e6860 +Subproject commit 2b89cb7d768c94c11a3902e85fd0858c4033ef74 diff --git a/configs b/configs index 16d7a0dab2..dd63cfca08 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 16d7a0dab2c4a48583d40bcf1dbf8e9a74316e91 +Subproject commit dd63cfca08a5a3baf8e829080bf9580723765566 diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 378a696b4c..32d2a073ad 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -900,7 +900,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) irqrestore(state); - *(int *)arg = count; + *(FAR int *)((uintptr_t)arg) = count; ret = 0; } break; @@ -923,7 +923,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) irqrestore(state); - *(int *)arg = count; + *(FAR int *)((uintptr_t)arg) = count; ret = 0; } break; -- GitLab From 31294fb46804503e383530cd0b7ea21599e27653 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 7 Jan 2016 08:15:00 -0600 Subject: [PATCH 507/858] Update submodules --- Documentation | 2 +- arch | 2 +- configs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index b4e33ca73c..4217e1a644 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit b4e33ca73c44aaca5f6986650e6d215a4d5adcab +Subproject commit 4217e1a644a0dfe8f111ab07f9df38af2ea906d7 diff --git a/arch b/arch index 2b89cb7d76..ea52a0fb85 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 2b89cb7d768c94c11a3902e85fd0858c4033ef74 +Subproject commit ea52a0fb857e10b4def9c68ef355db1390be213b diff --git a/configs b/configs index dd63cfca08..d28a8f8d19 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dd63cfca08a5a3baf8e829080bf9580723765566 +Subproject commit d28a8f8d19ce051147cf27eb7f85668ea588d33c -- GitLab From 5496c450c537acdeb10ee7eeb0b8c0937df14262 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 8 Jan 2016 07:51:21 -0600 Subject: [PATCH 508/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ea52a0fb85..629672a06e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ea52a0fb857e10b4def9c68ef355db1390be213b +Subproject commit 629672a06e2b1e88ef5bf606eb03cf42e3b50afd diff --git a/configs b/configs index d28a8f8d19..0fe559f698 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d28a8f8d19ce051147cf27eb7f85668ea588d33c +Subproject commit 0fe559f698b7ed422a826dd9d69018167ce28054 -- GitLab From 953298d51600c7fdc3047bc8383b4b334c030733 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 8 Jan 2016 11:26:45 -0600 Subject: [PATCH 509/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 629672a06e..36626dbc79 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 629672a06e2b1e88ef5bf606eb03cf42e3b50afd +Subproject commit 36626dbc796dfdda937ff197df2a9b84a425e3df diff --git a/configs b/configs index 0fe559f698..a8e9be00f9 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0fe559f698b7ed422a826dd9d69018167ce28054 +Subproject commit a8e9be00f98fe4abe13ad2703637f00c516d7d7d -- GitLab From d219f3a36e49914c7184514d8e6ace4f3b5aabf2 Mon Sep 17 00:00:00 2001 From: Dimitry Kloper Date: Sat, 9 Jan 2016 14:28:12 +0200 Subject: [PATCH 510/858] Introduce arch-specific debug macro hooks Make it possible for arch code to provide hook macros for NuttX dbg that will lead to arch-specific syslog() and lowsyslog() variants. --- Kconfig | 6 ++++++ include/debug.h | 27 +++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Kconfig b/Kconfig index 03a2a872a5..bc2e4316da 100644 --- a/Kconfig +++ b/Kconfig @@ -376,6 +376,12 @@ config ARCH_STDARG_H ARCH_STDARG_H=y and providing. If ARCH_STDARG_H, is not defined, then the stdarg.h header file will stay out-of-the-way in include/nuttx/. +config ARCH_DEBUG_H + bool "debug.h" + default n + ---help--- + The debug.h contains architecture dependent debugging primitives + endmenu # Customize Header Files menu "Debug Options" diff --git a/include/debug.h b/include/debug.h index b1bb2fc9d1..0f89753072 100644 --- a/include/debug.h +++ b/include/debug.h @@ -43,6 +43,10 @@ #include #include +#ifdef CONFIG_ARCH_DEBUG_H +# include +#endif + #include /**************************************************************************** @@ -94,6 +98,17 @@ # define EXTRA_ARG #endif +/* + * The actual logger function may be overridden in arch/debug.h if needed. + */ + +#ifndef __arch_syslog +# define __arch_syslog syslog +#endif +#ifndef __arch_lowsyslog +# define __arch_lowsyslog lowsyslog +#endif + /* Debug macros will differ depending upon if the toolchain supports * macros with a variable number of arguments or not. */ @@ -104,30 +119,30 @@ #ifdef CONFIG_DEBUG # define dbg(format, ...) \ - syslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + __arch_syslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # ifdef CONFIG_ARCH_LOWPUTC # define lldbg(format, ...) \ - lowsyslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + __arch_lowsyslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else # define lldbg(x...) # endif # ifdef CONFIG_DEBUG_VERBOSE # define vdbg(format, ...) \ - syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + __arch_syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # ifdef CONFIG_ARCH_LOWPUTC # define llvdbg(format, ...) \ - lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + __arch_lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else # define llvdbg(x...) # endif -# else +# else /* CONFIG_DEBUG_VERBOSE */ # define vdbg(x...) # define llvdbg(x...) -# endif +# endif /* CONFIG_DEBUG_VERBOSE */ #else /* CONFIG_DEBUG */ -- GitLab From 1ac6ecac87ec6ef30587974c7c2a1f4a0bb1dfdf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 07:27:22 -0600 Subject: [PATCH 511/858] Changes to last pull request needed for conformance with coding standard --- Kconfig | 2 +- arch | 2 +- include/debug.h | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Kconfig b/Kconfig index bc2e4316da..09991c5e6d 100644 --- a/Kconfig +++ b/Kconfig @@ -380,7 +380,7 @@ config ARCH_DEBUG_H bool "debug.h" default n ---help--- - The debug.h contains architecture dependent debugging primitives + The debug.h contains architecture dependent debugging primitives endmenu # Customize Header Files diff --git a/arch b/arch index 36626dbc79..3fbe4f51dc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 36626dbc796dfdda937ff197df2a9b84a425e3df +Subproject commit 3fbe4f51dc531070c93821018a342cfb5d8a6c02 diff --git a/include/debug.h b/include/debug.h index 0f89753072..066ba5a2d6 100644 --- a/include/debug.h +++ b/include/debug.h @@ -98,9 +98,7 @@ # define EXTRA_ARG #endif -/* - * The actual logger function may be overridden in arch/debug.h if needed. - */ +/* The actual logger function may be overridden in arch/debug.h if needed. */ #ifndef __arch_syslog # define __arch_syslog syslog -- GitLab From 87a8616976a4bfda1557ca7ec8469b174763839d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 07:39:38 -0600 Subject: [PATCH 512/858] Update ChangeLog --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index b7c3f724d2..58ee7eef19 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11287,4 +11287,9 @@ used with the format parameter. From Dimitry Kloper (2016-01-05). * drivers/net/tun.c: Fix a compile time error in the TUN driver. From Vladimir Komendantskiy (2016-01-05). + * Kconfig and include/debug.h: Add configuration to support an + architecture-specific debug.h header file. From Dimitri Kloper + (2016-01-09). + * arch/avr/include/debug.h: Add an AVR-specific header file used when + the AVR MEMX pointer is used. From Dimitri Kloper (2016-01-09). -- GitLab From b390bd802a8595018e2bc2411ccd3441ac162057 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 13:51:34 -0600 Subject: [PATCH 513/858] tools/cnvwindeps.c: Add a tool that will convert dependencies created by a Windows native toolchain for use the Cygwin make --- ChangeLog | 3 + arch | 2 +- configs | 2 +- tools/Makefile.host | 14 ++- tools/cnvwindeps.c | 266 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 tools/cnvwindeps.c diff --git a/ChangeLog b/ChangeLog index 58ee7eef19..dcb13526e1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11292,4 +11292,7 @@ (2016-01-09). * arch/avr/include/debug.h: Add an AVR-specific header file used when the AVR MEMX pointer is used. From Dimitri Kloper (2016-01-09). + * tools/cnvwindeps.c: Add a tool that will convert paths in + dependencies generated by a Windows compiler so that they can be + used with the Cygwin make (2016-01-09). diff --git a/arch b/arch index 3fbe4f51dc..4570fe271a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3fbe4f51dc531070c93821018a342cfb5d8a6c02 +Subproject commit 4570fe271a034ae7aa23e579064f90c75594f985 diff --git a/configs b/configs index a8e9be00f9..6fb104206e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a8e9be00f98fe4abe13ad2703637f00c516d7d7d +Subproject commit 6fb104206eed94cba309bb827d59780e3d24f002 diff --git a/tools/Makefile.host b/tools/Makefile.host index 1f9f0027d0..3cc0080261 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -63,7 +63,7 @@ endif all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \ configure$(HOSTEXEEXT) mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \ mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \ - nxstyle$(HOSTEXEEXT) + cnvwindeps$(HOSTEXEEXT) nxstyle$(HOSTEXEEXT) default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) ifdef HOSTEXEEXT @@ -153,7 +153,7 @@ ifdef HOSTEXEEXT bdf-converter: bdf-converter$(HOSTEXEEXT) endif -# nxsytle - Check a file for compliance to NuttX coding style +# nxstyle - Check a file for compliance to NuttX coding style nxstyle$(HOSTEXEEXT): nxstyle.c $(Q) $(HOSTCC) $(HOSTCFLAGS) -o nxstyle$(HOSTEXEEXT) nxstyle.c @@ -162,6 +162,16 @@ ifdef HOSTEXEEXT nxstyle: nxstyle$(HOSTEXEEXT) endif +# cnvwindeps - Convert dependences generated by a Windows native toolchain +# for use in a Cygwin/POSIX build environment + +cnvwindeps$(HOSTEXEEXT): cnvwindeps.c + $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cnvwindeps$(HOSTEXEEXT) cnvwindeps.c + +ifdef HOSTEXEEXT +cnvwindeps: cnvwindeps$(HOSTEXEEXT) +endif + # Create dependencies for a list of files mkdeps$(HOSTEXEEXT): mkdeps.c csvparser.c diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c new file mode 100644 index 0000000000..c390e6f778 --- /dev/null +++ b/tools/cnvwindeps.c @@ -0,0 +1,266 @@ +/**************************************************************************** + * tools/cnvwindeps.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MAX_LINE 1024 +#define MAX_PATH 1024 + +/**************************************************************************** + * Global Data + ****************************************************************************/ + +static unsigned long g_lineno; +static char g_line[MAX_LINE]; +static char g_dequoted[MAX_PATH]; +static char g_posix[MAX_PATH]; +static const char g_cygpath[] = "/usr/bin/cygpath"; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static char *skip_spaces(char *ptr) +{ + while (*ptr && isspace((int)*ptr)) ptr++; + return ptr; +} + +static char *find_spaces(char *ptr) +{ + bool quoted = false; + + while (*ptr) + { + if (ptr[0] == '\\' && isspace((int)ptr[1])) + { + quoted = true; + ptr++; + } + else if (!quoted && isspace((int)*ptr)) + { + break; + } + else + { + quoted = false; + ptr++; + } + } + + return ptr; +} + +static bool dequote_path(const char *winpath) +{ + char *dest = g_dequoted; + const char *src = winpath; + int len = 0; + bool quoted = false; + + while (*src && len < MAX_PATH) + { + if (src[0] != '\\' || (src[1] != ' ' && src[1] != '(' && src[1] != ')')) + { + *dest++ = *src; + len++; + } + else + { + quoted = true; + } + + src++; + } + + if (*src || len >= MAX_PATH) + { + fprintf(stderr, "%lu: Line truncated\n", g_lineno); + exit(EXIT_FAILURE); + } + + *dest = '\0'; + return quoted; +} + +static bool convert_path(const char *winpath) +{ + ssize_t size; + ssize_t ret; + bool quoted; + + quoted = dequote_path(winpath); + + size = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, g_dequoted, NULL, 0); + if (size > MAX_PATH) + { + fprintf(stderr, "%lu: POSIX path too long: %lu\n", + g_lineno, (unsigned long)size); + exit(EXIT_FAILURE); + } + + ret = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, g_dequoted, g_posix, MAX_PATH); + if (ret < 0) + { + fprintf(stderr, "%lu: cygwin_conv_path '%s' failed: %s\n", + g_lineno, g_dequoted, strerror(errno)); + exit(EXIT_FAILURE); + } + + return quoted; +} + +static void show_usage(const char *progname) +{ + fprintf(stderr, "USAGE: %s \n", progname); + exit(EXIT_FAILURE); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + char *path; + char *next; + FILE *stream; + bool begin; + bool quoted; + + if (argc != 2) + { + fprintf(stderr, "Unexpected number of arguments\n"); + show_usage(argv[0]); + } + + stream = fopen(argv[1], "r"); + if (!stream) + { + fprintf(stderr, "open %s failed: %s\n", argv[1], strerror(errno)); + exit(EXIT_FAILURE); + } + + begin = true; + g_lineno = 0; + + while (fgets(g_line, MAX_LINE, stream) != NULL) + { + g_lineno++; + next = g_line; + + for (; ; ) + { + if (begin) + { + path = skip_spaces(next); + next = strchr(path, ':'); + if (!next) + { + fprintf(stderr, "%lu: Expected semicolon\n", g_lineno); + exit(EXIT_FAILURE); + } + + if (*next != '\0') + { + *next++ = '\0'; + } + + quoted = convert_path(path); + if (quoted) + { + printf("\"%s\":", g_posix); + } + else + { + printf("%s:", g_posix); + } + + begin = false; + } + else + { + path = skip_spaces(next); + next = find_spaces(path); + + if (path[0] == '\\') + { + break; + } + else if (strcmp(path, "") == 0) + { + printf("\n\n"); + begin = true; + break; + } + else + { + if (*next != '\0') + { + *next++ = '\0'; + } + + quoted = convert_path(path); + if (quoted) + { + printf(" \\\n\t\"%s\"", g_posix); + } + else + { + printf(" \\\n\t%s", g_posix); + } + } + } + } + } + + fclose(stream); + return 0; +} -- GitLab From 7f041b2af4afed4e8738992a4506edb29f3da561 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 14:27:22 -0600 Subject: [PATCH 514/858] Update README --- Documentation | 2 +- README.txt | 11 ----------- configs | 2 +- tools/README.txt | 15 ++++++++++++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Documentation b/Documentation index 4217e1a644..1d164c4df5 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 4217e1a644a0dfe8f111ab07f9df38af2ea906d7 +Subproject commit 1d164c4df5b6577c52f88d56ce270bd4f7556963 diff --git a/README.txt b/README.txt index 48fcea6396..87fde12020 100644 --- a/README.txt +++ b/README.txt @@ -1112,17 +1112,6 @@ Window Native Toolchain Issues is not a long as you might think because there is no dependency checking if you are using a native Windows toolchain. That bring us to #3: - 3. Dependencies are not made when using Windows versions of the GCC on a POSIX - platform (i.e., Cygwin). This is because the dependencies are generated - using Windows paths which do not work with the Cygwin make. - - MKDEP = $(TOPDIR)/tools/mknulldeps.sh - - If you are building natively on Windows, then no such conflict exists - and the best selection is: - - MKDEP = $(TOPDIR)/tools/mkdeps.exe - General Pre-built Toolchain Issues To continue with the list of "Window Native Toolchain Issues" we can add diff --git a/configs b/configs index 6fb104206e..da294ce5cc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6fb104206eed94cba309bb827d59780e3d24f002 +Subproject commit da294ce5cc305030e4f9bb8bd238054f20317525 diff --git a/tools/README.txt b/tools/README.txt index 5766a98458..8578c32839 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -396,6 +396,8 @@ mkromfsimg.sh mkdeps.sh mkdeps.bat mkdeps.c +cnvwindeps.c +mkwindeps.sh mknulldeps.sh ------------- @@ -418,8 +420,15 @@ mknulldeps.sh script that produces dependencies well for POSIX style hosts (e..g., Linux and Cygwin). It does not work well for mixed environments with a Windows toolchain running in a POSIX style environment (hence, the - mknulldeps.sh script). And, of course, cannot be used in a Windows - nativ environment. + mkwindeps.sh script). And, of course, cannot be used in a Windows + native environment. + + mkwindeps.sh is a version that creates dependencies using the Windows + native toolchain. That generates Windows native paths in the dependency + file. But the mkwindeps.sh uses cnvwindeps.c to convert the Windows + paths to POSIX paths. This adds some time to the Windows dependency + generation but is generally th best option available for that mixed + environment of Cygwin with a native Windows GCC toolchain. [mkdeps.sh does have an option, --winpath, that purports to convert the dependencies generated by a Windows toolchain to POSIX format. @@ -437,7 +446,7 @@ mknulldeps.sh does not work well in mixed POSIX environment with a Windows toolchain. In that case, there are still issues with the conversion of things like 'c:\Program Files' to 'c:program files' by bash. Those issues may, - eventually be solvable but for now continue to use mknulldeps.sh in + eventually be solvable but for now continue to use mkwindeps.sh in that mixed environment. define.sh -- GitLab From 1608b7c33fcc42b1bcda6069503606316005db59 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 15:56:08 -0600 Subject: [PATCH 515/858] Some networking logic was used helpers from apps/netutils. Not good. Quick fix is to duplicate logic --- libc/netdb/Make.defs | 2 +- libc/netdb/lib_dns.h | 6 +- libc/netdb/lib_getdnsaddr.c | 98 +++++++++++++++++ net/procfs/netdev_statistics.c | 6 +- net/utils/Make.defs | 2 +- net/utils/net_ipv6_mask2pref.c | 188 +++++++++++++++++++++++++++++++++ net/utils/utils.h | 28 +++++ 7 files changed, 323 insertions(+), 7 deletions(-) create mode 100644 libc/netdb/lib_getdnsaddr.c create mode 100644 net/utils/net_ipv6_mask2pref.c diff --git a/libc/netdb/Make.defs b/libc/netdb/Make.defs index dbddf836d5..b9347eb0fc 100644 --- a/libc/netdb/Make.defs +++ b/libc/netdb/Make.defs @@ -48,7 +48,7 @@ endif # Add DNS lookup support ifeq ($(CONFIG_NETDB_DNSCLIENT),y) -CSRCS += lib_dnsclient.c +CSRCS += lib_dnsclient.c lib_getdnsaddr.c endif # Add the net directory to the build diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index dee8985f99..e3e5d3bae5 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -57,11 +57,11 @@ /* DNS client configuration **************************************************/ #ifndef CONFIG_NETDB_DNSCLIENT_ENTRIES -# define RESOLV_ENTRIES 4 -#else -# define RESOLV_ENTRIES CONFIG_NETDB_DNSCLIENT_ENTRIES +# define CONFIG_NETDB_DNSCLIENT_ENTRIES 4 #endif +#define RESOLV_ENTRIES CONFIG_NETDB_DNSCLIENT_ENTRIES + #ifndef CONFIG_NETDB_DNSCLIENT_MAXRESPONSE # define CONFIG_NETDB_DNSCLIENT_MAXRESPONSE 96 #endif diff --git a/libc/netdb/lib_getdnsaddr.c b/libc/netdb/lib_getdnsaddr.c new file mode 100644 index 0000000000..a6e6c4335a --- /dev/null +++ b/libc/netdb/lib_getdnsaddr.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * libc/netdb/lib_dnsgetaddr.c + * + * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include + +#include + +#include + +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_getaddr + * + * Description: + * Get the DNS server IPv4 address + * + * Parameters: + * ipaddr The location to return the IPv4 address + * + * Return: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int dns_getaddr(FAR struct in_addr *inaddr) +{ + struct sockaddr_in addr; + socklen_t addrlen; + int ret = -EINVAL; + + if (inaddr) + { + addrlen = sizeof(struct sockaddr_in); + ret = dns_getserver((FAR struct sockaddr *)&addr, &addrlen); + if (ret >= 0) + { + /* Sanity check */ + + DEBUGASSERT(addr.sin_family == AF_INET && + addrlen == sizeof(struct sockaddr_in)); + memcpy(inaddr, &addr.sin_addr, sizeof(struct in_addr)); + } + } + + return ret; +} + +#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index b81741a409..61bc0f3573 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -47,8 +47,10 @@ #include #include +#include #include "netdev/netdev.h" +#include "utils/utils.h" #include "procfs/procfs.h" #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ @@ -246,7 +248,7 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) "Mask:%s\n", inet_ntoa(addr)); #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) - netlib_get_ipv4dnsaddr(&addr); + dns_getaddr(&addr); len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tDNSaddr:%s\n", inet_ntoa(addr)); #endif @@ -255,7 +257,7 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) #ifdef CONFIG_NET_IPv6 /* Convert the 128 network mask to a human friendly prefix length */ - preflen = netlib_ipv6netmask2prefix(dev->d_ipv6netmask); + preflen = net_ipv6_mask2pref(dev->d_ipv6netmask); /* Show the assigned IPv6 address */ diff --git a/net/utils/Make.defs b/net/utils/Make.defs index 6be4afdfc1..5abcb9226c 100644 --- a/net/utils/Make.defs +++ b/net/utils/Make.defs @@ -41,7 +41,7 @@ NET_CSRCS += net_chksum.c # IPv6 utilities ifeq ($(CONFIG_NET_IPv6),y) -NET_CSRCS += net_ipv6_maskcmp.c net_ipv6_pref2mask.c +NET_CSRCS += net_ipv6_maskcmp.c net_ipv6_mask2pref.c net_ipv6_pref2mask.c endif # Non-interrupt level support required? diff --git a/net/utils/net_ipv6_mask2pref.c b/net/utils/net_ipv6_mask2pref.c new file mode 100644 index 0000000000..dd9e00b6d8 --- /dev/null +++ b/net/utils/net_ipv6_mask2pref.c @@ -0,0 +1,188 @@ +/**************************************************************************** + * net/utils/net_ipv6_mask2pref.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "utils/utils.h" + +#ifdef CONFIG_NET_IPv6 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint8_t g_nibblemap[16] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0: No bits, 1-7: Should not happen */ + 1, 1, 1, 1, /* 8: 1 bit, 9-b: Should not happen */ + 2, 2, 3, 4 /* c: 2 bits, d: Should not happen, e: 3 bits, f: 4 bits */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: net_msbits4 + * + * Description: + * Count the number of leading '1' bits in an 4-bit nibble + * + ****************************************************************************/ + +static inline uint8_t net_msbits4(uint8_t nibble) +{ + /* Return the number of leading zeroes: 0-4) */ + + return g_nibblemap[nibble]; +} + +/**************************************************************************** + * Name: net_msbits8 + * + * Description: + * Count the number of leading '1' bits in an 8-bit byte + * + ****************************************************************************/ + +static uint8_t net_msbits8(uint8_t byval) +{ + uint8_t ones; + + /* Check the MS nibble */ + + ones = net_msbits4(byval >> 4); + if (ones == 4) + { + /* All ones, try the LS nibble */ + + ones += net_msbits4(byval & 0x0f); + } + + /* Return the number of leading ones (0-8) */ + + return ones; +} + +/**************************************************************************** + * Name: net_msbits16 + * + * Description: + * Count the number of leading '1' bits in a 16-bit half-workd + * + ****************************************************************************/ + +static inline uint8_t net_msbits16(uint16_t hword) +{ + uint8_t ones; + + /* Look at the MS byte of the 16-bit value */ + + ones = net_msbits8((uint8_t)(hword >> 8)); + if (ones == 8) + { + /* All '1's, try the LS byte */ + + ones += net_msbits8((uint8_t)(hword & 0xff)); + } + + /* Return the number of leading ones (0-15) */ + + return ones; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: net_ipv6_mask2pref + * + * Description: + * Convert a 128-bit netmask to a prefix length. The Nuttx IPv6 + * networking uses 128-bit network masks internally. This function + * converts the IPv6 netmask to a prefix length. + * + * The prefix length is the number of MS '1' bits on in the netmask. + * This, of course, assumes that all MS bits are '1' and all LS bits are + * '0' with no intermixed 1's and 0's. This function searches from the MS + * bit until the first '0' is found (this does not necessary mean that + * there might not be additional '1' bits following the firs '0', but that + * will be a malformed netmask. + * + * Parameters: + * mask Points to an IPv6 netmask in the form of uint16_t[8] + * + * Return: + * The prefix length, range 0-128 on success; This function will not + * fail. + * + ****************************************************************************/ + +uint8_t net_ipv6_mask2pref(FAR const uint16_t *mask) +{ + uint8_t preflen; + int i; + + /* Count the leading all '1' 16-bit groups */ + + for (i = 0, preflen = 0; i < 8 && mask[i] == 0xffff; i++, preflen += 16); + + /* Now i either, (1) indexes past the end of the mask, or (2) is the index + * to the first half-word that is not equal to 0xffff. + */ + + if (i < 8) + { + preflen += net_msbits16(ntohs(mask[i])); + } + + /* Return the prefix length */ + + return preflen; +} + +#endif /* CONFIG_NET_IPv6 */ diff --git a/net/utils/utils.h b/net/utils/utils.h index d3644d446a..90592b2f7a 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -151,6 +151,34 @@ unsigned int net_dsec2tick(int dsec); unsigned int net_timeval2dsec(FAR struct timeval *tv, enum tv2ds_remainder_e remainder); +/**************************************************************************** + * Name: net_ipv6_mask2pref + * + * Description: + * Convert a 128-bit netmask to a prefix length. The Nuttx IPv6 + * networking uses 128-bit network masks internally. This function + * converts the IPv6 netmask to a prefix length. + * + * The prefix length is the number of MS '1' bits on in the netmask. + * This, of course, assumes that all MS bits are '1' and all LS bits are + * '0' with no intermixed 1's and 0's. This function searches from the MS + * bit until the first '0' is found (this does not necessary mean that + * there might not be additional '1' bits following the firs '0', but that + * will be a malformed netmask. + * + * Parameters: + * mask Points to an IPv6 netmask in the form of uint16_t[8] + * + * Return: + * The prefix length, range 0-128 on success; This function will not + * fail. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +uint8_t net_ipv6_mask2pref(FAR const uint16_t *mask); +#endif + /**************************************************************************** * Function: net_ipv6_pref2mask * -- GitLab From fbb4dcc0af4b5b1e61243cbc0999f5e80e5ab6fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 15:57:44 -0600 Subject: [PATCH 516/858] Some networking logic was used helpers from apps/netutils. Not good. Quick fix is to duplicate logic --- include/nuttx/net/dns.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/nuttx/net/dns.h b/include/nuttx/net/dns.h index 94da6abbec..f7dff02af6 100644 --- a/include/nuttx/net/dns.h +++ b/include/nuttx/net/dns.h @@ -198,6 +198,25 @@ int dns_setserver(FAR const struct sockaddr *addr, socklen_t addrlen); int dns_getserver(FAR struct sockaddr *addr, FAR socklen_t *addrlen); +/**************************************************************************** + * Name: dns_getaddr + * + * Description: + * Get the DNS server IPv4 address + * + * Parameters: + * ipaddr The location to return the IPv4 address + * + * Return: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv4 +int dns_getaddr(FAR struct in_addr *inaddr); +#endif + #undef EXTERN #if defined(__cplusplus) } -- GitLab From 468732e0643c99db616db20662aa98219a2d184a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 16:07:12 -0600 Subject: [PATCH 517/858] mkdeps.sh and mkdeps.bat have been deleted. All configurations must now use the compiler mkeps program --- ChangeLog | 3 + Documentation | 2 +- arch | 2 +- configs | 2 +- tools/README.txt | 26 +----- tools/mkdeps.bat | 200 ------------------------------------------- tools/mkdeps.sh | 218 ----------------------------------------------- 7 files changed, 9 insertions(+), 444 deletions(-) delete mode 100644 tools/mkdeps.bat delete mode 100755 tools/mkdeps.sh diff --git a/ChangeLog b/ChangeLog index 58ee7eef19..f0f79dde08 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11292,4 +11292,7 @@ (2016-01-09). * arch/avr/include/debug.h: Add an AVR-specific header file used when the AVR MEMX pointer is used. From Dimitri Kloper (2016-01-09). + * tools/mkdeps.c: Deleted mkdeps.sh and mkdeps.bat. The mkdeps + executable generated from mkdeps.c is now that the only supported + way to make dependencies (2016-01-09). diff --git a/Documentation b/Documentation index 4217e1a644..8830f8f638 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 4217e1a644a0dfe8f111ab07f9df38af2ea906d7 +Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 diff --git a/arch b/arch index 3fbe4f51dc..4570fe271a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 3fbe4f51dc531070c93821018a342cfb5d8a6c02 +Subproject commit 4570fe271a034ae7aa23e579064f90c75594f985 diff --git a/configs b/configs index a8e9be00f9..57c7e67c4d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a8e9be00f98fe4abe13ad2703637f00c516d7d7d +Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 diff --git a/tools/README.txt b/tools/README.txt index 5766a98458..7c88cef6c9 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -393,18 +393,15 @@ mkromfsimg.sh image. It accepts an rcS script "template" and generates and image that may be mounted under /etc in the NuttX pseudo file system. -mkdeps.sh -mkdeps.bat mkdeps.c mknulldeps.sh ------------- NuttX uses the GCC compilers capabilities to create Makefile dependencies. - The bash script mkdeps.sh is used to run GCC in order to create the - dependencies. If a NuttX configuration uses the GCC toolchain, its Make.defs - file (see configs/README.txt) will include a line like: + The program mkdeps is used to run GCC in order to create the dependencies. + If a NuttX configuration uses the GCC toolchain, its Make.defs file (see + configs/README.txt) will include a line like: - MKDEP = $(TOPDIR)/tools/mkdeps.sh, or MKDEP = $(TOPDIR)/tools/mkdeps[.exe] (See NOTE below) If the NuttX configuration does not use a GCC compatible toolchain, then @@ -414,23 +411,6 @@ mknulldeps.sh The mknulldeps.sh is a stub script that does essentially nothing. - NOTE: The mk*deps.* files are undergoing change. mkdeps.sh is a bash - script that produces dependencies well for POSIX style hosts (e..g., - Linux and Cygwin). It does not work well for mixed environments with - a Windows toolchain running in a POSIX style environment (hence, the - mknulldeps.sh script). And, of course, cannot be used in a Windows - nativ environment. - - [mkdeps.sh does have an option, --winpath, that purports to convert - the dependencies generated by a Windows toolchain to POSIX format. - However, that is not being used and mostly likely does not cover - all of the conversion cases.] - - mkdeps.bat is a simple port of the bash script to run in a Windows - command shell. However, it does not work well either because some - of the common CFLAGS use characters like '=' which are transformed - by the CMD.exe shell. - mkdeps.c generates mkdeps (on Linux) or mkdeps.exe (on Windows). However, this verison is still under-development. It works well in the all POSIX environment or in the all Windows environment but also diff --git a/tools/mkdeps.bat b/tools/mkdeps.bat deleted file mode 100644 index 64b4429d10..0000000000 --- a/tools/mkdeps.bat +++ /dev/null @@ -1,200 +0,0 @@ -@echo off - -rem tools/mkdeps.sh -rem -rem Copyright (C) 2012 Gregory Nutt. All rights reserved. -rem Author: Gregory Nutt -rem -rem Redistribution and use in source and binary forms, with or without -rem modification, are permitted provided that the following conditions -rem are met: -rem -rem 1. Redistributions of source code must retain the above copyright -rem notice, this list of conditions and the following disclaimer. -rem 2. Redistributions in binary form must reproduce the above copyright -rem notice, this list of conditions and the following disclaimer in -rem the documentation and/or other materials provided with the -rem distribution. -rem 3. Neither the name NuttX nor the names of its contributors may be -rem used to endorse or promote products derived from this software -rem without specific prior written permission. -rem -rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -rem POSSIBILITY OF SUCH DAMAGE. - -rem Accumulate CFLAGS up to "--" - -set cc= -set cflags= -set altpath= -set files= -set args= -set objpath= -set suffix=.o -set debug=n - -:Loop -if "%1"=="" goto Continue - -if "%1"=="--" ( - set cc=%cflags% - set cflags=%args% - set args= - goto NextParm -) - -if "%1"=="--dep-path" ( - if "%args%"=="" ( - set altpath=%altpath% %2 - ) else ( - set args=%args% %2 - ) - shift - goto NextParm -) - -if "%1"=="--obj-path" ( - set objpath=%2 - shift - goto NextParm -) - -if "%1"=="--obj-suffix" ( - set suffix=%2 - shift - goto NextParm -) - -if "%1"=="--dep-debug" ( -rem @echo on - set debug=y - goto NextParm -) - -if "%1"=="--help" goto Usage - -if "%args%"=="" ( - set args=%1 -) else ( - set args=%args% %1 -) - -:NextParm -shift -goto Loop -:Continue - -set files=%args% - -if "%debug%"=="y" ( - echo cc=%cc% - echo cflags=%cflags% - echo files=%files% - echo altpath=%altpath% -) - -rem Now check if we have everything - -if "%cc%"=="" ( - echo ERROR: No compiler specified - goto Usage -) - -if "%files%"=="" ( - rem Don't report an error -- this happens normally in some configurations - echo # No files specified for dependency generataion - goto End -) - -rem Then get the dependencies for each file - -if "%altpath%"=="" goto NoPaths -for %%G in (%files%) do ( - set fullpath= - set file=%%G - call :Checkpaths - if "%debug%"=="y" echo %file%: fullpath=%fullpath% - if "%fullpath%"=="" goto :NoFile - - mtarg="" - if "%objpath%"=="" ( - set objname=%~n1 - set mtarg="-MT %objpath%\%objname%%suffix% - ) - - if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath% - %cc% -M %mtarg% %cflags% %fullpath% || goto DepFail -) -goto :End - -:NoPaths -for %%G in (%files%) do ( - set fullpath= - set file=%%G - call :CheckFile %%G -) -goto :End - -:CheckFile -if "%debug%"=="y" echo Checkfile: Checking %file% -if not exist %file% goto :NoFile -set fullpath=%file% - if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath% -%cc% -M %cflags% %fullpath% || goto DepFail -goto :EOF - -:CheckPaths -for %%H in (%altpath%) do ( - set tmppath=%%H\%file% - if "%debug%"=="y" echo Checkfile: Checking %tmppath% - if exist %tmppath% ( - set fullpath=%tmppath% - goto :EOF - ) -) -goto :EOF - -:NoFile -echo ERROR: No readable file at %file% -goto Usage - -:DepFail -echo ERROR: Failed to created dependencies for %file% - -:Usage -echo Usage: mkdeps [OPTIONS] CC -- CFLAGS -- file [file [file...]] -echo Where: -echo CC -echo A variable number of arguments that define how to execute the compiler -echo CFLAGS -echo The compiler compilation flags -echo file -echo One or more C files whose dependencies will be checked. Each file is expected -echo to reside in the current directory unless --dep-path is provided on the command line -echo And [OPTIONS] include: -echo --dep-debug -echo Enable script debug -echo --dep-path ^ -echo Do not look in the current directory for the file. Instead, look in to see -echo if the file resides there. --dep-path may be used multiple times to specify -echo multiple alternative location -echo --obj-path ^ -echo The final objects will not reside in this path but, rather, at the path provided by -echo ^. if provided multiple time, only the last --obj-path will be used. -echo --obj-suffix ^ -echo If and object path is provided, then the extension will be assumed to be .o. This -echo default suffix can be overrided with this command line option. -echo --help -echo Shows this message and exits - -:End diff --git a/tools/mkdeps.sh b/tools/mkdeps.sh deleted file mode 100755 index 8a03ac5712..0000000000 --- a/tools/mkdeps.sh +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/bash -############################################################################ -# tools/mkdeps.sh -# -# Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ -# -# Usage: - -show_usage () -{ - echo "" - echo "$progname [OPTIONS] CC -- CFLAGS -- file [file [file...]]" - echo "" - echo "Where:" - echo " CC" - echo " A variable number of arguments that define how to execute the compiler" - echo " CFLAGS" - echo " The compiler compilation flags" - echo " file" - echo " One or more C files whose dependencies will be checked. Each file is expected" - echo " to reside in the current directory unless --dep-path is provided on the command line" - echo "" - echo "And [OPTIONS] include:" - echo " --dep-debug" - echo " Enable script debug" - echo " --dep-path " - echo " Do not look in the current directory for the file. Instead, look in to see" - echo " if the file resides there. --dep-path may be used multiple times to specify" - echo " multiple alternative location" - echo " --obj-path " - echo " The final objects will not reside in this path but, rather, at the path provided by" - echo " . if provided multiple time, only the last --obj-path will be used." - echo " --obj-suffix " - echo " If and object path is provided, then the extension will be assumed to be .o. This" - echo " default suffix can be overrided with this command line option." - echo " --winpaths " - echo " CC generates dependency lists using Windows paths (e.g., C:\blablah\blabla). This" - echo " switch instructs the script to use 'cygpath' to convert the Windows paths to Cygwin" - echo " paths" - echo " --help" - echo " Shows this message and exits" - exit 1 -} - -dodep () -{ - unset fullpath - if [ -z "$altpath" ]; then - if [ -r $1 ]; then - fullpath=$1 - else - echo "# ERROR: No readable file at $1" - show_usage - fi - else - for path in $altpath; do - tmppath=$path/$1 - if [ -r $tmppath ]; then - fullpath=$tmppath - break; - fi - done - if [ -z "$fullpath" ]; then - echo "# ERROR: No readable file for $1 found at any location" - show_usage - fi - fi - - unset mtarg - if [ ! -z "$objpath" ]; then - srcname=`basename $1` - objname="${srcname%.*}" - mtarg="-MT ${objpath}/${objname}${suffix}" - fi - - $cc -M $mtarg $cflags $fullpath || \ - ( echo "# ERROR: $cc -M $cflags $fullpath FAILED"; exit 4; ) -} - -unset cc -unset cflags -unset files -unset args -unset altpath -unset objpath -suffix=.o -winpaths=n -unset topdir - -# Accumulate CFLAGS up to "--" -progname=$0 -while [ ! -z "$1" ]; do - case $1 in - -- ) - cc=$cflags - cflags=$args - args= - ;; - --dep-debug ) - if [ -z "$args" ]; then - set -x - else - args="$args $1" - fi - ;; - --dep-path ) - if [ -z "$args" ]; then - shift - altpath="$altpath $1" - else - args="$args $1" - fi - ;; - --obj-path ) - shift - objpath="$1" - ;; - --obj-suffix ) - shift - suffix="$1" - ;; - --winpaths ) - if [ -z "$args" ]; then - shift - winpaths=y - topdir=$1 - else - args="$args $1" - fi - ;; - --help ) - show_usage - ;; - *) - args="$args $1" - ;; - esac - shift -done -files=$args - -if [ -z "$cc" ]; then - echo "ERROR: No compiler specified" - show_usage - exit 1 -fi - -if [ -z "$files" ]; then - # Don't report an error -- this happens normally in some configurations - echo "# No files specified for dependency generataion" - exit 0 -fi - -# Check if this compiler generates Cygwin/Linux paths or Windows paths - -if [ "X${winpaths}" = "Xy" ]; then - # We will have to parse and modify each dependency (yech) - # Make sure a valid TOPDIR argument was provided - - if [ -z "$topdir" -o ! -d $topdir ]; then - echo " not specified or does not exist: $topdir" - show_usage - exit 1 - fi - - # Get the top dir expressed like the Windows GCC would use it, except - # with forward slashs - - wtopdir=`cygpath -w ${topdir} | sed -e "s,\\\\\\,/,g"` - - # Then get the dependency and perform conversions on it to make it - # palatable to the Cygwin make. This is probably not sufficiently - # general to work on all platforms (like if your disk is not C:). - - for file in $files ; do - dodep $file | sed -e "s,\\\,/,g" -e "s,${wtopdir},${topdir},g" \ - -e "s,/ ,\\\ ,g" -e "s,c:/,/cygdrive/c/,g" \ - -e "s,/$,\\\,g" - done -else - # For normal Cygwin/Linux GCC, the dependency paths are in the - # correct form and can simply be echoed on stdout - - for file in $files ; do - dodep $file - done -fi - -- GitLab From 435b29fa7c5444814590abb1468a88a5d42bd224 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 16:39:30 -0600 Subject: [PATCH 518/858] Update submodules --- Documentation | 2 +- arch | 2 +- configs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index 8830f8f638..e3d982b2f1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 +Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 diff --git a/arch b/arch index 4570fe271a..95a83af6d1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4570fe271a034ae7aa23e579064f90c75594f985 +Subproject commit 95a83af6d1ee3d2ecd2cd6a3c3bb4a99c4c06d7a diff --git a/configs b/configs index 57c7e67c4d..7b507f0c3c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 +Subproject commit 7b507f0c3c812869cb4ec5981b740ac94444b49f -- GitLab From 4d02274d50d9ab8132de1d66537b2dd3d6f920b7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 16:41:18 -0600 Subject: [PATCH 519/858] Update submodules --- Documentation | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index e3d982b2f1..8830f8f638 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 +Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 diff --git a/configs b/configs index 7b507f0c3c..57c7e67c4d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7b507f0c3c812869cb4ec5981b740ac94444b49f +Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 -- GitLab From c5bcfc166d0504a919a9987526df4cf4587c2bbc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 17:27:56 -0600 Subject: [PATCH 520/858] tools/mkwindeps.sh. A script that coordinates the use of cnvwindeps.exe --- ChangeLog | 2 ++ Documentation | 2 +- Makefile.unix | 11 ++++++-- arch | 2 +- configs | 2 +- tools/Makefile.host | 4 +++ tools/mkwindeps.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 tools/mkwindeps.sh diff --git a/ChangeLog b/ChangeLog index dcb13526e1..c1f27a6d1f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11295,4 +11295,6 @@ * tools/cnvwindeps.c: Add a tool that will convert paths in dependencies generated by a Windows compiler so that they can be used with the Cygwin make (2016-01-09). + * tools/mkwindeps.sh: A script that coordinates us ov cnvwindeps.exe + (2016-01-09). diff --git a/Documentation b/Documentation index 1d164c4df5..e3d982b2f1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 1d164c4df5b6577c52f88d56ce270bd4f7556963 +Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 diff --git a/Makefile.unix b/Makefile.unix index 28d0df608d..2aca0beb09 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -269,7 +269,12 @@ include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT) # Targets used to create dependencies tools/mkdeps$(HOSTEXEEXT): - $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT) + $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT) + +tools/cnvwindeps$(HOSTEXEEXT): +ifeq ($(CONFIG_WINDOWS_CYGWIN),y) + $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" cnvwindeps$(HOSTEXEEXT) +endif # dirlinks, and helpers # @@ -460,12 +465,12 @@ download: $(BIN) # pass1dep: Create pass1 build dependencies # pass2dep: Create pass2 build dependencies -pass1dep: context tools/mkdeps$(HOSTEXEEXT) +pass1dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) $(Q) for dir in $(USERDEPDIRS) ; do \ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \ done -pass2dep: context tools/mkdeps$(HOSTEXEEXT) +pass2dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) $(Q) for dir in $(KERNDEPDIRS) ; do \ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend; \ done diff --git a/arch b/arch index 4570fe271a..95a83af6d1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4570fe271a034ae7aa23e579064f90c75594f985 +Subproject commit 95a83af6d1ee3d2ecd2cd6a3c3bb4a99c4c06d7a diff --git a/configs b/configs index da294ce5cc..7b507f0c3c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit da294ce5cc305030e4f9bb8bd238054f20317525 +Subproject commit 7b507f0c3c812869cb4ec5981b740ac94444b49f diff --git a/tools/Makefile.host b/tools/Makefile.host index 3cc0080261..08cf639016 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -165,8 +165,12 @@ endif # cnvwindeps - Convert dependences generated by a Windows native toolchain # for use in a Cygwin/POSIX build environment +ifeq ($(CONFIG_WINDOWS_CYGWIN),y) cnvwindeps$(HOSTEXEEXT): cnvwindeps.c $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cnvwindeps$(HOSTEXEEXT) cnvwindeps.c +else +cnvwindeps$(HOSTEXEEXT): +endif ifdef HOSTEXEEXT cnvwindeps: cnvwindeps$(HOSTEXEEXT) diff --git a/tools/mkwindeps.sh b/tools/mkwindeps.sh new file mode 100644 index 0000000000..ce50a32ae9 --- /dev/null +++ b/tools/mkwindeps.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# tools/mkwindeps.sh +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# set -x + +# Make sure that we know where we are + +TOOLDIR=$(dirname $0) + +if [ ! -x ${TOOLDIR}/mkwindeps.sh ]; then + echo "ERROR: tools/ directory not found" + exit 1 +fi + +# Make sure that executables are ready + +MKDEPS=${TOOLDIR}/mkdeps.exe +CNVWINDEPS=${TOOLDIR}/cnvwindeps.exe + +if [ ! -x ${MKDEPS} ]; then + echo "ERROR: tools/mkdeps.exe does not exist" + exit 1 +fi + +if [ ! -x ${CNVWINDEPS} ]; then + echo "ERROR: tools/cnvwindeps.exe does not exist" + exit 1 +fi + +# Run the mkdeps.exe program to generate a Windows dependency file + +TMPFILE=$(mktemp) +${MKDEPS} $* > ${TMPFILE} || { echo "mkdeps.exe failed"; exit 1; } + +# Then convert this to a POSIX dependency file (on stdout) + +${CNVWINDEPS} ${TMPFILE} +rm -f ${TMPFILE} -- GitLab From 5ec04daaa2580dd4ad6190a8365425620ad71873 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 19:52:24 -0600 Subject: [PATCH 521/858] Extending tools/mkdeps.c --- tools/Makefile.host | 8 +- tools/cnvwindeps.c | 1 - tools/mkdeps.c | 221 +++++++++++++++++++++++++++++++++++++------- tools/mkwindeps.sh | 8 +- 4 files changed, 200 insertions(+), 38 deletions(-) diff --git a/tools/Makefile.host b/tools/Makefile.host index 08cf639016..cc64a3d999 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -49,13 +49,17 @@ HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. -DCONFIG_WINDOWS_NATIVE else -# GCC is assumed in the POSIX environment. +# GCC is assumed in the POSIX environment (Linux or Cygwin). # strtok_r is used in some tools, but does not seem to be available in # the MinGW environment. HOSTCC ?= gcc -HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. -DHAVE_STRTOK_C +HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. +HOSTCFLAGS += -DHAVE_STRTOK_C=1 +ifeq ($(CONFIG_WINDOWS_CYGWIN),y) +HOSTCFLAGS += -DHAVE_CYGWIN=1 +endif endif # Targets diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index c390e6f778..81fab6953b 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -61,7 +61,6 @@ static unsigned long g_lineno; static char g_line[MAX_LINE]; static char g_dequoted[MAX_PATH]; static char g_posix[MAX_PATH]; -static const char g_cygpath[] = "/usr/bin/cygpath"; /**************************************************************************** * Private Functions diff --git a/tools/mkdeps.c b/tools/mkdeps.c index 91e4147171..cef60d0f1d 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -48,11 +48,17 @@ #include #include +#ifdef HAVE_CYGWIN +# include +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #define MAX_BUFFER (4096) +#define MAX_EXPAND (2048) +#define MAX_PATH (512) /* NAME_MAX is typically defined in limits.h */ @@ -101,15 +107,19 @@ static char *g_objpath = NULL; static char *g_suffix = ".o"; static int g_debug = 0; static bool g_winnative = false; + #ifdef HAVE_WINPATH static bool g_winpath = false; static char *g_topdir = NULL; -#define DELIM "\\" -#else -#define DELIM "/" #endif static char g_command[MAX_BUFFER]; +static char g_expand[MAX_EXPAND]; + +#ifdef HAVE_CYGWIN +static char g_dequoted[MAX_PATH]; +static char g_posixpath[MAX_PATH]; +#endif /**************************************************************************** * Private Functions @@ -413,12 +423,144 @@ static void parse_args(int argc, char **argv) #ifdef HAVE_WINPATH if (g_winnative && g_winpath) { - show_usage(argv[0], "ERROR: Both --winnative and --winpapth makes no sense", EXIT_FAILURE); + show_usage(argv[0], "ERROR: Both --winnative and --winpath makes no sense", EXIT_FAILURE); } #endif } -static void do_dependency(const char *file, char separator) +static const char *do_expand(const char *argument) +{ + if (g_winnative) + { + const char *src; + char *dest; + int len; + + src = argument; + dest = g_expand; + len = 0; + + while (*src && len < MAX_EXPAND) + { + if (*src == '\\') + { + *dest++ = '\\'; + if (++len >= MAX_EXPAND) + { + break; + } + } + + *dest++ = *src++; + len++; + } + + if (*src) + { + fprintf(stderr, "ERROR: Truncated during expansion string is too long [%lu/%u]\n", + (unsigned long)strlen(argument), MAX_EXPAND); + exit(EXIT_FAILURE); + } + + *dest = '\0'; + return g_expand; + } + else + { + return argument; + } +} + +#ifdef HAVE_CYGWIN +static bool dequote_path(const char *winpath) +{ + char *dest = g_dequoted; + const char *src = winpath; + int len = 0; + bool quoted = false; + + while (*src && len < MAX_PATH) + { + if (src[0] != '\\' || (src[1] != ' ' && src[1] != '(' && src[1] != ')')) + { + *dest++ = *src; + len++; + } + else + { + quoted = true; + } + + src++; + } + + if (*src || len >= MAX_PATH) + { + fprintf(stderr, "# ERROR: Path truncated\n"); + exit(EXIT_FAILURE); + } + + *dest = '\0'; + return quoted; +} +#endif + +static const char *convert_path(const char *path) +{ +#ifdef HAVE_CYGWIN + if (g_winnative) + { + const char *retptr; + ssize_t size; + ssize_t ret; + bool quoted; + + quoted = dequote_path(path); + if (quoted) + { + retptr = g_posixpath; + } + else + { + retptr = &g_posixpath[1]; + } + + size = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_RELATIVE, g_dequoted, + NULL, 0); + if (size > (MAX_PATH-3)) + { + fprintf(stderr, "# ERROR: POSIX path too long: %lu\n", + (unsigned long)size); + exit(EXIT_FAILURE); + } + + ret = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_RELATIVE, g_dequoted, + &g_posixpath[1], MAX_PATH-3); + if (ret < 0) + { + fprintf(stderr, "# ERROR: cygwin_conv_path '%s' failed: %s\n", + g_dequoted, strerror(errno)); + exit(EXIT_FAILURE); + } + + if (quoted) + { + size++; + g_posixpath[0] = '"'; + g_posixpath[size] = '"'; + } + + g_posixpath[size+1] = '\0'; + return retptr; + } + else +#endif + { + return path; + } +} + +static void do_dependency(const char *file) { static const char moption[] = " -M "; struct stat buf; @@ -426,12 +568,17 @@ static void do_dependency(const char *file, char separator) char *altpath; char *path; char *lasts; + char separator; int cmdlen; int pathlen; int filelen; int totallen; int ret; + /* Initialize the separator */ + + separator = g_winnative ? '\\' : '/'; + /* Copy the compiler into the command buffer */ cmdlen = strlen(g_cc); @@ -444,16 +591,6 @@ static void do_dependency(const char *file, char separator) strcpy(g_command, g_cc); - /* Copy " -M " */ - - cmdlen += strlen(moption); - if (cmdlen >= MAX_BUFFER) - { - fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n", - cmdlen, MAX_BUFFER, moption); - exit(EXIT_FAILURE); - } - /* Copy " -MT " */ if (g_objpath) @@ -462,6 +599,7 @@ static void do_dependency(const char *file, char separator) char *dupname; char *objname; char *dotptr; + const char *expanded; dupname = strdup(file); if (!dupname) @@ -477,10 +615,11 @@ static void do_dependency(const char *file, char separator) *dotptr = '\0'; } - snprintf(tmp, NAME_MAX+6, " -MT %s" DELIM "%s%s ", - g_objpath, objname, g_suffix); + snprintf(tmp, NAME_MAX+6, " -MT %s%c%s%s ", + g_objpath, separator, objname, g_suffix); + expanded = do_expand(tmp); - cmdlen += strlen(tmp); + cmdlen += strlen(expanded); if (cmdlen >= MAX_BUFFER) { fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n", @@ -488,16 +627,28 @@ static void do_dependency(const char *file, char separator) exit(EXIT_FAILURE); } - strcat(g_command, tmp); + strcat(g_command, expanded); free(dupname); } + /* Copy " -M " */ + + cmdlen += strlen(moption); + if (cmdlen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n", + cmdlen, MAX_BUFFER, moption); + exit(EXIT_FAILURE); + } + strcat(g_command, moption); /* Copy the CFLAGS into the command buffer */ if (g_cflags) { + const char *expanded; + cmdlen += strlen(g_cflags); if (cmdlen >= MAX_BUFFER) { @@ -506,7 +657,8 @@ static void do_dependency(const char *file, char separator) exit(EXIT_FAILURE); } - strcat(g_command, g_cflags); + expanded = do_expand(g_cflags); + strcat(g_command, expanded); } /* Add a space */ @@ -534,9 +686,14 @@ static void do_dependency(const char *file, char separator) while ((path = strtok_r(altpath, " ", &lasts)) != NULL) { + const char *expanded; + const char *converted; + /* Create a full path to the file */ - pathlen = strlen(path); + expanded = do_expand(path); + pathlen = strlen(expanded); + totallen = cmdlen + pathlen; if (totallen >= MAX_BUFFER) { @@ -545,7 +702,7 @@ static void do_dependency(const char *file, char separator) exit(EXIT_FAILURE); } - strcpy(&g_command[cmdlen], path); + strcpy(&g_command[cmdlen], expanded); if (g_command[totallen] != '\0') { @@ -553,7 +710,7 @@ static void do_dependency(const char *file, char separator) exit(EXIT_FAILURE); } - if (g_command[totallen-1] != separator) + if (g_command[totallen-1] != separator) { g_command[totallen] = separator; g_command[totallen+1] = '\0'; @@ -561,16 +718,17 @@ static void do_dependency(const char *file, char separator) totallen++; } - filelen = strlen(file); - totallen += filelen; - if (totallen >= MAX_BUFFER) - { + expanded = do_expand(file); + filelen = strlen(expanded); + totallen += filelen; + if (totallen >= MAX_BUFFER) + { fprintf(stderr, "ERROR: Path+file is too long [%d/%d]\n", totallen, MAX_BUFFER); exit(EXIT_FAILURE); - } + } - strcat(g_command, file); + strcat(g_command, expanded); /* Check that a file actually exists at this path */ @@ -580,7 +738,8 @@ static void do_dependency(const char *file, char separator) path, file, &g_command[cmdlen]); } - ret = stat(&g_command[cmdlen], &buf); + converted = convert_path(&g_command[cmdlen]); + ret = stat(converted, &buf); if (ret < 0) { altpath = NULL; @@ -822,7 +981,7 @@ int main(int argc, char **argv, char **envp) else #endif { - do_dependency(file, g_winnative ? '\\' : '/'); + do_dependency(file); } files = NULL; diff --git a/tools/mkwindeps.sh b/tools/mkwindeps.sh index ce50a32ae9..d5d002f4e1 100644 --- a/tools/mkwindeps.sh +++ b/tools/mkwindeps.sh @@ -39,7 +39,7 @@ TOOLDIR=$(dirname $0) if [ ! -x ${TOOLDIR}/mkwindeps.sh ]; then - echo "ERROR: tools/ directory not found" + echo "# ERROR: tools/ directory not found" exit 1 fi @@ -49,19 +49,19 @@ MKDEPS=${TOOLDIR}/mkdeps.exe CNVWINDEPS=${TOOLDIR}/cnvwindeps.exe if [ ! -x ${MKDEPS} ]; then - echo "ERROR: tools/mkdeps.exe does not exist" + echo "# ERROR: tools/mkdeps.exe does not exist" exit 1 fi if [ ! -x ${CNVWINDEPS} ]; then - echo "ERROR: tools/cnvwindeps.exe does not exist" + echo "# ERROR: tools/cnvwindeps.exe does not exist" exit 1 fi # Run the mkdeps.exe program to generate a Windows dependency file TMPFILE=$(mktemp) -${MKDEPS} $* > ${TMPFILE} || { echo "mkdeps.exe failed"; exit 1; } +${MKDEPS} --winnative $* > ${TMPFILE} || { echo "# ERROR: mkdeps.exe failed"; exit 1; } # Then convert this to a POSIX dependency file (on stdout) -- GitLab From 51ee01255b65b514adbb58f8f9734120cdece06b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 19:56:47 -0600 Subject: [PATCH 522/858] =?UTF-8?q?ENC28J60:=20Missing=20semicolon=20cause?= =?UTF-8?q?s=20error=20in=20some=20configurations.=20=20Noted=20by=20Macie?= =?UTF-8?q?j=20W=C3=B3jcik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation | 2 +- configs | 2 +- drivers/net/enc28j60.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index 8830f8f638..e3d982b2f1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 +Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 diff --git a/configs b/configs index 57c7e67c4d..7b507f0c3c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 +Subproject commit 7b507f0c3c812869cb4ec5981b740ac94444b49f diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 7df9597a82..4a940a71ee 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -381,7 +381,7 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_ENC28J60_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY) + SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY); } #endif -- GitLab From c0cb4c8b038bf770838874e6f199d391e4a0548f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Jan 2016 20:06:40 -0600 Subject: [PATCH 523/858] Update submodules --- Documentation | 2 +- arch | 2 +- configs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index e3d982b2f1..8830f8f638 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 +Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 diff --git a/arch b/arch index 95a83af6d1..1a314699cf 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 95a83af6d1ee3d2ecd2cd6a3c3bb4a99c4c06d7a +Subproject commit 1a314699cf004cd85dae0038b566bab3343d294f diff --git a/configs b/configs index 7b507f0c3c..57c7e67c4d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7b507f0c3c812869cb4ec5981b740ac94444b49f +Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 -- GitLab From e5c8290d5cce80c074b10a911bc2f47f69980623 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 09:25:32 -0600 Subject: [PATCH 524/858] Should use --winpath option, not the --winnative option --- tools/Makefile.host | 2 +- tools/mkdeps.c | 204 +++----------------------------------------- tools/mkwindeps.sh | 4 +- 3 files changed, 17 insertions(+), 193 deletions(-) diff --git a/tools/Makefile.host b/tools/Makefile.host index cc64a3d999..3dd60a47fe 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -58,7 +58,7 @@ HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. HOSTCFLAGS += -DHAVE_STRTOK_C=1 ifeq ($(CONFIG_WINDOWS_CYGWIN),y) -HOSTCFLAGS += -DHAVE_CYGWIN=1 +HOSTCFLAGS += -DHOST_CYGWIN=1 endif endif diff --git a/tools/mkdeps.c b/tools/mkdeps.c index cef60d0f1d..84d37d1727 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -48,7 +48,7 @@ #include #include -#ifdef HAVE_CYGWIN +#ifdef HOST_CYGWIN # include #endif @@ -107,16 +107,13 @@ static char *g_objpath = NULL; static char *g_suffix = ".o"; static int g_debug = 0; static bool g_winnative = false; - -#ifdef HAVE_WINPATH +#ifdef HOST_CYGWIN static bool g_winpath = false; -static char *g_topdir = NULL; #endif static char g_command[MAX_BUFFER]; static char g_expand[MAX_EXPAND]; - -#ifdef HAVE_CYGWIN +#ifdef HOST_CYGWIN static char g_dequoted[MAX_PATH]; static char g_posixpath[MAX_PATH]; #endif @@ -267,7 +264,7 @@ static void show_usage(const char *progname, const char *msg, int exitcode) fprintf(stderr, " --winnative\n"); fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n"); fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n"); -#ifdef HAVE_WINPATH +#ifdef HOST_CYGWIN fprintf(stderr, " --winpaths \n"); fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n"); fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n"); @@ -339,22 +336,10 @@ static void parse_args(int argc, char **argv) { g_winnative = true; } -#ifdef HAVE_WINPATH +#ifdef HOST_CYGWIN else if (strcmp(argv[argidx], "--winpath") == 0) { g_winpath = true; - if (g_topdir) - { - free(g_topdir); - } - - argidx++; - if (argidx >= argc) - { - show_usage(argv[0], "ERROR: Missing argument to --winpath", EXIT_FAILURE); - } - - g_topdir = strdup(argv[argidx]); } #endif else if (strcmp(argv[argidx], "--help") == 0) @@ -395,12 +380,8 @@ static void parse_args(int argc, char **argv) fprintf(stderr, " OBJDIR : (None)\n"); } -#ifdef HAVE_WINPATH +#ifdef HOST_CYGWIN fprintf(stderr, " Windows Paths : [%s]\n", g_winpath ? "TRUE" : "FALSE"); - if (g_winpath) - { - fprintf(stderr, " TOPDIR : [%s]\n", g_topdir); - } #endif fprintf(stderr, " Windows Native : [%s]\n", g_winnative ? "TRUE" : "FALSE"); } @@ -420,7 +401,7 @@ static void parse_args(int argc, char **argv) exit(EXIT_SUCCESS); } -#ifdef HAVE_WINPATH +#ifdef HOST_CYGWIN if (g_winnative && g_winpath) { show_usage(argv[0], "ERROR: Both --winnative and --winpath makes no sense", EXIT_FAILURE); @@ -430,7 +411,7 @@ static void parse_args(int argc, char **argv) static const char *do_expand(const char *argument) { - if (g_winnative) + if (g_winpath) { const char *src; char *dest; @@ -471,7 +452,7 @@ static const char *do_expand(const char *argument) } } -#ifdef HAVE_CYGWIN +#ifdef HOST_CYGWIN static bool dequote_path(const char *winpath) { char *dest = g_dequoted; @@ -507,8 +488,8 @@ static bool dequote_path(const char *winpath) static const char *convert_path(const char *path) { -#ifdef HAVE_CYGWIN - if (g_winnative) +#ifdef HOST_CYGWIN + if (g_winpath) { const char *retptr; ssize_t size; @@ -577,7 +558,7 @@ static void do_dependency(const char *file) /* Initialize the separator */ - separator = g_winnative ? '\\' : '/'; + separator = (g_winnative || g_winpath) ? '\\' : '/'; /* Copy the compiler into the command buffer */ @@ -798,155 +779,6 @@ static void do_dependency(const char *file) exit(EXIT_FAILURE); } -/* Convert a Cygwin path to a Windows path */ - -#ifdef HAVE_WINPATH -static char *cywin2windows(const char *str, const char *append, enum slashmode_e mode) -{ - static const char cygdrive[] = "/cydrive"; - char *dest; - char *newpath; - char *allocpath = NULL; - int srclen = strlen(str); - int alloclen = 0; - int drive = 0; - int lastchar; - - /* Skip any leading whitespace */ - - while (isspace(*str)) str++; - - /* Were we asked to append something? */ - - if (append) - { - alloclen = sizeof(str) + sizeof(append) + 1; - allocpath = (char *)malloc(alloclen); - if (!allocpath) - { - fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen); - exit(EXIT_FAILURE); - } - - snprintf(allocpath, alloclen, "%s/%s", str, append); - str = allocpath; - } - - /* Looking for path of the form /cygdrive/c/bla/bla/bla */ - - if (strcasecmp(str, cygdrive) == 0) - { - int cygsize = sizeof(cygdrive); - if (str[cygsize] == '/') - { - cygsize++; - srclen -= cygsize; - str += cygsize; - - if (srclen <= 0) - { - fprintf(stderr, "ERROR: Unhandled path: \"%s\"\n", str); - exit(EXIT_FAILURE); - } - - drive = toupper(*str); - if (drive < 'A' || drive > 'Z') - { - fprintf(stderr, "ERROR: Drive character: \"%s\"\n", str); - exit(EXIT_FAILURE); - } - - srclen--; - str++; - alloclen = 2; - } - } - - /* Determine the size of the new path */ - - alloclen += sizeof(str) + 1; - if (mode == MODE_DBLBACK) - { - const char *tmpptr; - for (tmpptr = str; *tmpptr; tmpptr++) - { - if (*tmpptr == '/') alloclen++; - } - } - - /* Allocate memory for the new path */ - - newpath = (char *)malloc(alloclen); - if (!newpath) - { - fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen); - exit(EXIT_FAILURE); - } - - dest = newpath; - - /* Copy the drive character */ - - if (drive) - { - *dest++ = drive; - *dest++ = ':'; - } - - /* Copy each character from the source, making modifications for foward - * slashes as required. - */ - - lastchar = '\0'; - for (; *str; str++) - { - if (mode != MODE_FSLASH && *str == '/') - { - if (lastchar != '/') - { - *dest++ = '\\'; - if (mode == MODE_DBLBACK) - { - *dest++ = '\\'; - } - } - } - else - { - *dest++ = *str; - } - - lastchar = *str; - } - - *dest++ = '\0'; - if (allocpath) - { - free(allocpath); - } - return dest; -} -#endif - -#ifdef HAVE_WINPATH -static void do_winpath(char *file) -{ - /* The file is in POSIX format. CC expects Windows format to generate the - * dependencies, but GNU make expect the resulting dependencies to be back - * in POSIX format. What a mess! - */ - - char *path = cywin2windows(g_topdir, file, MODE_FSLASH); - - /* Then get the dependency and perform conversions on it to make it - * palatable to the Cygwin make. - */ -#warning "Missing logic" - - free(path); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -973,17 +805,7 @@ int main(int argc, char **argv, char **envp) * being using in a POSIX/Cygwin environment. */ -#ifdef HAVE_WINPATH - if (g_winpath) - { - do_winpath(file); - } - else -#endif - { - do_dependency(file); - } - + do_dependency(file); files = NULL; } diff --git a/tools/mkwindeps.sh b/tools/mkwindeps.sh index d5d002f4e1..b8851efe30 100644 --- a/tools/mkwindeps.sh +++ b/tools/mkwindeps.sh @@ -32,7 +32,9 @@ # POSSIBILITY OF SUCH DAMAGE. # +# Uncomment to enable debug options # set -x +# DEBUG=--dep-debug # Make sure that we know where we are @@ -61,7 +63,7 @@ fi # Run the mkdeps.exe program to generate a Windows dependency file TMPFILE=$(mktemp) -${MKDEPS} --winnative $* > ${TMPFILE} || { echo "# ERROR: mkdeps.exe failed"; exit 1; } +${MKDEPS} ${DEBUG} --winpath $* > ${TMPFILE} || { echo "# ERROR: mkdeps.exe failed"; exit 1; } # Then convert this to a POSIX dependency file (on stdout) -- GitLab From 76f4c2bf20ed57923f22e12c7d01c02a32d4c761 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 10:16:21 -0600 Subject: [PATCH 525/858] tools/mkdeps.c: Correct logic that exands paths --- tools/mkdeps.c | 99 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/tools/mkdeps.c b/tools/mkdeps.c index 84d37d1727..f98a38172f 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -113,6 +113,7 @@ static bool g_winpath = false; static char g_command[MAX_BUFFER]; static char g_expand[MAX_EXPAND]; +static char g_path[MAX_PATH]; #ifdef HOST_CYGWIN static char g_dequoted[MAX_PATH]; static char g_posixpath[MAX_PATH]; @@ -187,6 +188,7 @@ static char *MY_strtok_r(char *str, const char *delim, char **saveptr) { *saveptr = pend; } + return pbegin; } @@ -425,15 +427,46 @@ static const char *do_expand(const char *argument) { if (*src == '\\') { - *dest++ = '\\'; + /* Copy backslash */ + + *dest++ = *src++; if (++len >= MAX_EXPAND) { break; } - } - *dest++ = *src++; - len++; + /* Already expanded? */ + + if (*src == '\\') + { + /* Yes... just copy all consecutive backslashes */ + + do + { + *dest++ = *src++; + if (++len >= MAX_EXPAND) + { + break; + } + } + while (*src == '\\'); + } + else + { + /* No.. expeand */ + + *dest++ = '\\'; + if (++len >= MAX_EXPAND) + { + break; + } + } + } + else + { + *dest++ = *src++; + len++; + } } if (*src) @@ -672,54 +705,49 @@ static void do_dependency(const char *file) /* Create a full path to the file */ - expanded = do_expand(path); - pathlen = strlen(expanded); - - totallen = cmdlen + pathlen; - if (totallen >= MAX_BUFFER) + pathlen = strlen(path); + if (pathlen >= MAX_PATH) { fprintf(stderr, "ERROR: Path is too long [%d/%d]: %s\n", - totallen, MAX_BUFFER, path); + pathlen, MAX_PATH, path); exit(EXIT_FAILURE); } - strcpy(&g_command[cmdlen], expanded); + strcpy(g_path, path); - if (g_command[totallen] != '\0') + if (g_path[pathlen] != '\0') { fprintf(stderr, "ERROR: Missing NUL terminator\n"); exit(EXIT_FAILURE); } - if (g_command[totallen-1] != separator) + if (g_path[pathlen-1] != separator) { - g_command[totallen] = separator; - g_command[totallen+1] = '\0'; + g_path[pathlen] = separator; + g_path[pathlen+1] = '\0'; pathlen++; - totallen++; } - expanded = do_expand(file); - filelen = strlen(expanded); - totallen += filelen; - if (totallen >= MAX_BUFFER) + filelen = strlen(file); + pathlen += filelen; + if (pathlen >= MAX_PATH) { fprintf(stderr, "ERROR: Path+file is too long [%d/%d]\n", - totallen, MAX_BUFFER); + pathlen, MAX_PATH); exit(EXIT_FAILURE); } - strcat(g_command, expanded); + strcat(g_path, file); /* Check that a file actually exists at this path */ if (g_debug) { fprintf(stderr, "Trying path=%s file=%s fullpath=%s\n", - path, file, &g_command[cmdlen]); + path, file, g_path); } - converted = convert_path(&g_command[cmdlen]); + converted = convert_path(g_path); ret = stat(converted, &buf); if (ret < 0) { @@ -730,13 +758,28 @@ static void do_dependency(const char *file) if (!S_ISREG(buf.st_mode)) { fprintf(stderr, "ERROR: File %s exists but is not a regular file\n", - &g_command[cmdlen]); + g_path); exit(EXIT_FAILURE); } - /* Okay.. we have. Create the dependency. One a failure to start the - * compiler, system() will return -1; Otherwise, the returned value - * from the compiler is in WEXITSTATUS(ret). + /* Append the expanded path to the command */ + + expanded = do_expand(g_path); + pathlen = strlen(expanded); + totallen = cmdlen + pathlen; + + if (totallen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Path string is too long [%d/%d]: %s\n", + totallen, MAX_BUFFER, g_path); + exit(EXIT_FAILURE); + } + + strcat(g_command, expanded); + + /* Okay.. we have everything. Create the dependency. One a failure + * to start the compiler, system() will return -1; Otherwise, the + * returned value from the compiler is in WEXITSTATUS(ret). */ if (g_debug) -- GitLab From 65826c7f218347dcf326e44847514dec43009c0b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 11:15:30 -0600 Subject: [PATCH 526/858] tools/mkdeps.c: Fix error in calculation of the length of the command --- tools/mkdeps.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/mkdeps.c b/tools/mkdeps.c index f98a38172f..378deab28f 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -663,7 +663,9 @@ static void do_dependency(const char *file) { const char *expanded; - cmdlen += strlen(g_cflags); + expanded = do_expand(g_cflags); + cmdlen += strlen(expanded); + if (cmdlen >= MAX_BUFFER) { fprintf(stderr, "ERROR: CFLAG string is too long [%d/%d]: %s\n", @@ -671,7 +673,6 @@ static void do_dependency(const char *file) exit(EXIT_FAILURE); } - expanded = do_expand(g_cflags); strcat(g_command, expanded); } -- GitLab From a6da474a6990e6e3eb57f994cde1591c5c8453e3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 13:02:51 -0600 Subject: [PATCH 527/858] Update ChangeLog; fix some tools/mkdeps.c compile issue in non-Cygwin environemnts --- ChangeLog | 3 +++ tools/mkdeps.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 141409e93b..d507b51894 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11300,3 +11300,6 @@ * tools/mkdeps.c: Deleted mkdeps.sh and mkdeps.bat. The mkdeps executable generated from mkdeps.c is now that the only supported way to make dependencies (2016-01-09). + * tools/mkdeps.c: Extended/fixed support for --winpath option. + Dependencies now work under Cygwin with a native Windows toolchain + (2016-01-10). diff --git a/tools/mkdeps.c b/tools/mkdeps.c index 378deab28f..fd4c8dc07d 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -112,9 +112,9 @@ static bool g_winpath = false; #endif static char g_command[MAX_BUFFER]; -static char g_expand[MAX_EXPAND]; static char g_path[MAX_PATH]; #ifdef HOST_CYGWIN +static char g_expand[MAX_EXPAND]; static char g_dequoted[MAX_PATH]; static char g_posixpath[MAX_PATH]; #endif @@ -413,6 +413,7 @@ static void parse_args(int argc, char **argv) static const char *do_expand(const char *argument) { +#ifdef HOST_CYGWIN if (g_winpath) { const char *src; @@ -480,6 +481,7 @@ static const char *do_expand(const char *argument) return g_expand; } else +#endif { return argument; } @@ -591,7 +593,11 @@ static void do_dependency(const char *file) /* Initialize the separator */ +#ifdef HOST_CYGWIN separator = (g_winnative || g_winpath) ? '\\' : '/'; +#else + separator = g_winnative ? '\\' : '/'; +#endif /* Copy the compiler into the command buffer */ -- GitLab From 61e0eb8006156339a1f2ed253687a8e8e5b5dc15 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 13:09:10 -0600 Subject: [PATCH 528/858] Use name, not CONFIG_ settings, to determine host OS; Fix errors in help text. --- tools/Makefile.host | 4 +++- tools/mkdeps.c | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/Makefile.host b/tools/Makefile.host index 3dd60a47fe..9bd3c2ef3e 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -57,8 +57,10 @@ HOSTCC ?= gcc HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. HOSTCFLAGS += -DHAVE_STRTOK_C=1 -ifeq ($(CONFIG_WINDOWS_CYGWIN),y) +HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"} +ifeq ($(HOSTOS),Cygwin) HOSTCFLAGS += -DHOST_CYGWIN=1 +HOSTEXEEXT ?= .exe endif endif diff --git a/tools/mkdeps.c b/tools/mkdeps.c index fd4c8dc07d..7c42c568e3 100644 --- a/tools/mkdeps.c +++ b/tools/mkdeps.c @@ -267,11 +267,10 @@ static void show_usage(const char *progname, const char *msg, int exitcode) fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n"); fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n"); #ifdef HOST_CYGWIN - fprintf(stderr, " --winpaths \n"); + fprintf(stderr, " --winpaths\n"); fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n"); fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n"); - fprintf(stderr, " (e.g., C:\\blablah\\blabla). This switch instructs the script to use 'cygpath' to convert\n"); - fprintf(stderr, " the Windows paths to Cygwin POSIXE paths.\n"); + fprintf(stderr, " (e.g., C:\\blablah\\blabla).\n"); #endif fprintf(stderr, " --help\n"); fprintf(stderr, " Shows this message and exits\n"); -- GitLab From 586b31abc523ffa07368402cda36aa01aab1ea3a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Jan 2016 13:38:41 -0600 Subject: [PATCH 529/858] tools/cnvwindeps.c: Need to build this tool even on non-Cygwin platforms (either that or rethink the dependencies). --- Documentation | 2 +- Makefile.unix | 2 -- configs | 2 +- tools/Makefile.host | 7 ++----- tools/cnvwindeps.c | 13 +++++++++++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Documentation b/Documentation index 8830f8f638..e3d982b2f1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8830f8f6387b287a480b849e02569b881e5cd413 +Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 diff --git a/Makefile.unix b/Makefile.unix index 2aca0beb09..b1147390ae 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -272,9 +272,7 @@ tools/mkdeps$(HOSTEXEEXT): $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT): -ifeq ($(CONFIG_WINDOWS_CYGWIN),y) $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" cnvwindeps$(HOSTEXEEXT) -endif # dirlinks, and helpers # diff --git a/configs b/configs index 57c7e67c4d..097e95b685 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 57c7e67c4d5374ed87a94091deee8ae65eccde64 +Subproject commit 097e95b68591dbbb53cba593a041e830f051c758 diff --git a/tools/Makefile.host b/tools/Makefile.host index 9bd3c2ef3e..fa165f5e08 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -40,6 +40,8 @@ include ${TOPDIR}/tools/Config.mk # Define HOSTCC on the make command line if it differs from these defaults # Define HOSTCFLAGS with -g on the make command line to build debug versions +HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"} + ifeq ($(CONFIG_WINDOWS_NATIVE),y) # In the Windows native environment, the MinGW GCC compiler is assumed @@ -57,7 +59,6 @@ HOSTCC ?= gcc HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -I. HOSTCFLAGS += -DHAVE_STRTOK_C=1 -HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"} ifeq ($(HOSTOS),Cygwin) HOSTCFLAGS += -DHOST_CYGWIN=1 HOSTEXEEXT ?= .exe @@ -171,12 +172,8 @@ endif # cnvwindeps - Convert dependences generated by a Windows native toolchain # for use in a Cygwin/POSIX build environment -ifeq ($(CONFIG_WINDOWS_CYGWIN),y) cnvwindeps$(HOSTEXEEXT): cnvwindeps.c $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cnvwindeps$(HOSTEXEEXT) cnvwindeps.c -else -cnvwindeps$(HOSTEXEEXT): -endif ifdef HOSTEXEEXT cnvwindeps: cnvwindeps$(HOSTEXEEXT) diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index 81fab6953b..7c13b314d4 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -44,6 +44,8 @@ #include #include +#ifdef HOST_CYGWIN + #include /**************************************************************************** @@ -263,3 +265,14 @@ int main(int argc, char **argv, char **envp) fclose(stream); return 0; } + +#else /* HOST_CYGWIN */ + +int main(int argc, char **argv, char **envp) +{ + fprintf(stderr, "ERROR: This tool is only available under Cywgin\n"); + return EXIT_FAILURE; +} + +#endif /* HOST_CYGWIN */ + -- GitLab From a0c4c071edd80b2808ea8eac5ca439f4de9c7456 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 11 Jan 2016 08:01:42 -0600 Subject: [PATCH 530/858] tools/cnvwindeps.c: Omit dependency paths that include spaces --- TODO | 14 ++---------- arch | 2 +- configs | 2 +- tools/cnvwindeps.c | 55 +++++++++++++++++++++++++++++++--------------- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/TODO b/TODO index 84ee69a066..2a592d41b2 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 3, 2016) +NuttX TODO List (Last updated January 11, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -24,7 +24,7 @@ nuttx/ (11) File system/Generic drivers (fs/, drivers/) (8) Graphics subsystem (graphics/) (1) Pascal add-on (pcode/) - (2) Build system / Toolchains + (1) Build system / Toolchains (3) Linux/Cywgin simulation (arch/sim) (5) ARM (arch/arm/) @@ -1586,16 +1586,6 @@ o Pascal Add-On (pcode/) o Build system ^^^^^^^^^^^^ - Title: WINDOWS DEPENDENCY GENERATION - Description: Dependency generation is currently disabled when a Windows native - toolchain is used in a POSIX-like environment (like Cygwin). The - issue is that the Windows tool generates dependencies use Windows - path formatting and this fails with the dependency file (Make.dep) - is include). Perhaps the only issue is that all of the Windows - dependencies needed to be quoted in the Make.dep files. - Status: Open - Priority: Low -- unless some dependency-related build issues is discovered. - Title: MAKE EXPORT LIMITATIONS Description: The top-level Makefile 'export' target that will bundle up all of the NuttX libraries, header files, and the startup object into an export-able diff --git a/arch b/arch index 1a314699cf..ad4ca80846 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1a314699cf004cd85dae0038b566bab3343d294f +Subproject commit ad4ca8084676b719edc4b16ad24f37d2b1aec7b1 diff --git a/configs b/configs index 097e95b685..5eb7ce1631 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 097e95b68591dbbb53cba593a041e830f051c758 +Subproject commit 5eb7ce16316971813ced45e4869167ec55a72b45 diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index 7c13b314d4..df4fe7b586 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -99,6 +99,15 @@ static char *find_spaces(char *ptr) return ptr; } +static bool scour_path(const char *path) +{ + /* KLUDGE: GNU make cannot handle dependencies with spaces in them. + * There may be addition characters that cause problems too. + */ + + return strchr(path, ' ') != NULL; +} + static bool dequote_path(const char *winpath) { char *dest = g_dequoted; @@ -175,6 +184,7 @@ int main(int argc, char **argv, char **envp) FILE *stream; bool begin; bool quoted; + bool scouring; if (argc != 2) { @@ -189,7 +199,8 @@ int main(int argc, char **argv, char **envp) exit(EXIT_FAILURE); } - begin = true; + begin = true; + scouring = false; g_lineno = 0; while (fgets(g_line, MAX_LINE, stream) != NULL) @@ -214,15 +225,19 @@ int main(int argc, char **argv, char **envp) *next++ = '\0'; } - quoted = convert_path(path); - if (quoted) + scouring = scour_path(path); + if (!scouring) { - printf("\"%s\":", g_posix); - } - else - { - printf("%s:", g_posix); - } + quoted = convert_path(path); + if (quoted) + { + printf("\"%s\":", g_posix); + } + else + { + printf("%s:", g_posix); + } + } begin = false; } @@ -238,7 +253,8 @@ int main(int argc, char **argv, char **envp) else if (strcmp(path, "") == 0) { printf("\n\n"); - begin = true; + begin = true; + scouring = false; break; } else @@ -248,15 +264,18 @@ int main(int argc, char **argv, char **envp) *next++ = '\0'; } - quoted = convert_path(path); - if (quoted) + if (!scouring && !scour_path(path)) { - printf(" \\\n\t\"%s\"", g_posix); - } - else - { - printf(" \\\n\t%s", g_posix); - } + quoted = convert_path(path); + if (quoted) + { + printf(" \\\n\t\"%s\"", g_posix); + } + else + { + printf(" \\\n\t%s", g_posix); + } + } } } } -- GitLab From 42bcda4933f58563df4130ca5a2c4a70c48feb95 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 11 Jan 2016 08:10:08 -0600 Subject: [PATCH 531/858] Trivial to typo in error message text --- tools/cnvwindeps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index df4fe7b586..a6e75e4666 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -289,7 +289,7 @@ int main(int argc, char **argv, char **envp) int main(int argc, char **argv, char **envp) { - fprintf(stderr, "ERROR: This tool is only available under Cywgin\n"); + fprintf(stderr, "ERROR: This tool is only available under Cygwin\n"); return EXIT_FAILURE; } -- GitLab From 53226b608e1d4e38eacad3a59e109e6bcc86cacd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 11 Jan 2016 17:14:34 -0600 Subject: [PATCH 532/858] Trivial correction of alighment --- tools/cnvwindeps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index a6e75e4666..516f441b51 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -275,7 +275,7 @@ int main(int argc, char **argv, char **envp) { printf(" \\\n\t%s", g_posix); } - } + } } } } -- GitLab From f87358faf93594e76d871a996494f273bc78fc28 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 12 Jan 2016 07:05:50 -0600 Subject: [PATCH 533/858] correct some conditional compilation; update some comments --- net/procfs/netdev_statistics.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 61bc0f3573..16cfb440d9 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -247,7 +247,12 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) len += snprintf(&netfile->line[len], NET_LINELEN - len, "Mask:%s\n", inet_ntoa(addr)); -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) +#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) + /* Show the IPv4 DNS address */ + /* REVISIT: DNS client is global, not per device, and resides in the + * application space and is not generally accessible from kernel space. + */ + dns_getaddr(&addr); len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tDNSaddr:%s\n", inet_ntoa(addr)); @@ -275,7 +280,8 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); } -#if defined(CONFIG_NSH_DHCPCv6) || defined(CONFIG_NSH_DNS) +#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) + /* Show the IPv6 DNS address */ # warning Missing logic #endif #endif -- GitLab From 8ee75a96fee9c77426accc538aff14c45d4856e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 07:44:44 -0600 Subject: [PATCH 534/858] Update TODO list and Kconfig help --- TODO | 24 +++++++++++++++++++++++- sched/Kconfig | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 2a592d41b2..c011a56051 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,7 @@ nuttx/ (8) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) - (11) Network (net/, drivers/net) + (13) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (1) Other drivers (drivers/) (11) Libraries (libc/, libm/) @@ -1008,6 +1008,28 @@ o Network (net/, drivers/net) Priority: Low. I don't know of any issues now, but I am sure that someone will encounter this in the future. + Title: GLOBAL DNS ADDRESS + Description: Currently there is a single, global DNS server address. I am + thinking that there should be one DNS server address per + network device. This would mean: + - Moving the global DNS server address into the network + device structure + - Add netwok IOCTLs to set and get the DNS address + - Use these address in libc/netdb and apps/netutils/netlib. + - The netdb/netlib interface would need to have the device + name as a parameter and would need to call the IOCTL to + get/set the DNS server address associated with the device. + Needs a more investigation. + Status: Open + Priority: Low. I doubt that there are any multiple NIC, multiple DNS + server configurations + + Title: MISSING netdb INTERFACES + Description: There is no implementation for many netdb interfaces such as + getaddrinfo(), freeaddrinfo(), getnameinfo(), etc. + Status: Open + Priority: Low + o USB (drivers/usbdev, drivers/usbhost) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/sched/Kconfig b/sched/Kconfig index d1e72a30e8..5dd5ab72bf 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -500,6 +500,11 @@ config SCHED_CPULOAD The statistics collected in this could be used, for example in the PROCFS file system to provide CPU load measurements when read. + Note that in tickless mode of operation (SCHED_TICKLESS) there is + no system timer interrupt and CPU load measurements will not be + possible unless you provide an alternative clock to driver the + sampling and select SCHED_CPULOAD_EXTCLK. + if SCHED_CPULOAD config SCHED_CPULOAD_EXTCLK -- GitLab From 47c8eaab588bc356cdf60f3fa02dbe0ee73653c7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 11:08:05 -0600 Subject: [PATCH 535/858] Update TODO list --- TODO | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index c011a56051..773a90684e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 11, 2016) +NuttX TODO List (Last updated January 13, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -1009,17 +1009,31 @@ o Network (net/, drivers/net) someone will encounter this in the future. Title: GLOBAL DNS ADDRESS - Description: Currently there is a single, global DNS server address. I am - thinking that there should be one DNS server address per - network device. This would mean: - - Moving the global DNS server address into the network - device structure - - Add netwok IOCTLs to set and get the DNS address - - Use these address in libc/netdb and apps/netutils/netlib. - - The netdb/netlib interface would need to have the device - name as a parameter and would need to call the IOCTL to - get/set the DNS server address associated with the device. - Needs a more investigation. + Description: Currently there is a single, global DNS server address. This + address resides in user space (owned by libc/netdb) but is + accessed by network code in kernel space (net/procfs). This + work in a FLAT build, not not in other build modules. + + Things would be really weird in the kernel build: There + would be a separate name server address and a separate netdb + DNS client in each process. That can't be right. + + The Linux kernel has no knowledge at all about DNS addresses. + DNS addresses are retained in /etc/resolv.conf in records + ike: + + nameserver + + The nameserver is associated with the device only through + the routing of the IP address. And this is how there can + be multiple, global DNS addresses. + + Conclusion: The logic in net/procfs needs to be re-designed + so that it does not use the DNS address. The DNS address(es) + should to applied to the device status by logic in the + implementation of the NSH ifconfig command. This would be, + unfortunately, a significant re-design since the formatting + is currently performed in net/procfs. Status: Open Priority: Low. I doubt that there are any multiple NIC, multiple DNS server configurations -- GitLab From 530975a9b584466a6f947223fed1aa67e2c2abfe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 15:03:28 -0600 Subject: [PATCH 536/858] Fix typos in TODO --- TODO | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 773a90684e..1a5f890746 100644 --- a/TODO +++ b/TODO @@ -1012,17 +1012,17 @@ o Network (net/, drivers/net) Description: Currently there is a single, global DNS server address. This address resides in user space (owned by libc/netdb) but is accessed by network code in kernel space (net/procfs). This - work in a FLAT build, not not in other build modules. + works in a FLAT build, not not in other build modules. Things would be really weird in the kernel build: There would be a separate name server address and a separate netdb DNS client in each process. That can't be right. The Linux kernel has no knowledge at all about DNS addresses. - DNS addresses are retained in /etc/resolv.conf in records + DNS addresses are retained in /etc/resolv.conf in records ike: - nameserver + nameserver The nameserver is associated with the device only through the routing of the IP address. And this is how there can -- GitLab From 8e9f884eb72cfb3266bda5430087dc1d9b364cca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 15:06:44 -0600 Subject: [PATCH 537/858] Step 1 in /etc/resolv.conf support --- TODO | 32 +---------- include/nuttx/net/dns.h | 31 ++++------- libc/Kconfig | 18 ++++++- libc/net/lib_inetpton.c | 2 +- libc/netdb/Make.defs | 2 +- libc/netdb/lib_dns.h | 11 +++- libc/netdb/lib_dnsclient.c | 81 ++-------------------------- libc/netdb/lib_getdnsaddr.c | 98 ---------------------------------- net/procfs/netdev_statistics.c | 17 ------ 9 files changed, 46 insertions(+), 246 deletions(-) delete mode 100644 libc/netdb/lib_getdnsaddr.c diff --git a/TODO b/TODO index 1a5f890746..5438686674 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,7 @@ nuttx/ (8) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) - (13) Network (net/, drivers/net) + (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (1) Other drivers (drivers/) (11) Libraries (libc/, libm/) @@ -1008,36 +1008,6 @@ o Network (net/, drivers/net) Priority: Low. I don't know of any issues now, but I am sure that someone will encounter this in the future. - Title: GLOBAL DNS ADDRESS - Description: Currently there is a single, global DNS server address. This - address resides in user space (owned by libc/netdb) but is - accessed by network code in kernel space (net/procfs). This - works in a FLAT build, not not in other build modules. - - Things would be really weird in the kernel build: There - would be a separate name server address and a separate netdb - DNS client in each process. That can't be right. - - The Linux kernel has no knowledge at all about DNS addresses. - DNS addresses are retained in /etc/resolv.conf in records - ike: - - nameserver - - The nameserver is associated with the device only through - the routing of the IP address. And this is how there can - be multiple, global DNS addresses. - - Conclusion: The logic in net/procfs needs to be re-designed - so that it does not use the DNS address. The DNS address(es) - should to applied to the device status by logic in the - implementation of the NSH ifconfig command. This would be, - unfortunately, a significant re-design since the formatting - is currently performed in net/procfs. - Status: Open - Priority: Low. I doubt that there are any multiple NIC, multiple DNS - server configurations - Title: MISSING netdb INTERFACES Description: There is no implementation for many netdb interfaces such as getaddrinfo(), freeaddrinfo(), getnameinfo(), etc. diff --git a/include/nuttx/net/dns.h b/include/nuttx/net/dns.h index f7dff02af6..921ec595bf 100644 --- a/include/nuttx/net/dns.h +++ b/include/nuttx/net/dns.h @@ -178,44 +178,35 @@ extern "C" #endif /**************************************************************************** - * Name: dns_setserver + * Name: dns_add_nameserver * * Description: - * Configure which DNS server to use for queries. Set the port number - * to zero to use the default DNS server port. + * Configure a DNS server to use for queries. Set the port number to zero + * to use the default DNS server port. * ****************************************************************************/ -int dns_setserver(FAR const struct sockaddr *addr, socklen_t addrlen); +int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen); /**************************************************************************** - * Name: dns_getserver + * Name: dns_del_nameserver * * Description: - * Obtain the currently configured DNS server. + * Remove a DNS server so it is no longer available for further use. * ****************************************************************************/ - -int dns_getserver(FAR struct sockaddr *addr, FAR socklen_t *addrlen); +/* REVISIT: Not implemented */ /**************************************************************************** - * Name: dns_getaddr + * Name: dns_foreach_nameserver * * Description: - * Get the DNS server IPv4 address - * - * Parameters: - * ipaddr The location to return the IPv4 address - * - * Return: - * Zero (OK) is returned on success; A negated errno value is returned - * on failure. + * Traverse each nameserver entry in the resolv.conf file and perform the + * the provided callback. * ****************************************************************************/ -#ifdef CONFIG_NET_IPv4 -int dns_getaddr(FAR struct in_addr *inaddr); -#endif +int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg); #undef EXTERN #if defined(__cplusplus) diff --git a/libc/Kconfig b/libc/Kconfig index e51915d1c2..b008f05e87 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -533,6 +533,22 @@ config NETDB_BUFSIZE endif # NETDB_HOSTFILE +menuconfig NETDB_RESOLVCONF + bool "DNS server file support" + default n + depends on FS_READABLE + select LIBC_NETDB + ---help--- + Enable DNS server look ups in resolver file. + +if NETDB_RESOLVCONF + +config NETDB_RESOLVCONF_PATH + string "Path to host configuration file" + default "/etc/resolv.conf" + +endif # NETDB_RESOLVCONF + config NETDB_DNSCLIENT bool "DNS Name resolution" default n @@ -615,7 +631,7 @@ config NETDB_DNSSERVER_IPv4ADDR depends on NETDB_DNSSERVER_IPv4 ---help--- Default DNS server IPv4 address in host byte order. Default value - 10.0.0.0.1. This may be changed via dns_setserver(). + 10.0.0.0.1. This may be changed via dns_add_nameserver(). if NETDB_DNSSERVER_IPv6 diff --git a/libc/net/lib_inetpton.c b/libc/net/lib_inetpton.c index 96338bde11..8b5eb77dd1 100644 --- a/libc/net/lib_inetpton.c +++ b/libc/net/lib_inetpton.c @@ -372,7 +372,7 @@ static int inet_ipv6_pton(FAR const char *src, FAR void *dest) * af - The af argument specifies the family of the address. This can be * AF_INET or AF_INET6. * src - The src argument points to the string being passed in. - * dest - The dest argument points to a numstr into which the function stores + * dest - The dest argument points to memory into which the function stores * the numeric address; this must be large enough to hold the numeric * address (32 bits for AF_INET, 128 bits for AF_INET6). * diff --git a/libc/netdb/Make.defs b/libc/netdb/Make.defs index b9347eb0fc..ac7069f153 100644 --- a/libc/netdb/Make.defs +++ b/libc/netdb/Make.defs @@ -48,7 +48,7 @@ endif # Add DNS lookup support ifeq ($(CONFIG_NETDB_DNSCLIENT),y) -CSRCS += lib_dnsclient.c lib_getdnsaddr.c +CSRCS += lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c endif # Add the net directory to the build diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index e3e5d3bae5..826b4c94c3 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -74,6 +74,15 @@ # define CONFIG_NETDB_DNSCLIENT_LIFESEC 3600 #endif +#define DNS_MAX_LINE 80 +#define NETDB_DNS_KEYWORD "nameserver" + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef CODE int (*dns_callback_t)(FAR void *arg, int af, FAR void *addr); + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -156,7 +165,7 @@ int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr, FAR socklen_t *addrlen); #endif -#undef EXTERN +o#undef EXTERN #if defined(__cplusplus) } #endif diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index c510f2f431..70f1eb4af5 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -5,7 +5,7 @@ * The uIP DNS resolver functions are used to lookup a hostname and * map it to a numerical IP address. * - * Copyright (C) 2007, 2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Based heavily on portions of uIP: @@ -227,8 +227,8 @@ static bool dns_initialize(void) addr4.sin_port = DNS_DEFAULT_PORT; addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR); - ret = dns_setserver((FAR struct sockaddr *)&addr4, - sizeof(struct sockaddr_in)); + ret = dns_add_nameserver((FAR struct sockaddr *)&addr4, + sizeof(struct sockaddr_in)); if (ret < 0) { return false; @@ -244,8 +244,8 @@ static bool dns_initialize(void) addr6.sin6_port = DNS_DEFAULT_PORT; memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16); - ret = dns_setserver((FAR struct sockaddr *)&addr6, - sizeof(struct sockaddr_in6)); + ret = dns_add_nameserver((FAR struct sockaddr *)&addr6, + sizeof(struct sockaddr_in6)); if (ret < 0) { return false; @@ -877,77 +877,6 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, return -ETIMEDOUT; } -/**************************************************************************** - * Name: dns_setserver - * - * Description: - * Configure which DNS server to use for queries - * - ****************************************************************************/ - -int dns_setserver(FAR const struct sockaddr *addr, socklen_t addrlen) -{ - FAR uint16_t *pport; - size_t copylen; - - DEBUGASSERT(addr != NULL); - - /* Copy the new server IP address into our private global data structure */ - -#ifdef CONFIG_NET_IPv4 - /* Check for an IPv4 address */ - - if (addr->sa_family == AF_INET) - { - /* Set up for the IPv4 address copy */ - - copylen = sizeof(struct sockaddr_in); - pport = &g_dns_server.ipv4.sin_port; - } - else -#endif - -#ifdef CONFIG_NET_IPv6 - /* Check for an IPv6 address */ - - if (addr->sa_family == AF_INET6) - { - /* Set up for the IPv6 address copy */ - - copylen = sizeof(struct sockaddr_in6); - pport = &g_dns_server.ipv6.sin6_port; - } - else -#endif - { - nvdbg("ERROR: Unsupported family: %d\n", addr->sa_family); - return -ENOSYS; - } - - /* Copy the IP address */ - - if (addrlen < copylen) - { - nvdbg("ERROR: Invalid addrlen %ld for family %d\n", - (long)addrlen, addr->sa_family); - return -EINVAL; - } - - memcpy(&g_dns_server.addr, addr, copylen); - - /* A port number of zero means to use the default DNS server port number */ - - if (*pport == 0) - { - *pport = HTONS(DNS_DEFAULT_PORT); - } - - /* We now have a valid DNS address */ - - g_dns_address = true; - return OK; -} - /**************************************************************************** * Name: dns_getserver * diff --git a/libc/netdb/lib_getdnsaddr.c b/libc/netdb/lib_getdnsaddr.c deleted file mode 100644 index a6e6c4335a..0000000000 --- a/libc/netdb/lib_getdnsaddr.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * libc/netdb/lib_dnsgetaddr.c - * - * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include - -#include - -#include - -#include - -#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dns_getaddr - * - * Description: - * Get the DNS server IPv4 address - * - * Parameters: - * ipaddr The location to return the IPv4 address - * - * Return: - * Zero (OK) is returned on success; A negated errno value is returned - * on failure. - * - ****************************************************************************/ - -int dns_getaddr(FAR struct in_addr *inaddr) -{ - struct sockaddr_in addr; - socklen_t addrlen; - int ret = -EINVAL; - - if (inaddr) - { - addrlen = sizeof(struct sockaddr_in); - ret = dns_getserver((FAR struct sockaddr *)&addr, &addrlen); - if (ret >= 0) - { - /* Sanity check */ - - DEBUGASSERT(addr.sin_family == AF_INET && - addrlen == sizeof(struct sockaddr_in)); - memcpy(inaddr, &addr.sin_addr, sizeof(struct in_addr)); - } - } - - return ret; -} - -#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 16cfb440d9..80154c91fa 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -47,7 +47,6 @@ #include #include -#include #include "netdev/netdev.h" #include "utils/utils.h" @@ -246,17 +245,6 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) addr.s_addr = dev->d_netmask; len += snprintf(&netfile->line[len], NET_LINELEN - len, "Mask:%s\n", inet_ntoa(addr)); - -#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) - /* Show the IPv4 DNS address */ - /* REVISIT: DNS client is global, not per device, and resides in the - * application space and is not generally accessible from kernel space. - */ - - dns_getaddr(&addr); - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "\tDNSaddr:%s\n", inet_ntoa(addr)); -#endif #endif #ifdef CONFIG_NET_IPv6 @@ -279,11 +267,6 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); } - -#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) - /* Show the IPv6 DNS address */ -# warning Missing logic -#endif #endif len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); -- GitLab From b112d8fddc7673aa48477dd3743884df7451b205 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 16:02:23 -0600 Subject: [PATCH 538/858] DNS: A little more resolv.conf logic. Still not complete. --- libc/netdb/lib_dns.h | 37 +++++- libc/netdb/lib_dnsaddserver.c | 211 +++++++++++++++++++++++++++++++++ libc/netdb/lib_dnsclient.c | 65 ---------- libc/netdb/lib_dnsforeach.c | 215 ++++++++++++++++++++++++++++++++++ 4 files changed, 461 insertions(+), 67 deletions(-) create mode 100644 libc/netdb/lib_dnsaddserver.c create mode 100644 libc/netdb/lib_dnsforeach.c diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index 826b4c94c3..0f2544df7b 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -74,17 +74,39 @@ # define CONFIG_NETDB_DNSCLIENT_LIFESEC 3600 #endif +#ifndef CONFIG_NETDB_RESOLVCONF_PATH +# define CONFIG_NETDB_RESOLVCONF_PATH "/etc/resolv.conf" +#endif + #define DNS_MAX_LINE 80 #define NETDB_DNS_KEYWORD "nameserver" /**************************************************************************** * Public Types ****************************************************************************/ +/* This describes either an IPv4 or IPv6 address. It is essentially a named + * alternative to sockaddr_storage. + */ + +union dns_server_u +{ + struct sockaddr addr; /* Common address representation */ +#ifdef CONFIG_NET_IPv4 + struct sockaddr_in ipv4; /* IPv4 address */ +#endif +#ifdef CONFIG_NET_IPv6 + struct sockaddr_in6 ipv6; /* IPv6 address */ +#endif +}; -typedef CODE int (*dns_callback_t)(FAR void *arg, int af, FAR void *addr); +/* The type of the callback from dns_foreach_nameserver() */ + +typedef CODE int (*dns_callback_t)(FAR void *arg, + FAR struct sockaddr *addr, + FAR socklen_t *addrlen); /**************************************************************************** - * Public Function Prototypes + * Public Data ****************************************************************************/ #undef EXTERN @@ -96,6 +118,17 @@ extern "C" #define EXTERN extern #endif +#ifndef CONFIG_NETDB_RESOLVCONF +/* The DNS server address */ + +EXTERN union dns_server_u g_dns_server; +EXTERN bool g_dns_address; /* true: We have the address of the DNS server */ +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + /**************************************************************************** * Name: dns_bind * diff --git a/libc/netdb/lib_dnsaddserver.c b/libc/netdb/lib_dnsaddserver.c new file mode 100644 index 0000000000..2cbc68644b --- /dev/null +++ b/libc/netdb/lib_dnsaddserver.c @@ -0,0 +1,211 @@ +/**************************************************************************** + * libc/netdb/lib_dnsaddserver.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "netdb/lib_dns.h" + +#ifdef CONFIG_NETDB_DNSCLIENT + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef CONFIG_NETDB_RESOLVCONF +/* The DNS server address */ + +union dns_server_u g_dns_server; +bool g_dns_address; /* true: We have the address of the DNS server */ +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_add_nameserver + * + * Description: + * Configure which DNS server to use for queries + * + ****************************************************************************/ + +#ifdef CONFIG_NETDB_RESOLVCONF +int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) +{ + FAR FILE *stream; + char line[DNS_MAX_LINE]; + int ret = OK; + + stream = fopen(CONFIG_NETDB_RESOLVCONF, "at"); + if (stream == NULL) + { + int errcode = errno; + ndbg("ERROR: Failed to open %s: %d\n", + CONFIG_NETDB_RESOLVCONF, errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } + +#ifdef CONFIG_NET_IPv4 + /* Check for an IPv4 address */ + + if (addr->sa_family == AF_INET) + { + if (socklen < sizeof(struct sockaddr_in)) + { + ret = -EINVAL; + } + else + { + FAR struct sockaddr_in *in4 = (FAR struct sockaddr_in *)addr; + + if (inet_ntop(AF_INET, &in4->sin_addr, line, DNS_MAX_LINE) == NULL) + { + int errcode = errno; + ndbg("ERROR: inet_ntop failed: %d\n", errcode); + DEBUGASSERT(errcode > 0); + ret = -errcode; + } + } + else +#endif + +#ifdef CONFIG_NET_IPv6 + /* Check for an IPv4 address */ + + if (addr->sa_family == AF_INET6) + { + if (socklen < sizeof(struct sockaddr_in6)) + { + ret = -EINVAL; + } + else + { + FAR struct sockaddr_in6 *in6 = (FAR struct sockaddr_in6 *)addr; + + if (inet_ntop(AF_INET6, &in6->sin6_addr, line, DNS_MAX_LINE) == NULL) + { + int errcode = errno; + ndbg("ERROR: inet_ntop failed: %d\n", errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } + } + else +#endif + { + nvdbg("ERROR: Unsupported family: %d\n", + g_dns_server.addr.sa_family); + ret = -ENOSYS; + } + + fclose(stream); + return ret; +} + +#else /* CONFIG_NETDB_RESOLVCONF */ + +int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) +{ + FAR uint16_t *pport; + size_t copylen; + + DEBUGASSERT(addr != NULL); + + /* Copy the new server IP address into our private global data structure */ + +#ifdef CONFIG_NET_IPv4 + /* Check for an IPv4 address */ + + if (addr->sa_family == AF_INET) + { + /* Set up for the IPv4 address copy */ + + copylen = sizeof(struct sockaddr_in); + pport = &g_dns_server.ipv4.sin_port; + } + else +#endif + +#ifdef CONFIG_NET_IPv6 + /* Check for an IPv6 address */ + + if (addr->sa_family == AF_INET6) + { + /* Set up for the IPv6 address copy */ + + copylen = sizeof(struct sockaddr_in6); + pport = &g_dns_server.ipv6.sin6_port; + } + else +#endif + { + nvdbg("ERROR: Unsupported family: %d\n", addr->sa_family); + return -ENOSYS; + } + + /* Copy the IP address */ + + if (addrlen < copylen) + { + nvdbg("ERROR: Invalid addrlen %ld for family %d\n", + (long)addrlen, addr->sa_family); + return -EINVAL; + } + + memcpy(&g_dns_server.addr, addr, copylen); + + /* A port number of zero means to use the default DNS server port number */ + + if (*pport == 0) + { + *pport = HTONS(DNS_DEFAULT_PORT); + } + + /* We now have a valid DNS address */ + + g_dns_address = true; + return OK; +#endif /* CONFIG_NETDB_RESOLVCONF */ +} + +#endif /* CONFIG_NETDB_DNSCLIENT */ diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index 70f1eb4af5..be87213029 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -89,20 +89,6 @@ /**************************************************************************** * Private Types ****************************************************************************/ -/* This describes either an IPv4 or IPv6 address. It is essentially a named - * alternative to sockaddr_storage. - */ - -union dns_server_u -{ - struct sockaddr addr; /* Common address representation */ -#ifdef CONFIG_NET_IPv4 - struct sockaddr_in ipv4; /* IPv4 address */ -#endif -#ifdef CONFIG_NET_IPv6 - struct sockaddr_in6 ipv6; /* IPv6 address */ -#endif -}; #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 /* This described one entry in the cache of resolved hostnames */ @@ -123,17 +109,12 @@ struct dns_cache_s static sem_t g_dns_sem; /* Protects g_seqno and DNS cache */ static bool g_dns_initialized; /* DNS data structures initialized */ -static bool g_dns_address; /* We have the address of the DNS server */ #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 static uint8_t g_dns_head; /* Head of the circular, DNS resolver cache */ static uint8_t g_dns_tail; /* Tail of the circular, DNS resolver cache */ #endif static uint8_t g_seqno; /* Sequence number of the next request */ -/* The DNS server address */ - -static union dns_server_u g_dns_server; - #ifdef CONFIG_NETDB_DNSSERVER_IPv6 /* This is the default IPv6 DNS server address */ @@ -877,52 +858,6 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, return -ETIMEDOUT; } -/**************************************************************************** - * Name: dns_getserver - * - * Description: - * Obtain the currently configured DNS server. - * - ****************************************************************************/ - -int dns_getserver(FAR struct sockaddr *addr, FAR socklen_t *addrlen) -{ - socklen_t copylen; - - DEBUGASSERT(addr != NULL && addrlen != NULL); - -#ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - if (g_dns_server.addr.sa_family == AF_INET) -#endif - { - copylen = sizeof(struct sockaddr_in); - } -#endif - -#ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - else -#endif - { - copylen = sizeof(struct sockaddr_in6); - } -#endif - - /* Copy the DNS server address to the caller-provided buffer */ - - if (copylen > *addrlen) - { - nvdbg("ERROR: addrlen %ld too small for address family %d\n", - (long)addrlen, g_dns_server.addr.sa_family); - return -EINVAL; - } - - memcpy(addr, &g_dns_server.addr, copylen); - *addrlen = copylen; - return OK; -} - /**************************************************************************** * Name: dns_find_answer * diff --git a/libc/netdb/lib_dnsforeach.c b/libc/netdb/lib_dnsforeach.c new file mode 100644 index 0000000000..ca6c01ee6f --- /dev/null +++ b/libc/netdb/lib_dnsforeach.c @@ -0,0 +1,215 @@ +/**************************************************************************** + * libc/netdb/lib_dnsforeach.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "netdb/lib_dns.h" + +#ifdef CONFIG_NETDB_DNSCLIENT + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static FAR char *skip_spaces(FAR char *ptr) +{ + while (isspace(*ptr)) ptr++; + return ptr; +} + +static FAR char *find_spaces(FAR char *ptr) +{ + while (isspace(*ptr)) ptr++; + return ptr; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_foreach_nameserver + * + * Description: + * Traverse each nameserver entry in the resolv.conf file and perform the + * the provided callback. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDB_RESOLVCONF + +int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) +{ + union dns_server_u u; + FAR FILE *stream; + char line[DNS_MAX_LINE]; + FAR char *ptr; + int keylen; + int ret; + + /* Open the resolver configuration file */ + + stream = fopen(CONFIG_NETDB_RESOLVCONF, "rb"); + if (stream == NULL) + { + int errcode = errno; + ndbg("ERROR: Failed to open %s: %d\n", + CONFIG_NETDB_RESOLVCONF, errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } + + keylen = strlen(NETDB_DNS_KEYWORD); + while (fgets(line, DNS_MAX_LINE, stream) != NULL) + { + ptr = skip_spaces(line); + if (strncmp(ptr, NETDB_DNS_KEYWORD, keylen) == 0) + { + socklen_t copylen; + + /* REVISIT: We really need a customizable port number. The + * OpenBSD version supports a [host]:port syntax. When a + * non-standard port is specified the host address must be + * enclosed in square brackets. For example: + * + * nameserver [10.0.0.1]:5353 + * nameserver [::1]:5353 + */ + +#ifdef CONFIG_NET_IPv4 + /* Try to convert the IPv4 address */ + + ret = inet_pton(AF_INET, ptr, &u.ipv4.sin_addr); + + /* The inet_pton() function returns 1 if the conversion succeeds */ + + if (ret == 1) + { + /* REVISIT: We really need a customizable port number */ + + u.ipv4.sin_family = AF_INET; + u.ipv4.sin_port = DNS_DEFAULT_PORT; + ret = callback(arg, AF_INET, &u.ipv4, sizeof(struct sockaddr_in)); + } + else +#endif +#ifdef CONFIG_NET_IPv6 + { + /* Try to convert the IPv6 address */ + + ret = inet_pton(AF_INET6, ptr, &u.ipv6.sin6_addr); + + /* The inet_pton() function returns 1 if the conversion + * succeeds. + */ + + if (ret == 1) + { + /* REVISIT: We really need a customizable port number */ + + u.ipv6.sin6_family = AF_INET6; + u.ipv6.sin6_port = DNS_DEFAULT_PORT; + ret = callback(arg, &u.ipv6, sizeof(struct sockaddr_in6)); + } + else +#endif + { + ndbg("ERROR: Unrecognized address: %s\n", ptr) + ret = OK; + } +#ifdef CONFIG_NET_IPv6 + } +#endif + if (ret != OK) + { + fclose(stream); + return ret; + } + } + } + + fclose(stream); + return OK; +} + +#else /* CONFIG_NETDB_RESOLVCONF */ + +int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) +{ + int ret = OK; + + if (g_dns_address) + { +#ifdef CONFIG_NET_IPv4 + /* Check for an IPv4 address */ + + if (g_dns_server.addr.sa_family == AF_INET) + { + /* Perform the callback */ + + ret = callback(arg, &g_dns_server.ipv4, sizeof(struct sockaddr_in); + } + else +#endif + +#ifdef CONFIG_NET_IPv6 + /* Check for an IPv6 address */ + + if (g_dns_server.addr.sa_family == AF_INET6) + { + /* Perform the callback */ + + ret = callback(arg, &g_dns_server.ipv6, sizeof(struct sockaddr_in6); + } + else +#endif + { + nvdbg("ERROR: Unsupported family: %d\n", + g_dns_server.addr.sa_family); + ret = -ENOSYS; + } + } + + return ret; +} + +#endif /* CONFIG_NETDB_RESOLVCONF */ +#endif /* CONFIG_NETDB_DNSCLIENT */ -- GitLab From a7acb45ca6bc92da7ddc3eaf03e468c26d26989d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 13 Jan 2016 16:29:50 -0600 Subject: [PATCH 539/858] Add logic misssing from dns_add_server --- libc/netdb/lib_dnsaddserver.c | 46 ++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/libc/netdb/lib_dnsaddserver.c b/libc/netdb/lib_dnsaddserver.c index 2cbc68644b..3bfbef4f5d 100644 --- a/libc/netdb/lib_dnsaddserver.c +++ b/libc/netdb/lib_dnsaddserver.c @@ -73,7 +73,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) { FAR FILE *stream; char line[DNS_MAX_LINE]; - int ret = OK; + int ret; stream = fopen(CONFIG_NETDB_RESOLVCONF, "at"); if (stream == NULL) @@ -93,6 +93,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (socklen < sizeof(struct sockaddr_in)) { ret = -EINVAL; + goto errout; } else { @@ -100,13 +101,14 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (inet_ntop(AF_INET, &in4->sin_addr, line, DNS_MAX_LINE) == NULL) { - int errcode = errno; + ret = -errno; ndbg("ERROR: inet_ntop failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - ret = -errcode; + DEBUGASSERT(errcode < 0); + goto errout; } } - else + } + else #endif #ifdef CONFIG_NET_IPv6 @@ -117,6 +119,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (socklen < sizeof(struct sockaddr_in6)) { ret = -EINVAL; + goto errout; } else { @@ -124,20 +127,35 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (inet_ntop(AF_INET6, &in6->sin6_addr, line, DNS_MAX_LINE) == NULL) { - int errcode = errno; + ret = -errno; ndbg("ERROR: inet_ntop failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + DEBUGASSERT(errcode < 0); + goto errout; } } - else + } + else #endif - { - nvdbg("ERROR: Unsupported family: %d\n", - g_dns_server.addr.sa_family); - ret = -ENOSYS; - } + { + nvdbg("ERROR: Unsupported family: %d\n", + g_dns_server.addr.sa_family); + ret = -ENOSYS; + goto errout; + } + + /* Write the new record to the end of the resolv.conf file */ + + if (fprintf(stream, "%s %s\n", NETDB_DNS_KEYWORD, line) < 0) + { + ret = -errno; + ndbg("ERROR: fprintf failed: %d\n", errcode); + DEBUGASSERT(errcode < 0); + goto errout; + } + + ret = OK; +errout: fclose(stream); return ret; } -- GitLab From 0889963b5052ba2f5087f5493a84284fd91ed281 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 08:32:20 -0600 Subject: [PATCH 540/858] resolv.conf: Fix some basic compilation issues. Logic still not complete. --- include/nuttx/net/dns.h | 6 +++++ libc/Kconfig | 33 +++++++++++++------------ libc/netdb/lib_dns.h | 10 +++----- libc/netdb/lib_dnsaddserver.c | 18 ++++++++++---- libc/netdb/lib_dnsclient.c | 8 ++++--- libc/netdb/lib_dnsforeach.c | 45 +++++++++++++++++++++++++++-------- 6 files changed, 78 insertions(+), 42 deletions(-) diff --git a/include/nuttx/net/dns.h b/include/nuttx/net/dns.h index 921ec595bf..8c11147e7e 100644 --- a/include/nuttx/net/dns.h +++ b/include/nuttx/net/dns.h @@ -164,6 +164,12 @@ struct dns_answer_s } u; }; +/* The type of the callback from dns_foreach_nameserver() */ + +typedef CODE int (*dns_callback_t)(FAR void *arg, + FAR struct sockaddr *addr, + FAR socklen_t addrlen); + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/libc/Kconfig b/libc/Kconfig index b008f05e87..a9246777b9 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -533,23 +533,7 @@ config NETDB_BUFSIZE endif # NETDB_HOSTFILE -menuconfig NETDB_RESOLVCONF - bool "DNS server file support" - default n - depends on FS_READABLE - select LIBC_NETDB - ---help--- - Enable DNS server look ups in resolver file. - -if NETDB_RESOLVCONF - -config NETDB_RESOLVCONF_PATH - string "Path to host configuration file" - default "/etc/resolv.conf" - -endif # NETDB_RESOLVCONF - -config NETDB_DNSCLIENT +menuconfig NETDB_DNSCLIENT bool "DNS Name resolution" default n depends on NET && NET_UDP @@ -716,6 +700,21 @@ config NETDB_DNSSERVER_IPv6ADDR_8 of the 8-values. The default for all eight values is fc00::1. endif # NETDB_DNSSERVER_IPv6 + +config NETDB_RESOLVCONF + bool "DNS server file support" + default n + depends on FS_READABLE + ---help--- + Enable DNS server look ups in resolver file. + +if NETDB_RESOLVCONF + +config NETDB_RESOLVCONF_PATH + string "Path to host configuration file" + default "/etc/resolv.conf" + +endif # NETDB_RESOLVCONF endif # NETDB_DNSCLIENT comment "Non-standard Library Support" diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index 0f2544df7b..6aee65a57c 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -45,6 +45,8 @@ #include +#include + #include #include @@ -99,12 +101,6 @@ union dns_server_u #endif }; -/* The type of the callback from dns_foreach_nameserver() */ - -typedef CODE int (*dns_callback_t)(FAR void *arg, - FAR struct sockaddr *addr, - FAR socklen_t *addrlen); - /**************************************************************************** * Public Data ****************************************************************************/ @@ -198,7 +194,7 @@ int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr, FAR socklen_t *addrlen); #endif -o#undef EXTERN +#undef EXTERN #if defined(__cplusplus) } #endif diff --git a/libc/netdb/lib_dnsaddserver.c b/libc/netdb/lib_dnsaddserver.c index 3bfbef4f5d..dfeff175c2 100644 --- a/libc/netdb/lib_dnsaddserver.c +++ b/libc/netdb/lib_dnsaddserver.c @@ -39,6 +39,14 @@ #include +#include +#include +#include +#include +#include +#include + +#include #include #include "netdb/lib_dns.h" @@ -75,12 +83,12 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) char line[DNS_MAX_LINE]; int ret; - stream = fopen(CONFIG_NETDB_RESOLVCONF, "at"); + stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "at"); if (stream == NULL) { int errcode = errno; ndbg("ERROR: Failed to open %s: %d\n", - CONFIG_NETDB_RESOLVCONF, errcode); + CONFIG_NETDB_RESOLVCONF_PATH, errcode); DEBUGASSERT(errcode > 0); return -errcode; } @@ -90,7 +98,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (addr->sa_family == AF_INET) { - if (socklen < sizeof(struct sockaddr_in)) + if (addrlen < sizeof(struct sockaddr_in)) { ret = -EINVAL; goto errout; @@ -116,7 +124,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) if (addr->sa_family == AF_INET6) { - if (socklen < sizeof(struct sockaddr_in6)) + if (addrlen < sizeof(struct sockaddr_in6)) { ret = -EINVAL; goto errout; @@ -223,7 +231,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) g_dns_address = true; return OK; -#endif /* CONFIG_NETDB_RESOLVCONF */ } +#endif /* CONFIG_NETDB_RESOLVCONF */ #endif /* CONFIG_NETDB_DNSCLIENT */ diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index be87213029..6d7d3c9d6f 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -194,6 +194,7 @@ static bool dns_initialize(void) g_dns_initialized = true; } +#ifndef CONFIG_NETDB_RESOLVCONF /* Has the DNS server IP address been assigned? */ if (!g_dns_address) @@ -205,7 +206,7 @@ static bool dns_initialize(void) /* No, configure the default IPv4 DNS server address */ addr4.sin_family = AF_INET; - addr4.sin_port = DNS_DEFAULT_PORT; + addr4.sin_port = HTONS(DNS_DEFAULT_PORT); addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR); ret = dns_add_nameserver((FAR struct sockaddr *)&addr4, @@ -222,7 +223,7 @@ static bool dns_initialize(void) /* No, configure the default IPv6 DNS server address */ addr6.sin6_family = AF_INET6; - addr6.sin6_port = DNS_DEFAULT_PORT; + addr6.sin6_port = HTONS(DNS_DEFAULT_PORT); memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16); ret = dns_add_nameserver((FAR struct sockaddr *)&addr6, @@ -233,11 +234,12 @@ static bool dns_initialize(void) } #else - /* No, then we are not ready to perform DNS queries */ + /* Then we are not ready to perform DNS queries */ return false; #endif } +#endif /* !ONFIG_NETDB_RESOLVCONF */ return true; } diff --git a/libc/netdb/lib_dnsforeach.c b/libc/netdb/lib_dnsforeach.c index ca6c01ee6f..27ceed99d7 100644 --- a/libc/netdb/lib_dnsforeach.c +++ b/libc/netdb/lib_dnsforeach.c @@ -39,6 +39,15 @@ #include +#include +#include +#include +#include +#include +#include + +#include + #include #include "netdb/lib_dns.h" @@ -49,6 +58,7 @@ * Private Functions ****************************************************************************/ +#ifdef CONFIG_NETDB_RESOLVCONF static FAR char *skip_spaces(FAR char *ptr) { while (isspace(*ptr)) ptr++; @@ -57,9 +67,10 @@ static FAR char *skip_spaces(FAR char *ptr) static FAR char *find_spaces(FAR char *ptr) { - while (isspace(*ptr)) ptr++; + while (*ptr && !isspace(*ptr)) ptr++; return ptr; } +#endif /**************************************************************************** * Public Functions @@ -87,12 +98,12 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* Open the resolver configuration file */ - stream = fopen(CONFIG_NETDB_RESOLVCONF, "rb"); + stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "rb"); if (stream == NULL) { int errcode = errno; ndbg("ERROR: Failed to open %s: %d\n", - CONFIG_NETDB_RESOLVCONF, errcode); + CONFIG_NETDB_RESOLVCONF_PATH, errcode); DEBUGASSERT(errcode > 0); return -errcode; } @@ -103,8 +114,18 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) ptr = skip_spaces(line); if (strncmp(ptr, NETDB_DNS_KEYWORD, keylen) == 0) { - socklen_t copylen; + /* Skip over the 'nameserver' keyword */ + + ptr = find_spaces(ptr); + ptr = skip_spaces(ptr); + if (*ptr == '\0') + { + ndbg("ERROR: Missing address in %s record\n", + CONFIG_NETDB_RESOLVCONF_PATH); + continue; + } + /* Convert the address string to a binary representation */ /* REVISIT: We really need a customizable port number. The * OpenBSD version supports a [host]:port syntax. When a * non-standard port is specified the host address must be @@ -126,8 +147,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* REVISIT: We really need a customizable port number */ u.ipv4.sin_family = AF_INET; - u.ipv4.sin_port = DNS_DEFAULT_PORT; - ret = callback(arg, AF_INET, &u.ipv4, sizeof(struct sockaddr_in)); + u.ipv4.sin_port = HTONS(DNS_DEFAULT_PORT); + ret = callback(arg, (FAR struct sockaddr *)&u.ipv4, + sizeof(struct sockaddr_in)); } else #endif @@ -146,8 +168,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* REVISIT: We really need a customizable port number */ u.ipv6.sin6_family = AF_INET6; - u.ipv6.sin6_port = DNS_DEFAULT_PORT; - ret = callback(arg, &u.ipv6, sizeof(struct sockaddr_in6)); + u.ipv6.sin6_port = HTONS(DNS_DEFAULT_PORT); + ret = callback(arg, (FAR struct sockaddr *)&u.ipv6, + sizeof(struct sockaddr_in6)); } else #endif @@ -185,7 +208,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { /* Perform the callback */ - ret = callback(arg, &g_dns_server.ipv4, sizeof(struct sockaddr_in); + ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv4, + sizeof(struct sockaddr_in)); } else #endif @@ -197,7 +221,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { /* Perform the callback */ - ret = callback(arg, &g_dns_server.ipv6, sizeof(struct sockaddr_in6); + ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv6, + sizeof(struct sockaddr_in6)); } else #endif -- GitLab From 62f04d98c19af4310090b447db21f042039f616b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 10:17:15 -0600 Subject: [PATCH 541/858] netdb: Move DNS initialization and cache logic to separate files --- libc/netdb/Make.defs | 6 +- libc/netdb/lib_dns.h | 51 +++++ libc/netdb/lib_dnscache.c | 316 ++++++++++++++++++++++++++++++ libc/netdb/lib_dnsclient.c | 388 +------------------------------------ libc/netdb/lib_dnsinit.c | 184 ++++++++++++++++++ 5 files changed, 562 insertions(+), 383 deletions(-) create mode 100644 libc/netdb/lib_dnscache.c create mode 100644 libc/netdb/lib_dnsinit.c diff --git a/libc/netdb/Make.defs b/libc/netdb/Make.defs index ac7069f153..758534c09e 100644 --- a/libc/netdb/Make.defs +++ b/libc/netdb/Make.defs @@ -48,7 +48,11 @@ endif # Add DNS lookup support ifeq ($(CONFIG_NETDB_DNSCLIENT),y) -CSRCS += lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c +CSRCS += lib_dnsinit.c lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c + +ifneq ($(CONFIG_NETDB_DNSCLIENT_ENTRIES),0) +CSRCS += lib_dnscache.c +endif endif # Add the net directory to the build diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index 6aee65a57c..86287dc226 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -125,6 +125,36 @@ EXTERN bool g_dns_address; /* true: We have the address of the DNS server */ * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Name: dns_initialize + * + * Description: + * Make sure that the DNS client has been properly initialized for use. + * + ****************************************************************************/ + +bool dns_initialize(void); + +/**************************************************************************** + * Name: dns_semtake + * + * Description: + * Take the DNS semaphore, ignoring errors do to the receipt of signals. + * + ****************************************************************************/ + +void dns_semtake(void); + +/**************************************************************************** + * Name: dns_semgive + * + * Description: + * Release the DNS semaphore + * + ****************************************************************************/ + +void dns_semgive(void); + /**************************************************************************** * Name: dns_bind * @@ -167,6 +197,27 @@ int dns_bind(void); int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, FAR socklen_t *addrlen); +/**************************************************************************** + * Name: dns_save_answer + * + * Description: + * Same the last resolved hostname in the DNS cache + * + * Input Parameters: + * hostname - The hostname string to be cached. + * addr - The IP address associated with the hostname + * addrlen - The size of the of the IP address. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 +void dns_save_answer(FAR const char *hostname, + FAR const struct sockaddr *addr, socklen_t addrlen); +#endif + /**************************************************************************** * Name: dns_find_answer * diff --git a/libc/netdb/lib_dnscache.c b/libc/netdb/lib_dnscache.c new file mode 100644 index 0000000000..72979e4066 --- /dev/null +++ b/libc/netdb/lib_dnscache.c @@ -0,0 +1,316 @@ +/**************************************************************************** + * libc/netdb/lib_dnscache.c + * + * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "netdb/lib_dns.h" + +#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Use clock monotonic, if possible */ + +#ifdef CONFIG_CLOCK_MONOTONIC +# define DNS_CLOCK CLOCK_MONOTONIC +#else +# define DNS_CLOCK CLOCK_REALTIME +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This described one entry in the cache of resolved hostnames */ + +struct dns_cache_s +{ +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + time_t ctime; /* Creation time */ +#endif + char name[CONFIG_NETDB_DNSCLIENT_NAMESIZE]; + union dns_server_u addr; /* Resolved address */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint8_t g_dns_head; /* Head of the circular, DNS resolver cache */ +static uint8_t g_dns_tail; /* Tail of the circular, DNS resolver cache */ + +/* This is the DNS resolver cache */ + +static struct dns_cache_s g_dns_cache[CONFIG_NETDB_DNSCLIENT_ENTRIES]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_save_answer + * + * Description: + * Same the last resolved hostname in the DNS cache + * + * Input Parameters: + * hostname - The hostname string to be cached. + * addr - The IP address associated with the hostname + * addrlen - The size of the of the IP address. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void dns_save_answer(FAR const char *hostname, + FAR const struct sockaddr *addr, socklen_t addrlen) +{ + FAR struct dns_cache_s *entry; +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + struct timespec now; +#endif + int next; + int ndx; + + /* Get exclusive access to the DNS cache */ + + dns_semtake(); + + /* Get the index to the new head of the list */ + + ndx = g_dns_head; + next = ndx + 1; + if (next >= CONFIG_NETDB_DNSCLIENT_ENTRIES) + { + next = 0; + } + + /* If the next head pointer would match the tail index, then increment + * the tail index, discarding the oldest mapping in the cache. + */ + + if (next == g_dns_tail) + { + int tmp = g_dns_tail + 1; + if (tmp >= CONFIG_NETDB_DNSCLIENT_ENTRIES) + { + tmp = 0; + } + + g_dns_tail = tmp; + } + + /* Save the answer in the cache */ + + entry = &g_dns_cache[ndx]; + +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + /* Get the current time, using CLOCK_MONOTONIC if possible */ + + (void)clock_settime(DNS_CLOCK, &now); + entry->ctime = (time_t)now.tv_sec; +#endif + + strncpy(entry->name, hostname, CONFIG_NETDB_DNSCLIENT_NAMESIZE); + memcpy(&entry->addr.addr, addr, addrlen); + + /* Save the updated head index */ + + g_dns_head = next; + dns_semgive(); +} + +/**************************************************************************** + * Name: dns_find_answer + * + * Description: + * Check if we already have the resolved hostname address in the cache. + * + * Input Parameters: + * hostname - The hostname string to be resolved. + * addr - The location to return the IP address associated with the + * hostname + * addrlen - On entry, the size of the buffer backing up the 'addr' + * pointer. On return, this location will hold the actual size of + * the returned address. + * + * Returned Value: + * If the host name was successfully found in the DNS name resolution + * cache, zero (OK) will be returned. Otherwise, some negated errno + * value will be returned, typically -ENOENT meaning that the hostname + * was not found in the cache. + * + ****************************************************************************/ + +int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr, + FAR socklen_t *addrlen) +{ + FAR struct dns_cache_s *entry; +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + struct timespec now; + uint32_t elapsed; + int ret; +#endif + int next; + int ndx; + + /* If DNS not initialized, no need to proceed */ + + if (!dns_initialize()) + { + ndbg("ERROR: DNS failed to initialize\n"); + return -EAGAIN; + } + + /* Get exclusive access to the DNS cache */ + + dns_semtake(); + +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + /* Get the current time, using CLOCK_MONOTONIC if possible */ + + ret = clock_settime(DNS_CLOCK, &now); +#endif + + /* REVISIT: This is not thread safe */ + + for (ndx = g_dns_tail; ndx != g_dns_head; ndx = next) + { + entry = &g_dns_cache[ndx]; + + /* Advance the index for the next time through the loop, handling + * wrapping to the beginning of the circular buffer. + */ + + next = ndx + 1; + if (next >= CONFIG_NETDB_DNSCLIENT_ENTRIES) + { + next = 0; + } + +#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 + /* Check if this entry has expired + * REVISIT: Does not this calculation assume that the sizeof(time_t) + * is equal to the sizeof(uint32_t)? + */ + + elapsed = (uint32_t)now.tv_sec - (uint32_t)entry->ctime; + if (ret >= 0 && elapsed > CONFIG_NETDB_DNSCLIENT_LIFESEC) + { + /* This entry has expired. Increment the tail index to exclude + * this entry on future traversals. + */ + + g_dns_tail = next; + } + else +#endif + { + /* The entry has not expired, check for a name match. Notice that + * because the names are truncated to CONFIG_NETDB_DNSCLIENT_NAMESIZE, + * this has the possibility of aliasing two names and returning + * the wrong entry from the cache. + */ + + if (strncmp(hostname, entry->name, CONFIG_NETDB_DNSCLIENT_NAMESIZE) == 0) + { + socklen_t inlen; + + /* We have a match. Return the resolved host address */ + +#ifdef CONFIG_NET_IPv4 + if (entry->addr.addr.sa_family == AF_INET) +#ifdef CONFIG_NET_IPv6 +#endif + { + inlen = sizeof(struct sockaddr_in); + } +#endif + +#ifdef CONFIG_NET_IPv6 + else +#ifdef CONFIG_NET_IPv4 +#endif + { + inlen = sizeof(struct sockaddr_in6); + } +#endif + /* Make sure that the address will fit in the caller-provided + * buffer. + */ + + if (*addrlen < inlen) + { + ret = -ERANGE; + goto errout_with_sem; + } + + /* Return the address information */ + + memcpy(addr, &entry->addr.addr, inlen); + *addrlen = inlen; + + dns_semgive(); + return OK; + } + } + } + + ret = -ENOENT; + +errout_with_sem: + dns_semgive(); + return ret; +} + +#endif /* CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 */ + diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index 6d7d3c9d6f..ba56279eb8 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -46,20 +46,18 @@ #include -#include #include -#include -#include -#include #include -#include -#include +#include #include #include -#include #include -#include + +#if 0 +#include + +#endif #include @@ -78,249 +76,20 @@ #define SEND_BUFFER_SIZE 64 #define RECV_BUFFER_SIZE CONFIG_NETDB_DNSCLIENT_MAXRESPONSE -/* Use clock monotonic, if possible */ - -#ifdef CONFIG_CLOCK_MONOTONIC -# define DNS_CLOCK CLOCK_MONOTONIC -#else -# define DNS_CLOCK CLOCK_REALTIME -#endif - /**************************************************************************** * Private Types ****************************************************************************/ -#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 -/* This described one entry in the cache of resolved hostnames */ - -struct dns_cache_s -{ -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - time_t ctime; /* Creation time */ -#endif - char name[CONFIG_NETDB_DNSCLIENT_NAMESIZE]; - union dns_server_u addr; /* Resolved address */ -}; -#endif - /**************************************************************************** * Private Data ****************************************************************************/ -static sem_t g_dns_sem; /* Protects g_seqno and DNS cache */ -static bool g_dns_initialized; /* DNS data structures initialized */ -#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 -static uint8_t g_dns_head; /* Head of the circular, DNS resolver cache */ -static uint8_t g_dns_tail; /* Tail of the circular, DNS resolver cache */ -#endif static uint8_t g_seqno; /* Sequence number of the next request */ -#ifdef CONFIG_NETDB_DNSSERVER_IPv6 -/* This is the default IPv6 DNS server address */ - -static const uint16_t g_ipv6_hostaddr[8] = -{ - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_1), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_2), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_3), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_4), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_5), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_6), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_7), - HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_8) -}; -#endif - -#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 -/* This is the DNS resolver cache */ - -static struct dns_cache_s g_dns_cache[CONFIG_NETDB_DNSCLIENT_ENTRIES]; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: dns_semtake - * - * Description: - * Take the DNS semaphore, ignoring errors do to the receipt of signals. - * - ****************************************************************************/ - -static void dns_semtake(void) -{ - int errcode = 0; - int ret; - - do - { - ret = sem_wait(&g_dns_sem); - if (ret < 0) - { - errcode = get_errno(); - DEBUGASSERT(errcode == EINTR); - } - } - while (ret < 0 && errcode == EINTR); -} - -/**************************************************************************** - * Name: dns_semgive - * - * Description: - * Release the DNS semaphore - * - ****************************************************************************/ - -#define dns_semgive() sem_post(&g_dns_sem) - -/**************************************************************************** - * Name: dns_initialize - * - * Description: - * Make sure that the DNS client has been properly initialized for use. - * - ****************************************************************************/ - -static bool dns_initialize(void) -{ - /* Have DNS data structures been initialized? */ - - if (!g_dns_initialized) - { - sem_init(&g_dns_sem, 0, 1); - g_dns_initialized = true; - } - -#ifndef CONFIG_NETDB_RESOLVCONF - /* Has the DNS server IP address been assigned? */ - - if (!g_dns_address) - { -#if defined(CONFIG_NETDB_DNSSERVER_IPv4) - struct sockaddr_in addr4; - int ret; - - /* No, configure the default IPv4 DNS server address */ - - addr4.sin_family = AF_INET; - addr4.sin_port = HTONS(DNS_DEFAULT_PORT); - addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR); - - ret = dns_add_nameserver((FAR struct sockaddr *)&addr4, - sizeof(struct sockaddr_in)); - if (ret < 0) - { - return false; - } - -#elif defined(CONFIG_NETDB_DNSSERVER_IPv6) - struct sockaddr_in6 addr6; - int ret; - - /* No, configure the default IPv6 DNS server address */ - - addr6.sin6_family = AF_INET6; - addr6.sin6_port = HTONS(DNS_DEFAULT_PORT); - memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16); - - ret = dns_add_nameserver((FAR struct sockaddr *)&addr6, - sizeof(struct sockaddr_in6)); - if (ret < 0) - { - return false; - } - -#else - /* Then we are not ready to perform DNS queries */ - - return false; -#endif - } -#endif /* !ONFIG_NETDB_RESOLVCONF */ - - return true; -} - -/**************************************************************************** - * Name: dns_save_answer - * - * Description: - * Same the last resolved hostname in the DNS cache - * - * Input Parameters: - * hostname - The hostname string to be cached. - * addr - The IP address associated with the hostname - * addrlen - The size of the of the IP address. - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 -static void dns_save_answer(FAR const char *hostname, - FAR const struct sockaddr *addr, - socklen_t addrlen) -{ - FAR struct dns_cache_s *entry; -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - struct timespec now; -#endif - int next; - int ndx; - - /* Get exclusive access to the DNS cache */ - - dns_semtake(); - - /* Get the index to the new head of the list */ - - ndx = g_dns_head; - next = ndx + 1; - if (next >= CONFIG_NETDB_DNSCLIENT_ENTRIES) - { - next = 0; - } - - /* If the next head pointer would match the tail index, then increment - * the tail index, discarding the oldest mapping in the cache. - */ - - if (next == g_dns_tail) - { - int tmp = g_dns_tail + 1; - if (tmp >= CONFIG_NETDB_DNSCLIENT_ENTRIES) - { - tmp = 0; - } - - g_dns_tail = tmp; - } - - /* Save the answer in the cache */ - - entry = &g_dns_cache[ndx]; - -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - /* Get the current time, using CLOCK_MONOTONIC if possible */ - - (void)clock_settime(DNS_CLOCK, &now); - entry->ctime = (time_t)now.tv_sec; -#endif - - strncpy(entry->name, hostname, CONFIG_NETDB_DNSCLIENT_NAMESIZE); - memcpy(&entry->addr.addr, addr, addrlen); - - /* Save the updated head index */ - - g_dns_head = next; - dns_semgive(); -} -#endif - /**************************************************************************** * Name: dns_parse_name * @@ -859,148 +628,3 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, return -ETIMEDOUT; } - -/**************************************************************************** - * Name: dns_find_answer - * - * Description: - * Check if we already have the resolved hostname address in the cache. - * - * Input Parameters: - * hostname - The hostname string to be resolved. - * addr - The location to return the IP address associated with the - * hostname - * addrlen - On entry, the size of the buffer backing up the 'addr' - * pointer. On return, this location will hold the actual size of - * the returned address. - * - * Returned Value: - * If the host name was successfully found in the DNS name resolution - * cache, zero (OK) will be returned. Otherwise, some negated errno - * value will be returned, typically -ENOENT meaning that the hostname - * was not found in the cache. - * - ****************************************************************************/ - -#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 -int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr, - FAR socklen_t *addrlen) -{ - FAR struct dns_cache_s *entry; -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - struct timespec now; - uint32_t elapsed; - int ret; -#endif - int next; - int ndx; - - /* If DNS not initialized, no need to proceed */ - - if (!g_dns_initialized) - { - ndbg("ERROR: DNS not initialized yet\n"); - return -EAGAIN; - } - - /* Get exclusive access to the DNS cache */ - - dns_semtake(); - -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - /* Get the current time, using CLOCK_MONOTONIC if possible */ - - ret = clock_settime(DNS_CLOCK, &now); -#endif - - /* REVISIT: This is not thread safe */ - - for (ndx = g_dns_tail; ndx != g_dns_head; ndx = next) - { - entry = &g_dns_cache[ndx]; - - /* Advance the index for the next time through the loop, handling - * wrapping to the beginning of the circular buffer. - */ - - next = ndx + 1; - if (next >= CONFIG_NETDB_DNSCLIENT_ENTRIES) - { - next = 0; - } - -#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0 - /* Check if this entry has expired - * REVISIT: Does not this calculation assume that the sizeof(time_t) - * is equal to the sizeof(uint32_t)? - */ - - elapsed = (uint32_t)now.tv_sec - (uint32_t)entry->ctime; - if (ret >= 0 && elapsed > CONFIG_NETDB_DNSCLIENT_LIFESEC) - { - /* This entry has expired. Increment the tail index to exclude - * this entry on future traversals. - */ - - g_dns_tail = next; - } - else -#endif - { - /* The entry has not expired, check for a name match. Notice that - * because the names are truncated to CONFIG_NETDB_DNSCLIENT_NAMESIZE, - * this has the possibility of aliasing two names and returning - * the wrong entry from the cache. - */ - - if (strncmp(hostname, entry->name, CONFIG_NETDB_DNSCLIENT_NAMESIZE) == 0) - { - socklen_t inlen; - - /* We have a match. Return the resolved host address */ - -#ifdef CONFIG_NET_IPv4 - if (entry->addr.addr.sa_family == AF_INET) -#ifdef CONFIG_NET_IPv6 -#endif - { - inlen = sizeof(struct sockaddr_in); - } -#endif - -#ifdef CONFIG_NET_IPv6 - else -#ifdef CONFIG_NET_IPv4 -#endif - { - inlen = sizeof(struct sockaddr_in6); - } -#endif - /* Make sure that the address will fit in the caller-provided - * buffer. - */ - - if (*addrlen < inlen) - { - ret = -ERANGE; - goto errout_with_sem; - } - - /* Return the address information */ - - memcpy(addr, &entry->addr.addr, inlen); - *addrlen = inlen; - - dns_semgive(); - return OK; - } - } - } - - ret = -ENOENT; - -errout_with_sem: - dns_semgive(); - return ret; -} -#endif diff --git a/libc/netdb/lib_dnsinit.c b/libc/netdb/lib_dnsinit.c new file mode 100644 index 0000000000..ddb138d896 --- /dev/null +++ b/libc/netdb/lib_dnsinit.c @@ -0,0 +1,184 @@ +/**************************************************************************** + * libc/netdb/lib_dnscache.c + * + * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "netdb/lib_dns.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static sem_t g_dns_sem; /* Protects g_seqno and DNS cache */ +static bool g_dns_initialized; /* DNS data structures initialized */ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#if defined(CONFIG_NETDB_DNSSERVER_IPv6) && !defined(CONFIG_NETDB_RESOLVCONF) + +/* This is the default IPv6 DNS server address */ + +static const uint16_t g_ipv6_hostaddr[8] = +{ + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_1), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_2), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_3), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_4), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_5), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_6), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_7), + HTONS(CONFIG_NETDB_DNSSERVER_IPv6ADDR_8) +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_initialize + * + * Description: + * Make sure that the DNS client has been properly initialized for use. + * + ****************************************************************************/ + +bool dns_initialize(void) +{ + /* Have DNS data structures been initialized? */ + + if (!g_dns_initialized) + { + sem_init(&g_dns_sem, 0, 1); + g_dns_initialized = true; + } + +#ifndef CONFIG_NETDB_RESOLVCONF + /* Has the DNS server IP address been assigned? */ + + if (!g_dns_address) + { +#if defined(CONFIG_NETDB_DNSSERVER_IPv4) + struct sockaddr_in addr4; + int ret; + + /* No, configure the default IPv4 DNS server address */ + + addr4.sin_family = AF_INET; + addr4.sin_port = HTONS(DNS_DEFAULT_PORT); + addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR); + + ret = dns_add_nameserver((FAR struct sockaddr *)&addr4, + sizeof(struct sockaddr_in)); + if (ret < 0) + { + return false; + } + +#elif defined(CONFIG_NETDB_DNSSERVER_IPv6) + struct sockaddr_in6 addr6; + int ret; + + /* No, configure the default IPv6 DNS server address */ + + addr6.sin6_family = AF_INET6; + addr6.sin6_port = HTONS(DNS_DEFAULT_PORT); + memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16); + + ret = dns_add_nameserver((FAR struct sockaddr *)&addr6, + sizeof(struct sockaddr_in6)); + if (ret < 0) + { + return false; + } + +#else + /* Then we are not ready to perform DNS queries */ + + return false; +#endif + } +#endif /* !CONFIG_NETDB_RESOLVCONF */ + + return true; +} + +/**************************************************************************** + * Name: dns_semtake + * + * Description: + * Take the DNS semaphore, ignoring errors do to the receipt of signals. + * + ****************************************************************************/ + +void dns_semtake(void) +{ + int errcode = 0; + int ret; + + do + { + ret = sem_wait(&g_dns_sem); + if (ret < 0) + { + errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + } + } + while (ret < 0 && errcode == EINTR); +} + +/**************************************************************************** + * Name: dns_semgive + * + * Description: + * Release the DNS semaphore + * + ****************************************************************************/ + +void dns_semgive(void) +{ + DEBUGVERIFY(sem_post(&g_dns_sem)); +} -- GitLab From 9097425203c55f0abea9a24dd0ef89f7b4e5d5a6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 10:30:47 -0600 Subject: [PATCH 542/858] netdb: Separate lib_dnsclient.c into lib_dnsbind.c and lib_dnsquery.c --- libc/netdb/Make.defs | 3 +- .../netdb/{lib_dnsclient.c => lib_dnsquery.c} | 65 ------------------- 2 files changed, 2 insertions(+), 66 deletions(-) rename libc/netdb/{lib_dnsclient.c => lib_dnsquery.c} (91%) diff --git a/libc/netdb/Make.defs b/libc/netdb/Make.defs index 758534c09e..68b87a288f 100644 --- a/libc/netdb/Make.defs +++ b/libc/netdb/Make.defs @@ -48,7 +48,8 @@ endif # Add DNS lookup support ifeq ($(CONFIG_NETDB_DNSCLIENT),y) -CSRCS += lib_dnsinit.c lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c +CSRCS += lib_dnsinit.c lib_dnsbind.c lib_dnsquery.c lib_dnsaddserver.c +CSRCS += lib_dnsforeach.c ifneq ($(CONFIG_NETDB_DNSCLIENT_ENTRIES),0) CSRCS += lib_dnscache.c diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsquery.c similarity index 91% rename from libc/netdb/lib_dnsclient.c rename to libc/netdb/lib_dnsquery.c index ba56279eb8..21e0c14f05 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsquery.c @@ -46,19 +46,12 @@ #include -#include -#include #include #include #include #include -#if 0 -#include - -#endif - #include #include "netdb/lib_dns.h" @@ -409,64 +402,6 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: dns_bind - * - * Description: - * Initialize the DNS resolver and return a socket bound to the DNS name - * server. The name server was previously selected via dns_server(). - * - * Input Parameters: - * None - * - * Returned Value: - * On success, the bound, non-negative socket descriptor is returned. A - * negated errno value is returned on any failure. - * - ****************************************************************************/ - -int dns_bind(void) -{ - struct timeval tv; - int errcode; - int sd; - int ret; - - /* Has the DNS client been properly initialized? */ - - if (!dns_initialize()) - { - ndbg("ERROR: DNS client has not been initialized\n"); - return -EDESTADDRREQ; - } - - /* Create a new socket */ - - sd = socket(PF_INET, SOCK_DGRAM, 0); - if (sd < 0) - { - errcode = get_errno(); - ndbg("ERROR: socket() failed: %d\n", errcode); - return -errcode; - } - - /* Set up a receive timeout */ - - tv.tv_sec = 30; - tv.tv_usec = 0; - - ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); - if (ret < 0) - { - errcode = get_errno(); - ndbg("ERROR: setsockopt() failed: %d\n", errcode); - close(sd); - return -errcode; - } - - return sd; -} - /**************************************************************************** * Name: dns_query * -- GitLab From 1a8531c95198b70cd484fc8b31f4897dca1d1ef8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 14:18:19 -0600 Subject: [PATCH 543/858] netdb: Extend dns_query so that it can handle multiple nameserver addresses --- libc/netdb/lib_dnsquery.c | 261 +++++++++++++++++++++++++++----------- 1 file changed, 187 insertions(+), 74 deletions(-) diff --git a/libc/netdb/lib_dnsquery.c b/libc/netdb/lib_dnsquery.c index 21e0c14f05..5b1861e88b 100644 --- a/libc/netdb/lib_dnsquery.c +++ b/libc/netdb/lib_dnsquery.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/netdb/lib_dnsclient.c + * libc/netdb/lib_dnsquery.c * DNS host name to IP address resolver. * * The uIP DNS resolver functions are used to lookup a hostname and @@ -73,6 +73,15 @@ * Private Types ****************************************************************************/ +struct dns_query_s +{ + int sd; /* DNS server socket */ + int result; /* Explanation of the failure */ + FAR const char *hostname; /* Hostname to lookup */ + FAR struct sockaddr *addr; /* Location to return host address */ + FAR socklen_t *addrlen; /* Length of the address */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -399,37 +408,28 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, } /**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dns_query + * Name: dns_query_callback * * Description: - * Using the DNS resolver socket (sd), look up the the 'hostname', and - * return its IP address in 'ipaddr' + * Using the DNS information and this DNS server address, look up the the + * hostname. * * Input Parameters: - * sd - The socket descriptor previously initialized by dsn_bind(). - * hostname - The hostname string to be resolved. - * addr - The location to return the IP address associated with the - * hostname - * addrlen - On entry, the size of the buffer backing up the 'addr' - * pointer. On return, this location will hold the actual size of - * the returned address. + * arg - Query arguements + * addr - DNS name server address + * addrlen - Length of the DNS name server address. * * Returned Value: - * Returns zero (OK) if the query was successful. + * Returns one (1) if the query was successful. Zero is returned in all + * other cases. The result field of the query structure is set to a + * negated errno value indicate the reason for the last failure (only). * ****************************************************************************/ -int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, - FAR socklen_t *addrlen) +static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, + FAR socklen_t addrlen) { -#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - int noipv4 = false; - int noipv6 = false; -#endif + FAR struct dns_query_s *query = (FAR struct dns_query_s *)arg; int retries; int ret; @@ -438,26 +438,42 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, for (retries = 0; retries < 3; retries++) { #ifdef CONFIG_NET_IPv4 -#ifdef CONFIG_NET_IPv6 - /* If we know that the IPv4 address is not available, then don't try - * again. - */ + /* Is this an IPv4 address? */ - if (!noipv4) -#endif + if (addr->sa_family == AF_INET) { + /* Yes.. verify the address size */ + + if (addrlen < sizeof(struct sockaddr_in)) + { + /* Return zero to skip this address and try the next + * namserver address in resolv.conf. + */ + + ndbg("ERROR: Invalid IPv4 address size: %d\n", addrlen); + query->result = -EINVAL; + return 0; + } + /* Send the IPv4 query */ - ret = dns_send_query(sd, hostname, &g_dns_server, DNS_RECTYPE_A); + ret = dns_send_query(query->sd, query->hostname, + (FAR union dns_server_u *)addr, + DNS_RECTYPE_A); if (ret < 0) { + /* Return zero to skip this address and try the next + * namserver address in resolv.conf. + */ + ndbg("ERROR: IPv4 dns_send_query failed: %d\n", ret); - return ret; + query->result = ret; + return 0; } /* Obtain the IPv4 response */ - ret = dns_recv_response(sd, addr, addrlen); + ret = dns_recv_response(query->sd, query->addr, query->addrlen); if (ret >= 0) { /* IPv4 response received successfully */ @@ -465,61 +481,80 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 /* Save the answer in the DNS cache */ - dns_save_answer(hostname, addr, *addrlen); + dns_save_answer(query->hostname, query->addr, *query->addrlen); #endif - return OK; + /* Return 1 to indicate to (1) stop the traversal, and (2) + * indicate that the address was found. + */ + + return 1; } /* Handle errors */ ndbg("ERROR: IPv4 dns_recv_response failed: %d\n", ret); -#ifdef CONFIG_NET_IPv6 if (ret != -EADDRNOTAVAIL) { - /* The IPv4 address is not available. */ + /* The IPv4 address is not available. Return zero to + * continue the tranversal with the next nameserver + * address in resolv.conf. + */ - noipv4 = true; - if (noipv6) - { - /* Neither address is available */ - - return ret; - } + query->result = -EADDRNOTAVAIL; + return 0; } - else -#endif - if (ret != -EAGAIN) + else if (ret != -EAGAIN) { - /* Some failure other than receive timeout occurred */ + /* Some failure other than receive timeout occurred. Return + * zero to skip this address and try the next namserver + * address in resolv.conf. + */ - return ret; + query->result = ret; + return 0; } } -#endif + else +#endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 -#ifdef CONFIG_NET_IPv4 - /* If we know that the IPv4 address is not available, then don't try - * again. - */ + /* Is this an IPv4 address? */ - if (!noipv6) -#endif + if (query->addr.sa_family == AF_INET6) { + /* Yes.. verify the address size */ + + if (addrlen < sizeof(struct sockaddr_in6)) + { + /* Return zero to skip this address and try the next + * namserver address in resolv.conf. + */ + + ndbg("ERROR: Invalid IPv6 address size: %d\n", addrlen); + query->result = -EINVAL; + return 0; + } + /* Send the IPv6 query */ - ret = dns_send_query(sd, hostname, &g_dns_server, + ret = dns_send_query(query->sd, query->hostname, + (FAR union dns_server_u *)addr, DNS_RECTYPE_AAAA); if (ret < 0) { + /* Return zero to skip this address and try the next + * namserver address in resolv.conf. + */ + ndbg("ERROR: IPv6 dns_send_query failed: %d\n", ret); - return ret; + query->result = ret; + return 0; } /* Obtain the IPv6 response */ - ret = dns_recv_response(sd, addr, addrlen); + ret = dns_recv_response(query->sd, query->addr, query->addrlen); if (ret >= 0) { /* IPv6 response received successfully */ @@ -527,39 +562,117 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 /* Save the answer in the DNS cache */ - dns_save_answer(hostname, addr, *addrlen); + dns_save_answer(query->hostname, query->addr, *query->addrlen); #endif - return OK; + /* Return 1 to indicate to (1) stop the traversal, and (2) + * indicate that the address was found. + */ + + return 1; } /* Handle errors */ ndbg("ERROR: IPv6 dns_recv_response failed: %d\n", ret); -#ifdef CONFIG_NET_IPv4 if (ret != -EADDRNOTAVAIL) { - /* The IPv6 address is not available. */ - - noipv6 = true; - if (noipv4) - { - /* Neither address is available */ + /* The IPv6 address is not available. Return zero to + * continue the tranversal with the next nameserver + * address in resolv.conf. + */ - return ret; - } + query->result = -EADDRNOTAVAIL; + return 0; } - else -#endif - if (ret != -EAGAIN) + else if (ret != -EAGAIN) { - /* Some failure other than receive timeout occurred */ + /* Some failure other than receive timeout occurred. Return + * zero to skip this address and try the next namserver + * address in resolv.conf. + */ - return ret; + query->result = ret; + return 0; } } + else #endif + { + /* Unsupported address family. Return zero to continue the + * tranversal with the next nameserver address in resolv.conf. + */ + + return 0; + } + } + + /* We tried three times and could not communicate with this nameserver. + * Perhaps it is down? Return zero to continue with the next address + * in the resolv.conf file. + */ + + query->result = -ETIMEDOUT; + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_query + * + * Description: + * Using the DNS resolver socket (sd), look up the the 'hostname', and + * return its IP address in 'ipaddr' + * + * Input Parameters: + * sd - The socket descriptor previously initialized by dsn_bind(). + * hostname - The hostname string to be resolved. + * addr - The location to return the IP address associated with the + * hostname + * addrlen - On entry, the size of the buffer backing up the 'addr' + * pointer. On return, this location will hold the actual size of + * the returned address. + * + * Returned Value: + * Returns zero (OK) if the query was successful. + * + ****************************************************************************/ + +int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, + FAR socklen_t *addrlen) +{ + FAR struct dns_query_s query; + int ret; + + /* Set up the query info structure */ + + query.sd = sd; + query.result = OK; + query.hostname = hostname; + query.addr = addr; + query.addrlen = addrlen; + + /* Perform the query. dns_foreach_nameserver() will return: + * + * 1 - The query was successful. + * 0 - Look up failed + * <0 - Some other failure (?, shouldn't happen) + */ + + ret = dns_foreach_nameserver(dns_query_callback, &query); + if (ret > 0) + { + /* The lookup was successful */ + + ret = OK; + } + else if (ret == 0) + { + ret = query.result; } - return -ETIMEDOUT; + return ret; } -- GitLab From 300d34f029a2dafe4f82d64d1ce992094061e660 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 15:12:42 -0600 Subject: [PATCH 544/858] netdb: resolv.conf logic is functional --- ChangeLog | 2 + libc/Kconfig | 32 +++++----- libc/netdb/lib_dnsbind.c | 123 ++++++++++++++++++++++++++++++++++++ libc/netdb/lib_dnsforeach.c | 18 ++++-- libc/netdb/lib_dnsinit.c | 2 + libc/netdb/lib_dnsquery.c | 2 +- 6 files changed, 158 insertions(+), 21 deletions(-) create mode 100644 libc/netdb/lib_dnsbind.c diff --git a/ChangeLog b/ChangeLog index d507b51894..82532d0571 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11303,3 +11303,5 @@ * tools/mkdeps.c: Extended/fixed support for --winpath option. Dependencies now work under Cygwin with a native Windows toolchain (2016-01-10). + * libc/netdb: Add support for the use of a DNS resolver file like + /etc/resolv.conf (2016-01-14). diff --git a/libc/Kconfig b/libc/Kconfig index a9246777b9..3f8e88b017 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -592,9 +592,26 @@ config NETDB_DNSCLIENT_MAXRESPONSE can be received by the DNS resolver. The default is 96 but may need to be larger on enterprise networks (perhaps 176). + +config NETDB_RESOLVCONF + bool "DNS resolver file support" + default n + depends on FS_READABLE + ---help--- + Enable DNS server look ups in resolver file like /etc/resolv.conf. + +if NETDB_RESOLVCONF + +config NETDB_RESOLVCONF_PATH + string "Path to host configuration file" + default "/etc/resolv.conf" + +endif # NETDB_RESOLVCONF + choice prompt "DNS server address type" default NETDB_DNSSERVER_NOADDR + depends on !NETDB_RESOLVCONF config NETDB_DNSSERVER_NOADDR bool "No default DNS server address" @@ -700,21 +717,6 @@ config NETDB_DNSSERVER_IPv6ADDR_8 of the 8-values. The default for all eight values is fc00::1. endif # NETDB_DNSSERVER_IPv6 - -config NETDB_RESOLVCONF - bool "DNS server file support" - default n - depends on FS_READABLE - ---help--- - Enable DNS server look ups in resolver file. - -if NETDB_RESOLVCONF - -config NETDB_RESOLVCONF_PATH - string "Path to host configuration file" - default "/etc/resolv.conf" - -endif # NETDB_RESOLVCONF endif # NETDB_DNSCLIENT comment "Non-standard Library Support" diff --git a/libc/netdb/lib_dnsbind.c b/libc/netdb/lib_dnsbind.c new file mode 100644 index 0000000000..c7eae42953 --- /dev/null +++ b/libc/netdb/lib_dnsbind.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * libc/netdb/lib_dnsclien.c + * + * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "netdb/lib_dns.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if CONFIG_NSOCKET_DESCRIPTORS < 1 +# error CONFIG_NSOCKET_DESCRIPTORS must be greater than zero +#endif + +#if CONFIG_NET_SOCKOPTS < 1 +# error CONFIG_NET_SOCKOPTS required by this logic +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dns_bind + * + * Description: + * Initialize the DNS resolver and return a socket bound to the DNS name + * server. The name server was previously selected via dns_server(). + * + * Input Parameters: + * None + * + * Returned Value: + * On success, the bound, non-negative socket descriptor is returned. A + * negated errno value is returned on any failure. + * + ****************************************************************************/ + +int dns_bind(void) +{ + struct timeval tv; + int errcode; + int sd; + int ret; + + /* Has the DNS client been properly initialized? */ + + if (!dns_initialize()) + { + ndbg("ERROR: DNS client has not been initialized\n"); + return -EDESTADDRREQ; + } + + /* Create a new socket */ + + sd = socket(PF_INET, SOCK_DGRAM, 0); + if (sd < 0) + { + errcode = get_errno(); + ndbg("ERROR: socket() failed: %d\n", errcode); + return -errcode; + } + + /* Set up a receive timeout */ + + tv.tv_sec = 30; + tv.tv_usec = 0; + + ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); + if (ret < 0) + { + errcode = get_errno(); + ndbg("ERROR: setsockopt() failed: %d\n", errcode); + close(sd); + return -errcode; + } + + return sd; +} diff --git a/libc/netdb/lib_dnsforeach.c b/libc/netdb/lib_dnsforeach.c index 27ceed99d7..63ae1024e2 100644 --- a/libc/netdb/lib_dnsforeach.c +++ b/libc/netdb/lib_dnsforeach.c @@ -92,6 +92,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) union dns_server_u u; FAR FILE *stream; char line[DNS_MAX_LINE]; + FAR char *addrstr; FAR char *ptr; int keylen; int ret; @@ -117,14 +118,21 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* Skip over the 'nameserver' keyword */ ptr = find_spaces(ptr); - ptr = skip_spaces(ptr); - if (*ptr == '\0') + addrstr = skip_spaces(ptr); + if (*addrstr == '\0') { ndbg("ERROR: Missing address in %s record\n", CONFIG_NETDB_RESOLVCONF_PATH); continue; } + /* Make sure that the address string is NUL terminated and + * not followed by garbage. + */ + + ptr = find_spaces(addrstr); + *ptr = '\0'; + /* Convert the address string to a binary representation */ /* REVISIT: We really need a customizable port number. The * OpenBSD version supports a [host]:port syntax. When a @@ -138,7 +146,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) #ifdef CONFIG_NET_IPv4 /* Try to convert the IPv4 address */ - ret = inet_pton(AF_INET, ptr, &u.ipv4.sin_addr); + ret = inet_pton(AF_INET, addrstr, &u.ipv4.sin_addr); /* The inet_pton() function returns 1 if the conversion succeeds */ @@ -157,7 +165,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { /* Try to convert the IPv6 address */ - ret = inet_pton(AF_INET6, ptr, &u.ipv6.sin6_addr); + ret = inet_pton(AF_INET6, addrstr, &u.ipv6.sin6_addr); /* The inet_pton() function returns 1 if the conversion * succeeds. @@ -175,7 +183,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) else #endif { - ndbg("ERROR: Unrecognized address: %s\n", ptr) + ndbg("ERROR: Unrecognized address: %s\n", addrstr) ret = OK; } #ifdef CONFIG_NET_IPv6 diff --git a/libc/netdb/lib_dnsinit.c b/libc/netdb/lib_dnsinit.c index ddb138d896..04b490a167 100644 --- a/libc/netdb/lib_dnsinit.c +++ b/libc/netdb/lib_dnsinit.c @@ -43,6 +43,8 @@ #include #include +#include + #include "netdb/lib_dns.h" /**************************************************************************** diff --git a/libc/netdb/lib_dnsquery.c b/libc/netdb/lib_dnsquery.c index 5b1861e88b..283b3ae8fe 100644 --- a/libc/netdb/lib_dnsquery.c +++ b/libc/netdb/lib_dnsquery.c @@ -650,7 +650,7 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, /* Set up the query info structure */ query.sd = sd; - query.result = OK; + query.result = -EADDRNOTAVAIL; query.hostname = hostname; query.addr = addr; query.addrlen = addrlen; -- GitLab From fd91b4dd8592f004727ecaf6cff24442373f1fe8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 15:20:30 -0600 Subject: [PATCH 545/858] Fix minor typo in ChangeLog --- ChangeLog | 2 +- arch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82532d0571..6dd11f68a3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11295,7 +11295,7 @@ * tools/cnvwindeps.c: Add a tool that will convert paths in dependencies generated by a Windows compiler so that they can be used with the Cygwin make (2016-01-09). - * tools/mkwindeps.sh: A script that coordinates us ov cnvwindeps.exe + * tools/mkwindeps.sh: A script that coordinates use of cnvwindeps.exe (2016-01-09). * tools/mkdeps.c: Deleted mkdeps.sh and mkdeps.bat. The mkdeps executable generated from mkdeps.c is now that the only supported diff --git a/arch b/arch index ad4ca80846..90edeff649 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ad4ca8084676b719edc4b16ad24f37d2b1aec7b1 +Subproject commit 90edeff649c771af511ab88aee3f800ae794a64f -- GitLab From aa691e6d08c0524be9af0401f0724706e10cd8a5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 16:28:43 -0600 Subject: [PATCH 546/858] tools/Makefile.host: clean target was not removing cnvwindeps program --- tools/Makefile.host | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/Makefile.host b/tools/Makefile.host index fa165f5e08..c408a0a4e7 100644 --- a/tools/Makefile.host +++ b/tools/Makefile.host @@ -71,10 +71,12 @@ all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \ configure$(HOSTEXEEXT) mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \ mksymtab$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT) \ cnvwindeps$(HOSTEXEEXT) nxstyle$(HOSTEXEEXT) -default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) +default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \ + cnvwindeps$(HOSTEXEEXT) ifdef HOSTEXEEXT -.PHONY: b16 bdf-converter cmpconfig clean configure mkconfig mkdeps mksymtab mksyscall mkversion +.PHONY: b16 bdf-converter cmpconfig clean configure mkconfig mkdeps \ + cnvwindeps mksymtab mksyscall mkversion else .PHONY: clean endif @@ -191,6 +193,8 @@ endif clean: $(call DELFILE, mkdeps) $(call DELFILE, mkdeps.exe) + $(call DELFILE, cnvwindeps) + $(call DELFILE, cnvwindeps.exe) $(call DELFILE, mkconfig) $(call DELFILE, mkconfig.exe) $(call DELFILE, Make.dep) -- GitLab From 8a3033643eb0056167c0ecbedfe061b80504546a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 16:38:47 -0600 Subject: [PATCH 547/858] Add cnvwindeps to .gitignore --- tools/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/.gitignore b/tools/.gitignore index 6a55708068..5579d406f4 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -4,6 +4,7 @@ /configure /mkconfig /mkdeps +/cnvwindeps /mksymtab /mksyscall /mkversion -- GitLab From 2a5c7e9a924b93fb46b38b04d4d324fe378c9a25 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Jan 2016 17:55:53 -0600 Subject: [PATCH 548/858] resolv.conf: Add support for OpenBSD style resolv.conf syntax where a non-standard DNS server port can be specified using a backet syntax. --- configs | 2 +- libc/Kconfig | 33 +++++++++++++++++++- libc/netdb/lib_dns.h | 3 +- libc/netdb/lib_dnsaddserver.c | 49 +++++++++++++++++++++++++---- libc/netdb/lib_dnsforeach.c | 59 +++++++++++++++++++++++++++++------ 5 files changed, 128 insertions(+), 18 deletions(-) diff --git a/configs b/configs index 5eb7ce1631..a4a4be4004 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 5eb7ce16316971813ced45e4869167ec55a72b45 +Subproject commit a4a4be4004173c67c8ed160cc48fcea1cf57308a diff --git a/libc/Kconfig b/libc/Kconfig index 3f8e88b017..54df4e2ede 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -606,23 +606,54 @@ config NETDB_RESOLVCONF_PATH string "Path to host configuration file" default "/etc/resolv.conf" +config NETDB_RESOLVCONF_NONSTDPORT + bool "Non-standard port support" + default n + ---help--- + By default, the resolv.conf file will hold only records like: + + nameserver xx.xx.xx.xx + nameserver xxxx:::::::xxxx + + The default port of 53 is always assumed. + + If this option is selected, then OpenBSD style resolv.conf files + will be supported. This adds logic for a bracket port notation + like: + + nameserver [xx.xx.xx.xx]:ppppp + nameserver [xxxx:::::::xxxx]:ppppp + endif # NETDB_RESOLVCONF choice prompt "DNS server address type" - default NETDB_DNSSERVER_NOADDR + default NETDB_DNSSERVER_IPv4 if NET_IPv4 + default NETDB_DNSSERVER_IPv6 if !NET_IPv4 && NET_IPv6 + default NETDB_DNSSERVER_NOADDR if !NET_IPv4 && !NET_IPv6 depends on !NETDB_RESOLVCONF config NETDB_DNSSERVER_NOADDR bool "No default DNS server address" + ---help--- + There is not default DNS nameserver address. Application must call + dns_add_server() at runtime to add the DNS server address. config NETDB_DNSSERVER_IPv4 bool "IPv4 DNS server address" depends on NET_IPv4 + ---help--- + An IPv4 default DNS nameserver address will be provided. Application + may overwrite this start default server address by calling + dns_add_server() at runtime. config NETDB_DNSSERVER_IPv6 bool "IPv6 DNS server address" depends on NET_IPv6 + ---help--- + An IPv6 default DNS nameserver address will be provided. Application + may overwrite this start default server address by calling + dns_add_server() at runtime. endchoice # DNS server address type diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index 86287dc226..9a6f25b7e6 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -80,7 +80,8 @@ # define CONFIG_NETDB_RESOLVCONF_PATH "/etc/resolv.conf" #endif -#define DNS_MAX_LINE 80 +#define DNS_MAX_ADDRSTR 48 +#define DNS_MAX_LINE 64 #define NETDB_DNS_KEYWORD "nameserver" /**************************************************************************** diff --git a/libc/netdb/lib_dnsaddserver.c b/libc/netdb/lib_dnsaddserver.c index dfeff175c2..ff2436985a 100644 --- a/libc/netdb/lib_dnsaddserver.c +++ b/libc/netdb/lib_dnsaddserver.c @@ -80,7 +80,11 @@ bool g_dns_address; /* true: We have the address of the DNS server */ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) { FAR FILE *stream; - char line[DNS_MAX_LINE]; + char addrstr[DNS_MAX_ADDRSTR]; +#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT + uint16_t port; +#endif + int status; int ret; stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "at"); @@ -107,20 +111,26 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) { FAR struct sockaddr_in *in4 = (FAR struct sockaddr_in *)addr; - if (inet_ntop(AF_INET, &in4->sin_addr, line, DNS_MAX_LINE) == NULL) + if (inet_ntop(AF_INET, &in4->sin_addr, addrstr, DNS_MAX_ADDRSTR) == NULL) { ret = -errno; ndbg("ERROR: inet_ntop failed: %d\n", errcode); DEBUGASSERT(errcode < 0); goto errout; } + +#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT + /* Get the port number */ + + port = ntohs(in4->sin_port); +#endif } } else #endif #ifdef CONFIG_NET_IPv6 - /* Check for an IPv4 address */ + /* Check for an IPv6 address */ if (addr->sa_family == AF_INET6) { @@ -133,13 +143,19 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) { FAR struct sockaddr_in6 *in6 = (FAR struct sockaddr_in6 *)addr; - if (inet_ntop(AF_INET6, &in6->sin6_addr, line, DNS_MAX_LINE) == NULL) + if (inet_ntop(AF_INET6, &in6->sin6_addr, addrstr, DNS_MAX_ADDRSTR) == NULL) { ret = -errno; ndbg("ERROR: inet_ntop failed: %d\n", errcode); DEBUGASSERT(errcode < 0); goto errout; } + +#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT + /* Get the port number */ + + port = ntohs(in6->sin6_port); +#endif } } else @@ -151,9 +167,30 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) goto errout; } - /* Write the new record to the end of the resolv.conf file */ + /* Write the new record to the end of the resolv.conf file. */ + +#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT + /* The OpenBSD version supports a [host]:port syntax. When a non-standard + * port is specified the host address must be enclosed in square brackets. + * For example: + * + * nameserver [10.0.0.1]:5353 + * nameserver [::1]:5353 + */ + + if (port != 0 && port != DNS_DEFAULT_PORT) + { + status = fprintf(stream, "%s [%s]:%u\n", + NETDB_DNS_KEYWORD, addrstr, port); + } + else +#endif + { + status = fprintf(stream, "%s %s\n", + NETDB_DNS_KEYWORD, addrstr); + } - if (fprintf(stream, "%s %s\n", NETDB_DNS_KEYWORD, line) < 0) + if (status < 0) { ret = -errno; ndbg("ERROR: fprintf failed: %d\n", errcode); diff --git a/libc/netdb/lib_dnsforeach.c b/libc/netdb/lib_dnsforeach.c index 63ae1024e2..761cc441f3 100644 --- a/libc/netdb/lib_dnsforeach.c +++ b/libc/netdb/lib_dnsforeach.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) char line[DNS_MAX_LINE]; FAR char *addrstr; FAR char *ptr; + uint16_t port; int keylen; int ret; @@ -133,9 +135,12 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) ptr = find_spaces(addrstr); *ptr = '\0'; - /* Convert the address string to a binary representation */ - /* REVISIT: We really need a customizable port number. The - * OpenBSD version supports a [host]:port syntax. When a + /* Convert the address string to a binary representation. */ + + port = HTONS(DNS_DEFAULT_PORT); + +#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT + /* The OpenBSD version supports a [host]:port syntax. When a * non-standard port is specified the host address must be * enclosed in square brackets. For example: * @@ -143,6 +148,46 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) * nameserver [::1]:5353 */ + if (*addrstr == '[') + { + /* Make sure that ther is a right bracket */ + + ptr = strchr(addrstr, ']'); + if (ptr == NULL) + { + ndbg("ERROR: Missing right bracket after %s\n", line); + continue; + } + + /* Replace the right bracket with a NULL terminator */ + + addrstr++; + *ptr++ = '\0'; + + /* Get the port number following the right bracket */ + + if (*ptr == ':') + { + FAR char *portstr; + int tmp; + + /* Isolate the port string */ + + portstr = ptr; + ptr = find_spaces(addrstr); + *ptr = '\0'; + + /* Get the port number */ + + tmp = atoi(portstr); + if (tmp != 0) + { + port = htons(tmp); + } + } + } +#endif /* CONFIG_NETDB_RESOLVCONF_NONSTDPORT */ + #ifdef CONFIG_NET_IPv4 /* Try to convert the IPv4 address */ @@ -152,10 +197,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) if (ret == 1) { - /* REVISIT: We really need a customizable port number */ - u.ipv4.sin_family = AF_INET; - u.ipv4.sin_port = HTONS(DNS_DEFAULT_PORT); + u.ipv4.sin_port = port; ret = callback(arg, (FAR struct sockaddr *)&u.ipv4, sizeof(struct sockaddr_in)); } @@ -173,10 +216,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) if (ret == 1) { - /* REVISIT: We really need a customizable port number */ - u.ipv6.sin6_family = AF_INET6; - u.ipv6.sin6_port = HTONS(DNS_DEFAULT_PORT); + u.ipv6.sin6_port = port; ret = callback(arg, (FAR struct sockaddr *)&u.ipv6, sizeof(struct sockaddr_in6)); } -- GitLab From 75d6c4cee3297d99d4622f870609ef136e58b86a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Fri, 15 Jan 2016 07:25:58 -0600 Subject: [PATCH 549/858] drivers/sensors/mcp9844: Driver for the MCP9844 I2C digital temperature sensor with a selectable resolution --- ChangeLog | 3 + drivers/sensors/Kconfig | 7 + drivers/sensors/Make.defs | 4 + drivers/sensors/mcp9844.c | 352 ++++++++++++++++++++++++++++++++ include/nuttx/sensors/mcp9844.h | 128 ++++++++++++ 5 files changed, 494 insertions(+) create mode 100644 drivers/sensors/mcp9844.c create mode 100644 include/nuttx/sensors/mcp9844.h diff --git a/ChangeLog b/ChangeLog index 6dd11f68a3..1e9bbb3986 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11305,3 +11305,6 @@ (2016-01-10). * libc/netdb: Add support for the use of a DNS resolver file like /etc/resolv.conf (2016-01-14). + * drivers/sensors/mcp9844.c and include/nuttx/sensors/mcp9844.h: Driver + for the MCP9844 I2C digital temperature sensor with a selectable + resolution. From Entinger Alexander (2016-01-15). diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 80cdfcec0c..993cc41254 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -31,6 +31,13 @@ config MB7040 ---help--- Enable driver support for the MaxBotix MB7040 sonar. +config MCP9844 + bool "MCP9844 Temperature Sensor" + default n + select I2C + ---help--- + Enable driver support for the MCP9844 I2C Temperature sensor. + config MS58XX bool "MEAS MS58XX Altimeter support" default n diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index a1c5c69a54..e4d38ca075 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -73,6 +73,10 @@ ifeq ($(CONFIG_MB7040),y) CSRCS += mb7040.c endif +ifeq ($(CONFIG_MCP9844),y) + CSRCS += mcp9844.c +endif + ifeq ($(CONFIG_MS58XX),y) CSRCS += ms58xx.c endif diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c new file mode 100644 index 0000000000..68a5091ce3 --- /dev/null +++ b/drivers/sensors/mcp9844.c @@ -0,0 +1,352 @@ +/**************************************************************************** + * drivers/sensors/mcp9844.c + * Character driver for the MCP9844 Temperature Sensor + * + * Copyright (C) 2015 DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MCP9844) + +/**************************************************************************** + * Private + ****************************************************************************/ + +struct mcp9844_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* I2C helper functions */ + +static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, + uint8_t const regaddr, FAR uint16_t *value); +static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, + uint8_t const regaddr, uint16_t const regval); + +/* Character driver methods */ + +static int mcp9844_open(FAR struct file *filep); +static int mcp9844_close(FAR struct file *filep); +static ssize_t mcp9844_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t mcp9844_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int mcp9844_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_mcp9844_fops = +{ + mcp9844_open, + mcp9844_close, + mcp9844_read, + mcp9844_write, + NULL, + mcp9844_ioctl +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mcp9844_read_u16 + * + * Description: + * Read a 16 bit valie from the MCP9844 at the address regaddr. + * + ****************************************************************************/ + +static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, + uint8_t const regaddr, FAR uint16_t *value) +{ + int ret = -1; + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + + ret = I2C_WRITE(priv->i2c, ®addr, 1); + if (ret < 0) + { + sndbg ("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 16-bits from the register */ + + uint8_t const BUFFER_SIZE = 2; + uint8_t buffer[BUFFER_SIZE]; + ret = I2C_READ(priv->i2c, buffer, BUFFER_SIZE); + if (ret < 0) + { + sndbg ("I2C_READ failed: %d\n", ret); + return ret; + } + + /* Copy the content of the buffer to the location of the uint16_t pointer */ + + *value = (((uint16_t)(buffer[0]))<<8) + ((uint16_t)(buffer[1])); + + sndbg("addr: %02x value: %08x ret: %d\n", regaddr, *value, ret); + + return OK; +} + +/**************************************************************************** + * Name: mcp9844_write_u16 + * + * Description: + * Write to a 16-bit register of the MCP9844. + * + ****************************************************************************/ + +static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, + uint8_t const regaddr, uint16_t const regval) +{ + sndbg("addr: %02x value: %08x\n", regaddr, regval); + + /* Set up a 3 byte message to send */ + + uint8_t const BUFFER_SIZE = 3; + uint8_t buffer[BUFFER_SIZE]; + + buffer[0] = regaddr; + buffer[1] = (uint8_t)(regval >> 8); + buffer[2] = (uint8_t)(regval); + + /* Write the register address followed by the data (no RESTART) */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + + return I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE); +} + +/**************************************************************************** + * Name: mcp9844_open + * + * Description: + * This function is called whenever the MCP9844 device is opened. + * + ****************************************************************************/ + +static int mcp9844_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: mcp9844_close + * + * Description: + * This routine is called when the MCP9844 device is closed. + * + ****************************************************************************/ + +static int mcp9844_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: mcp9844_read + ****************************************************************************/ + +static ssize_t mcp9844_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: mcp9844_write + ****************************************************************************/ + +static ssize_t mcp9844_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: lm75_ioctl + ****************************************************************************/ + +static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct mcp9844_dev_s *priv = inode->i_private; + int ret = OK; + + switch (cmd) + { + /* Read from the ambient temperature register. Arg: uint16_t* pointer */ + + case SNIOC_READTEMP: + { + FAR struct mcp9844_temp_arg_s *temp_result = + (FAR struct mcp9844_temp_arg_s *)((uintptr_t)arg); + + DEBUGASSERT(temp_result != NULL); + + /* Read the ambient temperature value from the device */ + + uint16_t raw_temperature = 0; + ret = mcp9844_read_u16(priv, MCP9844_TEMP_REG, &raw_temperature); + + /* Convert from the proprietary sensor temperature data representation + * to a more user friendly version. + */ + + if (ret == OK) + { + /* BIT15 - 13 contain information if preset temperature values + * have been exceeded or undercut. BIT12 is now not any longer + * needed since we do have the sign information retrieved. + * We do not need them for the temperature so those bits + * need to be masked out. + */ + + raw_temperature &= 0x0FFF; /* 0x0FFF = 0b 0000 1111 1111 1111 */ + + /* The post comma temperature value is encoded in BIT3 to BIT0 */ + + temp_result->temp_post_comma = (uint8_t)(raw_temperature & 0x000F); + + /* The pre comma temperature value is encoded in BIT11 to BIT4 */ + + temp_result->temp_pre_comma = (int8_t)(raw_temperature >> 4); + } + else + { + sndbg("ioctl::SNIOC_READTEMP - mcp9844_read_u16 failed - no temperature retrieved\n"); + } + } + break; + + case SNIOC_SETRESOLUTION: + { + ret = mcp9844_write_u16(priv, MCP9844_RESO_REG, (uint16_t)(arg)); + if (ret != OK) + { + sndbg("ioctl::SNIOC_SETRESOLUTION - mcp9844_write_u16 failed - no resolution set\n"); + } + } + break; + + default: + sndbg("Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mcp9844_register + * + * Description: + * Register the MCP9844 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * i2c - An instance of the I2C interface to use to communicate with MCP9844 + * addr - The I2C address of the MCP9844. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int mcp9844_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr) +{ + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + + /* Initialize the LM-75 device structure */ + + FAR struct mcp9844_dev_s *priv = + (FAR struct mcp9844_dev_s *)kmm_malloc(sizeof(struct mcp9844_dev_s)); + + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + + /* Register the character driver */ + + int ret = register_driver(devpath, &g_mcp9844_fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + return ret; +} +#endif /* CONFIG_I2C && CONFIG_I2C_LM75 */ diff --git a/include/nuttx/sensors/mcp9844.h b/include/nuttx/sensors/mcp9844.h new file mode 100644 index 0000000000..68276b8487 --- /dev/null +++ b/include/nuttx/sensors/mcp9844.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * include/nuttx/sensors/mcp9844.h + * + * Copyright (C) 2016, DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NUTTX_INCLUDE_NUTTX_SENSORS_MCP9844_H +#define __NUTTX_INCLUDE_NUTTX_SENSORS_MCP9844_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_MCP9844) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* IOCTL Commands ***********************************************************/ + +#define SNIOC_READTEMP _SNIOC(0x0001) /* Arg: mcp9844_temp_arg_s* pointer */ +#define SNIOC_SETRESOLUTION _SNIOC(0x0002) /* Arg: uint16_t value */ + +/* MCP9844 Register Definitions *********************************************/ + +/* MCP9844 Registers addresses */ + +#define MCP9844_CAPA_REG (0x00) /* Sensor Capability Register */ +#define MCP9844_CONF_REG (0x01) /* Sensor Configuration Register */ +#define MCP9844_TEMP_REG (0x05) /* Sensor Temperature Register */ +#define MCP9844_RESO_REG (0x09) /* Register to control the resolution of the temperature sensor */ + +/* Resolution Register Bit definitions */ + +#define MCP9844_RESO_REG_BIT_0 (1<<0) +#define MCP9844_RESO_REG_BIT_1 (1<<1) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct mcp9844_temp_arg_s +{ + int8_t temp_pre_comma; + uint8_t temp_post_comma; +}; + +enum mcp9844_resolution_e +{ + RES_0_5 = 0, + RES_0_25 = MCP9844_RESO_REG_BIT_0, + RES_0_125 = MCP9844_RESO_REG_BIT_1, + RES_0_0625 = MCP9844_RESO_REG_BIT_1 | MCP9844_RESO_REG_BIT_0 +}; + +struct i2c_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: mcp9844_register + * + * Description: + * Register the MCP9844 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * i2c - An instance of the I2C interface to use to communicate with MCP9844 + * addr - The I2C address of the MCP9844. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int mcp9844_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_MCP9844 */ +#endif /* __NUTTX_INCLUDE_NUTTX_SENSORS_MCP9844_H */ -- GitLab From 8138a947483739ae928140379ba705975b624698 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 15 Jan 2016 07:38:01 -0600 Subject: [PATCH 550/858] Make sure all scripts are marked as executable --- tools/configure.bat | 0 tools/define.bat | 0 tools/mkctags.sh | 0 tools/mkwindeps.sh | 0 tools/xmlrpc_test.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/configure.bat mode change 100644 => 100755 tools/define.bat mode change 100644 => 100755 tools/mkctags.sh mode change 100644 => 100755 tools/mkwindeps.sh mode change 100644 => 100755 tools/xmlrpc_test.py diff --git a/tools/configure.bat b/tools/configure.bat old mode 100644 new mode 100755 diff --git a/tools/define.bat b/tools/define.bat old mode 100644 new mode 100755 diff --git a/tools/mkctags.sh b/tools/mkctags.sh old mode 100644 new mode 100755 diff --git a/tools/mkwindeps.sh b/tools/mkwindeps.sh old mode 100644 new mode 100755 diff --git a/tools/xmlrpc_test.py b/tools/xmlrpc_test.py old mode 100644 new mode 100755 -- GitLab From ff7a9c2798709cdc3f9b30952846e119b4a8dca2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 15 Jan 2016 08:35:50 -0600 Subject: [PATCH 551/858] Trivial fix to ChangeLog --- ChangeLog | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e9bbb3986..6d6fcdf9f5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11307,4 +11307,4 @@ /etc/resolv.conf (2016-01-14). * drivers/sensors/mcp9844.c and include/nuttx/sensors/mcp9844.h: Driver for the MCP9844 I2C digital temperature sensor with a selectable - resolution. From Entinger Alexander (2016-01-15). + resolution. From Alexander Entinger (2016-01-15). diff --git a/configs b/configs index a4a4be4004..17ffdc6c4a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit a4a4be4004173c67c8ed160cc48fcea1cf57308a +Subproject commit 17ffdc6c4a1547c328e3db561dd0ba2983678b0f -- GitLab From 19810eef6b69e779d34e9790d8efe175cb144dac Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 15 Jan 2016 13:14:07 -0600 Subject: [PATCH 552/858] Update Changelog and README.txt --- ChangeLog | 4 ++++ Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d6fcdf9f5..d532de18ce 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11308,3 +11308,7 @@ * drivers/sensors/mcp9844.c and include/nuttx/sensors/mcp9844.h: Driver for the MCP9844 I2C digital temperature sensor with a selectable resolution. From Alexander Entinger (2016-01-15). + * arch/arm/src/lpc43xx: Numerous LPC43 improvements to SPIFI and ADC + from Lok Tep (2016-01-15). + * configs/lpc4337-ws: Support for the WaveShare LPC4337-WS board. From + Lok Tep (2016-01-15). diff --git a/Documentation b/Documentation index e3d982b2f1..3a2794d91b 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit e3d982b2f1c179747551a015d5a4c11132dbfe47 +Subproject commit 3a2794d91b40d09e13bf6882b12c121f75b1297b diff --git a/README.txt b/README.txt index 87fde12020..66d960a1bd 100644 --- a/README.txt +++ b/README.txt @@ -1312,6 +1312,8 @@ nuttx/ | | `- README.txt | |- lpc4330-xplorer/ | | `- README.txt + | |- lpc4337-ws/ + | | `- README.txt | |- lpc4357-evb/ | | `- README.txt | |- lpc4370-link2/ diff --git a/arch b/arch index 90edeff649..7c5481f1c4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 90edeff649c771af511ab88aee3f800ae794a64f +Subproject commit 7c5481f1c4eb9eaf30708421faa6e4f1a45bea4e diff --git a/configs b/configs index 17ffdc6c4a..06531e6baa 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 17ffdc6c4a1547c328e3db561dd0ba2983678b0f +Subproject commit 06531e6baa4f6407f027c3e2765d5aba69630d25 -- GitLab From 5da37ba164b7ef521c3d6824b6cb2eafc5e4933f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 15 Jan 2016 13:40:52 -0600 Subject: [PATCH 553/858] Fix .gitignore --- arch | 2 +- configs | 2 +- tools/.gitignore | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 7c5481f1c4..196bc24d8b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7c5481f1c4eb9eaf30708421faa6e4f1a45bea4e +Subproject commit 196bc24d8ba27ad0af0306bbbd145008399628fa diff --git a/configs b/configs index 06531e6baa..be3e062398 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 06531e6baa4f6407f027c3e2765d5aba69630d25 +Subproject commit be3e06239810d80185654a74b99dd5a7b10a26ee diff --git a/tools/.gitignore b/tools/.gitignore index 5579d406f4..d10c12aa3c 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -8,6 +8,7 @@ /mksymtab /mksyscall /mkversion +/nxstyle /*.exe /*.dSYM /.k2h-body.dat -- GitLab From c6d967e632a459aa236213ed1f724f864a3f6318 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 16 Jan 2016 09:05:39 -0600 Subject: [PATCH 554/858] OVR2640: Reverse frequency/address --- TODO | 2 ++ drivers/video/ov2640.c | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 5438686674..5a828ea901 100644 --- a/TODO +++ b/TODO @@ -1616,6 +1616,8 @@ o Other drivers (drivers/) I2C usage. - I2C_SETADDRESS used with I2C_READ, I2C_WRITE, and I2C_WRITEREAD: Similarly, address can and will be changed by other I2C usage. + NOTE also that I2C_SETADDRESS also sets the address width (either + 7 or 10 bits). - I2C_TRANSFER: This is the only interface that is properly self contained and protected from most mult-tasking issues. But even this interface can suffer if there are differing frequency settings. diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 1e736f5e07..e0fe18d21f 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -87,7 +87,8 @@ # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION #endif -#if defined(CONFIG_OV2640_QCIF_RESOLUTION) || defined(CONFIG_OV2640_JPEG_QCIF_RESOLUTION) +#if defined(CONFIG_OV2640_QCIF_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_QCIF_RESOLUTION) # define OV2460_IMAGE_WIDTH 176 # define OV2460_IMAGE_HEIGHT 144 @@ -107,7 +108,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_QVGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_QVGA_RESOLUTION) +#elif defined(CONFIG_OV2640_QVGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_QVGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 320 # define OV2460_IMAGE_HEIGHT 240 @@ -127,7 +129,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_CIF_RESOLUTION) || defined(CONFIG_OV2640_JPEG_CIF_RESOLUTION) +#elif defined(CONFIG_OV2640_CIF_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_CIF_RESOLUTION) # define OV2460_IMAGE_WIDTH 352 # define OV2460_IMAGE_HEIGHT 288 @@ -147,7 +150,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_VGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_VGA_RESOLUTION) +#elif defined(CONFIG_OV2640_VGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_VGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 640 # define OV2460_IMAGE_HEIGHT 480 @@ -167,7 +171,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_SVGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_SVGA_RESOLUTION) +#elif defined(CONFIG_OV2640_SVGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_SVGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 800 # define OV2460_IMAGE_HEIGHT 600 @@ -187,7 +192,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_XVGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_XVGA_RESOLUTION) +#elif defined(CONFIG_OV2640_XVGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_XVGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 1024 # define OV2460_IMAGE_HEIGHT 768 @@ -207,7 +213,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_SXGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_SXVGA_RESOLUTION) +#elif defined(CONFIG_OV2640_SXGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_SXVGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 1280 # define OV2460_IMAGE_HEIGHT 1024 @@ -227,7 +234,8 @@ # undef CONFIG_OV2640_UXGA_RESOLUTION # undef CONFIG_OV2640_JPEG_UXGA_RESOLUTION -#elif defined(CONFIG_OV2640_UXGA_RESOLUTION) || defined(CONFIG_OV2640_JPEG_UXGA_RESOLUTION) +#elif defined(CONFIG_OV2640_UXGA_RESOLUTION) || \ + defined(CONFIG_OV2640_JPEG_UXGA_RESOLUTION) # define OV2460_IMAGE_WIDTH 1600 # define OV2460_IMAGE_HEIGHT 1200 @@ -901,8 +909,8 @@ int ov2640_initialize(FAR struct i2c_dev_s *i2c) /* Configure I2C bus for the OV2640 */ - I2C_SETADDRESS(i2c, CONFIG_OV2640_FREQUENCY, 7); - I2C_SETFREQUENCY(i2c, CONFIG_OV2640_I2CADDR); + I2C_SETADDRESS(i2c, CONFIG_OV2640_I2CADDR, 7); + I2C_SETFREQUENCY(i2c, CONFIG_OV2640_FREQUENCY); /* Reset the OVR2640 */ -- GitLab From 1cddcc7bde354293b405ffc95cdc9a8bf23e0f6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 16 Jan 2016 09:44:23 -0600 Subject: [PATCH 555/858] Duplicated line in README --- README.txt | 1 - configs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.txt b/README.txt index 66d960a1bd..ac996d21f4 100644 --- a/README.txt +++ b/README.txt @@ -1,5 +1,4 @@ README -README ^^^^^^ o Installation diff --git a/configs b/configs index be3e062398..4a2f9e08a6 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit be3e06239810d80185654a74b99dd5a7b10a26ee +Subproject commit 4a2f9e08a634e3adc1ee53b5577deec83f943fda -- GitLab From 4a7896b5538df1d7f9aba0b1ba5ac52926b317ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 16 Jan 2016 12:22:54 -0600 Subject: [PATCH 556/858] tools/indent.sh: Add an option to reformat multiple files in-place --- tools/README.txt | 18 +++++++++ tools/indent.sh | 103 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 28 deletions(-) diff --git a/tools/README.txt b/tools/README.txt index 7662f9adab..7a9d013caa 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -541,6 +541,24 @@ indent.sh to my coding NuttX coding style. It doesn't do a really good job, however (see the comments at the top of the indent.sh file). + USAGE: + ./indent.sh [-d] -o + ./indent.sh [-d] + ./indent.sh [-d] -h + + Where: + - + A single, unformatted input file + - + A list of unformatted input files that will be reformatted in place. + -o + Write the single, reformatted to . + will not be modified. + -d + Enable script debug + -h + Show this help message and exit + refresh.sh ---------- diff --git a/tools/indent.sh b/tools/indent.sh index 866430e7e2..10bffdd60f 100755 --- a/tools/indent.sh +++ b/tools/indent.sh @@ -2,7 +2,7 @@ ############################################################################ # tools/indent.sh # -# Copyright (C) 2008, 2010 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2010, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -48,39 +48,86 @@ options="-nbad -bap -bbb -nbbo -nbc -bl -bl2 -bls -nbs -cbi2 -ncdw -nce -ci2 -cli0 -cp40 -ncs -nbfda -nbfde -di1 -nfc1 -fca -i2 -l80 -lp -ppi2 -lps -npcs -pmt -nprs -npsl -saf -sai -sbi2 -saw -sc -sob -nss -nut" -usage="USAGE: $0 " +advice="Try '$0 -h' for more information" -# Inputs +# Parse inputs -infile=$1 -outfile=$2 +unset filelist +unset outfile +files=none +mode=inplace -# Verify inputs +while [ ! -z "${1}" ]; do + case ${1} in + -d ) + set -x + ;; + -o ) + shift + outfile=${1} + mode=copy + ;; + -h ) + echo "$0 is a tool for generation of proper version files for the NuttX build" + echo "" + echo "USAGE:" + echo " $0 [-d] -o " + echo " $0 [-d] " + echo " $0 [-d] -h" + echo "" + echo "Where:" + echo " -" + echo " A single, unformatted input file" + echo " -" + echo " A list of unformatted input files that will be reformatted in place." + echo " -o " + echo " Write the single, reformatted to . " + echo " will not be modified." + echo " -d" + echo " Enable script debug" + echo " -h" + echo " Show this help message and exit" + exit 0 + ;; + * ) + if [ ! -r ${1} ]; then + echo "Readable ${1} does not exist" + echo ${advice} + exit 1 + fi + if [ -z "${filelist}" ]; then + filelist="${1}" + files=single + else + filelist="${filelist} ${1}" + files=multiple + fi + ;; + esac + shift +done -if [ -z "$infile" ]; then - echo "Missing " - echo $usage - exit 1 -fi - -if [ ! -r $infile ]; then - echo "Readable $infile does not exist" - exit 1 -fi - -if [ -z "$outfile" ]; then - echo "Missing " - echo $usage - exit 1 -fi +# Verify that at least one input file was provided -if [ -f $outfile ]; then - echo "Removing old $outfile" - rm $outfile || { echo "Failed to remove $outfile" ; exit 1 ; } +if [ "X${files}" == "Xnone" ]; then + echo "ERROR: Neither nor provided" + echo ${advice} + exit 1 fi # Perform the indentation -indent $options $infile -o $outfile - - +if [ "X${mode}" == "Xcopy" ]; then + if [ "X${files}" == "Xmultiple" ]; then + echo "ERROR: Only a single can be used with the -o option" + echo ${advice} + exit 1 + fi + if [ -f $outfile ]; then + echo "Removing old $outfile" + rm $outfile || { echo "Failed to remove $outfile" ; exit 1 ; } + fi + indent $options $filelist -o $outfile +else + indent $options $filelist +fi -- GitLab From f7b8069b0719a32f40d91c0a93e89bcc40908205 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 17 Jan 2016 08:12:21 -0600 Subject: [PATCH 557/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 196bc24d8b..73c05e32bc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 196bc24d8ba27ad0af0306bbbd145008399628fa +Subproject commit 73c05e32bc594ba7b4b270f374e76fa38a6766eb diff --git a/configs b/configs index 4a2f9e08a6..edf5f361a6 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4a2f9e08a634e3adc1ee53b5577deec83f943fda +Subproject commit edf5f361a60ccf886d651ecba1fa730f483b6c83 -- GitLab From fb1bf10a3d66489f41ff56cf3e051eec8328ae28 Mon Sep 17 00:00:00 2001 From: Janne Rosberg Date: Thu, 7 Jan 2016 10:26:07 +0200 Subject: [PATCH 558/858] add pn532 support Signed-off-by: Janne Rosberg --- drivers/wireless/Kconfig | 37 ++ drivers/wireless/Make.defs | 4 + drivers/wireless/pn532.c | 1068 ++++++++++++++++++++++++++++++++ drivers/wireless/pn532.h | 155 +++++ include/nuttx/wireless/pn532.h | 159 +++++ 5 files changed, 1423 insertions(+) create mode 100644 drivers/wireless/pn532.c create mode 100644 drivers/wireless/pn532.h create mode 100644 include/nuttx/wireless/pn532.h diff --git a/drivers/wireless/Kconfig b/drivers/wireless/Kconfig index 194cdd05f8..37bcc7cb2b 100644 --- a/drivers/wireless/Kconfig +++ b/drivers/wireless/Kconfig @@ -61,3 +61,40 @@ config WL_NRF24L01_RXFIFO_LEN endif endif + +config WL_PN532 + bool "pn532 NFC-chip support" + default n + select SPI + ---help--- + This options adds driver support for the PN532 NFC chip. + +if WL_PN532 + +config PN532_SPI_FREQ + int "SPI frequency for PN532" + default 1000000 + depends on WL_PN532 + +config WL_PN532_DEBUG + bool "Enable PN532 debug" + default n + depends on WL_PN532 + +config WL_PN532_DEBUG_TX + bool "trace TX frames" + default n + depends on WL_PN532_DEBUG + +config WL_PN532_DEBUG_RX + bool "trace RX frames" + default n + depends on WL_PN532_DEBUG + + + +endif + + + + diff --git a/drivers/wireless/Make.defs b/drivers/wireless/Make.defs index b75c487641..23053f8c7b 100644 --- a/drivers/wireless/Make.defs +++ b/drivers/wireless/Make.defs @@ -49,6 +49,10 @@ ifeq ($(CONFIG_WL_CC3000),y) include wireless$(DELIM)cc3000$(DELIM)Make.defs endif +ifeq ($(CONFIG_WL_PN532),y) +CSRCS += pn532.c +endif + # Include wireless devices build support DEPPATH += --dep-path wireless diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c new file mode 100644 index 0000000000..8788f455d3 --- /dev/null +++ b/drivers/wireless/pn532.c @@ -0,0 +1,1068 @@ +/**************************************************************************** + * include/wireless/pn532.h + * + * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Authors: Janne Rosberg + * Teemu Pirinen + * Juho Grundström + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "pn532.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_WL_PN532_DEBUG +# define pn532dbg dbg +#else +# ifdef CONFIG_CPP_HAVE_VARARGS +# define pn532dbg(x...) +# else +# define pn532dbg (void) +# endif +#endif + +#ifdef CONFIG_WL_PN532_DEBUG_TX +# define tracetx dbgdumpbuffer +#else +# define tracetx(x...) +#endif + +#ifdef CONFIG_WL_PN532_DEBUG_RX +# define tracerx dbgdumpbuffer +#else +# define tracerx(x...) +#endif + +#define FRAME_SIZE(f) (sizeof(struct pn532_frame) + f->len + 2) +#define FRAME_POSTAMBLE(f) (f->data[f->len + 1]) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_SPI_OWNBUS +static inline void pn532_configspi(FAR struct spi_dev_s *spi); +# define pn532_lock(spi) +# define pn532_unlock(spi) +#else +# define pn532_configspi(spi); +static void pn532_lock(FAR struct spi_dev_s *spi); +static void pn532_unlock(FAR struct spi_dev_s *spi); +#endif + +/* Character driver methods */ + +static int _open(FAR struct file *filep); +static int _close(FAR struct file *filep); +static ssize_t _read(FAR struct file *, FAR char *, size_t); +static ssize_t _write(FAR struct file *filep, FAR const char *buffer, size_t buflen); +static int _ioctl(FAR struct file *filep,int cmd,unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_pn532fops = +{ + _open, + _close, + _read, + _write, + 0, + _ioctl +#ifndef CONFIG_DISABLE_POLL + ,0 +#endif +}; + +static uint8_t pn532_checksum(uint8_t value); +static uint8_t pn532_data_checksum(uint8_t *data, int datalen); + +int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n); + +/* IRQ Handling TODO: +static int pn532_irqhandler(FAR int irq, FAR void *context, FAR void* dev); +static inline int pn532_attachirq(FAR struct pn532_dev_s *dev, xcpt_t isr); +*/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifndef CONFIG_SPI_OWNBUS +static void pn532_lock(FAR struct spi_dev_s *spi) +{ + (void)SPI_LOCK(spi, true); + + SPI_SETMODE(spi, SPIDEV_MODE0); + SPI_SETBITS(spi, -8); + SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); + +} +#endif + +#ifndef CONFIG_SPI_OWNBUS +static void pn532_unlock(FAR struct spi_dev_s *spi) +{ + (void)SPI_LOCK(spi, false); +} +#endif + +#ifdef CONFIG_SPI_OWNBUS +static inline void pn532_configspi(FAR struct spi_dev_s *spi) +{ + /* Configure SPI for the PN532 module. + * As we own the SPI bus this method is called just once. + */ + SPI_SETMODE(spi, SPIDEV_MODE0); + SPI_SETBITS(spi, -8); + SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); +} +#endif + +static inline void pn532_select(struct pn532_dev_s *dev) +{ + if (dev->config->select) + { + dev->config->select(dev, true); + } + else + { + SPI_SELECT(dev->spi, SPIDEV_WIRELESS, true); + } +} + +static inline void pn532_deselect(struct pn532_dev_s *dev) +{ + if (dev->config->select) + { + dev->config->select(dev, false); + } + else + { + SPI_SELECT(dev->spi, SPIDEV_WIRELESS, false); + } +} + +static void pn532_frame_init(struct pn532_frame *frame, uint8_t cmd) +{ + frame->preamble = PN532_PREAMBLE; + frame->start_code = PN532_SOF; + frame->tfi = PN532_HOSTTOPN532; + frame->data[0] = cmd; + frame->len = 2; +} + +static void pn532_frame_finish(struct pn532_frame *frame) +{ + frame->lcs = pn532_checksum(frame->len); + frame->data[frame->len-1] = pn532_data_checksum(&frame->tfi, frame->len); + frame->data[frame->len] = PN532_POSTAMBLE; +} + +static inline uint8_t pn532_checksum(uint8_t value) +{ + return ~value + 1; +} + +static uint8_t pn532_data_checksum(uint8_t *data, int datalen) +{ + uint8_t sum = 0x00; + int i; + + for (i = 0; i < datalen; i++) + { + sum += data[i]; + } + + return pn532_checksum(sum); +} + + +bool pn532_rx_frame_is_valid(struct pn532_frame *f, bool check_data) +{ + uint8_t chk; + + if (f->start_code != PN532_SOF) + { + pn532dbg("Frame startcode 0x%X != 0x%X\n", PN532_SOF, f->start_code); + return false; + } + + if (f->tfi != PN532_PN532TOHOST) + return false; + + chk = pn532_checksum(f->len); + if (chk != f->lcs) + { + pn532dbg("Frame data len checksum failed"); + return false; + } + + if (check_data) + { + chk = pn532_data_checksum(&f->tfi, f->len); + if (chk != f->data[f->len-1]) { + pn532dbg("Frame data checksum failed: calc=0x%X != 0x%X", chk, f->data[f->len-1]); + return false; + } + } + + return true; +} + +static uint8_t pn532_status(struct pn532_dev_s *dev) +{ + int rs; + + pn532_lock(dev->spi); + pn532_select(dev); + + rs = SPI_SEND(dev->spi, PN532_SPI_STATREAD); + rs = SPI_SEND(dev->spi, PN532_SPI_STATREAD); + + pn532_deselect(dev); + pn532_unlock(dev->spi); + + return rs; +} + +/** + * Blocks until Data frame available from chip. + * + * @return 0 for OK. -ETIMEDOUT if no data available + */ + +static int pn532_wait_rx_ready(struct pn532_dev_s *dev, int timeout) +{ + int ret = OK; + +#ifdef CONFIG_PN532_USE_IRQ_FLOW_CONTROL + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += 1; + sem_timedwait(dev->sem_rx, &ts); +#endif + + // TODO: Handle Exception bits 2, 3 + while (pn532_status(dev) != PN532_SPI_READY) + { + if (--timeout == 0x00) + { + pn532dbg("wait RX timeout!\n"); + return -ETIMEDOUT; + } + usleep(1000); + } + + dev->state = PN532_STATE_DATA_READY; + + return ret; +} + + +#if 0 +/* Helper for debug/testing */ + +static void pn532_writecommand(struct pn532_dev_s *dev, uint8_t cmd) +{ + char cmd_buffer[16]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + pn532_frame_init(f, cmd); + pn532_frame_finish(f); + + pn532_lock(dev->spi); + pn532_select(dev); + usleep(10000); + + SPI_SEND(dev->spi, PN532_SPI_DATAWRITE); + SPI_SNDBLOCK(dev->spi, f, FRAME_SIZE(f)); + + pn532_deselect(dev); + pn532_unlock(dev->spi); + + tracetx("command sent", (uint8_t *) f, FRAME_SIZE(f)); + +} +#endif + + +/** + * RAW Read data from chip. + * @note this DON'T wait if data is available! + * + */ +int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) +{ + pn532_lock(dev->spi); + pn532_select(dev); + SPI_SEND(dev->spi, PN532_SPI_DATAREAD); + SPI_RECVBLOCK(dev->spi, buff, n); + pn532_deselect(dev); + pn532_unlock(dev->spi); + + tracerx("read", buff, n); + return n; +} + +int pn532_read_more(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) +{ + pn532_lock(dev->spi); + pn532_select(dev); + SPI_RECVBLOCK(dev->spi, buff, n); + pn532_deselect(dev); + pn532_unlock(dev->spi); + + tracerx("read_more", buff, n); + return n; +} + + +static const uint8_t pn532ack[] = {0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00}; + +/** + * @brief Read Ack responce from device + * + * @return 0 = NOK, 1 = OK + **/ +int pn532_read_ack(struct pn532_dev_s *dev) +{ + int res = 0; + uint8_t ack[6]; + + pn532_read(dev, (uint8_t *) &ack, 6); + + if (memcmp(&ack, &pn532ack, 6) == 0x00) + { + res = 1; + } else { + pn532dbg("ACK NOK"); + res = 0; + } + + return res; +} + + +/** + * @brief Write frame to chip + * also waits and reads ACK frame from chip. + * + * construct frame with + * pn532_frame_init(), pn532_frame_finish() + * + * @param dev device instance + * @param f pointer to start frame + * @return 0 for OK, negative for error + */ +int pn532_write_frame(struct pn532_dev_s *dev, struct pn532_frame *f) +{ + int res = OK; + + pn532_lock(dev->spi); + pn532_select(dev); + usleep(2000); + + SPI_SEND(dev->spi, PN532_SPI_DATAWRITE); + SPI_SNDBLOCK(dev->spi, f, FRAME_SIZE(f)); + pn532_deselect(dev); + pn532_unlock(dev->spi); + tracetx("WriteFrame", (uint8_t *) f, FRAME_SIZE(f)); + + // wait ACK frame + res = pn532_wait_rx_ready(dev, 30); + if (res == OK) + { + if (!pn532_read_ack(dev)) + { + pn532dbg("command FAILED\n"); + res = -EIO; + } + } + + return res; +} + + +int pn532_read_frame(struct pn532_dev_s *dev, struct pn532_frame *f, int max_size) +{ + int res = -EIO; + + /* wait for frame available */ + + if ((res = pn532_wait_rx_ready(dev, 100)) == OK) + { + /* read header */ + + pn532_read(dev, (uint8_t *) f, sizeof(struct pn532_frame)); + if (pn532_rx_frame_is_valid(f, false)) + { + if (max_size < f->len) + { + return -EINVAL; + } + pn532_read_more(dev, &f->data[0], f->len); + + /* TODO: optimize frame integrity check... + * pn532_data_checksum(&f.tfi, f->len); + * dbgdumpbuffer("RX Frame:", f, f->len+6); + */ + + if (pn532_rx_frame_is_valid(f, true)) + { + res = OK; + } + } + } + + return res; +} + + +bool pn532_set_config(struct pn532_dev_s *dev, uint8_t flags) +{ + char cmd_buffer[2+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + + pn532_frame_init(f, PN532_COMMAND_SETPARAMETERS); + f->data[1] = flags; + f->len += 1; + pn532_frame_finish(f); + + uint8_t resp[9]; + bool res = false; + + if (pn532_write_frame(dev, f) == OK) + { + pn532_read(dev, (uint8_t *) &resp, 9); + tracerx("set config responce", resp, 9); + res = true; + } + + return res; +} + +int pn532_sam_config(struct pn532_dev_s *dev, struct pn_sam_settings_s *settings) +{ + char cmd_buffer[4+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + + pn532_frame_init(f, PN532_COMMAND_SAMCONFIGURATION); + f->data[1] = PN532_SAM_NORMAL_MODE; + f->data[2] = 0x14; /* Timeout LSB=50ms 0x14*50ms = 1sec */ + f->data[3] = 0x01; /* P-70, IRQ enabled */ + + if (settings) { + /* TODO: !!! */ + } + f->len += 3; + pn532_frame_finish(f); + + int res = -EIO; + + if (pn532_write_frame(dev, f) == OK) + { + if (pn532_read_frame(dev, f, 4) == OK) + { + tracerx("sam config response", (uint8_t *) f->data, 3); + if (f->data[0] == PN532_COMMAND_SAMCONFIGURATION + 1) + res = OK; + } + } + + return res; +} + + +int pn532_get_fw_version(struct pn532_dev_s *dev, + struct pn_firmware_version *fv) +{ + uint8_t cmd_buffer[4+8+1]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + struct pn_firmware_version *fw; + int res = -EIO; + + pn532_frame_init(f, PN532_COMMAND_GETFIRMWAREVERSION); + pn532_frame_finish(f); + + if (pn532_write_frame(dev, f) == OK) + { + if (pn532_read_frame(dev, f, 6) == OK) + { + if (f->data[0] == PN532_COMMAND_GETFIRMWAREVERSION + 1) + { + fw = (struct pn_firmware_version*) &f->data[1]; + pn532dbg("FW: %d.%d on IC:0x%X (Features: 0x%X)\n", + fw->ver, fw->rev, fw->ic, fw->support); + if (fv) + { + memcpy(fv, fw, sizeof(struct pn_firmware_version)); + } + res = OK; + } + } + } + + return res; +} + + + +int pn532_write_gpio(struct pn532_dev_s *dev, uint8_t p3, uint8_t p7) +{ + uint8_t cmd_buffer[3+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + int res = -EIO; + + pn532_frame_init(f, PN532_COMMAND_WRITEGPIO); + f->data[1] = p3; + f->data[2] = p7; + f->len += 2; + pn532_frame_finish(f); + + if (pn532_write_frame(dev, f)) + { + pn532_read(dev, cmd_buffer, 10); + tracetx("Resp:", cmd_buffer, 10); + pn532dbg("TFI=%x, data0=%X", f->tfi, f->data[0]); + if ((f->tfi == PN532_PN532TOHOST) && (f->data[0] == PN532_COMMAND_WRITEGPIO+1)) + res = OK; + } + + return res; +} + +uint32_t pn532_write_passive_data(struct pn532_dev_s *dev, uint8_t address, + uint8_t *data, uint8_t len) +{ + uint8_t cmd_buffer[8+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + uint8_t resp[20]; + uint32_t res = -EIO; + + pn532_frame_init(f, PN532_COMMAND_INDATAEXCHANGE); + f->data[1] = 1; /* max n cards at once */ + f->data[2] = 0xA2; /* command WRITE */ + f->data[3] = address; /* ADDRESS, 0 = serial */ + memcpy(&f->data[4], data, len); + f->len += 7; + pn532_frame_finish(f); + + if (pn532_write_frame(dev, f) == OK) + { + if (dev->state == PN532_STATE_DATA_READY) + { + if (pn532_read_frame(dev, (struct pn532_frame *) resp, 15) == OK) + { + dev->state = PN532_STATE_IDLE; + f = (struct pn532_frame *) resp; + tracerx("passive target id resp:", f, f->len+6); + + if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1) + { + res = f->data[1]; + } + } + } + } + return res; +} + +uint32_t pn532_read_passive_data(struct pn532_dev_s *dev, uint8_t address, + uint8_t *data, uint8_t len) +{ + uint8_t cmd_buffer[4+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + uint8_t resp[30]; + uint32_t res = -1; + + pn532_frame_init(f, PN532_COMMAND_INDATAEXCHANGE); + f->data[1] = 1; /* max n cards at once */ + f->data[2] = 0x30; /* command READ */ + f->data[3] = address; /* ADDRESS, 0 = serial */ + f->len += 3; + pn532_frame_finish(f); + + if (pn532_write_frame(dev, f) == OK) + { + if (dev->state == PN532_STATE_DATA_READY) + { + if (pn532_read_frame(dev, (struct pn532_frame *)resp, 25) == OK) + { + dev->state = PN532_STATE_IDLE; + f = (struct pn532_frame *) resp; + tracerx("passive target id resp:", f, f->len+6); + + if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1) + { + if(f->data[1] == 0 && data && len) + { + memcpy(data, &f->data[2], len); + } + + res = f->data[1]; + } + } + } + } + return res; +} + +uint32_t pn532_read_passive_target_id(struct pn532_dev_s *dev, uint8_t baudrate) +{ + uint8_t cmd_buffer[4+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + uint8_t resp[20]; + uint32_t res = -EAGAIN; + int i; + + if (dev->state == PN532_STATE_DATA_READY) + { + res = -EIO; + if (pn532_read_frame(dev, (struct pn532_frame *) resp, 15) == OK) + { + dev->state = PN532_STATE_IDLE; + f = (struct pn532_frame *) resp; + struct pn_poll_response *r = (struct pn_poll_response *) &f->data[1]; + tracerx("passive target id resp:", f, f->len+6); + + if (f->data[0] == PN532_COMMAND_INLISTPASSIVETARGET+1) + { + uint32_t cid = 0; + + if (r->nbtg == 1) + { + pn532dbg("Found %d card(s)\n", r->nbtg); + + /* now supports only type_a cards + * if (poll_mode == PN532_POLL_MOD_106KBPS_A) + */ + + struct pn_target_type_a *t = (struct pn_target_type_a *) &r->target_data; + pn532dbg("sens:0x%x sel:0x%x", t->sens_res, t->sel_res); + pn532dbg("idlen:0x%x ", t->nfcid_len); + + /* generate 32bit cid from id (could be longer) + * HACK: Using only top 4 bytes */ + + for (i = 0; i < 4 /*t->nfcid_len*/; i++) + { + cid <<= 8; + cid |= t->nfcid_data[i]; + } + } + res = cid; + } + } + } + + return res; + +} + +static int pn532_read_passive_target(struct pn532_dev_s *dev, uint8_t baudrate) +{ + uint8_t cmd_buffer[4+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + + pn532_frame_init(f, PN532_COMMAND_INLISTPASSIVETARGET); + f->data[1] = 1; + f->data[2] = baudrate; + f->len += 2; + pn532_frame_finish(f); + return pn532_write_frame(dev, f); +} + +bool pn532_set_rf_config(struct pn532_dev_s *dev, struct pn_rf_config_s *conf) +{ + bool res = false; + uint8_t cmd_buffer[15+7]; + struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + + pn532_frame_init(f, PN532_COMMAND_RFCONFIGURATION); + f->data[1] = conf->cfg_item; + memcpy(&f->data[2], conf->config, conf->data_size); + f->len += conf->data_size+1; + pn532_frame_finish(f); + + if (pn532_write_frame(dev, f) == OK) + { + pn532_read(dev, (uint8_t *) f, 10); + tracerx("rf config response", (uint8_t *) f, 10); + if (pn532_rx_frame_is_valid(f, true)) + { + if (f->data[0] == PN532_COMMAND_RFCONFIGURATION + 1) + res = true; + } + } + + return res; +} + +#if 0 + +/* IRQ handling TODO: */ + +static inline int pn532_attachirq(FAR struct pn532_dev_s *dev, xcpt_t isr) +{ + return dev->config->irqattach(dev,isr); +} + +static int irq_handler(int irq, FAR void *context) +{ + (void) irq; + (void) context; + + /* pn532dbg("*IRQ*\n"); */ + /* work_queue(HPWORK, &g_dev->irq_work, pn532_worker, dev, 0); */ + + return OK; +} +#endif + +/**************************************************************************** + * Name: pn532_open + * + * Description: + * This function is called whenever the PN532 device is opened. + * + ****************************************************************************/ + +static int _open(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct pn532_dev_s *dev; + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + dev = inode->i_private; + + pn532_configspi(dev->spi); + + dev->config->reset(1); + usleep(10000); + + pn532_sam_config(dev, NULL); + pn532_get_fw_version(dev, NULL); + + dev->state = PN532_STATE_IDLE; + return OK; +} + +/**************************************************************************** + * Name: _close + * + * Description: + * This routine is called when the PN532 device is closed. + * + ****************************************************************************/ + +static int _close(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct pn532_dev_s *dev; + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + dev = inode->i_private; + + dev->config->reset(0); + dev->state = PN532_STATE_NOT_INIT; + +#ifdef CONFIG_PM + if(dev->pm_level >= PM_SLEEP) + { + // priv->config->reset(0); + } +#endif + return OK; +} + + +/**************************************************************************** + * Name: _read + * + * Description: + * This routine is called when the device is read. + * + * Returns TAG id as string to buffer. + * or -EIO if no TAG found + * + ****************************************************************************/ + +static ssize_t _read(FAR struct file *filep, FAR char *buffer, size_t buflen) +{ + FAR struct inode *inode; + FAR struct pn532_dev_s *dev; + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + dev = inode->i_private; + + uint32_t id = pn532_read_passive_target_id(dev, PN532_MIFARE_ISO14443A); + if (id != 0xFFFFFFFF) { + if (buffer) { + return snprintf(buffer, buflen, "0X%X", id); + } + } + + return -EIO; +} + +/**************************************************************************** + * Name: pn532_write + ****************************************************************************/ + +static ssize_t _write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + FAR struct inode *inode; + FAR struct pn532_dev_s *dev; + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + dev = inode->i_private; + + (void) dev; + + return -ENOSYS; +} + +/**************************************************************************** + * Name: pn532_ioctl + ****************************************************************************/ + +static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct pn532_dev_s *dev; + int ret = OK; + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + dev = inode->i_private; + + switch (cmd) + { + case PN532IOC_READ_TAG_DATA: + { + struct pn_mifare_tag_data_s *tag_data = (struct pn_mifare_tag_data_s *) arg; + if (tag_data) + { + /* HACK: get rid of previous command */ + if (dev->state == PN532_STATE_CMD_SENT) + { + if (pn532_wait_rx_ready(dev, 1)) + { + pn532_read_passive_target_id(dev,0); + } + } + + ret = pn532_read_passive_data(dev, tag_data->address, + (uint8_t *) &tag_data->data, + sizeof(tag_data->data)); + + dev->state = PN532_STATE_IDLE; + } + } + break; + + case PN532IOC_WRITE_TAG_DATA: + { + struct pn_mifare_tag_data_s *tag_data = (struct pn_mifare_tag_data_s *) arg; + if (tag_data) + { + /* HACK: get rid of previous command */ + if (dev->state == PN532_STATE_CMD_SENT) + { + if (pn532_wait_rx_ready(dev, 1)) + { + pn532_read_passive_target_id(dev,0); + } + } + + ret = pn532_write_passive_data(dev, tag_data->address, + (uint8_t *) &tag_data->data, + sizeof(tag_data->data)); + + dev->state = PN532_STATE_IDLE; + } + } + break; + + case PN532IOC_SET_SAM_CONF: + pn532_sam_config(dev, (struct pn_sam_settings_s *) arg); + break; + + case PN532IOC_READ_PASSIVE: + if (dev->state == PN532_STATE_CMD_SENT) + { + uint32_t *ptr = (uint32_t *)((uintptr_t)arg); + *ptr = pn532_read_passive_target_id(dev,0); + } + else + { + uint32_t *ptr = (uint32_t *)((uintptr_t)arg); + *ptr = -1; + } + break; + + case PN532IOC_SET_RF_CONF: + pn532_set_rf_config(dev, (struct pn_rf_config_s *) arg); + break; + + case PN532IOC_SEND_CMD_READ_PASSIVE: + ret = pn532_read_passive_target(dev,0); + if (ret == 0) + { + dev->state = PN532_STATE_CMD_SENT; + } + else + { + dev->state = PN532_STATE_IDLE; + } + break; + + case PN532IOC_GET_DATA_READY: + if (pn532_wait_rx_ready(dev, 1)) + { + ret = 0; + } + else + { + ret = 1; + } + break; + + case PN532IOC_GET_TAG_ID: + { + uint32_t *ptr = (uint32_t *)((uintptr_t)arg); + *ptr = pn532_read_passive_target_id(dev,0); + } + break; + + case PN532IOC_GET_STATE: + ret = dev->state; + break; + + default: + pn532dbg("Unrecognized cmd: %d\n", cmd); + ret = -EINVAL; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pn532_register + * + * Description: + * Register the PN532 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. + * E.g., "/dev/nfc0" + * spi - An instance of the SPI interface to use to communicate with + * PN532. + * config - chip config + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi, + FAR struct pn532_config_s *config) +{ + FAR struct pn532_dev_s *dev; + int ret; + + /* Initialize the PN532 device structure */ + + dev = (FAR struct pn532_dev_s *)kmm_malloc(sizeof(struct pn532_dev_s)); + if (!dev) + { + pn532dbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + dev->spi = spi; + dev->config = config; + +#if defined CONFIG_PM + dev->pm_level = PM_IDLE; +#endif + + /* pn532_attachirq(dev, pn532_irqhandler); */ + + /* Register the character driver */ + + ret = register_driver(devpath, &g_pn532fops, 0666, dev); + if (ret < 0) + { + pn532dbg("Failed to register driver: %d\n", ret); + kmm_free(dev); + } + + return ret; +} diff --git a/drivers/wireless/pn532.h b/drivers/wireless/pn532.h new file mode 100644 index 0000000000..abb0f20faf --- /dev/null +++ b/drivers/wireless/pn532.h @@ -0,0 +1,155 @@ +/**************************************************************************** + * drivers/wireless/pn532.h + * + * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Authors: Janne Rosberg + * Teemu Pirinen + * Juho Grundström + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define PN532_PREAMBLE 0x00 +#define PN532_STARTCODE1 0x00 +#define PN532_STARTCODE2 0xFF +#define PN532_POSTAMBLE 0x00 + +#define PN532_SOF 0xFF00 + +#define PN532_HOSTTOPN532 0xD4 +#define PN532_PN532TOHOST 0xD5 + +#define PN532_SPI_STATREAD 0x02 +#define PN532_SPI_DATAWRITE 0x01 +#define PN532_SPI_DATAREAD 0x03 +#define PN532_SPI_READY 0x01 + +/* PN532 Commands */ + +#define PN532_COMMAND_DIAGNOSE 0x00 +#define PN532_COMMAND_GETFIRMWAREVERSION 0x02 +#define PN532_COMMAND_GETGENERALSTATUS 0x04 +#define PN532_COMMAND_READREGISTER 0x06 +#define PN532_COMMAND_WRITEREGISTER 0x08 +#define PN532_COMMAND_READGPIO 0x0C +#define PN532_COMMAND_WRITEGPIO 0x0E +#define PN532_COMMAND_SETSERIALBAUDRATE 0x10 +#define PN532_COMMAND_SETPARAMETERS 0x12 +#define PN532_COMMAND_SAMCONFIGURATION 0x14 +#define PN532_COMMAND_POWERDOWN 0x16 +#define PN532_COMMAND_RFCONFIGURATION 0x32 +#define PN532_COMMAND_RFREGULATIONTEST 0x58 +#define PN532_COMMAND_INJUMPFORDEP 0x56 +#define PN532_COMMAND_INJUMPFORPSL 0x46 +#define PN532_COMMAND_INLISTPASSIVETARGET 0x4A +#define PN532_COMMAND_INATR 0x50 +#define PN532_COMMAND_INPSL 0x4E +#define PN532_COMMAND_INDATAEXCHANGE 0x40 +#define PN532_COMMAND_INCOMMUNICATETHRU 0x42 +#define PN532_COMMAND_INDESELECT 0x44 +#define PN532_COMMAND_INRELEASE 0x52 +#define PN532_COMMAND_INSELECT 0x54 +#define PN532_COMMAND_INAUTOPOLL 0x60 +#define PN532_COMMAND_TGINITASTARGET 0x8C +#define PN532_COMMAND_TGSETGENERALBYTES 0x92 +#define PN532_COMMAND_TGGETDATA 0x86 +#define PN532_COMMAND_TGSETDATA 0x8E +#define PN532_COMMAND_TGSETMETADATA 0x94 +#define PN532_COMMAND_TGGETINITIATORCOMMAND 0x88 +#define PN532_COMMAND_TGRESPONSETOINITIATOR 0x90 +#define PN532_COMMAND_TGGETTARGETSTATUS 0x8A + +#define PN532_WAKEUP 0x55 + +#define PN532_SAM_NORMAL_MODE 0x01 +#define PN532_SAM_VIRTUAL_CARD 0x02 +#define PN532_SAM_WIRED_CARD 0x03 +#define PN532_SAM_DUAL_CARD 0x04 + + +struct pn532_frame { + uint8_t preamble; /* 0x00 */ + uint16_t start_code; /* 0x00FF (BE) -> 0xFF00 (LE) */ + uint8_t len; /* 1 byte indicating the number of bytes in + * the data field */ + uint8_t lcs; /* 1 Packet Length Checksum LCS byte that satisfies + * the relation: Lower byte of [LEN + LCS] = 00h */ + uint8_t tfi; /* Frame idenfifier 0xD4, 0xD5 */ + uint8_t data[]; /* LEN-1 bytes of Packet Data Information. + * The first byte PD0 is the Command Code */ +} packed_struct; + +struct pn_poll_response { + uint8_t nbtg; + uint8_t tg; + uint8_t target_data[]; +} packed_struct; + +struct pn_target_type_a { + uint16_t sens_res; + uint8_t sel_res; + uint8_t nfcid_len; + uint8_t nfcid_data[]; +} packed_struct; + +struct pn_firmware_version { + uint8_t ic; + uint8_t ver; + uint8_t rev; + uint8_t support; +}; + +struct pn532_dev_s +{ + uint8_t state; + FAR struct spi_dev_s *spi; /* SPI interface */ + FAR struct pn532_config_s *config; /* Board configuration data */ +}; + +#ifndef CONFIG_PN532_SPI_FREQ +#define CONFIG_PN532_SPI_FREQ (5000000) +#endif + +bool pn532_set_config(struct pn532_dev_s *dev, uint8_t flags); + diff --git a/include/nuttx/wireless/pn532.h b/include/nuttx/wireless/pn532.h new file mode 100644 index 0000000000..7b92522c54 --- /dev/null +++ b/include/nuttx/wireless/pn532.h @@ -0,0 +1,159 @@ +/**************************************************************************** + * include/wireless/nfc.h + * + * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Authors: Janne Rosberg + * Teemu Pirinen + * Juho Grundström + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NUTTX_WIRELESS_PN532_H +#define __NUTTX_WIRELESS_PN532_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define PN532_MIFARE_ISO14443A (0x00) + +/* IOCTL Commands ***********************************************************/ + +#define PN532IOC_SET_SAM_CONF _WLIOC_USER(0x0001) +#define PN532IOC_READ_PASSIVE _WLIOC_USER(0x0002) +#define PN532IOC_SET_RF_CONF _WLIOC_USER(0x0003) +#define PN532IOC_SEND_CMD_READ_PASSIVE _WLIOC_USER(0x0004) +#define PN532IOC_GET_DATA_READY _WLIOC_USER(0x0005) +#define PN532IOC_GET_TAG_ID _WLIOC_USER(0x0006) +#define PN532IOC_GET_STATE _WLIOC_USER(0x0007) +#define PN532IOC_READ_TAG_DATA _WLIOC_USER(0x0008) +#define PN532IOC_WRITE_TAG_DATA _WLIOC_USER(0x0009) + +enum pn532_state_E +{ + PN532_STATE_NOT_INIT, + PN532_STATE_IDLE, + PN532_STATE_CMD_SENT, + PN532_STATE_DATA_READY, +}; + + +/**************************************************************************** + * Global Data + ****************************************************************************/ +struct pn532_dev_s; + +struct pn532_config_s +{ + int (*reset)(uint8_t enable); + + /* external CS, if NULL then SPIDEV_WIRELESS CS is used */ + + int (*select)(struct pn532_dev_s *dev, bool sel); + int (*irqattach)(void* dev, xcpt_t isr); +}; + +enum PN_SAM_MODE { + PN_SAM_NORMAL_MODE = 0x01, + PN_SAM_VIRTUAL_CARD, + PN_SAM_WIRED_CARD, + SAM_DUAL_CARD +}; + +struct pn_sam_settings_s +{ + enum PN_SAM_MODE mode; /* Mode */ + uint8_t timeout; /* Timeout: LSB=50ms 0x14*50ms = 1sec */ + uint8_t irq_en; /* If 1 - enable P-70, IRQ */ +}; + +enum PN_RF_CONFIG_ITEM { + PN_RF_CONFIG_RF_FIELD = 0x01, + PN_RF_CONFIG_VARIOUS_TIMINGS = 0x02, + + PN_RF_CONFIG_ITEM_ANALOG_106A = 0x0A, + PN_RF_CONFIG_ITEM_ANALOG_212 = 0x0B, +}; + +struct pn_rf_config_s +{ + uint8_t cfg_item; /* Item */ + uint8_t data_size; /* number of config items */ + uint8_t config[11]; /* Item config data */ +}; + +struct pn_mifare_tag_data_s +{ + uint32_t data; + uint8_t address; +}; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: pn532_register + * + * Description: + * Register the PN532 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/nfc0" + * spi - An instance of the SPI interface to use to communicate with PN532 + * config - Device persistent board data + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +EXTERN int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi, + FAR struct pn532_config_s *config); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __NUTTX_WIRELESS_PN532_H */ -- GitLab From 63301fe213dd906d8457850e4693d7173b21556c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 17 Jan 2016 14:52:11 -0600 Subject: [PATCH 559/858] Cosmetic changes from review of last pull request --- drivers/wireless/Kconfig | 12 +- drivers/wireless/Make.defs | 2 +- drivers/wireless/pn532.c | 235 ++++++++++++++++++++++----------- drivers/wireless/pn532.h | 70 ++++++---- include/nuttx/wireless/pn532.h | 40 +++--- 5 files changed, 225 insertions(+), 134 deletions(-) diff --git a/drivers/wireless/Kconfig b/drivers/wireless/Kconfig index 37bcc7cb2b..b55b9d5756 100644 --- a/drivers/wireless/Kconfig +++ b/drivers/wireless/Kconfig @@ -59,8 +59,8 @@ config WL_NRF24L01_RXFIFO_LEN Length of the software based fifo used to store content of received messages. -endif -endif +endif # WL_NRF24L01_RXSUPPORT +endif # WL_NRF24L01 config WL_PN532 bool "pn532 NFC-chip support" @@ -91,10 +91,4 @@ config WL_PN532_DEBUG_RX default n depends on WL_PN532_DEBUG - - -endif - - - - +endif # WL_PN532 diff --git a/drivers/wireless/Make.defs b/drivers/wireless/Make.defs index 23053f8c7b..235e09a672 100644 --- a/drivers/wireless/Make.defs +++ b/drivers/wireless/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # drivers/wireless/Make.defs # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c index 8788f455d3..d429948957 100644 --- a/drivers/wireless/pn532.c +++ b/drivers/wireless/pn532.c @@ -1,7 +1,7 @@ /**************************************************************************** * include/wireless/pn532.h * - * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Copyright(C) 2012, 2013, 2016 Offcode Ltd. All rights reserved. * Authors: Janne Rosberg * Teemu Pirinen * Juho Grundström @@ -63,7 +63,7 @@ # define pn532dbg(x...) # else # define pn532dbg (void) -# endif +# endif #endif #ifdef CONFIG_WL_PN532_DEBUG_TX @@ -97,11 +97,22 @@ static void pn532_unlock(FAR struct spi_dev_s *spi); /* Character driver methods */ -static int _open(FAR struct file *filep); -static int _close(FAR struct file *filep); +static int _open(FAR struct file *filep); +static int _close(FAR struct file *filep); static ssize_t _read(FAR struct file *, FAR char *, size_t); -static ssize_t _write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int _ioctl(FAR struct file *filep,int cmd,unsigned long arg); +static ssize_t _write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int _ioctl(FAR struct file *filep,int cmd,unsigned long arg); + +static uint8_t pn532_checksum(uint8_t value); +static uint8_t pn532_data_checksum(uint8_t *data, int datalen); + +int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n); + +/* IRQ Handling TODO: +static int pn532_irqhandler(FAR int irq, FAR void *context, FAR void* dev); +static inline int pn532_attachirq(FAR struct pn532_dev_s *dev, xcpt_t isr); +*/ /**************************************************************************** * Private Data @@ -118,17 +129,15 @@ static const struct file_operations g_pn532fops = #ifndef CONFIG_DISABLE_POLL ,0 #endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + ,0 +#endif }; -static uint8_t pn532_checksum(uint8_t value); -static uint8_t pn532_data_checksum(uint8_t *data, int datalen); - -int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n); - -/* IRQ Handling TODO: -static int pn532_irqhandler(FAR int irq, FAR void *context, FAR void* dev); -static inline int pn532_attachirq(FAR struct pn532_dev_s *dev, xcpt_t isr); -*/ +static const uint8_t pn532ack[] = +{ + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 +}; /**************************************************************************** * Private Functions @@ -142,7 +151,6 @@ static void pn532_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, -8); SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); - } #endif @@ -159,6 +167,7 @@ static inline void pn532_configspi(FAR struct spi_dev_s *spi) /* Configure SPI for the PN532 module. * As we own the SPI bus this method is called just once. */ + SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, -8); SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); @@ -223,7 +232,6 @@ static uint8_t pn532_data_checksum(uint8_t *data, int datalen) return pn532_checksum(sum); } - bool pn532_rx_frame_is_valid(struct pn532_frame *f, bool check_data) { uint8_t chk; @@ -235,7 +243,9 @@ bool pn532_rx_frame_is_valid(struct pn532_frame *f, bool check_data) } if (f->tfi != PN532_PN532TOHOST) - return false; + { + return false; + } chk = pn532_checksum(f->len); if (chk != f->lcs) @@ -247,7 +257,8 @@ bool pn532_rx_frame_is_valid(struct pn532_frame *f, bool check_data) if (check_data) { chk = pn532_data_checksum(&f->tfi, f->len); - if (chk != f->data[f->len-1]) { + if (chk != f->data[f->len-1]) + { pn532dbg("Frame data checksum failed: calc=0x%X != 0x%X", chk, f->data[f->len-1]); return false; } @@ -272,11 +283,20 @@ static uint8_t pn532_status(struct pn532_dev_s *dev) return rs; } -/** - * Blocks until Data frame available from chip. +/**************************************************************************** + * Name: pn532_wait_rx_ready * - * @return 0 for OK. -ETIMEDOUT if no data available - */ + * Description: + * Blocks until Data frame available from chip. + * + * Input Parameters: + * dev + * timeout + * + * Returned Value: + * 0 for OK. -ETIMEDOUT if no data available + * + ****************************************************************************/ static int pn532_wait_rx_ready(struct pn532_dev_s *dev, int timeout) { @@ -289,7 +309,8 @@ static int pn532_wait_rx_ready(struct pn532_dev_s *dev, int timeout) sem_timedwait(dev->sem_rx, &ts); #endif - // TODO: Handle Exception bits 2, 3 + /* TODO: Handle Exception bits 2, 3 */ + while (pn532_status(dev) != PN532_SPI_READY) { if (--timeout == 0x00) @@ -297,22 +318,32 @@ static int pn532_wait_rx_ready(struct pn532_dev_s *dev, int timeout) pn532dbg("wait RX timeout!\n"); return -ETIMEDOUT; } + usleep(1000); } dev->state = PN532_STATE_DATA_READY; - return ret; } +/**************************************************************************** + * Name: pn532_writecommand + * + * Description: + * Helper for debug/testing + * + * Input Parameters: + * + * Returned Value: + * + ****************************************************************************/ #if 0 -/* Helper for debug/testing */ - static void pn532_writecommand(struct pn532_dev_s *dev, uint8_t cmd) { char cmd_buffer[16]; struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + pn532_frame_init(f, cmd); pn532_frame_finish(f); @@ -327,16 +358,22 @@ static void pn532_writecommand(struct pn532_dev_s *dev, uint8_t cmd) pn532_unlock(dev->spi); tracetx("command sent", (uint8_t *) f, FRAME_SIZE(f)); - } #endif - -/** - * RAW Read data from chip. - * @note this DON'T wait if data is available! +/**************************************************************************** + * Name: pn532_read * - */ + * Description: + * RAW Read data from chip. + * NOTE: This WON'T wait if data is available! + * + * Input Parameters: + * + * Returned Value: + * + ****************************************************************************/ + int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) { pn532_lock(dev->spi); @@ -362,14 +399,20 @@ int pn532_read_more(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) return n; } - -static const uint8_t pn532ack[] = {0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00}; - -/** - * @brief Read Ack responce from device +/**************************************************************************** + * Name: pn532_read_ack + * + * Description: + * Read Ack responce from device + * + * Input Parameters: + * dev + * + * Returned Value: + * 0 = NOK, 1 = OK * - * @return 0 = NOK, 1 = OK - **/ + ****************************************************************************/ + int pn532_read_ack(struct pn532_dev_s *dev) { int res = 0; @@ -380,7 +423,9 @@ int pn532_read_ack(struct pn532_dev_s *dev) if (memcmp(&ack, &pn532ack, 6) == 0x00) { res = 1; - } else { + } + else + { pn532dbg("ACK NOK"); res = 0; } @@ -388,18 +433,24 @@ int pn532_read_ack(struct pn532_dev_s *dev) return res; } - -/** - * @brief Write frame to chip - * also waits and reads ACK frame from chip. +/**************************************************************************** + * Name: pn532_write_frame * - * construct frame with - * pn532_frame_init(), pn532_frame_finish() + * Description: + * Write frame to chip. Also waits and reads ACK frame from chip. + * + * Construct frame with + * pn532_frame_init(), pn532_frame_finish() + * + * Input Parameters: + * dev - Device instance + * f - Pointer to start frame + * + * Returned Value: + * 0 for OK, negative for error * - * @param dev device instance - * @param f pointer to start frame - * @return 0 for OK, negative for error - */ + ****************************************************************************/ + int pn532_write_frame(struct pn532_dev_s *dev, struct pn532_frame *f) { int res = OK; @@ -414,7 +465,8 @@ int pn532_write_frame(struct pn532_dev_s *dev, struct pn532_frame *f) pn532_unlock(dev->spi); tracetx("WriteFrame", (uint8_t *) f, FRAME_SIZE(f)); - // wait ACK frame + /* Wait ACK frame */ + res = pn532_wait_rx_ready(dev, 30); if (res == OK) { @@ -428,16 +480,15 @@ int pn532_write_frame(struct pn532_dev_s *dev, struct pn532_frame *f) return res; } - int pn532_read_frame(struct pn532_dev_s *dev, struct pn532_frame *f, int max_size) { int res = -EIO; - /* wait for frame available */ + /* Wait for frame available */ if ((res = pn532_wait_rx_ready(dev, 100)) == OK) { - /* read header */ + /* Read header */ pn532_read(dev, (uint8_t *) f, sizeof(struct pn532_frame)); if (pn532_rx_frame_is_valid(f, false)) @@ -446,6 +497,7 @@ int pn532_read_frame(struct pn532_dev_s *dev, struct pn532_frame *f, int max_siz { return -EINVAL; } + pn532_read_more(dev, &f->data[0], f->len); /* TODO: optimize frame integrity check... @@ -463,7 +515,6 @@ int pn532_read_frame(struct pn532_dev_s *dev, struct pn532_frame *f, int max_siz return res; } - bool pn532_set_config(struct pn532_dev_s *dev, uint8_t flags) { char cmd_buffer[2+7]; @@ -491,19 +542,22 @@ int pn532_sam_config(struct pn532_dev_s *dev, struct pn_sam_settings_s *settings { char cmd_buffer[4+7]; struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; + int res; pn532_frame_init(f, PN532_COMMAND_SAMCONFIGURATION); f->data[1] = PN532_SAM_NORMAL_MODE; - f->data[2] = 0x14; /* Timeout LSB=50ms 0x14*50ms = 1sec */ - f->data[3] = 0x01; /* P-70, IRQ enabled */ + f->data[2] = 0x14; /* Timeout LSB=50ms 0x14*50ms = 1sec */ + f->data[3] = 0x01; /* P-70, IRQ enabled */ - if (settings) { + if (settings) + { /* TODO: !!! */ } + f->len += 3; pn532_frame_finish(f); - int res = -EIO; + res = -EIO; if (pn532_write_frame(dev, f) == OK) { @@ -511,14 +565,15 @@ int pn532_sam_config(struct pn532_dev_s *dev, struct pn_sam_settings_s *settings { tracerx("sam config response", (uint8_t *) f->data, 3); if (f->data[0] == PN532_COMMAND_SAMCONFIGURATION + 1) - res = OK; + { + res = OK; + } } } return res; } - int pn532_get_fw_version(struct pn532_dev_s *dev, struct pn_firmware_version *fv) { @@ -543,6 +598,7 @@ int pn532_get_fw_version(struct pn532_dev_s *dev, { memcpy(fv, fw, sizeof(struct pn_firmware_version)); } + res = OK; } } @@ -551,8 +607,6 @@ int pn532_get_fw_version(struct pn532_dev_s *dev, return res; } - - int pn532_write_gpio(struct pn532_dev_s *dev, uint8_t p3, uint8_t p7) { uint8_t cmd_buffer[3+7]; @@ -571,7 +625,9 @@ int pn532_write_gpio(struct pn532_dev_s *dev, uint8_t p3, uint8_t p7) tracetx("Resp:", cmd_buffer, 10); pn532dbg("TFI=%x, data0=%X", f->tfi, f->data[0]); if ((f->tfi == PN532_PN532TOHOST) && (f->data[0] == PN532_COMMAND_WRITEGPIO+1)) - res = OK; + { + res = OK; + } } return res; @@ -610,6 +666,7 @@ uint32_t pn532_write_passive_data(struct pn532_dev_s *dev, uint8_t address, } } } + return res; } @@ -650,6 +707,7 @@ uint32_t pn532_read_passive_data(struct pn532_dev_s *dev, uint8_t address, } } } + return res; } @@ -688,7 +746,8 @@ uint32_t pn532_read_passive_target_id(struct pn532_dev_s *dev, uint8_t baudrate) pn532dbg("idlen:0x%x ", t->nfcid_len); /* generate 32bit cid from id (could be longer) - * HACK: Using only top 4 bytes */ + * HACK: Using only top 4 bytes. + */ for (i = 0; i < 4 /*t->nfcid_len*/; i++) { @@ -696,6 +755,7 @@ uint32_t pn532_read_passive_target_id(struct pn532_dev_s *dev, uint8_t baudrate) cid |= t->nfcid_data[i]; } } + res = cid; } } @@ -737,18 +797,29 @@ bool pn532_set_rf_config(struct pn532_dev_s *dev, struct pn_rf_config_s *conf) if (pn532_rx_frame_is_valid(f, true)) { if (f->data[0] == PN532_COMMAND_RFCONFIGURATION + 1) - res = true; + { + res = true; + } } } return res; } -#if 0 - -/* IRQ handling TODO: */ +/**************************************************************************** + * Name: pn532_attachirq + * + * Description: + * IRQ handling TODO: + * + * Input Parameters: + * + * Returned Value: + * + ****************************************************************************/ -static inline int pn532_attachirq(FAR struct pn532_dev_s *dev, xcpt_t isr) +#if 0 +static inline int (FAR struct pn532_dev_s *dev, xcpt_t isr) { return dev->config->irqattach(dev,isr); } @@ -821,13 +892,13 @@ static int _close(FAR struct file *filep) #ifdef CONFIG_PM if(dev->pm_level >= PM_SLEEP) { - // priv->config->reset(0); + //priv->config->reset(0); } #endif + return OK; } - /**************************************************************************** * Name: _read * @@ -851,8 +922,10 @@ static ssize_t _read(FAR struct file *filep, FAR char *buffer, size_t buflen) dev = inode->i_private; uint32_t id = pn532_read_passive_target_id(dev, PN532_MIFARE_ISO14443A); - if (id != 0xFFFFFFFF) { - if (buffer) { + if (id != 0xFFFFFFFF) + { + if (buffer) + { return snprintf(buffer, buflen, "0X%X", id); } } @@ -905,6 +978,7 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (tag_data) { /* HACK: get rid of previous command */ + if (dev->state == PN532_STATE_CMD_SENT) { if (pn532_wait_rx_ready(dev, 1)) @@ -928,6 +1002,7 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (tag_data) { /* HACK: get rid of previous command */ + if (dev->state == PN532_STATE_CMD_SENT) { if (pn532_wait_rx_ready(dev, 1)) @@ -1020,11 +1095,11 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg) * Register the PN532 character device as 'devpath' * * Input Parameters: - * devpath - The full path to the driver to register. - * E.g., "/dev/nfc0" - * spi - An instance of the SPI interface to use to communicate with - * PN532. - * config - chip config + * devpath - The full path to the driver to register. + * E.g., "/dev/nfc0" + * spi - An instance of the SPI interface to use to communicate with + * PN532. + * config - chip config * * Returned Value: * Zero (OK) on success; a negated errno value on failure. diff --git a/drivers/wireless/pn532.h b/drivers/wireless/pn532.h index abb0f20faf..8361f5ed50 100644 --- a/drivers/wireless/pn532.h +++ b/drivers/wireless/pn532.h @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/wireless/pn532.h * - * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Copyright(C) 2012, 2013, 2016 Offcode Ltd. All rights reserved. * Authors: Janne Rosberg * Teemu Pirinen * Juho Grundström @@ -35,35 +35,39 @@ * ****************************************************************************/ +#ifndef __DRIVERS_WIRELESS_PN532_H +#define __DRIVERS_WIRELESS_PN532_H 1 + /**************************************************************************** * Included Files ****************************************************************************/ #include + #include + #include #include - #include /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ -#define PN532_PREAMBLE 0x00 -#define PN532_STARTCODE1 0x00 -#define PN532_STARTCODE2 0xFF -#define PN532_POSTAMBLE 0x00 +#define PN532_PREAMBLE 0x00 +#define PN532_STARTCODE1 0x00 +#define PN532_STARTCODE2 0xFF +#define PN532_POSTAMBLE 0x00 -#define PN532_SOF 0xFF00 +#define PN532_SOF 0xFF00 -#define PN532_HOSTTOPN532 0xD4 -#define PN532_PN532TOHOST 0xD5 +#define PN532_HOSTTOPN532 0xD4 +#define PN532_PN532TOHOST 0xD5 -#define PN532_SPI_STATREAD 0x02 -#define PN532_SPI_DATAWRITE 0x01 -#define PN532_SPI_DATAREAD 0x03 -#define PN532_SPI_READY 0x01 +#define PN532_SPI_STATREAD 0x02 +#define PN532_SPI_DATAWRITE 0x01 +#define PN532_SPI_DATAREAD 0x03 +#define PN532_SPI_READY 0x01 /* PN532 Commands */ @@ -102,38 +106,49 @@ #define PN532_WAKEUP 0x55 -#define PN532_SAM_NORMAL_MODE 0x01 -#define PN532_SAM_VIRTUAL_CARD 0x02 -#define PN532_SAM_WIRED_CARD 0x03 -#define PN532_SAM_DUAL_CARD 0x04 +#define PN532_SAM_NORMAL_MODE 0x01 +#define PN532_SAM_VIRTUAL_CARD 0x02 +#define PN532_SAM_WIRED_CARD 0x03 +#define PN532_SAM_DUAL_CARD 0x04 +#ifndef CONFIG_PN532_SPI_FREQ +# define CONFIG_PN532_SPI_FREQ (5000000) +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ -struct pn532_frame { +struct pn532_frame +{ uint8_t preamble; /* 0x00 */ - uint16_t start_code; /* 0x00FF (BE) -> 0xFF00 (LE) */ + uint16_t start_code; /* 0x00FF (BE) -> 0xFF00 (LE) */ uint8_t len; /* 1 byte indicating the number of bytes in * the data field */ uint8_t lcs; /* 1 Packet Length Checksum LCS byte that satisfies * the relation: Lower byte of [LEN + LCS] = 00h */ - uint8_t tfi; /* Frame idenfifier 0xD4, 0xD5 */ + uint8_t tfi; /* Frame idenfifier 0xD4, 0xD5 */ uint8_t data[]; /* LEN-1 bytes of Packet Data Information. * The first byte PD0 is the Command Code */ } packed_struct; -struct pn_poll_response { +struct pn_poll_response +{ uint8_t nbtg; uint8_t tg; uint8_t target_data[]; } packed_struct; -struct pn_target_type_a { +struct pn_target_type_a +{ uint16_t sens_res; uint8_t sel_res; uint8_t nfcid_len; uint8_t nfcid_data[]; } packed_struct; -struct pn_firmware_version { +struct pn_firmware_version +{ uint8_t ic; uint8_t ver; uint8_t rev; @@ -142,14 +157,15 @@ struct pn_firmware_version { struct pn532_dev_s { - uint8_t state; + uint8_t state; FAR struct spi_dev_s *spi; /* SPI interface */ FAR struct pn532_config_s *config; /* Board configuration data */ }; -#ifndef CONFIG_PN532_SPI_FREQ -#define CONFIG_PN532_SPI_FREQ (5000000) -#endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ bool pn532_set_config(struct pn532_dev_s *dev, uint8_t flags); +#endif /* __DRIVERS_WIRELESS_PN532_H */ diff --git a/include/nuttx/wireless/pn532.h b/include/nuttx/wireless/pn532.h index 7b92522c54..450b7c7ba3 100644 --- a/include/nuttx/wireless/pn532.h +++ b/include/nuttx/wireless/pn532.h @@ -1,7 +1,7 @@ /**************************************************************************** - * include/wireless/nfc.h + * include/wireless/pn532.h * - * Copyright(C) 2012,2013,2016 Offcode Ltd. All rights reserved. + * Copyright(C) 2012, 2013, 2016 Offcode Ltd. All rights reserved. * Authors: Janne Rosberg * Teemu Pirinen * Juho Grundström @@ -52,7 +52,7 @@ * Pre-Processor Definitions ****************************************************************************/ -#define PN532_MIFARE_ISO14443A (0x00) +#define PN532_MIFARE_ISO14443A (0x00) /* IOCTL Commands ***********************************************************/ @@ -66,6 +66,10 @@ #define PN532IOC_READ_TAG_DATA _WLIOC_USER(0x0008) #define PN532IOC_WRITE_TAG_DATA _WLIOC_USER(0x0009) +/**************************************************************************** + * Public Types + ****************************************************************************/ + enum pn532_state_E { PN532_STATE_NOT_INIT, @@ -74,23 +78,19 @@ enum pn532_state_E PN532_STATE_DATA_READY, }; - -/**************************************************************************** - * Global Data - ****************************************************************************/ struct pn532_dev_s; - struct pn532_config_s { int (*reset)(uint8_t enable); - /* external CS, if NULL then SPIDEV_WIRELESS CS is used */ + /* External CS, if NULL then SPIDEV_WIRELESS CS is used */ int (*select)(struct pn532_dev_s *dev, bool sel); int (*irqattach)(void* dev, xcpt_t isr); }; -enum PN_SAM_MODE { +enum PN_SAM_MODE +{ PN_SAM_NORMAL_MODE = 0x01, PN_SAM_VIRTUAL_CARD, PN_SAM_WIRED_CARD, @@ -104,7 +104,8 @@ struct pn_sam_settings_s uint8_t irq_en; /* If 1 - enable P-70, IRQ */ }; -enum PN_RF_CONFIG_ITEM { +enum PN_RF_CONFIG_ITEM +{ PN_RF_CONFIG_RF_FIELD = 0x01, PN_RF_CONFIG_VARIOUS_TIMINGS = 0x02, @@ -114,9 +115,9 @@ enum PN_RF_CONFIG_ITEM { struct pn_rf_config_s { - uint8_t cfg_item; /* Item */ - uint8_t data_size; /* number of config items */ - uint8_t config[11]; /* Item config data */ + uint8_t cfg_item; /* Item */ + uint8_t data_size; /* number of config items */ + uint8_t config[11]; /* Item config data */ }; struct pn_mifare_tag_data_s @@ -125,9 +126,14 @@ struct pn_mifare_tag_data_s uint8_t address; }; +/**************************************************************************** + * Public Functions + ****************************************************************************/ + #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -148,8 +154,8 @@ extern "C" { * ****************************************************************************/ -EXTERN int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi, - FAR struct pn532_config_s *config); +int pn532_register(FAR const char *devpath, FAR struct spi_dev_s *spi, + FAR struct pn532_config_s *config); #undef EXTERN #ifdef __cplusplus -- GitLab From 57b8a9526de1a241d83ca4d7df7b158a2e13d8c9 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Sat, 9 Jan 2016 12:43:05 -0500 Subject: [PATCH 560/858] Add LSM9DS1 accelerometer, gyroscope and magnetometer --- drivers/sensors/Kconfig | 7 + drivers/sensors/Make.defs | 4 + drivers/sensors/lsm9ds1.c | 1554 +++++++++++++++++++++++++++++++ include/nuttx/sensors/lsm9ds1.h | 151 +++ 4 files changed, 1716 insertions(+) create mode 100644 drivers/sensors/lsm9ds1.c create mode 100644 include/nuttx/sensors/lsm9ds1.h diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 80cdfcec0c..1cc726a7ba 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -24,6 +24,13 @@ config LIS331DL select I2C select I2C_TRANSFER +config SN_LSM9DS1 + bool "STMicro LSM9DS1 support" + default n + depends on I2C + ---help--- + Enable driver support for the STMicro LSM9DS1. + config MB7040 bool "MaxBotix MB7040 Sonar support" default n diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index a1c5c69a54..339085bc08 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -53,6 +53,10 @@ ifeq ($(CONFIG_LIS331DL),y) CSRCS += lis331dl.c endif +ifeq ($(CONFIG_SN_LSM9DS1),y) + CSRCS += lsm9ds1.c +endif + ifeq ($(CONFIG_ADXL345_I2C),y) CSRCS += adxl345_i2c.c endif diff --git a/drivers/sensors/lsm9ds1.c b/drivers/sensors/lsm9ds1.c new file mode 100644 index 0000000000..ba6e07784b --- /dev/null +++ b/drivers/sensors/lsm9ds1.c @@ -0,0 +1,1554 @@ +/**************************************************************************** + * drivers/sensors/lsm9ds1.c + * + * Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_SN_LSM9DS1) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Register Addresses *******************************************************/ +/* Accelerometer and gyroscope registers */ + +#define LSM9DS1_ACT_THS 0x04 /* Inactivity threshold */ +#define LSM9DS1_ACT_DUR 0x05 /* Inactivity duration */ +#define LSM9DS1_INT_GEN_CFG_XL 0x06 /* Accelerometer interrupt configuration */ +#define LSM9DS1_INT_GEN_THS_X_XL 0x07 /* Accelerometer X interrupt threshold */ +#define LSM9DS1_INT_GEN_THS_Y_XL 0x08 /* Accelerometer Y interrupt threshold */ +#define LSM9DS1_INT_GEN_THS_Z_XL 0x09 /* Accelerometer Z interrupt threshold */ +#define LSM9DS1_INT_GEN_DUR_XL 0x0a /* Accelerometer interrupt duration */ +#define LSM9DS1_REFERENCE_G 0x0b /* Gyroscope reference value for high-pass filter */ +#define LSM9DS1_INT1_CTRL 0x0c /* INT1_A/G pin control */ +#define LSM9DS1_INT2_CTRL 0x0d /* INT2_A/G pin control */ +#define LSM9DS1_WHO_AM_I 0x0f /* Accelerometer and gyroscope device identification */ +#define LSM9DS1_CTRL_REG1_G 0x10 /* Gyroscope control register 1 */ +#define LSM9DS1_CTRL_REG2_G 0x11 /* Gyroscope control register 2 */ +#define LSM9DS1_CTRL_REG3_G 0x12 /* Gyroscope control register 3 */ +#define LSM9DS1_ORIENT_CFG_G 0x13 /* Gyroscope sign and orientation */ +#define LSM9DS1_INT_GEN_SRC_G 0x14 /* Gyroscope interrupt source */ +#define LSM9DS1_OUT_TEMP_L 0x15 /* Temperature low byte */ +#define LSM9DS1_OUT_TEMP_H 0x16 /* Temperature high byte */ +#define LSM9DS1_STATUS_REG 0x17 /* Status register */ +#define LSM9DS1_OUT_X_L_G 0x18 /* Gyroscope pitch (X) low byte */ +#define LSM9DS1_OUT_X_H_G 0x19 /* Gyroscope pitch (X) high byte */ +#define LSM9DS1_OUT_Y_L_G 0x1a /* Gyroscope roll (Y) low byte */ +#define LSM9DS1_OUT_Y_H_G 0x1b /* Gyroscope roll (Y) high byte */ +#define LSM9DS1_OUT_Z_L_G 0x1c /* Gyroscope yaw (Z) low byte */ +#define LSM9DS1_OUT_Z_H_G 0x1d /* Gyroscope yaw (Z) high byte */ +#define LSM9DS1_CTRL_REG4 0x1e /* Control register 4 */ +#define LSM9DS1_CTRL_REG5_XL 0x1f /* Accelerometer control register 5 */ +#define LSM9DS1_CTRL_REG6_XL 0x20 /* Accelerometer control register 6 */ +#define LSM9DS1_CTRL_REG7_XL 0x21 /* Accelerometer control register 7 */ +#define LSM9DS1_CTRL_REG8 0x22 /* Control register 8 */ +#define LSM9DS1_CTRL_REG9 0x23 /* Control register 9 */ +#define LSM9DS1_CTRL_REG10 0x24 /* Control register 10 */ +#define LSM9DS1_INT_GEN_SRC_XL 0x26 /* Accelerometer interrupt source */ +#define LSM9DS1_STATUS_REG2 0x27 /* Status register 2 */ +#define LSM9DS1_OUT_X_L_XL 0x28 /* Accelerometer X low byte */ +#define LSM9DS1_OUT_X_H_XL 0x29 /* Accelerometer X high byte */ +#define LSM9DS1_OUT_Y_L_XL 0x2a /* Accelerometer Y low byte */ +#define LSM9DS1_OUT_Y_H_XL 0x2b /* Accelerometer Y high byte */ +#define LSM9DS1_OUT_Z_L_XL 0x2c /* Accelerometer Z low byte */ +#define LSM9DS1_OUT_Z_H_XL 0x2d /* Accelerometer Z high byte */ +#define LSM9DS1_FIFO_CTRL 0x2e /* FIFO control register */ +#define LSM9DS1_FIFO_SRC 0x2f /* FIFO status control register */ +#define LSM9DS1_INT_GEN_CFG_G 0x30 /* Gyroscope interrupt configuration */ +#define LSM9DS1_INT_GEN_THS_XH_G 0x31 /* Gyroscope pitch (X) interrupt threshold high byte */ +#define LSM9DS1_INT_GEN_THS_XL_G 0x32 /* Gyroscope pitch (X) interrupt threshold low byte */ +#define LSM9DS1_INT_GEN_THS_YH_G 0x33 /* Gyroscope roll (Y) interrupt threshold high byte */ +#define LSM9DS1_INT_GEN_THS_YL_G 0x34 /* Gyroscope roll (Y) interrupt threshold low byte */ +#define LSM9DS1_INT_GEN_THS_ZH_G 0x35 /* Gyroscope yaw (Z) interrupt threshold high byte */ +#define LSM9DS1_INT_GEN_THS_ZL_G 0x36 /* Gyroscope yaw (Z) interrupt threshold low byte */ +#define LSM9DS1_INT_GEN_DUR_G 0x37 /* Gyroscope interrupt duration */ + +/* Magnetometer registers */ + +#define LSM9DS1_OFFSET_X_REG_L_M 0x05 /* X low byte offset */ +#define LSM9DS1_OFFSET_X_REG_H_M 0x06 /* X high byte offset */ +#define LSM9DS1_OFFSET_Y_REG_L_M 0x07 /* Y low byte offset */ +#define LSM9DS1_OFFSET_Y_REG_H_M 0x08 /* Y high byte offset */ +#define LSM9DS1_OFFSET_Z_REG_L_M 0x09 /* Z low byte offset */ +#define LSM9DS1_OFFSET_Z_REG_H_M 0x0a /* Z high byte offset */ +#define LSM9DS1_WHO_AM_I_M 0x0f /* Device identification */ +#define LSM9DS1_CTRL_REG1_M 0x20 /* Control register 1 */ +#define LSM9DS1_CTRL_REG2_M 0x21 /* Control register 2 */ +#define LSM9DS1_CTRL_REG3_M 0x22 /* Control register 3 */ +#define LSM9DS1_CTRL_REG4_M 0x23 /* Control register 4 */ +#define LSM9DS1_CTRL_REG5_M 0x24 /* Control register 5 */ +#define LSM9DS1_STATUS_REG_M 0x27 /* Status register */ +#define LSM9DS1_OUT_X_L_M 0x28 /* X low byte */ +#define LSM9DS1_OUT_X_H_M 0x29 /* X high byte */ +#define LSM9DS1_OUT_Y_L_M 0x2a /* Y low byte */ +#define LSM9DS1_OUT_Y_H_M 0x2b /* Y high byte */ +#define LSM9DS1_OUT_Z_L_M 0x2c /* Z low byte */ +#define LSM9DS1_OUT_Z_H_M 0x2d /* Z high byte */ +#define LSM9DS1_INT_CFG_M 0x30 /* Interrupt configuration */ +#define LSM9DS1_INT_SRC_M 0x31 /* Interrupt source */ +#define LSM9DS1_INT_THS_L_M 0x32 /* Interrupt threshold low byte */ +#define LSM9DS1_INT_THS_H_M 0x33 /* Interrupt threshold high byte */ + +/* Register Bit Definitions *************************************************/ +/* Inactivity threshold register */ + +#define LSM9DS1_ACT_THS_ACT_THS_SHIFT 0 /* Inactivity threshold */ +#define LSM9DS1_ACT_THS_ACT_THS_MASK (127 << LSM9DS1_ACT_THS_ACT_THS_SHIFT) +#define LSM9DS1_ACT_THS_SLEEP_ON_INACT_EN (1 << 7) /* Gyroscope operating mode during inactivity */ + +/* Accelerometer interrupt configuration register */ + +#define LSM9DS1_INT_GEN_CFG_XL_XLIE_XL (1 << 0) /* X-axis low byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_XHIE_XL (1 << 1) /* X-axis high byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_YLIE_XL (1 << 2) /* Y-axis low byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_YHIE_XL (1 << 3) /* Y-axis high byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_ZLIE_XL (1 << 4) /* Z-axis low byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_ZHIE_XL (1 << 5) /* Z-axis high byte interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_XL_6D (1 << 6) /* 6-direction detection function for interrupt */ +#define LSM9DS1_INT_GEN_CFG_XL_AOI_XL (1 << 7) /* AND/OR combination of interrupt events */ + +/* Accelerometer interrupt duration register */ + +#define LSM9DS1_INT_GEN_DUR_XL_DUR_XL_SHIFT 0 /* Enter/exit interrupt duration */ +#define LSM9DS1_INT_GEN_DUR_XL_DUR_XL_MASK (127 << LSM9DS1_INT_GEN_DUR_XL_DUR_XL_SHIFT) +#define LSM9DS1_INT_GEN_DUR_XL_WAIT_XL (1 << 7) /* Wait function enabled on duration counter */ + +/* INT1_A/G pin control register */ + +#define LSM9DS1_INT1_CTRL_INT1_DRDY_XL (1 << 0) /* Accelerometer data ready */ +#define LSM9DS1_INT1_CTRL_INT1_DRDY_G (1 << 1) /* Gyroscope data ready */ +#define LSM9DS1_INT1_CTRL_INT1_BOOT (1 << 2) /* Boot status available */ +#define LSM9DS1_INT1_CTRL_INT1_FTH (1 << 3) /* FIFO threshold interrupt */ +#define LSM9DS1_INT1_CTRL_INT1_OVR (1 << 4) /* Overrun interrupt */ +#define LSM9DS1_INT1_CTRL_INT1_FSS5 (1 << 5) /* FSS5 interrupt */ +#define LSM9DS1_INT1_CTRL_INT1_IG_XL (1 << 6) /* Accelerometer interrupt enable */ +#define LSM9DS1_INT1_CTRL_INT1_IG_G (1 << 7) /* Gyroscope interrupt enable */ + +/* INT2_A/G pin control register */ + +#define LSM9DS1_INT2_CTRL_INT2_DRDY_XL (1 << 0) /* Accelerometer data ready */ +#define LSM9DS1_INT2_CTRL_INT2_DRDY_G (1 << 1) /* Gyroscope data ready */ +#define LSM9DS1_INT2_CTRL_INT2_DRDY_TEMP (1 << 2) /* Temperature data ready */ +#define LSM9DS1_INT2_CTRL_INT2_FTH (1 << 3) /* FIFO threshold interrupt */ +#define LSM9DS1_INT2_CTRL_INT2_OVR (1 << 4) /* Overrun interrupt */ +#define LSM9DS1_INT2_CTRL_INT2_FSS5 (1 << 5) /* FSS5 interrupt */ +#define LSM9DS1_INT2_CTRL_INT2_INACT (1 << 7) /* Inactivity interrupt output signal */ + +/* Device identification register */ + +#define LSM9DS1_WHO_AM_I_VALUE 0x68 + +/* Gyroscope control register 1 */ + +#define LSM9DS1_CTRL_REG1_G_BW_G_SHIFT 0 /* Gyroscope bandwidth selection */ +#define LSM9DS1_CTRL_REG1_G_BW_G_MASK (3 << LSM9DS1_CTRL_REG1_G_BW_G_SHIFT) +#define LSM9DS1_CTRL_REG1_G_FS_G_SHIFT 3 /* Gyroscope full-scale selection */ +#define LSM9DS1_CTRL_REG1_G_FS_G_MASK (3 << LSM9DS1_CTRL_REG1_G_FS_G_SHIFT) +# define LSM9DS1_CTRL_REG1_G_FS_G_245DPS (0 << LSM9DS1_CTRL_REG1_G_FS_G_SHIFT) /* 245 dps */ +# define LSM9DS1_CTRL_REG1_G_FS_G_500DPS (1 << LSM9DS1_CTRL_REG1_G_FS_G_SHIFT) /* 500 dps */ +# define LSM9DS1_CTRL_REG1_G_FS_G_2000DPS (3 << LSM9DS1_CTRL_REG1_G_FS_G_SHIFT) /* 2000 dps */ +#define LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT 5 /* Gyroscope bandwidth selection */ +#define LSM9DS1_CTRL_REG1_G_ODR_G_MASK (7 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) +# define LSM9DS1_CTRL_REG1_G_ODR_G_POWERDOWN (0 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* Power-down mode */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_14p9HZ (1 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 14.9 Hz */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_59p5HZ (2 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 59.5 Hz */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_119HZ (3 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 119 Hz */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_238HZ (4 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 238 Hz */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_476HZ (5 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 476 Hz */ +# define LSM9DS1_CTRL_REG1_G_ODR_G_952HZ (6 << LSM9DS1_CTRL_REG1_G_ODR_G_SHIFT) /* 952 Hz */ + +/* Gyroscope control register 2 */ + +#define LSM9DS1_CTRL_REG2_G_OUT_SEL_SHIFT 0 /* Out selection configuration */ +#define LSM9DS1_CTRL_REG2_G_OUT_SEL_MASK (3 << LSM9DS1_CTRL_REG2_G_OUT_SEL_SHIFT) +#define LSM9DS1_CTRL_REG2_G_INT_SEL_SHIFT 2 /* INT selection configuration */ +#define LSM9DS1_CTRL_REG2_G_INT_SEL_MASK (3 << LSM9DS1_CTRL_REG2_G_INT_SEL_SHIFT) + +/* Gyroscope control register 3 */ + +#define LSM9DS1_CTRL_REG3_G_HPCF_G_SHIFT 0 /* Gyroscope high-pass filter cutoff frequency selection */ +#define LSM9DS1_CTRL_REG3_G_HPCF_G_MASK (15 << LSM9DS1_CTRL_REG3_G_HPCF_G_SHIFT) +#define LSM9DS1_CTRL_REG3_G_HP_EN (1 << 6) /* High-pass filter enable */ +#define LSM9DS1_CTRL_REG3_G_LP_MODE (1 << 7) /* Low-power mode enable */ + +/* Gyroscope sign and orientation register */ + +#define LSM9DS1_ORIENT_CFG_G_ORIENT_SHIFT 0 /* Directional user orientation selection */ +#define LSM9DS1_ORIENT_CFG_G_ORIENT_MASK (3 << LSM9DS1_ORIENT_CFG_G_ORIENT_SHIFT) +#define LSM9DS1_ORIENT_CFG_G_SIGNZ_G (1 << 3) /* Yaw axis (Z) angular rate sign */ +#define LSM9DS1_ORIENT_CFG_G_SIGNY_G (1 << 4) /* Roll axis (Y) angular rate sign */ +#define LSM9DS1_ORIENT_CFG_G_SIGNX_G (1 << 5) /* Pitch axis (X) angular rate sign */ + +/* Gyroscope interrupt source register */ + +#define LSM9DS1_INT_GEN_SRC_G_XL_G (1 << 0) /* Pitch (X) low */ +#define LSM9DS1_INT_GEN_SRC_G_XH_G (1 << 1) /* Pitch (X) high */ +#define LSM9DS1_INT_GEN_SRC_G_YL_G (1 << 2) /* Roll (Y) low */ +#define LSM9DS1_INT_GEN_SRC_G_YH_G (1 << 3) /* Roll (Y) high */ +#define LSM9DS1_INT_GEN_SRC_G_ZL_G (1 << 4) /* Yaw (Z) low */ +#define LSM9DS1_INT_GEN_SRC_G_ZH_G (1 << 5) /* Yaw (Z) high */ +#define LSM9DS1_INT_GEN_SRC_G_IA_G (1 << 6) /* Interrupt active */ + +/* Status register */ + +#define LSM9DS1_STATUS_REG_XLDA (1 << 0) /* Accelerometer new data available */ +#define LSM9DS1_STATUS_REG_GDA (1 << 1) /* Gyroscope new data available */ +#define LSM9DS1_STATUS_REG_TDA (1 << 2) /* Temperature sensor new data available */ +#define LSM9DS1_STATUS_REG_BOOT_STATUS (1 << 3) /* Boot running flag signal */ +#define LSM9DS1_STATUS_REG_INACT (1 << 4) /* Inactivity interrupt output signal */ +#define LSM9DS1_STATUS_REG_IG_G (1 << 5) /* Gyroscope interrupt output signal */ +#define LSM9DS1_STATUS_REG_IG_XL (1 << 6) /* Accelerometer interrupt output signal */ + +/* Control register 4 */ + +#define LSM9DS1_CTRL_REG4_4D_XL1 (1 << 0) /* 4D option enabled on interrupt */ +#define LSM9DS1_CTRL_REG4_LIR_XL1 (1 << 1) /* Latched interrupt */ +#define LSM9DS1_CTRL_REG4_XEN_G (1 << 3) /* Gyroscope's pitch axis (X) output enable */ +#define LSM9DS1_CTRL_REG4_YEN_G (1 << 4) /* Gyroscope's roll axis (Y) output enable */ +#define LSM9DS1_CTRL_REG4_ZEN_G (1 << 5) /* Gyroscope's yaw axis (Z) output enable */ + +/* Accelerometer control register 5 */ + +#define LSM9DS1_CTRL_REG5_XL_XEN_XL (1 << 3) /* Accelerometer's X-axis output enable */ +#define LSM9DS1_CTRL_REG5_XL_YEN_XL (1 << 4) /* Accelerometer's Y-axis output enable */ +#define LSM9DS1_CTRL_REG5_XL_ZEN_XL (1 << 5) /* Accelerometer's Z-axis output enable */ +#define LSM9DS1_CTRL_REG5_XL_DEC_SHIFT 6 /* Decimation of acceleration data on OUT REG and FIFO */ +#define LSM9DS1_CTRL_REG5_XL_DEC_MASK (3 << LSM9DS1_CTRL_REG5_XL_DEC_SHIFT) +# define LSM9DS1_CTRL_REG5_XL_DEC_NODEC (0 << LSM9DS1_CTRL_REG5_XL_DEC_SHIFT) /* No decimation */ +# define LSM9DS1_CTRL_REG5_XL_DEC_2SAMPLES (1 << LSM9DS1_CTRL_REG5_XL_DEC_SHIFT) /* Update every 2 samples */ +# define LSM9DS1_CTRL_REG5_XL_DEC_4SAMPLES (2 << LSM9DS1_CTRL_REG5_XL_DEC_SHIFT) /* Update every 4 samples */ +# define LSM9DS1_CTRL_REG5_XL_DEC_8SAMPLES (3 << LSM9DS1_CTRL_REG5_XL_DEC_SHIFT) /* Update every 8 samples */ + +/* Accelerometer control register 6 */ + +#define LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT 0 /* Anti-aliasing filter bandwidth selection */ +#define LSM9DS1_CTRL_REG6_XL_BW_XL_MASK (3 << LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT) +# define LSM9DS1_CTRL_REG6_XL_BW_XL_408HZ (0 << LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT) /* 408 Hz */ +# define LSM9DS1_CTRL_REG6_XL_BW_XL_211HZ (1 << LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT) /* 211 Hz */ +# define LSM9DS1_CTRL_REG6_XL_BW_XL_105HZ (2 << LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT) /* 105 Hz */ +# define LSM9DS1_CTRL_REG6_XL_BW_XL_50HZ (3 << LSM9DS1_CTRL_REG6_XL_BW_XL_SHIFT) /* 50 Hz */ +#define LSM9DS1_CTRL_REG6_XL_BW_SCAL_ODR (1 << 2) /* Bandwidth selection */ +#define LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT 3 /* Accelerometer full-scale selection */ +#define LSM9DS1_CTRL_REG6_XL_FS_XL_MASK (3 << LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT) +# define LSM9DS1_CTRL_REG6_XL_FS_XL_2G (0 << LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT) /* +/- 2 g */ +# define LSM9DS1_CTRL_REG6_XL_FS_XL_16G (1 << LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT) /* +/- 16 g */ +# define LSM9DS1_CTRL_REG6_XL_FS_XL_4G (2 << LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT) /* +/- 4 g */ +# define LSM9DS1_CTRL_REG6_XL_FS_XL_8G (3 << LSM9DS1_CTRL_REG6_XL_FS_XL_SHIFT) /* +/- 8 g */ +#define LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT 5 /* Output data rate and power mode selection */ +#define LSM9DS1_CTRL_REG6_XL_ODR_XL_MASK (7 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_POWERDOWN (0 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* Power-down mode */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_10HZ (1 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 10 Hz */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_50HZ (2 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 50 Hz */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_119HZ (3 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 119 Hz */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_238HZ (4 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 238 Hz */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_476HZ (5 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 476 Hz */ +# define LSM9DS1_CTRL_REG6_XL_ODR_XL_952HZ (6 << LSM9DS1_CTRL_REG6_XL_ODR_XL_SHIFT) /* 952 Hz */ + +/* Accelerometer control register 7 */ + +#define LSM9DS1_CTRL_REG7_XL_HPIS1 (1 << 0) /* High-pass filter enabled */ +#define LSM9DS1_CTRL_REG7_XL_FDS (1 << 2) /* Filtered data selection */ +#define LSM9DS1_CTRL_REG7_XL_DCF_SHIFT 5 /* Accelerometer digital filter cutoff frequency selection */ +#define LSM9DS1_CTRL_REG7_XL_DCF_MASK (3 << LSM9DS1_CTRL_REG7_XL_DCF_SHIFT) +# define LSM9DS1_CTRL_REG7_XL_DCF_ODR_DIV50 (0 << LSM9DS1_CTRL_REG7_XL_DCF_SHIFT) +# define LSM9DS1_CTRL_REG7_XL_DCF_ODR_DIV100 (1 << LSM9DS1_CTRL_REG7_XL_DCF_SHIFT) +# define LSM9DS1_CTRL_REG7_XL_DCF_ODR_DIV9 (2 << LSM9DS1_CTRL_REG7_XL_DCF_SHIFT) +# define LSM9DS1_CTRL_REG7_XL_DCF_ODR_DIV400 (3 << LSM9DS1_CTRL_REG7_XL_DCF_SHIFT) +#define LSM9DS1_CTRL_REG7_XL_HR (1 << 7) /* High resolution mode enable */ + +/* Control register 8 */ + +#define LSM9DS1_CTRL_REG8_SW_RESET (1 << 0) /* Software reset */ +#define LSM9DS1_CTRL_REG8_BLE (1 << 1) /* Big/little endian data selection */ +#define LSM9DS1_CTRL_REG8_IF_ADD_INC (1 << 2) /* Register address automatically incremented during a multibyte access */ +#define LSM9DS1_CTRL_REG8_SIM (1 << 3) /* SPI serial interface mode selection */ +#define LSM9DS1_CTRL_REG8_PP_OD (1 << 4) /* Push-pull/open-drain selection on the INT1_A/G and INT2_A/G pins */ +#define LSM9DS1_CTRL_REG8_H_LACTIVE (1 << 5) /* Interrupt activation level */ +#define LSM9DS1_CTRL_REG8_BDU (1 << 6) /* Block data update */ +#define LSM9DS1_CTRL_REG8_BOOT (1 << 7) /* Reboot memory content */ + +/* Control register 9 */ + +#define LSM9DS1_CTRL_REG9_STOP_ON_FTH (1 << 0) /* Enable FIFO threshold level use */ +#define LSM9DS1_CTRL_REG9_FIFO_EN (1 << 1) /* FIFO memory enable */ +#define LSM9DS1_CTRL_REG9_I2C_DISABLE (1 << 2) /* Disable I2C interface */ +#define LSM9DS1_CTRL_REG9_DRDY_MASK_BIT (1 << 3) /* Data available enable bit */ +#define LSM9DS1_CTRL_REG9_FIFO_TEMP_EN (1 << 4) /* Temperature data storage in FIFO enable */ +#define LSM9DS1_CTRL_REG9_SLEEP_G (1 << 6) /* Gyroscope sleep mode enable */ + +/* Control register 10 */ + +#define LSM9DS1_CTRL_REG10_ST_XL (1 << 0) /* Linear acceleration sensor self-test enable */ +#define LSM9DS1_CTRL_REG10_ST_G (1 << 2) /* Angular rate sensor self-test enable */ + +/* Accelerometer interrupt source register */ + +#define LSM9DS1_INT_GEN_SRC_XL_XL_XL (1 << 0) /* Accelerometer's X low event */ +#define LSM9DS1_INT_GEN_SRC_XL_XH_XL (1 << 1) /* Accelerometer's X high event */ +#define LSM9DS1_INT_GEN_SRC_XL_YL_XL (1 << 2) /* Accelerometer's Y low event */ +#define LSM9DS1_INT_GEN_SRC_XL_YH_XL (1 << 3) /* Accelerometer's Y high event */ +#define LSM9DS1_INT_GEN_SRC_XL_ZL_XL (1 << 4) /* Accelerometer's Z low event */ +#define LSM9DS1_INT_GEN_SRC_XL_ZH_XL (1 << 5) /* Accelerometer's Z high event */ +#define LSM9DS1_INT_GEN_SRC_XL_IA_XL (1 << 6) /* Interrupt active */ + +/* Status register 2 */ + +#define LSM9DS1_STATUS_REG2_XLDA (1 << 0) /* Accelerometer new data available */ +#define LSM9DS1_STATUS_REG2_GDA (1 << 1) /* Gyroscope new data available */ +#define LSM9DS1_STATUS_REG2_TDA (1 << 2) /* Temperature sensor new data available */ +#define LSM9DS1_STATUS_REG2_BOOT_STATUS (1 << 3) /* Boot running flag signal */ +#define LSM9DS1_STATUS_REG2_INACT (1 << 4) /* Inactivity interrupt output signal */ +#define LSM9DS1_STATUS_REG2_IG_G (1 << 5) /* Gyroscope interrupt output signal */ +#define LSM9DS1_STATUS_REG2_IG_XL (1 << 6) /* Accelerometer interrupt output signal */ + +/* FIFO control register */ + +#define LSM9DS1_FIFO_CTRL_FTH_SHIFT 0 /* FIFO threshold level setting */ +#define LSM9DS1_FIFO_CTRL_FTH_MASK (31 << LSM9DS1_FIFO_CTRL_FTH_SHIFT) +#define LSM9DS1_FIFO_CTRL_FMODE_SHIFT 5 /* FIFO mode selection bits */ +#define LSM9DS1_FIFO_CTRL_FMODE_MASK (7 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) +# define LSM9DS1_FIFO_CTRL_FMODE_BYPASS (0 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) /* Bypass mode */ +# define LSM9DS1_FIFO_CTRL_FMODE_FIFO (1 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) /* FIFO mode */ +# define LSM9DS1_FIFO_CTRL_FMODE_CONT_FIFO (3 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) /* Continuous-to-FIFO mode */ +# define LSM9DS1_FIFO_CTRL_FMODE_BYPASS_CONT (4 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) /* Bypass-to-continuous mode */ +# define LSM9DS1_FIFO_CTRL_FMODE_CONT (5 << LSM9DS1_FIFO_CTRL_FMODE_SHIFT) /* Continuous mode */ + +/* FIFO status control register */ + +#define LSM9DS1_FIFO_SRC_FSS_SHIFT 0 /* Number of unread samples stored into FIFO */ +#define LSM9DS1_FIFO_SRC_FSS_MASK (63 << LSM9DS1_FIFO_SRC_FSS_SHIFT) +#define LSM9DS1_FIFO_SRC_OVRN (1 << 6) /* FIFO overrun status */ +#define LSM9DS1_FIFO_SRC_FTH (1 << 7) /* FIFO threshold status */ + +/* Gyroscope interrupt configuration register */ + +#define LSM9DS1_INT_GEN_CFG_G_XLIE_G (1 << 0) /* Pitch (X) axis low event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_XHIE_G (1 << 1) /* Pitch (X) axis high event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_YLIE_G (1 << 2) /* Roll (Y) axis low event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_YHIE_G (1 << 3) /* Roll (Y) axis high event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_ZLIE_G (1 << 4) /* Yaw (Z) axis low event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_ZHIE_G (1 << 5) /* Yaw (Z) axis high event interrupt enable */ +#define LSM9DS1_INT_GEN_CFG_G_LIR_G (1 << 6) /* Latch interrupt request */ +#define LSM9DS1_INT_GEN_CFG_G_AOI_G (1 << 7) /* AND/OR combination of interrupt events */ + +/* Gyroscope interrupt threshold registers */ + +#define LSM9DS1_INT_GEN_THS_XH_G_THS_XH_G_SHIFT 0 /* X interrupt threshold high byte */ +#define LSM9DS1_INT_GEN_THS_XH_G_THS_XH_G_MASK (127 << LSM9DS1_INT_GEN_THS_XH_G_THS_XH_G_SHIFT) +#define LSM9DS1_INT_GEN_THS_XH_G_DCRM_G (1 << 7) /* Decrement or reset counter mode selection */ + +/* Gyroscope interrupt duration register */ + +#define LSM9DS1_INT_GEN_DUR_G_DUR_G_SHIFT 0 /* Enter/exit interrupt duration */ +#define LSM9DS1_INT_GEN_DUR_G_DUR_G_MASK (127 << LSM9DS1_INT_GEN_DUR_G_DUR_G_SHIFT) +#define LSM9DS1_INT_GEN_DUR_G_WAIT_G (1 << 7) /* Exit from interrupt wait function enable */ + +/* Device identification register */ + +#define LSM9DS1_WHO_AM_I_M_VALUE 0x3d + +/* Magnetometer control register 1 */ + +#define LSM9DS1_CTRL_REG1_M_ST (1 << 0) /* Self-test enable */ +#define LSM9DS1_CTRL_REG1_M_FAST_ODR (1 << 1) /* Enable data rates higher than 80 Hz */ +#define LSM9DS1_CTRL_REG1_M_DO_SHIFT 2 /* Output data rate selection */ +#define LSM9DS1_CTRL_REG1_M_DO_MASK (7 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) +# define LSM9DS1_CTRL_REG1_M_DO_0p625HZ (0 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 0.625 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_1p25HZ (1 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 1.25 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_2p5HZ (2 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 2.5 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_5HZ (3 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 5 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_10HZ (4 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 10 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_20HZ (5 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 20 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_40HZ (6 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 40 Hz */ +# define LSM9DS1_CTRL_REG1_M_DO_80HZ (7 << LSM9DS1_CTRL_REG1_M_DO_SHIFT) /* 80 Hz */ +#define LSM9DS1_CTRL_REG1_M_OM_SHIFT 5 /* X and Y axes operative mode selection */ +#define LSM9DS1_CTRL_REG1_M_OM_MASK (3 << LSM9DS1_CTRL_REG1_M_OM_SHIFT) +# define LSM9DS1_CTRL_REG1_M_OM_LOW (0 << LSM9DS1_CTRL_REG1_M_OM_SHIFT) /* Low-power mode */ +# define LSM9DS1_CTRL_REG1_M_OM_MEDIUM (1 << LSM9DS1_CTRL_REG1_M_OM_SHIFT) /* Medium-performance mode */ +# define LSM9DS1_CTRL_REG1_M_OM_HIGH (2 << LSM9DS1_CTRL_REG1_M_OM_SHIFT) /* High-performance mode */ +# define LSM9DS1_CTRL_REG1_M_OM_ULTRAHIGH (3 << LSM9DS1_CTRL_REG1_M_OM_SHIFT) /* Ultra-high performance mode */ +#define LSM9DS1_CTRL_REG1_M_TEMP_COMP (1 << 7) /* Temperature compensation enable */ + +/* Magnetometer control register 2 */ + +#define LSM9DS1_CTRL_REG2_M_SOFT_RST (1 << 2) /* Configuration register and user register reset */ +#define LSM9DS1_CTRL_REG2_M_REBOOT (1 << 3) /* Reboot memory content */ +#define LSM9DS1_CTRL_REG2_M_FS_SHIFT 5 /* Full-scale configuration */ +#define LSM9DS1_CTRL_REG2_M_FS_MASK (3 << LSM9DS1_CTRL_REG2_M_FS_SHIFT) +# define LSM9DS1_CTRL_REG2_M_FS_4GAUSS (0 << LSM9DS1_CTRL_REG2_M_FS_SHIFT) /* +/- 4 gauss */ +# define LSM9DS1_CTRL_REG2_M_FS_8GAUSS (1 << LSM9DS1_CTRL_REG2_M_FS_SHIFT) /* +/- 8 gauss */ +# define LSM9DS1_CTRL_REG2_M_FS_12GAUSS (2 << LSM9DS1_CTRL_REG2_M_FS_SHIFT) /* +/- 12 gauss */ +# define LSM9DS1_CTRL_REG2_M_FS_16GAUSS (3 << LSM9DS1_CTRL_REG2_M_FS_SHIFT) /* +/- 16 gauss */ + +/* Magnetometer control register 3 */ + +#define LSM9DS1_CTRL_REG3_M_MD_SHIFT 0 /* Operating mode selection */ +#define LSM9DS1_CTRL_REG3_M_MD_MASK (3 << LSM9DS1_CTRL_REG3_M_MD_SHIFT) +# define LSM9DS1_CTRL_REG3_M_MD_CONT (0 << LSM9DS1_CTRL_REG3_M_MD_SHIFT) /* Continuous-conversion mode */ +# define LSM9DS1_CTRL_REG3_M_MD_SINGLE (1 << LSM9DS1_CTRL_REG3_M_MD_SHIFT) /* Single-conversion mode */ +# define LSM9DS1_CTRL_REG3_M_MD_POWERDOWN (2 << LSM9DS1_CTRL_REG3_M_MD_SHIFT) /* Power-down mode */ +# define LSM9DS1_CTRL_REG3_M_MD_POWERDOWN2 (3 << LSM9DS1_CTRL_REG3_M_MD_SHIFT) /* Power-down mode */ +#define LSM9DS1_CTRL_REG3_M_SIM (1 << 2) /* SPI serial interface mode selection */ +#define LSM9DS1_CTRL_REG3_M_LP (1 << 5) /* Low-power mode configuration */ +#define LSM9DS1_CTRL_REG3_M_I2C_DISABLE (1 << 7) /* Disable I2C interface */ + +/* Magnetometer control register 4 */ + +#define LSM9DS1_CTRL_REG4_M_BLE (1 << 1) /* Big/little endian data selection */ +#define LSM9DS1_CTRL_REG4_M_OMZ_SHIFT 2 /* Z-axis operative mode selection */ +#define LSM9DS1_CTRL_REG4_M_OMZ_MASK (3 << LSM9DS1_CTRL_REG4_M_OMZ_SHIFT) +# define LSM9DS1_CTRL_REG4_M_OMZ_LOW (0 << LSM9DS1_CTRL_REG4_M_OMZ_SHIFT) /* Low-power mode */ +# define LSM9DS1_CTRL_REG4_M_OMZ_MEDIUM (1 << LSM9DS1_CTRL_REG4_M_OMZ_SHIFT) /* Medium-performance mode */ +# define LSM9DS1_CTRL_REG4_M_OMZ_HIGH (2 << LSM9DS1_CTRL_REG4_M_OMZ_SHIFT) /* High-performance mode */ +# define LSM9DS1_CTRL_REG4_M_OMZ_ULTRAHIGH (3 << LSM9DS1_CTRL_REG4_M_OMZ_SHIFT) /* Ultra-high performance mode */ + +/* Magnetometer control register 5 */ + +#define LSM9DS1_CTRL_REG5_M_BDU (1 << 6) /* Block data update */ +#define LSM9DS1_CTRL_REG5_M_FAST_READ (1 << 7) /* Fast read enable */ + +/* Magnetometer status register */ + +#define LSM9DS1_STATUS_REG_M_XDA (1 << 0) /* X-axis new data available */ +#define LSM9DS1_STATUS_REG_M_YDA (1 << 1) /* Y-axis new data available */ +#define LSM9DS1_STATUS_REG_M_ZDA (1 << 2) /* Z-axis new data available */ +#define LSM9DS1_STATUS_REG_M_ZYXDA (1 << 3) /* X, Y and Z-axis new data available */ +#define LSM9DS1_STATUS_REG_M_XOR (1 << 4) /* X-axis data overrun */ +#define LSM9DS1_STATUS_REG_M_YOR (1 << 5) /* Y-axis data overrun */ +#define LSM9DS1_STATUS_REG_M_ZOR (1 << 6) /* Z-axis data overrun */ +#define LSM9DS1_STATUS_REG_M_ZYXOR (1 << 7) /* X, Y and Z-axis data overrun */ + +/* Magnetometer interrupt configuration register */ + +#define LSM9DS1_INT_CFG_M_IEN (1 << 0) /* Interrupt enable on the INT_M pin */ +#define LSM9DS1_INT_CFG_M_IEL (1 << 1) /* Latch interrupt request */ +#define LSM9DS1_INT_CFG_M_IEA (1 << 2) /* Interrupt active configuration on INT_MAG */ +#define LSM9DS1_INT_CFG_M_ZIEN (1 << 5) /* Z-axis interrupt enable */ +#define LSM9DS1_INT_CFG_M_YIEN (1 << 6) /* Y-axis interrupt enable */ +#define LSM9DS1_INT_CFG_M_XIEN (1 << 7) /* X-axis interrupt enable */ + +/* Magnetometer interrupt source register */ + +#define LSM9DS1_INT_SRC_M_INT (1 << 0) /* Interrupt occurred */ +#define LSM9DS1_INT_SRC_M_MROI (1 << 1) /* Internal measurement range overflow */ +#define LSM9DS1_INT_SRC_M_NTH_Z (1 << 2) /* Value on Z-axis exceeds threshold on negative side */ +#define LSM9DS1_INT_SRC_M_NTH_Y (1 << 3) /* Value on Y-axis exceeds threshold on negative side */ +#define LSM9DS1_INT_SRC_M_NTH_X (1 << 4) /* Value on X-axis exceeds threshold on negative side */ +#define LSM9DS1_INT_SRC_M_PTH_Z (1 << 5) /* Value on Z-axis exceeds threshold on positive side */ +#define LSM9DS1_INT_SRC_M_PTH_Y (1 << 6) /* Value on Y-axis exceeds threshold on positive side */ +#define LSM9DS1_INT_SRC_M_PTH_X (1 << 7) /* Value on X-axis exceeds threshold on positive side */ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct lsm9ds1_dev_s; +struct lsm9ds1_ops_s +{ + CODE int (*config)(FAR struct lsm9ds1_dev_s *priv); + CODE int (*start)(FAR struct lsm9ds1_dev_s *priv); + CODE int (*stop)(FAR struct lsm9ds1_dev_s *priv); + CODE int (*setsamplerate)(FAR struct lsm9ds1_dev_s *priv, + uint32_t samplerate); + CODE int (*setfullscale)(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale); +}; + +struct lsm9ds1_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + + FAR const struct lsm9ds1_ops_s *ops; + + uint32_t samplerate; /* Output data rate */ + uint8_t datareg; /* Output data register of X low byte */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* I2C Helpers */ + +static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, + FAR uint8_t *regval); +static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, + uint8_t regval); +static int lsm9ds1_modifyreg8(FAR struct lsm9ds1_dev_s *priv, + uint8_t regaddr, uint8_t clearbits, + uint8_t setbits); + +/* Other Helpers */ + +static uint32_t lsm9ds1_midpoint(uint32_t a, uint32_t b); + +/* Accelerometer Operations */ + +static int lsm9ds1accelgyro_config(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1accel_start(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1accel_stop(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1accelgyro_setsamplerate(FAR struct lsm9ds1_dev_s *priv, + uint32_t samplerate); +static int lsm9ds1accel_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale); + +/* Gyroscope Operations */ + +static int lsm9ds1gyro_start(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1gyro_stop(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1gyro_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale); + +/* Magnetometer Operations */ + +static int lsm9ds1mag_config(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1mag_start(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1mag_stop(FAR struct lsm9ds1_dev_s *priv); +static int lsm9ds1mag_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale); +static int lsm9ds1mag_setsamplerate(FAR struct lsm9ds1_dev_s *priv, + uint32_t samplerate); + +/* Character Driver Methods */ + +static int lsm9ds1_open(FAR struct file *filep); +static int lsm9ds1_close(FAR struct file *filep); +static ssize_t lsm9ds1_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t lsm9ds1_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int lsm9ds1_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/* Common Register Function */ + +static int lsm9ds1_register(FAR const char *devpath, + FAR struct i2c_dev_s *i2c, uint8_t addr, + FAR const struct lsm9ds1_ops_s *ops, + uint8_t datareg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_fops = +{ + lsm9ds1_open, + lsm9ds1_close, + lsm9ds1_read, + lsm9ds1_write, + NULL, + lsm9ds1_ioctl, +#ifndef CONFIG_DISABLE_POLL + NULL, +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + NULL, +#endif +}; + +static const struct lsm9ds1_ops_s g_lsm9ds1accel_ops = +{ + lsm9ds1accelgyro_config, + lsm9ds1accel_start, + lsm9ds1accel_stop, + lsm9ds1accelgyro_setsamplerate, + lsm9ds1accel_setfullscale, +}; + +static const struct lsm9ds1_ops_s g_lsm9ds1gyro_ops = +{ + lsm9ds1accelgyro_config, + lsm9ds1gyro_start, + lsm9ds1gyro_stop, + lsm9ds1accelgyro_setsamplerate, + lsm9ds1gyro_setfullscale, +}; + +static const struct lsm9ds1_ops_s g_lsm9ds1mag_ops = +{ + lsm9ds1mag_config, + lsm9ds1mag_start, + lsm9ds1mag_stop, + lsm9ds1mag_setsamplerate, + lsm9ds1mag_setfullscale, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lsm9ds1_readreg8 + * + * Description: + * Read from an 8-bit register. + * + ****************************************************************************/ + +static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, + FAR uint8_t *regval) +{ + int ret; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + DEBUGASSERT(regval != NULL); + + /* Write the register address */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + /* Restart and read 8 bits from the register */ + + ret = I2C_READ(priv->i2c, regval, sizeof(*regval)); + if (ret < 0) + { + sndbg("I2C_READ failed: %d\n", ret); + return ret; + } + + snvdbg("addr: %02x value: %02x\n", regaddr, *regval); + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1_writereg8 + * + * Description: + * Write to an 8-bit register. + * + ****************************************************************************/ + +static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, + uint8_t regval) +{ + int ret; + uint8_t buffer[2]; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + /* Set up a 2-byte message to send */ + + buffer[0] = regaddr; + buffer[1] = regval; + + /* Write the register address followed by the data (no RESTART) */ + + I2C_SETADDRESS(priv->i2c, priv->addr, 7); + ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer)); + if (ret < 0) + { + sndbg("I2C_WRITE failed: %d\n", ret); + return ret; + } + + snvdbg("addr: %02x value: %02x\n", regaddr, regval); + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1_modifyreg8 + * + * Description: + * Modify an 8-bit register. + * + ****************************************************************************/ + +static int lsm9ds1_modifyreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, + uint8_t clearbits, uint8_t setbits) +{ + int ret; + uint8_t regval; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + ret = lsm9ds1_readreg8(priv, regaddr, ®val); + if (ret < 0) + { + sndbg("lsm9ds1_readreg8 failed: %d\n", ret); + return ret; + } + + regval &= ~clearbits; + regval |= setbits; + + ret = lsm9ds1_writereg8(priv, regaddr, regval); + if (ret < 0) + { + sndbg("lsm9ds1_writereg8 failed: %d\n", ret); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1_midpoint + * + * Description: + * Find the midpoint between two numbers. + * + ****************************************************************************/ + +static uint32_t lsm9ds1_midpoint(uint32_t a, uint32_t b) +{ + return (uint32_t)(((uint64_t)a + (uint64_t)b + (uint64_t)1) / (uint64_t)2); +} + +/**************************************************************************** + * Name: lsm9ds1accelgyro_config + * + * Description: + * Configure the accelerometer and gyroscope. + * + ****************************************************************************/ + +static int lsm9ds1accelgyro_config(FAR struct lsm9ds1_dev_s *priv) +{ + int ret; + uint8_t regval; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + /* Get the device identification */ + + ret = lsm9ds1_readreg8(priv, LSM9DS1_WHO_AM_I, ®val); + if (ret < 0) + { + sndbg("lsm9ds1_readreg8 failed: %d\n", ret); + return ret; + } + + if (regval != LSM9DS1_WHO_AM_I_VALUE) + { + sndbg("Invalid device identification %02x\n", regval); + return -ENODEV; + } + + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1accel_start + * + * Description: + * Start the accelerometer. + * + ****************************************************************************/ + +static int lsm9ds1accel_start(FAR struct lsm9ds1_dev_s *priv) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + if (priv->samplerate < lsm9ds1_midpoint(10, 50)) + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_10HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(50, 119)) + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_50HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(119, 238)) + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_119HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(238, 476)) + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_238HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(476, 952)) + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_476HZ; + } + else + { + setbits = LSM9DS1_CTRL_REG6_XL_ODR_XL_952HZ; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG6_XL, + LSM9DS1_CTRL_REG6_XL_ODR_XL_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1accel_stop + * + * Description: + * Stop the accelerometer. + * + ****************************************************************************/ + +static int lsm9ds1accel_stop(FAR struct lsm9ds1_dev_s *priv) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG6_XL, + LSM9DS1_CTRL_REG6_XL_ODR_XL_MASK, + LSM9DS1_CTRL_REG6_XL_ODR_XL_POWERDOWN); +} + +/**************************************************************************** + * Name: lsm9ds1accelgyro_setsamplerate + * + * Description: + * Set the accelerometer or gyroscope's sample rate. + * + ****************************************************************************/ + +static int lsm9ds1accelgyro_setsamplerate(FAR struct lsm9ds1_dev_s *priv, + uint32_t samplerate) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + priv->samplerate = samplerate; + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1accel_setfullscale + * + * Description: + * Set the accelerometer's full-scale range. + * + ****************************************************************************/ + +static int lsm9ds1accel_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + if (fullscale < lsm9ds1_midpoint(2, 4)) + { + setbits = LSM9DS1_CTRL_REG6_XL_FS_XL_2G; + } + else if (fullscale < lsm9ds1_midpoint(4, 8)) + { + setbits = LSM9DS1_CTRL_REG6_XL_FS_XL_4G; + } + else if (fullscale < lsm9ds1_midpoint(8, 16)) + { + setbits = LSM9DS1_CTRL_REG6_XL_FS_XL_8G; + } + else + { + setbits = LSM9DS1_CTRL_REG6_XL_FS_XL_16G; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG6_XL, + LSM9DS1_CTRL_REG6_XL_FS_XL_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1gyro_start + * + * Description: + * Start the gyroscope. + * + ****************************************************************************/ + +static int lsm9ds1gyro_start(FAR struct lsm9ds1_dev_s *priv) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + if (priv->samplerate < lsm9ds1_midpoint(14, 59)) + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_14p9HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(59, 119)) + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_59p5HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(119, 238)) + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_119HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(238, 476)) + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_238HZ; + } + else if (priv->samplerate < lsm9ds1_midpoint(476, 952)) + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_476HZ; + } + else + { + setbits = LSM9DS1_CTRL_REG1_G_ODR_G_952HZ; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG1_G, + LSM9DS1_CTRL_REG1_G_ODR_G_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1gyro_stop + * + * Description: + * Stop the gyroscope. + * + ****************************************************************************/ + +static int lsm9ds1gyro_stop(FAR struct lsm9ds1_dev_s *priv) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG1_G, + LSM9DS1_CTRL_REG1_G_ODR_G_MASK, + LSM9DS1_CTRL_REG1_G_ODR_G_POWERDOWN); +} + +/**************************************************************************** + * Name: lsm9ds1gyro_setfullscale + * + * Description: + * Set the gyroscope's full-scale range. + * + ****************************************************************************/ + +static int lsm9ds1gyro_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + if (fullscale < lsm9ds1_midpoint(245, 500)) + { + setbits = LSM9DS1_CTRL_REG1_G_FS_G_245DPS; + } + else if (fullscale < lsm9ds1_midpoint(500, 2000)) + { + setbits = LSM9DS1_CTRL_REG1_G_FS_G_500DPS; + } + else + { + setbits = LSM9DS1_CTRL_REG1_G_FS_G_2000DPS; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG1_G, + LSM9DS1_CTRL_REG1_G_FS_G_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1mag_config + * + * Description: + * Configure the magnetometer. + * + ****************************************************************************/ + +static int lsm9ds1mag_config(FAR struct lsm9ds1_dev_s *priv) +{ + int ret; + uint8_t regval; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + /* Get the device identification */ + + ret = lsm9ds1_readreg8(priv, LSM9DS1_WHO_AM_I_M, ®val); + if (ret < 0) + { + sndbg("lsm9ds1_readreg8 failed: %d\n", ret); + return ret; + } + + if (regval != LSM9DS1_WHO_AM_I_M_VALUE) + { + sndbg("Invalid device identification %02x\n", regval); + return -ENODEV; + } + + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1mag_start + * + * Description: + * Start the magnetometer. + * + ****************************************************************************/ + +static int lsm9ds1mag_start(FAR struct lsm9ds1_dev_s *priv) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG3_M, + LSM9DS1_CTRL_REG3_M_MD_MASK, + LSM9DS1_CTRL_REG3_M_MD_CONT); +} + +/**************************************************************************** + * Name: lsm9ds1mag_stop + * + * Description: + * Stop the magnetometer. + * + ****************************************************************************/ + +static int lsm9ds1mag_stop(FAR struct lsm9ds1_dev_s *priv) +{ + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG3_M, + LSM9DS1_CTRL_REG3_M_MD_MASK, + LSM9DS1_CTRL_REG3_M_MD_POWERDOWN2); +} + +/**************************************************************************** + * Name: lsm9ds1mag_setfullscale + * + * Description: + * Set the magnetometer's full-scale range. + * + ****************************************************************************/ + +static int lsm9ds1mag_setfullscale(FAR struct lsm9ds1_dev_s *priv, + uint32_t fullscale) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + if (fullscale < lsm9ds1_midpoint(4, 8)) + { + setbits = LSM9DS1_CTRL_REG2_M_FS_4GAUSS; + } + else if (fullscale < lsm9ds1_midpoint(8, 12)) + { + setbits = LSM9DS1_CTRL_REG2_M_FS_8GAUSS; + } + else if (fullscale < lsm9ds1_midpoint(12, 16)) + { + setbits = LSM9DS1_CTRL_REG2_M_FS_12GAUSS; + } + else + { + setbits = LSM9DS1_CTRL_REG2_M_FS_16GAUSS; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG2_M, + LSM9DS1_CTRL_REG2_M_FS_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1mag_setsamplerate + * + * Description: + * Set the magnetometer's sample rate. + * + ****************************************************************************/ + +static int lsm9ds1mag_setsamplerate(FAR struct lsm9ds1_dev_s *priv, + uint32_t samplerate) +{ + uint8_t setbits; + + /* Sanity check */ + + DEBUGASSERT(priv != NULL); + + /* The magnetometer can change its sample rate without exiting + * power-down mode, so we don't need to save the value for later, + * unlike the accelerometer and gyroscope. + */ + + if (samplerate < lsm9ds1_midpoint(0, 1)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_0p625HZ; + } + else if (samplerate < lsm9ds1_midpoint(1, 2)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_1p25HZ; + } + else if (samplerate < lsm9ds1_midpoint(2, 5)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_2p5HZ; + } + else if (samplerate < lsm9ds1_midpoint(5, 10)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_5HZ; + } + else if (samplerate < lsm9ds1_midpoint(10, 20)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_10HZ; + } + else if (samplerate < lsm9ds1_midpoint(20, 40)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_20HZ; + } + else if (samplerate < lsm9ds1_midpoint(40, 80)) + { + setbits = LSM9DS1_CTRL_REG1_M_DO_40HZ; + } + else + { + setbits = LSM9DS1_CTRL_REG1_M_DO_80HZ; + } + + return lsm9ds1_modifyreg8(priv, LSM9DS1_CTRL_REG1_M, + LSM9DS1_CTRL_REG1_M_DO_MASK, setbits); +} + +/**************************************************************************** + * Name: lsm9ds1_open + * + * Description: + * This method is called when the device is opened. + * + ****************************************************************************/ + +static int lsm9ds1_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1_close + * + * Description: + * This method is called when the device is closed. + * + ****************************************************************************/ + +static int lsm9ds1_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: lsm9ds1_read + * + * Description: + * The standard read method. + * + ****************************************************************************/ + +static ssize_t lsm9ds1_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + FAR struct inode *inode; + FAR struct lsm9ds1_dev_s *priv; + int ret; + size_t i; + size_t j; + size_t samplesize; + size_t nsamples; + uint16_t data; + FAR int16_t *ptr; + uint8_t regaddr; + uint8_t lo; + uint8_t hi; + + /* Sanity check */ + + DEBUGASSERT(filep != NULL); + inode = filep->f_inode; + + DEBUGASSERT(inode != NULL); + priv = (FAR struct lsm9ds1_dev_s *)inode->i_private; + + DEBUGASSERT(priv != NULL); + DEBUGASSERT(priv->datareg == LSM9DS1_OUT_X_L_G || + priv->datareg == LSM9DS1_OUT_X_L_XL || + priv->datareg == LSM9DS1_OUT_X_L_M); + DEBUGASSERT(buffer != NULL); + + samplesize = 3 * sizeof(*ptr); + nsamples = buflen / samplesize; + ptr = (FAR int16_t *)buffer; + + /* Get the requested number of samples */ + + for (i = 0; i < nsamples; i++) + { + /* Reset the register address to the X low byte register */ + + regaddr = priv->datareg; + + /* Read the X, Y and Z data */ + + for (j = 0; j < 3; j++) + { + /* Read the low byte */ + + ret = lsm9ds1_readreg8(priv, regaddr, &lo); + if (ret < 0) + { + sndbg("lsm9ds1_readreg8 failed: %d\n", ret); + return (ssize_t)ret; + } + + regaddr++; + + /* Read the high byte */ + + ret = lsm9ds1_readreg8(priv, regaddr, &hi); + if (ret < 0) + { + sndbg("lsm9ds1_readreg8 failed: %d\n", ret); + return (ssize_t)ret; + } + + regaddr++; + + /* The data is 16 bits in two's complement representation */ + + data = ((uint16_t)hi << 8) | (uint16_t)lo; + + /* The value is positive */ + + if (data < 0x8000) + { + ptr[j] = (int16_t)data; + } + + /* The value is negative, so find its absolute value by taking the + * two's complement + */ + + else if (data > 0x8000) + { + data = ~data + 1; + ptr[j] = -(int16_t)data; + } + + /* The value is negative and can't be represented as a positive + * int16_t value + */ + + else + { + ptr[j] = (int16_t)(-32768); + } + } + } + + return nsamples * samplesize; +} + +/**************************************************************************** + * Name: lsm9ds1_write + * + * Description: + * A dummy write method. + * + ****************************************************************************/ + +static ssize_t lsm9ds1_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: lsm9ds1_ioctl + * + * Description: + * The standard ioctl method. + * + ****************************************************************************/ + +static int lsm9ds1_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct lsm9ds1_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(filep != NULL); + inode = filep->f_inode; + + DEBUGASSERT(inode != NULL); + priv = (FAR struct lsm9ds1_dev_s *)inode->i_private; + + DEBUGASSERT(priv != NULL); + + /* Handle ioctl commands */ + + switch (cmd) + { + /* Start converting. Arg: None. */ + + case SNIOC_START: + ret = priv->ops->start(priv); + break; + + /* Stop converting. Arg: None. */ + + case SNIOC_STOP: + ret = priv->ops->stop(priv); + break; + + /* Set the sample rate. Arg: uint32_t value. */ + + case SNIOC_SETSAMPLERATE: + ret = priv->ops->setsamplerate(priv, (uint32_t)arg); + sndbg("sample rate: %08x ret: %d\n", (uint32_t)arg, ret); + break; + + /* Set the full-scale range. Arg: uint32_t value. */ + + case SNIOC_SETFULLSCALE: + ret = priv->ops->setfullscale(priv, (uint32_t)arg); + sndbg("full-scale range: %08x ret: %d\n", (uint32_t)arg, ret); + break; + + /* Unrecognized commands */ + + default: + sndbg("Unrecognized cmd: %d arg: %lu\n", cmd, arg); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Name: lsm9ds1_register + * + * Description: + * Register the LSM9DS1 accelerometer, gyroscope or magnetometer character + * device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/accel0", + * "/dev/gyro0" or "/dev/mag0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 accelerometer, gyroscope or + * magnetometer. + * ops - The device operations structure. + * datareg - The register address of the low byte of the X-coordinate data. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int lsm9ds1_register(FAR const char *devpath, + FAR struct i2c_dev_s *i2c, uint8_t addr, + FAR const struct lsm9ds1_ops_s *ops, + uint8_t datareg) +{ + FAR struct lsm9ds1_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(devpath != NULL); + DEBUGASSERT(i2c != NULL); + DEBUGASSERT(datareg == LSM9DS1_OUT_X_L_XL || + datareg == LSM9DS1_OUT_X_L_G || + datareg == LSM9DS1_OUT_X_L_M); + + /* Initialize the device's structure */ + + priv = (FAR struct lsm9ds1_dev_s *)kmm_malloc(sizeof(*priv)); + if (priv == NULL) + { + sndbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + priv->ops = ops; + priv->samplerate = 0; + priv->datareg = datareg; + + /* Configure the device */ + + ret = priv->ops->config(priv); + if (ret < 0) + { + sndbg("Failed to configure device: %d\n", ret); + kmm_free(priv); + return ret; + } + + /* Register the character driver */ + + ret = register_driver(devpath, &g_fops, 0666, priv); + if (ret < 0) + { + sndbg("Failed to register driver: %d\n", ret); + kmm_free(priv); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lsm9ds1accel_register + * + * Description: + * Register the LSM9DS1 accelerometer character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/accel0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 accelerometer. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr) +{ + /* Sanity check */ + + DEBUGASSERT(addr == LSM9DS1ACCEL_ADDR0 || addr == LSM9DS1ACCEL_ADDR1); + + return lsm9ds1_register(devpath, i2c, addr, &g_lsm9ds1accel_ops, + LSM9DS1_OUT_X_L_XL); +} + +/**************************************************************************** + * Name: lsm9ds1gyro_register + * + * Description: + * Register the LSM9DS1 gyroscope character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/gyro0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 gyroscope. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr) +{ + /* Sanity check */ + + DEBUGASSERT(addr == LSM9DS1GYRO_ADDR0 || addr == LSM9DS1GYRO_ADDR1); + + return lsm9ds1_register(devpath, i2c, addr, &g_lsm9ds1gyro_ops, + LSM9DS1_OUT_X_L_G); +} + +/**************************************************************************** + * Name: lsm9ds1mag_register + * + * Description: + * Register the LSM9DS1 magnetometer character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/mag0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 magnetometer. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr) +{ + /* Sanity check */ + + DEBUGASSERT(addr == LSM9DS1MAG_ADDR0 || addr == LSM9DS1MAG_ADDR1); + + return lsm9ds1_register(devpath, i2c, addr, &g_lsm9ds1mag_ops, + LSM9DS1_OUT_X_L_M); +} + +#endif /* CONFIG_I2C && CONFIG_SN_LSM9DS1 */ diff --git a/include/nuttx/sensors/lsm9ds1.h b/include/nuttx/sensors/lsm9ds1.h new file mode 100644 index 0000000000..d69ca9e808 --- /dev/null +++ b/include/nuttx/sensors/lsm9ds1.h @@ -0,0 +1,151 @@ +/**************************************************************************** + * include/nuttx/sensors/lsm9ds1.h + * + * Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_LSM9DS1 +#define __INCLUDE_NUTTX_SENSORS_LSM9DS1 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_SN_LSM9DS1) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* IOCTL Commands ***********************************************************/ + +#define SNIOC_START _SNIOC(0x0001) /* Arg: None */ +#define SNIOC_STOP _SNIOC(0x0002) /* Arg: None */ +#define SNIOC_SETSAMPLERATE _SNIOC(0x0003) /* Arg: uint32_t value */ +#define SNIOC_SETFULLSCALE _SNIOC(0x0004) /* Arg: uint32_t value */ + +/* I2C Addresses ************************************************************/ +/* Accelerometer addresses */ + +#define LSM9DS1ACCEL_ADDR0 0x6a +#define LSM9DS1ACCEL_ADDR1 0x6b + +/* Gyroscope addresses */ + +#define LSM9DS1GYRO_ADDR0 LSM9DS1ACCEL_ADDR0 +#define LSM9DS1GYRO_ADDR1 LSM9DS1ACCEL_ADDR1 + +/* Magnetometer addresses */ + +#define LSM9DS1MAG_ADDR0 0x1c +#define LSM9DS1MAG_ADDR1 0x1e + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_dev_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/**************************************************************************** + * Name: lsm9ds1accel_register + * + * Description: + * Register the LSM9DS1 accelerometer character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/accel0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 accelerometer. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr); + +/**************************************************************************** + * Name: lsm9ds1gyro_register + * + * Description: + * Register the LSM9DS1 gyroscope character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/gyro0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 gyroscope. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr); + +/**************************************************************************** + * Name: lsm9ds1mag_register + * + * Description: + * Register the LSM9DS1 magnetometer character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register, e.g., "/dev/mag0". + * i2c - An I2C driver instance. + * addr - The I2C address of the LSM9DS1 magnetometer. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, + uint8_t addr); + +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_SN_LSM9DS1 */ +#endif /* __INCLUDE_NUTTX_SENSORS_LSM9DS1 */ -- GitLab From b54cf004f3f4cded98a11aad3f7cfc6f97e9ced3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 17 Jan 2016 15:15:01 -0600 Subject: [PATCH 561/858] Update ChangeLog --- ChangeLog | 6 ++++++ drivers/sensors/Make.defs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d532de18ce..4efe7f077f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11312,3 +11312,9 @@ from Lok Tep (2016-01-15). * configs/lpc4337-ws: Support for the WaveShare LPC4337-WS board. From Lok Tep (2016-01-15). + * drivers/wireless/pn532.c: Add driver for the NXP pn532 NFC-chip. From + Janne Rosberg and others at Offcode Ltd (2016-01-17). + * drivers/sensors/lsm9ds1.c: Add driver for the STMicro LSM9DS1 chip. + The LSM9DS1 is a system-in-package featuring a 3D digital linear + acceleration sensor, a 3D digital angular rate sensor, and a 3D + digital magnetic sensor. From Paul Alexander Patience (2016-01-17). diff --git a/drivers/sensors/Make.defs b/drivers/sensors/Make.defs index 902194a95e..ca0912d095 100644 --- a/drivers/sensors/Make.defs +++ b/drivers/sensors/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # drivers/sensors/Make.defs # -# Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2015-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without -- GitLab From 60bb90cdedac064d5747323dad062775b35f5c6a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 18 Jan 2016 08:04:25 -0600 Subject: [PATCH 562/858] Update README, Changelog, submodules --- ChangeLog | 3 +++ Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4efe7f077f..0df47e3039 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11318,3 +11318,6 @@ The LSM9DS1 is a system-in-package featuring a 3D digital linear acceleration sensor, a 3D digital angular rate sensor, and a 3D digital magnetic sensor. From Paul Alexander Patience (2016-01-17). + * configs/olimex-stm32-h407: Added a port to the Olimex STM32 H407 + board. This board features the STMicro STM32F407ZGT6 (144 pins). + Contributed by Neil Hancock. (2016-01-18) diff --git a/Documentation b/Documentation index 3a2794d91b..fe9faae374 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 3a2794d91b40d09e13bf6882b12c121f75b1297b +Subproject commit fe9faae374c6803518530f218cb15db552350e9b diff --git a/README.txt b/README.txt index ac996d21f4..13e9d8db56 100644 --- a/README.txt +++ b/README.txt @@ -1360,6 +1360,8 @@ nuttx/ | | `- README.txt | |- olimex-stm32-h405/ | | `- README.txt + | |- olimex-stm32-h407/ + | | `- README.txt | |- olimex-stm32-p107/ | | `- README.txt | |- olimex-stm32-p207/ diff --git a/arch b/arch index 73c05e32bc..adcfd2f14c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 73c05e32bc594ba7b4b270f374e76fa38a6766eb +Subproject commit adcfd2f14c19d86292beb8c2dd9412d6f0040c3a diff --git a/configs b/configs index edf5f361a6..e4dd8d606f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit edf5f361a60ccf886d651ecba1fa730f483b6c83 +Subproject commit e4dd8d606f5feca506e251ae1b508094282dca7b -- GitLab From 7670936bbff5f42099ce6780ef4707d0abeae1ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 18 Jan 2016 08:13:26 -0600 Subject: [PATCH 563/858] Update ChangeLog and submodule --- ChangeLog | 3 +++ arch | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0df47e3039..f338ee1917 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11321,3 +11321,6 @@ * configs/olimex-stm32-h407: Added a port to the Olimex STM32 H407 board. This board features the STMicro STM32F407ZGT6 (144 pins). Contributed by Neil Hancock. (2016-01-18) + * arch/arm/src/stm32/stm32_otgfs/hs/host.c: Fix some backward + arguments to stm32_putreg(). Note by Hang Xu (2016-01-18). + diff --git a/arch b/arch index adcfd2f14c..5416a1d51b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit adcfd2f14c19d86292beb8c2dd9412d6f0040c3a +Subproject commit 5416a1d51b6e50303414d156accb236a4c6ba11e -- GitLab From da33ec6b2ed9f3a164f5d0f559b9693d0a966034 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Mon, 18 Jan 2016 12:22:27 -0600 Subject: [PATCH 564/858] CAN: Add more extensive error reporting information --- ChangeLog | 3 ++ arch | 2 +- drivers/Kconfig | 14 ++++++ include/nuttx/can.h | 104 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 109 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f338ee1917..5fb1d8f1a3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11323,4 +11323,7 @@ Contributed by Neil Hancock. (2016-01-18) * arch/arm/src/stm32/stm32_otgfs/hs/host.c: Fix some backward arguments to stm32_putreg(). Note by Hang Xu (2016-01-18). + * include/nuttx/can.h and several CAN drivers: Add more extensive + error reporting capaibility to the CAN interferace. From Frank + Benkert (21016-01-18). diff --git a/arch b/arch index 5416a1d51b..0ecb54e365 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5416a1d51b6e50303414d156accb236a4c6ba11e +Subproject commit 0ecb54e3650597c45b3e759a036e516be556c586 diff --git a/drivers/Kconfig b/drivers/Kconfig index 4d7d813edd..a51ac4549f 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -104,6 +104,20 @@ config CAN_EXTID Enables support for the 28-bit extended ID. Default Standard 11-bit IDs. +config ARCH_HAVE_CAN_ERRORS + bool + default n + +config CAN_ERRORS + bool "CAN error reporting" + default n + depends on ARCH_HAVE_CAN_ERRORS + ---help--- + Support CAN error reporting. If this option is selected then CAN + error reporting is enabled. In the event of an error, the ch_error + bit will be set in the CAN message and the following message payload + will include a more detailed description of certain errors. + config CAN_FD bool "CAN FD" default n diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 38f84a42ff..8367529fd4 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -207,19 +207,91 @@ /* CAN Error Indications ************************************************************/ -#define CAN_ERROR_SYSTEM (1 << 0) /* Bit 0: Driver internal error */ -#define CAN_ERROR_RXLOST (1 << 1) /* Bit 1: RX Message Lost */ -#define CAN_ERROR_TXLOST (1 << 2) /* Bit 2: TX Message Lost */ -#define CAN_ERROR_ACCESS (1 << 3) /* Bit 3: RAM Access Failure */ -#define CAN_ERROR_TIMEOUT (1 << 4) /* Bit 4: Timeout Occurred */ -#define CAN_ERROR_PASSIVE (1 << 5) /* Bit 5: Error Passive */ -#define CAN_ERROR_CRC (1 << 6) /* Bit 6: RX CRC Error */ -#define CAN_ERROR_BIT (1 << 7) /* Bit 7: Bit Error */ -#define CAN_ERROR_ACK (1 << 8) /* Bit 8: Acknowledge Error */ -#define CAN_ERROR_FORMAT (1 << 9) /* Bit 9: Format Error */ -#define CAN_ERROR_STUFF (1 << 10) /* Bit 10: Stuff Error */ - -#define CAN_ERROR_ALL (0x07ff) +#ifdef CONFIG_CAN_ERRORS +/* Bit settings in the ch_error field of the CAN error message */ + +# define CAN_ERROR_TXTIMEOUT (1 << 0) /* TX timeout */ +# define CAN_ERROR_LOSTARB (1 << 1) /* Lost arbitration (See CAN_ERROR0_* definitions) */ +# define CAN_ERROR_CONTROLLER (1 << 2) /* Controller error (See CAN_ERROR1_* definitions) */ +# define CAN_ERROR_PROTOCOL (1 << 3) /* Protocol error (see CAN_ERROR1_* and CAN_ERROR3_* definitions) */ +# define CAN_ERROR_TRANSCEIVER (1 << 4) /* Transceiver error (See CAN_ERROR4_* definitions) */ +# define CAN_ERROR_NOACK (1 << 5) /* No ACK received on transmission */ +# define CAN_ERROR_BUSOFF (1 << 6) /* Bus off */ +# define CAN_ERROR_BUSERROR (1 << 7) /* Bus error */ +# define CAN_ERROR_RESTARTED (1 << 8) /* Controller restarted */ + +/* The remaining definitions described the error report payload that follows the + * CAN header. + */ + +# define CAN_ERROR_DLC (8) /* DLC of error report */ + +/* Data[0]: Arbitration lost in ch_error. */ + +# define CAN_ERROR0_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR0_BIT(n) (n) /* Bit number in the bit stream */ + +/* Data[1]: Error status of CAN-controller */ + +# define CAN_ERROR1_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR1_RXOVERFLOW (1 << 0) /* RX buffer overflow */ +# define CAN_ERROR1_TXOVERFLOW (1 << 1) /* TX buffer overflow */ +# define CAN_ERROR1_RXWARNING (1 << 2) /* Reached warning level for RX errors */ +# define CAN_ERROR1_TXWARNING (1 << 3) /* Reached warning level for TX errors */ +# define CAN_ERROR1_RXPASSIVE (1 << 4) /* Reached passive level for RX errors */ +# define CAN_ERROR1_TXPASSIVE (1 << 5) /* Reached passive level for TX errors */ + +/* Data[2]: Error in CAN protocol. This provides the type of the error. */ + +# define CAN_ERROR2_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR2_BIT (1 << 0) /* Single bit error */ +# define CAN_ERROR2_FORM (1 << 1) /* Frame format error */ +# define CAN_ERROR2_STUFF (1 << 2) /* Bit stuffing error */ +# define CAN_ERROR2_BIT0 (1 << 3) /* Unable to send dominant bit */ +# define CAN_ERROR2_BIT1 (1 << 4) /* Unable to send recessive bit */ +# define CAN_ERROR2_OVERLOAD (1 << 5) /* Bus overload */ +# define CAN_ERROR2_ACTIVE (1 << 6) /* Active error announcement */ +# define CAN_ERROR2_TX (1 << 7) /* Error occured on transmission */ + +/* Data[3]: Error in CAN protocol. This provides the loation of the error. */ + +# define CAN_ERROR3_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR3_SOF 0x01 /* start of frame */ +# define CAN_ERROR3_ID0 0x02 /* ID bits 0-4 */ +# define CAN_ERROR3_ID1 0x03 /* ID bits 5-12 */ +# define CAN_ERROR3_ID2 0x04 /* ID bits 13-17 */ +# define CAN_ERROR3_ID3 0x05 /* ID bits 21-28 */ +# define CAN_ERROR3_ID4 0x06 /* ID bits 18-20 */ +# define CAN_ERROR3_IDE 0x07 /* Identifier extension */ +# define CAN_ERROR3_RTR 0x08 /* RTR */ +# define CAN_ERROR3_SRTR 0x09 /* Substitute RTR */ +# define CAN_ERROR3_RES0 0x0a /* Reserved bit 0 */ +# define CAN_ERROR3_RES1 0x0b /* Reserved bit 1 */ +# define CAN_ERROR3_DLC 0x0c /* Data length code */ +# define CAN_ERROR3_DATA 0x0d /* Data section */ +# define CAN_ERROR3_CRCSEQ 0x0e /* CRC sequence */ +# define CAN_ERROR3_CRCDEL 0x0f /* CRC delimiter */ +# define CAN_ERROR3_ACK 0x10 /* ACK slot */ +# define CAN_ERROR3_ACKDEL 0x11 /* ACK delimiter */ +# define CAN_ERROR3_EOF 0x12 /* End of frame */ +# define CAN_ERROR3_INTERM 0x13 /* Intermission */ + +/* error status of CAN-transceiver / data[4] */ + +# define CAN_ERROR4_UNSPEC 0x00 + +# define CANH_ERROR4_NOWIRE 0x01 +# define CANH_ERROR4_SHORT2BAT 0x02 +# define CANH_ERROR4_SHORT2VCC 0x03 +# define CANH_ERROR4_SHORT2GND 0x04 + +# define CANL_ERROR4_NOWIRE 0x10 +# define CANL_ERROR4_SHORT2BAT 0x20 +# define CANL_ERROR4_SHORT2VCC 0x30 +# define CANL_ERROR4_SHORT2GND 0x40 +# define CANL_ERROR4_SHORT2CANH 0x50 + +#endif /* CONFIG_CAN_ERRORS */ /* CAN filter support ***************************************************************/ /* Some CAN hardware supports a notion of prioritizing messages that match filters. @@ -272,6 +344,8 @@ * NOTE: The error indication if valid only on message reports received from the * CAN driver; it is ignored on transmission. When the error bit is set, the * message ID is an encoded set of error indications (see CAN_ERROR_* definitions). + * A more detailed report of certain errors then follows in message payload. + * CONFIG_CAN_ERRORS=y is required in order to receive error reports. * * The struct can_msg_s holds this information in a user-friendly, unpacked form. * This is the form that is used at the read() and write() driver interfaces. The @@ -285,7 +359,9 @@ struct can_hdr_s uint32_t ch_id; /* 11- or 29-bit ID (20- or 3-bits unused) */ uint8_t ch_dlc : 4; /* 4-bit DLC */ uint8_t ch_rtr : 1; /* RTR indication */ +#ifdef CONFIG_CAN_ERRORS uint8_t ch_error : 1; /* 1=ch_id is an error report */ +#endif uint8_t ch_extid : 1; /* Extended ID indication */ uint8_t ch_unused : 1; /* Unused */ } packed_struct; @@ -295,7 +371,9 @@ struct can_hdr_s uint16_t ch_id; /* 11-bit standard ID (5-bits unused) */ uint8_t ch_dlc : 4; /* 4-bit DLC. May be encoded in CAN_FD mode. */ uint8_t ch_rtr : 1; /* RTR indication */ +#ifdef CONFIG_CAN_ERRORS uint8_t ch_error : 1; /* 1=ch_id is an error report */ +#endif uint8_t ch_unused : 2; /* Unused */ } packed_struct; #endif -- GitLab From e73ccd6638dd53d6eb7333fc3a6b2cd491fdc5c0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 18 Jan 2016 16:27:46 -0600 Subject: [PATCH 565/858] Update some comments --- include/nuttx/can.h | 126 +++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 8367529fd4..6f8b3d72aa 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -208,17 +208,18 @@ /* CAN Error Indications ************************************************************/ #ifdef CONFIG_CAN_ERRORS -/* Bit settings in the ch_error field of the CAN error message */ - -# define CAN_ERROR_TXTIMEOUT (1 << 0) /* TX timeout */ -# define CAN_ERROR_LOSTARB (1 << 1) /* Lost arbitration (See CAN_ERROR0_* definitions) */ -# define CAN_ERROR_CONTROLLER (1 << 2) /* Controller error (See CAN_ERROR1_* definitions) */ -# define CAN_ERROR_PROTOCOL (1 << 3) /* Protocol error (see CAN_ERROR1_* and CAN_ERROR3_* definitions) */ -# define CAN_ERROR_TRANSCEIVER (1 << 4) /* Transceiver error (See CAN_ERROR4_* definitions) */ -# define CAN_ERROR_NOACK (1 << 5) /* No ACK received on transmission */ -# define CAN_ERROR_BUSOFF (1 << 6) /* Bus off */ -# define CAN_ERROR_BUSERROR (1 << 7) /* Bus error */ -# define CAN_ERROR_RESTARTED (1 << 8) /* Controller restarted */ +/* Bit settings in the ch_id field of the CAN error message (when ch_error is set) */ + +# define CAN_ERROR_TXTIMEOUT (1 << 0) /* Bit 0: TX timeout */ +# define CAN_ERROR_LOSTARB (1 << 1) /* Bit 1: Lost arbitration (See CAN_ERROR0_* definitions) */ +# define CAN_ERROR_CONTROLLER (1 << 2) /* Bit 2: Controller error (See CAN_ERROR1_* definitions) */ +# define CAN_ERROR_PROTOCOL (1 << 3) /* Bit 3: Protocol error (see CAN_ERROR1_* and CAN_ERROR3_* definitions) */ +# define CAN_ERROR_TRANSCEIVER (1 << 4) /* Bit 4: Transceiver error (See CAN_ERROR4_* definitions) */ +# define CAN_ERROR_NOACK (1 << 5) /* Bit 5: No ACK received on transmission */ +# define CAN_ERROR_BUSOFF (1 << 6) /* Bit 6: Bus off */ +# define CAN_ERROR_BUSERROR (1 << 7) /* Bit 7: Bus error */ +# define CAN_ERROR_RESTARTED (1 << 8) /* Bit 8: Controller restarted */ + /* Bits 9-10: Available */ /* The remaining definitions described the error report payload that follows the * CAN header. @@ -234,62 +235,65 @@ /* Data[1]: Error status of CAN-controller */ # define CAN_ERROR1_UNSPEC 0x00 /* Unspecified error */ -# define CAN_ERROR1_RXOVERFLOW (1 << 0) /* RX buffer overflow */ -# define CAN_ERROR1_TXOVERFLOW (1 << 1) /* TX buffer overflow */ -# define CAN_ERROR1_RXWARNING (1 << 2) /* Reached warning level for RX errors */ -# define CAN_ERROR1_TXWARNING (1 << 3) /* Reached warning level for TX errors */ -# define CAN_ERROR1_RXPASSIVE (1 << 4) /* Reached passive level for RX errors */ -# define CAN_ERROR1_TXPASSIVE (1 << 5) /* Reached passive level for TX errors */ +# define CAN_ERROR1_RXOVERFLOW (1 << 0) /* Bit 0: RX buffer overflow */ +# define CAN_ERROR1_TXOVERFLOW (1 << 1) /* Bit 1: TX buffer overflow */ +# define CAN_ERROR1_RXWARNING (1 << 2) /* Bit 2: Reached warning level for RX errors */ +# define CAN_ERROR1_TXWARNING (1 << 3) /* Bit 3: Reached warning level for TX errors */ +# define CAN_ERROR1_RXPASSIVE (1 << 4) /* Bit 4: Reached passive level for RX errors */ +# define CAN_ERROR1_TXPASSIVE (1 << 5) /* Bit 5: Reached passive level for TX errors */ + /* Bits 6-7: Available */ /* Data[2]: Error in CAN protocol. This provides the type of the error. */ -# define CAN_ERROR2_UNSPEC 0x00 /* Unspecified error */ -# define CAN_ERROR2_BIT (1 << 0) /* Single bit error */ -# define CAN_ERROR2_FORM (1 << 1) /* Frame format error */ -# define CAN_ERROR2_STUFF (1 << 2) /* Bit stuffing error */ -# define CAN_ERROR2_BIT0 (1 << 3) /* Unable to send dominant bit */ -# define CAN_ERROR2_BIT1 (1 << 4) /* Unable to send recessive bit */ -# define CAN_ERROR2_OVERLOAD (1 << 5) /* Bus overload */ -# define CAN_ERROR2_ACTIVE (1 << 6) /* Active error announcement */ -# define CAN_ERROR2_TX (1 << 7) /* Error occured on transmission */ +# define CAN_ERROR2_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR2_BIT (1 << 0) /* Bit 0: Single bit error */ +# define CAN_ERROR2_FORM (1 << 1) /* Bit 1: Frame format error */ +# define CAN_ERROR2_STUFF (1 << 2) /* Bit 2: Bit stuffing error */ +# define CAN_ERROR2_BIT0 (1 << 3) /* Bit 3: Unable to send dominant bit */ +# define CAN_ERROR2_BIT1 (1 << 4) /* Bit 4: Unable to send recessive bit */ +# define CAN_ERROR2_OVERLOAD (1 << 5) /* Bit 5: Bus overload */ +# define CAN_ERROR2_ACTIVE (1 << 6) /* Bit 6: Active error announcement */ +# define CAN_ERROR2_TX (1 << 7) /* Bit 7: Error occured on transmission */ /* Data[3]: Error in CAN protocol. This provides the loation of the error. */ -# define CAN_ERROR3_UNSPEC 0x00 /* Unspecified error */ -# define CAN_ERROR3_SOF 0x01 /* start of frame */ -# define CAN_ERROR3_ID0 0x02 /* ID bits 0-4 */ -# define CAN_ERROR3_ID1 0x03 /* ID bits 5-12 */ -# define CAN_ERROR3_ID2 0x04 /* ID bits 13-17 */ -# define CAN_ERROR3_ID3 0x05 /* ID bits 21-28 */ -# define CAN_ERROR3_ID4 0x06 /* ID bits 18-20 */ -# define CAN_ERROR3_IDE 0x07 /* Identifier extension */ -# define CAN_ERROR3_RTR 0x08 /* RTR */ -# define CAN_ERROR3_SRTR 0x09 /* Substitute RTR */ -# define CAN_ERROR3_RES0 0x0a /* Reserved bit 0 */ -# define CAN_ERROR3_RES1 0x0b /* Reserved bit 1 */ -# define CAN_ERROR3_DLC 0x0c /* Data length code */ -# define CAN_ERROR3_DATA 0x0d /* Data section */ -# define CAN_ERROR3_CRCSEQ 0x0e /* CRC sequence */ -# define CAN_ERROR3_CRCDEL 0x0f /* CRC delimiter */ -# define CAN_ERROR3_ACK 0x10 /* ACK slot */ -# define CAN_ERROR3_ACKDEL 0x11 /* ACK delimiter */ -# define CAN_ERROR3_EOF 0x12 /* End of frame */ -# define CAN_ERROR3_INTERM 0x13 /* Intermission */ - -/* error status of CAN-transceiver / data[4] */ - -# define CAN_ERROR4_UNSPEC 0x00 - -# define CANH_ERROR4_NOWIRE 0x01 -# define CANH_ERROR4_SHORT2BAT 0x02 -# define CANH_ERROR4_SHORT2VCC 0x03 -# define CANH_ERROR4_SHORT2GND 0x04 - -# define CANL_ERROR4_NOWIRE 0x10 -# define CANL_ERROR4_SHORT2BAT 0x20 -# define CANL_ERROR4_SHORT2VCC 0x30 -# define CANL_ERROR4_SHORT2GND 0x40 -# define CANL_ERROR4_SHORT2CANH 0x50 +# define CAN_ERROR3_UNSPEC 0x00 /* Unspecified error */ +# define CAN_ERROR3_SOF 0x01 /* start of frame */ +# define CAN_ERROR3_ID0 0x02 /* ID bits 0-4 */ +# define CAN_ERROR3_ID1 0x03 /* ID bits 5-12 */ +# define CAN_ERROR3_ID2 0x04 /* ID bits 13-17 */ +# define CAN_ERROR3_ID3 0x05 /* ID bits 21-28 */ +# define CAN_ERROR3_ID4 0x06 /* ID bits 18-20 */ +# define CAN_ERROR3_IDE 0x07 /* Identifier extension */ +# define CAN_ERROR3_RTR 0x08 /* RTR */ +# define CAN_ERROR3_SRTR 0x09 /* Substitute RTR */ +# define CAN_ERROR3_RES0 0x0a /* Reserved bit 0 */ +# define CAN_ERROR3_RES1 0x0b /* Reserved bit 1 */ +# define CAN_ERROR3_DLC 0x0c /* Data length code */ +# define CAN_ERROR3_DATA 0x0d /* Data section */ +# define CAN_ERROR3_CRCSEQ 0x0e /* CRC sequence */ +# define CAN_ERROR3_CRCDEL 0x0f /* CRC delimiter */ +# define CAN_ERROR3_ACK 0x10 /* ACK slot */ +# define CAN_ERROR3_ACKDEL 0x11 /* ACK delimiter */ +# define CAN_ERROR3_EOF 0x12 /* End of frame */ +# define CAN_ERROR3_INTERM 0x13 /* Intermission */ + +/* Data[4]: Error status of CAN-transceiver */ + +# define CAN_ERROR4_UNSPEC 0x00 + +# define CANH_ERROR4_MASK 0x0f /* Bits 0-3: CANH */ +# define CANH_ERROR4_NOWIRE 0x01 +# define CANH_ERROR4_SHORT2BAT 0x02 +# define CANH_ERROR4_SHORT2VCC 0x03 +# define CANH_ERROR4_SHORT2GND 0x04 + +# define CANL_ERROR4_MASK 0xf0 /* Bits 0-3: CANL */ +# define CANL_ERROR4_NOWIRE 0x10 +# define CANL_ERROR4_SHORT2BAT 0x20 +# define CANL_ERROR4_SHORT2VCC 0x30 +# define CANL_ERROR4_SHORT2GND 0x40 +# define CANL_ERROR4_SHORT2CANH 0x50 #endif /* CONFIG_CAN_ERRORS */ -- GitLab From f849116a0bc953cc404711f86e4b26f6233d8082 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 19 Jan 2016 16:37:45 -0600 Subject: [PATCH 566/858] Add implementatino of Tiny Encryption Algorithm --- include/nuttx/crypto/tea.h | 77 ++++++++++++++++++++++++ libc/misc/Make.defs | 2 +- libc/misc/lib_tea.c | 119 +++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 include/nuttx/crypto/tea.h create mode 100644 libc/misc/lib_tea.c diff --git a/include/nuttx/crypto/tea.h b/include/nuttx/crypto/tea.h new file mode 100644 index 0000000000..1b568150a0 --- /dev/null +++ b/include/nuttx/crypto/tea.h @@ -0,0 +1,77 @@ +/**************************************************************************** + * include/nuttx/crypto/tea.h + * Tiny Encryption Algorithm + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm: "Following is + * an adaptation of the reference encryption and decryption routines in C, + * released into the public domain by David Wheeler and Roger Needham." + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_CRYPTO_TEA_H +#define __INCLUDE_NUTTX_CRYPTO_TEA_H 1 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: tea_encrypt + * + * Input Parameters: + * value = 2 x 32-bit value (input/output) + * key = 4 x 32-bit Cache key (input) + * + ****************************************************************************/ + +void tea_encrypt(FAR uint32_t *value, FAR const uint32_t *key); + +/**************************************************************************** + * Name: tea_decrypt + * + * Input Parameters: + * value = 2 x 32-bit value (input/output) + * key = 4 x 32-bit Cache key (input) + * + ****************************************************************************/ + +void tea_decrypt(FAR uint32_t *value, FAR const uint32_t *key); + +#endif /* __INCLUDE_NUTTX_CRYPTO_TEA_H */ + diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index b1260b29e3..7b53111e8d 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -35,7 +35,7 @@ # Add the internal C files to the build -CSRCS += lib_stream.c lib_filesem.c lib_utsname.c +CSRCS += lib_stream.c lib_filesem.c lib_utsname.c lib_tea.c # Add C files that depend on file OR socket descriptors diff --git a/libc/misc/lib_tea.c b/libc/misc/lib_tea.c new file mode 100644 index 0000000000..927357ff40 --- /dev/null +++ b/libc/misc/lib_tea.c @@ -0,0 +1,119 @@ +/**************************************************************************** + * libc/misc/lib_tea.c + * Tiny Encryption Algorithm + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm: "Following is + * an adaptation of the reference encryption and decryption routines in C, + * released into the public domain by David Wheeler and Roger Needham." + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TEA_KEY_SCHEDULE_CONSTANT 0x9e3779b9 +#define TEA_SUM_SETUP_CONSTANT 0xc6ef3720 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tea_encrypt + * + * Input Parameters: + * value = 2 x 32-bit value (input/output) + * key = 4 x 32-bit Cache key (input) + * + ****************************************************************************/ + +void tea_encrypt(FAR uint32_t *value, FAR const uint32_t *key) +{ + uint32_t v0 = value[0]; + uint32_t v1 = value[1]; + uint32_t sum = 0; + int i; + + /* Basic cycle start */ + + for (i = 0; i < 32; i++) + { + sum += TEA_KEY_SCHEDULE_CONSTANT; + v0 += ((v1 << 4) + key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); + v1 += ((v0 << 4) + key[2]) ^ (v0 + sum) ^ ((v0 >> 5) + key[3]); + } + + /* End cycle */ + + value[0] = v0; + value[1] = v1; +} + +/**************************************************************************** + * Name: tea_decrypt + * + * Input Parameters: + * value = 2 x 32-bit value (input/output) + * key = 4 x 32-bit Cache key (input) + * + ****************************************************************************/ + +void tea_decrypt(FAR uint32_t *value, FAR const uint32_t *key) +{ + uint32_t v0 = value[0]; + uint32_t v1 = value[1]; + uint32_t sum = TEA_SUM_SETUP_CONSTANT; + int i; + + /* Basic cycle start */ + + for (i = 0; i < 32; i++) + { + v1 -= ((v0 << 4) + key[2]) ^ (v0 + sum) ^ ((v0 >> 5) + key[3]); + v0 -= ((v1 << 4) + key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); + sum -= TEA_KEY_SCHEDULE_CONSTANT; + } + + /* End cycle */ + + value[0] = v0; + value[1] = v1; +} -- GitLab From f4f931c2a53de3f8c724edf97344cea5eb0d16fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 19 Jan 2016 16:38:48 -0600 Subject: [PATCH 567/858] Update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5fb1d8f1a3..6ec771ab7c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11326,4 +11326,6 @@ * include/nuttx/can.h and several CAN drivers: Add more extensive error reporting capaibility to the CAN interferace. From Frank Benkert (21016-01-18). + * libc/misc/lib_tea.h and include/nuttx/crypto/tea.h: Add an + implementation of the Tiny Encryption Algorithm (2016-01-19). -- GitLab From a60a822ef23e4e9e3d312a41ae35ef38de9a9d46 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 19 Jan 2016 16:46:25 -0600 Subject: [PATCH 568/858] Separate TEA encryption and decryption to separate files --- libc/misc/Make.defs | 3 +- libc/misc/{lib_tea.c => lib_tea_decrypt.c} | 35 +-------- libc/misc/lib_tea_encrypt.c | 88 ++++++++++++++++++++++ 3 files changed, 92 insertions(+), 34 deletions(-) rename libc/misc/{lib_tea.c => lib_tea_decrypt.c} (81%) create mode 100644 libc/misc/lib_tea_encrypt.c diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index 7b53111e8d..6c0a37ac7c 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -35,7 +35,8 @@ # Add the internal C files to the build -CSRCS += lib_stream.c lib_filesem.c lib_utsname.c lib_tea.c +CSRCS += lib_stream.c lib_filesem.c lib_utsname.c +CSRCS += lib_tea_encrypt.c lib_tea_decrypt.c # Add C files that depend on file OR socket descriptors diff --git a/libc/misc/lib_tea.c b/libc/misc/lib_tea_decrypt.c similarity index 81% rename from libc/misc/lib_tea.c rename to libc/misc/lib_tea_decrypt.c index 927357ff40..378407879e 100644 --- a/libc/misc/lib_tea.c +++ b/libc/misc/lib_tea_decrypt.c @@ -1,6 +1,6 @@ /**************************************************************************** - * libc/misc/lib_tea.c - * Tiny Encryption Algorithm + * libc/misc/lib_tea_decrypt.c + * Tiny Encryption Algorithm - Decryption support * * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -56,37 +56,6 @@ * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: tea_encrypt - * - * Input Parameters: - * value = 2 x 32-bit value (input/output) - * key = 4 x 32-bit Cache key (input) - * - ****************************************************************************/ - -void tea_encrypt(FAR uint32_t *value, FAR const uint32_t *key) -{ - uint32_t v0 = value[0]; - uint32_t v1 = value[1]; - uint32_t sum = 0; - int i; - - /* Basic cycle start */ - - for (i = 0; i < 32; i++) - { - sum += TEA_KEY_SCHEDULE_CONSTANT; - v0 += ((v1 << 4) + key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); - v1 += ((v0 << 4) + key[2]) ^ (v0 + sum) ^ ((v0 >> 5) + key[3]); - } - - /* End cycle */ - - value[0] = v0; - value[1] = v1; -} - /**************************************************************************** * Name: tea_decrypt * diff --git a/libc/misc/lib_tea_encrypt.c b/libc/misc/lib_tea_encrypt.c new file mode 100644 index 0000000000..7ea5e545f7 --- /dev/null +++ b/libc/misc/lib_tea_encrypt.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/misc/lib_tea_encrypt.c + * Tiny Encryption Algorithm - Encryption support + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm: "Following is + * an adaptation of the reference encryption and decryption routines in C, + * released into the public domain by David Wheeler and Roger Needham." + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TEA_KEY_SCHEDULE_CONSTANT 0x9e3779b9 +#define TEA_SUM_SETUP_CONSTANT 0xc6ef3720 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tea_encrypt + * + * Input Parameters: + * value = 2 x 32-bit value (input/output) + * key = 4 x 32-bit Cache key (input) + * + ****************************************************************************/ + +void tea_encrypt(FAR uint32_t *value, FAR const uint32_t *key) +{ + uint32_t v0 = value[0]; + uint32_t v1 = value[1]; + uint32_t sum = 0; + int i; + + /* Basic cycle start */ + + for (i = 0; i < 32; i++) + { + sum += TEA_KEY_SCHEDULE_CONSTANT; + v0 += ((v1 << 4) + key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); + v1 += ((v0 << 4) + key[2]) ^ (v0 + sum) ^ ((v0 >> 5) + key[3]); + } + + /* End cycle */ + + value[0] = v0; + value[1] = v1; +} -- GitLab From 2bd27c856c1bbe7706c071514fc7393ac0f23962 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 20 Jan 2016 12:31:28 -0600 Subject: [PATCH 569/858] Upate ChangeLog and README --- ChangeLog | 4 ++++ Documentation | 2 +- README.txt | 1 + arch | 2 +- configs | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ec771ab7c..d9764a3b2e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11328,4 +11328,8 @@ Benkert (21016-01-18). * libc/misc/lib_tea.h and include/nuttx/crypto/tea.h: Add an implementation of the Tiny Encryption Algorithm (2016-01-19). + * sim/include: Now supports a customizable startup script with a + read-only passwd file (2016-01-20). + * sim/nsh: Uses the custom start up script, includes hoks for + an MOTD message. (2016-01-20). diff --git a/Documentation b/Documentation index fe9faae374..24ac305ba0 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit fe9faae374c6803518530f218cb15db552350e9b +Subproject commit 24ac305ba0741997b756ef23a28c675a7b365838 diff --git a/README.txt b/README.txt index 13e9d8db56..4d0c53436c 100644 --- a/README.txt +++ b/README.txt @@ -1417,6 +1417,7 @@ nuttx/ | |- samv71-xult/ | | `- README.txt | |- sim/ + | | |- include/README.txt | | `- README.txt | |- shenzhou/ | | `- README.txt diff --git a/arch b/arch index 0ecb54e365..09b1721505 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0ecb54e3650597c45b3e759a036e516be556c586 +Subproject commit 09b1721505896b61b147e2fa25cab9ad532579cd diff --git a/configs b/configs index e4dd8d606f..9495be5119 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e4dd8d606f5feca506e251ae1b508094282dca7b +Subproject commit 9495be511983679867e898407f87d18a37ac72bd -- GitLab From 3a59eb4340eafe253c48492162c25e21dd31c357 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 20 Jan 2016 13:04:07 -0600 Subject: [PATCH 570/858] Fix romdisk_register prototype. Most ROMFS images actually lie in RAM. If moved to FLASH with const storage class, then changes are required to avoid warnings --- arch | 2 +- configs | 2 +- include/nuttx/fs/ramdisk.h | 4 ++-- tools/README.txt | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 09b1721505..09d21fd8e0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 09b1721505896b61b147e2fa25cab9ad532579cd +Subproject commit 09d21fd8e0b47fd0d6f7c32adf39b9b29dba9cd3 diff --git a/configs b/configs index 9495be5119..36aec1e67d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 9495be511983679867e898407f87d18a37ac72bd +Subproject commit 36aec1e67d0f2c877d3943c2c30297516ae051a1 diff --git a/include/nuttx/fs/ramdisk.h b/include/nuttx/fs/ramdisk.h index 8721839775..0f425c46aa 100644 --- a/include/nuttx/fs/ramdisk.h +++ b/include/nuttx/fs/ramdisk.h @@ -94,9 +94,9 @@ extern "C" #ifdef CONFIG_FS_WRITABLE int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors, uint16_t sectize, uint8_t rdflags); -#define romdisk_register(m,b,n,s) ramdisk_register(m,b,n,s,0) +#define romdisk_register(m,b,n,s) ramdisk_register(m,(FAR uint8_t *)b,n,s,0) #else -int romdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors, +int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors, uint16_t sectize); #endif diff --git a/tools/README.txt b/tools/README.txt index 7a9d013caa..d4acb034f5 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -393,6 +393,9 @@ mkromfsimg.sh image. It accepts an rcS script "template" and generates and image that may be mounted under /etc in the NuttX pseudo file system. + TIP: Edit the resulting header file and mark the generated data values + as 'const' so that they will be stored in FLASH. + mkdeps.c cnvwindeps.c mkwindeps.sh -- GitLab From 3986f6cdeebc40dffa67dd18e51f7c213a1c91e9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 20 Jan 2016 13:09:03 -0600 Subject: [PATCH 571/858] Part of last change was still in the editor --- drivers/ramdisk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ramdisk.c b/drivers/ramdisk.c index 39fbc8d807..09382dadd6 100644 --- a/drivers/ramdisk.c +++ b/drivers/ramdisk.c @@ -441,10 +441,10 @@ static int rd_unlink(FAR struct inode *inode) ****************************************************************************/ #ifdef CONFIG_FS_WRITABLE -int ramdisk_register(int minor, uint8_t *buffer, uint32_t nsectors, +int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors, uint16_t sectsize, uint8_t rdflags) #else -int romdisk_register(int minor, uint8_t *buffer, uint32_t nsectors, +int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors, uint16_t sectsize) #endif { -- GitLab From 350890d598dfed4916718f062c93d4955d68d6a7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 20 Jan 2016 14:37:39 -0600 Subject: [PATCH 572/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 36aec1e67d..f9cebd15f4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 36aec1e67d0f2c877d3943c2c30297516ae051a1 +Subproject commit f9cebd15f4871a6929e6859a8ccd87ba02538769 -- GitLab From cb7bbdfed464b9cede8407a6e8b53e20b359aecb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 08:55:29 -0600 Subject: [PATCH 573/858] Update submodules --- Documentation | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index 24ac305ba0..f080d80b68 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 24ac305ba0741997b756ef23a28c675a7b365838 +Subproject commit f080d80b68c7f98694ab9db8fad0e4d27e2436d7 diff --git a/configs b/configs index f9cebd15f4..6aa9bb01b7 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f9cebd15f4871a6929e6859a8ccd87ba02538769 +Subproject commit 6aa9bb01b7372bc44ff0718a9634d51e2732e918 -- GitLab From f348e6806972214d95d90cbe6098ae769cffb251 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 11:54:26 -0600 Subject: [PATCH 574/858] Update to use 64-bit timer when available --- drivers/mmcsd/mmcsd_sdio.c | 12 ++++---- drivers/mmcsd/mmcsd_spi.c | 18 +++++------ drivers/mtd/sst39vf.c | 8 ++--- drivers/net/enc28j60.c | 6 ++-- drivers/net/encx24j600.c | 10 +++--- drivers/net/slip.c | 4 +-- drivers/power/pm.h | 5 +-- drivers/power/pm_activity.c | 2 +- drivers/power/pm_checkstate.c | 4 +-- fs/procfs/fs_procfsuptime.c | 27 +++++----------- fs/vfs/fs_poll.c | 2 +- include/nuttx/clock.h | 49 ++++++++++++++++++++---------- include/nuttx/sched.h | 19 ++++++------ include/nuttx/semaphore.h | 5 +-- include/nuttx/wqueue.h | 8 +++-- include/sys/syscall.h | 6 +++- libc/wqueue/work_usrthread.c | 12 ++++---- net/icmp/icmp_ping.c | 6 ++-- net/icmpv6/icmpv6_ping.c | 6 ++-- net/neighbor/neighbor.h | 3 +- net/neighbor/neighbor_initialize.c | 2 +- net/neighbor/neighbor_periodic.c | 6 ++-- net/socket/net_close.c | 2 +- net/socket/net_sendfile.c | 4 +-- net/socket/net_timeo.c | 6 ++-- net/socket/recvfrom.c | 4 +-- net/socket/socket.h | 3 +- net/tcp/tcp_send_unbuffered.c | 4 +-- net/udp/udp_psock_sendto.c | 4 +-- sched/Kconfig | 2 +- sched/clock/clock_systimer.c | 8 ++--- sched/paging/pg_worker.c | 2 +- sched/sched/sched_sporadic.c | 4 +-- sched/semaphore/sem_tickwait.c | 6 ++-- sched/signal/sig_nanosleep.c | 8 ++--- sched/wqueue/kwork_process.c | 30 +++++------------- sched/wqueue/wqueue.h | 12 +++++--- syscall/syscall.csv | 3 +- syscall/syscall_clock_systimer.c | 13 ++++++-- syscall/syscall_funclookup.c | 6 +++- syscall/syscall_lookup.h | 6 +++- 41 files changed, 182 insertions(+), 165 deletions(-) diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index d8ae4561af..e3097d4812 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/mmcsd/mmcsd_sdio.c * - * Copyright (C) 2009-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1120,10 +1120,10 @@ static int mmcsd_eventwait(FAR struct mmcsd_state_s *priv, static int mmcsd_transferready(FAR struct mmcsd_state_s *priv) { - uint32_t starttime; - uint32_t elapsed; + systime_t starttime; + systime_t elapsed; uint32_t r1; - int ret; + int ret; /* First, check if the card has been removed. */ @@ -2714,9 +2714,9 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv) static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv) { uint32_t response; - uint32_t start; - uint32_t elapsed; uint32_t sdcapacity = MMCSD_ACMD41_STDCAPACITY; + systime_t start; + systime_t elapsed; int ret; /* Assume failure to identify the card */ diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index 7219648845..b5ab0cd8e3 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -443,8 +443,8 @@ static int mmcsd_waitready(FAR struct mmcsd_slot_s *slot) { FAR struct spi_dev_s *spi = slot->spi; uint8_t response; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; /* Wait until the card is no longer busy (up to 500MS) */ @@ -548,8 +548,8 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, case MMCSD_CMDRESP_R1B: { uint32_t busy = 0; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; start = START_TIME; do @@ -963,9 +963,9 @@ static int mmcsd_recvblock(FAR struct mmcsd_slot_s *slot, uint8_t *buffer, int nbytes) { FAR struct spi_dev_s *spi = slot->spi; - uint32_t start; - uint32_t elapsed; - uint8_t token; + systime_t start; + systime_t elapsed; + uint8_t token; /* Wait up to the maximum to receive a valid data token. taccess is the * time from when the command is sent until the first byte of data is @@ -1579,8 +1579,8 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) FAR struct spi_dev_s *spi = slot->spi; uint8_t csd[16]; uint32_t result = MMCSD_SPIR1_IDLESTATE; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; int i; int j; diff --git a/drivers/mtd/sst39vf.c b/drivers/mtd/sst39vf.c index e2fe862c9e..5386427587 100644 --- a/drivers/mtd/sst39vf.c +++ b/drivers/mtd/sst39vf.c @@ -417,8 +417,8 @@ static int sst39vf_chiperase(FAR struct sst39vf_dev_s *priv) { #if 0 struct sst39vf_wrinfo_s wrinfo; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; #endif /* Send the sequence to erase the chip */ @@ -488,8 +488,8 @@ static int sst39vf_sectorerase(FAR struct sst39vf_dev_s *priv, { struct sst39vf_wrinfo_s wrinfo; #if 0 - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; #endif /* Set up the sector address */ diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 4a940a71ee..b619c59b31 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/enc28j60.c * - * Copyright (C) 2010-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -750,8 +750,8 @@ static void enc_wrbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, uint8_t bits, uint8_t value) { - uint32_t start = clock_systimer(); - uint32_t elapsed; + systime_t start = clock_systimer(); + systime_t elapsed; uint8_t rddata; /* Loop until the exit condition is met */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 4de0d694ca..fcd36f87a0 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -679,8 +679,8 @@ static void enc_wrreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg, static int enc_waitreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg, uint16_t bits, uint16_t value) { - uint32_t start = clock_systimer(); - uint32_t elapsed; + systime_t start = clock_systimer(); + systime_t elapsed; uint16_t rddata; /* Loop until the exit condition is met */ @@ -1533,7 +1533,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) arp_ipin(&priv->dev); ret = ipv4_input(&priv->dev); - if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) + if (ret == OK || (clock_systimer() - (systime_t)descr->ts) > ENC_RXTIMEOUT) { /* If packet has been successfully processed or has timed out, * free it. @@ -1580,7 +1580,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) ret = ipv6_input(&priv->dev); - if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) + if (ret == OK || (clock_systimer() - (systime_t)descr->ts) > ENC_RXTIMEOUT) { /* If packet has been successfully processed or has timed out, * free it. @@ -1728,7 +1728,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) /* Set current timestamp */ - descr->ts = clock_systimer(); + descr->ts = (uint32_t)clock_systimer(); /* Store the start address of the frame without the enc's header */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 6026ec3d5b..d1ecef3aca 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -434,8 +434,8 @@ static void slip_txtask(int argc, FAR char *argv[]) FAR struct slip_driver_s *priv; unsigned int index = *(argv[1]) - '0'; net_lock_t flags; - unsigned int msec_start; - unsigned int msec_now; + systime_t msec_start; + systime_t msec_now; unsigned int hsec; ndbg("index: %d\n", index); diff --git a/drivers/power/pm.h b/drivers/power/pm.h index 8ed66d3d30..9df1ec5c0c 100644 --- a/drivers/power/pm.h +++ b/drivers/power/pm.h @@ -45,8 +45,9 @@ #include #include -#include +#include #include +#include #ifdef CONFIG_PM @@ -136,7 +137,7 @@ struct pm_global_s /* stime - The time (in ticks) at the start of the current time slice */ - uint32_t stime; + systime_t stime; /* This semaphore manages mutually exclusive access to the power management * registry. It must be initialized to the value 1. diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c index e15cc78b1e..2bf96b08c2 100644 --- a/drivers/power/pm_activity.c +++ b/drivers/power/pm_activity.c @@ -103,7 +103,7 @@ void pm_activity(int priority) { - uint32_t now; + systime_t now; uint32_t accum; irqstate_t flags; diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index 85f4415323..b085cbe0be 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/power/pm_checkstate.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -108,7 +108,7 @@ enum pm_state_e pm_checkstate(void) { - uint32_t now; + systime_t now; irqstate_t flags; /* Check for the end of the current time slice. This must be performed diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index c5f8c719a5..fd273badbb 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -212,23 +212,16 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, size_t linesize; off_t offset; ssize_t ret; - -#ifdef CONFIG_SYSTEM_TIME64 - uint64_t ticktime; -#if !defined(CONFIG_HAVE_DOUBLE) || !defined(CONFIG_LIBC_FLOATINGPOINT) - uint64_t sec; -#endif - -#else - uint32_t ticktime; -#if !defined(CONFIG_HAVE_DOUBLE) || !defined(CONFIG_LIBC_FLOATINGPOINT) - uint32_t sec; -#endif -#endif + systime ticktime; #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) double now; #else +# if defined(CONFIG_SYSTEM_TIME64) + uint64_t sec; +# else + uint32_t sec; +# endif unsigned int remainder; unsigned int csec; #endif @@ -249,15 +242,9 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, if (filep->f_pos == 0) { -#ifdef CONFIG_SYSTEM_TIME64 - /* 64-bit timer */ - - ticktime = clock_systimer64(); -#else - /* 32-bit timer */ + /* System time */ ticktime = clock_systimer(); -#endif #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) /* Convert the system up time to a seconds + hundredths of seconds string */ diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index f13148288c..2385f85a25 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/vfs/fs_poll.c * - * Copyright (C) 2008-2009, 2012-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 49659f04cb..cc6eccd14c 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -1,7 +1,8 @@ /**************************************************************************** * include/nuttx/clock.h * - * Copyright (C) 2007-2009, 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2014, 2016 Gregory Nutt. + All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -164,6 +165,14 @@ #define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ +/* Select the access to the system timer using its natural with */ + +#ifdef CONFIG_SYSTEM_TIME64 +# define clock_systimer() clock_systimer64() +#else +# define clock_systimer() clock_systimer32() +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -177,10 +186,26 @@ struct cpuload_s }; #endif +/* This type is the natural with of the system timer */ + +#ifdef CONFIG_SYSTEM_TIME64 +typedef uint64_t systime_t; +#else +typedef uint32_t systime_t; +#endif + /**************************************************************************** * Public Data ****************************************************************************/ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /* Access to raw system clock ***********************************************/ /* Direct access to the system timer/counter is supported only if (1) the * system timer counter is available (i.e., we are not configured to use @@ -191,14 +216,14 @@ struct cpuload_s #ifdef __HAVE_KERNEL_GLOBALS # ifdef CONFIG_SYSTEM_TIME64 -extern volatile uint64_t g_system_timer; -#define clock_systimer() (uint32_t)(g_system_timer & 0x00000000ffffffff) +EXTERN volatile uint64_t g_system_timer; +#define clock_systimer32() (uint32_t)(g_system_timer & 0x00000000ffffffff) #define clock_systimer64() g_system_timer # else -extern volatile uint32_t g_system_timer; -#define clock_systimer() g_system_timer +EXTERN volatile uint32_t g_system_timer; +#define clock_systimer32() g_system_timer # endif #endif @@ -207,14 +232,6 @@ extern volatile uint32_t g_system_timer; * Public Function Prototypes ****************************************************************************/ -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - /**************************************************************************** * Function: clock_synchronize * @@ -248,7 +265,7 @@ void clock_synchronize(void); #endif /**************************************************************************** - * Function: clock_systimer + * Function: clock_systimer32 * * Description: * Return the current value of the 32-bit system timer counter. Indirect @@ -268,9 +285,9 @@ void clock_synchronize(void); #ifndef __HAVE_KERNEL_GLOBALS # ifdef CONFIG_SYSTEM_TIME64 -# define clock_systimer() (uint32_t)(clock_systimer64() & 0x00000000ffffffff) +# define clock_systimer32() (uint32_t)(clock_systimer64() & 0x00000000ffffffff) # else -uint32_t clock_systimer(void); +uint32_t clock_systimer32(void); # endif #endif diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 07ec74cd82..b25f64e219 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -1,7 +1,7 @@ /******************************************************************************** * include/nuttx/sched.h * - * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -273,14 +274,14 @@ struct replenishment_s struct sporadic_s { - bool suspended; /* Thread is currently suspended */ - uint8_t hi_priority; /* Sporadic high priority */ - uint8_t low_priority; /* Sporadic low priority */ - uint8_t max_repl; /* Maximum number of replenishments */ - uint8_t nrepls; /* Number of active replenishments */ - uint32_t repl_period; /* Sporadic replenishment period */ - uint32_t budget; /* Sporadic execution budget period */ - uint32_t eventtime; /* Time thread suspended or [re-]started */ + bool suspended; /* Thread is currently suspended */ + uint8_t hi_priority; /* Sporadic high priority */ + uint8_t low_priority; /* Sporadic low priority */ + uint8_t max_repl; /* Maximum number of replenishments */ + uint8_t nrepls; /* Number of active replenishments */ + uint32_t repl_period; /* Sporadic replenishment period */ + uint32_t budget; /* Sporadic execution budget period */ + systime_t eventtime; /* Time thread suspended or [re-]started */ /* This is the last interval timer activated */ diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index cfd0feb19d..691e2f9624 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/semaphore.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include +#include #include /**************************************************************************** @@ -110,7 +111,7 @@ extern "C" * ****************************************************************************/ -int sem_tickwait(FAR sem_t *sem, uint32_t start, uint32_t delay); +int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index a194783978..59fa8f0a92 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -47,6 +47,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -290,8 +292,8 @@ struct work_s struct dq_entry_s dq; /* Implements a doubly linked list */ worker_t worker; /* Work callback */ FAR void *arg; /* Callback argument */ - uint32_t qtime; /* Time work queued */ - uint32_t delay; /* Delay until work performed */ + systime_t qtime; /* Time work queued */ + systime_t delay; /* Delay until work performed */ }; /**************************************************************************** @@ -359,7 +361,7 @@ int work_usrstart(void); ****************************************************************************/ int work_queue(int qid, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay); + FAR void *arg, systime_t delay); /**************************************************************************** * Name: work_cancel diff --git a/include/sys/syscall.h b/include/sys/syscall.h index c7d9b086c4..362a8b2dac 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -211,7 +211,11 @@ * NuttX configuration. */ -#define SYS_clock_systimer (__SYS_clock+0) +#ifdef CONFIG_SYSTEM_TIME64 +# define SYS_clock_systimer64 (__SYS_clock+0) +#endif +# define SYS_clock_systimer32 (__SYS_clock+0) +#endif #define SYS_clock_getres (__SYS_clock+1) #define SYS_clock_gettime (__SYS_clock+2) #define SYS_clock_settime (__SYS_clock+3) diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index 21bd65916e..f0815ac0c7 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/wqueue/work_usrthread.c * - * Copyright (C) 2009-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -122,11 +122,11 @@ void work_process(FAR struct usr_wqueue_s *wqueue) volatile FAR struct work_s *work; worker_t worker; FAR void *arg; - uint32_t elapsed; - uint32_t remaining; - uint32_t stick; - uint32_t ctick; - uint32_t next; + systime_t elapsed; + systime_t remaining; + systime_t stick; + systime_t ctick; + systime_t next; int ret; /* Then process queued work. Lock the work queue while we process items diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 767bceec16..4b62bd1c82 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -83,8 +83,8 @@ struct icmp_ping_s FAR struct devif_callback_s *png_cb; /* Reference to callback instance */ sem_t png_sem; /* Use to manage the wait for the response */ - uint32_t png_time; /* Start time for determining timeouts */ - uint32_t png_ticks; /* System clock ticks to wait */ + systime_t png_time; /* Start time for determining timeouts */ + systime_t png_ticks; /* System clock ticks to wait */ int png_result; /* 0: success; <0:negated errno on fail */ in_addr_t png_addr; /* The peer to be ping'ed */ uint16_t png_id; /* Used to match requests with replies */ @@ -124,7 +124,7 @@ struct icmp_ping_s static inline int ping_timeout(FAR struct icmp_ping_s *pstate) { - uint32_t elapsed = clock_systimer() - pstate->png_time; + systime_t elapsed = clock_systimer() - pstate->png_time; if (elapsed >= pstate->png_ticks) { return TRUE; diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index 956c18c656..b6f8edd299 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -86,8 +86,8 @@ struct icmpv6_ping_s FAR struct devif_callback_s *png_cb; /* Reference to callback instance */ sem_t png_sem; /* Use to manage the wait for the response */ - uint32_t png_time; /* Start time for determining timeouts */ - uint32_t png_ticks; /* System clock ticks to wait */ + systime_t png_time; /* Start time for determining timeouts */ + systime_t png_ticks; /* System clock ticks to wait */ int png_result; /* 0: success; <0:negated errno on fail */ net_ipv6addr_t png_addr; /* The peer to be ping'ed */ uint16_t png_id; /* Used to match requests with replies */ @@ -127,7 +127,7 @@ struct icmpv6_ping_s static inline int ping_timeout(FAR struct icmpv6_ping_s *pstate) { - uint32_t elapsed = clock_systimer() - pstate->png_time; + systime_t elapsed = clock_systimer() - pstate->png_time; if (elapsed >= pstate->png_ticks) { return TRUE; diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 0a2a1c287f..d6330f16a9 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -49,6 +49,7 @@ #include +#include #include #ifdef CONFIG_NET_IPv6 @@ -100,7 +101,7 @@ extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; /* This is the time, in clock ticks, of the last poll */ -extern uint32_t g_neighbor_polltime; +extern systime_t g_neighbor_polltime; /**************************************************************************** * Public Function Prototypes diff --git a/net/neighbor/neighbor_initialize.c b/net/neighbor/neighbor_initialize.c index ce4ebdb562..124e0f9a89 100644 --- a/net/neighbor/neighbor_initialize.c +++ b/net/neighbor/neighbor_initialize.c @@ -58,7 +58,7 @@ struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; /* This is the time, in clock ticks, of the last poll */ -uint32_t g_neighbor_polltime; +systime_t g_neighbor_polltime; /**************************************************************************** * Public Functions diff --git a/net/neighbor/neighbor_periodic.c b/net/neighbor/neighbor_periodic.c index 2a9f0d99fd..c242b099d2 100644 --- a/net/neighbor/neighbor_periodic.c +++ b/net/neighbor/neighbor_periodic.c @@ -75,8 +75,8 @@ void neighbor_periodic(void) { - uint32_t now; - uint32_t ticks; + systime_t now; + systime_t ticks; uint32_t hsecs; int i; @@ -84,7 +84,7 @@ void neighbor_periodic(void) now = clock_systimer(); ticks = now - g_neighbor_polltime; - hsecs = TICK2HSEC(ticks); + hsecs = (uint32_t)TICK2HSEC(ticks); /* Reset the time of the last poll */ diff --git a/net/socket/net_close.c b/net/socket/net_close.c index c76baacaf2..0635bab504 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -82,7 +82,7 @@ struct tcp_close_s FAR struct socket *cl_psock; /* Reference to the TCP socket */ sem_t cl_sem; /* Signals disconnect completion */ int cl_result; /* The result of the close */ - uint32_t cl_start; /* Time close started (in ticks) */ + systime_t cl_start; /* Time close started (in ticks) */ #endif }; #endif diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 0769662ce5..a8b7b9f162 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -2,7 +2,7 @@ * net/socket/net_sendfile.c * * Copyright (C) 2013 UVC Ingenieure. All rights reserved. - * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Max Holtzberg * @@ -103,7 +103,7 @@ struct sendfile_s uint32_t snd_isn; /* Initial sequence number */ uint32_t snd_acked; /* The number of bytes acked */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t snd_time; /* Last send time for determining timeout */ + systime_t snd_time; /* Last send time for determining timeout */ #endif }; diff --git a/net/socket/net_timeo.c b/net/socket/net_timeo.c index 70f670dacd..47099d205d 100644 --- a/net/socket/net_timeo.c +++ b/net/socket/net_timeo.c @@ -69,10 +69,10 @@ * ****************************************************************************/ -int net_timeo(uint32_t start_time, socktimeo_t timeo) +int net_timeo(systime_t start_time, socktimeo_t timeo) { - uint32_t timeo_ticks = DSEC2TICK(timeo); - uint32_t elapsed = clock_systimer() - start_time; + systime_t timeo_ticks = DSEC2TICK(timeo); + systime_t elapsed = clock_systimer() - start_time; if (elapsed >= timeo_ticks) { diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a14b673542..a6921315fd 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/recvfrom.c * - * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -93,7 +93,7 @@ struct recvfrom_s { FAR struct socket *rf_sock; /* The parent socket structure */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t rf_starttime; /* rcv start time for determining timeout */ + systime_t rf_starttime; /* rcv start time for determining timeout */ #endif FAR struct devif_callback_s *rf_cb; /* Reference to callback instance */ sem_t rf_sem; /* Semaphore signals recv completion */ diff --git a/net/socket/socket.h b/net/socket/socket.h index 3793573961..e9bfa161db 100644 --- a/net/socket/socket.h +++ b/net/socket/socket.h @@ -47,6 +47,7 @@ #include #include +#include #include /**************************************************************************** @@ -345,7 +346,7 @@ int net_close(int sockfd); ****************************************************************************/ #ifdef CONFIG_NET_SOCKOPTS -int net_timeo(uint32_t start_time, socktimeo_t timeo); +int net_timeo(systime_t start_time, socktimeo_t timeo); #endif /**************************************************************************** diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 559820b1dd..bb53b11d58 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_send_unbuffered.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -103,7 +103,7 @@ struct send_s uint32_t snd_isn; /* Initial sequence number */ uint32_t snd_acked; /* The number of bytes acked */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t snd_time; /* Last send time for determining timeout */ + systime_t snd_time; /* Last send time for determining timeout */ #endif #if defined(CONFIG_NET_TCP_SPLIT) bool snd_odd; /* True: Odd packet in pair transaction */ diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 7714db60c6..71fbe55af1 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/udp/udp_psock_sendto.c * - * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -99,7 +99,7 @@ struct sendto_s FAR struct socket *st_sock; /* Points to the parent socket structure */ #endif #ifdef CONFIG_NET_SENDTO_TIMEOUT - uint32_t st_time; /* Last send time for determining timeout */ + systime_t st_time; /* Last send time for determining timeout */ #endif FAR struct devif_callback_s *st_cb; /* Reference to callback instance */ sem_t st_sem; /* Semaphore signals sendto completion */ diff --git a/sched/Kconfig b/sched/Kconfig index 5dd5ab72bf..26e3237642 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -147,7 +147,7 @@ config SYSTEM_TIME64 USEC_PER_TICK, typically at 100Hz. The count at any given time is then the "uptime" in units of system timer ticks. By default, the system time is 32-bits wide. Those defaults provide a range of about - 13.6 years which is probably a sufficient range for "uptime". + 497 days which is probably a sufficient range for "uptime". However, if the system timer rate is significantly higher than 100Hz and/or if a very long "uptime" is required, then this option can be diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index a87f36a0af..650587b32a 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/clock/clock_systimer.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,7 +51,7 @@ ****************************************************************************/ /* See nuttx/clock.h */ -#undef clock_systimer +#undef cloc_systimer32 #undef clock_systimer64 /**************************************************************************** @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: clock_systimer + * Name: cloc_systimer32 * * Description: * Return the current value of the 32-bit system timer counter @@ -78,7 +78,7 @@ * ****************************************************************************/ -uint32_t clock_systimer(void) +uint32_t cloc_systimer32(void) { #ifdef CONFIG_SCHED_TICKLESS struct timespec ts; diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 1a661a8af2..a50f917d09 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -110,7 +110,7 @@ static int g_fillresult; */ #ifdef CONFIG_PAGING_TIMEOUT_TICKS -status uint32_t g_starttime; +static systime_t g_starttime; #endif #endif diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index 7cfa152b09..235d987044 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_sporadic.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -975,9 +975,9 @@ int sched_sporadic_resume(FAR struct tcb_s *tcb) { FAR struct sporadic_s *sporadic; FAR struct replenishment_s *repl; + systime_t now; uint32_t unrealized; uint32_t last; - uint32_t now; DEBUGASSERT(tcb && tcb->sporadic); sporadic = tcb->sporadic; diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index a72370383e..804e1ed83c 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_tickdwait.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -80,11 +80,11 @@ * ****************************************************************************/ -int sem_tickwait(FAR sem_t *sem, uint32_t start, uint32_t delay) +int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay) { FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; irqstate_t flags; - uint32_t elapsed; + systime_t elapsed; int ret; DEBUGASSERT(sem != NULL && up_interrupt_context() == false && diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index 25f9f30231..da87609ea3 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig/nanosleep.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,7 +124,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) { irqstate_t flags; - uint32_t starttick; + systime_t starttick; sigset_t set; struct siginfo value; int errval; @@ -183,8 +183,8 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) if (rmtp) { - uint32_t elapsed; - uint32_t remaining; + systime_t elapsed; + systime_t remaining; int ticks; /* First get the number of clock ticks that we were requested to diff --git a/sched/wqueue/kwork_process.c b/sched/wqueue/kwork_process.c index ff854fe83a..b5c44be5ae 100644 --- a/sched/wqueue/kwork_process.c +++ b/sched/wqueue/kwork_process.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/wqueue/work_process.c * - * Copyright (C) 2009-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -72,22 +72,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -109,17 +93,17 @@ * ****************************************************************************/ -void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx) +void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) { volatile FAR struct work_s *work; worker_t worker; irqstate_t flags; FAR void *arg; - uint32_t elapsed; - uint32_t remaining; - uint32_t stick; - uint32_t ctick; - uint32_t next; + systime_t elapsed; + systime_t remaining; + systime_t stick; + systime_t ctick; + systime_t next; /* Then process queued work. We need to keep interrupts disabled while * we process items in the work list. diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h index 14bf74b44c..701af9b300 100644 --- a/sched/wqueue/wqueue.h +++ b/sched/wqueue/wqueue.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wqueue/wqueue.h * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,8 @@ #include #include +#include + #ifdef CONFIG_SCHED_WORKQUEUE /**************************************************************************** @@ -72,7 +74,7 @@ struct kworker_s struct kwork_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ struct kworker_s worker[1]; /* Describes a worker thread */ }; @@ -84,7 +86,7 @@ struct kwork_wqueue_s #ifdef CONFIG_SCHED_HPWORK struct hp_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ struct kworker_s worker[1]; /* Describes the single high priority worker */ }; @@ -97,7 +99,7 @@ struct hp_wqueue_s #ifdef CONFIG_SCHED_LPWORK struct lp_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ /* Describes each thread in the low priority queue's thread pool */ @@ -183,7 +185,7 @@ int work_lpstart(void); * ****************************************************************************/ -void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx); +void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx); #endif /* CONFIG_SCHED_WORKQUEUE */ #endif /* __SCHED_WQUEUE_WQUEUE_H */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 647ee8f4c4..43e8e9175f 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -11,7 +11,8 @@ "clock_getres","time.h","","int","clockid_t","struct timespec*" "clock_gettime","time.h","","int","clockid_t","struct timespec*" "clock_settime","time.h","","int","clockid_t","const struct timespec*" -"clock_systimer","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS)","uint32_t" +"clock_systimer32","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && !defined(CONFIG_SYSTEM_TIME64)","uint32_t" +"clock_systimer64","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && defined(CONFIG_SYSTEM_TIME64)","uint64_t" "close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int" "closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*" "connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t" diff --git a/syscall/syscall_clock_systimer.c b/syscall/syscall_clock_systimer.c index 18801debbd..b6bbc00cac 100644 --- a/syscall/syscall_clock_systimer.c +++ b/syscall/syscall_clock_systimer.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: syscall_clock_systimer + * Name: syscall_clock_systimer32/64 * * Description: * In the kernel build, proxying for clock_systimer() must be handled @@ -74,7 +74,14 @@ * ****************************************************************************/ -uint32_t syscall_clock_systimer(void) +#ifdef CONFIG_SYSTEM_TIME64 +uint64_t syscall_clock_systimer64(void) { - return clock_systimer(); + return clock_systimer64(); } +#else +uint32_t syscall_clock_systimer32(void) +{ + return clock_systimer32(); +} +#endif diff --git a/syscall/syscall_funclookup.c b/syscall/syscall_funclookup.c index 8aa14a6926..b1545fb4f1 100644 --- a/syscall/syscall_funclookup.c +++ b/syscall/syscall_funclookup.c @@ -99,7 +99,11 @@ * have an address that can be included in the g_funclookup[] table. */ -uint32_t syscall_clock_systimer(void); +#ifdef CONFIG_SYSTEM_TIME64 +uint64_t syscall_clock_systimer64(void); +#else +uint32_t syscall_clock_systimer32(void); +#endif /**************************************************************************** * Pre-processor Definitions diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 6ad246ba5b..ca378b07e6 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -148,7 +148,11 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) * NuttX configuration. */ - SYSCALL_LOOKUP(syscall_clock_systimer, 0, STUB_clock_systimer) +#ifdef CONFIG_SYSTEM_TIME64 + SYSCALL_LOOKUP(syscall_clock_systimer64, 0, STUB_clock_systimer64) +#endif + SYSCALL_LOOKUP(syscall_clock_systimer32, 0, STUB_clock_systimer32) +#endif SYSCALL_LOOKUP(clock_getres, 2, STUB_clock_getres) SYSCALL_LOOKUP(clock_gettime, 2, STUB_clock_gettime) SYSCALL_LOOKUP(clock_settime, 2, STUB_clock_settime) -- GitLab From de995653fe8885ed23c02af6e99e21e182d4979f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 12:26:53 -0600 Subject: [PATCH 575/858] Fix a typo from the last big set of changes --- arch | 2 +- configs | 2 +- fs/procfs/fs_procfsuptime.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 09d21fd8e0..8dd7a88dd5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 09d21fd8e0b47fd0d6f7c32adf39b9b29dba9cd3 +Subproject commit 8dd7a88dd571af62e1da85ef4f9717db6cd80028 diff --git a/configs b/configs index 6aa9bb01b7..6789354447 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6aa9bb01b7372bc44ff0718a9634d51e2732e918 +Subproject commit 6789354447c099458909b61fd03bbec045f03eed diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index fd273badbb..dce272e69f 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -212,7 +212,7 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, size_t linesize; off_t offset; ssize_t ret; - systime ticktime; + systime_t ticktime; #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) double now; -- GitLab From e001f37593ed0201b5ebe1e542aaed7f3d5162f8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 13:31:00 -0600 Subject: [PATCH 576/858] sched/clock/clock_timespec.c: Fix an error in the time conversion --- ChangeLog | 6 +++++ sched/clock/clock_abstime2ticks.c | 18 +------------ sched/clock/clock_gettime.c | 30 +-------------------- sched/clock/clock_systimespec.c | 43 +++++++++++++++++++------------ 4 files changed, 35 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9764a3b2e..3bbd4e2c0d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11332,4 +11332,10 @@ read-only passwd file (2016-01-20). * sim/nsh: Uses the custom start up script, includes hoks for an MOTD message. (2016-01-20). + * include/clock.h and lots of other files: If the 64-bit timer is + selected, then use it whenever clock_systimer() is called rather + then chopping the 64-bit timer down to 32-bits. Add a new type, + systime_t to represent the 32- or 64-bit system timer (2016-01-21). + * sched/clock/clock_systimespec.c: Fix an error in a time + conversion (2016-01-21). diff --git a/sched/clock/clock_abstime2ticks.c b/sched/clock/clock_abstime2ticks.c index 30027d7617..24213dd07b 100644 --- a/sched/clock/clock_abstime2ticks.c +++ b/sched/clock/clock_abstime2ticks.c @@ -1,7 +1,7 @@ /******************************************************************************** * sched/clock/clock_abstime2ticks.c * - * Copyright (C) 2007, 2008, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2013-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,22 +44,6 @@ #include #include "clock/clock.h" -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - /******************************************************************************** * Private Functions ********************************************************************************/ diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index 519785d9ea..50e3c6e7c1 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/clock/clock_gettime.c * - * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,34 +50,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/clock/clock_systimespec.c b/sched/clock/clock_systimespec.c index 37511f1d0a..030f3f7e0c 100644 --- a/sched/clock/clock_systimespec.c +++ b/sched/clock/clock_systimespec.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/clock/clock_systimespec.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,14 +48,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -138,15 +130,17 @@ int clock_systimespec(FAR struct timespec *ts) return up_timer_gettime(ts); #elif defined(CONFIG_HAVE_LONG_LONG) && (CONFIG_USEC_PER_TICK % 1000) != 0 - /* 64-bit microsecond calculations should improve our accuracy. */ + /* 64-bit microsecond calculations should improve our accuracy + * when the clock period is in units of microseconds. + */ uint64_t usecs; uint64_t secs; uint64_t nsecs; - /* Get the time since power-on in seconds and milliseconds */ + /* Get the time since power-on in seconds and microsecon */ - usecs = TICK2MSEC(clock_systimer()); + usecs = (uint64_t)TICK2USEC(clock_systimer()); secs = usecs / USEC_PER_SEC; /* Return the elapsed time in seconds and nanoseconds */ @@ -158,11 +152,28 @@ int clock_systimespec(FAR struct timespec *ts) return OK; #else - /* 32-bit millisecond calculations should be just fine. */ + /* We know that the clock rate is in units of milliseconds + * show we should be able to do the calculations with less + * chance of overflow. + * + * 32-bit millisecond calculations should be just fine in + * most cases. For a 32-bit system timer and a clock period + * of 10 milliseconds, the msecs value will overflow at about + * 49.7 days. + * + * So, we will still use 64-bit calculations if we have them + * in order to avoid that limitation. + */ - uint32_t msecs; - uint32_t secs; - uint32_t nsecs; +#ifdef CONFIG_HAVE_LONG_LONG + uint64_t msecs; + uint64_t secs; + uint64_t nsecs; +#else + systime_t msecs; + systime_t secs; + systime_t nsecs; +#endif /* Get the time since power-on in seconds and milliseconds */ -- GitLab From a4f5254cbe538bbe65bbad1aa5c5fbc55fb796dd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 13:48:35 -0600 Subject: [PATCH 577/858] Fix a typo introduced into the last commit --- sched/clock/clock_systimer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index 650587b32a..24c92b7916 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -51,7 +51,7 @@ ****************************************************************************/ /* See nuttx/clock.h */ -#undef cloc_systimer32 +#undef clock_systimer32 #undef clock_systimer64 /**************************************************************************** @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: cloc_systimer32 + * Name: clock_systimer32 * * Description: * Return the current value of the 32-bit system timer counter @@ -78,7 +78,7 @@ * ****************************************************************************/ -uint32_t cloc_systimer32(void) +uint32_t clock_systimer32(void) { #ifdef CONFIG_SCHED_TICKLESS struct timespec ts; -- GitLab From 7db9a952bcbb24c4465041a7d6d825029cbcef49 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 13:42:34 -0600 Subject: [PATCH 578/858] Fix an error in conditional compilation introduced in the last set of changes --- include/sys/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 362a8b2dac..87bd73faf0 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -213,7 +213,7 @@ #ifdef CONFIG_SYSTEM_TIME64 # define SYS_clock_systimer64 (__SYS_clock+0) -#endif +#else # define SYS_clock_systimer32 (__SYS_clock+0) #endif #define SYS_clock_getres (__SYS_clock+1) -- GitLab From c4e61a4761fbacdf700f8f37c4b14e6152cf6e2a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 14:05:50 -0600 Subject: [PATCH 579/858] Fix another error introduced with last clock_systimer changes --- syscall/syscall_stublookup.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index ed151d246b..1d58924768 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -150,7 +150,11 @@ uintptr_t STUB_nanosleep(int nbr, uintptr_t parm1, uintptr_t parm2); * NuttX configuration. */ -uintptr_t STUB_clock_systimer(int nbr); +#ifdef CONFIG_SYSTEM_TIME64 +uintptr_t STUB_clock_systimer32(int nbr); +#else +uintptr_t STUB_clock_systimer64(int nbr); +#endif uintptr_t STUB_clock_getres(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_clock_gettime(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_clock_settime(int nbr, uintptr_t parm1, uintptr_t parm2); -- GitLab From 19919d630b3d5e1a047686af6d7c1af15350ccf8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 14:09:06 -0600 Subject: [PATCH 580/858] Yet another error introduced with last clock_systimer changes --- syscall/syscall_lookup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index ca378b07e6..615d17ba87 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -150,7 +150,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) #ifdef CONFIG_SYSTEM_TIME64 SYSCALL_LOOKUP(syscall_clock_systimer64, 0, STUB_clock_systimer64) -#endif +#else SYSCALL_LOOKUP(syscall_clock_systimer32, 0, STUB_clock_systimer32) #endif SYSCALL_LOOKUP(clock_getres, 2, STUB_clock_getres) -- GitLab From 72bd1e76343b073c262629b59c7b717698693065 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 14:12:52 -0600 Subject: [PATCH 581/858] Yet another error introduced with last clock_systimer changes --- syscall/syscall_stublookup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 1d58924768..8c10723f89 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -151,9 +151,9 @@ uintptr_t STUB_nanosleep(int nbr, uintptr_t parm1, uintptr_t parm2); */ #ifdef CONFIG_SYSTEM_TIME64 -uintptr_t STUB_clock_systimer32(int nbr); -#else uintptr_t STUB_clock_systimer64(int nbr); +#else +uintptr_t STUB_clock_systimer32(int nbr); #endif uintptr_t STUB_clock_getres(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_clock_gettime(int nbr, uintptr_t parm1, uintptr_t parm2); -- GitLab From b04e2ea02102670940b5b701f7ed9823d71520d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 16:28:36 -0600 Subject: [PATCH 582/858] Trivial improvement to comments --- Documentation | 2 +- configs | 2 +- sched/clock/clock_systimespec.c | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation b/Documentation index f080d80b68..b4f9bbd970 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit f080d80b68c7f98694ab9db8fad0e4d27e2436d7 +Subproject commit b4f9bbd9708111b44d40ff19248b5493fdafc6c1 diff --git a/configs b/configs index 6789354447..d9bb7ac167 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6789354447c099458909b61fd03bbec045f03eed +Subproject commit d9bb7ac167d730a1c152cea388852c8690795d93 diff --git a/sched/clock/clock_systimespec.c b/sched/clock/clock_systimespec.c index 030f3f7e0c..260be4aab6 100644 --- a/sched/clock/clock_systimespec.c +++ b/sched/clock/clock_systimespec.c @@ -138,7 +138,10 @@ int clock_systimespec(FAR struct timespec *ts) uint64_t secs; uint64_t nsecs; - /* Get the time since power-on in seconds and microsecon */ + /* Get the time since power-on in seconds and microsecond. + * NOTE that overflow is still possible if we use a 64-bit + * timer. + */ usecs = (uint64_t)TICK2USEC(clock_systimer()); secs = usecs / USEC_PER_SEC; @@ -161,7 +164,7 @@ int clock_systimespec(FAR struct timespec *ts) * of 10 milliseconds, the msecs value will overflow at about * 49.7 days. * - * So, we will still use 64-bit calculations if we have them + * So.. we will still use 64-bit calculations if we have them * in order to avoid that limitation. */ -- GitLab From 032ad1b70b61fb6b10406e5a29f1aa0f2c792e09 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 16:49:24 -0600 Subject: [PATCH 583/858] Remove clock_systimer32 and clock_systimer64. There is now only clock_systimer --- ChangeLog | 2 ++ include/nuttx/clock.h | 61 +++++--------------------------- include/sys/syscall.h | 6 +--- sched/clock/clock_systimer.c | 61 +++++++------------------------- syscall/syscall.csv | 3 +- syscall/syscall_clock_systimer.c | 15 +++----- syscall/syscall_funclookup.c | 6 +--- syscall/syscall_lookup.h | 6 +--- syscall/syscall_stublookup.c | 6 +--- 9 files changed, 32 insertions(+), 134 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bbd4e2c0d..dce32ae0dc 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11338,4 +11338,6 @@ systime_t to represent the 32- or 64-bit system timer (2016-01-21). * sched/clock/clock_systimespec.c: Fix an error in a time conversion (2016-01-21). + * include/nuttx/clock.h: Get rid of clock_systimer32() and + clock_systime64(). There is now only clock_systimer() (2016-01-21). diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index cc6eccd14c..f2e354725a 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -165,14 +165,6 @@ #define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ -/* Select the access to the system timer using its natural with */ - -#ifdef CONFIG_SYSTEM_TIME64 -# define clock_systimer() clock_systimer64() -#else -# define clock_systimer() clock_systimer32() -#endif - /**************************************************************************** * Public Types ****************************************************************************/ @@ -214,18 +206,8 @@ extern "C" */ #ifdef __HAVE_KERNEL_GLOBALS -# ifdef CONFIG_SYSTEM_TIME64 - -EXTERN volatile uint64_t g_system_timer; -#define clock_systimer32() (uint32_t)(g_system_timer & 0x00000000ffffffff) -#define clock_systimer64() g_system_timer - -# else - -EXTERN volatile uint32_t g_system_timer; -#define clock_systimer32() g_system_timer - -# endif +EXTERN volatile systime_t g_system_timer; +# define clock_systimer() g_system_timer #endif /**************************************************************************** @@ -265,13 +247,13 @@ void clock_synchronize(void); #endif /**************************************************************************** - * Function: clock_systimer32 + * Function: clock_systimer * * Description: - * Return the current value of the 32-bit system timer counter. Indirect - * access to the system timer counter is required through this function if - * the execution environment does not have direct access to kernel global - * data + * Return the current value of the 32/64-bit system timer counter. + * Indirect access to the system timer counter is required through this + * function if the execution environment does not have direct access to + * kernel globaldata * * Parameters: * None @@ -284,34 +266,7 @@ void clock_synchronize(void); ****************************************************************************/ #ifndef __HAVE_KERNEL_GLOBALS -# ifdef CONFIG_SYSTEM_TIME64 -# define clock_systimer32() (uint32_t)(clock_systimer64() & 0x00000000ffffffff) -# else -uint32_t clock_systimer32(void); -# endif -#endif - -/**************************************************************************** - * Function: clock_systimer64 - * - * Description: - * Return the current value of the 64-bit system timer counter. Indirect - * access to the system timer counter is required through this function if - * the execution environment does not have direct access to kernel global - * data - * - * Parameters: - * None - * - * Return Value: - * The current value of the system timer counter - * - * Assumptions: - * - ****************************************************************************/ - -#if !defined(__HAVE_KERNEL_GLOBALS) && defined(CONFIG_SYSTEM_TIME64) -uint64_t clock_systimer64(void); +systime_t clock_systimer(void); #endif /**************************************************************************** diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 87bd73faf0..c7d9b086c4 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -211,11 +211,7 @@ * NuttX configuration. */ -#ifdef CONFIG_SYSTEM_TIME64 -# define SYS_clock_systimer64 (__SYS_clock+0) -#else -# define SYS_clock_systimer32 (__SYS_clock+0) -#endif +#define SYS_clock_systimer (__SYS_clock+0) #define SYS_clock_getres (__SYS_clock+1) #define SYS_clock_gettime (__SYS_clock+2) #define SYS_clock_settime (__SYS_clock+3) diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index 24c92b7916..c3f56a7421 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -51,8 +51,7 @@ ****************************************************************************/ /* See nuttx/clock.h */ -#undef clock_systimer32 -#undef clock_systimer64 +#undef clock_systimer /**************************************************************************** * Private Data @@ -63,10 +62,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: clock_systimer32 + * Name: clock_systimer * * Description: - * Return the current value of the 32-bit system timer counter + * Return the current value of the 32/64-bit system timer counter * * Parameters: * None @@ -78,71 +77,37 @@ * ****************************************************************************/ -uint32_t clock_systimer32(void) +systime_t clock_systimer(void) { #ifdef CONFIG_SCHED_TICKLESS +#ifdef CONFIG_SYSTEM_TIME64 struct timespec ts; - uint64_t tmp; /* Get the time from the platform specific hardware */ (void)up_timer_gettime(&ts); - /* Convert to a 64- then 32-bit value */ - - tmp = MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); - return (uint32_t)(tmp & 0x00000000ffffffff); - -#else - -#ifdef CONFIG_SYSTEM_TIME64 - /* Return the current system time truncated to 32-bits */ - - return (uint32_t)(g_system_timer & 0x00000000ffffffff); + /* Convert to a 64-bit value in microseconds, then in clock tick units */ + return USEC2TICK(1000000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000); #else - /* Return the current system time */ - - return g_system_timer; - -#endif -#endif -} - -/**************************************************************************** - * Name: clock_systimer64 - * - * Description: - * Return the current value of the 64-bit system timer counter - * - * Parameters: - * None - * - * Return Value: - * The current value of the system timer counter - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_SYSTEM_TIME64 -uint64_t clock_systimer64(void) -{ -#ifdef CONFIG_SCHED_TICKLESS struct timespec ts; + uint64_t tmp; /* Get the time from the platform specific hardware */ (void)up_timer_gettime(&ts); - /* Convert to a 64-bit value in microseconds, then in clock tick units */ + /* Convert to a 64- then 32-bit value */ - return USEC2TICK(1000000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000); + tmp = MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); + return (systime_t)(tmp & 0x00000000ffffffff); +#endif #else + /* Return the current system time */ return g_system_timer; #endif } -#endif diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 43e8e9175f..b20a2aca97 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -11,8 +11,7 @@ "clock_getres","time.h","","int","clockid_t","struct timespec*" "clock_gettime","time.h","","int","clockid_t","struct timespec*" "clock_settime","time.h","","int","clockid_t","const struct timespec*" -"clock_systimer32","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && !defined(CONFIG_SYSTEM_TIME64)","uint32_t" -"clock_systimer64","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && defined(CONFIG_SYSTEM_TIME64)","uint64_t" +"clock_systimer","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS)","systime_t" "close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int" "closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*" "connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t" diff --git a/syscall/syscall_clock_systimer.c b/syscall/syscall_clock_systimer.c index b6bbc00cac..dce97f1633 100644 --- a/syscall/syscall_clock_systimer.c +++ b/syscall/syscall_clock_systimer.c @@ -1,7 +1,7 @@ /**************************************************************************** * syscall/syscall_clock_systimer.c * - * Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: syscall_clock_systimer32/64 + * Name: syscall_clock_systimer * * Description: * In the kernel build, proxying for clock_systimer() must be handled @@ -74,14 +74,7 @@ * ****************************************************************************/ -#ifdef CONFIG_SYSTEM_TIME64 -uint64_t syscall_clock_systimer64(void) +systime_t syscall_clock_systimer(void) { - return clock_systimer64(); + return clock_systime(); } -#else -uint32_t syscall_clock_systimer32(void) -{ - return clock_systimer32(); -} -#endif diff --git a/syscall/syscall_funclookup.c b/syscall/syscall_funclookup.c index b1545fb4f1..8e62470103 100644 --- a/syscall/syscall_funclookup.c +++ b/syscall/syscall_funclookup.c @@ -99,11 +99,7 @@ * have an address that can be included in the g_funclookup[] table. */ -#ifdef CONFIG_SYSTEM_TIME64 -uint64_t syscall_clock_systimer64(void); -#else -uint32_t syscall_clock_systimer32(void); -#endif +systime_t syscall_clock_systimer(void); /**************************************************************************** * Pre-processor Definitions diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 615d17ba87..6ad246ba5b 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -148,11 +148,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) * NuttX configuration. */ -#ifdef CONFIG_SYSTEM_TIME64 - SYSCALL_LOOKUP(syscall_clock_systimer64, 0, STUB_clock_systimer64) -#else - SYSCALL_LOOKUP(syscall_clock_systimer32, 0, STUB_clock_systimer32) -#endif + SYSCALL_LOOKUP(syscall_clock_systimer, 0, STUB_clock_systimer) SYSCALL_LOOKUP(clock_getres, 2, STUB_clock_getres) SYSCALL_LOOKUP(clock_gettime, 2, STUB_clock_gettime) SYSCALL_LOOKUP(clock_settime, 2, STUB_clock_settime) diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 8c10723f89..ed151d246b 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -150,11 +150,7 @@ uintptr_t STUB_nanosleep(int nbr, uintptr_t parm1, uintptr_t parm2); * NuttX configuration. */ -#ifdef CONFIG_SYSTEM_TIME64 -uintptr_t STUB_clock_systimer64(int nbr); -#else -uintptr_t STUB_clock_systimer32(int nbr); -#endif +uintptr_t STUB_clock_systimer(int nbr); uintptr_t STUB_clock_getres(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_clock_gettime(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_clock_settime(int nbr, uintptr_t parm1, uintptr_t parm2); -- GitLab From d68d9cbd322b7334684afc6f5a0621fe16a9c931 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 16:51:28 -0600 Subject: [PATCH 584/858] Fix typo introduced in the last commit --- syscall/syscall_clock_systimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscall/syscall_clock_systimer.c b/syscall/syscall_clock_systimer.c index dce97f1633..3473cc673d 100644 --- a/syscall/syscall_clock_systimer.c +++ b/syscall/syscall_clock_systimer.c @@ -76,5 +76,5 @@ systime_t syscall_clock_systimer(void) { - return clock_systime(); + return clock_systimer(); } -- GitLab From 2de5be34e52689ba7015a6839de694f007092045 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 19:29:43 -0600 Subject: [PATCH 585/858] Update ChangeLog --- ChangeLog | 5 ++++- arch | 2 +- sched/clock/clock_systimespec.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index dce32ae0dc..b2432bfce2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11340,4 +11340,7 @@ conversion (2016-01-21). * include/nuttx/clock.h: Get rid of clock_systimer32() and clock_systime64(). There is now only clock_systimer() (2016-01-21). - + * arch/arm/src/kinetis: Numerous updates to the Kinetis ENET driver. + From Andrew Webster (2016-01-21). + * arch/arm/src/kinetis: Add support for the MK60N512VLL100 Kinetis part. + From Andrew Webster (2016-01-21). diff --git a/arch b/arch index 8dd7a88dd5..eabf13f41e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8dd7a88dd571af62e1da85ef4f9717db6cd80028 +Subproject commit eabf13f41e38c104b907bb4cb29655b3cba9f35f diff --git a/sched/clock/clock_systimespec.c b/sched/clock/clock_systimespec.c index 260be4aab6..5d6009d051 100644 --- a/sched/clock/clock_systimespec.c +++ b/sched/clock/clock_systimespec.c @@ -138,7 +138,7 @@ int clock_systimespec(FAR struct timespec *ts) uint64_t secs; uint64_t nsecs; - /* Get the time since power-on in seconds and microsecond. + /* Get the time since power-on in seconds and microseconds. * NOTE that overflow is still possible if we use a 64-bit * timer. */ -- GitLab From 2b05f3e830ffa8d2694c17cf74ce831a39ad2540 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Fri, 22 Jan 2016 07:08:59 -0600 Subject: [PATCH 586/858] I/O Expander: Fix some bad macros, make naming consisted --- drivers/ioexpander/pca9555.c | 49 +++++++++++++-------------- include/nuttx/ioexpander/ioexpander.h | 10 +++--- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index cc11416662..a582a228d8 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -72,26 +72,23 @@ * Private Function Prototypes ****************************************************************************/ -static int pca9555_direction (FAR struct ioexpander_dev_s *dev, - uint8_t pin, int dir); -static int pca9555_option (FAR struct ioexpander_dev_s *dev, - uint8_t pin, int opt, void *val); -static int pca9555_write (FAR struct ioexpander_dev_s *dev, - uint8_t pin, bool value); -static int pca9555_readpin (FAR struct ioexpander_dev_s *dev, - uint8_t pin, FAR bool *value); -static int pca9555_readbuf (FAR struct ioexpander_dev_s *dev, - uint8_t pin, FAR bool *value); +static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, + int dir); +static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, + int opt, void *val); +static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, + bool value); +static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, + FAR bool *value); +static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, + FAR bool *value); #ifdef CONFIG_IOEXPANDER_MULTIPIN -static int pca9555_multiwrite (FAR struct ioexpander_dev_s *dev, - FAR uint8_t *pins, FAR bool *values, - int count); +static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, + FAR uint8_t *pins, FAR bool *values, int count); static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, - FAR uint8_t *pins, FAR bool *values, - int count); + FAR uint8_t *pins, FAR bool *values, int count); static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, - FAR uint8_t *pins, FAR bool *values, - int count); + FAR uint8_t *pins, FAR bool *values, int count); #endif /**************************************************************************** @@ -115,11 +112,11 @@ static const struct ioexpander_ops_s g_pca9555_ops = { pca9555_direction, pca9555_option, - pca9555_write, + pca9555_writepin, pca9555_readpin, pca9555_readbuf, #ifdef CONFIG_IOEXPANDER_MULTIPIN - pca9555_multiwrite, + pca9555_multiwritepin, pca9555_multireadpin, pca9555_multireadbuf, #endif @@ -245,15 +242,15 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, } /**************************************************************************** - * Name: pca9555_write + * Name: pca9555_writepin * * Description: * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ -static int pca9555_write(FAR struct ioexpander_dev_s *dev, uint8_t pin, - bool value) +static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, + bool value) { FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; return pca9555_setbit(pca->i2c, PCA9555_REG_OUTPUT, pin, value); @@ -339,16 +336,16 @@ static int pca9555_getmultibits(FAR struct i2c_dev_s *i2c, uint8_t addr, } /**************************************************************************** - * Name: pca9555_multiwrite + * Name: pca9555_multiwritepin * * Description: * See include/nuttx/ioexpander/ioexpander.h * ****************************************************************************/ -static int pca9555_multiwrite(FAR struct ioexpander_dev_s *dev, - FAR uint8_t *pins, FAR bool *values, - int count) +static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, + FAR uint8_t *pins, FAR bool *values, + int count) { FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t addr = PCA9555_REG_OUTPUT; diff --git a/include/nuttx/ioexpander/ioexpander.h b/include/nuttx/ioexpander/ioexpander.h index 72df8b5f37..e39c29113c 100644 --- a/include/nuttx/ioexpander/ioexpander.h +++ b/include/nuttx/ioexpander/ioexpander.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/ioexpander/ioexpander.h * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet * * Redistribution and use in source and binary forms, with or without @@ -104,7 +104,7 @@ #define IOEXP_SETOPTION(dev,pin,opt,val) ((dev)->ops->ioe_option(dev,pin,opt,val)) /**************************************************************************** - * Name: IOEXP_WRITE + * Name: IOEXP_WRITEPIN * * Description: * Set the pin level. Required. @@ -164,7 +164,7 @@ #ifdef CONFIG_IOEXPANDER_MULTIPIN /**************************************************************************** - * Name: IOEXP_MULTIWRITE + * Name: IOEXP_MULTIWRITEPIN * * Description: * Set the pin level for multiple pins. This routine may be faster than @@ -237,14 +237,14 @@ struct ioexpander_ops_s int direction); CODE int (*ioe_option)(FAR struct ioexpander_dev_s *dev, uint8_t pin, int opt, void *val); - CODE int (*ioe_write)(FAR struct ioexpander_dev_s *dev, uint8_t pin, + CODE int (*ioe_writepin)(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool value); CODE int (*ioe_readpin)(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool *value); CODE int (*ioe_readbuf)(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool *value); #ifdef CONFIG_IOEXPANDER_MULTIPIN - CODE int (*ioe_multiwrite)(FAR struct ioexpander_dev_s *dev, + CODE int (*ioe_multiwritepin)(FAR struct ioexpander_dev_s *dev, uint8_t *pins, bool *values, int count); CODE int (*ioe_multireadpin)(FAR struct ioexpander_dev_s *dev, uint8_t *pins, bool *values, int count); -- GitLab From 2dcebe1e3d80129558f6010168a37bff4c091ff2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 07:11:29 -0600 Subject: [PATCH 587/858] Purely cosmetic changes from review of last commit --- include/nuttx/ioexpander/ioexpander.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/include/nuttx/ioexpander/ioexpander.h b/include/nuttx/ioexpander/ioexpander.h index e39c29113c..ce95d6d491 100644 --- a/include/nuttx/ioexpander/ioexpander.h +++ b/include/nuttx/ioexpander/ioexpander.h @@ -47,7 +47,7 @@ #ifndef CONFIG_PCA9555_INT_DISABLE #ifndef CONFIG_SCHED_WORKQUEUE -#error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." +# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." #endif #endif @@ -223,7 +223,7 @@ #define IOEXP_MULTIREADBUF(dev,pins,vals,count) \ ((dev)->ops->ioe_multireadbuf(dev,pin,vals,count)) -#endif +#endif /* CONFIG_IOEXPANDER_MULTIPIN */ /**************************************************************************** * Public Types @@ -238,14 +238,14 @@ struct ioexpander_ops_s CODE int (*ioe_option)(FAR struct ioexpander_dev_s *dev, uint8_t pin, int opt, void *val); CODE int (*ioe_writepin)(FAR struct ioexpander_dev_s *dev, uint8_t pin, - bool value); + bool value); CODE int (*ioe_readpin)(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool *value); CODE int (*ioe_readbuf)(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool *value); #ifdef CONFIG_IOEXPANDER_MULTIPIN CODE int (*ioe_multiwritepin)(FAR struct ioexpander_dev_s *dev, - uint8_t *pins, bool *values, int count); + uint8_t *pins, bool *values, int count); CODE int (*ioe_multireadpin)(FAR struct ioexpander_dev_s *dev, uint8_t *pins, bool *values, int count); CODE int (*ioe_multireadbuf)(FAR struct ioexpander_dev_s *dev, @@ -257,12 +257,11 @@ struct ioexpander_dev_s { FAR const struct ioexpander_ops_s *ops; #ifdef CONFIG_IOEXPANDER_INT_ENABLE - struct work_s work; /* Supports the interrupt handling "bottom half" */ - int sigpid; /* PID to be signaled in case of interrupt */ - int sigval; /* signal to be sent in case of interrupt */ + struct work_s work; /* Supports the interrupt handling "bottom half" */ + int sigpid; /* PID to be signaled in case of interrupt */ + int sigval; /* Signal to be sent in case of interrupt */ #endif }; -#endif //CONFIG_IOEXPANDER -#endif //__INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H - +#endif /* CONFIG_IOEXPANDER */ +#endif /* __INCLUDE_NUTTX_IOEXPANDER_IOEXPANDER_H */ -- GitLab From 7ead6b4972ad05e388d90c634af3107aa6508cf4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 10:46:43 -0600 Subject: [PATCH 588/858] Update submodules --- Documentation | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index b4f9bbd970..32d1052962 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit b4f9bbd9708111b44d40ff19248b5493fdafc6c1 +Subproject commit 32d10529620c0bf17c207760ef85b1457d1799a0 diff --git a/configs b/configs index d9bb7ac167..bc84da3069 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d9bb7ac167d730a1c152cea388852c8690795d93 +Subproject commit bc84da30695b62f2d559ce49993b72489d605480 -- GitLab From 84d4cb007b3eb5e3222829674784c6ddc02d1aca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 12:24:36 -0600 Subject: [PATCH 589/858] clock_systimer: 64-bit timer accesses are not atomic. Noted by Freddie Chopin. --- include/nuttx/clock.h | 10 ++++++++-- sched/clock/Make.defs | 2 +- sched/clock/clock_systimer.c | 30 ++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index f2e354725a..501545fac9 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -207,8 +207,11 @@ extern "C" #ifdef __HAVE_KERNEL_GLOBALS EXTERN volatile systime_t g_system_timer; + +#ifndef CONFIG_SYSTEM_TIME64 # define clock_systimer() g_system_timer #endif +#endif /**************************************************************************** * Public Function Prototypes @@ -253,7 +256,10 @@ void clock_synchronize(void); * Return the current value of the 32/64-bit system timer counter. * Indirect access to the system timer counter is required through this * function if the execution environment does not have direct access to - * kernel globaldata + * kernel global data. + * + * Use of this function is also required to assue atomic access to the + * 64-bit system timer. * * Parameters: * None @@ -265,7 +271,7 @@ void clock_synchronize(void); * ****************************************************************************/ -#ifndef __HAVE_KERNEL_GLOBALS +#if !defined(__HAVE_KERNEL_GLOBALS) || defined(CONFIG_SYSTEM_TIME64) systime_t clock_systimer(void); #endif diff --git a/sched/clock/Make.defs b/sched/clock/Make.defs index 927c41625d..c0bc23f510 100644 --- a/sched/clock/Make.defs +++ b/sched/clock/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # sched/clock/Make.defs # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index c3f56a7421..2710385a54 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -80,7 +80,8 @@ systime_t clock_systimer(void) { #ifdef CONFIG_SCHED_TICKLESS -#ifdef CONFIG_SYSTEM_TIME64 +# ifdef CONFIG_SYSTEM_TIME64 + struct timespec ts; /* Get the time from the platform specific hardware */ @@ -90,7 +91,9 @@ systime_t clock_systimer(void) /* Convert to a 64-bit value in microseconds, then in clock tick units */ return USEC2TICK(1000000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000); -#else + +# else /* CONFIG_SYSTEM_TIME64 */ + struct timespec ts; uint64_t tmp; @@ -98,16 +101,31 @@ systime_t clock_systimer(void) (void)up_timer_gettime(&ts); - /* Convert to a 64- then 32-bit value */ + /* Convert to a 64- then a 32-bit value */ tmp = MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); return (systime_t)(tmp & 0x00000000ffffffff); -#endif -#else + +# endif /* CONFIG_SYSTEM_TIME64 */ +#else /* CONFIG_SCHED_TICKLESS */ +# ifdef CONFIG_SYSTEM_TIME64 + + irqstate_t flags; + systime_t sample; + + /* 64-bit accesses are not atomic on most architectures. */ + + flags = irqsave(); + sample = g_system_timer; + irqrestore(flags); + return sample; + +# else /* CONFIG_SYSTEM_TIME64 */ /* Return the current system time */ return g_system_timer; -#endif +# endif /* CONFIG_SYSTEM_TIME64 */ +#endif /* CONFIG_SCHED_TICKLESS */ } -- GitLab From 99f5fcda70652f86202dfa9eae9709f191be2d5e Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:41:48 -0600 Subject: [PATCH 590/858] iTCP: use lowlevel syslog to avoid infinte recursion If stdout is a socket (e.g. telnet), then the debug message will cause more TCP data to be sent, which generates another message, and so on --- net/tcp/tcp_send_buffered.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 9b22630143..9a056b1ab5 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -1054,9 +1054,9 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, */ sq_addlast(&wrb->wb_node, &conn->write_q); - nvdbg("Queued WRB=%p pktlen=%u write_q(%p,%p)\n", - wrb, WRB_PKTLEN(wrb), - conn->write_q.head, conn->write_q.tail); + nllvdbg("Queued WRB=%p pktlen=%u write_q(%p,%p)\n", + wrb, WRB_PKTLEN(wrb), + conn->write_q.head, conn->write_q.tail); /* Notify the device driver of the availability of TX data */ -- GitLab From df211ee46ad9c0420a9f8215db9b3c46a1b2c9f0 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:52:14 -0600 Subject: [PATCH 591/858] TCP: add writable check during poll When a poll requesting POLLOUT happens, the poll should return immediately if a write will not block. This change adds that, as opposed to the old behaviour of blocking until a timer from the Ethernet driver eventually triggers the poll to complete. This is only implemented for buffered TCP. Unbuffered TCP should behave as before. --- net/tcp/tcp.h | 46 ++++++++++++++++++++++++++++++- net/tcp/tcp_netpoll.c | 6 ++++- net/tcp/tcp_send_buffered.c | 51 ++++++++++++++++++++++++++++++++++- net/tcp/tcp_send_unbuffered.c | 26 ++++++++++++++++++ net/tcp/tcp_wrbuffer.c | 18 +++++++++++++ 5 files changed, 144 insertions(+), 3 deletions(-) diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 8662ccd7a7..2f3284d709 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1143,6 +1143,35 @@ struct socket; ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len); +/**************************************************************************** + * Function: psock_tcp_cansend + * + * Description: + * psock_tcp_cansend() returns a value indicating if a write to the socket + * would block. No space in the buffer is actually reserved, so it is + * possible that the write may still block if the buffer is filled by + * another means. + * + * Parameters: + * psock An instance of the internal socket structure. + * + * Returned Value: + * OK + * At least one byte of data could be succesfully written. + * -EWOULDBLOCK + * There is no room in the output buffer. + * -EBADF + * An invalid descriptor was specified. + * -ENOTCONN + * The socket is not connected. + * + * Assumptions: + * Not running at the interrupt level + * + ****************************************************************************/ + +int psock_tcp_cansend(FAR struct socket *psock); + /**************************************************************************** * Function: tcp_wrbuffer_initialize * @@ -1197,6 +1226,21 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void); void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb); #endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ +/**************************************************************************** + * Function: tcp_wrbuffer_test + * + * Description: + * Check if there is room in the write buffer. Does not reserve any space. + * + * Assumptions: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_TCP_WRITE_BUFFERS +int tcp_wrbuffer_test(void); +#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ + /**************************************************************************** * Function: tcp_wrbuffer_dump * diff --git a/net/tcp/tcp_netpoll.c b/net/tcp/tcp_netpoll.c index dbe8eff03f..522c00986b 100644 --- a/net/tcp/tcp_netpoll.c +++ b/net/tcp/tcp_netpoll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_netpoll.c * - * Copyright (C) 2008-2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -282,6 +282,10 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) fds->revents |= (POLLERR | POLLHUP); } + else if (_SS_ISCONNECTED(psock->s_flags) && psock_tcp_cansend(psock) >= 0) + { + fds->revents |= (POLLWRNORM & fds->events); + } /* Check if any requested events are already in effect */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 9a056b1ab5..d25a88567f 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_send_buffered.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Jason Jiang * @@ -1104,4 +1104,53 @@ errout: return ERROR; } +/**************************************************************************** + * Function: psock_tcp_cansend + * + * Description: + * psock_tcp_cansend() returns a value indicating if a write to the socket + * would block. No space in the buffer is actually reserved, so it is + * possible that the write may still block if the buffer is filled by + * another means. + * + * Parameters: + * psock An instance of the internal socket structure. + * + * Returned Value: + * OK + * At least one byte of data could be succesfully written. + * -EWOULDBLOCK + * There is no room in the output buffer. + * -EBADF + * An invalid descriptor was specified. + * -ENOTCONN + * The socket is not connected. + * + * Assumptions: + * Not running at the interrupt level + * + ****************************************************************************/ + +int psock_tcp_cansend(FAR struct socket *psock) +{ + if (!psock || psock->s_crefs <= 0) + { + ndbg("ERROR: Invalid socket\n"); + return -EBADF; + } + + if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags)) + { + ndbg("ERROR: Not connected\n"); + return -ENOTCONN; + } + + if (tcp_wrbuffer_test()) + { + return -EWOULDBLOCK; + } + + return OK; +} + #endif /* CONFIG_NET && CONFIG_NET_TCP && CONFIG_NET_TCP_WRITE_BUFFERS */ diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index bb53b11d58..7c0faac458 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -880,4 +880,30 @@ errout: return ERROR; } +/**************************************************************************** + * Function: psock_tcp_cansend + * + * Description: + * psock_tcp_cansend() returns a value indicating if a write to the socket + * would block. It is still possible that the write may block if another + * write occurs first. + * + * Parameters: + * psock An instance of the internal socket structure. + * + * Returned Value: + * OK (Function not implemented). + * + * Assumptions: + * None + * + ****************************************************************************/ + +int psock_tcp_cansend(FAR struct socket *psock) +{ + /* TODO: return OK unless someone is waiting for a packet to send */ + + return OK; +} + #endif /* CONFIG_NET && CONFIG_NET_TCP && !CONFIG_NET_TCP_WRITE_BUFFERS */ diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index 3bdb8b2ba9..d50878a455 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -201,4 +201,22 @@ void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb) sem_post(&g_wrbuffer.sem); } +/**************************************************************************** + * Function: tcp_wrbuffer_test + * + * Description: + * Check if there is room in the write buffer. Does not reserve any space. + * + * Assumptions: + * None. + * + ****************************************************************************/ + +int tcp_wrbuffer_test(void) +{ + int val = 0; + sem_getvalue(&g_wrbuffer.sem, &val); + return val > 0 ? OK : ERROR; +} + #endif /* CONFIG_NET && CONFIG_NET_TCP && CONFIG_NET_TCP_WRITE_BUFFERS */ -- GitLab From cdd187a7f3f85ef03ad20feef33395a2af24b9a2 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:54:45 -0600 Subject: [PATCH 592/858] TCP: check for sndcb before using it --- net/tcp/tcp_send_buffered.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index d25a88567f..8dfa9fae0e 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -181,8 +181,11 @@ static inline void psock_lost_connection(FAR struct socket *psock, /* Do not allow any further callbacks */ - psock->s_sndcb->flags = 0; - psock->s_sndcb->event = NULL; + if (psock->s_sndcb != NULL) + { + psock->s_sndcb->flags = 0; + psock->s_sndcb->event = NULL; + } /* Free all queued write buffers */ -- GitLab From f1ef2c6cdeb032eaa1833cc534a63b50c5058270 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:58:02 -0600 Subject: [PATCH 593/858] TCP: attempt to flush the write buffers before closing When a socket is closed, it should make sure that any pending write data is sent before the FIN is sent. It already would wait for all sent data to be acked, however it would discard any pending write data that had not been sent at least once. This change adds a check for pending write data in addition to unacked data. However, to be able to actually send any new data, the send callback must be left. The callback should be freed later when the socket is actually destroyed. --- net/socket/net_close.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 0635bab504..f2a67f78c3 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -223,7 +223,7 @@ static uint16_t netclose_interrupt(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* Check if all outstanding bytes have been ACKed */ - else if (conn->unacked != 0) + else if (conn->unacked != 0 || !sq_empty(&conn->write_q)) { /* No... we are still waiting for ACKs. Drop any received data, but * do not yet report TCP_CLOSE in the response. @@ -357,14 +357,11 @@ static inline int netclose_disconnect(FAR struct socket *psock) #ifdef CONFIG_NET_TCP_WRITE_BUFFERS if (psock->s_sndcb) { - tcp_callback_free(conn, psock->s_sndcb); psock->s_sndcb = NULL; } #endif - /* There shouldn't be any callbacks registered. */ - - DEBUGASSERT(conn && conn->list == NULL); + DEBUGASSERT(conn != NULL); /* Check for the case where the host beat us and disconnected first */ -- GitLab From 4875c6bbe328dfe666550a3791a6c5362dcb46c7 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:59:15 -0600 Subject: [PATCH 594/858] TCP: check for connection before deleting it It is possible for a socket to have no connection, for example if a TCP socket is waiting in accept. This checks for this condition in case the socket is closed from a different thread. --- net/socket/net_close.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/socket/net_close.c b/net/socket/net_close.c index f2a67f78c3..8d657583bd 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -524,9 +524,12 @@ int psock_close(FAR struct socket *psock) /* We perform the uIP close operation only if this is the last count on * the socket. (actually, I think the socket crefs only takes the values * 0 and 1 right now). + * + * It is possible for a psock to have no connection, e.g. a TCP socket + * waiting in accept. */ - if (psock->s_crefs <= 1) + if (psock->s_crefs <= 1 && psock->s_conn != NULL) { /* Perform uIP side of the close depending on the protocol type */ -- GitLab From e221777a7ae3581c1e8b773ace3b9b0c6f507b01 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 16:15:10 -0600 Subject: [PATCH 595/858] TCP: post buffer semaphore before re-acquiring both TCP uses two semaphores for buffers, one for the entire buffer pool, and one for the number of allowed buffers for readahead. To avoid double taking a semaphore under heavy load, release the semaphore after waiting before trying to acquire both again. --- net/iob/iob_alloc.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index 9fd2c0e13e..b2c9677a1e 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -121,16 +121,45 @@ static FAR struct iob_s *iob_allocwait(bool throttled) */ ret = sem_wait(sem); - - /* When we wake up from wait, an I/O buffer was returned to - * the free list. However, if there are concurrent allocations - * from interrupt handling, then I suspect that there is a - * race condition. But no harm, we will just wait again in - * that case. - */ + if (ret < 0) + { + int errcode = get_errno(); + + /* EINTR is not an error! EINTR simply means that we were + * awakened by a signal and we should try again. + */ + + if (errcode == EINTR) + { + /* Force a success indication so that we will continue + * looping. + */ + + ret = 0; + } + } + else + { + /* When we wake up from wait successfully, an I/O buffer was + * returned to the free list. However, if there are concurrent + * allocations from interrupt handling, then I suspect that + * there is a race condition. But no harm, we will just wait + * again in that case. + * + * We need release our count so that it is available to + * iob_tryalloc(), perhaps allowing another thread to take our + * count. In that event, iob_tryalloc() will fail above and + * we will have to wait again. + * + * TODO: Consider a design modification to permit us to + * complete the allocation without losing our count. + */ + + sem_post(sem); + } } } - while (ret == OK && !iob); + while (ret == OK && iob == NULL); irqrestore(flags); return iob; -- GitLab From 5e3023bef11c4d9f8ce3d2c3dcb14b2fa9a46cf0 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 16:19:20 -0600 Subject: [PATCH 596/858] TCP: return from write when there is no buffer space During a write, if there is no more buffer space for the user data, return the amount that was written instead of waiting until there is free space. If nothing has been written yet, then block as before. This solves a deadlock that occurs if the user data is too large to fit in the available buffer: the write thread will block before any data is added to the write queue, leaving no possibility that more buffers will free up when they are ACKed (since they have not yet been sent). The write thread will then block forever and hold all of the buffers. --- net/iob/iob_copyin.c | 40 ++++++++++++++++++++++++++++--------- net/tcp/tcp_send_buffered.c | 3 +-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/net/iob/iob_copyin.c b/net/iob/iob_copyin.c index 924c0a6459..d4a18e7831 100644 --- a/net/iob/iob_copyin.c +++ b/net/iob/iob_copyin.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/iob/iob_copyin.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,17 +89,21 @@ typedef CODE struct iob_s *(*iob_alloc_t)(bool throttled); * Copy data 'len' bytes from a user buffer into the I/O buffer chain, * starting at 'offset', extending the chain as necessary. * + * Returned Value: + * The number of uncopied bytes left if >= 0 OR a negative error code. + * ****************************************************************************/ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, unsigned int len, unsigned int offset, - bool throttled, iob_alloc_t allocator) + bool throttled, bool can_block) { FAR struct iob_s *head = iob; FAR struct iob_s *next; FAR uint8_t *dest; unsigned int ncopy; unsigned int avail; + unsigned int total = len; nllvdbg("iob=%p len=%u offset=%u\n", iob, len, offset); DEBUGASSERT(iob && src); @@ -207,13 +211,25 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, if (len > 0 && !next) { - /* Yes.. allocate a new buffer */ + /* Yes.. allocate a new buffer. + * + * Copy as many bytes as possible. If we have successfully copied + * any already don't block, otherwise block if we're allowed. + */ + + if (!can_block || len < total) + { + next = iob_tryalloc(throttled); + } + else + { + next = iob_alloc(throttled); + } - next = allocator(throttled); if (next == NULL) { ndbg("ERROR: Failed to allocate I/O buffer\n"); - return -ENOMEM; + return len; } /* Add the new, empty I/O buffer to the end of the buffer chain. */ @@ -226,7 +242,7 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, offset = 0; } - return OK; + return 0; } /**************************************************************************** @@ -245,7 +261,7 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src, unsigned int len, unsigned int offset, bool throttled) { - return iob_copyin_internal(iob, src, len, offset, throttled, iob_alloc); + return len - iob_copyin_internal(iob, src, len, offset, throttled, true); } /**************************************************************************** @@ -261,6 +277,12 @@ int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src, int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src, unsigned int len, unsigned int offset, bool throttled) { - return iob_copyin_internal(iob, src, len, offset, throttled, iob_tryalloc); + if (iob_copyin_internal(iob, src, len, offset, throttled, false) == 0) + { + return OK; + } + else + { + return -ENOMEM; + } } - diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 8dfa9fae0e..1d560c7e89 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -1046,7 +1046,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, WRB_SEQNO(wrb) = (unsigned)-1; WRB_NRTX(wrb) = 0; - WRB_COPYIN(wrb, (FAR uint8_t *)buf, len); + result = WRB_COPYIN(wrb, (FAR uint8_t *)buf, len); /* Dump I/O buffer chain */ @@ -1065,7 +1065,6 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, send_txnotify(psock, conn); net_unlock(save); - result = len; } /* Set the socket state to idle */ -- GitLab From 49e5cc5a6fa19460b41c8667d67b912d6f71affe Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 16:22:09 -0600 Subject: [PATCH 597/858] TCP: check for an active connection before cleaning it up If there is no active connection (e.g. it is waiting in accept), then the connection object, which doesn't yet exist, should not be cleaned up when the socket is closed. --- net/tcp/tcp_send_buffered.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 1d560c7e89..077a1dbe2e 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -507,9 +507,12 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, { nllvdbg("Lost connection: %04x\n", flags); - /* Report not connected */ + if (psock->s_conn != NULL) + { + /* Report not connected */ - net_lostconnection(psock, flags); + net_lostconnection(psock, flags); + } /* Free write buffers and terminate polling */ -- GitLab From 5c589e5b9c98aa8965a9cdce632261c7138035aa Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 16:23:31 -0600 Subject: [PATCH 598/858] Net: use nlldbg since an iob can be added from an interrupt --- net/iob/iob_add_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/iob/iob_add_queue.c b/net/iob/iob_add_queue.c index c3da0dd68f..bc7e0adb8e 100644 --- a/net/iob/iob_add_queue.c +++ b/net/iob/iob_add_queue.c @@ -150,7 +150,7 @@ int iob_tryadd_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq) qentry = iob_tryalloc_qentry(); if (!qentry) { - ndbg("ERROR: Failed to allocate a container\n"); + nlldbg("ERROR: Failed to allocate a container\n"); return -ENOMEM; } -- GitLab From bf2106a684042c0e9c7d67bc28cc6db67c3bd7f4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 16:26:16 -0600 Subject: [PATCH 599/858] Update ChangeLog --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index b2432bfce2..1d6caa8bc7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11344,3 +11344,8 @@ From Andrew Webster (2016-01-21). * arch/arm/src/kinetis: Add support for the MK60N512VLL100 Kinetis part. From Andrew Webster (2016-01-21). + * net/tcp and net/iob: Numerous fixes, mostly relate to TCP and IOB + buffering and race conditions. These were necessary for for the + NuttX networking later to be stable in some stress testing. From + Andrew Webster (2016-01-22). + -- GitLab From 3ba9e82c72da0278496a08091105e220ee961f00 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 17:21:49 -0600 Subject: [PATCH 600/858] Update README --- Documentation | 2 +- binfmt/libpcode/README.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation b/Documentation index 32d1052962..8fab2a865d 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 32d10529620c0bf17c207760ef85b1457d1799a0 +Subproject commit 8fab2a865d3cc1496588c5a1227037dfb1f970e3 diff --git a/binfmt/libpcode/README.txt b/binfmt/libpcode/README.txt index 8f980ce1e9..d0bbb4ffc3 100644 --- a/binfmt/libpcode/README.txt +++ b/binfmt/libpcode/README.txt @@ -50,6 +50,8 @@ Files include in this directory include: xxd -g 1 -i romfs.img >romfs.h then cleaned up with an editor to conform with NuttX coding standards. + Also, the data definitions in the romfs.h file should be marked with + 'const' qualifier the so that the data will be stored in FLASH. Test Configuration ------------------ -- GitLab From 91b762aa86d49aa58cd28faa4c9e6fb6799cef56 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Jan 2016 17:35:06 -0600 Subject: [PATCH 601/858] Networking: Fix an error that I introduced with my last review changes --- net/iob/iob_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index b2c9677a1e..08d13ce30c 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/iob/iob_alloc.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include -- GitLab From 9ece46e917e7a053c4cc4f8393bb9cb669de4828 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 11:18:39 -0600 Subject: [PATCH 602/858] Costmetic update --- libc/misc/lib_crc8.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libc/misc/lib_crc8.c b/libc/misc/lib_crc8.c index 8bd10995f0..ae3e01d5d7 100644 --- a/libc/misc/lib_crc8.c +++ b/libc/misc/lib_crc8.c @@ -47,20 +47,27 @@ /************************************************************************************************ * Private Data - * + ************************************************************************************************/ + +/************************************************************************************************ * CRC8 table generated with: * * #define POLY 0xB2 // ((uint8_t) 0x14D) ^ 0xFF * * printf(" "); - * for (y=0; y<256; y++) - * { - * crc = y; - * for (x=0; x<8; x++) - * crc = (crc & 1) ? POLY ^ (crc >> 1) : crc >> 1; + * for (y = 0; y < 256; y++) + * { + * crc = y; + * for (x = 0; x < 8; x++) + * { + * crc = (crc & 1) ? POLY ^ (crc >> 1) : crc >> 1; + * } + * * printf("0x%02X, ", crc); * if ((y & 0x07) == 0x7) - * printf("\n "); + * { + * printf("\n "); + * } * } * ************************************************************************************************/ @@ -104,6 +111,7 @@ static const uint8_t crc8_tab[256] = /************************************************************************************************ * Public Functions ************************************************************************************************/ + /************************************************************************************************ * Name: crc8part * @@ -138,4 +146,3 @@ uint8_t crc8(FAR const uint8_t *src, size_t len) { return crc8part(src, len, 0); } - -- GitLab From accd99db25ebcbc8a9cb080b431d01a74f540778 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 15:12:45 -0600 Subject: [PATCH 603/858] Add an optional hwfeatures method to the SPI interface --- ChangeLog | 2 ++ arch | 2 +- configs | 2 +- drivers/spi/Kconfig | 17 +++++++++++++ drivers/spi/spi_bitbang.c | 29 ++++++++++++---------- include/nuttx/spi/spi.h | 51 ++++++++++++++++++++++++++++++++++++++- 6 files changed, 87 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d6caa8bc7..7ba0f26784 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11348,4 +11348,6 @@ buffering and race conditions. These were necessary for for the NuttX networking later to be stable in some stress testing. From Andrew Webster (2016-01-22). + * include/spi/spi.h: Add an optional hwfeaqtures() method to the + SPI interface (2016-01-22). diff --git a/arch b/arch index eabf13f41e..10e420a652 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit eabf13f41e38c104b907bb4cb29655b3cba9f35f +Subproject commit 10e420a652fd8bcf9441f542172182f5db05e70a diff --git a/configs b/configs index bc84da3069..5f36fcd26e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bc84da30695b62f2d559ce49993b72489d605480 +Subproject commit 5f36fcd26edfb955c28974a2d335ad5e82a3c515 diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 488c08c251..c416b67b56 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -62,6 +62,23 @@ config SPI_BITBANG Enable support for a generic SPI bit-bang device. See include/nuttx/spi/spi_bitbang.h for further information. +config SPI_HWFEATURES + bool + default n + ---help--- + Selected only if a specific H/W feature is selected. This is + basically the OR of any specific hardware feature and eanbles + the SPI hwfeatures() interface method. + +config SPI_CRCGENERATION + bool + default n + select SPI_HWFEATURES + ---help--- + Selected by MCU Kconfig logic if implementation supports automatic + generation of SPI CRCs. Enables the HWFEAT_CRCGENERATION option + as well as the hwfeartures() interface method. + if SPI_BITBANG config SPI_BITBANG_VARWIDTH diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index fae90a75ad..7f3a41c549 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/spi/spi_bitbang.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -145,24 +145,27 @@ static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, static const struct spi_ops_s g_spiops = { #ifndef CONFIG_SPI_OWNBUS - .lock = spi_lock, + spi_lock, /* lock */ #endif - .select = spi_select, - .setfrequency = spi_setfrequency, - .setmode = spi_setmode, - .setbits = spi_setbits, - .status = spi_status, + spi_select, /* select */ + spi_setfrequency, /* setfrequency */ + spi_setmode, /* setmode */ + spi_setbits, /* setbits */ +#ifdef CONFIG_SPI_HWFEATURES + 0, /* hwfeatures */ +#endif + spi_status, /* status */ #ifdef CONFIG_SPI_CMDDATA - .cmddata = spi_cmddata, + spi_cmddata, /* cmddata */ #endif - .send = spi_send, + spi_send, /* send */ #ifdef CONFIG_SPI_EXCHANGE - .exchange = spi_exchange, + spi_exchange, /* exchange */ #else - .sndblock = spi_sndblock, - .recvblock = spi_recvblock, + spi_sndblock, /* sndblock */ + spi_recvblock, /* recvblock */ #endif - .registercallback = 0, /* Not implemented */ + 0 /* registercallback */ }; /**************************************************************************** diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index ebd4d872e1..fb2b012c97 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/spi/spi.h * - * Copyright(C) 2008-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright(C) 2008-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -166,6 +167,44 @@ #define SPI_SETBITS(d,b) \ do { if ((d)->ops->setbits) (d)->ops->setbits(d,b); } while (0) +/**************************************************************************** + * Name: SPI_HWFEATURES + * + * Description: + * Set hardware-specific feature flags. + * + * Input Parameters: + * dev - Device-specific state data + * flags - H/W feature flags + * + * Returned Value: + * Zero (OK) if the selected H/W features are enabled; A negated errno + * value if any H/W feature is not supportable. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_HWFEATURES + /* If there are multiple SPI drivers, some may not support hardware + * feature selection. + */ + +# define SPI_HWFEATURES(d,f) \ + (((d)->ops->hwfeatures) ? (d)->ops->hwfeatures(d,f) : ((f) == 0 ? OK : -ENOSYS)) + + /* These are currently defined feature flags */ + +# ifdef CONFIG_SPI_CRCGENERATION +# HWFEAT_CRCGENERATION (1 << 0) /* Bit 0: Hardward CRC generation */ +# endif + +#else + /* Any attempt to select hardware features with CONFIG_SPI_HWFEATURES + * deselected will cause an assertion. + */ + +# define SPI_HWFEATURES(d,f) (((f) == 0) ? OK : -ENOSYS) +#endif + /**************************************************************************** * Name: SPI_STATUS * @@ -378,6 +417,12 @@ enum spi_mode_e SPIDEV_MODE3 /* CPOL=1 CHPHA=1 */ }; +#ifdef CONFIG_SPI_HWFEATURES +/* This is a type wide enough to support all hardware features */ + +typedef uint8_t spi_hwfeatures_t; +#endif + /* The SPI vtable */ struct spi_dev_s; @@ -391,6 +436,10 @@ struct spi_ops_s CODE uint32_t (*setfrequency)(FAR struct spi_dev_s *dev, uint32_t frequency); CODE void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode); CODE void (*setbits)(FAR struct spi_dev_s *dev, int nbits); +#ifdef CONFIG_SPI_HWFEATURES + CODE int (*hwfeatures)(FAR struct spi_dev_s *dev, + spi_hwfeatures_t features); +#endif CODE uint8_t (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); #ifdef CONFIG_SPI_CMDDATA CODE int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, -- GitLab From c36c49657b9718569f8a72e261b79f22672e71d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 15:26:10 -0600 Subject: [PATCH 604/858] Remove carriage returns from files --- arch | 2 +- configs | 2 +- libnx/nxglib/nxglib_rgbblend.c | 466 ++++++++++++++++----------------- 3 files changed, 235 insertions(+), 235 deletions(-) diff --git a/arch b/arch index 10e420a652..244343293f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 10e420a652fd8bcf9441f542172182f5db05e70a +Subproject commit 244343293fcfa82e03e002fa792a4e09d238b9f2 diff --git a/configs b/configs index 5f36fcd26e..06c7256f4e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 5f36fcd26edfb955c28974a2d335ad5e82a3c515 +Subproject commit 06c7256f4ece872da23f96e1e587e86e0ba89271 diff --git a/libnx/nxglib/nxglib_rgbblend.c b/libnx/nxglib/nxglib_rgbblend.c index 41b8cc9430..96b1fd7003 100644 --- a/libnx/nxglib/nxglib_rgbblend.c +++ b/libnx/nxglib/nxglib_rgbblend.c @@ -1,233 +1,233 @@ -/**************************************************************************** - * libnx/nxglib/nxglib_runcopy.c - * - * Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxglib_rgb24_blend and nxglib_rgb565_blend - * - * Description: - * Blend a single RGB color component. This is *not* alpha blending: - * component2 is assumed to be opaque and "under" a semi-transparent - * component1. - * - * The frac1 value could be though as related to the 1/alpha value for - * component1. However, the background, component2, is always treated as though - * alpha == 1. - * - * This algorithm is used to handle endpoints as part of the - * implementation of anti-aliasing without transparency. - * - * Input Parameters: - * component1 - The semi-transparent, forground 8-bit color component - * component2 - The opaque, background color component - * frac1 - The fractional amount of component1 to blend into component2 - * - * Returned Value: - * The blended 8-bit color component. - * - ****************************************************************************/ - -#if !defined(CONFIG_NX_DISABLE_16BPP) || !defined(CONFIG_NX_DISABLE_24BPP) || \ - !defined(CONFIG_NX_DISABLE_32BPP) - -static uint8_t nxglib_blend_component(uint8_t component1, uint8_t component2, - ub8_t frac1) -{ - uint16_t blend; - uint32_t blendb8; - - /* Use a uint32_t for the intermediate calculation. Due to rounding this - * value could exceed ub8MAX (0xffff == 255.999..). - * - * Hmm.. that might not actually be possible but this gives me piece of - * mind and there should not be any particular overhead on a 32-bit - * processor. - */ - - blendb8 = (uint32_t)((ub16_t)component1 * frac1) + - (uint32_t)((ub16_t)component2 * (b8ONE - frac1)) + - (uint32_t)b8HALF; - - /* Now we can snap it down to 16-bits and check for the overflow condition. */ - - blend = ub8toi(blendb8); - if (blend > 255) - { - blend = 255; - } - - /* Return the blended value */ - - return (uint8_t)blend; -} - -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nxglib_rgb24_blend and nxglib_rgb565_blend - * - * Description: - * Blend a foreground color onto a background color. This is *not* alpha - * blending: color2 is assumed to be opaque and "under" a semi- - * transparent color1. - * - * The frac1 value could be though as related to the 1/alpha value for - * color1. However, the background, color2, is always treated as though - * alpha == 1. - * - * This algorithm is used to handle endpoints as part of the - * implementation of anti-aliasing without transparency. - * - * Input Parameters: - * color1 - The semi-transparent, forground color - * color2 - The opaque, background color - * frac1 - The fractional amount of color1 to blend into color2 - * - * Returned Value: - * The blended color, encoded just was the input color1 and color2 - * - ****************************************************************************/ - -#if !defined(CONFIG_NX_DISABLE_24BPP) || !defined(CONFIG_NX_DISABLE_32BPP) - -uint32_t nxglib_rgb24_blend(uint32_t color1, uint32_t color2, ub16_t frac1) -{ - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t bg; - ub8_t fracb8; - - /* Convert the fraction to ub8_t. We don't need that much precision to - * scale an 8-bit color component. - */ - - fracb8 = ub16toub8(frac1); - - /* Some limit checks. Rounding in the b16 to b8 conversion could cause - * the fraction exceed one; the loss of precision could cause small b16 - * values to convert to zero. - */ - - if (fracb8 >= b8ONE) - { - return color1; - } - else if (fracb8 == 0) - { - return color2; - } - - /* Separate and blend each component */ - - r = RGB24RED(color1); - bg = RGB24RED(color2); - r = nxglib_blend_component(r, bg, fracb8); - - g = RGB24GREEN(color1); - bg = RGB24GREEN(color2); - g = nxglib_blend_component(g, bg, fracb8); - - b = RGB24BLUE(color1); - bg = RGB24BLUE(color2); - b = nxglib_blend_component(b, bg, fracb8); - - /* Recombine and return the blended value */ - - return RGBTO24(r,g,b) ; -} - -#endif - -#ifndef CONFIG_NX_DISABLE_16BPP - -uint16_t nxglib_rgb565_blend(uint16_t color1, uint16_t color2, ub16_t frac1) -{ - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t bg; - ub8_t fracb8; - - /* Convert the fraction to ub8_t. We don't need that much precision. */ - - fracb8 = ub16toub8(frac1); - - /* Some limit checks */ - - if (fracb8 >= b8ONE) - { - return color1; - } - else if (fracb8 == 0) - { - return color2; - } - - /* Separate and blend each component */ - - r = RGB16RED(color1); - bg = RGB16RED(color2); - r = nxglib_blend_component(r, bg, fracb8); - - g = RGB16GREEN(color1); - bg = RGB16GREEN(color2); - g = nxglib_blend_component(g, bg, fracb8); - - b = RGB16BLUE(color1); - bg = RGB16BLUE(color2); - b = nxglib_blend_component(b, bg, fracb8); - - /* Recombine and return the blended value */ - - return RGBTO24(r,g,b) ; -} - -#endif +/**************************************************************************** + * libnx/nxglib/nxglib_runcopy.c + * + * Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxglib_rgb24_blend and nxglib_rgb565_blend + * + * Description: + * Blend a single RGB color component. This is *not* alpha blending: + * component2 is assumed to be opaque and "under" a semi-transparent + * component1. + * + * The frac1 value could be though as related to the 1/alpha value for + * component1. However, the background, component2, is always treated as though + * alpha == 1. + * + * This algorithm is used to handle endpoints as part of the + * implementation of anti-aliasing without transparency. + * + * Input Parameters: + * component1 - The semi-transparent, forground 8-bit color component + * component2 - The opaque, background color component + * frac1 - The fractional amount of component1 to blend into component2 + * + * Returned Value: + * The blended 8-bit color component. + * + ****************************************************************************/ + +#if !defined(CONFIG_NX_DISABLE_16BPP) || !defined(CONFIG_NX_DISABLE_24BPP) || \ + !defined(CONFIG_NX_DISABLE_32BPP) + +static uint8_t nxglib_blend_component(uint8_t component1, uint8_t component2, + ub8_t frac1) +{ + uint16_t blend; + uint32_t blendb8; + + /* Use a uint32_t for the intermediate calculation. Due to rounding this + * value could exceed ub8MAX (0xffff == 255.999..). + * + * Hmm.. that might not actually be possible but this gives me piece of + * mind and there should not be any particular overhead on a 32-bit + * processor. + */ + + blendb8 = (uint32_t)((ub16_t)component1 * frac1) + + (uint32_t)((ub16_t)component2 * (b8ONE - frac1)) + + (uint32_t)b8HALF; + + /* Now we can snap it down to 16-bits and check for the overflow condition. */ + + blend = ub8toi(blendb8); + if (blend > 255) + { + blend = 255; + } + + /* Return the blended value */ + + return (uint8_t)blend; +} + +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxglib_rgb24_blend and nxglib_rgb565_blend + * + * Description: + * Blend a foreground color onto a background color. This is *not* alpha + * blending: color2 is assumed to be opaque and "under" a semi- + * transparent color1. + * + * The frac1 value could be though as related to the 1/alpha value for + * color1. However, the background, color2, is always treated as though + * alpha == 1. + * + * This algorithm is used to handle endpoints as part of the + * implementation of anti-aliasing without transparency. + * + * Input Parameters: + * color1 - The semi-transparent, forground color + * color2 - The opaque, background color + * frac1 - The fractional amount of color1 to blend into color2 + * + * Returned Value: + * The blended color, encoded just was the input color1 and color2 + * + ****************************************************************************/ + +#if !defined(CONFIG_NX_DISABLE_24BPP) || !defined(CONFIG_NX_DISABLE_32BPP) + +uint32_t nxglib_rgb24_blend(uint32_t color1, uint32_t color2, ub16_t frac1) +{ + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t bg; + ub8_t fracb8; + + /* Convert the fraction to ub8_t. We don't need that much precision to + * scale an 8-bit color component. + */ + + fracb8 = ub16toub8(frac1); + + /* Some limit checks. Rounding in the b16 to b8 conversion could cause + * the fraction exceed one; the loss of precision could cause small b16 + * values to convert to zero. + */ + + if (fracb8 >= b8ONE) + { + return color1; + } + else if (fracb8 == 0) + { + return color2; + } + + /* Separate and blend each component */ + + r = RGB24RED(color1); + bg = RGB24RED(color2); + r = nxglib_blend_component(r, bg, fracb8); + + g = RGB24GREEN(color1); + bg = RGB24GREEN(color2); + g = nxglib_blend_component(g, bg, fracb8); + + b = RGB24BLUE(color1); + bg = RGB24BLUE(color2); + b = nxglib_blend_component(b, bg, fracb8); + + /* Recombine and return the blended value */ + + return RGBTO24(r,g,b); +} + +#endif + +#ifndef CONFIG_NX_DISABLE_16BPP + +uint16_t nxglib_rgb565_blend(uint16_t color1, uint16_t color2, ub16_t frac1) +{ + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t bg; + ub8_t fracb8; + + /* Convert the fraction to ub8_t. We don't need that much precision. */ + + fracb8 = ub16toub8(frac1); + + /* Some limit checks */ + + if (fracb8 >= b8ONE) + { + return color1; + } + else if (fracb8 == 0) + { + return color2; + } + + /* Separate and blend each component */ + + r = RGB16RED(color1); + bg = RGB16RED(color2); + r = nxglib_blend_component(r, bg, fracb8); + + g = RGB16GREEN(color1); + bg = RGB16GREEN(color2); + g = nxglib_blend_component(g, bg, fracb8); + + b = RGB16BLUE(color1); + bg = RGB16BLUE(color2); + b = nxglib_blend_component(b, bg, fracb8); + + /* Recombine and return the blended value */ + + return RGBTO24(r,g,b); +} + +#endif -- GitLab From f6e49caba89ffc2033e152c8164a5a49cf154a2f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 16:18:13 -0600 Subject: [PATCH 605/858] All SPI-based device drivers needs to call SPI_HWFEATURES() with zero in order to co-exist with drivers that use H/W features --- configs | 2 +- drivers/analog/ads1255.c | 1 + drivers/analog/pga11x.c | 1 + drivers/audio/vs1053.c | 1 + drivers/eeprom/spi_xx25xx.c | 1 + drivers/input/ads7843e.c | 6 ++++-- drivers/input/max11802.c | 6 ++++-- drivers/lcd/memlcd.c | 10 ++++++---- drivers/lcd/nokia6100.c | 6 ++++-- drivers/lcd/p14201.c | 6 ++++-- drivers/lcd/ssd1306_base.c | 13 +++++++------ drivers/lcd/ssd1306_spi.c | 3 ++- drivers/lcd/ssd1351.c | 6 ++++-- drivers/lcd/st7567.c | 3 ++- drivers/lcd/ug-2864ambag01.c | 6 ++++-- drivers/lcd/ug-9664hswag01.c | 3 ++- drivers/mmcsd/mmcsd_spi.c | 6 ++++-- drivers/mtd/at25.c | 1 + drivers/mtd/at45db.c | 1 + drivers/mtd/m25px.c | 1 + drivers/mtd/ramtron.c | 1 + drivers/mtd/sst25.c | 1 + drivers/mtd/sst25xx.c | 1 + drivers/mtd/w25.c | 1 + drivers/net/enc28j60.c | 6 ++++-- drivers/net/encx24j600.c | 6 ++++-- drivers/sensors/adxl345_base.c | 3 ++- drivers/sensors/adxl345_spi.c | 3 ++- drivers/sensors/max31855.c | 3 ++- drivers/sensors/max6675.c | 3 ++- drivers/sensors/mpl115a.c | 3 ++- drivers/wireless/cc1101.c | 1 + drivers/wireless/cc3000/cc3000.c | 3 ++- drivers/wireless/nrf24l01.c | 6 ++++-- drivers/wireless/pn532.c | 6 ++++-- 35 files changed, 88 insertions(+), 42 deletions(-) diff --git a/configs b/configs index 06c7256f4e..66325b8ab4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 06c7256f4ece872da23f96e1e587e86e0ba89271 +Subproject commit 66325b8ab4f012c1261e88ae262d5cd2e3d54fd1 diff --git a/drivers/analog/ads1255.c b/drivers/analog/ads1255.c index 93bed6d2f6..432b7dd766 100644 --- a/drivers/analog/ads1255.c +++ b/drivers/analog/ads1255.c @@ -203,6 +203,7 @@ static void adc_reset(FAR struct adc_dev_s *dev) SPI_SETMODE(spi, SPIDEV_MODE1); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); SPI_SETFREQUENCY(spi, CONFIG_ADS1255_FREQUENCY); usleep(1000); SPI_SELECT(spi, priv->devno, true); diff --git a/drivers/analog/pga11x.c b/drivers/analog/pga11x.c index 7bb4a11bb0..143b897bc9 100644 --- a/drivers/analog/pga11x.c +++ b/drivers/analog/pga11x.c @@ -155,6 +155,7 @@ static void pga11x_configure(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_PGA11X_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_PGA11X_SPIFREQUENCY); } diff --git a/drivers/audio/vs1053.c b/drivers/audio/vs1053.c index 35b0a95647..68167ca31e 100644 --- a/drivers/audio/vs1053.c +++ b/drivers/audio/vs1053.c @@ -274,6 +274,7 @@ static void vs1053_spi_lock(FAR struct spi_dev_s *dev, unsigned long freq_mhz) SPI_SETMODE(dev, CONFIG_VS1053_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, freq_mhz); } diff --git a/drivers/eeprom/spi_xx25xx.c b/drivers/eeprom/spi_xx25xx.c index 6fdc39458b..1f9335b856 100644 --- a/drivers/eeprom/spi_xx25xx.c +++ b/drivers/eeprom/spi_xx25xx.c @@ -288,6 +288,7 @@ static void ee25xx_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_EE25XX_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, 10000000); /* This is the default speed */ } diff --git a/drivers/input/ads7843e.c b/drivers/input/ads7843e.c index c0500229b5..d09afce312 100644 --- a/drivers/input/ads7843e.c +++ b/drivers/input/ads7843e.c @@ -197,7 +197,8 @@ static void ads7843e_lock(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true); SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); } #endif @@ -258,7 +259,8 @@ static inline void ads7843e_configspi(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true); SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); } #endif diff --git a/drivers/input/max11802.c b/drivers/input/max11802.c index fe87fc32fe..85a5b77347 100644 --- a/drivers/input/max11802.c +++ b/drivers/input/max11802.c @@ -197,7 +197,8 @@ static void max11802_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); } #endif @@ -256,7 +257,8 @@ static inline void max11802_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); } #endif diff --git a/drivers/lcd/memlcd.c b/drivers/lcd/memlcd.c index 06683ba0c9..c4a8a6e10f 100644 --- a/drivers/lcd/memlcd.c +++ b/drivers/lcd/memlcd.c @@ -299,10 +299,11 @@ static inline void memlcd_configspi(FAR struct spi_dev_s *spi) #ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, MEMLCD_SPI_MODE); SPI_SETBITS(spi, MEMLCD_SPI_BITS); + (void)SPI_HWFEATURES(spi, 0); # ifdef CONFIG_MEMLCD_SPI_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY); # else - SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); # endif #endif } @@ -344,10 +345,11 @@ static void memlcd_select(FAR struct spi_dev_s *spi) */ SPI_SETMODE(spi, MEMLCD_SPI_MODE); SPI_SETBITS(spi, MEMLCD_SPI_BITS); + (void)SPI_HWFEATURES(spi, 0); # ifdef CONFIG_MEMLCD_SPI_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY); # else - SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); # endif } #endif diff --git a/drivers/lcd/nokia6100.c b/drivers/lcd/nokia6100.c index 735ae3c628..d6f71590e9 100644 --- a/drivers/lcd/nokia6100.c +++ b/drivers/lcd/nokia6100.c @@ -678,7 +678,8 @@ static inline void nokia_configspi(FAR struct spi_dev_s *spi) #ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); - SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY) + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY) #endif } @@ -723,7 +724,8 @@ static void nokia_select(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); - SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY); } #endif diff --git a/drivers/lcd/p14201.c b/drivers/lcd/p14201.c index a97a608e32..b79e036aed 100644 --- a/drivers/lcd/p14201.c +++ b/drivers/lcd/p14201.c @@ -460,8 +460,9 @@ static inline void rit_configspi(FAR struct spi_dev_s *spi) #ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_P14201_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); #ifdef CONFIG_P14201_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY) + (void)SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY) #endif #endif } @@ -505,8 +506,9 @@ static void rit_select(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_P14201_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); #ifdef CONFIG_P14201_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY); #endif } #endif diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index a47fb590bc..13d0a7195d 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -824,15 +824,16 @@ FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_dev_s *dev, unsigned int */ # ifdef CONFIG_SPI_OWNBUS - /* Configure SPI */ + /* Configure SPI */ - SPI_SETMODE(priv->spi, CONFIG_SSD1306_SPIMODE); - SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, CONFIG_SSD1306_FREQUENCY); + SPI_SETMODE(priv->spi, CONFIG_SSD1306_SPIMODE); + SPI_SETBITS(priv->spi, 8); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, CONFIG_SSD1306_FREQUENCY); # else - /* Configure the SPI */ + /* Configure the SPI */ - ssd1306_configspi(priv->spi); + ssd1306_configspi(priv->spi); # endif #else diff --git a/drivers/lcd/ssd1306_spi.c b/drivers/lcd/ssd1306_spi.c index 78fcdbb601..fedc3eae9d 100644 --- a/drivers/lcd/ssd1306_spi.c +++ b/drivers/lcd/ssd1306_spi.c @@ -71,7 +71,8 @@ static inline void ssd1306_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_SSD1306_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_SSD1306_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1306_FREQUENCY); } #endif diff --git a/drivers/lcd/ssd1351.c b/drivers/lcd/ssd1351.c index 45e768a879..30178930a2 100644 --- a/drivers/lcd/ssd1351.c +++ b/drivers/lcd/ssd1351.c @@ -510,7 +510,8 @@ static void ssd1351_select(FAR struct ssd1351_dev_s *priv) #ifndef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); SPI_SETBITS(spi, SSD1351_SPIBITS); - SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); #endif } #endif @@ -1196,7 +1197,8 @@ FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, #ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); SPI_SETBITS(spi, SSD1351_SPIBITS); - SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); #endif #endif diff --git a/drivers/lcd/st7567.c b/drivers/lcd/st7567.c index 33d4a773ef..1a597f22e4 100644 --- a/drivers/lcd/st7567.c +++ b/drivers/lcd/st7567.c @@ -394,8 +394,9 @@ static void st7567_select(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_ST7567_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); #ifdef CONFIG_ST7567_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_ST7567_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, CONFIG_ST7567_FREQUENCY); #endif } #endif diff --git a/drivers/lcd/ug-2864ambag01.c b/drivers/lcd/ug-2864ambag01.c index ffc3a8a8b1..1d1b773316 100644 --- a/drivers/lcd/ug-2864ambag01.c +++ b/drivers/lcd/ug-2864ambag01.c @@ -436,7 +436,8 @@ static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_UG2864AMBAG01_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); } #endif @@ -469,7 +470,8 @@ static inline void ug2864ambag01_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_UG2864AMBAG01_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); } #endif diff --git a/drivers/lcd/ug-9664hswag01.c b/drivers/lcd/ug-9664hswag01.c index 5a567688ac..be97d551b0 100644 --- a/drivers/lcd/ug-9664hswag01.c +++ b/drivers/lcd/ug-9664hswag01.c @@ -438,8 +438,9 @@ static void ug_select(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_UG9664HSWAG01_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); #ifdef CONFIG_UG9664HSWAG01_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_UG9664HSWAG01_FREQUENCY); + (void)SPI_SETFREQUENCY(spi, CONFIG_UG9664HSWAG01_FREQUENCY); #endif } #endif diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index b5ab0cd8e3..e4cfc4ecda 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -365,9 +365,10 @@ static void mmcsd_semtake(FAR struct mmcsd_slot_s *slot) * changed those since the last time that we had the SPI bus. */ - SPI_SETFREQUENCY(slot->spi, slot->spispeed); SPI_SETMODE(slot->spi, CONFIG_MMCSD_SPIMODE); SPI_SETBITS(slot->spi, 8); + (void)SPI_HWFEATURES(slot->spi, 0); + (void)SPI_SETFREQUENCY(slot->spi, slot->spispeed); #endif /* Get exclusive access to the MMC/SD device (possibly unnecessary if @@ -425,6 +426,7 @@ static inline void mmcsd_spiinit(FAR struct mmcsd_slot_s *slot) { SPI_SETMODE(slot->spi, CONFIG_MMCSD_SPIMODE); SPI_SETBITS(slot->spi, 8); + (void)SPI_HWFEATURES(slot->spi, 0); } #endif @@ -1608,7 +1610,7 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) #ifndef CONFIG_SPI_OWNBUS slot->spispeed = MMCSD_IDMODE_CLOCK; #endif - SPI_SETFREQUENCY(spi, MMCSD_IDMODE_CLOCK); + (void)SPI_SETFREQUENCY(spi, MMCSD_IDMODE_CLOCK); /* Set the maximum access time out */ diff --git a/drivers/mtd/at25.c b/drivers/mtd/at25.c index 87b08405a4..8ab7c1728c 100644 --- a/drivers/mtd/at25.c +++ b/drivers/mtd/at25.c @@ -191,6 +191,7 @@ static void at25_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_AT25_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, CONFIG_AT25_SPIFREQUENCY); } diff --git a/drivers/mtd/at45db.c b/drivers/mtd/at45db.c index 0fb7d8018d..a76994d5e4 100644 --- a/drivers/mtd/at45db.c +++ b/drivers/mtd/at45db.c @@ -292,6 +292,7 @@ static void at45db_lock(FAR struct at45db_dev_s *priv) SPI_SETMODE(priv->spi, SPIDEV_MODE0); SPI_SETBITS(priv->spi, 8); + (void)SPI_HWFEATURES(priv->spi, 0); (void)SPI_SETFREQUENCY(priv->spi, CONFIG_AT45DB_FREQUENCY); } diff --git a/drivers/mtd/m25px.c b/drivers/mtd/m25px.c index 60eba9558a..f1b71dfc11 100644 --- a/drivers/mtd/m25px.c +++ b/drivers/mtd/m25px.c @@ -284,6 +284,7 @@ static void m25p_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_M25P_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, 20000000); } diff --git a/drivers/mtd/ramtron.c b/drivers/mtd/ramtron.c index b800d0f27c..89e0ade859 100644 --- a/drivers/mtd/ramtron.c +++ b/drivers/mtd/ramtron.c @@ -343,6 +343,7 @@ static void ramtron_lock(FAR struct ramtron_dev_s *priv) SPI_SETMODE(dev, SPIDEV_MODE3); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, priv->speed); } diff --git a/drivers/mtd/sst25.c b/drivers/mtd/sst25.c index 3a3db16e19..2a9b3e50f0 100644 --- a/drivers/mtd/sst25.c +++ b/drivers/mtd/sst25.c @@ -286,6 +286,7 @@ static void sst25_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_SST25_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, CONFIG_SST25_SPIFREQUENCY); } diff --git a/drivers/mtd/sst25xx.c b/drivers/mtd/sst25xx.c index 8598dd51d7..3a1c086c25 100644 --- a/drivers/mtd/sst25xx.c +++ b/drivers/mtd/sst25xx.c @@ -236,6 +236,7 @@ static void sst25xx_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_SST25XX_SPIMODE); SPI_SETBITS(dev, 8); + (void)SPI_HWFEATURES(dev, 0); (void)SPI_SETFREQUENCY(dev, CONFIG_SST25XX_SPIFREQUENCY); } diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index df5ec83df6..1ea22d5bc3 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -310,6 +310,7 @@ static void w25_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_W25_SPIMODE); SPI_SETBITS(spi, 8); + (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_W25_SPIFREQUENCY); } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index b619c59b31..43d0e6c685 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -381,7 +381,8 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_ENC28J60_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY); } #endif @@ -416,7 +417,8 @@ static void enc_lock(FAR struct enc_driver_s *priv) SPI_SETMODE(priv->spi, CONFIG_ENC28J60_SPIMODE); SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, CONFIG_ENC28J60_FREQUENCY); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, CONFIG_ENC28J60_FREQUENCY); } #endif diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index fcd36f87a0..8c5e57e255 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -404,7 +404,8 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_ENCX24J600_SPIMODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_ENCX24J600_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_ENCX24J600_FREQUENCY); } #endif @@ -439,7 +440,8 @@ static void enc_lock(FAR struct enc_driver_s *priv) SPI_SETMODE(priv->spi, CONFIG_ENCX24J600_SPIMODE); SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, CONFIG_ENCX24J600_FREQUENCY); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, CONFIG_ENCX24J600_FREQUENCY); } #endif diff --git a/drivers/sensors/adxl345_base.c b/drivers/sensors/adxl345_base.c index d761702a33..dfca4e30d0 100644 --- a/drivers/sensors/adxl345_base.c +++ b/drivers/sensors/adxl345_base.c @@ -419,7 +419,8 @@ ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_dev_s *dev, SPI_SETMODE(priv->spi, SPIDEV_MODE3); SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, ADXL345_SPI_MAXFREQUENCY); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, ADXL345_SPI_MAXFREQUENCY); #endif #else diff --git a/drivers/sensors/adxl345_spi.c b/drivers/sensors/adxl345_spi.c index 0c9cf0b118..381eec64b7 100644 --- a/drivers/sensors/adxl345_spi.c +++ b/drivers/sensors/adxl345_spi.c @@ -71,7 +71,8 @@ static inline void adxl345_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE3); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, ADXL345_SPI_MAXFREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, ADXL345_SPI_MAXFREQUENCY); } #endif diff --git a/drivers/sensors/max31855.c b/drivers/sensors/max31855.c index fae6d8783e..7fc21f4356 100644 --- a/drivers/sensors/max31855.c +++ b/drivers/sensors/max31855.c @@ -284,7 +284,8 @@ int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi) SPI_SETMODE(priv->spi, SPIDEV_MODE1); SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, MAX31855_SPI_MAXFREQ); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, MAX31855_SPI_MAXFREQ); #endif /* Register the character driver */ diff --git a/drivers/sensors/max6675.c b/drivers/sensors/max6675.c index a39544ecea..7c2404d176 100644 --- a/drivers/sensors/max6675.c +++ b/drivers/sensors/max6675.c @@ -261,7 +261,8 @@ int max6675_register(FAR const char *devpath, FAR struct spi_dev_s *spi) SPI_SETMODE(priv->spi, SPIDEV_MODE1); SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, MAX6675_SPI_MAXFREQ); + (void)SPI_HWFEATURES(priv->spi, 0); + (void)SPI_SETFREQUENCY(priv->spi, MAX6675_SPI_MAXFREQ); #endif /* Register the character driver */ diff --git a/drivers/sensors/mpl115a.c b/drivers/sensors/mpl115a.c index 86a92dfe25..ba43af3aa8 100644 --- a/drivers/sensors/mpl115a.c +++ b/drivers/sensors/mpl115a.c @@ -119,7 +119,8 @@ static inline void mpl115a_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, MPL115A_SPI_MAXFREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, MPL115A_SPI_MAXFREQUENCY); } #endif diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index bd86776bbd..8d8958fc72 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -313,6 +313,7 @@ void cc1101_access_begin(FAR struct cc1101_dev_s * dev) SPI_SELECT(dev->spi, SPIDEV_WIRELESS, true); SPI_SETMODE(dev->spi, SPIDEV_MODE0); /* CPOL=0, CPHA=0 */ SPI_SETBITS(dev->spi, 8); + (void)SPI_HWFEATURES(dev->spi, 0); } void cc1101_access_end(FAR struct cc1101_dev_s * dev) diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index 0434cdbacd..9e7e9d2c0c 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -259,7 +259,8 @@ static inline void cc3000_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, CONFIG_CC3000_SPI_MODE); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, CONFIG_CC3000_SPI_FREQUENCY); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_CC3000_SPI_FREQUENCY); } /**************************************************************************** diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index 607a56a1aa..430c0b5b7a 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -267,7 +267,8 @@ static void nrf24l01_lock(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_WIRELESS, true); SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); SPI_SELECT(spi, SPIDEV_WIRELESS, false); } #endif @@ -328,7 +329,8 @@ static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_WIRELESS, true); /* Useful ? */ SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, 8); - SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); SPI_SELECT(spi, SPIDEV_WIRELESS, false); } #endif diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c index d429948957..1596db3a6e 100644 --- a/drivers/wireless/pn532.c +++ b/drivers/wireless/pn532.c @@ -150,7 +150,8 @@ static void pn532_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, -8); - SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); } #endif @@ -170,7 +171,8 @@ static inline void pn532_configspi(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, -8); - SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); } #endif -- GitLab From 7edf921c5e133684a5da81d99d90f1026a246464 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 18:54:36 -0600 Subject: [PATCH 606/858] Remove CONFIG_SPI_OWNBUS: Now it is not just a good idea, it is the law --- arch | 2 +- configs | 2 +- drivers/analog/pga11x.c | 20 +-------- drivers/input/ads7843e.c | 55 +---------------------- drivers/input/max11802.c | 55 ++--------------------- drivers/lcd/memlcd.c | 75 +++----------------------------- drivers/lcd/nokia6100.c | 63 +-------------------------- drivers/lcd/p14201.c | 25 ----------- drivers/lcd/ssd1306.h | 3 -- drivers/lcd/ssd1306_base.c | 14 ------ drivers/lcd/ssd1306_spi.c | 6 --- drivers/lcd/ssd1351.c | 15 ------- drivers/lcd/st7567.c | 23 ---------- drivers/lcd/ug-2864ambag01.c | 48 -------------------- drivers/lcd/ug-9664hswag01.c | 23 ---------- drivers/mmcsd/mmcsd_spi.c | 41 +---------------- drivers/mtd/at25.c | 29 ------------ drivers/mtd/m25px.c | 29 ------------ drivers/mtd/sst25.c | 29 ------------ drivers/mtd/sst25xx.c | 32 +------------- drivers/mtd/w25.c | 29 ------------ drivers/net/enc28j60.c | 16 +------ drivers/net/encx24j600.c | 16 +------ drivers/sensors/adxl345_base.c | 14 ------ drivers/sensors/adxl345_spi.c | 15 +------ drivers/sensors/max31855.c | 9 ---- drivers/sensors/max6675.c | 9 ---- drivers/sensors/mpl115a.c | 6 --- drivers/spi/Kconfig | 8 ---- drivers/spi/spi_bitbang.c | 6 --- drivers/wireless/cc3000/cc3000.c | 13 +----- drivers/wireless/nrf24l01.c | 28 ++---------- drivers/wireless/pn532.c | 12 ----- include/nuttx/analog/pga11x.h | 2 - include/nuttx/spi/spi.h | 14 ++---- include/nuttx/spi/spi_bitbang.h | 2 - 36 files changed, 32 insertions(+), 756 deletions(-) diff --git a/arch b/arch index 244343293f..32ca4e6150 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 244343293fcfa82e03e002fa792a4e09d238b9f2 +Subproject commit 32ca4e6150e8369dfa9f84f62863774cea6dc736 diff --git a/configs b/configs index 66325b8ab4..dd88ee499c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 66325b8ab4f012c1261e88ae262d5cd2e3d54fd1 +Subproject commit dd88ee499c9fc77884091a48cad9d6fc3ba451a9 diff --git a/drivers/analog/pga11x.c b/drivers/analog/pga11x.c index 143b897bc9..915cfca055 100644 --- a/drivers/analog/pga11x.c +++ b/drivers/analog/pga11x.c @@ -170,7 +170,6 @@ static void pga11x_configure(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void pga11x_lock(FAR struct spi_dev_s *spi) { spivdbg("Locking\n"); @@ -193,9 +192,6 @@ static void pga11x_lock(FAR struct spi_dev_s *spi) pga11x_configure(spi); } -#else -# define pga11x_lock(spi) -#endif /**************************************************************************** * Name: pga11x_unlock @@ -208,16 +204,12 @@ static void pga11x_lock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void pga11x_unlock(FAR struct spi_dev_s *spi) { spivdbg("Unlocking\n"); SPI_LOCK(spi, false); } -#else -# define pga11x_unlock(spi) -#endif /**************************************************************************** * Name: pga11x_send16 @@ -361,16 +353,8 @@ PGA11X_HANDLE pga11x_initialize(FAR struct spi_dev_s *spi) { spivdbg("Entry\n"); - /* Configure the SPI us for the device. Do this now only if the PGA11X is - * the only device on the bus. - */ - -#ifdef CONFIG_SPI_OWNBUS - pga11x_configure(spi); -#endif - - /* No other special state is required, just return the SPI driver instance - * as the handle. This gives us a place to extend functionality in the + /* No Special state is required, just return the SPI driver instance as + * the handle. This gives us a place to extend functionality in the * future if neccessary. */ diff --git a/drivers/input/ads7843e.c b/drivers/input/ads7843e.c index d09afce312..1648b7fddf 100644 --- a/drivers/input/ads7843e.c +++ b/drivers/input/ads7843e.c @@ -94,15 +94,8 @@ ****************************************************************************/ /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS -static inline void ads7843e_configspi(FAR struct spi_dev_s *spi); -# define ads7843e_lock(spi) -# define ads7843e_unlock(spi) -#else -# define ads7843e_configspi(spi); static void ads7843e_lock(FAR struct spi_dev_s *spi); static void ads7843e_unlock(FAR struct spi_dev_s *spi); -#endif static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv, uint8_t cmd); @@ -180,7 +173,6 @@ static struct ads7843e_dev_s *g_ads7843elist; * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void ads7843e_lock(FAR struct spi_dev_s *spi) { /* Lock the SPI bus because there are multiple devices competing for the @@ -201,15 +193,13 @@ static void ads7843e_lock(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); } -#endif /**************************************************************************** * Function: ads7843e_unlock * * Description: - * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS - * undefined) then we need to un-lock the SPI bus for each transfer, - * possibly losing the current configuration. + * Un-lock the SPI bus after each transfer, possibly losing the current + * configuration if we are sharing the bus with other devices. * * Parameters: * spi - Reference to the SPI driver structure @@ -221,49 +211,12 @@ static void ads7843e_lock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void ads7843e_unlock(FAR struct spi_dev_s *spi) { /* Relinquish the SPI bus. */ (void)SPI_LOCK(spi, false); } -#endif - -/**************************************************************************** - * Function: ads7843e_configspi - * - * Description: - * Configure the SPI for use with the ADS7843E. This function should be - * called once during touchscreen initialization to configure the SPI - * bus. Note that if CONFIG_SPI_OWNBUS is not defined, then this function - * does nothing. - * - * Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_SPI_OWNBUS -static inline void ads7843e_configspi(FAR struct spi_dev_s *spi) -{ - /* Configure SPI for the ADS7843. But only if we own the SPI bus. - * Otherwise, don't bother because it might change. - */ - - SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true); - SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY); - SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); -} -#endif /**************************************************************************** * Name: ads7843e_sendcmd @@ -1254,10 +1207,6 @@ int ads7843e_register(FAR struct spi_dev_s *spi, ads7843e_lock(spi); - /* Configure the SPI interface */ - - ads7843e_configspi(spi); - /* Enable the PEN IRQ */ ads7843e_sendcmd(priv, ADS7843_CMD_ENABPENIRQ); diff --git a/drivers/input/max11802.c b/drivers/input/max11802.c index 85a5b77347..25698427b9 100644 --- a/drivers/input/max11802.c +++ b/drivers/input/max11802.c @@ -88,16 +88,8 @@ ****************************************************************************/ /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS -static inline void max11802_configspi(FAR struct spi_dev_s *spi); -# define max11802_lock(spi) -# define max11802_unlock(spi) -#else -# define max11802_configspi(spi); static void max11802_lock(FAR struct spi_dev_s *spi); static void max11802_unlock(FAR struct spi_dev_s *spi); -#endif - static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, uint8_t cmd, int *tags); @@ -181,7 +173,6 @@ static struct max11802_dev_s *g_max11802list; * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void max11802_lock(FAR struct spi_dev_s *spi) { /* Lock the SPI bus because there are multiple devices competing for the @@ -200,15 +191,13 @@ static void max11802_lock(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); } -#endif /**************************************************************************** * Function: max11802_unlock * * Description: - * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS - * undefined) then we need to un-lock the SPI bus for each transfer, - * possibly losing the current configuration. + * Un-lock the SPI bus after each transfer, possibly losing the current + * configuration if we are sharing the SPI bus with other devices * * Parameters: * spi - Reference to the SPI driver structure @@ -220,47 +209,12 @@ static void max11802_lock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void max11802_unlock(FAR struct spi_dev_s *spi) { /* Relinquish the SPI bus. */ (void)SPI_LOCK(spi, false); } -#endif - -/**************************************************************************** - * Function: max11802_configspi - * - * Description: - * Configure the SPI for use with the MAX11802. This function should be - * called once during touchscreen initialization to configure the SPI - * bus. Note that if CONFIG_SPI_OWNBUS is not defined, then this function - * does nothing. - * - * Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_SPI_OWNBUS -static inline void max11802_configspi(FAR struct spi_dev_s *spi) -{ - /* Configure SPI for the MAX11802. But only if we own the SPI bus. - * Otherwise, don't bother because it might change. - */ - - SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); -} -#endif /**************************************************************************** * Name: max11802_sendcmd @@ -1256,11 +1210,8 @@ int max11802_register(FAR struct spi_dev_s *spi, max11802_lock(spi); - /* Configure the SPI interface */ - - max11802_configspi(spi); - /* Configure MAX11802 registers */ + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); (void)SPI_SEND(priv->spi, MAX11802_CMD_MODE_WR); (void)SPI_SEND(priv->spi, MAX11802_MODE); diff --git a/drivers/lcd/memlcd.c b/drivers/lcd/memlcd.c index c4a8a6e10f..e960e27612 100644 --- a/drivers/lcd/memlcd.c +++ b/drivers/lcd/memlcd.c @@ -150,14 +150,8 @@ struct memlcd_dev_s /* Low-level spi helpers */ -static inline void memlcd_configspi(FAR struct spi_dev_s *spi); -#ifdef CONFIG_SPI_OWNBUS -static inline void memlcd_select(FAR struct spi_dev_s *spi); -static inline void memlcd_deselect(FAR struct spi_dev_s *spi); -#else static void memlcd_select(FAR struct spi_dev_s *spi); static void memlcd_deselect(FAR struct spi_dev_s *spi); -#endif /* lcd data transfer methods */ @@ -266,48 +260,6 @@ static inline int __test_bit(int nr, const volatile uint8_t * addr) return 1 & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE - 1))); } -/**************************************************************************** - * Name: memlcd_configspi - * - * Description: - * Configure the SPI for use with the Sharp Memory LCD - * - * Input Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static inline void memlcd_configspi(FAR struct spi_dev_s *spi) -{ -#ifdef CONFIG_MEMLCD_SPI_FREQUENCY - lcddbg("Mode: %d Bits: %d Frequency: %d\n", - MEMLCD_SPI_MODE, MEMLCD_SPI_BITS, CONFIG_MEMLCD_SPI_FREQUENCY); -#else - lcddbg("Mode: %d Bits: %d Frequency: %d\n", - MEMLCD_SPI_MODE, MEMLCD_SPI_BITS, MEMLCD_SPI_FREQUENCY); -#endif - - /* Configure SPI for the Memory LCD. But only if we own the SPI bus. - * Otherwise, don't bother because it might change. - */ - -#ifdef CONFIG_SPI_OWNBUS - SPI_SETMODE(spi, MEMLCD_SPI_MODE); - SPI_SETBITS(spi, MEMLCD_SPI_BITS); - (void)SPI_HWFEATURES(spi, 0); -# ifdef CONFIG_MEMLCD_SPI_FREQUENCY - (void)SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY); -# else - (void)SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); -# endif -#endif -} - /**************************************************************************** * Name: memlcd_select * @@ -324,25 +276,19 @@ static inline void memlcd_configspi(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void memlcd_select(FAR struct spi_dev_s *spi) -{ - /* we own the spi bus, so just select the chip */ - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} - -#else static void memlcd_select(FAR struct spi_dev_s *spi) { /* Select memlcd (locking the SPI bus in case there are multiple * devices competing for the SPI bus */ + SPI_LOCK(spi, true); SPI_SELECT(spi, SPIDEV_DISPLAY, true); /* Now make sure that the SPI bus is configured for the memlcd (it * might have gotten configured for a different device while unlocked) */ + SPI_SETMODE(spi, MEMLCD_SPI_MODE); SPI_SETBITS(spi, MEMLCD_SPI_BITS); (void)SPI_HWFEATURES(spi, 0); @@ -352,7 +298,6 @@ static void memlcd_select(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY); # endif } -#endif /**************************************************************************** * Name: memlcd_deselect @@ -370,20 +315,13 @@ static void memlcd_select(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void memlcd_deselect(FAR struct spi_dev_s *spi) -{ - /* we own the spi bus, so just de-select the chip */ - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else static void memlcd_deselect(FAR struct spi_dev_s *spi) { - /* de-select memlcd and relinquish the spi bus. */ + /* De-select memlcd and relinquish the spi bus. */ + SPI_SELECT(spi, SPIDEV_DISPLAY, false); SPI_LOCK(spi, false); } -#endif /**************************************************************************** * Name: memlcd_clear @@ -765,11 +703,10 @@ FAR struct lcd_dev_s *memlcd_initialize(FAR struct spi_dev_s *spi, DEBUGASSERT(spi && priv && devno == 0); - /* register board specific functions */ - mlcd->priv = priv; + /* Register board specific functions */ + mlcd->priv = priv; mlcd->spi = spi; - memlcd_configspi(spi); mlcd->priv->attachirq(memlcd_extcominisr); diff --git a/drivers/lcd/nokia6100.c b/drivers/lcd/nokia6100.c index d6f71590e9..d3a765a812 100644 --- a/drivers/lcd/nokia6100.c +++ b/drivers/lcd/nokia6100.c @@ -338,14 +338,8 @@ struct nokia_dev_s /* SPI support */ -static inline void nokia_configspi(FAR struct spi_dev_s *spi); -#ifdef CONFIG_SPI_OWNBUS -static inline void nokia_select(FAR struct spi_dev_s *spi); -static inline void nokia_deselect(FAR struct spi_dev_s *spi); -#else static void nokia_select(FAR struct spi_dev_s *spi); static void nokia_deselect(FAR struct spi_dev_s *spi); -#endif static void nokia_sndcmd(FAR struct spi_dev_s *spi, const uint8_t cmd); static void nokia_cmdarray(FAR struct spi_dev_s *spi, int len, const uint8_t *cmddata); static void nokia_clrram(FAR struct spi_dev_s *spi); @@ -650,39 +644,6 @@ static const uint8_t g_setcon[] = * Private Functions **************************************************************************************/ -/************************************************************************************** - * Function: nokia_configspi - * - * Description: - * Configure the SPI for use with the Nokia 6100 - * - * Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - **************************************************************************************/ - -static inline void nokia_configspi(FAR struct spi_dev_s *spi) -{ - lcddbg("Mode: %d Bits: %d Frequency: %d\n", - CONFIG_NOKIA6100_SPIMODE, CONFIG_NOKIA6100_WORDWIDTH, CONFIG_NOKIA6100_FREQUENCY); - - /* Configure SPI for the Nokia 6100. But only if we own the SPI bus. Otherwise, don't - * bother because it might change. - */ - -#ifdef CONFIG_SPI_OWNBUS - SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); - SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY) -#endif -} - /************************************************************************************** * Function: nokia_select * @@ -699,15 +660,6 @@ static inline void nokia_configspi(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void nokia_select(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just select the chip */ - - lcddbg("SELECTED\n"); - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} -#else static void nokia_select(FAR struct spi_dev_s *spi) { /* Select Nokia 6100 chip (locking the SPI bus in case there are multiple @@ -727,7 +679,6 @@ static void nokia_select(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY); } -#endif /************************************************************************************** * Function: nokia_deselect @@ -745,15 +696,6 @@ static void nokia_select(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void nokia_deselect(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just de-select the chip */ - - lcddbg("DE-SELECTED\n"); - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else static void nokia_deselect(FAR struct spi_dev_s *spi) { /* De-select Nokia 6100 chip and relinquish the SPI bus. */ @@ -762,7 +704,6 @@ static void nokia_deselect(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_DISPLAY, false); SPI_LOCK(spi, false); } -#endif /************************************************************************************** * Name: nokia_sndcmd @@ -1218,9 +1159,8 @@ FAR struct lcd_dev_s *nokia_lcdinitialize(FAR struct spi_dev_s *spi, unsigned in priv->spi = spi; /* Save the SPI instance */ priv->contrast = NOKIA_DEFAULT_CONTRAST; /* Initial contrast setting */ - /* Configure and enable the LCD controller */ + /* Enable the LCD controller */ - nokia_configspi(spi); if (nokia_initialize(priv) == OK) { /* Turn on the backlight */ @@ -1228,5 +1168,6 @@ FAR struct lcd_dev_s *nokia_lcdinitialize(FAR struct spi_dev_s *spi, unsigned in nokia_backlight(CONFIG_NOKIA6100_BLINIT); return &priv->dev; } + return NULL; } diff --git a/drivers/lcd/p14201.c b/drivers/lcd/p14201.c index b79e036aed..a1df779364 100644 --- a/drivers/lcd/p14201.c +++ b/drivers/lcd/p14201.c @@ -206,13 +206,8 @@ struct rit_dev_s /* Low-level SPI helpers */ static inline void rit_configspi(FAR struct spi_dev_s *spi); -#ifdef CONFIG_SPI_OWNBUS -static inline void rit_select(FAR struct spi_dev_s *spi); -static inline void rit_deselect(FAR struct spi_dev_s *spi); -#else static void rit_select(FAR struct spi_dev_s *spi); static void rit_deselect(FAR struct spi_dev_s *spi); -#endif static void rit_sndbytes(FAR struct rit_dev_s *priv, FAR const uint8_t *buffer, size_t buflen, bool cmd); static void rit_sndcmds(FAR struct rit_dev_s *priv, FAR const uint8_t *table); @@ -457,14 +452,12 @@ static inline void rit_configspi(FAR struct spi_dev_s *spi) * bother because it might change. */ -#ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_P14201_SPIMODE); SPI_SETBITS(spi, 8); (void)SPI_HWFEATURES(spi, 0); #ifdef CONFIG_P14201_FREQUENCY (void)SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY) #endif -#endif } /************************************************************************************** @@ -483,14 +476,6 @@ static inline void rit_configspi(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void rit_select(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} -#else static void rit_select(FAR struct spi_dev_s *spi) { /* Select P14201 chip (locking the SPI bus in case there are multiple @@ -511,7 +496,6 @@ static void rit_select(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY); #endif } -#endif /************************************************************************************** * Name: rit_deselect @@ -529,14 +513,6 @@ static void rit_select(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void rit_deselect(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just de-select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else static void rit_deselect(FAR struct spi_dev_s *spi) { /* De-select P14201 chip and relinquish the SPI bus. */ @@ -544,7 +520,6 @@ static void rit_deselect(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_DISPLAY, false); SPI_LOCK(spi, false); } -#endif /************************************************************************************** * Name: rit_sndbytes diff --git a/drivers/lcd/ssd1306.h b/drivers/lcd/ssd1306.h index 8dbb4f1a83..b75672936e 100644 --- a/drivers/lcd/ssd1306.h +++ b/drivers/lcd/ssd1306.h @@ -258,10 +258,7 @@ void ssd1306_sendblk(FAR struct ssd1306_dev_s *priv, uint8_t *data, uint8_t len) #ifdef CONFIG_LCD_SSD1306_SPI void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs); void ssd1306_cmddata(FAR struct ssd1306_dev_s *priv, bool cmd); - -#ifndef CONFIG_SPI_OWNBUS static inline void ssd1306_configspi(FAR struct spi_dev_s *spi) -#endif #else # define ssd1306_select(priv, cs) diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index 13d0a7195d..2ac7bbeca1 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -818,23 +818,9 @@ FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_dev_s *dev, unsigned int #ifdef CONFIG_LCD_SSD1306_SPI priv->spi = dev; - /* If this SPI bus is not shared, then we can config it now. - * If it is shared, then other device could change our config, - * then just configure before sending data. - */ - -# ifdef CONFIG_SPI_OWNBUS - /* Configure SPI */ - - SPI_SETMODE(priv->spi, CONFIG_SSD1306_SPIMODE); - SPI_SETBITS(priv->spi, 8); - (void)SPI_HWFEATURES(priv->spi, 0); - (void)SPI_SETFREQUENCY(priv->spi, CONFIG_SSD1306_FREQUENCY); -# else /* Configure the SPI */ ssd1306_configspi(priv->spi); -# endif #else /* Remember the I2C configuration */ diff --git a/drivers/lcd/ssd1306_spi.c b/drivers/lcd/ssd1306_spi.c index fedc3eae9d..b17466c40e 100644 --- a/drivers/lcd/ssd1306_spi.c +++ b/drivers/lcd/ssd1306_spi.c @@ -61,7 +61,6 @@ * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void ssd1306_configspi(FAR struct spi_dev_s *spi) { lcdvdbg("Mode: %d Bits: 8 Frequency: %d\n", @@ -74,7 +73,6 @@ static inline void ssd1306_configspi(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1306_FREQUENCY); } -#endif /**************************************************************************** * Public Functions @@ -124,7 +122,6 @@ void ssd1306_sendblk(FAR struct ssd1306_dev_s *priv, uint8_t *data, uint8_t len) void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs) { -#ifndef CONFIG_SPI_OWNBUS /* If we are selecting the device */ if (cs == true) @@ -134,13 +131,11 @@ void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs) (void)SPI_LOCK(priv->spi, true); ssd1306_configspi(priv->spi); } -#endif /* Select/deselect SPI device */ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, cs); -#ifndef CONFIG_SPI_OWNBUS /* If we are deselecting the device */ if (cs == false) @@ -149,7 +144,6 @@ void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs) (void)SPI_LOCK(priv->spi, false); } -#endif } /**************************************************************************** diff --git a/drivers/lcd/ssd1351.c b/drivers/lcd/ssd1351.c index 30178930a2..c56cc2b682 100644 --- a/drivers/lcd/ssd1351.c +++ b/drivers/lcd/ssd1351.c @@ -507,12 +507,10 @@ static void ssd1351_select(FAR struct ssd1351_dev_s *priv) * have gotten configured for a different device while unlocked) */ -#ifndef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); SPI_SETBITS(spi, SSD1351_SPIBITS); (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); -#endif } #endif @@ -1189,19 +1187,6 @@ FAR struct lcd_dev_s *ssd1351_initialize(FAR struct spi_dev_s *spi, #endif priv->power = LCD_FULL_OFF; - /* Configure the SPI bus if we own it. Otherwise, don't bother because - * it might change. - */ - -#if defined(CONFIG_SSD1351_SPI3WIRE) || defined(CONFIG_SSD1351_SPI4WIRE) -#ifdef CONFIG_SPI_OWNBUS - SPI_SETMODE(spi, CONFIG_SSD1351_SPIMODE); - SPI_SETBITS(spi, SSD1351_SPIBITS); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_SSD1351_SPIFREQ); -#endif -#endif - /* Configure the device */ ssd1351_hwinitialize(priv); diff --git a/drivers/lcd/st7567.c b/drivers/lcd/st7567.c index 1a597f22e4..77ba1bbc1d 100644 --- a/drivers/lcd/st7567.c +++ b/drivers/lcd/st7567.c @@ -246,13 +246,8 @@ struct st7567_dev_s /* SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS -static inline void st7567_select(FAR struct spi_dev_s *spi); -static inline void st7567_deselect(FAR struct spi_dev_s *spi); -#else static void st7567_select(FAR struct spi_dev_s *spi); static void st7567_deselect(FAR struct spi_dev_s *spi); -#endif /* LCD Data Transfer Methods */ @@ -371,14 +366,6 @@ static struct st7567_dev_s g_st7567dev = * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void st7567_select(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} -#else static void st7567_select(FAR struct spi_dev_s *spi) { /* Select ST7567 chip (locking the SPI bus in case there are multiple @@ -399,7 +386,6 @@ static void st7567_select(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, CONFIG_ST7567_FREQUENCY); #endif } -#endif /************************************************************************************** * Function: st7567_deselect @@ -417,14 +403,6 @@ static void st7567_select(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void st7567_deselect(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just de-select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else static void st7567_deselect(FAR struct spi_dev_s *spi) { /* De-select ST7567 chip and relinquish the SPI bus. */ @@ -432,7 +410,6 @@ static void st7567_deselect(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_DISPLAY, false); SPI_LOCK(spi, false); } -#endif /************************************************************************************** * Name: st7567_putrun diff --git a/drivers/lcd/ug-2864ambag01.c b/drivers/lcd/ug-2864ambag01.c index 1d1b773316..ab53fbc024 100644 --- a/drivers/lcd/ug-2864ambag01.c +++ b/drivers/lcd/ug-2864ambag01.c @@ -301,15 +301,8 @@ struct ug2864ambag01_dev_s /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS -static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi); -# define ug2864ambag01_lock(spi) -# define ug2864ambag01_unlock(spi) -#else -# define ug2864ambag01_configspi(spi) static void ug2864ambag01_lock(FAR struct spi_dev_s *spi); static void ug2864ambag01_unlock(FAR struct spi_dev_s *spi); -#endif /* LCD Data Transfer Methods */ @@ -408,39 +401,6 @@ static struct ug2864ambag01_dev_s g_oleddev = * Private Functions **************************************************************************************/ -/************************************************************************************** - * Name: ug2864ambag01_configspi - * - * Description: - * Configure the SPI for use with the UG-2864AMBAG01 - * - * Input Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - **************************************************************************************/ - -#ifdef CONFIG_SPI_OWNBUS -static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi) -{ - lcdvdbg("Mode: %d Bits: 8 Frequency: %d\n", - CONFIG_UG2864AMBAG01_SPIMODE, CONFIG_UG2864AMBAG01_FREQUENCY); - - /* Configure SPI for the UG-2864AMBAG01. But only if we own the SPI bus. Otherwise, - * don't bother because it might change. - */ - - SPI_SETMODE(spi, CONFIG_UG2864AMBAG01_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); -} -#endif - /************************************************************************************** * Name: ug2864ambag01_lock * @@ -457,7 +417,6 @@ static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void ug2864ambag01_lock(FAR struct spi_dev_s *spi) { /* Lock the SPI bus if there are multiple devices competing for the SPI bus. */ @@ -473,7 +432,6 @@ static inline void ug2864ambag01_lock(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY); } -#endif /************************************************************************************** * Name: ug2864ambag01_unlock @@ -491,14 +449,12 @@ static inline void ug2864ambag01_lock(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void ug2864ambag01_unlock(FAR struct spi_dev_s *spi) { /* De-select UG-2864AMBAG01 chip and relinquish the SPI bus. */ SPI_LOCK(spi, false); } -#endif /************************************************************************************** * Name: ug2864ambag01_putrun @@ -1080,10 +1036,6 @@ FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi, unsign priv->spi = spi; - /* Configure the SPI */ - - ug2864ambag01_configspi(spi); - /* Lock and select device */ ug2864ambag01_lock(priv->spi); diff --git a/drivers/lcd/ug-9664hswag01.c b/drivers/lcd/ug-9664hswag01.c index be97d551b0..e9053a7218 100644 --- a/drivers/lcd/ug-9664hswag01.c +++ b/drivers/lcd/ug-9664hswag01.c @@ -261,13 +261,8 @@ struct ug_dev_s /* SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS -static inline void ug_select(FAR struct spi_dev_s *spi); -static inline void ug_deselect(FAR struct spi_dev_s *spi); -#else static void ug_select(FAR struct spi_dev_s *spi); static void ug_deselect(FAR struct spi_dev_s *spi); -#endif /* LCD Data Transfer Methods */ @@ -415,14 +410,6 @@ static inline FAR const char *ug_powerstring(uint8_t power) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void ug_select(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, true); -} -#else static void ug_select(FAR struct spi_dev_s *spi) { /* Select UG-9664HSWAG01 chip (locking the SPI bus in case there are multiple @@ -443,7 +430,6 @@ static void ug_select(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, CONFIG_UG9664HSWAG01_FREQUENCY); #endif } -#endif /************************************************************************************** * Function: ug_deselect @@ -461,14 +447,6 @@ static void ug_select(FAR struct spi_dev_s *spi) * **************************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void ug_deselect(FAR struct spi_dev_s *spi) -{ - /* We own the SPI bus, so just de-select the chip */ - - SPI_SELECT(spi, SPIDEV_DISPLAY, false); -} -#else static void ug_deselect(FAR struct spi_dev_s *spi) { /* De-select UG-9664HSWAG01 chip and relinquish the SPI bus. */ @@ -476,7 +454,6 @@ static void ug_deselect(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_DISPLAY, false); SPI_LOCK(spi, false); } -#endif /************************************************************************************** * Name: ug_putrun diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index e4cfc4ecda..b9101fe1b1 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -158,9 +158,7 @@ struct mmcsd_slot_s uint32_t twrite; /* Card write time */ uint32_t ocr; /* Last 4 bytes of OCR (R3) */ uint32_t r7; /* Last 4 bytes of R7 */ -#ifndef CONFIG_SPI_OWNBUS uint32_t spispeed; /* Speed to use for SPI in data mode */ -#endif }; struct mmcsd_cmdinfo_s @@ -181,12 +179,6 @@ static void mmcsd_semgive(FAR struct mmcsd_slot_s *slot); /* Card SPI interface *******************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void mmcsd_spiinit(FAR struct mmcsd_slot_s *slot); -#else -# define mmcsd_spiinit(slot) -#endif - static int mmcsd_waitready(FAR struct mmcsd_slot_s *slot); static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, const struct mmcsd_cmdinfo_s *cmd, uint32_t arg); @@ -358,7 +350,6 @@ static void mmcsd_semtake(FAR struct mmcsd_slot_s *slot) { /* Get exclusive access to the SPI bus (if necessary) */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(slot->spi, true); /* Set the frequency, bit width and mode, as some other driver could have @@ -369,7 +360,6 @@ static void mmcsd_semtake(FAR struct mmcsd_slot_s *slot) SPI_SETBITS(slot->spi, 8); (void)SPI_HWFEATURES(slot->spi, 0); (void)SPI_SETFREQUENCY(slot->spi, slot->spispeed); -#endif /* Get exclusive access to the MMC/SD device (possibly unnecessary if * SPI_LOCK is also implemented as a semaphore). @@ -397,7 +387,6 @@ static void mmcsd_semgive(FAR struct mmcsd_slot_s *slot) /* Relinquish the lock on the SPI bus */ -#ifndef CONFIG_SPI_OWNBUS /* The card may need up to 8 SCLK cycles to sample the CS status * and release the MISO line. */ @@ -407,29 +396,8 @@ static void mmcsd_semgive(FAR struct mmcsd_slot_s *slot) /* Relinquish exclusive access to the SPI bus */ (void)SPI_LOCK(slot->spi, false); -#endif } -/**************************************************************************** - * Name: mmcsd_spiinit - * - * Description: - * Set SPI mode and data width. - * - * Assumptions: - * MMC/SD card already selected - * - ****************************************************************************/ - -#ifdef CONFIG_SPI_OWNBUS -static inline void mmcsd_spiinit(FAR struct mmcsd_slot_s *slot) -{ - SPI_SETMODE(slot->spi, CONFIG_MMCSD_SPIMODE); - SPI_SETBITS(slot->spi, 8); - (void)SPI_HWFEATURES(slot->spi, 0); -} -#endif - /**************************************************************************** * Name: mmcsd_waitready * @@ -738,9 +706,7 @@ static void mmcsd_decodecsd(FAR struct mmcsd_slot_s *slot, uint8_t *csd) /* Set the actual SPI frequency as close as possible to the max frequency */ -#ifndef CONFIG_SPI_OWNBUS slot->spispeed = frequency; -#endif frequency = SPI_SETFREQUENCY(spi, frequency); /* Now determine the delay to access data */ @@ -1607,9 +1573,7 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) /* Clock Freq. Identification Mode < 400kHz */ -#ifndef CONFIG_SPI_OWNBUS slot->spispeed = MMCSD_IDMODE_CLOCK; -#endif (void)SPI_SETFREQUENCY(spi, MMCSD_IDMODE_CLOCK); /* Set the maximum access time out */ @@ -1974,17 +1938,14 @@ int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi) /* Bind the SPI port to the slot */ - slot->spi = spi; -#ifndef CONFIG_SPI_OWNBUS + slot->spi = spi; slot->spispeed = MMCSD_IDMODE_CLOCK; -#endif /* Get exclusive access to the SPI bus and make sure that SPI is properly * configured for the MMC/SD card */ mmcsd_semtake(slot); - mmcsd_spiinit(slot); /* Initialize for the media in the slot (if any) */ diff --git a/drivers/mtd/at25.c b/drivers/mtd/at25.c index 8ab7c1728c..e085ca8b89 100644 --- a/drivers/mtd/at25.c +++ b/drivers/mtd/at25.c @@ -256,34 +256,6 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv) { uint8_t status; - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, true); - - /* Send "Read Status Register (RDSR)" command */ - - (void)SPI_SEND(priv->dev, AT25_RDSR); - - /* Loop as long as the memory is busy with a write cycle */ - - do - { - /* Send a dummy byte to generate the clock needed to shift out the status */ - - status = SPI_SEND(priv->dev, AT25_DUMMY); - } - while ((status & AT25_SR_BUSY) != 0); - - /* Deselect the FLASH */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, false); - -#else - /* Loop as long as the memory is busy with a write cycle */ do @@ -317,7 +289,6 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv) } } while ((status & AT25_SR_BUSY) != 0); -#endif if (status & AT25_SR_EPE) { diff --git a/drivers/mtd/m25px.c b/drivers/mtd/m25px.c index f1b71dfc11..3a9bda2c9d 100644 --- a/drivers/mtd/m25px.c +++ b/drivers/mtd/m25px.c @@ -418,34 +418,6 @@ static void m25p_waitwritecomplete(struct m25p_dev_s *priv) { uint8_t status; - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, true); - - /* Send "Read Status Register (RDSR)" command */ - - (void)SPI_SEND(priv->dev, M25P_RDSR); - - /* Loop as long as the memory is busy with a write cycle */ - - do - { - /* Send a dummy byte to generate the clock needed to shift out the status */ - - status = SPI_SEND(priv->dev, M25P_DUMMY); - } - while ((status & M25P_SR_WIP) != 0); - - /* Deselect the FLASH */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, false); - -#else - /* Loop as long as the memory is busy with a write cycle */ do @@ -479,7 +451,6 @@ static void m25p_waitwritecomplete(struct m25p_dev_s *priv) } } while ((status & M25P_SR_WIP) != 0); -#endif fvdbg("Complete\n"); } diff --git a/drivers/mtd/sst25.c b/drivers/mtd/sst25.c index 2a9b3e50f0..61a79a63b5 100644 --- a/drivers/mtd/sst25.c +++ b/drivers/mtd/sst25.c @@ -396,34 +396,6 @@ static uint8_t sst25_waitwritecomplete(struct sst25_dev_s *priv) { uint8_t status; - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, true); - - /* Send "Read Status Register (RDSR)" command */ - - (void)SPI_SEND(priv->dev, SST25_RDSR); - - /* Loop as long as the memory is busy with a write cycle */ - - do - { - /* Send a dummy byte to generate the clock needed to shift out the status */ - - status = SPI_SEND(priv->dev, SST25_DUMMY); - } - while ((status & SST25_SR_BUSY) != 0); - - /* Deselect the FLASH */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, false); - -#else - /* Loop as long as the memory is busy with a write cycle */ do @@ -459,7 +431,6 @@ static uint8_t sst25_waitwritecomplete(struct sst25_dev_s *priv) #endif } while ((status & SST25_SR_BUSY) != 0); -#endif return status; } diff --git a/drivers/mtd/sst25xx.c b/drivers/mtd/sst25xx.c index 3a1c086c25..ebbcfd33f2 100644 --- a/drivers/mtd/sst25xx.c +++ b/drivers/mtd/sst25xx.c @@ -315,36 +315,10 @@ static void sst25xx_waitwritecomplete(struct sst25xx_dev_s *priv) #if 0 if (!priv->lastwaswrite) - return; -#endif - - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, true); - - /* Send "Read Status Register (RDSR)" command */ - - (void)SPI_SEND(priv->dev, SST25_RDSR); - - /* Loop as long as the memory is busy with a write cycle */ - - do { - /* Send a dummy byte to generate the clock needed to shift out the status */ - - status = SPI_SEND(priv->dev, SST25_DUMMY); + return; } - while ((status & SST25_SR_WIP) != 0); - - /* Deselect the FLASH */ - - SPI_SELECT(priv->dev, SPIDEV_FLASH, false); - -#else +#endif /* Loop as long as the memory is busy with a write cycle */ @@ -380,8 +354,6 @@ static void sst25xx_waitwritecomplete(struct sst25xx_dev_s *priv) } while ((status & SST25_SR_WIP) != 0); -#endif - priv->lastwaswrite = false; fvdbg("Complete\n"); diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index 1ea22d5bc3..09a7c015d2 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -472,34 +472,6 @@ static uint8_t w25_waitwritecomplete(struct w25_dev_s *priv) { uint8_t status; - /* Are we the only device on the bus? */ - -#ifdef CONFIG_SPI_OWNBUS - - /* Select this FLASH part */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, true); - - /* Send "Read Status Register (RDSR)" command */ - - (void)SPI_SEND(priv->spi, W25_RDSR); - - /* Loop as long as the memory is busy with a write cycle */ - - do - { - /* Send a dummy byte to generate the clock needed to shift out the status */ - - status = SPI_SEND(priv->spi, W25_DUMMY); - } - while ((status & W25_SR_BUSY) != 0); - - /* Deselect the FLASH */ - - SPI_SELECT(priv->spi, SPIDEV_FLASH, false); - -#else - /* Loop as long as the memory is busy with a write cycle */ do @@ -535,7 +507,6 @@ static uint8_t w25_waitwritecomplete(struct w25_dev_s *priv) #endif } while ((status & W25_SR_BUSY) != 0); -#endif return status; } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 43d0e6c685..842d18cc2a 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -270,15 +270,9 @@ static struct enc_driver_s g_enc28j60[CONFIG_ENC28J60_NINTERFACES]; /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS static inline void enc_configspi(FAR struct spi_dev_s *spi); -# define enc_lock(priv); -# define enc_unlock(priv); -#else -# define enc_configspi(spi) static void enc_lock(FAR struct enc_driver_s *priv); static inline void enc_unlock(FAR struct enc_driver_s *priv); -#endif /* SPI control register access */ @@ -372,19 +366,15 @@ static int enc_reset(FAR struct enc_driver_s *priv); * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS static inline void enc_configspi(FAR struct spi_dev_s *spi) { - /* Configure SPI for the ENC28J60. But only if we own the SPI bus. - * Otherwise, don't bother because it might change. - */ + /* Configure SPI for the ENC28J60. */ SPI_SETMODE(spi, CONFIG_ENC28J60_SPIMODE); SPI_SETBITS(spi, 8); (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY); } -#endif /**************************************************************************** * Function: enc_lock @@ -402,7 +392,6 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void enc_lock(FAR struct enc_driver_s *priv) { /* Lock the SPI bus in case there are multiple devices competing for the SPI @@ -420,7 +409,6 @@ static void enc_lock(FAR struct enc_driver_s *priv) (void)SPI_HWFEATURES(priv->spi, 0); (void)SPI_SETFREQUENCY(priv->spi, CONFIG_ENC28J60_FREQUENCY); } -#endif /**************************************************************************** * Function: enc_unlock @@ -438,14 +426,12 @@ static void enc_lock(FAR struct enc_driver_s *priv) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void enc_unlock(FAR struct enc_driver_s *priv) { /* Relinquish the lock on the bus. */ SPI_LOCK(priv->spi, false); } -#endif /**************************************************************************** * Function: enc_rdgreg2 diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 8c5e57e255..4eeb85f2e6 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -285,15 +285,9 @@ static struct enc_driver_s g_encx24j600[CONFIG_ENCX24J600_NINTERFACES]; /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS static inline void enc_configspi(FAR struct spi_dev_s *spi); -# define enc_lock(priv); -# define enc_unlock(priv); -#else -# define enc_configspi(spi) static void enc_lock(FAR struct enc_driver_s *priv); static inline void enc_unlock(FAR struct enc_driver_s *priv); -#endif /* SPI control register access */ @@ -395,19 +389,15 @@ static int enc_reset(FAR struct enc_driver_s *priv); * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS static inline void enc_configspi(FAR struct spi_dev_s *spi) { - /* Configure SPI for the ENCX24J600. But only if we own the SPI bus. - * Otherwise, don't bother because it might change. - */ + /* Configure SPI for the ENCX24J600. */ SPI_SETMODE(spi, CONFIG_ENCX24J600_SPIMODE); SPI_SETBITS(spi, 8); (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_ENCX24J600_FREQUENCY); } -#endif /**************************************************************************** * Function: enc_lock @@ -425,7 +415,6 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void enc_lock(FAR struct enc_driver_s *priv) { /* Lock the SPI bus in case there are multiple devices competing for the SPI @@ -443,7 +432,6 @@ static void enc_lock(FAR struct enc_driver_s *priv) (void)SPI_HWFEATURES(priv->spi, 0); (void)SPI_SETFREQUENCY(priv->spi, CONFIG_ENCX24J600_FREQUENCY); } -#endif /**************************************************************************** * Function: enc_unlock @@ -461,14 +449,12 @@ static void enc_lock(FAR struct enc_driver_s *priv) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void enc_unlock(FAR struct enc_driver_s *priv) { /* Relinquish the lock on the bus. */ SPI_LOCK(priv->spi, false); } -#endif /**************************************************************************** * Function: enc_cmd diff --git a/drivers/sensors/adxl345_base.c b/drivers/sensors/adxl345_base.c index dfca4e30d0..4b2f95fbde 100644 --- a/drivers/sensors/adxl345_base.c +++ b/drivers/sensors/adxl345_base.c @@ -409,20 +409,6 @@ ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_dev_s *dev, #ifdef CONFIG_ADXL345_SPI priv->spi = dev; - /* If this SPI bus is not shared, then we can config it now. - * If it is shared, then other device could change our config, - * then just configure before sending data. - */ - -#ifdef CONFIG_SPI_OWNBUS - /* Configure SPI for the ADXL345 */ - - SPI_SETMODE(priv->spi, SPIDEV_MODE3); - SPI_SETBITS(priv->spi, 8); - (void)SPI_HWFEATURES(priv->spi, 0); - (void)SPI_SETFREQUENCY(priv->spi, ADXL345_SPI_MAXFREQUENCY); -#endif - #else priv->i2c = dev; diff --git a/drivers/sensors/adxl345_spi.c b/drivers/sensors/adxl345_spi.c index 381eec64b7..1e837132af 100644 --- a/drivers/sensors/adxl345_spi.c +++ b/drivers/sensors/adxl345_spi.c @@ -64,7 +64,6 @@ * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void adxl345_configspi(FAR struct spi_dev_s *spi) { /* Configure SPI for the ADXL345 */ @@ -74,7 +73,6 @@ static inline void adxl345_configspi(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, ADXL345_SPI_MAXFREQUENCY); } -#endif /**************************************************************************** * Public Functions @@ -94,10 +92,8 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* If SPI bus is shared then lock and configure it */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, true); adxl345_configspi(priv->spi); -#endif /* Select the ADXL345 */ @@ -114,9 +110,7 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Unlock bus */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, false); -#endif #ifdef CONFIG_ADXL345_REGDEBUG dbg("%02x->%02x\n", regaddr, regval); @@ -141,10 +135,8 @@ void adxl345_putreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr, /* If SPI bus is shared then lock and configure it */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, true); adxl345_configspi(priv->spi); -#endif /* Select the ADXL345 */ @@ -160,9 +152,8 @@ void adxl345_putreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr, SPI_SELECT(priv->spi, SPIDEV_ACCELEROMETER, false); /* Unlock bus */ -#ifndef CONFIG_SPI_OWNBUS + (void)SPI_LOCK(priv->spi, false); -#endif } /**************************************************************************** @@ -179,10 +170,8 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* If SPI bus is shared then lock and configure it */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, true); adxl345_configspi(priv->spi); -#endif /* Select the ADXL345 */ @@ -199,9 +188,7 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Unlock bus */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, false); -#endif #ifdef CONFIG_ADXL345_REGDEBUG dbg("%02x->%04x\n", regaddr, regval); diff --git a/drivers/sensors/max31855.c b/drivers/sensors/max31855.c index 7fc21f4356..c239d9688d 100644 --- a/drivers/sensors/max31855.c +++ b/drivers/sensors/max31855.c @@ -279,15 +279,6 @@ int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi) priv->spi = spi; priv->temp = 0; -#ifdef CONFIG_SPI_OWNBUS - /* Configure SPI for the MAX31855 */ - - SPI_SETMODE(priv->spi, SPIDEV_MODE1); - SPI_SETBITS(priv->spi, 8); - (void)SPI_HWFEATURES(priv->spi, 0); - (void)SPI_SETFREQUENCY(priv->spi, MAX31855_SPI_MAXFREQ); -#endif - /* Register the character driver */ ret = register_driver(devpath, &g_max31855fops, 0666, priv); diff --git a/drivers/sensors/max6675.c b/drivers/sensors/max6675.c index 7c2404d176..38aa6c18a7 100644 --- a/drivers/sensors/max6675.c +++ b/drivers/sensors/max6675.c @@ -256,15 +256,6 @@ int max6675_register(FAR const char *devpath, FAR struct spi_dev_s *spi) priv->spi = spi; priv->temp = 0; -#ifdef CONFIG_SPI_OWNBUS - /* Configure SPI for the MAX6675 */ - - SPI_SETMODE(priv->spi, SPIDEV_MODE1); - SPI_SETBITS(priv->spi, 8); - (void)SPI_HWFEATURES(priv->spi, 0); - (void)SPI_SETFREQUENCY(priv->spi, MAX6675_SPI_MAXFREQ); -#endif - /* Register the character driver */ ret = register_driver(devpath, &g_max6675fops, 0666, priv); diff --git a/drivers/sensors/mpl115a.c b/drivers/sensors/mpl115a.c index ba43af3aa8..0c4e87414c 100644 --- a/drivers/sensors/mpl115a.c +++ b/drivers/sensors/mpl115a.c @@ -112,7 +112,6 @@ static const struct file_operations g_mpl115afops = * Private Functions ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static inline void mpl115a_configspi(FAR struct spi_dev_s *spi) { /* Configure SPI for the MPL115A */ @@ -122,7 +121,6 @@ static inline void mpl115a_configspi(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, MPL115A_SPI_MAXFREQUENCY); } -#endif /**************************************************************************** * Name: mpl115a_getreg8 @@ -138,10 +136,8 @@ static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv, uint8_t regaddr) /* If SPI bus is shared then lock and configure it */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, true); mpl115a_configspi(priv->spi); -#endif /* Select the MPL115A */ @@ -158,9 +154,7 @@ static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv, uint8_t regaddr) /* Unlock bus */ -#ifndef CONFIG_SPI_OWNBUS (void)SPI_LOCK(priv->spi, false); -#endif #ifdef CONFIG_MPL115A_REGDEBUG dbg("%02x->%02x\n", regaddr, regval); diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index c416b67b56..4d0b72741c 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -22,14 +22,6 @@ config SPI_SLAVE_DMA endif -config SPI_OWNBUS - bool "SPI single device" - default n - ---help--- - Set if there is only one active device on the SPI bus. No locking or - SPI configuration will be performed. It is not necessary for clients to - lock, re-configure, etc. - config SPI_EXCHANGE bool "SPI exchange" default y diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index 7f3a41c549..823b330982 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c @@ -110,9 +110,7 @@ /* SPI methods */ -#ifndef CONFIG_SPI_OWNBUS static int spi_lock(FAR struct spi_dev_s *dev, bool lock); -#endif static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, @@ -144,9 +142,7 @@ static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, static const struct spi_ops_s g_spiops = { -#ifndef CONFIG_SPI_OWNBUS spi_lock, /* lock */ -#endif spi_select, /* select */ spi_setfrequency, /* setfrequency */ spi_setmode, /* setmode */ @@ -193,7 +189,6 @@ static const struct spi_ops_s g_spiops = * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static int spi_lock(FAR struct spi_dev_s *dev, bool lock) { FAR struct spi_bitbang_s *priv = (FAR struct spi_bitbang_s *)dev; @@ -219,7 +214,6 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock) return OK; } -#endif /**************************************************************************** * Name: spi_select diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index 9e7e9d2c0c..29b6ad84b1 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -283,15 +283,9 @@ static inline void cc3000_configspi(FAR struct spi_dev_s *spi) static void cc3000_lock_and_select(FAR struct spi_dev_s *spi) { -#ifndef CONFIG_SPI_OWNBUS - /* Lock the SPI bus because there are multiple devices competing for the - * SPI bus - */ - /* Lock the SPI bus so that we have exclusive access */ (void)SPI_LOCK(spi, true); -#endif /* We have the lock. Now make sure that the SPI bus is configured for the * CC3000 (it might have gotten configured for a different device while @@ -306,9 +300,8 @@ static void cc3000_lock_and_select(FAR struct spi_dev_s *spi) * Function: cc3000_unlock * * Description: - * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS - * undefined) then we need to un-lock the SPI bus for each transfer, - * possibly losing the current configuration. + * Un-lock the SPI bus after each transfer, possibly losing the current + * configuration if we are sharing the SPI bus with other devices. * * Parameters: * spi - Reference to the SPI driver structure @@ -326,11 +319,9 @@ static void cc3000_deselect_and_unlock(FAR struct spi_dev_s *spi) SPI_SELECT(spi, SPIDEV_WIRELESS, false); -#ifndef CONFIG_SPI_OWNBUS /* Relinquish the SPI bus. */ (void)SPI_LOCK(spi, false); -#endif } /**************************************************************************** diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index 430c0b5b7a..0d83651cee 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -158,21 +158,13 @@ struct nrf24l01_dev_s ****************************************************************************/ /* Low-level SPI helpers */ -#ifdef CONFIG_SPI_OWNBUS static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi); -# define nrf24l01_lock(spi) -# define nrf24l01_unlock(spi) -#else -# define nrf24l01_configspi(spi); static void nrf24l01_lock(FAR struct spi_dev_s *spi); static void nrf24l01_unlock(FAR struct spi_dev_s *spi); -#endif static uint8_t nrf24l01_access(FAR struct nrf24l01_dev_s *dev, nrf24l01_access_mode_t mode, uint8_t cmd, uint8_t *buf, int length); - static uint8_t nrf24l01_flush_rx(FAR struct nrf24l01_dev_s *dev); - static uint8_t nrf24l01_flush_tx(FAR struct nrf24l01_dev_s *dev); /* Read register from nrf24 */ @@ -250,7 +242,6 @@ static const struct file_operations nrf24l01_fops = * Private Functions ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void nrf24l01_lock(FAR struct spi_dev_s *spi) { /* Lock the SPI bus because there are multiple devices competing for the @@ -271,15 +262,13 @@ static void nrf24l01_lock(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); SPI_SELECT(spi, SPIDEV_WIRELESS, false); } -#endif /**************************************************************************** * Function: nrf24l01_unlock * * Description: - * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS - * undefined) then we need to un-lock the SPI bus for each transfer, - * possibly losing the current configuration. + * Un-lock the SPI bus after each transfer, possibly losing the current + * configuration if we are sharing the SPI bus with other devices. * * Parameters: * spi - Reference to the SPI driver structure @@ -291,23 +280,18 @@ static void nrf24l01_lock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void nrf24l01_unlock(FAR struct spi_dev_s *spi) { /* Relinquish the SPI bus. */ (void)SPI_LOCK(spi, false); } -#endif /**************************************************************************** * Function: nrf24l01_configspi * * Description: - * Configure the SPI for use with the NRF24L01. This function should be - * called once during touchscreen initialization to configure the SPI - * bus. Note that if CONFIG_SPI_OWNBUS is not defined, then this function - * does nothing. + * Configure the SPI for use with the NRF24L01. * * Parameters: * spi - Reference to the SPI driver structure @@ -319,12 +303,9 @@ static void nrf24l01_unlock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi) { - /* Configure SPI for the NRF24L01 module. - * As we own the SPI bus this method is called just once. - */ + /* Configure SPI for the NRF24L01 module. */ SPI_SELECT(spi, SPIDEV_WIRELESS, true); /* Useful ? */ SPI_SETMODE(spi, SPIDEV_MODE0); @@ -333,7 +314,6 @@ static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi) (void)SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ); SPI_SELECT(spi, SPIDEV_WIRELESS, false); } -#endif static inline void nrf24l01_select(struct nrf24l01_dev_s * dev) { diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c index 1596db3a6e..f0a51be5af 100644 --- a/drivers/wireless/pn532.c +++ b/drivers/wireless/pn532.c @@ -85,15 +85,9 @@ * Private Function Prototypes ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS static inline void pn532_configspi(FAR struct spi_dev_s *spi); -# define pn532_lock(spi) -# define pn532_unlock(spi) -#else -# define pn532_configspi(spi); static void pn532_lock(FAR struct spi_dev_s *spi); static void pn532_unlock(FAR struct spi_dev_s *spi); -#endif /* Character driver methods */ @@ -143,7 +137,6 @@ static const uint8_t pn532ack[] = * Private Functions ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS static void pn532_lock(FAR struct spi_dev_s *spi) { (void)SPI_LOCK(spi, true); @@ -153,16 +146,12 @@ static void pn532_lock(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); } -#endif -#ifndef CONFIG_SPI_OWNBUS static void pn532_unlock(FAR struct spi_dev_s *spi) { (void)SPI_LOCK(spi, false); } -#endif -#ifdef CONFIG_SPI_OWNBUS static inline void pn532_configspi(FAR struct spi_dev_s *spi) { /* Configure SPI for the PN532 module. @@ -174,7 +163,6 @@ static inline void pn532_configspi(FAR struct spi_dev_s *spi) (void)SPI_HWFEATURES(spi, 0); (void)SPI_SETFREQUENCY(spi, CONFIG_PN532_SPI_FREQ); } -#endif static inline void pn532_select(struct pn532_dev_s *dev) { diff --git a/include/nuttx/analog/pga11x.h b/include/nuttx/analog/pga11x.h index 9a74e09f0e..7b6cf7881c 100644 --- a/include/nuttx/analog/pga11x.h +++ b/include/nuttx/analog/pga11x.h @@ -73,8 +73,6 @@ * When SPI_SELECT is called with devid=SPIDEV_MUX. * * Other settings that effect the driver: - * CONFIG_SPI_OWNBUS -- If the PGA117 is enabled, this must be set to 'y' - * if the PGA117 is the only device on the SPI bus; * CONFIG_DEBUG_SPI -- With CONFIG_DEBUG and CONFIG_DEBUG_VERBOSE, * this will enable debug output from the PGA117 driver. */ diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index fb2b012c97..b7ba3eac1b 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -51,11 +51,9 @@ * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ -/* CONFIG_SPI_OWNBUS - Set if there is only one active device on the SPI bus. - * No locking or SPI configuration will be performed. It is not necessary - * for clients to lock, re-configure, etc.. - * CONFIG_SPI_EXCHANGE - Driver supports a single exchange method +/* CONFIG_SPI_EXCHANGE - Driver supports a single exchange method * (vs a recvblock() and sndblock ()methods). + * CONFIG_SPI_HWFEATURES - Support special, hardware-specific SPI features. * CONFIG_SPI_CMDDATA - Devices on the SPI bus require out-of-band support * to distinguish command transfers from data transfers. Such devices * will often support either 9-bit SPI (yech) or 8-bit SPI and a GPIO @@ -85,11 +83,7 @@ * ****************************************************************************/ -#ifndef CONFIG_SPI_OWNBUS -# define SPI_LOCK(d,l) (d)->ops->lock(d,l) -#else -# define SPI_LOCK(d,l) 0 -#endif +#define SPI_LOCK(d,l) (d)->ops->lock(d,l) /**************************************************************************** * Name: SPI_SELECT @@ -428,9 +422,7 @@ typedef uint8_t spi_hwfeatures_t; struct spi_dev_s; struct spi_ops_s { -#ifndef CONFIG_SPI_OWNBUS CODE int (*lock)(FAR struct spi_dev_s *dev, bool lock); -#endif CODE void (*select)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); CODE uint32_t (*setfrequency)(FAR struct spi_dev_s *dev, uint32_t frequency); diff --git a/include/nuttx/spi/spi_bitbang.h b/include/nuttx/spi/spi_bitbang.h index b54a3b3d1a..fee6a9f1fc 100644 --- a/include/nuttx/spi/spi_bitbang.h +++ b/include/nuttx/spi/spi_bitbang.h @@ -127,9 +127,7 @@ struct spi_bitbang_s FAR const struct spi_bitbang_ops_s *low; /* Low-level operations */ uint32_t holdtime; /* SCK hold time to achieve requested frequency */ bitexchange_t exchange; /* The select bit exchange function */ -#ifndef CONFIG_SPI_OWNBUS sem_t exclsem; /* Supports mutually exclusive access to SPI */ -#endif #ifdef CONFIG_SPI_BITBANG_VARWIDTH uint8_t nbits; /* Number of bits in the transfer */ #endif -- GitLab From 3a1d3bba5a7345bd5923f157da69571e126478f8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 18:59:51 -0600 Subject: [PATCH 607/858] Update ChangeLog --- ChangeLog | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ba0f26784..226462a16d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11348,6 +11348,7 @@ buffering and race conditions. These were necessary for for the NuttX networking later to be stable in some stress testing. From Andrew Webster (2016-01-22). - * include/spi/spi.h: Add an optional hwfeaqtures() method to the - SPI interface (2016-01-22). - + * include/spi/spi.h: Add an optional hwfeatures() method to the + SPI interface (2016-01-23). + * drivers/spi/Kconfig and many other files: Remove CONFIG_SPI_OWNBUS: + Now its not just a good idea, its the law (2015-01-23). -- GitLab From 7ee6c5bcfc9f414f536b975fe62f64e49830140e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 19:18:55 -0600 Subject: [PATCH 608/858] Minor clean-up for last big commit --- drivers/lcd/p14201.c | 39 --------------------------------------- drivers/net/encx24j600.c | 31 ------------------------------- 2 files changed, 70 deletions(-) diff --git a/drivers/lcd/p14201.c b/drivers/lcd/p14201.c index a1df779364..8d51c77a97 100644 --- a/drivers/lcd/p14201.c +++ b/drivers/lcd/p14201.c @@ -205,7 +205,6 @@ struct rit_dev_s /* Low-level SPI helpers */ -static inline void rit_configspi(FAR struct spi_dev_s *spi); static void rit_select(FAR struct spi_dev_s *spi); static void rit_deselect(FAR struct spi_dev_s *spi); static void rit_sndbytes(FAR struct rit_dev_s *priv, FAR const uint8_t *buffer, @@ -423,43 +422,6 @@ static const uint8_t g_setallrow[] = * Private Functions **************************************************************************************/ -/************************************************************************************** - * Name: rit_configspi - * - * Description: - * Configure the SPI for use with the P14201 - * - * Input Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - **************************************************************************************/ - -static inline void rit_configspi(FAR struct spi_dev_s *spi) -{ -#ifdef CONFIG_P14201_FREQUENCY - ritdbg("Mode: %d Bits: 8 Frequency: %d\n", - CONFIG_P14201_SPIMODE, CONFIG_P14201_FREQUENCY); -#else - ritdbg("Mode: %d Bits: 8\n", CONFIG_P14201_SPIMODE); -#endif - - /* Configure SPI for the P14201. But only if we own the SPI bus. Otherwise, don't - * bother because it might change. - */ - - SPI_SETMODE(spi, CONFIG_P14201_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_HWFEATURES(spi, 0); -#ifdef CONFIG_P14201_FREQUENCY - (void)SPI_SETFREQUENCY(spi, CONFIG_P14201_FREQUENCY) -#endif -} - /************************************************************************************** * Name: rit_select * @@ -1204,7 +1166,6 @@ FAR struct lcd_dev_s *rit_initialize(FAR struct spi_dev_s *spi, unsigned int dev /* Select the SD1329 controller */ - rit_configspi(spi); rit_select(spi); /* Clear the display */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 4eeb85f2e6..7cc6791c70 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -285,7 +285,6 @@ static struct enc_driver_s g_encx24j600[CONFIG_ENCX24J600_NINTERFACES]; /* Low-level SPI helpers */ -static inline void enc_configspi(FAR struct spi_dev_s *spi); static void enc_lock(FAR struct enc_driver_s *priv); static inline void enc_unlock(FAR struct enc_driver_s *priv); @@ -373,32 +372,6 @@ static int enc_reset(FAR struct enc_driver_s *priv); * Private Functions ****************************************************************************/ -/**************************************************************************** - * Function: enc_configspi - * - * Description: - * Configure the SPI for use with the ENCX24J600 - * - * Parameters: - * spi - Reference to the SPI driver structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static inline void enc_configspi(FAR struct spi_dev_s *spi) -{ - /* Configure SPI for the ENCX24J600. */ - - SPI_SETMODE(spi, CONFIG_ENCX24J600_SPIMODE); - SPI_SETBITS(spi, 8); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_ENCX24J600_FREQUENCY); -} - /**************************************************************************** * Function: enc_lock * @@ -2912,10 +2885,6 @@ int enc_initialize(FAR struct spi_dev_s *spi, return -EAGAIN; } - /* Configure SPI for the ENCX24J600 */ - - enc_configspi(priv->spi); - /* Lock the SPI bus so that we have exclusive access */ enc_lock(priv); -- GitLab From a4a496ad6f8e875c1b646b0ad38ab8f38e024efb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 19:13:31 -0600 Subject: [PATCH 609/858] spi.h needs to include errno.h now --- include/nuttx/spi/spi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index b7ba3eac1b..ce2aec8655 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -46,6 +46,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions -- GitLab From d87f7e99d20c30730209bc1b027ff1560c704833 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 19:45:30 -0600 Subject: [PATCH 610/858] NOkia LCD needs to initialize SPI before using it --- drivers/analog/pga11x.c | 8 -------- drivers/lcd/nokia6100.c | 7 ++++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/analog/pga11x.c b/drivers/analog/pga11x.c index 915cfca055..d542bb7797 100644 --- a/drivers/analog/pga11x.c +++ b/drivers/analog/pga11x.c @@ -121,14 +121,6 @@ # define spivdbg(x...) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/drivers/lcd/nokia6100.c b/drivers/lcd/nokia6100.c index d3a765a812..3a392eec02 100644 --- a/drivers/lcd/nokia6100.c +++ b/drivers/lcd/nokia6100.c @@ -1159,7 +1159,12 @@ FAR struct lcd_dev_s *nokia_lcdinitialize(FAR struct spi_dev_s *spi, unsigned in priv->spi = spi; /* Save the SPI instance */ priv->contrast = NOKIA_DEFAULT_CONTRAST; /* Initial contrast setting */ - /* Enable the LCD controller */ + /* Configure and enable the LCD controller */ + + SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); + SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY) if (nokia_initialize(priv) == OK) { -- GitLab From 31cf7e0900a37c09430d8cae5f315917c32816d7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 Jan 2016 21:21:15 -0600 Subject: [PATCH 611/858] Fix missing semicolon --- drivers/lcd/nokia6100.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/lcd/nokia6100.c b/drivers/lcd/nokia6100.c index 3a392eec02..5a7e6ab976 100644 --- a/drivers/lcd/nokia6100.c +++ b/drivers/lcd/nokia6100.c @@ -1073,6 +1073,13 @@ static int nokia_initialize(struct nokia_dev_s *priv) { struct spi_dev_s *spi = priv->spi; + /* Configure SPI */ + + SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); + SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY); + /* Configure the display */ nokia_cmdarray(spi, sizeof(g_disctl), g_disctl); /* Display control */ @@ -1096,6 +1103,7 @@ static int nokia_initialize(struct nokia_dev_s *priv) nokia_cmdarray(spi, sizeof(g_paset), g_caset); /* Column address set */ nokia_clrram(spi); nokia_sndcmd(spi, S1D15G10_DISON); /* Display on */ + return OK; } #endif @@ -1105,6 +1113,15 @@ static int nokia_initialize(struct nokia_dev_s *priv) { struct struct spi_dev_s *spi = priv->spi; + /* Configure SPI */ + + SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); + SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); + (void)SPI_HWFEATURES(spi, 0); + (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY); + + /* Configure the display */ + nokia_sndcmd(spi, PCF8833_SLEEPOUT); /* Exit sleep mode */ nokia_sndcmd(spi, PCF8833_BSTRON); /* Turn on voltage booster */ #ifdef CONFIG_NOKIA6100_INVERT @@ -1118,6 +1135,7 @@ static int nokia_initialize(struct nokia_dev_s *priv) nokia_sndcmd(spi, PCF8833_NOP); /* No operation */ nokia_clrram(spi); nokia_sndcmd(spi, PCF8833_DISPON); /* Display on */ + return OK; } #endif /* CONFIG_NOKIA6100_PCF8833 */ @@ -1159,12 +1177,7 @@ FAR struct lcd_dev_s *nokia_lcdinitialize(FAR struct spi_dev_s *spi, unsigned in priv->spi = spi; /* Save the SPI instance */ priv->contrast = NOKIA_DEFAULT_CONTRAST; /* Initial contrast setting */ - /* Configure and enable the LCD controller */ - - SPI_SETMODE(spi, CONFIG_NOKIA6100_SPIMODE); - SPI_SETBITS(spi, CONFIG_NOKIA6100_WORDWIDTH); - (void)SPI_HWFEATURES(spi, 0); - (void)SPI_SETFREQUENCY(spi, CONFIG_NOKIA6100_FREQUENCY) + /* Enable the LCD controller */ if (nokia_initialize(priv) == OK) { -- GitLab From 564a1ce6064c3ff59dae93305424a2c71f4d7900 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 24 Jan 2016 08:21:55 -0600 Subject: [PATCH 612/858] Cosmetic clean-up of comments --- drivers/net/encx24j600.c | 4 +--- drivers/wireless/nrf24l01.c | 2 +- drivers/wireless/pn532.c | 4 +--- include/nuttx/spi/spi.h | 7 +++++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 7cc6791c70..9a94ac005d 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -248,9 +248,7 @@ struct enc_driver_s WDOG_ID txpoll; /* TX poll timer */ WDOG_ID txtimeout; /* TX timeout timer */ - /* If we don't own the SPI bus, then we cannot do SPI accesses from the - * interrupt handler. - */ + /* Avoid SPI accesses from the interrupt handler by using the work queue */ struct work_s irqwork; /* Interrupt continuation work queue support */ struct work_s towork; /* Tx timeout work queue support */ diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index 0d83651cee..d1f81ee930 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -1277,7 +1277,7 @@ int nrf24l01_init(FAR struct nrf24l01_dev_s *dev) CHECK_ARGS(dev); nrf24l01_lock(dev->spi); - /* Configure the SPI parameters now (if we own the bus) */ + /* Configure the SPI parameters before communicating */ nrf24l01_configspi(dev->spi); diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c index f0a51be5af..0f171950de 100644 --- a/drivers/wireless/pn532.c +++ b/drivers/wireless/pn532.c @@ -154,9 +154,7 @@ static void pn532_unlock(FAR struct spi_dev_s *spi) static inline void pn532_configspi(FAR struct spi_dev_s *spi) { - /* Configure SPI for the PN532 module. - * As we own the SPI bus this method is called just once. - */ + /* Configure SPI for the PN532 module. */ SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, -8); diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index ce2aec8655..167da6af4c 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -52,13 +52,16 @@ * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ -/* CONFIG_SPI_EXCHANGE - Driver supports a single exchange method +/* These SPI configuration options affect the form of the SPI interface: + * + * CONFIG_SPI_EXCHANGE - Driver supports a single exchange method * (vs a recvblock() and sndblock ()methods). - * CONFIG_SPI_HWFEATURES - Support special, hardware-specific SPI features. * CONFIG_SPI_CMDDATA - Devices on the SPI bus require out-of-band support * to distinguish command transfers from data transfers. Such devices * will often support either 9-bit SPI (yech) or 8-bit SPI and a GPIO * output that selects between command and data. + * CONFIG_SPI_HWFEATURES - Include an interface method to support special, + * hardware-specific SPI features. */ /* Access macros ************************************************************/ -- GitLab From 146031b29e227d388befa9792ea12af14c6e64c4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 24 Jan 2016 09:15:12 -0600 Subject: [PATCH 613/858] Flesh out unfinished lock() method implementations in al SPI drivers --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index dd88ee499c..927eaf0772 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dd88ee499c9fc77884091a48cad9d6fc3ba451a9 +Subproject commit 927eaf0772fa49978c0f64aa5e9d60c4e105ebd4 -- GitLab From abe8215a44a19c3001de75d109d9c6af77ac6965 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 24 Jan 2016 09:16:18 -0600 Subject: [PATCH 614/858] Refresh submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 32ca4e6150..f28b525870 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 32ca4e6150e8369dfa9f84f62863774cea6dc736 +Subproject commit f28b525870aa79ba2925468a0f6bd27b8af421b6 -- GitLab From 2bacc40350e38de606b3c1083ca5783403786e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3FUTF-8=3FQ=3FManuel=5FSt=3Dc3=3Dbchn=3F=3D?= Date: Sun, 24 Jan 2016 12:48:24 -0600 Subject: [PATCH 615/858] Fix mismatched prototype error in work_queue() --- arch | 2 +- libc/wqueue/work_queue.c | 22 +++------------------- sched/wqueue/kwork_queue.c | 22 +++------------------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/arch b/arch index f28b525870..7843ff7609 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f28b525870aa79ba2925468a0f6bd27b8af421b6 +Subproject commit 7843ff7609a657430a4ba0b86eb3267682d73a30 diff --git a/libc/wqueue/work_queue.c b/libc/wqueue/work_queue.c index ae3a412c57..ba9e13c97e 100644 --- a/libc/wqueue/work_queue.c +++ b/libc/wqueue/work_queue.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/wqueue/work_queue.c * - * Copyright (C) 2009-2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2011, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,22 +52,6 @@ #if defined(CONFIG_LIB_USRWORK) && !defined(__KERNEL__) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -103,7 +87,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay) + FAR void *arg, systime_t delay) { DEBUGASSERT(work != NULL); @@ -162,7 +146,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, ****************************************************************************/ int work_queue(int qid, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay) + FAR void *arg, systime_t delay) { if (qid == USRWORK) { diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index 45bd740600..e2f7d88003 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wqueue/kwork_queue.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,22 +52,6 @@ #ifdef CONFIG_SCHED_WORKQUEUE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -103,7 +87,7 @@ static void work_qqueue(FAR struct kwork_wqueue_s *wqueue, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay) + FAR void *arg, systime_t delay) { irqstate_t flags; @@ -162,7 +146,7 @@ static void work_qqueue(FAR struct kwork_wqueue_s *wqueue, ****************************************************************************/ int work_queue(int qid, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay) + FAR void *arg, systime_t delay) { #ifdef CONFIG_SCHED_HPWORK if (qid == HPWORK) -- GitLab From 0e3cd129ae917ad0c742009c40f3aca0cc3e116d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3FUTF-8=3FB=3F6ZmI5p6X6aOe=3F=3D?= Date: Sun, 24 Jan 2016 12:54:32 -0600 Subject: [PATCH 616/858] Fix some issues with strcasecmp() conditional compilation and with memccpy() return value --- libc/string/lib_memccpy.c | 6 +----- libc/string/lib_strcasecmp.c | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libc/string/lib_memccpy.c b/libc/string/lib_memccpy.c index bbb307afc6..2201870911 100644 --- a/libc/string/lib_memccpy.c +++ b/libc/string/lib_memccpy.c @@ -81,16 +81,12 @@ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) /* Did we just copy the terminating byte c? */ - if (*pout == (unsigned char)c) + if (*pout++ == (unsigned char)c) { /* Yes return a pointer to the byte after the copy of c into s1 */ return (FAR void *)pout; } - - /* No increment to the next destination location */ - - pout++; } /* C was not found in the first n bytes of s2 */ diff --git a/libc/string/lib_strcasecmp.c b/libc/string/lib_strcasecmp.c index 9017625b2a..5fa3e28914 100644 --- a/libc/string/lib_strcasecmp.c +++ b/libc/string/lib_strcasecmp.c @@ -46,7 +46,7 @@ * Public Functions ****************************************************************************/ -#ifndef CONFIG_ARCH_STRCMP +#ifndef CONFIG_ARCH_STRCASECMP int strcasecmp(FAR const char *cs, FAR const char *ct) { int result; -- GitLab From 047ed9e543a97ea2ef644507c5c84ed3acc5a22b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jan 2016 09:56:00 -0600 Subject: [PATCH 617/858] Add some utilities to support 64-bit math operations on platforms that do not support long long types. Not yet used anywhere --- arch | 2 +- include/nuttx/math32.h | 180 ++++++++++++++++++++++++++++++++++++++ libc/misc/Make.defs | 5 ++ libc/misc/lib_uadd64.c | 80 +++++++++++++++++ libc/misc/lib_umul32.c | 93 ++++++++++++++++++++ libc/misc/lib_umul32x64.c | 86 ++++++++++++++++++ libc/misc/lib_umul64.c | 101 +++++++++++++++++++++ libc/misc/lib_usub64.c | 82 +++++++++++++++++ 8 files changed, 628 insertions(+), 1 deletion(-) create mode 100644 include/nuttx/math32.h create mode 100644 libc/misc/lib_uadd64.c create mode 100644 libc/misc/lib_umul32.c create mode 100644 libc/misc/lib_umul32x64.c create mode 100644 libc/misc/lib_umul64.c create mode 100644 libc/misc/lib_usub64.c diff --git a/arch b/arch index 7843ff7609..e6307a4fa9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7843ff7609a657430a4ba0b86eb3267682d73a30 +Subproject commit e6307a4fa94d09845fee43de7c7fce0d379d9207 diff --git a/include/nuttx/math32.h b/include/nuttx/math32.h new file mode 100644 index 0000000000..d3bda49580 --- /dev/null +++ b/include/nuttx/math32.h @@ -0,0 +1,180 @@ +/**************************************************************************** + * include/nuttx/math32.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MATH32_H +#define __INCLUDE_NUTTX_MATH32_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* These types are useful on platforms that do not support 64-bit types. */ + +struct int64_s +{ +#ifdef CONFIG_ENDIAN_BIG + int32_t ms; + uint32_t ls; +#else + uint32_t ls; + int32_t ms; +#endif +}; + +struct uint64_s +{ +#ifdef CONFIG_ENDIAN_BIG + uint32_t ms; + uint32_t ls; +#else + uint32_t ls; + uint32_t ms; +#endif +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: umul32 + * + * Description: + * Multiply two 32-bit values, factor1 and factor2, and return the + * full 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32(uint32_t factor1, uint32_t factor2, FAR struct uint64_s *product); + +/**************************************************************************** + * Name: umul32x64 + * + * Description: + * Multiply one 32-bit and one 64-bit values, factor1 and factor2, + * respectively, and return the truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32x64(uint32_t factor1, FAR const struct uint64_s *factor2, + FAR struct uint64_s *product); + +/**************************************************************************** + * Name: umul64 + * + * Description: + * Multiply two 64-bit values, factor1 and factor2, and return the + * truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul64(FAR const struct uint64_s *factor1, + FAR const struct uint64_s *factor2, + FAR struct uint64_s *product); + +/**************************************************************************** + * Name: uadd64 + * + * Description: + * Add two 64-bit values and return a 64-bit sum. + * + * Input Parameters: + * term1 and term2 - The values to be added + * sum - The location to return the product of the two values. sum may + * be one of term1 or term2 + * + ****************************************************************************/ + +void uadd64(FAR const struct uint64_s *term1, + FAR const struct uint64_s *term2, + FAR struct uint64_s *sum); + +/**************************************************************************** + * Name: usub64 + * + * Description: + * Subtract two 64-bit values and return the 64-bit difference. + * + * Input Parameters: + * minuend - The number from which another number (the Subtrahend) is + * to be subtracted. + * subtrahend - The number that is to be subtracted. + * difference - The location to return the difference of the two values. + * difference may the same as one of minuend or subtrahend. + * + ****************************************************************************/ + +void usub64(FAR const struct uint64_s *minuend, + FAR const struct uint64_s *subtrahend, + FAR struct uint64_s *difference); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_MATH32_H */ diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index 6c0a37ac7c..5eaada16fa 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -38,6 +38,11 @@ CSRCS += lib_stream.c lib_filesem.c lib_utsname.c CSRCS += lib_tea_encrypt.c lib_tea_decrypt.c +# Support for platforms that do not have long long types + +CSRCS += lib_umul32.c lib_umul64.c lib_umul32x64.c +CSRCS += lib_uadd64.c lib_usub64.c + # Add C files that depend on file OR socket descriptors ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) diff --git a/libc/misc/lib_uadd64.c b/libc/misc/lib_uadd64.c new file mode 100644 index 0000000000..0a2f4a7588 --- /dev/null +++ b/libc/misc/lib_uadd64.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libc/fixedmath/lib_uadd64.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uadd64 + * + * Description: + * Add two 64-bit values and return a 64-bit sum. + * + * Input Parameters: + * term1 and term2 - The values to be added + * sum - The location to return the product of the two values. sum may + * be one of term1 or term2 + * + ****************************************************************************/ + +void uadd64(FAR const struct uint64_s *term1, + FAR const struct uint64_s *term2, + FAR struct uint64_s *sum) +{ + /* Get the MS part of the sum */ + + sum->ms = term1->ms + term2->ms; + + /* Check for carry, i.e., that is when: + * + * term1->ls + term2->ls > UINT32_MAX + */ + + if ((UINT32_MAX - term1->ls) > term2->ls) + { + sum->ms++; + } + + /* Get the LS part of the sum */ + + sum->ls = term1->ls + term2->ls; +} diff --git a/libc/misc/lib_umul32.c b/libc/misc/lib_umul32.c new file mode 100644 index 0000000000..2b971dd11f --- /dev/null +++ b/libc/misc/lib_umul32.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/fixedmath/lib_umul32.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: umul32 + * + * Description: + * Multiply two 32-bit values, factor1 and factor2, and return the + * full 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32(uint32_t factor1, uint32_t factor2, FAR struct uint64_s *product) +{ + struct uint64_s part2; + uint32_t ms1; + uint32_t ls1; + uint32_t ms2; + uint32_t ls2; + uint32_t tmp; + + /* factor1 = ms1 << 16 + ls1 + * factor2 = ms2 << 16 + ls2 + */ + + ms1 = factor1 >> 16; + ls1 = factor1 & 0x0000ffff; + ms2 = factor2 >> 16; + ls2 = factor2 & 0x0000ffff; + + /* factor1 * factor2 = (ms1 * ms2 << 32) + + * ls1 * (ms2 << 16) + ls2 * (ms1 << 16) + + * ls1 * ls2 + * part1 = (ms1 * ms2 << 32) + ls1 * ls2 + * part2 = ls1 * (ms2 << 16) + ls2 * (ms1 << 16) + * factor1 * factor2 = part1 + part2 + */ + + product->ms = ms1 * ms2; + product->ls = ls1 * ls2; + + tmp = ls1 * ms2 + ls2 * ms1; + part2.ms = tmp >> 16; + part2.ls = tmp << 16; + + uadd64(product, &part2, product); +} diff --git a/libc/misc/lib_umul32x64.c b/libc/misc/lib_umul32x64.c new file mode 100644 index 0000000000..ca37fa2ea8 --- /dev/null +++ b/libc/misc/lib_umul32x64.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * libc/fixedmath/lib_umul32x64.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: umul32x64 + * + * Description: + * Multiply one 32-bit and one 64-bit values, factor1 and factor2, + * respectively, and return the truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32x64(uint32_t factor1, FAR const struct uint64_s *factor2, + FAR struct uint64_s *product) +{ + struct uint64_s part1; + struct uint64_s part2; + + /* factor2 = factor2->ms << 32 + factor2->ls + * + * Full 128-bit product: + * factor1 * factor2 = factor1 * (factor2->ms << 32) + + * factor1 * factor2->ls + */ + + /* Get part1 = factor1 * factor2->ms, shifting left by 32-bits + * (truncating to 64-bits) + */ + + part1.ms = factor1 * factor2->ms; + part1.ls = 0; + + /* Get the full 64-bit part2 = factor1 * factor2->ls */ + + umul32(factor1, factor2->ls, &part2); + + /* The product is then the sum */ + + uadd64(&part1, &part2, product); +} diff --git a/libc/misc/lib_umul64.c b/libc/misc/lib_umul64.c new file mode 100644 index 0000000000..bf70a1b2a4 --- /dev/null +++ b/libc/misc/lib_umul64.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * libc/fixedmath/lib_umul64.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: umul64 + * + * Description: + * Multiply two 64-bit values, factor1 and factor2, and return the + * truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul64(FAR const struct uint64_s *factor1, + FAR const struct uint64_s *factor2, + FAR struct uint64_s *product) +{ + struct uint64_s part1; + struct uint64_s part2; + + /* factor1 = factor1->ms << 32 + factor1->ls + * factor2 = factor2->ms << 32 + factor2->ls + * + * Full 128-bit product: + * factor1 * factor2 = (factor1->ms * factor2->ms << 64) + + * factor1->ls * (factor2->ms << 32) + + * factor2->ls * (factor1->ms << 32) + + * factor1->ls * factor2->ls + * + * Truncated, 64-bit product: + * factor1 * factor2 = (factor1->ls * factor2->ms + + * factor2->ls * factor1->ms) << 32) + + * factor1->ls * factor2->ls + * + * part1 = (factor1->ls * factor2->ms + + * factor2->ls * factor1->ms) << 32) + * part2 = factor1->ls * factor2->ls + * factor1 * factor2 = part1 + part2 + */ + + /* Get part1 = factor1->ls * factor2->ms + factor2->ls * factor1->ms, + * shifting left by 32-bits (truncating to 64-bits) + */ + + part1.ms = factor1->ls * factor2->ms + + factor2->ls * factor2->ms; + part1.ls = 0; + + /* Get the full 64-bit part2 = factor1->ls * factor2->ls */ + + umul32(factor1->ls, factor2->ls, &part2); + + /* The product is then the sum */ + + uadd64(&part1, &part2, product); +} diff --git a/libc/misc/lib_usub64.c b/libc/misc/lib_usub64.c new file mode 100644 index 0000000000..ab9821cd8e --- /dev/null +++ b/libc/misc/lib_usub64.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * libc/fixedmath/lib_usub64.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: usub64 + * + * Description: + * Subtract two 64-bit values and return the 64-bit difference. + * + * Input Parameters: + * minuend - The number from which another number (the Subtrahend) is + * to be subtracted. + * subtrahend - The number that is to be subtracted. + * difference - The location to return the difference of the two values. + * difference may the same as one of minuend or subtrahend. + * + ****************************************************************************/ + +void usub64(FAR const struct uint64_s *minuend, + FAR const struct uint64_s *subtrahend, + FAR struct uint64_s *difference) +{ + /* Get the MS part of the difference */ + + difference->ms = minuend->ms - subtrahend->ms; + + /* Check for a borrow, i.e., that is when: + * + * subtrahend->ls > minuend->ls + */ + + if (subtrahend->ls > minuend->ls) + { + difference->ms--; + } + + /* Get the LS part of the difference */ + + difference->ls = minuend->ls - subtrahend->ls; +} -- GitLab From eac271413f43db848429d0e393a2fee22be3a7aa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jan 2016 11:19:25 -0600 Subject: [PATCH 618/858] Add more 32-bit math operations; Update ChangeLog --- ChangeLog | 3 + include/nuttx/math32.h | 121 ++++++++++++++++++++++++++++---------- libc/misc/Make.defs | 2 +- libc/misc/lib_uadd32x64.c | 80 +++++++++++++++++++++++++ libc/misc/lib_uadd64.c | 2 +- libc/misc/lib_umul32.c | 2 +- libc/misc/lib_umul64.c | 4 +- libc/misc/lib_usub64.c | 4 +- libc/misc/lib_usub64x32.c | 82 ++++++++++++++++++++++++++ 9 files changed, 263 insertions(+), 37 deletions(-) create mode 100644 libc/misc/lib_uadd32x64.c create mode 100644 libc/misc/lib_usub64x32.c diff --git a/ChangeLog b/ChangeLog index 226462a16d..7841c7b552 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11352,3 +11352,6 @@ SPI interface (2016-01-23). * drivers/spi/Kconfig and many other files: Remove CONFIG_SPI_OWNBUS: Now its not just a good idea, its the law (2015-01-23). + * include/nuttx/math32.h and libc/misc: Add some utilities to support + 64-bit arithmetic operations for platforms that do not support long + long types. Not yet used anywhere (2015-01-25). diff --git a/include/nuttx/math32.h b/include/nuttx/math32.h index d3bda49580..64e993d790 100644 --- a/include/nuttx/math32.h +++ b/include/nuttx/math32.h @@ -89,52 +89,46 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: umul32 + * Name: uneg64 * * Description: - * Multiply two 32-bit values, factor1 and factor2, and return the - * full 64-bit product. + * Negate a 64-bit unsigned value. * * Input Parameters: - * factor1 and factor2 - The values to be multiplied - * product - The location to return the product of the two values. + * value - The value to be negated. * ****************************************************************************/ -void umul32(uint32_t factor1, uint32_t factor2, FAR struct uint64_s *product); - -/**************************************************************************** - * Name: umul32x64 - * - * Description: - * Multiply one 32-bit and one 64-bit values, factor1 and factor2, - * respectively, and return the truncated 64-bit product. - * - * Input Parameters: - * factor1 and factor2 - The values to be multiplied - * product - The location to return the product of the two values. - * - ****************************************************************************/ +/* void uneg64(FAR const uint64_s *value); */ -void umul32x64(uint32_t factor1, FAR const struct uint64_s *factor2, - FAR struct uint64_s *product); +#define uneg64(value) \ + do \ + { \ + value->ms = ~value->ms; \ + value->ls = -value->ls; \ + if (value->ls == 0) \ + { \ + value->ms++; \ + } \ + } \ + while (0) /**************************************************************************** - * Name: umul64 + * Name: uadd32x64 * * Description: - * Multiply two 64-bit values, factor1 and factor2, and return the - * truncated 64-bit product. + * Add a 32-bit value to a 64-bit values and return the truncated 64-bit + * sum. * * Input Parameters: - * factor1 and factor2 - The values to be multiplied - * product - The location to return the product of the two values. + * term1 and term2 - The values to be added + * sum - The location to return the product of the two values. sum may + * be one of term1 or term2 * ****************************************************************************/ -void umul64(FAR const struct uint64_s *factor1, - FAR const struct uint64_s *factor2, - FAR struct uint64_s *product); +void uadd32x64(uint32_t term1, FAR const struct uint64_s *term2, + FAR struct uint64_s *sum); /**************************************************************************** * Name: uadd64 @@ -153,6 +147,25 @@ void uadd64(FAR const struct uint64_s *term1, FAR const struct uint64_s *term2, FAR struct uint64_s *sum); +/**************************************************************************** + * Name: usub64x32 + * + * Description: + * Subtract a 32-bit value from a 64-bit value and return the 64-bit + * difference. + * + * Input Parameters: + * minuend - The number from which another number (the Subtrahend) is + * to be subtracted. + * subtrahend - The number that is to be subtracted. + * difference - The location to return the difference of the two values. + * difference may the same as one of minuend or subtrahend. + * + ****************************************************************************/ + +void usub64x32(FAR const struct uint64_s *minuend, uint32_t subtrahend, + FAR struct uint64_s *difference); + /**************************************************************************** * Name: usub64 * @@ -163,7 +176,7 @@ void uadd64(FAR const struct uint64_s *term1, * minuend - The number from which another number (the Subtrahend) is * to be subtracted. * subtrahend - The number that is to be subtracted. - * difference - The location to return the difference of the two values. + * difference - The location to return the difference of the two values. * difference may the same as one of minuend or subtrahend. * ****************************************************************************/ @@ -172,6 +185,54 @@ void usub64(FAR const struct uint64_s *minuend, FAR const struct uint64_s *subtrahend, FAR struct uint64_s *difference); +/**************************************************************************** + * Name: umul32 + * + * Description: + * Multiply two 32-bit values, factor1 and factor2, and return the + * full 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32(uint32_t factor1, uint32_t factor2, FAR struct uint64_s *product); + +/**************************************************************************** + * Name: umul32x64 + * + * Description: + * Multiply one 32-bit and one 64-bit values, factor1 and factor2, + * respectively, and return the truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul32x64(uint32_t factor1, FAR const struct uint64_s *factor2, + FAR struct uint64_s *product); + +/**************************************************************************** + * Name: umul64 + * + * Description: + * Multiply two 64-bit values, factor1 and factor2, and return the + * truncated 64-bit product. + * + * Input Parameters: + * factor1 and factor2 - The values to be multiplied + * product - The location to return the product of the two values. + * + ****************************************************************************/ + +void umul64(FAR const struct uint64_s *factor1, + FAR const struct uint64_s *factor2, + FAR struct uint64_s *product); + #undef EXTERN #ifdef __cplusplus } diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index 5eaada16fa..1a9f7911c1 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -41,7 +41,7 @@ CSRCS += lib_tea_encrypt.c lib_tea_decrypt.c # Support for platforms that do not have long long types CSRCS += lib_umul32.c lib_umul64.c lib_umul32x64.c -CSRCS += lib_uadd64.c lib_usub64.c +CSRCS += lib_uadd32x64.c lib_uadd64.c lib_usub64x32.c lib_usub64.c # Add C files that depend on file OR socket descriptors diff --git a/libc/misc/lib_uadd32x64.c b/libc/misc/lib_uadd32x64.c new file mode 100644 index 0000000000..68800e5529 --- /dev/null +++ b/libc/misc/lib_uadd32x64.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libc/fixedmath/lib_uadd32x64.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uadd32x64 + * + * Description: + * Add a 32-bit value to a 64-bit values and return the truncated 64-bit + * sum. + * + * Input Parameters: + * term1 and term2 - The values to be added + * sum - The location to return the product of the two values. sum may + * be one of term1 or term2 + * + ****************************************************************************/ + +void uadd32x64(uint32_t term1, FAR const struct uint64_s *term2, + FAR struct uint64_s *sum) +{ + /* Get the MS part of the sum */ + + sum->ms = term2->ms; + + /* Check for carry, i.e., that is when: + * + * term1 + term2->ls > UINT32_MAX + */ + + if ((UINT32_MAX - term1) > term2->ls) + { + sum->ms++; + } + + /* Get the LS part of the sum */ + + sum->ls = term1 + term2->ls; +} diff --git a/libc/misc/lib_uadd64.c b/libc/misc/lib_uadd64.c index 0a2f4a7588..c9e634d1ee 100644 --- a/libc/misc/lib_uadd64.c +++ b/libc/misc/lib_uadd64.c @@ -65,7 +65,7 @@ void uadd64(FAR const struct uint64_s *term1, sum->ms = term1->ms + term2->ms; /* Check for carry, i.e., that is when: - * + * * term1->ls + term2->ls > UINT32_MAX */ diff --git a/libc/misc/lib_umul32.c b/libc/misc/lib_umul32.c index 2b971dd11f..b245e10ee0 100644 --- a/libc/misc/lib_umul32.c +++ b/libc/misc/lib_umul32.c @@ -75,7 +75,7 @@ void umul32(uint32_t factor1, uint32_t factor2, FAR struct uint64_s *product) ls2 = factor2 & 0x0000ffff; /* factor1 * factor2 = (ms1 * ms2 << 32) + - * ls1 * (ms2 << 16) + ls2 * (ms1 << 16) + + * ls1 * (ms2 << 16) + ls2 * (ms1 << 16) + * ls1 * ls2 * part1 = (ms1 * ms2 << 32) + ls1 * ls2 * part2 = ls1 * (ms2 << 16) + ls2 * (ms1 << 16) diff --git a/libc/misc/lib_umul64.c b/libc/misc/lib_umul64.c index bf70a1b2a4..d20612638e 100644 --- a/libc/misc/lib_umul64.c +++ b/libc/misc/lib_umul64.c @@ -69,12 +69,12 @@ void umul64(FAR const struct uint64_s *factor1, * Full 128-bit product: * factor1 * factor2 = (factor1->ms * factor2->ms << 64) + * factor1->ls * (factor2->ms << 32) + - * factor2->ls * (factor1->ms << 32) + + * factor2->ls * (factor1->ms << 32) + * factor1->ls * factor2->ls * * Truncated, 64-bit product: * factor1 * factor2 = (factor1->ls * factor2->ms + - * factor2->ls * factor1->ms) << 32) + + * factor2->ls * factor1->ms) << 32) + * factor1->ls * factor2->ls * * part1 = (factor1->ls * factor2->ms + diff --git a/libc/misc/lib_usub64.c b/libc/misc/lib_usub64.c index ab9821cd8e..2a327245ec 100644 --- a/libc/misc/lib_usub64.c +++ b/libc/misc/lib_usub64.c @@ -53,7 +53,7 @@ * minuend - The number from which another number (the Subtrahend) is * to be subtracted. * subtrahend - The number that is to be subtracted. - * difference - The location to return the difference of the two values. + * difference - The location to return the difference of the two values. * difference may the same as one of minuend or subtrahend. * ****************************************************************************/ @@ -67,7 +67,7 @@ void usub64(FAR const struct uint64_s *minuend, difference->ms = minuend->ms - subtrahend->ms; /* Check for a borrow, i.e., that is when: - * + * * subtrahend->ls > minuend->ls */ diff --git a/libc/misc/lib_usub64x32.c b/libc/misc/lib_usub64x32.c new file mode 100644 index 0000000000..b691e5105f --- /dev/null +++ b/libc/misc/lib_usub64x32.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * libc/fixedmath/lib_usub64x32.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: usub64x32 + * + * Description: + * Subtract a 32-bit value from a 64-bit value and return the 64-bit + * difference. + * + * Input Parameters: + * minuend - The number from which another number (the Subtrahend) is + * to be subtracted. + * subtrahend - The number that is to be subtracted. + * difference - The location to return the difference of the two values. + * difference may the same as one of minuend or subtrahend. + * + ****************************************************************************/ + +void usub64x32(FAR const struct uint64_s *minuend, uint32_t subtrahend, + FAR struct uint64_s *difference) +{ + /* Get the MS part of the difference */ + + difference->ms = minuend->ms; + + /* Check for a borrow, i.e., that is when: + * + * subtrahend->ls > minuend->ls + */ + + if (subtrahend > minuend->ls) + { + difference->ms--; + } + + /* Get the LS part of the difference */ + + difference->ls = minuend->ls - subtrahend; +} -- GitLab From 365e015010efb0e963d673070cc1d729aca7bd68 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jan 2016 17:46:59 -0600 Subject: [PATCH 619/858] iob_alloc_qentry() has the same issue that was recently fixed in iob_alloc() --- arch | 2 +- net/iob/iob_alloc.c | 28 +++++++-------- net/iob/iob_alloc_qentry.c | 74 +++++++++++++++++++++++++------------- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/arch b/arch index e6307a4fa9..c299f1fd71 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e6307a4fa94d09845fee43de7c7fce0d379d9207 +Subproject commit c299f1fd7161babd61ad5abf3501728966eeb34a diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index 08d13ce30c..2583fc4136 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -55,22 +55,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -128,6 +112,11 @@ static FAR struct iob_s *iob_allocwait(bool throttled) /* EINTR is not an error! EINTR simply means that we were * awakened by a signal and we should try again. + * + * REVISIT: Many end-user interfaces are required to return + * with an error if EINTR is set. Most uses of this function + * is in internal, non-user logic. But are there cases where + * the error should be returned. */ if (errcode == EINTR) @@ -138,6 +127,13 @@ static FAR struct iob_s *iob_allocwait(bool throttled) ret = 0; } + else + { + /* Stop the loop and return a error */ + + DEBUGASSERT(errcode > 0); + ret = -errcode; + } } else { diff --git a/net/iob/iob_alloc_qentry.c b/net/iob/iob_alloc_qentry.c index 64efefa93d..04f076bc4e 100644 --- a/net/iob/iob_alloc_qentry.c +++ b/net/iob/iob_alloc_qentry.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/iob/iob_alloc_qentry.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -56,22 +57,6 @@ #if CONFIG_IOB_NCHAINS > 0 -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -115,13 +100,54 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void) */ ret = sem_wait(&g_qentry_sem); - - /* When we wake up from wait, an I/O buffer chain container was - * returned to the free list. However, if there are concurrent - * allocations from interrupt handling, then I suspect that there - * is a race condition. But no harm, we will just wait again in - * that case. - */ + if (ret < 0) + { + int errcode = get_errno(); + + /* EINTR is not an error! EINTR simply means that we were + * awakened by a signal and we should try again. + * + * REVISIT: Many end-user interfaces are required to return + * with an error if EINTR is set. Most uses of this function + * is in internal, non-user logic. But are there cases where + * the error should be returned. + */ + + if (errcode == EINTR) + { + /* Force a success indication so that we will continue + * looping. + */ + + ret = 0; + } + else + { + /* Stop the loop and return a error */ + + DEBUGASSERT(errcode > 0); + ret = -errcode; + } + } + else + { + /* When we wake up from wait successfully, an I/O buffer chain + * container was returned to the free list. However, if there + * are concurrent allocations from interrupt handling, then I + * suspect that there is a race condition. But no harm, we + * will just wait again in that case. + * + * We need release our count so that it is available to + * iob_tryalloc_qentry(), perhaps allowing another thread to + * take our count. In that event, iob_tryalloc_qentry() will + * fail above and we will have to wait again. + * + * TODO: Consider a design modification to permit us to + * complete the allocation without losing our count. + */ + + sem_post(sem); + } } } while (ret == OK && !qentry); -- GitLab From aad3b013f1e57b7c994bc31c67de5fbde54f702d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jan 2016 18:28:59 -0600 Subject: [PATCH 620/858] Update ChangeLog --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7841c7b552..9d062cb48b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11355,3 +11355,6 @@ * include/nuttx/math32.h and libc/misc: Add some utilities to support 64-bit arithmetic operations for platforms that do not support long long types. Not yet used anywhere (2015-01-25). + * arch/arm/src/samv7/chip: Add an AFEC header file (2016-01-25). + * net/iob: iob_alloc_qentry() has the same issues as did iob_alloc() + fixed on 2016-01-23. (2016-01-26). -- GitLab From 26d40fa80cfd515013f140edffca44c0f7483adf Mon Sep 17 00:00:00 2001 From: xuhang Date: Mon, 25 Jan 2016 20:00:11 -0600 Subject: [PATCH 621/858] drivers/usbhost/hid_parser.c: Wrong size used in memcpy() --- ChangeLog | 2 ++ drivers/usbhost/hid_parser.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d062cb48b..4951d6f440 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11358,3 +11358,5 @@ * arch/arm/src/samv7/chip: Add an AFEC header file (2016-01-25). * net/iob: iob_alloc_qentry() has the same issues as did iob_alloc() fixed on 2016-01-23. (2016-01-26). + * drivers/usbhost/hid_parser.c: Wrong size used in memcpy(). From Hang + Xu (2016-01-25). diff --git a/drivers/usbhost/hid_parser.c b/drivers/usbhost/hid_parser.c index d20a080f64..59198faa93 100644 --- a/drivers/usbhost/hid_parser.c +++ b/drivers/usbhost/hid_parser.c @@ -139,9 +139,7 @@ int hid_parsereport(FAR const uint8_t *report, int rptlen, return -E2BIG; } - memcpy((currstate + 1), - currstate, sizeof(struct hid_rptitem_s)); - + memcpy((currstate + 1), currstate, sizeof(struct hid_state_s)); currstate++; break; -- GitLab From f74fbecf526239f51c41503b7a279fa7e01497c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 07:59:36 -0600 Subject: [PATCH 622/858] PCA9555 I/O expander: Fix an error in addressing noted by Stefan Kolb; convert to use I2C_TRANSFER instead of I2C_WRITEREAD which is not thread safe --- drivers/ioexpander/Kconfig | 1 + drivers/ioexpander/pca9555.c | 104 +++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/drivers/ioexpander/Kconfig b/drivers/ioexpander/Kconfig index f4b1694e97..438beeed5a 100644 --- a/drivers/ioexpander/Kconfig +++ b/drivers/ioexpander/Kconfig @@ -15,6 +15,7 @@ if IOEXPANDER_PCA9555 config PCA9555_MULTIPLE bool "Multiple PCA9555 Devices" default n + depends on EXPERIMENTAL ---help--- Can be defined to support multiple PCA9555 devices on board. diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index a582a228d8..c267f38308 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/ioexpander/pca9555.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2016 Gregory Nutt. All rights reserved. * Author: Sebastien Lorquet * * References: @@ -64,14 +64,17 @@ # warning I2C support is required (CONFIG_I2C) #endif -#ifndef CONFIG_I2C_WRITEREAD -# warning Support of the I2C writeread() method is required (CONFIG_I2C_WRITEREAD) +#ifndef CONFIG_I2C_TRANSFER +# warning Support of the I2C transfer() method is required (CONFIG_I2C_TRANSFER) #endif /**************************************************************************** * Private Function Prototypes ****************************************************************************/ +static int pca9555_writeread(FAR struct pca9555_dev_s *pca, + FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, + int rbuflen); static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, int dir); static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, @@ -126,6 +129,51 @@ static const struct ioexpander_ops_s g_pca9555_ops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: pca9555_writeread + * + * Description: + * Write to then read from the I2C device. + * + ****************************************************************************/ + +static int pca9555_writeread(FAR struct pca9555_dev_s *pca, + FAR const uint8_t *wbuffer, int wbuflen, + FAR uint8_t *rbuffer, int rbuflen) +{ + struct i2c_msg_s msg[2]; + + /* Format two messages: The first is a write */ + + msg[0].addr = pca->config->address; + msg[0].flags = 0; + msg[0].buffer = (uint8_t *)wbuffer; /* Override const */ + msg[0].length = wbuflen; + + /* The second is either a read (rbuflen > 0) or a write (rbuflen < 0) with + * no restart. + */ + + if (rbuflen > 0) + { + msg[1].flags = I2C_M_READ; + } + else + { + msg[1].flags = I2C_M_NORESTART; + rbuflen = -rbuflen; + } + + msg[1].addr = pca->config->address; + msg[1].buffer = rbuffer; + msg[1].length = rbuflen; + + /* Then perform the transfer */ + + I2C_SETFREQUENCY(pca->i2c, pca->config->frequency); + return I2C_TRANSFER(pca->i2c, msg, 2); +} + /**************************************************************************** * Name: pca9555_setbit * @@ -134,12 +182,12 @@ static const struct ioexpander_ops_s g_pca9555_ops = * ****************************************************************************/ -static int pca9555_setbit(FAR struct i2c_dev_s *i2c, uint8_t addr, +static int pca9555_setbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, uint8_t pin, int bitval) { - int ret; + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf[2]; - buf[0] = addr; + int ret; if (pin > 15) { @@ -147,11 +195,13 @@ static int pca9555_setbit(FAR struct i2c_dev_s *i2c, uint8_t addr, } else if (pin > 7) { - addr += 1; + addr++; pin -= 8; } - ret = I2C_WRITEREAD(i2c, &addr, 1, &buf[1], 1); + buf[0] = addr; + + ret = pca9555_writeread(pca, &buf[0], 1, &buf[1], 1); if (ret < 0) { return ret; @@ -166,7 +216,7 @@ static int pca9555_setbit(FAR struct i2c_dev_s *i2c, uint8_t addr, buf[1] &= ~(1 << pin); } - return I2C_WRITE(i2c, buf, 2); + return I2C_WRITE(pca->i2c, buf, 2); } /**************************************************************************** @@ -177,9 +227,10 @@ static int pca9555_setbit(FAR struct i2c_dev_s *i2c, uint8_t addr, * ****************************************************************************/ -static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, +static int pca9555_getbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, uint8_t pin, FAR bool *val) { + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf; int ret; @@ -193,7 +244,7 @@ static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, pin -= 8; } - ret = I2C_WRITEREAD(i2c, &addr, 1, &buf, 1); + ret = pca9555_writeread(pca, &addr, 1, &buf, 1); if (ret < 0) { return ret; @@ -214,8 +265,7 @@ static int pca9555_getbit(FAR struct i2c_dev_s *i2c, uint8_t addr, static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, int direction) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_setbit(pca->i2c, PCA9555_REG_CONFIG, pin, + return pca9555_setbit(dev, PCA9555_REG_CONFIG, pin, (direction == IOEXPANDER_DIRECTION_IN)); } @@ -230,12 +280,11 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, int opt, FAR void *val) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; int ival = (int)val; if (opt == IOEXPANDER_OPTION_INVERT) { - return pca9555_setbit(pca->i2c, PCA9555_REG_POLINV, pin, ival); + return pca9555_setbit(dev, PCA9555_REG_POLINV, pin, ival); } return -EINVAL; @@ -252,8 +301,7 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_setbit(pca->i2c, PCA9555_REG_OUTPUT, pin, value); + return pca9555_setbit(dev, PCA9555_REG_OUTPUT, pin, value); } /**************************************************************************** @@ -267,8 +315,7 @@ static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_getbit(pca->i2c, PCA9555_REG_INPUT, pin, value); + return pca9555_getbit(dev, PCA9555_REG_INPUT, pin, value); } /**************************************************************************** @@ -282,8 +329,7 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_getbit(pca->i2c, PCA9555_REG_OUTPUT, pin, value); + return pca9555_getbit(dev, PCA9555_REG_OUTPUT, pin, value); } #ifdef CONFIG_IOEXPANDER_MULTIPIN @@ -296,18 +342,18 @@ static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, * ****************************************************************************/ -static int pca9555_getmultibits(FAR struct i2c_dev_s *i2c, uint8_t addr, +static int pca9555_getmultibits(FAR struct ioexpander_dev_s *dev, uint8_t addr, FAR uint8_t *pins, FAR bool *values, int count) { + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf[2]; int ret = OK; int i; int index; int pin; - ret = I2C_WRITEREAD(i2c, &addr, 1, buf, 2); - + ret = pca9555_writeread(pca, &addr, 1, buf, 2); if (ret < 0) { return ret; @@ -359,7 +405,7 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, * attempt to read one port only if all pins were on the same port, but * this would not save much. */ - ret = I2C_WRITEREAD(pca->i2c, &addr, 1, &buf[1], 2); + ret = pca9555_writeread(pca, &addr, 1, &buf[1], 2); if (ret < 0) { return ret; @@ -409,8 +455,7 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_getmultibits(pca->i2c, PCA9555_REG_INPUT, + return pca9555_getmultibits(dev, PCA9555_REG_INPUT, pins, values, count); } @@ -426,8 +471,7 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; - return pca9555_getmultibits(pca->i2c, PCA9555_REG_OUTPUT, + return pca9555_getmultibits(dev, PCA9555_REG_OUTPUT, pins, values, count); } @@ -453,7 +497,7 @@ static void pca9555_irqworker(void *arg) /* Read inputs */ - ret = I2C_WRITEREAD(pca->i2c, &addr, 1, buf, 2); + ret = pca9555_writeread(pca, &addr, 1, buf, 2); if (ret != OK) { return; -- GitLab From a6b1e6bd2349ede7bf51b0cd3f3e4ca6a5539d34 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 08:04:36 -0600 Subject: [PATCH 623/858] Updat ChangeLog --- ChangeLog | 9 +++++++++ arch | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4951d6f440..cd94d5c3ef 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11360,3 +11360,12 @@ fixed on 2016-01-23. (2016-01-26). * drivers/usbhost/hid_parser.c: Wrong size used in memcpy(). From Hang Xu (2016-01-25). + * drivers/ioexpander/pca9555.c: Fixed a bug in the function pca9555_setbit + which occurs if someone tries to set one of the pins 8-15. The problem is + that after the check if the pin is greater than 7 the variable addr is + incremented and used in the Call I2C_WRITEREAD. But later in the call to + the I2C_WRITE buf[0] is used as address but this address is not incremented + as it should be. Note address does mean the address to the register in the + ioexpander and not the I2C address. From Stefan Kolb (2016-01-26). + * drivers/ioexpander/pca9555: Convert to use I2C_TRANSFER vs. I2C_WRITEREAD, + the former is thread safe while the latter is deprecated (2016-01-26). diff --git a/arch b/arch index c299f1fd71..17e8a324c8 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c299f1fd7161babd61ad5abf3501728966eeb34a +Subproject commit 17e8a324c80f02bb9881a12cf6d02509a128c431 -- GitLab From 7fb7bef2d223654ea06671633e4a93f20d5c4437 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 09:55:17 -0600 Subject: [PATCH 624/858] Fix an error introduced with last IOB fix --- net/iob/iob_alloc_qentry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/iob/iob_alloc_qentry.c b/net/iob/iob_alloc_qentry.c index 04f076bc4e..2aab1e6353 100644 --- a/net/iob/iob_alloc_qentry.c +++ b/net/iob/iob_alloc_qentry.c @@ -146,7 +146,7 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void) * complete the allocation without losing our count. */ - sem_post(sem); + sem_post(&g_qentry_sem); } } } -- GitLab From 67f38169b237743551b713dd34cc98c4db6e4931 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 09:58:18 -0600 Subject: [PATCH 625/858] drivers/i2c: Move wrapper that implements I2C_WRITEREAD using I2C_transfer from pc9555.c to a new, comon i2c directory --- ChangeLog | 3 + drivers/Kconfig | 34 +----------- drivers/Makefile | 1 + drivers/README.txt | 5 +- drivers/i2c/Kconfig | 38 +++++++++++++ drivers/i2c/Make.defs | 50 +++++++++++++++++ drivers/i2c/i2c_writeread.c | 103 +++++++++++++++++++++++++++++++++++ drivers/ioexpander/pca9555.c | 40 +++----------- drivers/spi/Kconfig | 4 +- include/nuttx/i2c.h | 39 +++++++++++-- 10 files changed, 245 insertions(+), 72 deletions(-) create mode 100644 drivers/i2c/Kconfig create mode 100644 drivers/i2c/Make.defs create mode 100644 drivers/i2c/i2c_writeread.c diff --git a/ChangeLog b/ChangeLog index cd94d5c3ef..4f4a34eb31 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11369,3 +11369,6 @@ ioexpander and not the I2C address. From Stefan Kolb (2016-01-26). * drivers/ioexpander/pca9555: Convert to use I2C_TRANSFER vs. I2C_WRITEREAD, the former is thread safe while the latter is deprecated (2016-01-26). + * drivers/i2c/i2c_writeread.c: Create a wrapper that uses I2C_TRANSFER + to implement I2C_WRITEREAD functionalit (2016-01-26). + diff --git a/drivers/Kconfig b/drivers/Kconfig index a51ac4549f..c836f5a8c4 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -271,38 +271,8 @@ menuconfig I2C See include/nuttx/i2c.h for further I2C driver information. if I2C - -config I2C_SLAVE - bool "I2C Slave" - default n - -config I2C_TRANSFER - bool "Support the I2C transfer() method" - default n - -config I2C_WRITEREAD - bool "Support the I2C writeread() method" - default n - -config I2C_POLLED - bool "Polled I2C (no interrupts)" - default n - -config I2C_TRACE - bool "Enable I2C trace debug" - default n - -config I2C_NTRACE - int "Number of I2C trace records" - default 32 - depends on I2C_TRACE - -config I2C_RESET - bool "Support up_i2creset" - default n - depends on ARCH_HAVE_I2CRESET - -endif # I2C +source drivers/i2c/Kconfig +endif menuconfig SPI bool "SPI Driver Support" diff --git a/drivers/Makefile b/drivers/Makefile index c508b353dd..c642b91877 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -52,6 +52,7 @@ VPATH = . include analog$(DELIM)Make.defs include audio$(DELIM)Make.defs include bch$(DELIM)Make.defs +include i2c$(DELIM)Make.defs include input$(DELIM)Make.defs include ioexpander$(DELIM)Make.defs include lcd$(DELIM)Make.defs diff --git a/drivers/README.txt b/drivers/README.txt index 82334c923c..6f731a153f 100644 --- a/drivers/README.txt +++ b/drivers/README.txt @@ -68,6 +68,9 @@ eeprom/ interface but instead use the simple character interface provided by the EEPROM drivers. +i2c/ + I2C drivers and support logic. See include/nuttx/i2c.h + input/ This directory holds implementations of human input device (HID) drivers. This includes such things as mouse, touchscreen, joystick, @@ -144,7 +147,7 @@ serial/ the NuttX system console. See also include/nuttx/serial/serial.h spi/ - SPI drivers. See include/nuttx/spi.h + SPI drivers and support logic. See include/nuttx/spi/spi.h syslog/ System logging devices. See include/syslog.h and include/nuttx/syslog/syslog.h diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig new file mode 100644 index 0000000000..664b105920 --- /dev/null +++ b/drivers/i2c/Kconfig @@ -0,0 +1,38 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if I2C + +config I2C_SLAVE + bool "I2C Slave" + default n + +config I2C_TRANSFER + bool "Support the I2C transfer() method" + default n + +config I2C_WRITEREAD + bool "Support the I2C writeread() method" + default n + +config I2C_POLLED + bool "Polled I2C (no interrupts)" + default n + +config I2C_TRACE + bool "Enable I2C trace debug" + default n + +config I2C_NTRACE + int "Number of I2C trace records" + default 32 + depends on I2C_TRACE + +config I2C_RESET + bool "Support up_i2creset" + default n + depends on ARCH_HAVE_I2CRESET + +endif # I2C diff --git a/drivers/i2c/Make.defs b/drivers/i2c/Make.defs new file mode 100644 index 0000000000..5354db1bfe --- /dev/null +++ b/drivers/i2c/Make.defs @@ -0,0 +1,50 @@ +############################################################################ +# drivers/i2c/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Don't build anything if there is no I2C support + +ifeq ($(CONFIG_I2C),y) + +ifeq ($(CONFIG_I2C_TRANSFER),y) + CSRCS += i2c_writeread.c +endif + +# Include I2C device driver build support + +DEPPATH += --dep-path i2c +VPATH += :i2c +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)i2c} +endif + diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c new file mode 100644 index 0000000000..49753277b9 --- /dev/null +++ b/drivers/i2c/i2c_writeread.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * drivers/i2c/i2c_writeread.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#if defined(CONFIG_I2C_TRANSFER) + +/**************************************************************************** + * Name: pca9555_writeread + * + * Description: + * Write to then read from the I2C device. + * + ****************************************************************************/ + +int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR const uint8_t *wbuffer, int wbuflen, + FAR uint8_t *rbuffer, int rbuflen) +{ + struct i2c_msg_s msg[2]; + unsigned int flags; + + /* 7- or 10-bit address? */ + + DEBUGASSERT(config->addrlen == 10 || config->addrlen == 7); + flags = (config->addrlen == 10) ? I2C_M_TEN : 0; + + /* Format two messages: The first is a write */ + + msg[0].addr = config->address; + msg[0].flags = flags; + msg[0].buffer = (FAR uint8_t *)wbuffer; /* Override const */ + msg[0].length = wbuflen; + + /* The second is either a read (rbuflen > 0) or a write (rbuflen < 0) with + * no restart. + */ + + if (rbuflen > 0) + { + msg[1].flags = (flags | I2C_M_READ); + } + else + { + msg[1].flags = (flags | I2C_M_NORESTART); + rbuflen = -rbuflen; + } + + msg[1].addr = config->address; + msg[1].buffer = rbuffer; + msg[1].length = rbuflen; + + /* Then perform the transfer + * + * REVISIT: The following two operations must become atomic in order to + * assure thread safety. + */ + + I2C_SETFREQUENCY(dev, config->frequency); + return I2C_TRANSFER(dev, msg, 2); +} + +#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index c267f38308..5d3843d7ea 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -137,41 +137,19 @@ static const struct ioexpander_ops_s g_pca9555_ops = * ****************************************************************************/ -static int pca9555_writeread(FAR struct pca9555_dev_s *pca, - FAR const uint8_t *wbuffer, int wbuflen, - FAR uint8_t *rbuffer, int rbuflen) +static inline int pca9555_writeread(FAR struct pca9555_dev_s *pca, + FAR const uint8_t *wbuffer, int wbuflen, + FAR uint8_t *rbuffer, int rbuflen) { - struct i2c_msg_s msg[2]; - - /* Format two messages: The first is a write */ - - msg[0].addr = pca->config->address; - msg[0].flags = 0; - msg[0].buffer = (uint8_t *)wbuffer; /* Override const */ - msg[0].length = wbuflen; - - /* The second is either a read (rbuflen > 0) or a write (rbuflen < 0) with - * no restart. - */ - - if (rbuflen > 0) - { - msg[1].flags = I2C_M_READ; - } - else - { - msg[1].flags = I2C_M_NORESTART; - rbuflen = -rbuflen; - } + struct i2c_config_s config; - msg[1].addr = pca->config->address; - msg[1].buffer = rbuffer; - msg[1].length = rbuflen; + /* Set up the configuration and perform the write-read operation */ - /* Then perform the transfer */ + config.frequency = pca->config->frequency; + config.address = pca->config->address; + config.addrlen = 7; - I2C_SETFREQUENCY(pca->i2c, pca->config->frequency); - return I2C_TRANSFER(pca->i2c, msg, 2); + return i2c_writeread(pca->i2c, &config, wbuffer, wbuflen, rbuffer, rbuflen); } /**************************************************************************** diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 4d0b72741c..b4c8e93bbc 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -80,5 +80,5 @@ config SPI_BITBANG_VARWIDTH Enable support for a variable data width transfers. Default: 8-bit only. -endif -endif +endif # SPI_BITBANG +endif # SPI diff --git a/include/nuttx/i2c.h b/include/nuttx/i2c.h index 6395fde925..264c0beeb4 100644 --- a/include/nuttx/i2c.h +++ b/include/nuttx/i2c.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/i2c.h * - * Copyright(C) 2009-2012 Gregory Nutt. All rights reserved. + * Copyright(C) 2009-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -251,23 +251,36 @@ struct i2c_ops_s uint32_t (*setfrequency)(FAR struct i2c_dev_s *dev, uint32_t frequency); int (*setaddress)(FAR struct i2c_dev_s *dev, int addr, int nbits); int (*write)(FAR struct i2c_dev_s *dev, const uint8_t *buffer, - int buflen); + int buflen); int (*read)(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen); #ifdef CONFIG_I2C_WRITEREAD - int (*writeread)(FAR struct i2c_dev_s *inst, const uint8_t *wbuffer, - int wbuflen, uint8_t *rbuffer, int rbuflen); + int (*writeread)(FAR struct i2c_dev_s *dev, + FAR const uint8_t *wbuffer, int wbuflen, + FAR uint8_t *rbuffer, int rbuflen); #endif #ifdef CONFIG_I2C_TRANSFER int (*transfer)(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, - int count); + int count); #endif #ifdef CONFIG_I2C_SLAVE int (*setownaddress)(FAR struct i2c_dev_s *dev, int addr, int nbits); int (*registercallback)(FAR struct i2c_dev_s *dev, - int (*callback)(FAR void *arg), FAR void *arg); + int (*callback)(FAR void *arg), FAR void *arg); #endif }; +/* This structure contains the full state of I2C as needed for a specific + * transfer. It is passed to I2C methods so that I2C transfer may be + * performed in a thread safe manner. + */ + +struct i2c_config_s +{ + uint32_t frequency; /* I2C frequency */ + uint16_t address; /* I2C address (7 or 10 bit) */ + uint8_t addrlen; /* I2C address length (7 or 10 bits) */ +}; + /* I2C transaction segment beginning with a START. A number of these can * be transferred together to form an arbitrary sequence of write/read transfer * to an I2C slave device. @@ -352,6 +365,20 @@ int up_i2cuninitialize(FAR struct i2c_dev_s *dev); int up_i2creset(FAR struct i2c_dev_s *dev); #endif +/************************************************************************************ + * Name: i2c_writeread + * + * Description: + * Write to then read from the I2C device. + * + ************************************************************************************/ + +#ifdef CONFIG_I2C_TRANSFER +int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR const uint8_t *wbuffer, int wbuflen, + FAR uint8_t *rbuffer, int rbuflen); +#endif + #undef EXTERN #if defined(__cplusplus) } -- GitLab From d4a53ee131bf41d40056c301e638040858ebe218 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 10:26:16 -0600 Subject: [PATCH 626/858] I2C: Eliminate the I2C_WRITEREAD method --- ChangeLog | 3 ++- TODO | 4 ++-- arch | 2 +- configs | 2 +- drivers/i2c/Kconfig | 4 ---- drivers/ioexpander/pca9555.h | 4 ++-- drivers/timers/ds3231.c | 2 +- drivers/timers/pcf85263.c | 2 +- include/nuttx/i2c.h | 27 --------------------------- 9 files changed, 10 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f4a34eb31..d1930acca6 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11370,5 +11370,6 @@ * drivers/ioexpander/pca9555: Convert to use I2C_TRANSFER vs. I2C_WRITEREAD, the former is thread safe while the latter is deprecated (2016-01-26). * drivers/i2c/i2c_writeread.c: Create a wrapper that uses I2C_TRANSFER - to implement I2C_WRITEREAD functionalit (2016-01-26). + to implement I2C_WRITEREAD functionality (2016-01-26). + * I2C: Eliminate the I@C_WRITEREAD method (2016-01-26). diff --git a/TODO b/TODO index 5a828ea901..9d7c25dfad 100644 --- a/TODO +++ b/TODO @@ -1614,7 +1614,7 @@ o Other drivers (drivers/) in a multi-tasking I2C environment: - I2C_SETFREQUENCY: Frequency setting can be overwritten by other I2C usage. - - I2C_SETADDRESS used with I2C_READ, I2C_WRITE, and I2C_WRITEREAD: + - I2C_SETADDRESS used with I2C_READ and I2C_WRITE: Similarly, address can and will be changed by other I2C usage. NOTE also that I2C_SETADDRESS also sets the address width (either 7 or 10 bits). @@ -1627,7 +1627,7 @@ o Other drivers (drivers/) as is provided with the SPI interface, or (2) make each interface self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS methods; Add frequency to all interfaces and add the address to - I2C_READ, I2C_WRITE, and I2C_WRITEREAD. + I2C_READ and I2C_WRITE. o Linux/Cywgin simulation (arch/sim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/arch b/arch index 17e8a324c8..40aba37060 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 17e8a324c80f02bb9881a12cf6d02509a128c431 +Subproject commit 40aba37060aa2746c7a492045ae0b79d014afad2 diff --git a/configs b/configs index 927eaf0772..e569b357a2 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 927eaf0772fa49978c0f64aa5e9d60c4e105ebd4 +Subproject commit e569b357a25df0f74730dfb4464f70a3acded6b2 diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 664b105920..72f331cc04 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -13,10 +13,6 @@ config I2C_TRANSFER bool "Support the I2C transfer() method" default n -config I2C_WRITEREAD - bool "Support the I2C writeread() method" - default n - config I2C_POLLED bool "Polled I2C (no interrupts)" default n diff --git a/drivers/ioexpander/pca9555.h b/drivers/ioexpander/pca9555.h index 5a8e1b69df..258cf0e640 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -63,8 +63,8 @@ /* Prerequisites: * CONFIG_I2C * I2C support is required - * CONFIG_I2C_WRITEREAD - * Support for the I2C writeread method is required. + * CONFIG_I2C_TRANSFER + * Support for the I2C transfer method is required. * CONFIG_IOEXPANDER * Enables support for the PCA9555 I/O expander * diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 894c069d22..18a60c1b62 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -334,7 +334,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_WRITEREAD()). The + /* Perform the transfer (This could be done with i2c_writeread()). The * transfer may be performed repeatedly of the seconds values decreases, * meaning that that was a rollover in the seconds. */ diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 9fa04887cb..6081d88018 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -333,7 +333,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_WRITEREAD()). The + /* Perform the transfer (This could be done with i2c_writeread()). The * transfer may be performed repeatedly of the seconds values decreases, * meaning that that was a rollover in the seconds. */ diff --git a/include/nuttx/i2c.h b/include/nuttx/i2c.h index 264c0beeb4..8c053d820a 100644 --- a/include/nuttx/i2c.h +++ b/include/nuttx/i2c.h @@ -195,28 +195,6 @@ #define I2C_READ(d,b,l) ((d)->ops->read(d,b,l)) -/**************************************************************************** - * Name: I2C_WRITEREAD - * - * Description: - * Send a block of data on I2C using the previously selected I2C - * frequency and slave address, followed by restarted read access. - * It provides a convenient wrapper to the transfer function. - * - * Input Parameters: - * dev - Device-specific state data - * wbuffer - A pointer to the read-only buffer of data to be written to device - * wbuflen - The number of bytes to send from the buffer - * rbuffer - A pointer to a buffer of data to receive the data from the device - * rbuflen - The requested number of bytes to be read - * - * Returned Value: - * 0: success, <0: A negated errno - * - ****************************************************************************/ - -#define I2C_WRITEREAD(d,wb,wl,rb,rl) ((d)->ops->writeread(d,wb,wl,rb,rl)) - /**************************************************************************** * Name: I2C_TRANSFER * @@ -253,11 +231,6 @@ struct i2c_ops_s int (*write)(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen); int (*read)(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen); -#ifdef CONFIG_I2C_WRITEREAD - int (*writeread)(FAR struct i2c_dev_s *dev, - FAR const uint8_t *wbuffer, int wbuflen, - FAR uint8_t *rbuffer, int rbuflen); -#endif #ifdef CONFIG_I2C_TRANSFER int (*transfer)(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count); -- GitLab From b6b3c2be3e8b4d5dcbe680dd4c4ad37749e7f91d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 10:57:51 -0600 Subject: [PATCH 627/858] Add I2C_TRANSFER based wrappers for I2C_TRANSFER as well --- drivers/i2c/Make.defs | 2 +- drivers/i2c/i2c_read.c | 98 +++++++++++++++++++++++++++++++++++++ drivers/i2c/i2c_write.c | 93 +++++++++++++++++++++++++++++++++++ drivers/i2c/i2c_writeread.c | 20 +++++++- include/nuttx/i2c.h | 71 +++++++++++++++++++++++++-- 5 files changed, 276 insertions(+), 8 deletions(-) create mode 100644 drivers/i2c/i2c_read.c create mode 100644 drivers/i2c/i2c_write.c diff --git a/drivers/i2c/Make.defs b/drivers/i2c/Make.defs index 5354db1bfe..4d1d737a57 100644 --- a/drivers/i2c/Make.defs +++ b/drivers/i2c/Make.defs @@ -38,7 +38,7 @@ ifeq ($(CONFIG_I2C),y) ifeq ($(CONFIG_I2C_TRANSFER),y) - CSRCS += i2c_writeread.c + CSRCS += i2c_read.c i2c_write.c i2c_writeread.c endif # Include I2C device driver build support diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c new file mode 100644 index 0000000000..2c93bac533 --- /dev/null +++ b/drivers/i2c/i2c_read.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * drivers/i2c/i2c_read.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#if defined(CONFIG_I2C_TRANSFER) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2c_read + * + * Description: + * Receive a block of data from I2C using the previously selected I2C + * frequency and slave address. Each read operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this read completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to a buffer of data to receive the data from the device + * buflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +int i2c_read(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_msg_s msg; + unsigned int flags; + + /* 7- or 10-bit? */ + + flags = (config->addrlen == 10) ? I2C_M_TEN : 0; + + /* Setup for the transfer */ + + msg.addr = config->address, + msg.flags = (flags | I2C_M_READ); + msg.buffer = buffer; + msg.length = buflen; + + /* Then perform the transfer + * + * REVISIT: The following two operations must become atomic in order to + * assure thread safety. + */ + + I2C_SETFREQUENCY(dev, config->frequency); + return I2C_TRANSFER(dev, &msg, 1); +} + +#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c new file mode 100644 index 0000000000..3f2395e370 --- /dev/null +++ b/drivers/i2c/i2c_write.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * drivers/i2c/i2c_write.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#if defined(CONFIG_I2C_TRANSFER) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2c_write + * + * Description: + * Send a block of data on I2C. Each write operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this write completes. + * + * Input Parameters: + * dev - Device-specific state data + * config - Described the I2C configuration + * buffer - A pointer to the read-only buffer of data to be written to device + * buflen - The number of bytes to send from the buffer + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +int i2c_write(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_msg_s msg; + + /* Setup for the transfer */ + + msg.addr = config->address; + msg.flags = (config->addrlen == 10) ? I2C_M_TEN : 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; + + /* Then perform the transfer + * + * REVISIT: The following two operations must become atomic in order to + * assure thread safety. + */ + + I2C_SETFREQUENCY(dev, config->frequency); + return I2C_TRANSFER(dev, &msg, 1); +} + +#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index 49753277b9..d5fab3f43b 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -46,10 +46,26 @@ #if defined(CONFIG_I2C_TRANSFER) /**************************************************************************** - * Name: pca9555_writeread + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2c_writeread * * Description: - * Write to then read from the I2C device. + * Send a block of data on I2C using the previously, followed by restarted + * read access. This provides a convenient wrapper to the transfer function. + * + * Input Parameters: + * dev - Device-specific state data + * config - Described the I2C configuration + * wbuffer - A pointer to the read-only buffer of data to be written to device + * wbuflen - The number of bytes to send from the buffer + * rbuffer - A pointer to a buffer of data to receive the data from the device + * rbuflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno * ****************************************************************************/ diff --git a/include/nuttx/i2c.h b/include/nuttx/i2c.h index 8c053d820a..03c03bced6 100644 --- a/include/nuttx/i2c.h +++ b/include/nuttx/i2c.h @@ -228,9 +228,10 @@ struct i2c_ops_s { uint32_t (*setfrequency)(FAR struct i2c_dev_s *dev, uint32_t frequency); int (*setaddress)(FAR struct i2c_dev_s *dev, int addr, int nbits); - int (*write)(FAR struct i2c_dev_s *dev, const uint8_t *buffer, + int (*write)(FAR struct i2c_dev_s *dev, FAR const uint8_t *buffer, + int buflen); + int (*read)(FAR struct i2c_dev_s *dev, FAR uint8_t *buffer, int buflen); - int (*read)(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen); #ifdef CONFIG_I2C_TRANSFER int (*transfer)(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count); @@ -338,13 +339,25 @@ int up_i2cuninitialize(FAR struct i2c_dev_s *dev); int up_i2creset(FAR struct i2c_dev_s *dev); #endif -/************************************************************************************ +/**************************************************************************** * Name: i2c_writeread * * Description: - * Write to then read from the I2C device. + * Send a block of data on I2C using the previously, followed by restarted + * read access. This provides a convenient wrapper to the transfer function. * - ************************************************************************************/ + * Input Parameters: + * dev - Device-specific state data + * config - Described the I2C configuration + * wbuffer - A pointer to the read-only buffer of data to be written to device + * wbuflen - The number of bytes to send from the buffer + * rbuffer - A pointer to a buffer of data to receive the data from the device + * rbuflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ #ifdef CONFIG_I2C_TRANSFER int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, @@ -352,6 +365,54 @@ int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *conf FAR uint8_t *rbuffer, int rbuflen); #endif +/**************************************************************************** + * Name: i2c_write + * + * Description: + * Send a block of data on I2C. Each write operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this write completes. + * + * Input Parameters: + * dev - Device-specific state data + * config - Described the I2C configuration + * buffer - A pointer to the read-only buffer of data to be written to device + * buflen - The number of bytes to send from the buffer + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +#ifdef CONFIG_I2C_TRANSFER +int i2c_write(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR const uint8_t *buffer, int buflen); +#endif + +/**************************************************************************** + * Name: i2c_read + * + * Description: + * Receive a block of data from I2C using the previously selected I2C + * frequency and slave address. Each read operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this read completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to a buffer of data to receive the data from the device + * buflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +#ifdef CONFIG_I2C_TRANSFER +int i2c_read(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, + FAR uint8_t *buffer, int buflen); +#endif + #undef EXTERN #if defined(__cplusplus) } -- GitLab From efb56747429242b603bc956ed2f9a309125ae4fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 11:07:47 -0600 Subject: [PATCH 628/858] drivers/ioexpander/pca9555: Now uses i2c_read and i2c_write instead of I2C_READ and I2C_WERITE --- ChangeLog | 2 ++ drivers/ioexpander/pca9555.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1930acca6..41bf078fdc 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11372,4 +11372,6 @@ * drivers/i2c/i2c_writeread.c: Create a wrapper that uses I2C_TRANSFER to implement I2C_WRITEREAD functionality (2016-01-26). * I2C: Eliminate the I@C_WRITEREAD method (2016-01-26). + * drivers/i2c/i2c_read.c and i2c_write.c: Convert to use I2C_TRANSFER vs. + I2C_READ and I2C_WRITE which are not thread safe (2016-01-26). diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 5d3843d7ea..9f3fe58ebf 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -72,7 +72,9 @@ * Private Function Prototypes ****************************************************************************/ -static int pca9555_writeread(FAR struct pca9555_dev_s *pca, +static inline int pca9555_write(FAR struct pca9555_dev_s *pca, + FAR const uint8_t *wbuffer, int wbuflen); +static inline int pca9555_writeread(FAR struct pca9555_dev_s *pca, FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, int rbuflen); static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, @@ -129,6 +131,28 @@ static const struct ioexpander_ops_s g_pca9555_ops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: pca9555_writeread + * + * Description: + * Write to then read from the I2C device. + * + ****************************************************************************/ + +static inline int pca9555_write(FAR struct pca9555_dev_s *pca, + FAR const uint8_t *wbuffer, int wbuflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = pca->config->frequency; + config.address = pca->config->address; + config.addrlen = 7; + + return i2c_write(pca->i2c, &config, wbuffer, wbuflen); +} + /**************************************************************************** * Name: pca9555_writeread * @@ -194,7 +218,7 @@ static int pca9555_setbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, buf[1] &= ~(1 << pin); } - return I2C_WRITE(pca->i2c, buf, 2); + return pca9555_write(pca, buf, 2); } /**************************************************************************** @@ -418,7 +442,7 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, /* Now write back the new pins states */ buf[0] = addr; - return I2C_WRITE(pca->i2c, buf, 3); + return pca9555_write(pca, buf, 3); } /**************************************************************************** -- GitLab From 49f3f30be41e6d8b78386c62a82def0721f09aaa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 12:23:10 -0600 Subject: [PATCH 629/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 40aba37060..8697021d58 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 40aba37060aa2746c7a492045ae0b79d014afad2 +Subproject commit 8697021d58fc05c6d047e62230e1573a45fb969a diff --git a/configs b/configs index e569b357a2..0e5857f50f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e569b357a25df0f74730dfb4464f70a3acded6b2 +Subproject commit 0e5857f50fc0033b25013f5027f4c83db8106161 -- GitLab From 11dab241de3460f493f82770484c9e64a2d36726 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 13:04:12 -0600 Subject: [PATCH 630/858] SPI slave: Prototype for MCU-specific slave initialization function removed from spi_slave.h --- arch | 2 +- configs | 2 +- include/nuttx/spi/slave.h | 28 ++++++++-------------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/arch b/arch index 8697021d58..8e91d976b4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8697021d58fc05c6d047e62230e1573a45fb969a +Subproject commit 8e91d976b4390ccf28a5f03d3a29c25c2a8c0b29 diff --git a/configs b/configs index 0e5857f50f..bea7a607db 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0e5857f50fc0033b25013f5027f4c83db8106161 +Subproject commit bea7a607db96fad3dc7871f4ff12b5a37f44c1d3 diff --git a/include/nuttx/spi/slave.h b/include/nuttx/spi/slave.h index eb557252e6..b53ce28f51 100644 --- a/include/nuttx/spi/slave.h +++ b/include/nuttx/spi/slave.h @@ -269,14 +269,19 @@ * slave device and the SPI slave controller hardware. This interface * is implemented by the SPI slave device controller lower-half driver * and is provided to the the SPI slave device driver when that driver - * is initialized. That SPI slave device initialization function has - * the prototype: + * is initialized. That SPI slave device initialization function is + * unique to the SPI slave implementation. The prototype is probably + * something like: * - * FAR struct spi_sctrlr_s *up_spi_slave_initialize(int port); + * FAR struct spi_sctrlr_s *xyz_spi_slave_initialize(int port); * * Given an SPI port number, this function returns an instance of the * SPI slave controller interface. * + * The actual prototype and more detailed usage instructions should + * appear in a header file associated with the specific SPI slave + * implementation. + * * 2) struct spi_sdev_s: Defines the second interface between the SPI * slave device and the SPI slave controller hardware. This interface * is implemented by the SPI slave device. The slave device passes this @@ -504,23 +509,6 @@ extern "C" * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: up_spi_slave_initialize - * - * Description: - * Initialize the selected SPI port in slave mode. - * - * Input Parameter: - * port - Chip select number identifying the "logical" SPI port. Includes - * encoded port and chip select information. - * - * Returned Value: - * Valid SPI device structure reference on success; a NULL on failure - * - ****************************************************************************/ - -FAR struct spi_sctrlr_s *up_spi_slave_initialize(int port); - #undef EXTERN #if defined(__cplusplus) } -- GitLab From 695ad45d83e5f4c4a80aaa617c7021cdd64d9bd3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 15:23:01 -0600 Subject: [PATCH 631/858] Update ChangeLog --- ChangeLog | 6 ++++++ arch | 2 +- configs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41bf078fdc..d28d18a385 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11374,4 +11374,10 @@ * I2C: Eliminate the I@C_WRITEREAD method (2016-01-26). * drivers/i2c/i2c_read.c and i2c_write.c: Convert to use I2C_TRANSFER vs. I2C_READ and I2C_WRITE which are not thread safe (2016-01-26). + * SPI: Rename the STM32 up_spiinitialize() to stm32_spibus_initialize() + (2016-01-26). + * SPI: Rename the SAM up_spiinitialize() to stm32_spibus_initialize() + (2016-01-26). + * SPI: Rename the Tiva up_spiinitialize() to tiva_spibus_intialize() + (2016-01-26). diff --git a/arch b/arch index 8e91d976b4..0995e8c843 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8e91d976b4390ccf28a5f03d3a29c25c2a8c0b29 +Subproject commit 0995e8c84365688956c9f97b6c9139462fd16d81 diff --git a/configs b/configs index bea7a607db..4759f24031 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bea7a607db96fad3dc7871f4ff12b5a37f44c1d3 +Subproject commit 4759f240312ffd5c7e008017cb11aa733ed900b7 -- GitLab From ee2bb9739ee100305870507e528dab36b710e2af Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 16:27:40 -0600 Subject: [PATCH 632/858] Update ChangeLog --- ChangeLog | 8 +++++++- arch | 2 +- configs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d28d18a385..8396797ba7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11380,4 +11380,10 @@ (2016-01-26). * SPI: Rename the Tiva up_spiinitialize() to tiva_spibus_intialize() (2016-01-26). - + * SPI: Rename the PIC32MX/MZ up_spiinitialize() to pic32mx/mz_spibus_intialize() + (2016-01-26). + * SPI: Rename EFM32's efm32_spi_initialize to efm32_spibus_initialize() + for compatibility with these other changes (2016-01-26). + * SPI: Rename the KL up_spiinitialize() to kl_spibus_intialize() (2016-01-26). + * SPI: Rename the Kinetis up_spiinitialize() to kinetis_spibus_intialize() + (2016-01-26). diff --git a/arch b/arch index 0995e8c843..77d542fbfa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0995e8c84365688956c9f97b6c9139462fd16d81 +Subproject commit 77d542fbfa7d8e43669acd7438292935fff50be4 diff --git a/configs b/configs index 4759f24031..e4ed73d32b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4759f240312ffd5c7e008017cb11aa733ed900b7 +Subproject commit e4ed73d32bdc3211c0408bd03614113846a2d97d -- GitLab From 3dcafdb20a6725468f6ec3b2be20dc0a5757ba05 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 17:31:29 -0600 Subject: [PATCH 633/858] Update ChangeLog --- ChangeLog | 6 ++++++ arch | 2 +- configs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8396797ba7..1c079d2433 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11387,3 +11387,9 @@ * SPI: Rename the KL up_spiinitialize() to kl_spibus_intialize() (2016-01-26). * SPI: Rename the Kinetis up_spiinitialize() to kinetis_spibus_intialize() (2016-01-26). + * SPI: Rename the LPC31xx up_spiinitialize() to lpc31_spibus_intialize() + (2016-01-26). + * SPI: Rename the LPC17xx lpc17_spiinitialize() to lpc31_spibus_intialize() + (2016-01-26). + * SPI: Rename the LPC43xx up_spiinitialize() to lpc43_spibus_intialize() + (2016-01-26). diff --git a/arch b/arch index 77d542fbfa..cdbbd6417c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 77d542fbfa7d8e43669acd7438292935fff50be4 +Subproject commit cdbbd6417c82e7e8ee72ecd9d0b5bd93b886d41c diff --git a/configs b/configs index e4ed73d32b..168b4f43e1 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e4ed73d32bdc3211c0408bd03614113846a2d97d +Subproject commit 168b4f43e1986526bd3926f00d812f5d7dda414d -- GitLab From 4c3194f768eb49582bd41c84b628f3e9fbbfcae0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 26 Jan 2016 18:27:37 -0600 Subject: [PATCH 634/858] Fix incorrect working about 'Missing semicolon' from cnvwindeps.exe --- tools/cnvwindeps.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index 516f441b51..b26b3c9b67 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -213,10 +213,18 @@ int main(int argc, char **argv, char **envp) if (begin) { path = skip_spaces(next); + if (*path == '#') + { + /* Comment line */ + + puts(g_line); + break; + } + next = strchr(path, ':'); if (!next) { - fprintf(stderr, "%lu: Expected semicolon\n", g_lineno); + fprintf(stderr, "%lu: Expected colon\n", g_lineno); exit(EXIT_FAILURE); } -- GitLab From 7bf1db388c32fd15127342b9e4c0960a80167764 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 08:22:44 -0600 Subject: [PATCH 635/858] Update ChangeLog --- ChangeLog | 6 ++++++ Documentation | 2 +- arch | 2 +- configs | 2 +- tools/cnvwindeps.c | 5 ++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c079d2433..77e4b2836a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11393,3 +11393,9 @@ (2016-01-26). * SPI: Rename the LPC43xx up_spiinitialize() to lpc43_spibus_intialize() (2016-01-26). + * SPI: Rename the AVR up_spiinitialize() to avr_spibus_intialize() + (2016-01-27). + * SPI: Rename the LPC2148 up_spiinitialize() to lpc214x_spibus_intialize() + (2016-01-27). + * SPI: Rename the Calypso up_spiinitialize() to calypso_spibus_intialize() + (2016-01-27). diff --git a/Documentation b/Documentation index 8fab2a865d..413649314c 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 8fab2a865d3cc1496588c5a1227037dfb1f970e3 +Subproject commit 413649314c27feb6b72dcfee8504bfbb50547e73 diff --git a/arch b/arch index cdbbd6417c..c67b774ba2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cdbbd6417c82e7e8ee72ecd9d0b5bd93b886d41c +Subproject commit c67b774ba2b64ed3a73f3568d2de25ec4fc3fdfb diff --git a/configs b/configs index 168b4f43e1..b1fc7fe280 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 168b4f43e1986526bd3926f00d812f5d7dda414d +Subproject commit b1fc7fe2805af8d21edd02fcb6522aeb524a4edd diff --git a/tools/cnvwindeps.c b/tools/cnvwindeps.c index b26b3c9b67..7f71bda584 100644 --- a/tools/cnvwindeps.c +++ b/tools/cnvwindeps.c @@ -215,9 +215,9 @@ int main(int argc, char **argv, char **envp) path = skip_spaces(next); if (*path == '#') { - /* Comment line */ + /* The reset of the line is comment */ - puts(g_line); + puts(path); break; } @@ -302,4 +302,3 @@ int main(int argc, char **argv, char **envp) } #endif /* HOST_CYGWIN */ - -- GitLab From 439620ab69b1337abb86b488f956ecf6f734a9fe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 09:11:54 -0600 Subject: [PATCH 636/858] Update ChangeLog --- ChangeLog | 10 ++++++++++ arch | 2 +- configs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77e4b2836a..ab9fc4f453 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11399,3 +11399,13 @@ (2016-01-27). * SPI: Rename the Calypso up_spiinitialize() to calypso_spibus_intialize() (2016-01-27). + * SPI: Rename the ez80 up_spiinitialize() to ez80_spibus_intialize() + (2016-01-27). + * SPI: Rename the STR71xx up_spiinitialize() to str71_spibus_intialize() + (2016-01-27). + * SPI: Rename the i.MX1 up_spiinitialize() to imx_spibus_intialize() + (2016-01-27). + * SPI: Rename the LPC2378 up_spiinitialize() to lpc23_spibus_intialize() + (2016-01-27). + * SPI: Rename the M9S12 up_spiinitialize() to hcs12_spibus_intialize() + (2016-01-27). diff --git a/arch b/arch index c67b774ba2..a55bcb538a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c67b774ba2b64ed3a73f3568d2de25ec4fc3fdfb +Subproject commit a55bcb538ab7ea49c64c898f96d1b94cfb3e0aa8 diff --git a/configs b/configs index b1fc7fe280..b5e84e337c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b1fc7fe2805af8d21edd02fcb6522aeb524a4edd +Subproject commit b5e84e337c9dd2fdd722a6ea1411de3298d5bf50 -- GitLab From fd896330d8af6d6506281394d2d7694e1f03d512 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 09:27:56 -0600 Subject: [PATCH 637/858] Remove the final vestiges of up_spiinitialize() --- ChangeLog | 35 ++++++++++++++--------------------- arch | 2 +- drivers/mmcsd/mmcsd_spi.c | 5 +++-- include/nuttx/mmcsd.h | 5 +++-- include/nuttx/spi/spi.h | 36 ------------------------------------ 5 files changed, 21 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index ab9fc4f453..1218481579 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11387,25 +11387,18 @@ * SPI: Rename the KL up_spiinitialize() to kl_spibus_intialize() (2016-01-26). * SPI: Rename the Kinetis up_spiinitialize() to kinetis_spibus_intialize() (2016-01-26). - * SPI: Rename the LPC31xx up_spiinitialize() to lpc31_spibus_intialize() + * SPI: Rename the LPC31xx up_spiinitialize() to lpc31_spibus_intialize(), + Rename the LPC17xx lpc17_spiinitialize() to lpc31_spibus_intialize(), + Rename the LPC43xx up_spiinitialize() to lpc43_spibus_intialize() (2016-01-26). - * SPI: Rename the LPC17xx lpc17_spiinitialize() to lpc31_spibus_intialize() - (2016-01-26). - * SPI: Rename the LPC43xx up_spiinitialize() to lpc43_spibus_intialize() - (2016-01-26). - * SPI: Rename the AVR up_spiinitialize() to avr_spibus_intialize() - (2016-01-27). - * SPI: Rename the LPC2148 up_spiinitialize() to lpc214x_spibus_intialize() - (2016-01-27). - * SPI: Rename the Calypso up_spiinitialize() to calypso_spibus_intialize() - (2016-01-27). - * SPI: Rename the ez80 up_spiinitialize() to ez80_spibus_intialize() - (2016-01-27). - * SPI: Rename the STR71xx up_spiinitialize() to str71_spibus_intialize() - (2016-01-27). - * SPI: Rename the i.MX1 up_spiinitialize() to imx_spibus_intialize() - (2016-01-27). - * SPI: Rename the LPC2378 up_spiinitialize() to lpc23_spibus_intialize() - (2016-01-27). - * SPI: Rename the M9S12 up_spiinitialize() to hcs12_spibus_intialize() - (2016-01-27). + * SPI: Rename the AVR up_spiinitialize() to avr_spibus_intialize(), + Rename the LPC2148 up_spiinitialize() to lpc214x_spibus_intialize(), + Rename the Calypso up_spiinitialize() to calypso_spibus_intialize(), + Rename the ez80 up_spiinitialize() to ez80_spibus_intialize(), + Rename the STR71xx up_spiinitialize() to str71_spibus_intialize(), + Rename the i.MX1 up_spiinitialize() to imx_spibus_intialize(), + Rename the LPC2378 up_spiinitialize() to lpc23_spibus_intialize(), + Rename the M9S12 up_spiinitialize() to hcs12_spibus_intialize(), + Rename the x86 up_spiinitialize() to i486_spibus_intialize(), + Rename the z16f up_spiinitialize() to z16_spibus_intialize(). + up_spiinitialize() has been completely eliminated. (2016-01-27). diff --git a/arch b/arch index a55bcb538a..b2139bdcb7 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a55bcb538ab7ea49c64c898f96d1b94cfb3e0aa8 +Subproject commit b2139bdcb73ff4bacbbce121482285a7592d0bb9 diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index b9101fe1b1..9a44011f42 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -1903,8 +1903,9 @@ static void mmcsd_mediachanged(void *arg) * slotno - The slot number to use. This is only meaningful for * architectures that support multiple MMC/SD slots. This value must be * in the range {0, ..., CONFIG_MMCSD_NSLOTS}. - * spi - And instance of an SPI interface obtained by called - * up_spiinitialize() with the appropriate port number (see spi.h) + * spi - And instance of an SPI interface obtained by called the + * approprite xyz_spibus_initialize() function for the MCU "xyz" with + * the appropriate port number. * ****************************************************************************/ diff --git a/include/nuttx/mmcsd.h b/include/nuttx/mmcsd.h index 29f256d82d..8d9c54b471 100644 --- a/include/nuttx/mmcsd.h +++ b/include/nuttx/mmcsd.h @@ -92,8 +92,9 @@ int mmcsd_slotinitialize(int minor, FAR struct sdio_dev_s *dev); * slotno - The slot number to use. This is only meaningful for architectures * that support multiple MMC/SD slots. This value must be in the range * {0, ..., CONFIG_MMCSD_NSLOTS}. - * spi - And instance of an SPI interface obtained by called - * up_spiinitialize() with the appropriate port number (see spi.h) + * spi - And instance of an SPI interface obtained by called the + * approprite xyz_spibus_initialize() function for the MCU "xyz" with + * the appropriate port number. * ****************************************************************************/ diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 167da6af4c..498fb294e4 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -479,42 +479,6 @@ extern "C" #define EXTERN extern #endif -/**************************************************************************** - * Name: up_spiinitialize - * - * Description: - * Initialize the selected SPI port in master mode. - * - * This is a generic prototype for the SPI initialize logic. Specific - * architectures may support different SPI initialization functions if, - * for example, those architectures support multiple, incompatible SPI - * implementations. In any event, the prototype of those architecture- - * specific initialization functions should be the same as - * up_spiinitialize() - * - * As an example, the LPC17xx family supports an SPI block and several SSP - * blocks that may be programmed to support the SPI function. In this - * case, the LPC17xx architecture supports these two initialization - * functions: - * - * FAR struct spi_dev_s *lpc17_spiinitialize(int port); - * FAR struct spi_dev_s *lpc17_sspinitialize(int port); - * - * Another example would be the STM32 families that support both SPI - * blocks as well as USARTs that can be configured to perform the SPI - * function as well (the STM32 USARTs do not support SPI as of this - * writing). - * - * Input Parameter: - * Port number (for hardware that has multiple SPI interfaces) - * - * Returned Value: - * Valid SPI device structure reference on success; a NULL on failure - * - ****************************************************************************/ - -FAR struct spi_dev_s *up_spiinitialize(int port); - #undef EXTERN #if defined(__cplusplus) } -- GitLab From 7d6c2d150d3fd842124c33dc72d8eee3e6edb9d5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 13:42:39 -0600 Subject: [PATCH 638/858] fs/vfs/fs_poll.c: Fix handling of sem_tickwait() return value sem_tickwait() does not return an -1+errno, it returns a negated errno value. Noted by Freddie Chopin. --- ChangeLog | 3 +++ configs | 2 +- fs/vfs/fs_poll.c | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1218481579..0772271d3e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11402,3 +11402,6 @@ Rename the x86 up_spiinitialize() to i486_spibus_intialize(), Rename the z16f up_spiinitialize() to z16_spibus_intialize(). up_spiinitialize() has been completely eliminated. (2016-01-27). + * fs/vfs/fs_poll.c: Fix handling of sem_tickwait() return value + sem_tickwait() does not return an -1+errno, it returns a negated + errno value. Noted by Freddie Chopin." diff --git a/configs b/configs index b5e84e337c..b7138e5722 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b5e84e337c9dd2fdd722a6ea1411de3298d5bf50 +Subproject commit b7138e5722f34d752d80d2ea5e8de8f2f06497fe diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 2385f85a25..668765420d 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -329,6 +329,7 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) { sem_t sem; int count = 0; + int err; int ret; sem_init(&sem, 0, 0); @@ -354,20 +355,14 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) ret = sem_tickwait(&sem, clock_systimer(), MSEC2TICK(timeout)); if (ret < 0) { - int err = get_errno(); - - if (err == ETIMEDOUT) + if (ret == -ETIMEDOUT) { /* Return zero (OK) in the event of a timeout */ ret = OK; } - else - { - /* EINTR is the only other error expected in normal operation */ - ret = -err; - } + /* EINTR is the only other error expected in normal operation */ } } else @@ -379,9 +374,15 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) /* Teardown the poll operation and get the count of events. Zero will be * returned in the case of a timeout. + * + * Preserve ret, if negative, since it holds the result of the wait. */ - ret = poll_teardown(fds, nfds, &count, ret); + err = poll_teardown(fds, nfds, &count, ret); + if (err < 0 && ret == OK) + { + ret = err; + } } sem_destroy(&sem); -- GitLab From f9e45122d42e1f49c934a21df8426b49909cb90d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 13:43:29 -0600 Subject: [PATCH 639/858] Remove a dangling space --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0772271d3e..7e6c467c70 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11402,6 +11402,6 @@ Rename the x86 up_spiinitialize() to i486_spibus_intialize(), Rename the z16f up_spiinitialize() to z16_spibus_intialize(). up_spiinitialize() has been completely eliminated. (2016-01-27). - * fs/vfs/fs_poll.c: Fix handling of sem_tickwait() return value + * fs/vfs/fs_poll.c: Fix handling of sem_tickwait() return value sem_tickwait() does not return an -1+errno, it returns a negated errno value. Noted by Freddie Chopin." -- GitLab From c1d4ce01e05be181f22cdaac03f56adc96b823ba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Jan 2016 16:42:01 -0600 Subject: [PATCH 640/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index b2139bdcb7..505399a54c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b2139bdcb73ff4bacbbce121482285a7592d0bb9 +Subproject commit 505399a54c301298ec308cefcc07dd7668b6df92 diff --git a/configs b/configs index b7138e5722..e643990c17 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b7138e5722f34d752d80d2ea5e8de8f2f06497fe +Subproject commit e643990c17347abf015d66bd3d832acb9d5e260b -- GitLab From 4a59ff34e95f736566119475d884e3f9022341be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Jan 2016 09:53:47 -0600 Subject: [PATCH 641/858] Update submodules --- arch | 2 +- configs | 2 +- fs/vfs/fs_poll.c | 2 +- tools/testbuild.sh | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 505399a54c..39dca5d1dc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 505399a54c301298ec308cefcc07dd7668b6df92 +Subproject commit 39dca5d1dc63ca02a7f897ff7de0bb03fee86a60 diff --git a/configs b/configs index e643990c17..2d69d8ab99 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e643990c17347abf015d66bd3d832acb9d5e260b +Subproject commit 2d69d8ab99187e4270bb4b4bd1d61d5324b81916 diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 668765420d..2910b30551 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -379,7 +379,7 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) */ err = poll_teardown(fds, nfds, &count, ret); - if (err < 0 && ret == OK) + if (err < 0 && ret >= 0) { ret = err; } diff --git a/tools/testbuild.sh b/tools/testbuild.sh index 594c58db2f..0490b5d781 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -44,9 +44,9 @@ unset testfile function showusage { echo "" echo "USAGE: $progname [-w|l] [-c|n] [-s] " - echo "USAGE: $progname -h" + echo " $progname -h" echo "" - echo "where" + echo "Where:" echo " -w|l selects Windows (w) or Linux (l). Default: Linux" echo " -c|n selects Windows native (n) or Cygwin (c). Default Cygwin" echo " -s Use C++ unsigned long size_t in new operator. Default unsigned int" -- GitLab From eb53d0158e712d4f3c2af5573b0ed0f57ed2c203 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Jan 2016 11:36:36 -0600 Subject: [PATCH 642/858] Prep for NuttX-7.14 release --- ChangeLog | 20 ++-- Documentation | 2 +- ReleaseNotes | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e6c467c70..7083c3f5f3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11206,12 +11206,12 @@ * configs/samv7-xult/: If Tickless mode is selected then enable PCK6 as a timer/counter clock source (2015-12-04). -7.14 2015-xx-xx Gregory Nutt +7.14 2016-01-28 Gregory Nutt * arch/arm/src/samv7: Port the TRNG driver from the SAMA5D3/4 to the SAMV7 (2015-12-06). * arch/arm/src/samv7: Port the WDT driver from the SAMA5D3/4 to the - SAMV7 (s015-12-06). + SAMV7 (2015-12-06). * arch/arm/src/samv7: Add an RSWDT driver (2015-12-06). * drivers/net/telnet.c: Move the Telnet driver from apps/netutils/telnetd to drivers/net. It is a driver a belongs in the OS. There are still @@ -11249,7 +11249,7 @@ (2015-12-22). * sys/time.h: Add timeradd(), timersub(), timerclear(), timerisset(), and timercmp() as macros. These are non-POSIX interfaces, but - included in most BSD deriviatives, included Linux. From Manuel Stühn + included in most BSD deriviatives, including Linux. From Manuel Stühn (2015-12-23). * arch/arm/src/stm32: Add timer input capture driver. From Pierre-Noel Bouteville (2015-12-24). @@ -11264,7 +11264,7 @@ FLAT build. See the top-level TODO file for additional details (2015-12-30). * include/nuttx/compiler.h, include/nuttx/streams.h include/stdio.h - include/syslog.h libc/stdio/, and libc/syslog: ntroduce support for + include/syslog.h libc/stdio/, and libc/syslog: introduce support for Atmel toolchain in-flash strings. Atmel toolchain AVR compiler provides a transparent in-flash object support using __flash and __memx symbols. The former indicates to compiler that this is a flash- @@ -11324,13 +11324,13 @@ * arch/arm/src/stm32/stm32_otgfs/hs/host.c: Fix some backward arguments to stm32_putreg(). Note by Hang Xu (2016-01-18). * include/nuttx/can.h and several CAN drivers: Add more extensive - error reporting capaibility to the CAN interferace. From Frank - Benkert (21016-01-18). + error reporting capaibility to the CAN interface. From Frank + Benkert (2016-01-18). * libc/misc/lib_tea.h and include/nuttx/crypto/tea.h: Add an implementation of the Tiny Encryption Algorithm (2016-01-19). * sim/include: Now supports a customizable startup script with a read-only passwd file (2016-01-20). - * sim/nsh: Uses the custom start up script, includes hoks for + * sim/nsh: Uses the custom start up script, includes hooks for an MOTD message. (2016-01-20). * include/clock.h and lots of other files: If the 64-bit timer is selected, then use it whenever clock_systimer() is called rather @@ -11371,7 +11371,7 @@ the former is thread safe while the latter is deprecated (2016-01-26). * drivers/i2c/i2c_writeread.c: Create a wrapper that uses I2C_TRANSFER to implement I2C_WRITEREAD functionality (2016-01-26). - * I2C: Eliminate the I@C_WRITEREAD method (2016-01-26). + * I2C: Eliminate the I2C_WRITEREAD method (2016-01-26). * drivers/i2c/i2c_read.c and i2c_write.c: Convert to use I2C_TRANSFER vs. I2C_READ and I2C_WRITE which are not thread safe (2016-01-26). * SPI: Rename the STM32 up_spiinitialize() to stm32_spibus_initialize() @@ -11404,4 +11404,6 @@ up_spiinitialize() has been completely eliminated. (2016-01-27). * fs/vfs/fs_poll.c: Fix handling of sem_tickwait() return value sem_tickwait() does not return an -1+errno, it returns a negated - errno value. Noted by Freddie Chopin." + errno value. Noted by Freddie Chopin. + +7.15 2016-xx-xx Gregory Nutt diff --git a/Documentation b/Documentation index 413649314c..b7d0b9c21a 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 413649314c27feb6b72dcfee8504bfbb50547e73 +Subproject commit b7d0b9c21a8f8990810c2db4ff5dbd1b747e3d03 diff --git a/ReleaseNotes b/ReleaseNotes index b68cdb7fa4..376f4e4f6d 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -10191,3 +10191,259 @@ detailed bugfix information): will not work in an environment where there are multiple NSH sessions. The I/O buffer must, instead, be a part part of the session-specific data defined in nsh_console.h. + +NuttX-7.14 Release Notes +------------------------ + +The 114th release of NuttX, Version 7.14, was made on January 28, 2016, +and is available for download from the Bitbucket.org website. Note +that release consists of two tarballs: nuttx-7.14.tar.gz and +apps-7.14.tar.gz. These are available from: + + https://bitbucket.org/patacongo/nuttx/downloads + https://bitbucket.org/nuttx/apps/downloads + +Both may be needed (see the top-level nuttx/README.txt file for build +information). + +Additional new features and extended functionality: + + * Core OS: + + - modules: Add support for kernel modules: insmod, rmmod, support + functions. procfs support for user lsmod functioniality. + - SIGEV_THREAD: Add support for the SIGEV_THREAD notification method + in struct sigevent. This initial implementation will only work in + the FLAT build since it utilizes the work queue for signal + callbacks. See the top-level TODO file for additional details. + - 64-Bit Timer: If the 64-bit timer is selected, then use it whenever + clock_systimer() is called rather then chopping the 64-bit timer + down to 32-bits. Add a new type, systime_t to represent the 32- or + 64-bit system timer. This eliminates clock_systimer32() and + clock_systime64(); there is now only clock_systimer(). + + * Common Device Drivers: + + - Telnet Driver: Move the Telnet driver from apps/ to + nuttx/drivers/net. It is a driver a belongs in the OS. Now works + like the loop device: A new interface called telnet_initialize() + registers a telnet session "factory" device at /dev/telnet. Via + ioctl, the factory device can create instances of the telnet + character devices at /dev/telnetN to support Telnet sessions. + - PCA9635PW: Add a driver for the PCA9635PW I2C LED driver IC which + can be used to control the intensity of up to 16 LEDs. From + Alexander Entinger. + - MCP9844: Driver for the MCP9844 I2C digital temperature sensor with + a selectable resolution. From Alexander Entinger. + - PN532: Add driver for the NXP PN532 NFC-chip. From Janne Rosberg + and others at Offcode Ltd. + - LSM9DS1: Add driver for the STMicro LSM9DS1 chip. The LSM9DS1 is a + system-in-package featuring a 3D digital linear acceleration sensor, + a 3D digital angular rate sensor, and a 3D digital magnetic sensor. + From Paul Alexander Patience. + - CAN Interface: Add more extensive error reporting capaibility to + the CAN interface definitions. From Frank Benkert. + - SPI Interface: Add an optional hwfeatures() method to the SPI + interface. + + * Simulation Platform: + + - NSH configuration uses the custom start up scriptwith a read-only + passwd file. Includes hooks for an MOTD message. + + * ARMv7-R + + - ARMv7-R: Add basic architecture support for the ARMv7-R processor + family. + + * Atmel AVR: + + - Atmega2560: Add support for the Atmega2560. From Dimitry Kloper. + - debug.h: Add an AVR-specific header file used when the AVR MEMX + pointer is used. From Dimitri Kloper. + + * Atmel AVR Boards: + + - Arduino-Mega2560: Add support for the Arduino-Mega2560. From + Dimitry Koper. + + * Atmel SAMV7 Drivers: + + - Port the TRNG driver from the SAMA5D3/4 to the SAMV7. + - Port the WDT driver from the SAMA5D3/4 to the SAMV7. + - Add an RSWDT driver. + + * Atmel SAMV7 Boards: + + - SAMV71-XULT: Add configuration for testing OS modules. + + * Freescale Kinetis: + + - MK60N512VLL100: Add support for the MK60N512VLL100 Kinetis part. + From Andrew Webster. + + * Freescale Kinetis Boards: + + - ENET: Numerous updates to the Kinetis ENET driver. That driver is + now functional. From Andrew Webster. + + * NXP LPC43xx Boards: + + - WaveShare LPC4337-WS: Support for the WaveShare LPC4337-WS board. + From Lok Tep. + + * STMicro STM32 Drivers: + + - Timer Capture: Add timer input capture driver. From Pierre-Noel + Bouteville. + + * STMicro STM32 Boards: + + - Olimex STM32 H407: Added a port to the Olimex STM32 H407 board. + This board features the STMicro STM32F407ZGT6 (144 pins). + Contributed by Neil Hancock. + + * TI TMS550 Boards: + + - TI LaunchXL-TMS57004: Add basic board support for TI LaunchXL- + TMS57004. Still a work in progress. + + * C Library/Header Files: + + - sys/time.h: Add timeradd(), timersub(), timerclear(), timerisset(), + and timercmp() as macros. These are non-POSIX interfaces, but + included in most BSD deriviatives, including Linux. From Manuel St??. + - AVR support: Introduce support for Atmel toolchain in-flash strings. + Atmel toolchain AVR compiler provides a transparent in-flash object + support using __flash and __memx symbols. The former indicates to + compiler that this is a flash-based object. The later used with + pointer indicates that the referenced object may reside either in + flash or in RAM. The compiler automatically makes 32-bit pointer + with flag indicating whether referenced object is in flash or RAM + and generates code to access either in run-time. Thus, any function + hat accepts __memx object can transparently work with RAM and flash + objects. + For platforms with a Harvard architecture and a very small RAM like + AVR this allows to move all constant strings used in trace messages + to flash in the instruction address space, releasing resources for + other things. This change introduces IOBJ and IPTR type qualifiers. + The 'I' indicates that the object may lie in instruction space on a + Harvard architecture machine. For platforms that do not have __flash + and __memx or similar symbols IOBJ and IPTR are empty, making the + types equivalent to, for example, 'const char' and 'const char*'. + For Atmel compiler these will become 'const __flash char' and + 'const __memx char*'. All printf() functions and syslog() functions + are changed so that the qualifier is used with the format parameter. + From Dimitry Kloper. + - debug.h: Add configuration to support an architecture-specific + debug.h header file. From Dimitri Kloper. + - netdb: Add support for the use of a DNS resolver file like + /etc/resolv.conf. + - TEA: Add an implementation of the Tiny Encryption Algorithm. + - math32.h: Add some utilities to support 64-bit arithmetic + operations for platforms that do not support long long types. + + * Tools: + + - tools/cnvwindeps.c: Add a tool that will convert paths in + dependencies generated by a Windows compiler so that they can be + used with the Cygwin make. + - tools/mkwindeps.sh: A script that coordinates use of cnvwindeps.exe. + Dependencies now work on the Cygwin platform when using a Windows + ative toolchain. + + * Applications: NSH + + - Module Commands: Add module commands: insmod, rmmod, and lsmod. + - Time Command: Add a 'time' command that may be used to time the + execution of other commands. + - Password Commands: Add useradd, userdel, and passwd commands. + - MOTD: Now supports a Message of the Day (MOTD) that will be + presented after the NSH greeting. + - Session Logins: All sessions may be protected with logins using the + encrypted password in /etc/passwd. + - Extended Logins. Added optional platform-specific function to + perform password verification and optional delay after each failed + login attempt. + + * Applications: apps/fsutils: + + - apps/fsutils/passwd: Utility library for accessing a password file + like /etc/passwd. + + * Applications: apps/netutils: + + - apps/netutils/telnetd: Now creates Telnet sessions by opening a new + factory device at /dev/telnet and then using ioctl calls to create + the session character drivers at /dev/telnetN. + - apps/netutils/netlib: Add netlib_get_dripv4addr() and + netlib_get_ipv4netmask(). From Pelle Windestam. + + * Applications: apps/examples: + + - apps/examples/module: Add a test harness for verifying NuttX kernel + modules. + - apps/examples/pca9635: Add a simple test of PCA9635PW PWM LED driver. + From Alan Carvalho de Assis. + - apps/examples/ostest: Add a test of POSIX timers using SIGEV_THREAD. + +Bugfixes. Only the most critical bugfixes are listed here (see the +ChangeLog for the complete list of bugfixes and for additional, more +detailed bugfix information): + + * Core OS: + + - pthreads: CRITICAL BUGFIX: Logic was wiping out the indication that + of the type of a pthread. Hence, it could be confused as a task. + - waitpid: CRITICAL BUGFIX. Add a reference count to prevent waitpid + from using stale memory released by the waited-for task group. + - clock_systimespec(): Fix an error in a time conversion. + + * File System/Block Drivers: + + - poll(): Fix handling of sem_tickwait() return value sem_tickwait() + does not return an -1+errno, it returns a negated errno value. + Noted by Freddie Chopin. + + * Common Drivers: + + - TUN Driver: Fix a compile time error in the TUN driver. From + Vladimir Komendantskiy. + - USB Host HID Parser: Wrong size used in memcpy(). From Hang Xu. + - PCA9555: Fixed a bug in the function pca9555_setbit which occurs if + someone tries to set one of the pins 8-15. The problem is that + after the check if the pin is greater than 7 the variable addr is + incremented and used in the Call I2C_WRITEREAD. But later in the + call to the I2C_WRITE buf[0] is used as address but this address is + not incremented as it should be. Note address does mean the address + to the register in the ioexpander and not the I2C address. From + Stefan Kolb. + + * Networking: + + - TCP/IOB: Numerous fixes, mostly relate to TCP and IOB buffering + and race conditions. These were necessary for for the NuttX + networking later to be stable in some stress testing. From Andrew + Webster. + + * Atmel SAMV7 Drivers: + + - USBHS Device: In USBHS device driver, fix check if zero length + packet is needed. + + * STMicro STM32 Drivers: + + - OTG FS Host: Fix some backward arguments to stm32_putreg(). Note + by Hang Xu. + + * Tools: + + - tools/mkdeps.c: Extended/fixed support for --winpath option. + Dependencies now work under Cygwin with a native Windows toolchain. + + * Build System: + + - apps/platform/Makefile: Use a relative path to the board directory + link rather than the absolute path. For Cygwin, the absolute would + would need converted with cygpath. But just using the relative path + is a simpler solution. -- GitLab From da5115e3e6b4e80d18795445e36513660178767a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Jan 2016 16:38:54 -0600 Subject: [PATCH 643/858] Correct an error in timer_created intoduced when SIGEV_THREAD support was added. --- configs | 2 +- sched/timer/timer_create.c | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/configs b/configs index 2d69d8ab99..94cc2c17de 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 2d69d8ab99187e4270bb4b4bd1d61d5324b81916 +Subproject commit 94cc2c17de89faf152b3388349092173f0d165b0 diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 0d5ce1b1e1..33d1e01874 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -1,7 +1,7 @@ /******************************************************************************** * sched/timer/timer_create.c * - * Copyright (C) 2007-2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,18 +52,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - /******************************************************************************** * Private Functions ********************************************************************************/ @@ -213,13 +201,31 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer ret->pt_delay = 0; ret->pt_wdog = wdog; + /* Was a struct sigevent provided? */ + if (evp) { + /* Yes, copy the entire struct sigevent content */ + memcpy(&ret->pt_event, evp, sizeof(struct sigevent)); } else { - memset(&ret->pt_event, 0, sizeof(struct sigevent)); + /* "If the evp argument is NULL, the effect is as if the evp argument + * pointed to a sigevent structure with the sigev_notify member + * having the value SIGEV_SIGNAL, the sigev_signo having a default + * signal number, and the sigev_value member having the value of the + * timer ID." + */ + + ret->pt_event.sigev_notify = SIGEV_SIGNAL; + ret->pt_event.sigev_signo = SIGALRM; + ret->pt_event.sigev_value.sival_ptr = ret; + +#ifdef CONFIG_SIG_EVTHREAD + ret->pt_event.sigev_value.sigev_notify_function = NULL; + ret->pt_event.sigev_value.sigev_notify_attributes = NULL; +#endif } /* Return the timer */ -- GitLab From 61819c0e3e1e76c78248e640b7438d5ece7be028 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Jan 2016 16:50:20 -0600 Subject: [PATCH 644/858] Fix a typo in last commit that was not noticed until CONFIG_SIG_EVTHREAD was enabled --- sched/timer/timer_create.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 33d1e01874..9f73875a17 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -218,13 +218,13 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer * timer ID." */ - ret->pt_event.sigev_notify = SIGEV_SIGNAL; - ret->pt_event.sigev_signo = SIGALRM; - ret->pt_event.sigev_value.sival_ptr = ret; + ret->pt_event.sigev_notify = SIGEV_SIGNAL; + ret->pt_event.sigev_signo = SIGALRM; + ret->pt_event.sigev_value.sival_ptr = ret; #ifdef CONFIG_SIG_EVTHREAD - ret->pt_event.sigev_value.sigev_notify_function = NULL; - ret->pt_event.sigev_value.sigev_notify_attributes = NULL; + ret->pt_event.sigev_notify_function = NULL; + ret->pt_event.sigev_notify_attributes = NULL; #endif } -- GitLab From dc8c14aa5302fbec2566a998f3a23e7f029412b1 Mon Sep 17 00:00:00 2001 From: Entinger Alexander Date: Fri, 29 Jan 2016 07:41:23 -0600 Subject: [PATCH 645/858] Driver for the 24-Bit Differential Input ADC ADS1242 that communicates via SPI with a MCU. Reading the ADC conversion result as well as configuring the ADC, setting the input channel, etc. is implemented via ioctl calls. However, it does not yet implement the standard ADC interface. --- arch | 2 +- drivers/analog/Kconfig | 7 + drivers/analog/ads1242.c | 584 +++++++++++++++++++++++++++++++++ include/nuttx/analog/ads1242.h | 202 ++++++++++++ 4 files changed, 794 insertions(+), 1 deletion(-) create mode 100644 drivers/analog/ads1242.c create mode 100644 include/nuttx/analog/ads1242.h diff --git a/arch b/arch index 39dca5d1dc..69b5f95ae5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 39dca5d1dc63ca02a7f897ff7de0bb03fee86a60 +Subproject commit 69b5f95ae5c4b953be4b6e1598a4e71f794afe52 diff --git a/drivers/analog/Kconfig b/drivers/analog/Kconfig index 1bbc219f81..3245cc7c40 100644 --- a/drivers/analog/Kconfig +++ b/drivers/analog/Kconfig @@ -43,6 +43,13 @@ config ADS1255_FREQUENCY endif # ADC_ADS125X +config ADC_ADS1242 + bool "ADS1242" + default n + select SPI + ---help--- + Enable driver support for the ADS1242 24-Bit SPI powered ADC. + config ADC_PGA11X bool "TI PGA112/3/6/7 support" default n diff --git a/drivers/analog/ads1242.c b/drivers/analog/ads1242.c new file mode 100644 index 0000000000..6c80df4d2a --- /dev/null +++ b/drivers/analog/ads1242.c @@ -0,0 +1,584 @@ +/**************************************************************************** + * drivers/sensors/ads1242.c + * Character driver for the MCP3426 Differential Input 16 Bit Delta/Sigma ADC + * + * Copyright (C) 2015 DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS1242) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ads1242_dev_s +{ + FAR struct spi_dev_s *spi; /* Pointer to the SPI instance */ + uint32_t osc_period_us; /* Period of the oscillator attached to the ADS1242 in us */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* SPI Helpers */ + +static void ads1242_reset(FAR struct ads1242_dev_s *dev); +static void ads1242_performSelfGainCalibration( + FAR struct ads1242_dev_s *dev); +static void ads1242_performSelfOffsetCalibration( + FAR struct ads1242_dev_s *dev); +static void ads1242_performSystemOffsetCalibration( + FAR struct ads1242_dev_s *dev); +static void ads1242_read_conversion_result(FAR struct ads1242_dev_s *dev, + FAR uint32_t *conversion_result); + +static void ads1242_write_reg(FAR struct ads1242_dev_s *dev, + uint8_t const reg_addr, uint8_t const reg_value); +static void ads1242_read_reg(FAR struct ads1242_dev_s *dev, + uint8_t const reg_addr, FAR uint8_t *reg_value); + +static void ads1242_set_gain(FAR struct ads1242_dev_s *dev, + ADS1242_GAIN_SELECTION const gain_selection); +static void ads1242_set_positive_input(FAR struct ads1242_dev_s *dev, + ADS1242_POSITIVE_INPUT_SELECTION const pos_in_sel); +static void ads1242_set_negative_input(FAR struct ads1242_dev_s *dev, + ADS1242_NEGATIVE_INPUT_SELECTION const neg_in_sel); +static bool ads1242_is_data_ready(FAR struct ads1242_dev_s *dev); + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) +static void ads1242_print_regs(FAR struct ads1242_dev_s *dev, char const *msg); +#endif / defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) */ + +/* Character driver methods */ + +static int ads1242_open(FAR struct file *filep); +static int ads1242_close(FAR struct file *filep); +static ssize_t ads1242_read(FAR struct file *, FAR char *, size_t); +static ssize_t ads1242_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int ads1242_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_ads1242_fops = +{ + ads1242_open, + ads1242_close, + ads1242_read, + ads1242_write, + NULL, + ads1242_ioctl +#ifndef CONFIG_DISABLE_POLL + , NULL +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ads1242_reset + ****************************************************************************/ + +static void ads1242_reset(FAR struct ads1242_dev_s *dev) +{ + SPI_SELECT(dev->spi, 0, true); /* Set nADC_SPI_CS to low which selects the ADS1242 */ + + SPI_SEND(dev->spi, ADS1242_CMD_RESET);/* Issue reset command */ + + SPI_SELECT(dev->spi, 0, false); /* Set nADC_SPI_CS to high which deselects the ADS1242 */ + + up_mdelay(100); /* Wait a little so the device has time to perform a proper reset */ +} + +/**************************************************************************** + * Name: ads1242_performSelfGainCalibration + ****************************************************************************/ + +static void ads1242_performSelfGainCalibration(FAR struct ads1242_dev_s *dev) +{ + SPI_SELECT(dev->spi, 0, true); + + SPI_SEND(dev->spi, ADS1242_CMD_SELF_GAIN_CALIB); + + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_performSelfOffsetCalibration + ****************************************************************************/ + +static void ads1242_performSelfOffsetCalibration(FAR struct ads1242_dev_s *dev) +{ + SPI_SELECT(dev->spi, 0, true); + + SPI_SEND(dev->spi, ADS1242_CMD_SELF_OFFSET_CALIB); + + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_performSystemOffsetCalibration + ****************************************************************************/ + +static void +ads1242_performSystemOffsetCalibration(FAR struct ads1242_dev_s *dev) +{ + SPI_SELECT(dev->spi, 0, true); + + SPI_SEND(dev->spi, ADS1242_CMD_SYSTEM_OFFSET_CALIB); + + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_read_conversion_result + ****************************************************************************/ + +static void ads1242_read_conversion_result(FAR struct ads1242_dev_s *dev, + FAR uint32_t *conversion_result) +{ + SPI_SELECT(dev->spi, 0, true); + + SPI_SEND(dev->spi, ADS1242_CMD_READ_DATA); + + /* Delay between last SCLK edge for DIN and first SCLK edge for DOUT: + * RDATA, RDATAC, RREG, WREG: Min 50 x tOSC Periods + */ + + up_udelay(50 * dev->osc_period_us); + + *conversion_result = 0; + + /* 1st Byte = MSB + * 2nd Byte = Mid-Byte + * 3rd Byte = LSB + */ + + *conversion_result |= ((uint32_t)(SPI_SEND(dev->spi, 0xFF))) << 16; + *conversion_result |= ((uint32_t)(SPI_SEND(dev->spi, 0xFF))) << 8; + *conversion_result |= ((uint32_t)(SPI_SEND(dev->spi, 0xFF))) << 0; + + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_write_reg + * + * Description: + * Write to the registers starting with the register address specified as + * part of the instruction. The number of registers that will be written + * is one plus the value of the second byte. + * + ****************************************************************************/ + +static void ads1242_write_reg(FAR struct ads1242_dev_s *dev, + uint8_t const reg_addr, uint8_t const reg_value) +{ + SPI_SELECT(dev->spi, 0, true); + SPI_SEND(dev->spi, ADS1242_CMD_WRITE_REGISTER | reg_addr); + SPI_SEND(dev->spi, 0x00); /* Write 1 Byte */ + SPI_SEND(dev->spi, reg_value); + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_read_reg + * + * Description: + * Output the data from up to 16 registers starting with the register + * address specified as part of the instruction. The number of registers + * read will be one plus the second byte count. If the count exceeds the + * remaining registers, the addresses wrap back to the beginning. + * + ****************************************************************************/ + +static void ads1242_read_reg(FAR struct ads1242_dev_s *dev, + uint8_t const reg_addr, FAR uint8_t *reg_value) +{ + SPI_SELECT(dev->spi, 0, true); + SPI_SEND(dev->spi, ADS1242_CMD_READ_REGISTER | reg_addr); + SPI_SEND(dev->spi, 0x00); /* Read 1 Byte */ + + /* Delay between last SCLK edge for DIN and first SCLK edge for DOUT: + * RDATA, RDATAC, RREG, WREG: Min 50 x tOSC Periods + */ + + up_udelay(50 * dev->osc_period_us); + + *reg_value = SPI_SEND(dev->spi, 0xFF); + + SPI_SELECT(dev->spi, 0, false); +} + +/**************************************************************************** + * Name: ads1242_set_gain + ****************************************************************************/ + +static void ads1242_set_gain(FAR struct ads1242_dev_s *dev, + ADS1242_GAIN_SELECTION const gain_selection) +{ + uint8_t setup_reg_value = 0; + + ads1242_read_reg(dev, ADS1242_REG_SETUP, &setup_reg_value); + setup_reg_value &= ~(ADS1242_REG_SETUP_BIT_PGA2 | + ADS1242_REG_SETUP_BIT_PGA1 | + ADS1242_REG_SETUP_BIT_PGA0); + setup_reg_value |= (uint8_t)(gain_selection); + ads1242_write_reg(dev, ADS1242_REG_SETUP, setup_reg_value); + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) + ads1242_print_regs(dev, "ads1242_set_gain"); +#endif + + /* It is necessary to perform a offset calibration after setting the gain */ + + ads1242_performSelfOffsetCalibration(dev); +} + +/**************************************************************************** + * Name: ads1242_set_positive_input + ****************************************************************************/ + +static void ads1242_set_positive_input(FAR struct ads1242_dev_s *dev, + ADS1242_POSITIVE_INPUT_SELECTION const pos_in_sel) +{ + uint8_t mux_reg_value = 0; + + ads1242_read_reg(dev, ADS1242_REG_MUX, &mux_reg_value); + mux_reg_value &= ~(ADS1242_REG_MUX_BIT_PSEL3 | ADS1242_REG_MUX_BIT_PSEL2 | + ADS1242_REG_MUX_BIT_PSEL1 | ADS1242_REG_MUX_BIT_PSEL0); + mux_reg_value |= (uint8_t)(pos_in_sel); + ads1242_write_reg(dev, ADS1242_REG_MUX, mux_reg_value); + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) + ads1242_print_regs(dev, "ads1242_set_positive_input"); +#endif +} + +/**************************************************************************** + * Name: ads1242_set_negative_input + ****************************************************************************/ + +static void ads1242_set_negative_input(FAR struct ads1242_dev_s *dev, + ADS1242_NEGATIVE_INPUT_SELECTION const neg_in_sel) +{ + uint8_t mux_reg_value = 0; + + ads1242_read_reg(dev, ADS1242_REG_MUX, &mux_reg_value); + mux_reg_value &= ~(ADS1242_REG_MUX_BIT_NSEL3 | ADS1242_REG_MUX_BIT_NSEL2 | + ADS1242_REG_MUX_BIT_NSEL1 | ADS1242_REG_MUX_BIT_NSEL0); + mux_reg_value |= (uint8_t)(neg_in_sel); + ads1242_write_reg(dev, ADS1242_REG_MUX, mux_reg_value); + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) + ads1242_print_regs(dev, "ads1242_set_negative_input"); +#endif +} + +/**************************************************************************** + * Name: ads1242_set_negative_input + ****************************************************************************/ + +static bool ads1242_is_data_ready(FAR struct ads1242_dev_s *dev) +{ + uint8_t acr_reg_value = 0xFF; + bool const is_data_ready; + + ads1242_read_reg(dev, ADS1242_REG_ACR, &acr_reg_value); + is_data_ready = (acr_reg_value & ADS1242_REG_ACR_BIT_nDRDY) == 0; + return is_data_ready; +} + +/**************************************************************************** + * Name: ads1242_print_regs + ****************************************************************************/ + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) +static void ads1242_print_regs(FAR struct ads1242_dev_s *dev, char const *msg) +{ + uint8_t setup_reg_value = 0; + uint8_t mux_reg_value = 0; + uint8_t acr_reg_value = 0; + + dbg("%s\n", msg); + + ads1242_read_reg(dev, ADS1242_REG_SETUP, &setup_reg_value); + ads1242_read_reg(dev, ADS1242_REG_MUX, &mux_reg_value); + ads1242_read_reg(dev, ADS1242_REG_ACR, &acr_reg_value); + + dbg("SETUP %02X\n", setup_reg_value); + dbg("MUX %02X\n", mux_reg_value); + dbg("ACR %02X\n", acr_reg_value); +} +#endif /* defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) */ + +/**************************************************************************** + * Name: ads1242_open + ****************************************************************************/ + +static int ads1242_open(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ads1242_dev_s *priv = inode->i_private; + + ads1242_reset(priv); + up_mdelay(100); + + ads1242_performSelfGainCalibration(priv); + up_mdelay(100); + + /* SPEED = 1 -> fMod = fOsc / 256 (fMod = Modulator Clock Speed) + * BUFEN = 1 -> Internal input buffer enabled -> results in a very high + * impedance input for the ADC ~ 5 GOhm + */ + + ads1242_write_reg(priv, ADS1242_REG_ACR, + ADS1242_REG_ACR_BIT_SPEED | ADS1242_REG_ACR_BIT_BUFEN); + + ads1242_performSelfOffsetCalibration(priv); + up_mdelay(100); + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) + ads1242_print_regs(priv, "ads1242_open"); +#endif + + return OK; +} +/**************************************************************************** + * Name: ads1242_close + ****************************************************************************/ + +static int ads1242_close(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ads1242_dev_s *priv = inode->i_private; + + ads1242_reset(priv); + up_mdelay(100); + + return OK; +} + +/**************************************************************************** + * Name: ads1242_read + ****************************************************************************/ + +static ssize_t ads1242_read(FAR struct file *filep, + FAR char *buffer, size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ads1242_dev_s *priv = inode->i_private; + + return -ENOSYS; +} + +/**************************************************************************** + * Name: ads1242_write + ****************************************************************************/ + +static ssize_t ads1242_write(FAR struct file *filep, + FAR const char *buffer, size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ads1242_dev_s *priv = inode->i_private; + + return -ENOSYS; +} + +/**************************************************************************** + * Name: ads1242_ioctl + ****************************************************************************/ + +static int ads1242_ioctl (FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ads1242_dev_s *priv = inode->i_private; + + int ret = OK; + + switch (cmd) + { + /* Read the result of an analog conversion */ + + case ANIOC_ADS2142_READ: + { + FAR uint32_t *data = (FAR uint32_t *)((uintptr_t)arg); + ads1242_read_conversion_result(priv, data); + } + break; + + /* Set the gain of the ADC */ + + case ANIOC_ADS2142_SET_GAIN: + { + ads1242_set_gain(priv, (ADS1242_GAIN_SELECTION)(arg)); + } + break; + + /* Set the positive input of the ADC */ + + case ANIOC_ADS2142_SET_POSITIVE_INPUT: + { + ads1242_set_positive_input(priv, + (ADS1242_POSITIVE_INPUT_SELECTION)(arg)); + } + break; + + /* Set the negative input of the ADC */ + + case ANIOC_ADS2142_SET_NEGATIVE_INPUT: + { + ads1242_set_negative_input(priv, + (ADS1242_NEGATIVE_INPUT_SELECTION)(arg)); + } + break; + + /* Check if data is ready to be read */ + + case ANIOC_ADS2142_IS_DATA_READY: + { + FAR bool *is_data_ready = (FAR bool *)((uintptr_t)arg); + *is_data_ready = ads1242_is_data_ready(priv); + } + break; + + /* Perform a system offset calibration - Note: Zero input signal must + * be applied. + */ + + case ANIOC_ADS2142_DO_SYSTEM_OFFSET_CALIB: + { + ads1242_performSystemOffsetCalibration(priv); + } + break; + + /* Command was not recognized */ + + default: + dbg ("Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ads1242_register + * + * Description: + * Register the ADS1242 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/ads1242" + * spi - An instance of the SPI interface to use to communicate with ADS1242 + * osc_freq_hz - The frequency of the ADS1242 oscillator in Hz. Required for + * calculating the minimum delay periods when accessing the device via SPI. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ads1242_register(FAR const char *devpath, FAR struct spi_dev_s *spi, + uint32_t const osc_freq_hz) +{ + FAR struct ads1242_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(spi != NULL); + + /* Initialize the ADS1242 device structure */ + + priv = (FAR struct ads1242_dev_s *)kmm_malloc(sizeof(struct ads1242_dev_s)); + if (priv == NULL) + { + dbg ("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->spi = spi; + + float const osc_period_us = (1000.0 * 1000.0) / ((float)(osc_freq_hz)); + priv->osc_period_us = (uint32_t)(osc_period_us); + + /* Register the character driver */ + + ret = register_driver(devpath, &g_ads1242_fops, 0666, priv); + if (ret < 0) + { + dbg ("Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + /* setup SPI frequency */ + + SPI_SETFREQUENCY(spi, ADS1242_SPI_FREQUENCY); + + /* Setup SPI mode */ + + SPI_SETMODE(spi, ADS1242_SPI_MODE); + + return ret; +} + +#endif /* CONFIG_SPI && CONFIG_ADC_ADS1242 */ diff --git a/include/nuttx/analog/ads1242.h b/include/nuttx/analog/ads1242.h new file mode 100644 index 0000000000..b74b2a28b2 --- /dev/null +++ b/include/nuttx/analog/ads1242.h @@ -0,0 +1,202 @@ +/**************************************************************************** + * include/nuttx/sensors/ads1242.h + * + * Copyright (C) 2016, DS-Automotion GmbH. All rights reserved. + * Author: Alexander Entinger + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef NUTTX_INCLUDE_NUTTX_ANALOG_ADS1242_H_ +#define NUTTX_INCLUDE_NUTTX_ANALOG_ADS1242_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS1242) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* IOCTL Commands ***********************************************************/ + +#define ANIOC_ADS2142_READ _ANIOC(0x0001) /* Arg: uint32_t *value */ +#define ANIOC_ADS2142_SET_GAIN _ANIOC(0x0002) /* Arg: uint8_t value */ +#define ANIOC_ADS2142_SET_POSITIVE_INPUT _ANIOC(0x0003) /* Arg: uint8_t value */ +#define ANIOC_ADS2142_SET_NEGATIVE_INPUT _ANIOC(0x0004) /* Arg: uint8_t value */ +#define ANIOC_ADS2142_IS_DATA_READY _ANIOC(0x0005) /* Arg: bool *value */ +#define ANIOC_ADS2142_DO_SYSTEM_OFFSET_CALIB _ANIOC(0x0006) /* Arg: None */ + +/* ADS1242 REGISTER *********************************************************/ + +#define ADS1242_REG_SETUP (0x00) /* Setup Register */ +#define ADS1242_REG_MUX (0x01) /* Multiplexer Control Register */ +#define ADS1242_REG_ACR (0x02) /* Analog Control Register */ +#define ADS1242_REG_ODAC (0x03) /* Offset DAC */ +#define ADS1242_REG_DIO (0x04) /* Data I/O */ +#define ADS1242_REG_DIR (0x05) /* Direction Control for Data I/O */ +#define ADS1242_REG_IOCON (0x06) /* I/O Configuration Register */ + +/* ADS1242 REGISTER Bit Definitions *****************************************/ + +/* SETUP */ +#define ADS1242_REG_SETUP_BIT_BOCS (1 << 3) +#define ADS1242_REG_SETUP_BIT_PGA2 (1 << 2) +#define ADS1242_REG_SETUP_BIT_PGA1 (1 << 1) +#define ADS1242_REG_SETUP_BIT_PGA0 (1 << 0) +/* MUX */ +#define ADS1242_REG_MUX_BIT_PSEL3 (1 << 7) +#define ADS1242_REG_MUX_BIT_PSEL2 (1 << 6) +#define ADS1242_REG_MUX_BIT_PSEL1 (1 << 5) +#define ADS1242_REG_MUX_BIT_PSEL0 (1 << 4) +#define ADS1242_REG_MUX_BIT_NSEL3 (1 << 3) +#define ADS1242_REG_MUX_BIT_NSEL2 (1 << 2) +#define ADS1242_REG_MUX_BIT_NSEL1 (1 << 1) +#define ADS1242_REG_MUX_BIT_NSEL0 (1 << 0) +/* ACR */ +#define ADS1242_REG_ACR_BIT_nDRDY (1 << 7) +#define ADS1242_REG_ACR_BIT_UnB (1 << 6) +#define ADS1242_REG_ACR_BIT_SPEED (1 << 5) +#define ADS1242_REG_ACR_BIT_BUFEN (1 << 4) +#define ADS1242_REG_ACR_BIT_BITORDER (1 << 3) +#define ADS1242_REG_ACR_BIT_RANGE (1 << 2) +#define ADS1242_REG_ACR_BIT_DR1 (1 << 1) +#define ADS1242_REG_ACR_BIT_DR0 (1 << 0) + +/* ADS1242 SPI COMMANDS *****************************************************/ + +#define ADS1242_CMD_READ_DATA (0x01) +#define ADS1242_CMD_READ_REGISTER (0x10) +#define ADS1242_CMD_WRITE_REGISTER (0x50) +#define ADS1242_CMD_SELF_OFFSET_CALIB (0xF1) +#define ADS1242_CMD_SELF_GAIN_CALIB (0xf2) +#define ADS1242_CMD_SYSTEM_OFFSET_CALIB (0xf3) +#define ADS1242_CMD_RESET (0xfe) + +/* SPI BUS PARAMETERS *******************************************************/ + +/* 100 kHz, SCLK period has to be at least 4 x tOsc period of ADS1242 + * oscillator circuit. + */ + +#define ADS1242_SPI_FREQUENCY (100000) + +/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */ + +#define ADS1242_SPI_MODE (SPIDEV_MODE1) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef enum +{ + ADS1242_x1 = 0, + ADS1242_x2 = ADS1242_REG_SETUP_BIT_PGA0, + ADS1242_x4 = ADS1242_REG_SETUP_BIT_PGA1, + ADS1242_x8 = ADS1242_REG_SETUP_BIT_PGA1 | ADS1242_REG_SETUP_BIT_PGA0, + ADS1242_x16 = ADS1242_REG_SETUP_BIT_PGA2, + ADS1242_x32 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA0, + ADS1242_x64 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA1, + ADS1242_x128 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA1 | + ADS1242_REG_SETUP_BIT_PGA0 +} ADS1242_GAIN_SELECTION; + +typedef enum +{ + ADS1242_P_AIN0 = 0, + ADS1242_P_AIN1 = ADS1242_REG_MUX_BIT_PSEL0, + ADS1242_P_AIN2 = ADS1242_REG_MUX_BIT_PSEL1, + ADS1242_P_AIN3 = ADS1242_REG_MUX_BIT_PSEL1 | ADS1242_REG_MUX_BIT_PSEL0, + ADS1242_P_AIN4 = ADS1242_REG_MUX_BIT_PSEL2, + ADS1242_P_AIN5 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL0, + ADS1242_P_AIN6 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL1, + ADS1242_P_AIN7 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL1 | + ADS1242_REG_MUX_BIT_PSEL0, +} ADS1242_POSITIVE_INPUT_SELECTION; + +typedef enum +{ + ADS1242_N_AIN0 = 0, + ADS1242_N_AIN1 = ADS1242_REG_MUX_BIT_NSEL0, + ADS1242_N_AIN2 = ADS1242_REG_MUX_BIT_NSEL1, + ADS1242_N_AIN3 = ADS1242_REG_MUX_BIT_NSEL1 | ADS1242_REG_MUX_BIT_NSEL0, + ADS1242_N_AIN4 = ADS1242_REG_MUX_BIT_NSEL2, + ADS1242_N_AIN5 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL0, + ADS1242_N_AIN6 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL1, + ADS1242_N_AIN7 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL1 | + ADS1242_REG_MUX_BIT_NSEL0, +} ADS1242_NEGATIVE_INPUT_SELECTION; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: ads1242_register + * + * Description: + * Register the ADS1242 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/ads1242" + * spi - An instance of the SPI interface to use to communicate with ADS1242 + * osc_freq_hz - The frequency of the ADS1242 oscillator in Hz. Required for + * calculating the minimum delay periods when accessing the device via SPI. + * + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ads1242_register(FAR const char *devpath, FAR struct spi_dev_s *spi, + uint32_t const osc_freq_hz); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_SPI && CONFIG_ADC_ADS1242 */ +#endif /* NUTTX_INCLUDE_NUTTX_ANALOG_ADS1242_H_ */ -- GitLab From ca792558bfe8318f2b527be72862de48111af541 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 29 Jan 2016 07:55:39 -0600 Subject: [PATCH 646/858] Update ChangeLog; add ADS1242 driver to build system; fix some typos; eliminate some warning --- ChangeLog | 7 +++++++ drivers/analog/Kconfig | 19 ++++++++++++------- drivers/analog/Make.defs | 4 ++++ drivers/analog/ads1242.c | 14 +++----------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7083c3f5f3..006db8725b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11407,3 +11407,10 @@ errno value. Noted by Freddie Chopin. 7.15 2016-xx-xx Gregory Nutt + + * drivers/analog/adc1242.c and include/nuttx/analog/adc1242.h: Driver + for the 24-Bit Differential Input ADC ADS1242 that communicates via + SPI with a MCU. Reading the ADC conversion result as well as configuring + the ADC, setting the input channel, etc. is implemented via ioctl calls. + However, it does not yet implement the standard ADC interface. From + Alexander Entinger (2014-01-29). diff --git a/drivers/analog/Kconfig b/drivers/analog/Kconfig index 3245cc7c40..bc05480422 100644 --- a/drivers/analog/Kconfig +++ b/drivers/analog/Kconfig @@ -30,6 +30,18 @@ config ADC_NO_STARTUP_CONV ---help--- Do not start conversion when opening ADC device. +config ADC_ADS1242 + bool "TI ADS1242 support" + default n + select SPI + ---help--- + Enable driver support for the ADS1242 24-Bit SPI powered ADC. + + This driver supports reading the ADC conversion result as well as + configuring the ADC, setting the input channel, etc. is implemented + via ioctl calls. However, it does not yet implement the standard ADC + interface. + config ADC_ADS125X bool "TI ADS1255/ADS1256 support" default n @@ -43,13 +55,6 @@ config ADS1255_FREQUENCY endif # ADC_ADS125X -config ADC_ADS1242 - bool "ADS1242" - default n - select SPI - ---help--- - Enable driver support for the ADS1242 24-Bit SPI powered ADC. - config ADC_PGA11X bool "TI PGA112/3/6/7 support" default n diff --git a/drivers/analog/Make.defs b/drivers/analog/Make.defs index 89cc5bd3f7..2d12a1695d 100644 --- a/drivers/analog/Make.defs +++ b/drivers/analog/Make.defs @@ -66,6 +66,10 @@ endif # Include ADC device drivers +ifeq ($(CONFIG_ADC_ADS1242),y) + CSRCS += ads1242.c +endif + ifeq ($(CONFIG_ADC_ADS125X),y) CSRCS += ads1255.c endif diff --git a/drivers/analog/ads1242.c b/drivers/analog/ads1242.c index 6c80df4d2a..93b82942c2 100644 --- a/drivers/analog/ads1242.c +++ b/drivers/analog/ads1242.c @@ -95,7 +95,7 @@ static bool ads1242_is_data_ready(FAR struct ads1242_dev_s *dev); #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) static void ads1242_print_regs(FAR struct ads1242_dev_s *dev, char const *msg); -#endif / defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) */ +#endif /* CONFIG_DEBUG && CONFIG_DEBUG_VERBOSE */ /* Character driver methods */ @@ -335,11 +335,9 @@ static void ads1242_set_negative_input(FAR struct ads1242_dev_s *dev, static bool ads1242_is_data_ready(FAR struct ads1242_dev_s *dev) { uint8_t acr_reg_value = 0xFF; - bool const is_data_ready; ads1242_read_reg(dev, ADS1242_REG_ACR, &acr_reg_value); - is_data_ready = (acr_reg_value & ADS1242_REG_ACR_BIT_nDRDY) == 0; - return is_data_ready; + return (acr_reg_value & ADS1242_REG_ACR_BIT_nDRDY) == 0; } /**************************************************************************** @@ -363,7 +361,7 @@ static void ads1242_print_regs(FAR struct ads1242_dev_s *dev, char const *msg) dbg("MUX %02X\n", mux_reg_value); dbg("ACR %02X\n", acr_reg_value); } -#endif /* defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) */ +#endif /* CONFIG_DEBUG && CONFIG_DEBUG_VERBOSE */ /**************************************************************************** * Name: ads1242_open @@ -419,9 +417,6 @@ static int ads1242_close(FAR struct file *filep) static ssize_t ads1242_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { - FAR struct inode *inode = filep->f_inode; - FAR struct ads1242_dev_s *priv = inode->i_private; - return -ENOSYS; } @@ -432,9 +427,6 @@ static ssize_t ads1242_read(FAR struct file *filep, static ssize_t ads1242_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { - FAR struct inode *inode = filep->f_inode; - FAR struct ads1242_dev_s *priv = inode->i_private; - return -ENOSYS; } -- GitLab From 33ed27a6bd80dea1a04248f1b25d20322bb4840c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 29 Jan 2016 11:34:07 -0600 Subject: [PATCH 647/858] Move xyz_cxxinitialize.c from nuttx/configs/abc/src to apps/platform/abc/ (where xyz is the processor family and abc is the board) --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 94cc2c17de..3af8fc18cb 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 94cc2c17de89faf152b3388349092173f0d165b0 +Subproject commit 3af8fc18cbdc6c6fd493e0d8d422b53a9b07bb04 -- GitLab From 6239f2e2f164700e80204068b376198f397ef55e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 29 Jan 2016 11:35:19 -0600 Subject: [PATCH 648/858] Update ChangeLog --- ChangeLog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 006db8725b..a56a37160e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11413,4 +11413,7 @@ SPI with a MCU. Reading the ADC conversion result as well as configuring the ADC, setting the input channel, etc. is implemented via ioctl calls. However, it does not yet implement the standard ADC interface. From - Alexander Entinger (2014-01-29). + * configs/board/src/xyz_cxxinitialize.c: Move CXX initialization logic + out of the RTOS and into the application space, specifically to + apps/platform/board, where it belongs (2016-01-29). + -- GitLab From 8645b7c57ff12f8a8f58280277eeb31365963e4a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 29 Jan 2016 11:36:43 -0600 Subject: [PATCH 649/858] Update submodule --- configs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs b/configs index 3af8fc18cb..f4d2471e10 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3af8fc18cbdc6c6fd493e0d8d422b53a9b07bb04 +Subproject commit f4d2471e1064a8c1dacfd3368aaa9229cc065274 -- GitLab From 19feab1bd6d5509ff988a40a81d13f22e1e99071 Mon Sep 17 00:00:00 2001 From: Vladimir Komendantskiy Date: Sat, 30 Jan 2016 07:37:43 -0600 Subject: [PATCH 650/858] drivers/modem/u-blox.c and include/nuttx/drivers/u-blox.h: Add an upper half driver for the U-Blox Modem. From Vladimir Komendantskiy --- ChangeLog | 3 + drivers/Kconfig | 10 ++ drivers/Makefile | 1 + drivers/modem/Kconfig | 20 +++ drivers/modem/Make.defs | 48 +++++ drivers/modem/u-blox.c | 338 +++++++++++++++++++++++++++++++++++ include/nuttx/fs/ioctl.h | 7 + include/nuttx/modem/u-blox.h | 119 ++++++++++++ 8 files changed, 546 insertions(+) create mode 100644 drivers/modem/Kconfig create mode 100644 drivers/modem/Make.defs create mode 100644 drivers/modem/u-blox.c create mode 100644 include/nuttx/modem/u-blox.h diff --git a/ChangeLog b/ChangeLog index a56a37160e..abe8b13bd7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11416,4 +11416,7 @@ * configs/board/src/xyz_cxxinitialize.c: Move CXX initialization logic out of the RTOS and into the application space, specifically to apps/platform/board, where it belongs (2016-01-29). + * drivers/modem/u-blox.c and include/nuttx/drivers/u-blox.h: Add an upper + half driver for the U-Blox Modem. From Vladimir Komendantskiy + (2018-01-30). diff --git a/drivers/Kconfig b/drivers/Kconfig index c836f5a8c4..41123641eb 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -403,6 +403,16 @@ if MMCSD source drivers/mmcsd/Kconfig endif # MMCSD +menuconfig MODEM + bool "Modem Support" + default n + ---help--- + Enable modem support. + +if MODEM +source drivers/modem/Kconfig +endif # MODEM + menuconfig MTD bool "Memory Technology Device (MTD) Support" default n diff --git a/drivers/Makefile b/drivers/Makefile index c642b91877..025444990f 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -59,6 +59,7 @@ include lcd$(DELIM)Make.defs include leds$(DELIM)Make.defs include loop$(DELIM)Make.defs include mmcsd$(DELIM)Make.defs +include modem$(DELIM)Make.defs include mtd$(DELIM)Make.defs include eeprom$(DELIM)Make.defs include net$(DELIM)Make.defs diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig new file mode 100644 index 0000000000..bfc7568612 --- /dev/null +++ b/drivers/modem/Kconfig @@ -0,0 +1,20 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config MODEM_U_BLOX + bool "Enable u-blox modem driver" + default n + ---help--- + Compile the u-blox serial modem driver. The driver consists of + the upper half in the OS and the lower half with implementation + in the chosen board. + +config MODEM_U_BLOX_DEBUG + bool "Debug u-blox modem driver" + default n + depends on MODEM_U_BLOX + ---help--- + Allow the u-blox modem driver print debug information. + diff --git a/drivers/modem/Make.defs b/drivers/modem/Make.defs new file mode 100644 index 0000000000..6916f46fa2 --- /dev/null +++ b/drivers/modem/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# drivers/modem/Make.defs +# +# Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. +# Author: Vladimir Komendantskiy +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_MODEM),y) + +ifeq ($(CONFIG_MODEM_U_BLOX),y) +CSRCS += u-blox.c +endif + +# Include modem driver build support + +DEPPATH += --dep-path modem +VPATH += :modem +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)modem} + +endif diff --git a/drivers/modem/u-blox.c b/drivers/modem/u-blox.c new file mode 100644 index 0000000000..05e4453ba9 --- /dev/null +++ b/drivers/modem/u-blox.c @@ -0,0 +1,338 @@ +/**************************************************************************** + * drivers/modem/u-blox.c + * + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Debug ********************************************************************/ +/* Non-standard debug that may be enabled just for testing the modem driver */ + +#ifdef CONFIG_MODEM_U_BLOX_DEBUG +# define m_dbg dbg +# define m_vdbg vdbg +# define m_vlldbg lldbg +# define m_vllvdbg llvdbg +#else +# define m_dbg(x...) +# define m_vdbg(x...) +# define m_lldbg(x...) +# define m_llvdbg(x...) +#endif + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/* The type of upper half driver state. */ + +struct ubxmdm_upper +{ + FAR char* path; /* Registration path */ + + /* The contained lower-half driver. */ + + FAR struct ubxmdm_lower* lower; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static ssize_t ubxmdm_read (FAR struct file* filep, + FAR char* buffer, + size_t buflen); +static ssize_t ubxmdm_write(FAR struct file* filep, + FAR const char* buffer, + size_t buflen); +static int ubxmdm_ioctl(FAR struct file* filep, + int cmd, + unsigned long arg); + +#ifndef CONFIG_DISABLE_POLL +static int ubxmdm_poll (FAR struct file* filep, + FAR struct pollfd* fds, + bool setup); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations ubxmdm_fops = +{ + 0, /* open */ + 0, /* close */ + ubxmdm_read, /* read */ + ubxmdm_write, /* write */ + 0, /* seek */ + ubxmdm_ioctl, /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + ubxmdm_poll, /* poll */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static ssize_t ubxmdm_read(FAR struct file* filep, + FAR char* buffer, + size_t len) +{ + return 0; /* Return EOF */ +} + +static ssize_t ubxmdm_write(FAR struct file* filep, + FAR const char* buffer, + size_t len) +{ + return len; /* Say that everything was written */ +} + +static int ubxmdm_ioctl(FAR struct file* filep, + int cmd, + unsigned long arg) +{ + FAR struct inode* inode = filep->f_inode; + FAR struct ubxmdm_upper* upper = inode->i_private; + FAR struct ubxmdm_lower* lower = upper->lower; + int ret; + FAR struct ubxmdm_status* status; + + m_vdbg("cmd: %d arg: %ld\n", cmd, arg); + DEBUGASSERT(upper && lower); + + switch (cmd) + { + /* cmd: UBXMDM_IOC_START + * Description: + * arg: Ignored + */ + + case MODEM_IOC_POWERON: + if (lower->ops->poweron) + { + ret = lower->ops->poweron(lower); + } + else + { + ret = -ENOSYS; + } + + break; + + /* cmd: UBXMDM_IOC_STOP + * Description: + * arg: Ignored + */ + + case MODEM_IOC_POWEROFF: + if (lower->ops->poweroff) + { + ret = lower->ops->poweroff(lower); + } + else + { + ret = -ENOSYS; + } + + break; + + /* cmd: UBXMDM_IOC_RESET + * Description: + * arg: Ignored + */ + + case MODEM_IOC_RESET: + if (lower->ops->reset) + { + ret = lower->ops->reset(lower); + } + else + { + ret = -ENOSYS; + } + + break; + + /* cmd: UBXMDM_IOC_GETSTATUS + * Description: + * arg: Writeable pointer to struct ubxmdm_status. + */ + + case MODEM_IOC_GETSTATUS: + if (lower->ops->getstatus) + { + status = (FAR struct ubxmdm_status*) ((uintptr_t) arg); + if (status) + { + ret = lower->ops->getstatus(lower, status); + } + else + { + ret = -EINVAL; + } + } + else + { + ret = -ENOSYS; + } + + break; + + /* Unrecognized IOCTL commands are forwarded to the lower-half IOCTL + * handler, if defined. + */ + + default: + m_vdbg("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg); + + if (lower->ops->ioctl) + { + ret = lower->ops->ioctl(lower, cmd, arg); + } + else + { + ret = -ENOSYS; + } + + break; + } + + return ret; +} + +#ifndef CONFIG_DISABLE_POLL +static int ubxmdm_poll(FAR struct file* filep, + FAR struct pollfd* fds, + bool setup) +{ + if (setup) + { + fds->revents |= (fds->events & (POLLIN | POLLOUT)); + if (fds->revents != 0) + { + sem_post(fds->sem); + } + } + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +FAR void* ubxmdm_register(FAR const char *path, + FAR struct ubxmdm_lower *lower) +{ + FAR struct ubxmdm_upper *upper; + int ret; + + DEBUGASSERT(path && lower); + + upper = (FAR struct ubxmdm_upper*) + kmm_zalloc(sizeof(struct ubxmdm_upper)); + if (!upper) + { + m_dbg("Upper half allocation failed\n"); + goto errout; + } + + upper->lower = lower; + upper->path = strdup(path); + if (!upper->path) + { + m_dbg("Path allocation failed\n"); + goto errout_with_upper; + } + + ret = register_driver(path, &ubxmdm_fops, 0666, upper); + if (ret < 0) + { + m_dbg("register_driver failed: %d\n", ret); + goto errout_with_path; + } + + return (FAR void*) upper; + +errout_with_path: + kmm_free(upper->path); + +errout_with_upper: + kmm_free(upper); + +errout: + return NULL; +} + +void ubxmdm_unregister(FAR void *handle) +{ + FAR struct ubxmdm_upper *upper; + FAR struct ubxmdm_lower *lower; + + upper = (FAR struct ubxmdm_upper*) handle; + lower = upper->lower; + DEBUGASSERT(upper && lower); + + m_vdbg("Unregistering: %s\n", upper->path); + + DEBUGASSERT(lower->ops->poweroff); + (void) lower->ops->poweroff(lower); + + (void) unregister_driver(upper->path); + + kmm_free(upper->path); + kmm_free(upper); +} diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 46fbdbf8ab..09893a63f8 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -81,6 +81,7 @@ #define _ULEDBASE (0x1c00) /* User LED ioctl commands */ #define _ZCBASE (0x1d00) /* Zero Cross ioctl commands */ #define _LOOPBASE (0x1e00) /* Loop device commands */ +#define _MODEMBASE (0x1f00) /* Modem ioctl commands */ /* boardctl commands share the same number space */ @@ -367,6 +368,12 @@ #define _LOOPIOCVALID(c) (_IOC_TYPE(c)==_LOOPBASE) #define _LOOPIOC(nr) _IOC(_LOOPBASE,nr) +/* Modem driver ioctl definitions ********************************************/ +/* see nuttx/include/modem/*.h */ + +#define _MODEMIOCVALID(c) (_IOC_TYPE(c)==_MODEMBASE) +#define _MODEMIOC(nr) _IOC(_MODEMBASE,nr) + /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/modem/u-blox.h b/include/nuttx/modem/u-blox.h new file mode 100644 index 0000000000..3b08ac422d --- /dev/null +++ b/include/nuttx/modem/u-blox.h @@ -0,0 +1,119 @@ +/**************************************************************************** + * include/nuttx/modem/u-blox.h + * + * Copyright (C) 2016 Vladimir Komendantskiy. All rights reserved. + * Author: Vladimir Komendantskiy + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MODEM_U_BLOX_H +#define __INCLUDE_NUTTX_MODEM_U_BLOX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MODEM_IOC_POWERON _MODEMIOC(1) +#define MODEM_IOC_POWEROFF _MODEMIOC(2) +#define MODEM_IOC_RESET _MODEMIOC(3) +#define MODEM_IOC_GETSTATUS _MODEMIOC(4) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ubxmdm_regval +{ + FAR char name[3]; + bool val; +}; + +struct ubxmdm_status +{ + bool on; + int register_values_size; + FAR struct ubxmdm_regval* register_values; +}; + +struct ubxmdm_lower; + +struct ubxmdm_ops +{ + CODE int (*poweron) (FAR struct ubxmdm_lower* lower); + CODE int (*poweroff) (FAR struct ubxmdm_lower* lower); + CODE int (*reset) (FAR struct ubxmdm_lower* lower); + CODE int (*getstatus)(FAR struct ubxmdm_lower* lower, + FAR struct ubxmdm_status* status); + CODE int (*ioctl) (FAR struct ubxmdm_lower* lower, + int cmd, + unsigned long arg); +}; + +struct ubxmdm_lower +{ + FAR const struct ubxmdm_ops *ops; +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * "Upper-Half" Timer Driver Interfaces + ****************************************************************************/ + +FAR void *ubxmdm_register(FAR const char *path, + FAR struct ubxmdm_lower *lower); + +void ubxmdm_unregister(FAR void *handle); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_MODEM_U_BLOX_H */ -- GitLab From ceb415204ec41ac1fa0b9e62d255a9763bca2445 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 08:00:16 -0600 Subject: [PATCH 651/858] Move include/nuttx/i2c.h to include/nuttx/i2c/i2c_master.h --- arch | 2 +- configs | 2 +- drivers/Kconfig | 2 +- drivers/README.txt | 2 +- drivers/audio/wm8904.c | 2 +- drivers/i2c/i2c_read.c | 2 +- drivers/i2c/i2c_write.c | 2 +- drivers/i2c/i2c_writeread.c | 2 +- drivers/input/mxt.c | 2 +- drivers/input/stmpe811_tsc.c | 2 +- drivers/input/tsc2007.c | 2 +- drivers/ioexpander/pca9555.c | 2 +- drivers/ioexpander/pca9555.h | 2 +- drivers/lcd/ssd1306_base.c | 2 +- drivers/lcd/ssd1306_i2c.c | 2 +- drivers/leds/pca9635pw.c | 2 +- drivers/mtd/at24xx.c | 2 +- drivers/power/bq2425x.c | 2 +- drivers/power/max1704x.c | 2 +- drivers/sensors/adxl345_i2c.c | 2 +- drivers/sensors/as5048b.c | 2 +- drivers/sensors/bmp180.c | 2 +- drivers/sensors/lis331dl.c | 2 +- drivers/sensors/lm75.c | 2 +- drivers/sensors/lm92.c | 2 +- drivers/sensors/lsm9ds1.c | 2 +- drivers/sensors/mb7040.c | 2 +- drivers/sensors/mcp9844.c | 2 +- drivers/sensors/ms58xx.c | 2 +- drivers/timers/cs2100-cp.c | 2 +- drivers/timers/ds3231.c | 2 +- drivers/timers/pcf85263.c | 2 +- drivers/video/ov2640.c | 2 +- include/nuttx/audio/wm8904.h | 2 +- include/nuttx/{i2c.h => i2c/i2c_master.h} | 8 ++++---- include/nuttx/input/ads7843e.h | 2 +- include/nuttx/input/mxt.h | 2 +- include/nuttx/input/stmpe811.h | 2 +- include/nuttx/input/tsc2007.h | 2 +- include/nuttx/ioexpander/pca9555.h | 2 +- include/nuttx/timers/cs2100-cp.h | 2 +- 41 files changed, 44 insertions(+), 44 deletions(-) rename include/nuttx/{i2c.h => i2c/i2c_master.h} (98%) diff --git a/arch b/arch index 69b5f95ae5..ce5362e2da 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 69b5f95ae5c4b953be4b6e1598a4e71f794afe52 +Subproject commit ce5362e2daf21444768b5219eb0eca6fa7929ea1 diff --git a/configs b/configs index f4d2471e10..6b24789ace 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f4d2471e1064a8c1dacfd3368aaa9229cc065274 +Subproject commit 6b24789ace585ef78778cff3a3c894ad11db6166 diff --git a/drivers/Kconfig b/drivers/Kconfig index 41123641eb..bef5458d4a 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -268,7 +268,7 @@ menuconfig I2C default n ---help--- This selection enables building of the "upper-half" I2C driver. - See include/nuttx/i2c.h for further I2C driver information. + See include/nuttx/i2c/i2c_master.h for further I2C driver information. if I2C source drivers/i2c/Kconfig diff --git a/drivers/README.txt b/drivers/README.txt index 6f731a153f..420988ccd4 100644 --- a/drivers/README.txt +++ b/drivers/README.txt @@ -69,7 +69,7 @@ eeprom/ the EEPROM drivers. i2c/ - I2C drivers and support logic. See include/nuttx/i2c.h + I2C drivers and support logic. See include/nuttx/i2c/i2c_master.h input/ This directory holds implementations of human input device (HID) diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index ac3bdf3668..a240aa7703 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 2c93bac533..04052c4447 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -41,7 +41,7 @@ #include -#include +#include #if defined(CONFIG_I2C_TRANSFER) diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index 3f2395e370..d8eceb610c 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -41,7 +41,7 @@ #include -#include +#include #if defined(CONFIG_I2C_TRANSFER) diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index d5fab3f43b..cfb9a127cb 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -41,7 +41,7 @@ #include -#include +#include #if defined(CONFIG_I2C_TRANSFER) diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index 6a1ebeceb6..0d89a1abfb 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/input/stmpe811_tsc.c b/drivers/input/stmpe811_tsc.c index 723d12c92f..fa701e0710 100644 --- a/drivers/input/stmpe811_tsc.c +++ b/drivers/input/stmpe811_tsc.c @@ -60,7 +60,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index 8f6a6930af..31d17a031a 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -65,7 +65,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 9f3fe58ebf..91a2f3e223 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/ioexpander/pca9555.h b/drivers/ioexpander/pca9555.h index 258cf0e640..0eb07101ec 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -51,7 +51,7 @@ #include #include -#include +#include #include #if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_PCA9555) diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index 2ac7bbeca1..b7d76eb9ec 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -129,7 +129,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/lcd/ssd1306_i2c.c b/drivers/lcd/ssd1306_i2c.c index 7164d890be..ffc72b075e 100644 --- a/drivers/lcd/ssd1306_i2c.c +++ b/drivers/lcd/ssd1306_i2c.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include "ssd1306.h" diff --git a/drivers/leds/pca9635pw.c b/drivers/leds/pca9635pw.c index fc0d413c34..92f8baaa94 100644 --- a/drivers/leds/pca9635pw.c +++ b/drivers/leds/pca9635pw.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 9ce0ee31c8..8f76e54f65 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -59,7 +59,7 @@ #include #include -#include +#include #include #ifdef CONFIG_MTD_AT24XX diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c index c4d281c392..bf9d3e86da 100644 --- a/drivers/power/bq2425x.c +++ b/drivers/power/bq2425x.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include #include "bq2425x.h" diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 571fe63c3e..73fd5b38ca 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include /* This driver requires: diff --git a/drivers/sensors/adxl345_i2c.c b/drivers/sensors/adxl345_i2c.c index 9b905b7b97..b5ece68727 100644 --- a/drivers/sensors/adxl345_i2c.c +++ b/drivers/sensors/adxl345_i2c.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include "adxl345.h" diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index e33ea6e038..cd56af85a1 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_QENCODER) && defined(CONFIG_AS5048B) diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index c379b5707a..8ffc326c26 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_BMP180) diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index aad762c8ec..4087579fd6 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL) diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index e1a43539e8..05f6f890ef 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -47,7 +47,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 02ed18196b..3159333721 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_LM92) diff --git a/drivers/sensors/lsm9ds1.c b/drivers/sensors/lsm9ds1.c index ba6e07784b..047591052a 100644 --- a/drivers/sensors/lsm9ds1.c +++ b/drivers/sensors/lsm9ds1.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_SN_LSM9DS1) diff --git a/drivers/sensors/mb7040.c b/drivers/sensors/mb7040.c index 16c853421a..22ed726eae 100644 --- a/drivers/sensors/mb7040.c +++ b/drivers/sensors/mb7040.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_MB7040) diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c index 68a5091ce3..92f738d6fb 100644 --- a/drivers/sensors/mcp9844.c +++ b/drivers/sensors/mcp9844.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_MCP9844) diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index ad01b23b84..58d9ec8b32 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #if defined(CONFIG_I2C) && defined(CONFIG_MS58XX) diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index f8064db33f..10da98d4b3 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #ifdef CONFIG_TIMERS_CS2100CP diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 18a60c1b62..aede53b9d2 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include "ds3231.h" diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 6081d88018..5d50240f7b 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include "pcf85263.h" diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index e0fe18d21f..58b38f974f 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include /**************************************************************************** diff --git a/include/nuttx/audio/wm8904.h b/include/nuttx/audio/wm8904.h index 6536d77890..983a205e3d 100644 --- a/include/nuttx/audio/wm8904.h +++ b/include/nuttx/audio/wm8904.h @@ -214,7 +214,7 @@ extern "C" * ****************************************************************************/ -struct i2c_dev_s; /* Forward reference. Defined in include/nuttx/i2c.h */ +struct i2c_dev_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */ struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */ struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */ diff --git a/include/nuttx/i2c.h b/include/nuttx/i2c/i2c_master.h similarity index 98% rename from include/nuttx/i2c.h rename to include/nuttx/i2c/i2c_master.h index 03c03bced6..2216026340 100644 --- a/include/nuttx/i2c.h +++ b/include/nuttx/i2c/i2c_master.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/i2c.h + * include/nuttx/i2c/i2c_master.h * * Copyright(C) 2009-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_I2C_H -#define __INCLUDE_NUTTX_I2C_H +#ifndef __INCLUDE_NUTTX_I2C_I2C_MASTER_H +#define __INCLUDE_NUTTX_I2C_I2C_MASTER_H /**************************************************************************** * Included Files @@ -417,4 +417,4 @@ int i2c_read(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, #if defined(__cplusplus) } #endif -#endif /* __INCLUDE_NUTTX_I2C_H */ +#endif /* __INCLUDE_NUTTX_I2C_I2C_MASTER_H */ diff --git a/include/nuttx/input/ads7843e.h b/include/nuttx/input/ads7843e.h index 4c4b3b1189..3b14507228 100644 --- a/include/nuttx/input/ads7843e.h +++ b/include/nuttx/input/ads7843e.h @@ -46,7 +46,7 @@ ****************************************************************************/ #include -#include +#include #if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) diff --git a/include/nuttx/input/mxt.h b/include/nuttx/input/mxt.h index fb606c1d78..aecc042c33 100644 --- a/include/nuttx/input/mxt.h +++ b/include/nuttx/input/mxt.h @@ -45,7 +45,7 @@ #include #include -#include +#include #if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_MXT) diff --git a/include/nuttx/input/stmpe811.h b/include/nuttx/input/stmpe811.h index 7b11496cc0..4c64b4005d 100644 --- a/include/nuttx/input/stmpe811.h +++ b/include/nuttx/input/stmpe811.h @@ -46,7 +46,7 @@ #include -#include +#include #include #include diff --git a/include/nuttx/input/tsc2007.h b/include/nuttx/input/tsc2007.h index 7ca219cd9a..468878f830 100644 --- a/include/nuttx/input/tsc2007.h +++ b/include/nuttx/input/tsc2007.h @@ -51,7 +51,7 @@ ****************************************************************************/ #include -#include +#include #if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_TSC2007) diff --git a/include/nuttx/ioexpander/pca9555.h b/include/nuttx/ioexpander/pca9555.h index 581528c531..2a0e4200d1 100644 --- a/include/nuttx/ioexpander/pca9555.h +++ b/include/nuttx/ioexpander/pca9555.h @@ -40,7 +40,7 @@ #ifndef __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H #define __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H -#include +#include /* A reference to a structure of this type must be passed to the PCA9555 driver when the * driver is instantiated. This structure provides information about the configuration of diff --git a/include/nuttx/timers/cs2100-cp.h b/include/nuttx/timers/cs2100-cp.h index 9947f99d86..8ef8bb726c 100644 --- a/include/nuttx/timers/cs2100-cp.h +++ b/include/nuttx/timers/cs2100-cp.h @@ -43,7 +43,7 @@ #include #include -#include +#include #ifdef CONFIG_TIMERS_CS2100CP -- GitLab From 3a781a2d3f5c12775cbe829cefcbaba1f443e30e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 08:36:47 -0600 Subject: [PATCH 652/858] Remove I2C slave methods from I2C master interface; rename i2c_dev_s to i2c_master_s. --- Documentation | 2 +- arch | 2 +- configs | 2 +- drivers/audio/wm8904.c | 2 +- drivers/audio/wm8904.h | 2 +- drivers/i2c/i2c_read.c | 3 +- drivers/i2c/i2c_write.c | 3 +- drivers/i2c/i2c_writeread.c | 3 +- drivers/input/mxt.c | 4 +- drivers/input/stmpe811.h | 2 +- drivers/input/stmpe811_base.c | 2 +- drivers/input/tsc2007.c | 4 +- drivers/ioexpander/pca9555.c | 2 +- drivers/ioexpander/pca9555.h | 6 +-- drivers/lcd/ssd1306.h | 2 +- drivers/lcd/ssd1306_base.c | 2 +- drivers/leds/pca9635pw.c | 4 +- drivers/mtd/at24xx.c | 18 +++---- drivers/power/bq2425x.c | 13 ++--- drivers/power/max1704x.c | 10 ++-- drivers/sensors/adxl345.h | 2 +- drivers/sensors/adxl345_base.c | 2 +- drivers/sensors/as5048b.c | 8 +-- drivers/sensors/bmp180.c | 14 ++--- drivers/sensors/lis331dl.c | 4 +- drivers/sensors/lm75.c | 8 +-- drivers/sensors/lm92.c | 8 +-- drivers/sensors/lsm9ds1.c | 12 ++--- drivers/sensors/mb7040.c | 6 +-- drivers/sensors/mcp9844.c | 6 +-- drivers/sensors/ms58xx.c | 14 ++--- drivers/timers/ds3231.c | 4 +- drivers/timers/pcf85263.c | 4 +- drivers/video/ov2640.c | 22 ++++---- include/nuttx/audio/wm8904.h | 4 +- include/nuttx/i2c/i2c_master.h | 74 ++++++--------------------- include/nuttx/input/mxt.h | 2 +- include/nuttx/input/stmpe811.h | 2 +- include/nuttx/input/tsc2007.h | 2 +- include/nuttx/ioexpander/pca9555.h | 2 +- include/nuttx/lcd/ssd1306.h | 2 +- include/nuttx/leds/pca9635pw.h | 4 +- include/nuttx/mtd/mtd.h | 6 +-- include/nuttx/power/battery_charger.h | 4 +- include/nuttx/power/battery_gauge.h | 4 +- include/nuttx/sensors/adxl345.h | 4 +- include/nuttx/sensors/as5048b.h | 4 +- include/nuttx/sensors/bmp180.h | 4 +- include/nuttx/sensors/lis331dl.h | 4 +- include/nuttx/sensors/lm75.h | 4 +- include/nuttx/sensors/lm92.h | 4 +- include/nuttx/sensors/lsm9ds1.h | 8 +-- include/nuttx/sensors/mb7040.h | 4 +- include/nuttx/sensors/mcp9844.h | 4 +- include/nuttx/sensors/ms58xx.h | 4 +- include/nuttx/timers/cs2100-cp.h | 16 +++--- include/nuttx/timers/ds3231.h | 4 +- include/nuttx/timers/pcf85263.h | 4 +- include/nuttx/video/ov2640.h | 4 +- 59 files changed, 171 insertions(+), 209 deletions(-) diff --git a/Documentation b/Documentation index b7d0b9c21a..bd05adddce 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit b7d0b9c21a8f8990810c2db4ff5dbd1b747e3d03 +Subproject commit bd05adddce9f801523a2b77363a8dddb01c952b3 diff --git a/arch b/arch index ce5362e2da..5ea918534a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ce5362e2daf21444768b5219eb0eca6fa7929ea1 +Subproject commit 5ea918534aef71cdff40f56081c70de8818cb5bc diff --git a/configs b/configs index 6b24789ace..c4eea61723 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6b24789ace585ef78778cff3a3c894ad11db6166 +Subproject commit c4eea61723a32ae07781338cd9a80637dec07822 diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index a240aa7703..0742db5072 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -2464,7 +2464,7 @@ static void wm8904_hw_reset(FAR struct wm8904_dev_s *priv) ****************************************************************************/ FAR struct audio_lowerhalf_s * - wm8904_initialize(FAR struct i2c_dev_s *i2c, FAR struct i2s_dev_s *i2s, + wm8904_initialize(FAR struct i2c_master_s *i2c, FAR struct i2s_dev_s *i2s, FAR const struct wm8904_lower_s *lower) { FAR struct wm8904_dev_s *priv; diff --git a/drivers/audio/wm8904.h b/drivers/audio/wm8904.h index 8aeb5bce63..e51d247c5f 100644 --- a/drivers/audio/wm8904.h +++ b/drivers/audio/wm8904.h @@ -1067,7 +1067,7 @@ struct wm8904_dev_s /* Our specific driver data goes here */ const FAR struct wm8904_lower_s *lower; /* Pointer to the board lower functions */ - FAR struct i2c_dev_s *i2c; /* I2C driver to use */ + FAR struct i2c_master_s *i2c; /* I2C driver to use */ FAR struct i2s_dev_s *i2s; /* I2S driver to use */ struct dq_queue_s pendq; /* Queue of pending buffers to be sent */ struct dq_queue_s doneq; /* Queue of sent buffers to be returned */ diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 04052c4447..1d7c16b8cb 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -68,7 +68,8 @@ * ****************************************************************************/ -int i2c_read(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_read(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR uint8_t *buffer, int buflen) { struct i2c_msg_s msg; diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index d8eceb610c..725e150ce4 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -68,7 +68,8 @@ * ****************************************************************************/ -int i2c_write(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_write(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR const uint8_t *buffer, int buflen) { struct i2c_msg_s msg; diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index cfb9a127cb..571fa1b305 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -69,7 +69,8 @@ * ****************************************************************************/ -int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_writeread(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, int rbuflen) { diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index 0d89a1abfb..f5ebec8e89 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -165,7 +165,7 @@ struct mxt_dev_s * lower half configuration data. */ - FAR struct i2c_dev_s *i2c; + FAR struct i2c_master_s *i2c; FAR const struct mxt_lower_s *lower; /* This is the allocated array of object information */ @@ -1850,7 +1850,7 @@ errout_with_objtab: * ****************************************************************************/ -int mxt_register(FAR struct i2c_dev_s *i2c, +int mxt_register(FAR struct i2c_master_s *i2c, FAR const struct mxt_lower_s * const lower, int minor) { FAR struct mxt_dev_s *priv; diff --git a/drivers/input/stmpe811.h b/drivers/input/stmpe811.h index d96944f4c4..dea9f3a0a8 100644 --- a/drivers/input/stmpe811.h +++ b/drivers/input/stmpe811.h @@ -138,7 +138,7 @@ struct stmpe811_dev_s #ifdef CONFIG_STMPE811_SPI FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ #else - FAR struct i2c_dev_s *i2c; /* Saved I2C driver instance */ + FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ #endif uint8_t inuse; /* STMPE811 pins in use */ diff --git a/drivers/input/stmpe811_base.c b/drivers/input/stmpe811_base.c index d10462e8fb..9a9ad6caac 100644 --- a/drivers/input/stmpe811_base.c +++ b/drivers/input/stmpe811_base.c @@ -287,7 +287,7 @@ static void stmpe811_reset(FAR struct stmpe811_dev_s *priv) STMPE811_HANDLE stmpe811_instantiate(FAR struct spi_dev_s *dev, FAR struct stmpe811_config_s *config) #else -STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_dev_s *dev, +STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev, FAR struct stmpe811_config_s *config) #endif { diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index 31d17a031a..9bc56706e7 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -165,7 +165,7 @@ struct tsc2007_dev_s sem_t waitsem; /* Used to wait for the availability of data */ FAR struct tsc2007_config_s *config; /* Board configuration data */ - FAR struct i2c_dev_s *i2c; /* Saved I2C driver instance */ + FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ struct work_s work; /* Supports the interrupt handling "bottom half" */ struct tsc2007_sample_s sample; /* Last sampled touch point data */ @@ -1210,7 +1210,7 @@ errout: * ****************************************************************************/ -int tsc2007_register(FAR struct i2c_dev_s *dev, +int tsc2007_register(FAR struct i2c_master_s *dev, FAR struct tsc2007_config_s *config, int minor) { FAR struct tsc2007_dev_s *priv; diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 91a2f3e223..f405a4a311 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -587,7 +587,7 @@ static int pca9555_interrupt(int irq, FAR void *context) * ****************************************************************************/ -FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_dev_s *i2cdev, +FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *i2cdev, FAR struct pca9555_config_s *config) { FAR struct pca9555_dev_s *pcadev; diff --git a/drivers/ioexpander/pca9555.h b/drivers/ioexpander/pca9555.h index 0eb07101ec..c7d2467674 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -116,14 +116,14 @@ struct pca9555_dev_s { - struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio expander. */ + struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio expander. */ #ifdef CONFIG_PCA9555_MULTIPLE - FAR struct pca9555_dev_s * flink; /* Supports a singly linked list of drivers */ + FAR struct pca9555_dev_s *flink; /* Supports a singly linked list of drivers */ #endif FAR struct pca9555_config_s *config; /* Board configuration data */ - FAR struct i2c_dev_s * i2c; /* Saved I2C driver instance */ + FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ }; diff --git a/drivers/lcd/ssd1306.h b/drivers/lcd/ssd1306.h index b75672936e..6c008e7a9b 100644 --- a/drivers/lcd/ssd1306.h +++ b/drivers/lcd/ssd1306.h @@ -234,7 +234,7 @@ struct ssd1306_dev_s #ifdef CONFIG_LCD_SSD1306_SPI FAR struct spi_dev_s *spi; /* Cached SPI device reference */ #else - FAR struct i2c_dev_s *i2c; /* Cached SPI device reference */ + FAR struct i2c_master_s *i2c; /* Cached SPI device reference */ uint8_t addr; /* 7-bit I2C address */ #endif uint8_t contrast; /* Current contrast setting */ diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index b7d76eb9ec..95394e6609 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -807,7 +807,7 @@ static int ssd1306_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) #ifdef CONFIG_LCD_SSD1306_SPI FAR struct lcd_dev_s *ssd1306_initialize(FAR struct spi_dev_s *dev, unsigned int devno) #else -FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_dev_s *dev, unsigned int devno) +FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_master_s *dev, unsigned int devno) #endif { FAR struct ssd1306_dev_s *priv = &g_oleddev; diff --git a/drivers/leds/pca9635pw.c b/drivers/leds/pca9635pw.c index 92f8baaa94..d07b10baab 100644 --- a/drivers/leds/pca9635pw.c +++ b/drivers/leds/pca9635pw.c @@ -54,7 +54,7 @@ struct pca9635pw_dev_s { - FAR struct i2c_dev_s *i2c; + FAR struct i2c_master_s *i2c; uint8_t i2c_addr; }; @@ -351,7 +351,7 @@ static int pca9635pw_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int pca9635pw_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t const pca9635pw_i2c_addr) { /* Sanity check */ diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 8f76e54f65..ef6abe5322 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -150,15 +150,15 @@ struct at24c_dev_s { - struct mtd_dev_s mtd; /* MTD interface */ - FAR struct i2c_dev_s *dev; /* Saved I2C interface instance */ - bool initd; /* True: The device has been initialize */ + struct mtd_dev_s mtd; /* MTD interface */ + FAR struct i2c_master_s *dev; /* Saved I2C interface instance */ + bool initd; /* True: The device has been initialize */ #ifdef CONFIG_AT24XX_EXTENDED - bool extended; /* True: use extended memory region */ + bool extended; /* True: use extended memory region */ #endif - uint8_t addr; /* I2C address */ - uint16_t pagesize; /* 32, 63 */ - uint16_t npages; /* 128, 256, 512, 1024 */ + uint8_t addr; /* I2C address */ + uint16_t pagesize; /* 32, 63 */ + uint16_t npages; /* 128, 256, 512, 1024 */ }; /************************************************************************************ @@ -547,9 +547,9 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) ************************************************************************************/ #ifdef CONFIG_AT24XX_MULTI -FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, uint8_t address) +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev, uint8_t address) #else -FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev) #endif { FAR struct at24c_dev_s *priv; diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c index bf9d3e86da..ad73f9f8ca 100644 --- a/drivers/power/bq2425x.c +++ b/drivers/power/bq2425x.c @@ -93,13 +93,13 @@ struct bq2425x_dev_s /* The common part of the battery driver visible to the upper-half driver */ FAR const struct battery_charger_operations_s *ops; /* Battery operations */ - sem_t batsem; /* Enforce mutually exclusive access */ + sem_t batsem; /* Enforce mutually exclusive access */ /* Data fields specific to the lower half BQ2425x driver follow */ - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ - uint32_t frequency; /* I2C frequency */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + uint32_t frequency; /* I2C frequency */ }; /**************************************************************************** @@ -715,8 +715,9 @@ static int bq2425x_current(struct battery_charger_dev_s *dev, int value) * ****************************************************************************/ -FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c, - uint8_t addr, uint32_t frequency) +FAR struct battery_charger_dev_s * + bq2425x_initialize(FAR struct i2c_master_s *i2c, uint8_t addr, + uint32_t frequency) { FAR struct bq2425x_dev_s *priv; int ret; diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 73fd5b38ca..ff358bda17 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -178,13 +178,13 @@ struct max1704x_dev_s /* The common part of the battery driver visible to the upper-half driver */ FAR const struct battery_gauge_operations_s *ops; /* Battery operations */ - sem_t batsem; /* Enforce mutually exclusive access */ + sem_t batsem; /* Enforce mutually exclusive access */ /* Data fields specific to the lower half MAX1704x driver follow */ - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ - uint32_t frequency; /* I2C frequency */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + uint32_t frequency; /* I2C frequency */ }; /**************************************************************************** @@ -520,7 +520,7 @@ static int max1704x_capacity(struct battery_gauge_dev_s *dev, b16_t *value) * ****************************************************************************/ -FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, +FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_master_s *i2c, uint8_t addr, uint32_t frequency) { diff --git a/drivers/sensors/adxl345.h b/drivers/sensors/adxl345.h index 9a87e9e131..e91fc6b074 100644 --- a/drivers/sensors/adxl345.h +++ b/drivers/sensors/adxl345.h @@ -120,7 +120,7 @@ struct adxl345_dev_s #ifdef CONFIG_ADXL345_SPI FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ #else - FAR struct i2c_dev_s *i2c; /* Saved I2C driver instance */ + FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ #endif uint8_t status; /* See ADXL345_STAT_* definitions */ diff --git a/drivers/sensors/adxl345_base.c b/drivers/sensors/adxl345_base.c index 4b2f95fbde..ff5789e339 100644 --- a/drivers/sensors/adxl345_base.c +++ b/drivers/sensors/adxl345_base.c @@ -384,7 +384,7 @@ static void adxl345_reset(FAR struct adxl345_dev_s *priv) ADXL345_HANDLE adxl345_instantiate(FAR struct spi_dev_s *dev, FAR struct adxl345_config_s *config) #else -ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_dev_s *dev, +ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_master_s *dev, FAR struct adxl345_config_s *config) #endif { diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index cd56af85a1..7ee52e1f0f 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -57,9 +57,9 @@ struct as5048b_dev_s { - struct qe_lowerhalf_s lower; /* AS5048B quadrature encoder lower half */ - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ + struct qe_lowerhalf_s lower; /* AS5048B quadrature encoder lower half */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ }; /**************************************************************************** @@ -577,7 +577,7 @@ static int as5048b_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, * ****************************************************************************/ -FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_dev_s *i2c, +FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_master_s *i2c, uint8_t addr) { FAR struct as5048b_dev_s *priv; diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index 8ffc326c26..ce16dd94e4 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -110,10 +110,10 @@ struct bmp180_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* BMP180 I2C address */ - int freq; /* BMP180 Frequency <= 3.4MHz */ - int16_t bmp180_cal_ac1; /* Calibration coefficients */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* BMP180 I2C address */ + int freq; /* BMP180 Frequency <= 3.4MHz */ + int16_t bmp180_cal_ac1; /* Calibration coefficients */ int16_t bmp180_cal_ac2; int16_t bmp180_cal_ac3; uint16_t bmp180_cal_ac4; @@ -124,8 +124,8 @@ struct bmp180_dev_s int16_t bmp180_cal_mb; int16_t bmp180_cal_mc; int16_t bmp180_cal_md; - int32_t bmp180_utemp; /* Uncompensated temperature read from BMP180 */ - int32_t bmp180_upress; /* Uncompensated pressure read from BMP180 */ + int32_t bmp180_utemp; /* Uncompensated temperature read from BMP180 */ + int32_t bmp180_upress; /* Uncompensated pressure read from BMP180 */ }; /**************************************************************************** @@ -569,7 +569,7 @@ static ssize_t bmp180_write(FAR struct file *filep, FAR const char *buffer, * ****************************************************************************/ -int bmp180_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c) +int bmp180_register(FAR const char *devpath, FAR struct i2c_master_s *i2c) { FAR struct bmp180_dev_s *priv; int ret; diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index 4087579fd6..7802eb086a 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -93,7 +93,7 @@ struct lis331dl_dev_s { - struct i2c_dev_s *i2c; + struct i2c_master_s *i2c; uint8_t address; struct lis331dl_vector_s a; uint8_t cr1; @@ -217,7 +217,7 @@ static int lis331dl_readregs(FAR struct lis331dl_dev_s *dev) * Public Functions ****************************************************************************/ -FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_dev_s *i2c, +FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c, uint16_t address) { FAR struct lis331dl_dev_s * dev; diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 05f6f890ef..609377f69e 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -67,9 +67,9 @@ struct lm75_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ - bool fahrenheit; /* true: temperature will be reported in fahrenheit */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + bool fahrenheit; /* true: temperature will be reported in fahrenheit */ }; /**************************************************************************** @@ -503,7 +503,7 @@ static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr) +int lm75_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { FAR struct lm75_dev_s *priv; int ret; diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 3159333721..432445e30c 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -69,9 +69,9 @@ struct lm92_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ - bool fahrenheit; /* true: temperature will be reported in Fahrenheit */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ + bool fahrenheit; /* true: temperature will be reported in Fahrenheit */ }; /**************************************************************************** @@ -595,7 +595,7 @@ static int lm92_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lm92_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { FAR struct lm92_dev_s *priv; diff --git a/drivers/sensors/lsm9ds1.c b/drivers/sensors/lsm9ds1.c index 047591052a..bdde5cdc35 100644 --- a/drivers/sensors/lsm9ds1.c +++ b/drivers/sensors/lsm9ds1.c @@ -500,7 +500,7 @@ struct lsm9ds1_ops_s struct lsm9ds1_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ + FAR struct i2c_master_s *i2c; /* I2C interface */ uint8_t addr; /* I2C address */ FAR const struct lsm9ds1_ops_s *ops; @@ -567,7 +567,7 @@ static int lsm9ds1_ioctl(FAR struct file *filep, int cmd, /* Common Register Function */ static int lsm9ds1_register(FAR const char *devpath, - FAR struct i2c_dev_s *i2c, uint8_t addr, + FAR struct i2c_master_s *i2c, uint8_t addr, FAR const struct lsm9ds1_ops_s *ops, uint8_t datareg); @@ -1413,7 +1413,7 @@ static int lsm9ds1_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ****************************************************************************/ static int lsm9ds1_register(FAR const char *devpath, - FAR struct i2c_dev_s *i2c, uint8_t addr, + FAR struct i2c_master_s *i2c, uint8_t addr, FAR const struct lsm9ds1_ops_s *ops, uint8_t datareg) { @@ -1486,7 +1486,7 @@ static int lsm9ds1_register(FAR const char *devpath, * ****************************************************************************/ -int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { /* Sanity check */ @@ -1513,7 +1513,7 @@ int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, * ****************************************************************************/ -int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { /* Sanity check */ @@ -1540,7 +1540,7 @@ int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, * ****************************************************************************/ -int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { /* Sanity check */ diff --git a/drivers/sensors/mb7040.c b/drivers/sensors/mb7040.c index 22ed726eae..3741761ca2 100644 --- a/drivers/sensors/mb7040.c +++ b/drivers/sensors/mb7040.c @@ -57,8 +57,8 @@ struct mb7040_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ }; /**************************************************************************** @@ -336,7 +336,7 @@ static int mb7040_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int mb7040_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int mb7040_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { FAR struct mb7040_dev_s *priv; diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c index 92f738d6fb..b8e5c90851 100644 --- a/drivers/sensors/mcp9844.c +++ b/drivers/sensors/mcp9844.c @@ -56,8 +56,8 @@ struct mcp9844_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ }; /**************************************************************************** @@ -317,7 +317,7 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int mcp9844_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int mcp9844_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr) { /* Sanity check */ diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 58d9ec8b32..36c6ac07ef 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -75,18 +75,18 @@ struct ms58xx_dev_s { - FAR struct i2c_dev_s *i2c; /* I2C interface */ - uint8_t addr; /* I2C address */ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ enum ms58xx_model_e model; uint8_t crcindex; uint8_t crcshift; - int32_t temp; /* Uncompensated temperature (degrees Centigrade) */ - int32_t press; /* Uncompensated pressure (millibar) */ + int32_t temp; /* Uncompensated temperature (degrees Centigrade) */ + int32_t press; /* Uncompensated pressure (millibar) */ - uint8_t osr; /* Oversampling ratio bits */ - useconds_t delay; /* Oversampling ratio delay */ + uint8_t osr; /* Oversampling ratio bits */ + useconds_t delay; /* Oversampling ratio delay */ /* Calibration coefficients */ @@ -838,7 +838,7 @@ static int ms58xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -int ms58xx_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int ms58xx_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr, uint16_t osr, enum ms58xx_model_e model) { FAR struct ms58xx_dev_s *priv; diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index aede53b9d2..0dd27bc754 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -108,7 +108,7 @@ struct ds3231_dev_s { - FAR struct i2c_dev_s *i2c; /* Contained reference to the I2C bus driver */ + FAR struct i2c_master_s *i2c; /* Contained reference to the I2C bus driver */ }; /************************************************************************************ @@ -237,7 +237,7 @@ static int rtc_bcd2bin(uint8_t value) * ************************************************************************************/ -int dsxxxx_rtc_initialize(FAR struct i2c_dev_s *i2c) +int dsxxxx_rtc_initialize(FAR struct i2c_master_s *i2c) { /* Remember the i2c device and claim that the RTC is enabled */ diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 5d50240f7b..ac6359c9da 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -108,7 +108,7 @@ struct pcf85263_dev_s { - FAR struct i2c_dev_s *i2c; /* Contained reference to the I2C bus driver */ + FAR struct i2c_master_s *i2c; /* Contained reference to the I2C bus driver */ }; /************************************************************************************ @@ -237,7 +237,7 @@ static int rtc_bcd2bin(uint8_t value) * ************************************************************************************/ -int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c) +int pcf85263_rtc_initialize(FAR struct i2c_master_s *i2c) { /* Remember the i2c device and claim that the RTC is enabled */ diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 58b38f974f..67322ff3b7 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -286,16 +286,16 @@ struct ovr2640_reg_s /* OV2640 register operations */ -static int ov2640_putreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr, +static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, uint8_t regval); -static uint8_t ov2640_getreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr); -static int ov2640_putreglist(FAR struct i2c_dev_s *i2c, +static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr); +static int ov2640_putreglist(FAR struct i2c_master_s *i2c, FAR const struct ovr2640_reg_s *reglist, size_t nentries); /* Initialization */ -static int ovr2640_chipid(FAR struct i2c_dev_s *i2c); -static int ov2640_reset(FAR struct i2c_dev_s *i2c); +static int ovr2640_chipid(FAR struct i2c_master_s *i2c); +static int ov2640_reset(FAR struct i2c_master_s *i2c); /**************************************************************************** * Private Data @@ -687,7 +687,7 @@ static const struct ovr2640_reg_s g_ov2640_jpeg_uxga_resolution[] = * ****************************************************************************/ -static int ov2640_putreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr, +static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, uint8_t regval) { uint8_t buffer[2]; @@ -731,7 +731,7 @@ static int ov2640_putreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr, * ****************************************************************************/ -static uint8_t ov2640_getreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr) +static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr) { uint8_t regval; int ret; @@ -780,7 +780,7 @@ static uint8_t ov2640_getreg(FAR struct i2c_dev_s *i2c, uint8_t regaddr) * ****************************************************************************/ -static int ov2640_putreglist(FAR struct i2c_dev_s *i2c, +static int ov2640_putreglist(FAR struct i2c_master_s *i2c, FAR const struct ovr2640_reg_s *reglist, size_t nentries) { @@ -815,7 +815,7 @@ static int ov2640_putreglist(FAR struct i2c_dev_s *i2c, * ****************************************************************************/ -static int ovr2640_chipid(FAR struct i2c_dev_s *i2c) +static int ovr2640_chipid(FAR struct i2c_master_s *i2c) { uint8_t pidl; uint8_t pidh; @@ -870,7 +870,7 @@ static int ovr2640_chipid(FAR struct i2c_dev_s *i2c) * ****************************************************************************/ -static int ov2640_reset(FAR struct i2c_dev_s *i2c) +static int ov2640_reset(FAR struct i2c_master_s *i2c) { int ret; @@ -903,7 +903,7 @@ static int ov2640_reset(FAR struct i2c_dev_s *i2c) * ****************************************************************************/ -int ov2640_initialize(FAR struct i2c_dev_s *i2c) +int ov2640_initialize(FAR struct i2c_master_s *i2c) { int ret; diff --git a/include/nuttx/audio/wm8904.h b/include/nuttx/audio/wm8904.h index 983a205e3d..a10c69739e 100644 --- a/include/nuttx/audio/wm8904.h +++ b/include/nuttx/audio/wm8904.h @@ -214,12 +214,12 @@ extern "C" * ****************************************************************************/ -struct i2c_dev_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */ +struct i2c_master_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */ struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */ struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */ FAR struct audio_lowerhalf_s * - wm8904_initialize(FAR struct i2c_dev_s *i2c, FAR struct i2s_dev_s *i2s, + wm8904_initialize(FAR struct i2c_master_s *i2c, FAR struct i2s_dev_s *i2s, FAR const struct wm8904_lower_s *lower); /**************************************************************************** diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 2216026340..a90beda0c3 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -47,17 +47,6 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* If a dynamic timeout is selected, then a non-negative, non-zero micro- - * seconds per byte value must be provided as well. - */ - -#ifdef CONFIG_STM32_I2C_DYNTIMEO -# if CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE < 1 -# warning "Ignoring CONFIG_STM32_I2C_DYNTIMEO because of CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE" -# undef CONFIG_STM32_I2C_DYNTIMEO -# endif -#endif - /* I2C address calculation. Convert 7- and 10-bit address to 8-bit and * 16-bit read/write address */ @@ -95,7 +84,7 @@ * * Description: * Set the I2C frequency. This frequency will be retained in the struct - * i2c_dev_s instance and will be used with all transfers. Required. + * i2c_master_s instance and will be used with all transfers. Required. * * Input Parameters: * dev - Device-specific state data @@ -113,7 +102,7 @@ * * Description: * Set the I2C slave address. This frequency will be retained in the struct - * i2c_dev_s instance and will be used with all transfers. Required. + * i2c_master_s instance and will be used with all transfers. Required. * * Input Parameters: * dev - Device-specific state data @@ -127,32 +116,6 @@ #define I2C_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n)) -/**************************************************************************** - * Name: I2C_SETOWNADDRESS - * - * Description: - * Set our own I2C address. Calling this function enables Slave mode and - * disables Master mode on given instance (note that I2C is a bus, where - * multiple masters and slave may be handled by one device driver). - * - * One may register a callback to be notified about reception. During the - * slave mode reception, the function READ and WRITE must be used to - * to handle reads and writes from a master. - * - * Input Parameters: - * dev - Device-specific state data - * address - Our own slave address; If it is 0x00, then the device driver - * listens to general call - * nbits - The number of address bits provided (7 or 10) - * - * Returned Value: - * OK on valid address and if the same address has not been assigned - * to another instance sharing the same port. Otherwise ERROR is returned. - * - ****************************************************************************/ - -#define I2C_SETOWNADDRESS(d,a,n) ((d)->ops->setownaddress(d,a,n)) - /**************************************************************************** * Name: I2C_WRITE * @@ -222,25 +185,20 @@ /* The I2C vtable */ -struct i2c_dev_s; +struct i2c_master_s; struct i2c_msg_s; struct i2c_ops_s { - uint32_t (*setfrequency)(FAR struct i2c_dev_s *dev, uint32_t frequency); - int (*setaddress)(FAR struct i2c_dev_s *dev, int addr, int nbits); - int (*write)(FAR struct i2c_dev_s *dev, FAR const uint8_t *buffer, + uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency); + int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits); + int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer, int buflen); - int (*read)(FAR struct i2c_dev_s *dev, FAR uint8_t *buffer, + int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer, int buflen); #ifdef CONFIG_I2C_TRANSFER - int (*transfer)(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, + int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count); #endif -#ifdef CONFIG_I2C_SLAVE - int (*setownaddress)(FAR struct i2c_dev_s *dev, int addr, int nbits); - int (*registercallback)(FAR struct i2c_dev_s *dev, - int (*callback)(FAR void *arg), FAR void *arg); -#endif }; /* This structure contains the full state of I2C as needed for a specific @@ -273,7 +231,7 @@ struct i2c_msg_s * add additional, device specific fields after the vtable. */ -struct i2c_dev_s +struct i2c_master_s { const struct i2c_ops_s *ops; /* I2C vtable */ }; @@ -296,7 +254,7 @@ extern "C" * * Description: * Initialize the selected I2C port. And return a unique instance of struct - * struct i2c_dev_s. This function may be called to obtain multiple + * struct i2c_master_s. This function may be called to obtain multiple * instances of the interface, each of which may be set up with a * different frequency and slave address. * @@ -308,7 +266,7 @@ extern "C" * ****************************************************************************/ -FAR struct i2c_dev_s *up_i2cinitialize(int port); +FAR struct i2c_master_s *up_i2cinitialize(int port); /**************************************************************************** * Name: up_i2cuninitialize @@ -325,7 +283,7 @@ FAR struct i2c_dev_s *up_i2cinitialize(int port); * ****************************************************************************/ -int up_i2cuninitialize(FAR struct i2c_dev_s *dev); +int up_i2cuninitialize(FAR struct i2c_master_s *dev); /************************************************************************************ * Name: up_i2creset @@ -336,7 +294,7 @@ int up_i2cuninitialize(FAR struct i2c_dev_s *dev); ************************************************************************************/ #ifdef CONFIG_I2C_RESET -int up_i2creset(FAR struct i2c_dev_s *dev); +int up_i2creset(FAR struct i2c_master_s *dev); #endif /**************************************************************************** @@ -360,7 +318,7 @@ int up_i2creset(FAR struct i2c_dev_s *dev); ****************************************************************************/ #ifdef CONFIG_I2C_TRANSFER -int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, int rbuflen); #endif @@ -385,7 +343,7 @@ int i2c_writeread(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *conf ****************************************************************************/ #ifdef CONFIG_I2C_TRANSFER -int i2c_write(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_write(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR const uint8_t *buffer, int buflen); #endif @@ -409,7 +367,7 @@ int i2c_write(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, ****************************************************************************/ #ifdef CONFIG_I2C_TRANSFER -int i2c_read(FAR struct i2c_dev_s *dev, FAR const struct i2c_config_s *config, +int i2c_read(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR uint8_t *buffer, int buflen); #endif diff --git a/include/nuttx/input/mxt.h b/include/nuttx/input/mxt.h index aecc042c33..4498be11c2 100644 --- a/include/nuttx/input/mxt.h +++ b/include/nuttx/input/mxt.h @@ -199,7 +199,7 @@ extern "C" * ****************************************************************************/ -int mxt_register(FAR struct i2c_dev_s *i2c, +int mxt_register(FAR struct i2c_master_s *i2c, FAR const struct mxt_lower_s *lower, int minor); #undef EXTERN diff --git a/include/nuttx/input/stmpe811.h b/include/nuttx/input/stmpe811.h index 4c64b4005d..6cf96e6a7f 100644 --- a/include/nuttx/input/stmpe811.h +++ b/include/nuttx/input/stmpe811.h @@ -549,7 +549,7 @@ extern "C" STMPE811_HANDLE stmpe811_instantiate(FAR struct spi_dev_s *dev, FAR struct stmpe811_config_s *config); #else -STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_dev_s *dev, +STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev, FAR struct stmpe811_config_s *config); #endif diff --git a/include/nuttx/input/tsc2007.h b/include/nuttx/input/tsc2007.h index 468878f830..1517fd488a 100644 --- a/include/nuttx/input/tsc2007.h +++ b/include/nuttx/input/tsc2007.h @@ -160,7 +160,7 @@ extern "C" * ****************************************************************************/ -int tsc2007_register(FAR struct i2c_dev_s *dev, +int tsc2007_register(FAR struct i2c_master_s *dev, FAR struct tsc2007_config_s *config, int minor); #undef EXTERN diff --git a/include/nuttx/ioexpander/pca9555.h b/include/nuttx/ioexpander/pca9555.h index 2a0e4200d1..aa0b3c2863 100644 --- a/include/nuttx/ioexpander/pca9555.h +++ b/include/nuttx/ioexpander/pca9555.h @@ -110,7 +110,7 @@ extern "C" * ********************************************************************************************/ -FAR struct ioexpander_dev_s* pca9555_initialize(FAR struct i2c_dev_s *dev, +FAR struct ioexpander_dev_s* pca9555_initialize(FAR struct i2c_master_s *dev, FAR struct pca9555_config_s *config); #ifdef __cplusplus diff --git a/include/nuttx/lcd/ssd1306.h b/include/nuttx/lcd/ssd1306.h index ea80189c46..286c573e3a 100644 --- a/include/nuttx/lcd/ssd1306.h +++ b/include/nuttx/lcd/ssd1306.h @@ -243,7 +243,7 @@ struct spi_dev_s; /* See include/nuttx/spi/spi.h */ #ifdef CONFIG_LCD_SSD1306_SPI FAR struct lcd_dev_s *ssd1306_initialize(FAR struct spi_dev_s *dev, unsigned int devno); #else -FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_dev_s *dev, unsigned int devno); +FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_master_s *dev, unsigned int devno); #endif /************************************************************************************************ diff --git a/include/nuttx/leds/pca9635pw.h b/include/nuttx/leds/pca9635pw.h index a65610ca15..9872cb1b8b 100644 --- a/include/nuttx/leds/pca9635pw.h +++ b/include/nuttx/leds/pca9635pw.h @@ -157,7 +157,7 @@ struct pca9635pw_setled_brightness_arg_s * Forward declarations ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Types @@ -189,7 +189,7 @@ extern "C" * ****************************************************************************/ -int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int pca9635pw_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t const pca9635pw_i2c_addr); #undef EXTERN diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 39803509f8..f17b7d3b70 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -381,13 +381,13 @@ FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *dev); * ****************************************************************************/ -struct i2c_dev_s; /* Forward reference */ +struct i2c_master_s; /* Forward reference */ #ifdef CONFIG_AT24XX_MULTI -FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev, uint8_t address); #else -FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev); #endif /************************************************************************************ diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index a2ce96196d..d90db10154 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -217,9 +217,9 @@ int battery_charger_register(FAR const char *devpath, ****************************************************************************/ #if defined(CONFIG_I2C) && defined(CONFIG_I2C_BQ2425X) -struct i2c_dev_s; /* Forward reference */ +struct i2c_master_s; /* Forward reference */ -FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_dev_s *i2c, +FAR struct battery_charger_dev_s *bq2425x_initialize(FAR struct i2c_master_s *i2c, uint8_t addr, uint32_t frequency); #endif diff --git a/include/nuttx/power/battery_gauge.h b/include/nuttx/power/battery_gauge.h index d087f2213c..8351faee8c 100644 --- a/include/nuttx/power/battery_gauge.h +++ b/include/nuttx/power/battery_gauge.h @@ -198,9 +198,9 @@ int battery_gauge_register(FAR const char *devpath, ****************************************************************************/ #if defined(CONFIG_I2C) && defined(CONFIG_I2C_MAX1704X) -struct i2c_dev_s; /* Forward reference */ +struct i2c_master_s; /* Forward reference */ -FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c +FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_master_s *i2c uint8_t addr, uint32_t frequency); #endif diff --git a/include/nuttx/sensors/adxl345.h b/include/nuttx/sensors/adxl345.h index 9655e84f69..23409efe80 100644 --- a/include/nuttx/sensors/adxl345.h +++ b/include/nuttx/sensors/adxl345.h @@ -325,7 +325,7 @@ struct adxl345_config_s typedef FAR void *ADXL345_HANDLE; -struct i2c_dev_s; +struct i2c_master_s; struct spi_dev_s; /******************************************************************************************** @@ -361,7 +361,7 @@ extern "C" ADXL345_HANDLE adxl345_instantiate(FAR struct spi_dev_s *dev, FAR struct adxl345_config_s *config); #else -ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_dev_s *dev, +ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_master_s *dev, FAR struct adxl345_config_s *config); #endif diff --git a/include/nuttx/sensors/as5048b.h b/include/nuttx/sensors/as5048b.h index 6a6de4eef0..9a274d90ae 100644 --- a/include/nuttx/sensors/as5048b.h +++ b/include/nuttx/sensors/as5048b.h @@ -99,7 +99,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -129,7 +129,7 @@ extern "C" * ****************************************************************************/ -FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_dev_s *i2c, +FAR struct qe_lowerhalf_s *as5048b_initialize(FAR struct i2c_master_s *i2c, uint8_t addr); #undef EXTERN diff --git a/include/nuttx/sensors/bmp180.h b/include/nuttx/sensors/bmp180.h index 505aa72488..0c12e24226 100644 --- a/include/nuttx/sensors/bmp180.h +++ b/include/nuttx/sensors/bmp180.h @@ -59,7 +59,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /******************************************************************************************** * Public Function Prototypes @@ -89,7 +89,7 @@ extern "C" * ****************************************************************************/ -int bmp180_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c); +int bmp180_register(FAR const char *devpath, FAR struct i2c_master_s *i2c); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/sensors/lis331dl.h b/include/nuttx/sensors/lis331dl.h index 6006288463..db4c4317d9 100644 --- a/include/nuttx/sensors/lis331dl.h +++ b/include/nuttx/sensors/lis331dl.h @@ -71,7 +71,7 @@ struct lis331dl_vector_s int8_t z; }; -struct i2c_dev_s; +struct i2c_master_s; /************************************************************************************ * Public Function Prototypes @@ -100,7 +100,7 @@ struct i2c_dev_s; * ************************************************************************************/ -FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_dev_s * i2c, +FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s * i2c, uint16_t address); /************************************************************************************ diff --git a/include/nuttx/sensors/lm75.h b/include/nuttx/sensors/lm75.h index a343a54874..827620adab 100644 --- a/include/nuttx/sensors/lm75.h +++ b/include/nuttx/sensors/lm75.h @@ -99,7 +99,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -131,7 +131,7 @@ extern "C" * ****************************************************************************/ -int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lm75_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); #undef EXTERN diff --git a/include/nuttx/sensors/lm92.h b/include/nuttx/sensors/lm92.h index 16266568a8..8b49a0da93 100644 --- a/include/nuttx/sensors/lm92.h +++ b/include/nuttx/sensors/lm92.h @@ -106,7 +106,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -139,7 +139,7 @@ extern "C" * ****************************************************************************/ -int lm92_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lm92_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); #undef EXTERN diff --git a/include/nuttx/sensors/lsm9ds1.h b/include/nuttx/sensors/lsm9ds1.h index d69ca9e808..cf3ef1b3c7 100644 --- a/include/nuttx/sensors/lsm9ds1.h +++ b/include/nuttx/sensors/lsm9ds1.h @@ -75,7 +75,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -102,7 +102,7 @@ extern "C" * ****************************************************************************/ -int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); /**************************************************************************** @@ -121,7 +121,7 @@ int lsm9ds1accel_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, * ****************************************************************************/ -int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); /**************************************************************************** @@ -140,7 +140,7 @@ int lsm9ds1gyro_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, * ****************************************************************************/ -int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int lsm9ds1mag_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); #ifdef __cplusplus diff --git a/include/nuttx/sensors/mb7040.h b/include/nuttx/sensors/mb7040.h index f3359ea1f3..0280ecadb6 100644 --- a/include/nuttx/sensors/mb7040.h +++ b/include/nuttx/sensors/mb7040.h @@ -78,7 +78,7 @@ * Public Types ****************************************************************************/ -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -108,7 +108,7 @@ extern "C" * ****************************************************************************/ -int mb7040_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int mb7040_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); #undef EXTERN diff --git a/include/nuttx/sensors/mcp9844.h b/include/nuttx/sensors/mcp9844.h index 68276b8487..97a8f2bda3 100644 --- a/include/nuttx/sensors/mcp9844.h +++ b/include/nuttx/sensors/mcp9844.h @@ -86,7 +86,7 @@ enum mcp9844_resolution_e RES_0_0625 = MCP9844_RESO_REG_BIT_1 | MCP9844_RESO_REG_BIT_0 }; -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -116,7 +116,7 @@ extern "C" * ****************************************************************************/ -int mcp9844_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int mcp9844_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr); #undef EXTERN diff --git a/include/nuttx/sensors/ms58xx.h b/include/nuttx/sensors/ms58xx.h index 3ad6bd3107..fb20a3b212 100644 --- a/include/nuttx/sensors/ms58xx.h +++ b/include/nuttx/sensors/ms58xx.h @@ -87,7 +87,7 @@ enum ms58xx_model_e MS58XX_MODEL_MS5837_30 = 7 }; -struct i2c_dev_s; +struct i2c_master_s; /**************************************************************************** * Public Function Prototypes @@ -119,7 +119,7 @@ extern "C" * ****************************************************************************/ -int ms58xx_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, +int ms58xx_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr, uint16_t osr, enum ms58xx_model_e model); #undef EXTERN diff --git a/include/nuttx/timers/cs2100-cp.h b/include/nuttx/timers/cs2100-cp.h index 8ef8bb726c..dcff2851e0 100644 --- a/include/nuttx/timers/cs2100-cp.h +++ b/include/nuttx/timers/cs2100-cp.h @@ -163,13 +163,13 @@ struct cs2100_config_s { - FAR struct i2c_dev_s *i2c; /* Instance of an I2C interface */ - uint32_t refclk; /* RefClk/XTAL frequency */ - uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */ - uint32_t clkout; /* Desired CLK_OUT frequency */ - uint8_t i2caddr; /* CP2100-CP I2C address */ - uint8_t loopbw; /* Minimum loop bandwidth: 1-128 */ - bool xtal; /* false: Refclck, true: Crystal on XTI/XTO */ + FAR struct i2c_master_s *i2c; /* Instance of an I2C interface */ + uint32_t refclk; /* RefClk/XTAL frequency */ + uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */ + uint32_t clkout; /* Desired CLK_OUT frequency */ + uint8_t i2caddr; /* CP2100-CP I2C address */ + uint8_t loopbw; /* Minimum loop bandwidth: 1-128 */ + bool xtal; /* false: Refclck, true: Crystal on XTI/XTO */ }; /******************************************************************************************** @@ -188,7 +188,7 @@ extern "C" * Public Function Prototypes ********************************************************************************************/ -struct i2c_dev_s; /* Forward reference */ +struct i2c_master_s; /* Forward reference */ /******************************************************************************************** * Name: cs2100_enable diff --git a/include/nuttx/timers/ds3231.h b/include/nuttx/timers/ds3231.h index b3f239e3ad..2aa0cfcf54 100644 --- a/include/nuttx/timers/ds3231.h +++ b/include/nuttx/timers/ds3231.h @@ -78,8 +78,8 @@ extern "C" * ************************************************************************************/ -struct i2c_dev_s; /* Forward reference */ -int dsxxxx_rtc_initialize(FAR struct i2c_dev_s *i2c); +struct i2c_master_s; /* Forward reference */ +int dsxxxx_rtc_initialize(FAR struct i2c_master_s *i2c); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/timers/pcf85263.h b/include/nuttx/timers/pcf85263.h index fdda2b815e..4018e1ca65 100644 --- a/include/nuttx/timers/pcf85263.h +++ b/include/nuttx/timers/pcf85263.h @@ -78,8 +78,8 @@ extern "C" * ************************************************************************************/ -struct i2c_dev_s; /* Forward reference */ -int pcf85263_rtc_initialize(FAR struct i2c_dev_s *i2c); +struct i2c_master_s; /* Forward reference */ +int pcf85263_rtc_initialize(FAR struct i2c_master_s *i2c); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/video/ov2640.h b/include/nuttx/video/ov2640.h index 4c037fdea2..b398994d97 100644 --- a/include/nuttx/video/ov2640.h +++ b/include/nuttx/video/ov2640.h @@ -77,8 +77,8 @@ extern "C" * ****************************************************************************/ -struct i2c_dev_s; -int ov2640_initialize(FAR struct i2c_dev_s *i2c); +struct i2c_master_s; +int ov2640_initialize(FAR struct i2c_master_s *i2c); #undef EXTERN #ifdef __cplusplus -- GitLab From cccfb11e3887254482ca086738971aea415b0575 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 08:49:20 -0600 Subject: [PATCH 653/858] Forgot to add a file in the last commit --- include/nuttx/i2c/i2c_master.h | 15 ++- include/nuttx/i2c/i2c_slave.h | 231 +++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 include/nuttx/i2c/i2c_slave.h diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index a90beda0c3..b181beca28 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -42,6 +42,7 @@ #include +#include #include /**************************************************************************** @@ -208,9 +209,9 @@ struct i2c_ops_s struct i2c_config_s { - uint32_t frequency; /* I2C frequency */ - uint16_t address; /* I2C address (7 or 10 bit) */ - uint8_t addrlen; /* I2C address length (7 or 10 bits) */ + uint32_t frequency; /* I2C frequency */ + uint16_t address; /* I2C address (7- or 10-bit) */ + uint8_t addrlen; /* I2C address length (7 or 10 bits) */ }; /* I2C transaction segment beginning with a START. A number of these can @@ -220,10 +221,10 @@ struct i2c_config_s struct i2c_msg_s { - uint16_t addr; /* Slave address */ - uint16_t flags; /* See I2C_M_* definitions */ - uint8_t *buffer; - int length; + uint16_t addr; /* Slave address (7- or 10-bit) */ + uint16_t flags; /* See I2C_M_* definitions */ + uint8_t *buffer; /* Buffer to be transferred */ + ssize_t length; /* Length of the buffer in byetes */ }; /* I2C private data. This structure only defines the initial fields of the diff --git a/include/nuttx/i2c/i2c_slave.h b/include/nuttx/i2c/i2c_slave.h new file mode 100644 index 0000000000..5d1632908f --- /dev/null +++ b/include/nuttx/i2c/i2c_slave.h @@ -0,0 +1,231 @@ +/**************************************************************************** + * include/nuttx/i2c/i2c_slave.h + * + * Copyright(C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_I2C_I2C_SLAVE_H +#define __INCLUDE_NUTTX_I2C_I2C_SLAVE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_I2C_SLAVE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* I2C address calculation. Convert 7- and 10-bit address to 8-bit and + * 16-bit read/write address + */ + +#define I2CS_READBIT 0x01 + +/* Convert 7- to 8-bit address */ + +#define I2CS_ADDR8(a) ((a) << 1) +#define I2CS_WRITEADDR8(a) I2CS_ADDR8(a) +#define I2CS_READADDR8(a) (I2CS_ADDR8(a) | I2CS_READBIT) + +/* Convert 10- to 16-bit address */ + +#define I2CS_ADDR10H(a) (0xf0 | (((a) >> 7) & 0x06)) +#define I2CS_ADDR10L(a) ((a) & 0xff) + +#define I2CS_WRITEADDR10H(a) I2CS_ADDR10H(a) +#define I2CS_WRITEADDR10L(a) I2CS_ADDR10L(a) + +#define I2CS_READADDR10H(a) (I2CS_ADDR10H(a) | I2CS_READBIT) +#define I2CS_READADDR10L(a) I2CS_ADDR10L(a) + +/* Access macros ************************************************************/ + +/**************************************************************************** + * Name: I2CS_SETFREQUENCY + * + * Description: + * Set the I2C frequency. This frequency will be retained in the struct + * i2c_slave_s instance and will be used with all transfers. Required. + * + * Input Parameters: + * dev - Device-specific state data + * frequency - The I2C frequency requested + * + * Returned Value: + * Returns the actual frequency selected + * + ****************************************************************************/ + +#define I2CS_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) + +/**************************************************************************** + * Name: I2CS_SETADDRESS + * + * Description: + * Set the I2C slave address. This frequency will be retained in the struct + * i2c_slave_s instance and will be used with all transfers. Required. + * + * Input Parameters: + * dev - Device-specific state data + * address - The I2C slave address + * nbits - The number of address bits provided (7 or 10) + * + * Returned Value: + * Returns OK on success; a negated errno on failure. + * + ****************************************************************************/ + +#define I2CS_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n)) + +/**************************************************************************** + * Name: I2CS_SETOWNADDRESS + * + * Description: + * Set our own I2C address. Calling this function enables Slave mode and + * disables Master mode on given instance (note that I2C is a bus, where + * multiple masters and slave may be handled by one device driver). + * + * One may register a callback to be notified about reception. During the + * slave mode reception, the function READ and WRITE must be used to + * to handle reads and writes from a master. + * + * Input Parameters: + * dev - Device-specific state data + * address - Our own slave address; If it is 0x00, then the device driver + * listens to general call + * nbits - The number of address bits provided (7 or 10) + * + * Returned Value: + * OK on valid address and if the same address has not been assigned + * to another instance sharing the same port. Otherwise ERROR is returned. + * + ****************************************************************************/ + +#define I2CS_SETOWNADDRESS(d,a,n) ((d)->ops->setownaddress(d,a,n)) + +/**************************************************************************** + * Name: I2CS_WRITE + * + * Description: + * Send a block of data on I2C using the previously selected I2C + * frequency and slave address. Each write operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this write completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to the read-only buffer of data to be written to device + * buflen - The number of bytes to send from the buffer + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +#define I2CS_WRITE(d,b,l) ((d)->ops->write(d,b,l)) + +/**************************************************************************** + * Name: I2CS_READ + * + * Description: + * Receive a block of data from I2C using the previously selected I2C + * frequency and slave address. Each read operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this read completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to a buffer of data to receive the data from the device + * buflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +#define I2CS_READ(d,b,l) ((d)->ops->read(d,b,l)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* The I2C vtable */ + +struct i2c_slave_s; +struct i2c_slaveops_s +{ + uint32_t (*setfrequency)(FAR struct i2c_slave_s *dev, uint32_t frequency); + int (*setaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); + int (*write)(FAR struct i2c_slave_s *dev, FAR const uint8_t *buffer, + int buflen); + int (*read)(FAR struct i2c_slave_s *dev, FAR uint8_t *buffer, + int buflen); + int (*setownaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); + int (*registercallback)(FAR struct i2c_slave_s *dev, + int (*callback)(FAR void *arg), FAR void *arg); +}; + +/* I2C private data. This structure only defines the initial fields of the + * structure visible to the I2C client. The specific implementation may + * add additional, device specific fields after the vtable. + */ + +struct i2c_slave_s +{ + const struct i2c_slaveops_s *ops; /* I2C vtable */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* CONFIG_I2C_SLAVE */ +#endif /* __INCLUDE_NUTTX_I2C_I2C_SLAVE_H */ -- GitLab From af335827d07b721e89a99d4afcf3131e379de94d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 11:27:49 -0600 Subject: [PATCH 654/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- include/nuttx/i2c/i2c_slave.h | 44 +++++++++++++++++------------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index abe8b13bd7..6794e32148 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11419,4 +11419,8 @@ * drivers/modem/u-blox.c and include/nuttx/drivers/u-blox.h: Add an upper half driver for the U-Blox Modem. From Vladimir Komendantskiy (2018-01-30). + * arch/arm/src/lpc17xx: Backport lpc43xx I2C driver, replacing the + the lpc17xx I2C drivers. This gives use the I2C_TRANSFER method. + (2016-01-30). + diff --git a/arch b/arch index 5ea918534a..150916cbf9 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5ea918534aef71cdff40f56081c70de8818cb5bc +Subproject commit 150916cbf96b04752df6874a7eccc6e52ace3815 diff --git a/include/nuttx/i2c/i2c_slave.h b/include/nuttx/i2c/i2c_slave.h index 5d1632908f..7f43316497 100644 --- a/include/nuttx/i2c/i2c_slave.h +++ b/include/nuttx/i2c/i2c_slave.h @@ -92,35 +92,16 @@ #define I2CS_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) -/**************************************************************************** - * Name: I2CS_SETADDRESS - * - * Description: - * Set the I2C slave address. This frequency will be retained in the struct - * i2c_slave_s instance and will be used with all transfers. Required. - * - * Input Parameters: - * dev - Device-specific state data - * address - The I2C slave address - * nbits - The number of address bits provided (7 or 10) - * - * Returned Value: - * Returns OK on success; a negated errno on failure. - * - ****************************************************************************/ - -#define I2CS_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n)) - /**************************************************************************** * Name: I2CS_SETOWNADDRESS * * Description: * Set our own I2C address. Calling this function enables Slave mode and - * disables Master mode on given instance (note that I2C is a bus, where + * disables Master mode on the I2C bus (note that I2C is a bus, where * multiple masters and slave may be handled by one device driver). * * One may register a callback to be notified about reception. During the - * slave mode reception, the function READ and WRITE must be used to + * slave mode reception, the methods READ and WRITE must be used to * to handle reads and writes from a master. * * Input Parameters: @@ -179,6 +160,24 @@ #define I2CS_READ(d,b,l) ((d)->ops->read(d,b,l)) +/**************************************************************************** + * Name: I2CS_REGISTERCALLBACK + * + * Description: + * Register to receive a callback when something is received on I2C. + * + * Input Parameters: + * dev - Device-specific state data + * callback - The function to be called when something has been received. + * arg - User provided argument to be used with the callback + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +#define I2CS_REGISTERCALLBACK(d,c,a) ((d)->ops->registercallback(d,c,a)) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -189,12 +188,11 @@ struct i2c_slave_s; struct i2c_slaveops_s { uint32_t (*setfrequency)(FAR struct i2c_slave_s *dev, uint32_t frequency); - int (*setaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); + int (*setownaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); int (*write)(FAR struct i2c_slave_s *dev, FAR const uint8_t *buffer, int buflen); int (*read)(FAR struct i2c_slave_s *dev, FAR uint8_t *buffer, int buflen); - int (*setownaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); int (*registercallback)(FAR struct i2c_slave_s *dev, int (*callback)(FAR void *arg), FAR void *arg); }; -- GitLab From 80476a16e21c959b68bf8f702fc1d9789d79c39d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 12:20:32 -0600 Subject: [PATCH 655/858] Update ChangeLog --- ChangeLog | 8 ++++---- arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6794e32148..7f0d431b0f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11420,7 +11420,7 @@ half driver for the U-Blox Modem. From Vladimir Komendantskiy (2018-01-30). * arch/arm/src/lpc17xx: Backport lpc43xx I2C driver, replacing the - the lpc17xx I2C drivers. This gives use the I2C_TRANSFER method. - (2016-01-30). - - + lpc17xx I2C driver. This gives us the I2C_TRANSFER method (2016-01-30). + * arch/arm/src/lpc11xx: Backport the lpc17xx I2C driver, replace the + lpc11xx I2C driver. This gives us the I2C_TRANSFER method (2019-01-30). + diff --git a/arch b/arch index 150916cbf9..0703fc2392 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 150916cbf96b04752df6874a7eccc6e52ace3815 +Subproject commit 0703fc2392562976e4c68f146c35e228ef4d04cf diff --git a/configs b/configs index c4eea61723..e21b27bdee 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c4eea61723a32ae07781338cd9a80637dec07822 +Subproject commit e21b27bdee2745be38a8c811ccd2eb0416e49792 -- GitLab From 10f3bb1fefe49c40ba51bebb11aadd793f5544d8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 30 Jan 2016 13:08:12 -0600 Subject: [PATCH 656/858] Update ChangeLog --- ChangeLog | 6 ++++-- arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f0d431b0f..3a0d78ef50 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11421,6 +11421,8 @@ (2018-01-30). * arch/arm/src/lpc17xx: Backport lpc43xx I2C driver, replacing the lpc17xx I2C driver. This gives us the I2C_TRANSFER method (2016-01-30). - * arch/arm/src/lpc11xx: Backport the lpc17xx I2C driver, replace the + * arch/arm/src/lpc11xx: Backport the lpc17xx I2C driver, replacing the lpc11xx I2C driver. This gives us the I2C_TRANSFER method (2019-01-30). - + * arcm/arm/src/lpc2378: Backo the Lpc17xx I2C driver, replacing the + lpc2378 I2C driver. This gives us the I2C_TRANSFER method (2019-01-30). + diff --git a/arch b/arch index 0703fc2392..b7f1b85c68 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0703fc2392562976e4c68f146c35e228ef4d04cf +Subproject commit b7f1b85c685293615089b16597f02fd1dd76db45 diff --git a/configs b/configs index e21b27bdee..eb16f3dcbc 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e21b27bdee2745be38a8c811ccd2eb0416e49792 +Subproject commit eb16f3dcbc0c72a169447965834b09503dc6c892 -- GitLab From 670c041e71ac553282e68a2394886b69e6142b7c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 31 Jan 2016 08:51:24 -0600 Subject: [PATCH 657/858] Update Changelog, submoduels, and README --- ChangeLog | 9 ++++++--- Documentation | 2 +- README.txt | 2 ++ configs | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a0d78ef50..1f05f87921 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11417,12 +11417,15 @@ out of the RTOS and into the application space, specifically to apps/platform/board, where it belongs (2016-01-29). * drivers/modem/u-blox.c and include/nuttx/drivers/u-blox.h: Add an upper - half driver for the U-Blox Modem. From Vladimir Komendantskiy + half driver for the U-Blox Modem. From Vladimir Komendantskiy (2018-01-30). * arch/arm/src/lpc17xx: Backport lpc43xx I2C driver, replacing the lpc17xx I2C driver. This gives us the I2C_TRANSFER method (2016-01-30). * arch/arm/src/lpc11xx: Backport the lpc17xx I2C driver, replacing the lpc11xx I2C driver. This gives us the I2C_TRANSFER method (2019-01-30). - * arcm/arm/src/lpc2378: Backo the Lpc17xx I2C driver, replacing the + * arch/arm/src/lpc2378: Backo the Lpc17xx I2C driver, replacing the lpc2378 I2C driver. This gives us the I2C_TRANSFER method (2019-01-30). - + * confgs/u-blox-c027: Support for the u-blox GSM and GPS module evaluation + board with NXP LPCExpresso LPC1768. The GSM module is one of LISA-C200, + LISA-U200 or SARA-G350. The GPS module is one of MAX-M7 or MAX-M8. From + Vladimir Komendantskiy (2016-01-31). diff --git a/Documentation b/Documentation index bd05adddce..443f68d553 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit bd05adddce9f801523a2b77363a8dddb01c952b3 +Subproject commit 443f68d553a2dbc7514366a4b05c81ee2ebb6350 diff --git a/README.txt b/README.txt index 4d0c53436c..0f3949ac6d 100644 --- a/README.txt +++ b/README.txt @@ -1461,6 +1461,8 @@ nuttx/ | | `- README.txt | |- twr-k60n512/ | | `- README.txt + | |- u-blox-co27/ + | | `- README.txt | |- ubw32/ | | `- README.txt | |- us7032evb1/ diff --git a/configs b/configs index eb16f3dcbc..4b4044a4d5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit eb16f3dcbc0c72a169447965834b09503dc6c892 +Subproject commit 4b4044a4d55a2e3cdf44479d38f242f6339432fc -- GitLab From 9370b94241e18cd1b59fd534b7d029ffc4c5af0d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 31 Jan 2016 12:44:44 -0600 Subject: [PATCH 658/858] compiler.h: Missing IOBJ/IPTR definitions for the ZDS-II toolchain --- arch | 2 +- configs | 2 +- include/nuttx/compiler.h | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch b/arch index b7f1b85c68..fe82498fb1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b7f1b85c685293615089b16597f02fd1dd76db45 +Subproject commit fe82498fb11af76d0bda08c4fd969f4e5b60de0a diff --git a/configs b/configs index 4b4044a4d5..446de79f49 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4b4044a4d55a2e3cdf44479d38f242f6339432fc +Subproject commit 446de79f4904d30bd0f4a787b36775f2ccf65902 diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 858902f696..ec93a9a192 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -378,6 +378,11 @@ # define CONFIG_HAVE_FUNCTIONNAME 1 /* Has __FUNCTION__ */ # define CONFIG_HAVE_FILENAME 1 /* Has __FILE__ */ +/* No I-space access qualifiers */ + +# define IOBJ +# define IPTR + /* Attributes * * The Zilog compiler does not support weak symbols -- GitLab From 10000841a82dbc0143cf73ff04ba5e3de3ace4ed Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 31 Jan 2016 14:16:05 -0600 Subject: [PATCH 659/858] The I2C_TRANSFER method is no longer optional --- arch | 2 +- configs | 2 +- drivers/i2c/Kconfig | 4 ---- drivers/i2c/Make.defs | 4 +--- drivers/i2c/i2c_read.c | 3 --- drivers/i2c/i2c_write.c | 3 --- drivers/i2c/i2c_writeread.c | 3 --- drivers/ioexpander/pca9555.c | 4 ---- drivers/ioexpander/pca9555.h | 2 -- drivers/sensors/lis331dl.c | 4 ++-- drivers/timers/ds3231.c | 4 ---- drivers/timers/pcf85263.c | 4 ---- include/nuttx/audio/wm8904.h | 4 ---- include/nuttx/i2c/i2c_master.h | 8 -------- include/nuttx/input/mxt.h | 4 ---- include/nuttx/input/stmpe811.h | 3 --- include/nuttx/input/tsc2007.h | 4 ---- include/nuttx/lcd/ssd1306.h | 4 ---- include/nuttx/sensors/adxl345.h | 3 --- include/nuttx/sensors/lis331dl.h | 4 ++-- include/nuttx/timers/cs2100-cp.h | 4 ---- 21 files changed, 7 insertions(+), 70 deletions(-) diff --git a/arch b/arch index fe82498fb1..f8825890e5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fe82498fb11af76d0bda08c4fd969f4e5b60de0a +Subproject commit f8825890e59d946bfffaf68e93ed5ecabebc5f04 diff --git a/configs b/configs index 446de79f49..13a5278c9d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 446de79f4904d30bd0f4a787b36775f2ccf65902 +Subproject commit 13a5278c9df0652122ecf6f458cab9fdf4d883b7 diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 72f331cc04..9f4e625dd7 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -9,10 +9,6 @@ config I2C_SLAVE bool "I2C Slave" default n -config I2C_TRANSFER - bool "Support the I2C transfer() method" - default n - config I2C_POLLED bool "Polled I2C (no interrupts)" default n diff --git a/drivers/i2c/Make.defs b/drivers/i2c/Make.defs index 4d1d737a57..8036cbcb75 100644 --- a/drivers/i2c/Make.defs +++ b/drivers/i2c/Make.defs @@ -37,9 +37,7 @@ ifeq ($(CONFIG_I2C),y) -ifeq ($(CONFIG_I2C_TRANSFER),y) - CSRCS += i2c_read.c i2c_write.c i2c_writeread.c -endif +CSRCS += i2c_read.c i2c_write.c i2c_writeread.c # Include I2C device driver build support diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 1d7c16b8cb..1c0a840cd4 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -43,8 +43,6 @@ #include -#if defined(CONFIG_I2C_TRANSFER) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,4 +94,3 @@ int i2c_read(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } -#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index 725e150ce4..d98be5e293 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -43,8 +43,6 @@ #include -#if defined(CONFIG_I2C_TRANSFER) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -91,4 +89,3 @@ int i2c_write(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } -#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index 571fa1b305..da421680f6 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -43,8 +43,6 @@ #include -#if defined(CONFIG_I2C_TRANSFER) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -117,4 +115,3 @@ int i2c_writeread(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, msg, 2); } -#endif /* CONFIG_I2C_TRANSFER */ \ No newline at end of file diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index f405a4a311..a2607a8db9 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -64,10 +64,6 @@ # warning I2C support is required (CONFIG_I2C) #endif -#ifndef CONFIG_I2C_TRANSFER -# warning Support of the I2C transfer() method is required (CONFIG_I2C_TRANSFER) -#endif - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ diff --git a/drivers/ioexpander/pca9555.h b/drivers/ioexpander/pca9555.h index c7d2467674..cb81eb27dd 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -63,8 +63,6 @@ /* Prerequisites: * CONFIG_I2C * I2C support is required - * CONFIG_I2C_TRANSFER - * Support for the I2C transfer method is required. * CONFIG_IOEXPANDER * Enables support for the PCA9555 I/O expander * diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index 7802eb086a..de4887ef2d 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -49,7 +49,7 @@ #include #include -#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL) +#if defined(CONFIG_I2C) && defined(CONFIG_LIS331DL) /**************************************************************************** * Pre-processor Definitions @@ -377,4 +377,4 @@ lis331dl_getreadings(FAR struct lis331dl_dev_s * dev) return NULL; } -#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */ +#endif /* CONFIG_I2C && CONFIG_LIS331DL */ diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 0dd27bc754..bff34b437a 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -66,10 +66,6 @@ # error CONFIG_RTC_HIRES must NOT be set with this driver #endif -#ifndef CONFIG_I2C_TRANSFER -# error CONFIG_I2C_TRANSFER is required by this driver -#endif - #ifndef CONFIG_DS3231_I2C_FREQUENCY # error CONFIG_DS3231_I2C_FREQUENCY is not configured # define CONFIG_DS3231_I2C_FREQUENCY 400000 diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index ac6359c9da..d6318820ef 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -66,10 +66,6 @@ # error CONFIG_RTC_HIRES must NOT be set with this driver #endif -#ifndef CONFIG_I2C_TRANSFER -# error CONFIG_I2C_TRANSFER is required by this driver -#endif - #ifndef CONFIG_PCF85263_I2C_FREQUENCY # error CONFIG_PCF85263_I2C_FREQUENCY is not configured # define CONFIG_PCF85263_I2C_FREQUENCY 400000 diff --git a/include/nuttx/audio/wm8904.h b/include/nuttx/audio/wm8904.h index a10c69739e..5b2bd7e549 100644 --- a/include/nuttx/audio/wm8904.h +++ b/include/nuttx/audio/wm8904.h @@ -84,10 +84,6 @@ # error CONFIG_I2C is required by the WM8904 driver #endif -#ifndef CONFIG_I2C_TRANSFER -# error CONFIG_I2C_TRANSFER is required in the I2C configuration -#endif - #ifndef CONFIG_SCHED_WORKQUEUE # error CONFIG_SCHED_WORKQUEUE is required by the WM8904 driver #endif diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index b181beca28..a8b91f8226 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -196,10 +196,8 @@ struct i2c_ops_s int buflen); int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer, int buflen); -#ifdef CONFIG_I2C_TRANSFER int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count); -#endif }; /* This structure contains the full state of I2C as needed for a specific @@ -318,11 +316,9 @@ int up_i2creset(FAR struct i2c_master_s *dev); * ****************************************************************************/ -#ifdef CONFIG_I2C_TRANSFER int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, int rbuflen); -#endif /**************************************************************************** * Name: i2c_write @@ -343,10 +339,8 @@ int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *c * ****************************************************************************/ -#ifdef CONFIG_I2C_TRANSFER int i2c_write(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR const uint8_t *buffer, int buflen); -#endif /**************************************************************************** * Name: i2c_read @@ -367,10 +361,8 @@ int i2c_write(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *confi * ****************************************************************************/ -#ifdef CONFIG_I2C_TRANSFER int i2c_read(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, FAR uint8_t *buffer, int buflen); -#endif #undef EXTERN #if defined(__cplusplus) diff --git a/include/nuttx/input/mxt.h b/include/nuttx/input/mxt.h index 4498be11c2..22ee792769 100644 --- a/include/nuttx/input/mxt.h +++ b/include/nuttx/input/mxt.h @@ -87,10 +87,6 @@ * in getting the right configuration. */ -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the I2C configuration" -#endif - #ifdef CONFIG_DISABLE_SIGNALS # error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected." #endif diff --git a/include/nuttx/input/stmpe811.h b/include/nuttx/input/stmpe811.h index 6cf96e6a7f..0ace9ea313 100644 --- a/include/nuttx/input/stmpe811.h +++ b/include/nuttx/input/stmpe811.h @@ -121,9 +121,6 @@ # ifndef CONFIG_I2C # error "CONFIG_I2C is required in the I2C support" # endif -# ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the I2C configuration" -# endif #endif #ifdef CONFIG_DISABLE_SIGNALS diff --git a/include/nuttx/input/tsc2007.h b/include/nuttx/input/tsc2007.h index 1517fd488a..20a832f870 100644 --- a/include/nuttx/input/tsc2007.h +++ b/include/nuttx/input/tsc2007.h @@ -69,10 +69,6 @@ * in getting the right configuration. */ -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the I2C configuration" -#endif - #ifdef CONFIG_DISABLE_SIGNALS # error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected." #endif diff --git a/include/nuttx/lcd/ssd1306.h b/include/nuttx/lcd/ssd1306.h index 286c573e3a..ed4195e78b 100644 --- a/include/nuttx/lcd/ssd1306.h +++ b/include/nuttx/lcd/ssd1306.h @@ -118,10 +118,6 @@ #ifdef CONFIG_LCD_SSD1306_I2C -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER must be defined in your NuttX configuration" -#endif - #ifndef CONFIG_SSD1306_I2CADDR # define CONFIG_SSD1306_I2CADDR 0x78 /* 120 in decimal */ #endif diff --git a/include/nuttx/sensors/adxl345.h b/include/nuttx/sensors/adxl345.h index 23409efe80..da563c8ac6 100644 --- a/include/nuttx/sensors/adxl345.h +++ b/include/nuttx/sensors/adxl345.h @@ -97,9 +97,6 @@ # ifndef CONFIG_I2C # error "CONFIG_I2C is required in the I2C support" # endif -# ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the I2C configuration" -# endif #endif /* I2C **************************************************************************************/ diff --git a/include/nuttx/sensors/lis331dl.h b/include/nuttx/sensors/lis331dl.h index db4c4317d9..8d69b5d7c3 100644 --- a/include/nuttx/sensors/lis331dl.h +++ b/include/nuttx/sensors/lis331dl.h @@ -41,7 +41,7 @@ #include #include -#if defined(CONFIG_I2C) && defined(CONFIG_I2C_TRANSFER) && defined(CONFIG_LIS331DL) +#if defined(CONFIG_I2C) && defined(CONFIG_LIS331DL) /************************************************************************************ * Pre-Processor Declarations @@ -208,5 +208,5 @@ FAR const struct lis331dl_vector_s * #endif #endif /* __ASSEMBLY__ */ -#endif /* CONFIG_I2C && CONFIG_I2C_TRANSFER && CONFIG_LIS331DL */ +#endif /* CONFIG_I2C && CONFIG_LIS331DL */ #endif /* __INCLUDE_NUTTX_SENSORS_LIS331DL_H */ diff --git a/include/nuttx/timers/cs2100-cp.h b/include/nuttx/timers/cs2100-cp.h index dcff2851e0..5d62149134 100644 --- a/include/nuttx/timers/cs2100-cp.h +++ b/include/nuttx/timers/cs2100-cp.h @@ -54,10 +54,6 @@ #ifndef CONFIG_I2C # error I2C driver support is required (CONFIG_I2C) -#else -# ifndef CONFIG_I2C_TRANSFER -# error I2C transfer method is required (CONFIG_I2C_TRANSFER) -# endif #endif #ifndef CONFIG_TIMERS_CS2100CP_CLKINBW -- GitLab From fa2448fe639e02aac4dbd73663fe69319a579a4d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 31 Jan 2016 15:39:43 -0600 Subject: [PATCH 660/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index f8825890e5..6e62a82efb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f8825890e59d946bfffaf68e93ed5ecabebc5f04 +Subproject commit 6e62a82efb16b69c704888c98a4c44442c69b803 diff --git a/configs b/configs index 13a5278c9d..ee7d12e263 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 13a5278c9df0652122ecf6f458cab9fdf4d883b7 +Subproject commit ee7d12e2635c22a7adedf923c6564c29ec057272 -- GitLab From 8c9bddf9985e5d1cb32a9edd611aac520474f098 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 08:57:22 -0600 Subject: [PATCH 661/858] I2C: Eliminate the I2C_WRITE and I2C_READ macros --- TODO | 10 ++-- configs | 2 +- drivers/audio/wm8904.c | 11 +++- drivers/ioexpander/pca9555.c | 4 +- drivers/leds/pca9635pw.c | 21 ++++---- drivers/mtd/at24xx.c | 64 ++++++++++++++++++++--- drivers/power/bq2425x.c | 57 +++++++++++++++++++-- drivers/power/max1704x.c | 56 +++++++++++++++++--- drivers/sensors/Kconfig | 36 +++++++++++++ drivers/sensors/as5048b.c | 59 ++++++++++++++++++--- drivers/sensors/bmp180.c | 68 +++++++++++++++++++++---- drivers/sensors/lm75.c | 87 ++++++++++++++++++++++++------- drivers/sensors/lm92.c | 93 ++++++++++++++++++++++++++-------- drivers/sensors/lsm9ds1.c | 68 ++++++++++++++++++++++--- drivers/sensors/mb7040.c | 71 +++++++++++++++++++++++--- drivers/sensors/mcp9844.c | 71 +++++++++++++++++++++++--- drivers/sensors/ms58xx.c | 80 ++++++++++++++++++++++++----- drivers/timers/ds3231.c | 5 +- drivers/timers/pcf85263.c | 5 +- drivers/video/ov2640.c | 57 ++++++++++++++++++--- include/nuttx/i2c/i2c_master.h | 67 +++++------------------- 21 files changed, 802 insertions(+), 190 deletions(-) diff --git a/TODO b/TODO index 9d7c25dfad..854b3996e4 100644 --- a/TODO +++ b/TODO @@ -1614,10 +1614,9 @@ o Other drivers (drivers/) in a multi-tasking I2C environment: - I2C_SETFREQUENCY: Frequency setting can be overwritten by other I2C usage. - - I2C_SETADDRESS used with I2C_READ and I2C_WRITE: - Similarly, address can and will be changed by other I2C usage. - NOTE also that I2C_SETADDRESS also sets the address width (either - 7 or 10 bits). + - I2C_SETADDRESS: The I2C address can and will be changed by other + I2C usage. NOTE also that I2C_SETADDRESS also sets the address width + (either 7 or 10 bits). - I2C_TRANSFER: This is the only interface that is properly self contained and protected from most mult-tasking issues. But even this interface can suffer if there are differing frequency settings. @@ -1626,8 +1625,7 @@ o Other drivers (drivers/) are two ways to fix theses problems: (1) Add a locking method such as is provided with the SPI interface, or (2) make each interface self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS - methods; Add frequency to all interfaces and add the address to - I2C_READ and I2C_WRITE. + methods; Add frequency to the I2C_TRANSFER message structure. o Linux/Cywgin simulation (arch/sim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/configs b/configs index ee7d12e263..7286dea76c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ee7d12e2635c22a7adedf923c6564c29ec057272 +Subproject commit 7286dea76c9a19895a14d02b593c4c6356461a9d diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index 0742db5072..6b298b079c 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -332,8 +332,15 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr) static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr, uint16_t regval) { + struct i2c_config_s config; int retries; + /* Setup up the I2C configuration */ + + config.frequency = priv->lower->frequency; + config.address = priv->lower->address; + config.addrlen = 7; + /* Try up to three times to read the register */ for (retries = 1; retries <= 3; retries++) @@ -351,13 +358,13 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr, * completed. */ - ret = I2C_WRITE(priv->i2c, data, 3); + ret = i2c_write(priv->i2c, &config, data, 3); if (ret < 0) { #ifdef CONFIG_I2C_RESET /* Perhaps the I2C bus is locked up? Try to shake the bus free */ - auddbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret); + auddbg("WARNING: i2c_write failed: %d ... Resetting\n", ret); ret = up_i2creset(priv->i2c); if (ret < 0) diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index a2607a8db9..7aafe3d9ae 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -128,10 +128,10 @@ static const struct ioexpander_ops_s g_pca9555_ops = ****************************************************************************/ /**************************************************************************** - * Name: pca9555_writeread + * Name: pca9555_write * * Description: - * Write to then read from the I2C device. + * Write to the I2C device. * ****************************************************************************/ diff --git a/drivers/leds/pca9635pw.c b/drivers/leds/pca9635pw.c index d07b10baab..b4a8419061 100644 --- a/drivers/leds/pca9635pw.c +++ b/drivers/leds/pca9635pw.c @@ -103,6 +103,8 @@ static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv, uint8_t const reg_addr, uint8_t const reg_val) { + struct i2c_config_s config; + dbg("pca9635pw_i2c_write_byte\n"); /* assemble the 2 byte message comprised of reg_addr and reg_val */ @@ -113,25 +115,22 @@ static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv, buffer[0] = reg_addr; buffer[1] = reg_val; - /* Write the register address followed by the data (no RESTART) */ + /* Setup up the I2C configuration */ - uint8_t const NUMBER_OF_I2C_ADDRESS_BITS = 7; + config.frequency = I2C_BUS_FREQ_HZ; + config.address = priv->i2c_addr; + config.addrlen = 7; + + /* Write the register address followed by the data (no RESTART) */ dbg("i2c addr: 0x%02X reg addr: 0x%02X value: 0x%02X\n", priv->i2c_addr, buffer[0], buffer[1]); - int ret = I2C_SETADDRESS(priv->i2c, priv->i2c_addr, - NUMBER_OF_I2C_ADDRESS_BITS); - if (ret != OK) - { - dbg("I2C_SETADDRESS returned error code %d\n", ret); - return ret; - } - ret = I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE); + ret = i2c_write(priv->i2c, &config, buffer, BUFFER_SIZE); if (ret != OK) { - dbg("I2C_WRITE returned error code %d\n", ret); + dbg("i2c_write returned error code %d\n", ret); return ret; } diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index ef6abe5322..5cfe754dd4 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -4,9 +4,9 @@ * * Copyright (C) 2011 Li Zhuoyi. All rights reserved. * Author: Li Zhuoyi - * History: 0.1 2011-08-20 initial version * - * 2011-11-1 Added support for larger MTD block sizes: Hal Glenn + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Derived from drivers/mtd/m25px.c * @@ -192,6 +192,54 @@ static struct at24c_dev_s g_at24c; * Private Functions ************************************************************************************/ +/**************************************************************************** + * Name: at24c_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int at24c_i2c_write(FAR struct at24c_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_AT24XX_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->dev, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: at24c_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int at24c_i2c_read(FAR struct at24c_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_AT24XX_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->dev, &config, buffer, buflen); +} + +/************************************************************************************ + * Name: at24c_eraseall + ************************************************************************************/ + static int at24c_eraseall(FAR struct at24c_dev_s *priv) { int startblock = 0; @@ -212,12 +260,12 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv) I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); #endif - while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) { usleep(1000); } - I2C_WRITE(priv->dev, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE); + at24c_i2c_write(priv, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE); } return OK; @@ -273,7 +321,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7); #endif - while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) { fvdbg("wait\n"); usleep(1000); @@ -281,7 +329,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, /* Then transfer the following bytes */ - I2C_READ(priv->dev, buffer, nbytes); + at24c_i2c_read(priv, buffer, nbytes); return nbytes; } @@ -388,7 +436,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); #endif - while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) { fvdbg("wait\n"); usleep(1000); @@ -396,7 +444,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t memcpy(&buf[AT24XX_ADDRSIZE], buffer, priv->pagesize); - I2C_WRITE(priv->dev, buf, priv->pagesize + AT24XX_ADDRSIZE); + at24c_i2c_write(priv, buf, priv->pagesize + AT24XX_ADDRSIZE); startblock++; buffer += priv->pagesize; } diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c index ad73f9f8ca..3a00dc6f1b 100644 --- a/drivers/power/bq2425x.c +++ b/drivers/power/bq2425x.c @@ -5,6 +5,9 @@ * Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved. * Author: Alan Carvalho de Assis * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -144,6 +147,50 @@ static const struct battery_charger_operations_s g_bq2425xops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: bq2425x_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int bq2425x_i2c_write(FAR struct bq2425x_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: bq2425x_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: bq2425x_getreg8 * @@ -167,19 +214,19 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, /* Write the register address */ - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = bq2425x_i2c_write(priv, ®addr, 1); if (ret < 0) { - batdbg("I2C_WRITE failed: %d\n", ret); + batdbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 8-bits from the register */ - ret = I2C_READ(priv->i2c, &val, 1); + ret = bq2425x_i2c_read(priv, &val, 1); if (ret < 0) { - batdbg("I2C_READ failed: %d\n", ret); + batdbg("i2c_read failed: %d\n", ret); return ret; } @@ -217,7 +264,7 @@ static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ - return I2C_WRITE(priv->i2c, buffer, 2); + return bq2425x_i2c_write(priv, buffer, 2); } /**************************************************************************** diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index ff358bda17..5ced5cfc09 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -2,7 +2,7 @@ * drivers/power/max1704x.c * Lower half driver for MAX1704x battery fuel gauge * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -229,6 +229,50 @@ static const struct battery_gauge_operations_s g_max1704xops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: max1704x_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int max1704x_i2c_write(FAR struct max1704x_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: max1704x_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: max1704x_getreg16 * @@ -252,19 +296,19 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, /* Write the register address */ - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = max1704x_i2c_write(priv, ®addr, 1); if (ret < 0) { - batdbg("I2C_WRITE failed: %d\n", ret); + batdbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 16-bits from the register */ - ret = I2C_READ(priv->i2c, buffer, 2); + ret = max1704x_i2c_read(priv, buffer, 2); if (ret < 0) { - batdbg("I2C_READ failed: %d\n", ret); + batdbg("i2c_read failed: %d\n", ret); return ret; } @@ -302,7 +346,7 @@ static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ - return I2C_WRITE(priv->i2c, buffer, 3); + return max1704x_i2c_write(priv, buffer, 3); } /**************************************************************************** diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index dc57cc69ba..46f0e3b2c9 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -31,6 +31,12 @@ config SN_LSM9DS1 ---help--- Enable driver support for the STMicro LSM9DS1. +config LSM9DS1_I2C_FREQUENCY + bool "LSM9DS1 I2C frequency" + default 400000 + range 1 400000 + depends on SN_LSM9DS1 + config MB7040 bool "MaxBotix MB7040 Sonar support" default n @@ -38,6 +44,12 @@ config MB7040 ---help--- Enable driver support for the MaxBotix MB7040 sonar. +config MB7040_I2C_FREQUENCY + bool "MB7040 I2C frequency" + default 400000 + range 1 400000 + depends on MB7040 + config MCP9844 bool "MCP9844 Temperature Sensor" default n @@ -45,6 +57,12 @@ config MCP9844 ---help--- Enable driver support for the MCP9844 I2C Temperature sensor. +config MCP9844_I2C_FREQUENCY + bool "MCP9844 I2C frequency" + default 400000 + range 1 400000 + depends on MCP9844 + config MS58XX bool "MEAS MS58XX Altimeter support" default n @@ -52,6 +70,12 @@ config MS58XX ---help--- Enable driver support for MEAS MS58XX altimeters. +config MS58XX_I2C_FREQUENCY + bool "MS58XX I2C frequency" + default 400000 + range 1 400000 + depends on MS58XX + config MS58XX_VDD int "MEAS MS58XX VDD" default 30 @@ -134,6 +158,12 @@ config LM75 This should also work with compatible temperature sensors such as the TI TMP100/101. +config LM75_I2C_FREQUENCY + bool "LM75 I2C frequency" + default 100000 + range 1 100000 + depends on I2C_LM75 + config LM92 bool "TI LM92 Temperature Sensor support" default n @@ -141,6 +171,12 @@ config LM92 ---help--- Enable driver support for the TI LM92 Temperature Sensor. +config LM92_I2C_FREQUENCY + bool "LM92 I2C frequency" + default 400000 + range 1 400000 + depends on LM92 + config QENCODER bool "Qencoder" default n diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index 7ee52e1f0f..154f82bd63 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -5,6 +5,9 @@ * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -111,6 +114,50 @@ static const struct qe_ops_s g_qeops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: as5048b_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int as5048b_i2c_write(FAR struct as5048b_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: as5048b_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int as5048b_i2c_read(FAR struct as5048b_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: as5048b_readu8 * @@ -127,19 +174,19 @@ static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = as5048b_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 8 bits from the register */ - ret = I2C_READ(priv->i2c, regval, sizeof(*regval)); + ret = as5048b_i2c_read(priv, regval, sizeof(*regval)); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -209,10 +256,10 @@ static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer)); + ret = as5048b_i2c_write(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); } return ret; diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index ce16dd94e4..97fda6221a 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -3,10 +3,12 @@ * drivers/sensors/bmp180.c * Character driver for the Freescale BMP1801 Barometer Sensor * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Alan Carvalho de Assis * Author: Alan Carvalho de Assis * + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -171,6 +173,50 @@ static const struct file_operations g_bmp180fops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: bmp180_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int bmp180_i2c_write(FAR struct bmp180_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->freq; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: bmp180_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int bmp180_i2c_read(FAR struct bmp180_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = priv->freq; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: bmp180_getreg8 * @@ -186,19 +232,19 @@ static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr) /* Restart the register */ - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = bmp180_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart the register */ - ret = I2C_READ(priv->i2c, ®val, 1); + ret = bmp180_i2c_read(priv, ®val, 1); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -221,19 +267,19 @@ static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr) /* Register to read */ - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = bmp180_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Read register */ - ret = I2C_READ(priv->i2c, (uint8_t *)®val, 2); + ret = bmp180_i2c_read(priv, (uint8_t *)®val, 2); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -266,10 +312,10 @@ static void bmp180_putreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr, /* Restart the register */ - ret = I2C_WRITE(priv->i2c, (uint8_t *) &data, 2); + ret = bmp180_i2c_write(priv, (uint8_t *) &data, 2); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return; } diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 609377f69e..f70c61bfd1 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -2,7 +2,7 @@ * drivers/sensors/lm75.c * Character driver for the STMicro LM-75 Temperature Sensor * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,6 +56,10 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef CONFIG_LM75_I2C_FREQUENCY +# define CONFIG_LM75_I2C_FREQUENCY 100000 +#endif + /* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */ #define B16_9DIV5 (9 * 65536 / 5) @@ -77,13 +81,17 @@ struct lm75_dev_s ****************************************************************************/ /* I2C Helpers */ -static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, - FAR b16_t *regvalue); -static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, - b16_t regval); -static int lm75_readtemp(FAR struct lm75_dev_s *priv, FAR b16_t *temp); -static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf); -static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf); +static int lm75_i2c_write(FAR struct lm75_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int lm75_i2c_read(FAR struct lm75_dev_s *priv, + FAR uint8_t *buffer, int buflen); +static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, + FAR b16_t *regvalue); +static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, + b16_t regval); +static int lm75_readtemp(FAR struct lm75_dev_s *priv, FAR b16_t *temp); +static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf); +static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf); /* Character driver methods */ @@ -115,6 +123,51 @@ static const struct file_operations g_lm75fops = /**************************************************************************** * Private Functions ****************************************************************************/ + +/**************************************************************************** + * Name: lm75_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int lm75_i2c_write(FAR struct lm75_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LM75_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: lm75_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int lm75_i2c_read(FAR struct lm75_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LM75_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: lm75_readb16 * @@ -132,19 +185,19 @@ static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = lm75_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 16-bits from the register (discarding 7) */ - ret = I2C_READ(priv->i2c, buffer, 2); + ret = lm75_i2c_read(priv, buffer, 2); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -185,7 +238,7 @@ static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - return I2C_WRITE(priv->i2c, buffer, 3); + return lm75_i2c_write(priv, buffer, 3); } /**************************************************************************** @@ -244,16 +297,16 @@ static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf) I2C_SETADDRESS(priv->i2c, priv->addr, 7); buffer = LM75_CONF_REG; - ret = I2C_WRITE(priv->i2c, &buffer, 1); + ret = lm75_i2c_write(priv, &buffer, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 8-bits from the register */ - ret = I2C_READ(priv->i2c, conf, 1); + ret = lm75_i2c_read(priv, conf, 1); sndbg("conf: %02x ret: %d\n", *conf, ret); return ret; } @@ -280,7 +333,7 @@ static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf) /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - return I2C_WRITE(priv->i2c, buffer, 2); + return lm75_i2c_write(priv, buffer, 2); } /**************************************************************************** diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 432445e30c..e168e90a51 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -58,6 +58,10 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef CONFIG_LM92_I2C_FREQUENCY +# define CONFIG_LM92_I2C_FREQUENCY 400000 +#endif + /* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */ #define B16_9DIV5 (9 * 65536 / 5) @@ -79,13 +83,17 @@ struct lm92_dev_s ****************************************************************************/ /* I2C Helpers */ -static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, - FAR b16_t *regvalue); -static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, - b16_t regval); -static int lm92_readtemp(FAR struct lm92_dev_s *priv, FAR b16_t *temp); -static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf); -static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf); +static int lm92_i2c_write(FAR struct lm92_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int lm92_i2c_read(FAR struct lm92_dev_s *priv, + FAR uint8_t *buffer, int buflen); +static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, + FAR b16_t *regvalue); +static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, + b16_t regval); +static int lm92_readtemp(FAR struct lm92_dev_s *priv, FAR b16_t *temp); +static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf); +static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf); /* Character driver methods */ @@ -117,6 +125,51 @@ static const struct file_operations g_lm92fops = /**************************************************************************** * Private Functions ****************************************************************************/ + +/**************************************************************************** + * Name: lm92_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int lm92_i2c_write(FAR struct lm92_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LM92_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: lm92_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int lm92_i2c_read(FAR struct lm92_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LM92_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: lm92_readb16 * @@ -135,19 +188,19 @@ static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = lm92_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 16 bits from the register (discarding 3) */ - ret = I2C_READ(priv->i2c, buffer, 2); + ret = lm92_i2c_read(priv, buffer, 2); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -188,7 +241,7 @@ static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - return I2C_WRITE(priv->i2c, buffer, 3); + return lm92_i2c_write(priv, buffer, 3); } /**************************************************************************** @@ -247,16 +300,16 @@ static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf) I2C_SETADDRESS(priv->i2c, priv->addr, 7); buffer = LM92_CONF_REG; - ret = I2C_WRITE(priv->i2c, &buffer, 1); + ret = lm92_i2c_write(priv, &buffer, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 8 bits from the register */ - ret = I2C_READ(priv->i2c, conf, 1); + ret = lm92_i2c_read(priv, conf, 1); sndbg("conf: %02x ret: %d\n", *conf, ret); return ret; } @@ -283,7 +336,7 @@ static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf) /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - return I2C_WRITE(priv->i2c, buffer, 2); + return lm92_i2c_write(priv, buffer, 2); } /**************************************************************************** @@ -305,19 +358,19 @@ static int lm92_readid(FAR struct lm92_dev_s *priv, FAR uint16_t *id) I2C_SETADDRESS(priv->i2c, priv->addr, 7); regaddr = LM92_ID_REG; - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = lm92_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 16 bits from the register */ - ret = I2C_READ(priv->i2c, buffer, 2); + ret = lm92_i2c_read(priv, buffer, 2); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } diff --git a/drivers/sensors/lsm9ds1.c b/drivers/sensors/lsm9ds1.c index bdde5cdc35..3977cafeb1 100644 --- a/drivers/sensors/lsm9ds1.c +++ b/drivers/sensors/lsm9ds1.c @@ -4,6 +4,9 @@ * Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -53,6 +56,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + +#ifndef CONFIG_LSM9DS1_I2C_FREQUENCY +# define CONFIG_LSM9DS1_I2C_FREQUENCY 400000 +#endif + /* Register Addresses *******************************************************/ /* Accelerometer and gyroscope registers */ @@ -514,6 +522,10 @@ struct lsm9ds1_dev_s ****************************************************************************/ /* I2C Helpers */ +static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv, + FAR uint8_t *buffer, int buflen); static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval); static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, @@ -622,6 +634,50 @@ static const struct lsm9ds1_ops_s g_lsm9ds1mag_ops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: lsm9ds1_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: lsm9ds1_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: lsm9ds1_readreg8 * @@ -643,19 +699,19 @@ static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = lsm9ds1_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 8 bits from the register */ - ret = I2C_READ(priv->i2c, regval, sizeof(*regval)); + ret = lsm9ds1_i2c_read(priv, regval, sizeof(*regval)); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -689,10 +745,10 @@ static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer)); + ret = lsm9ds1_i2c_write(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } diff --git a/drivers/sensors/mb7040.c b/drivers/sensors/mb7040.c index 3741761ca2..5840204e0a 100644 --- a/drivers/sensors/mb7040.c +++ b/drivers/sensors/mb7040.c @@ -5,6 +5,9 @@ * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -51,6 +54,14 @@ #if defined(CONFIG_I2C) && defined(CONFIG_MB7040) +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_MB7040_I2C_FREQUENCY +# define CONFIG_MB7040_I2C_FREQUENCY 400000 +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -66,6 +77,10 @@ struct mb7040_dev_s ****************************************************************************/ /* I2C Helpers */ +static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv, + FAR uint8_t *buffer, int buflen); static int mb7040_measurerange(FAR struct mb7040_dev_s *priv); static int mb7040_readrange(FAR struct mb7040_dev_s *priv, FAR uint16_t *range); @@ -106,6 +121,50 @@ static const struct file_operations g_fops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: mb7040_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MB7040_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: mb7040_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MB7040_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: mb7040_measurerange * @@ -125,10 +184,10 @@ static int mb7040_measurerange(FAR struct mb7040_dev_s *priv) /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = mb7040_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); } return ret; @@ -151,10 +210,10 @@ static int mb7040_readrange(FAR struct mb7040_dev_s *priv, /* Read two bytes */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + ret = mb7040_i2c_read(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -192,10 +251,10 @@ static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr) /* Write the register address followed by the data (no RESTART) */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer)); + ret = mb7040_i2c_write(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c index b8e5c90851..1c4b044e5d 100644 --- a/drivers/sensors/mcp9844.c +++ b/drivers/sensors/mcp9844.c @@ -5,6 +5,9 @@ * Copyright (C) 2015 DS-Automotion GmbH. All rights reserved. * Author: Alexander Entinger * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -51,7 +54,15 @@ #if defined(CONFIG_I2C) && defined(CONFIG_MCP9844) /**************************************************************************** - * Private + * Pre-process Definitions + ****************************************************************************/ + +#ifndef CONFIG_MCP9844_I2C_FREQUENCY +# define CONFIG_MCP9844_I2C_FREQUENCY 400000 +#endif + +/**************************************************************************** + * Private Types ****************************************************************************/ struct mcp9844_dev_s @@ -66,6 +77,10 @@ struct mcp9844_dev_s /* I2C helper functions */ +static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv, + FAR uint8_t *buffer, int buflen); static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, uint8_t const regaddr, FAR uint16_t *value); static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, @@ -103,6 +118,50 @@ static const struct file_operations g_mcp9844_fops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: mcp9844_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MCP9844_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: mcp9844_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MCP9844_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: mcp9844_read_u16 * @@ -120,10 +179,10 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, 1); + ret = mcp9844_i2c_write(priv, ®addr, 1); if (ret < 0) { - sndbg ("I2C_WRITE failed: %d\n", ret); + sndbg ("i2c_write failed: %d\n", ret); return ret; } @@ -131,10 +190,10 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, uint8_t const BUFFER_SIZE = 2; uint8_t buffer[BUFFER_SIZE]; - ret = I2C_READ(priv->i2c, buffer, BUFFER_SIZE); + ret = mcp9844_i2c_read(priv, buffer, BUFFER_SIZE); if (ret < 0) { - sndbg ("I2C_READ failed: %d\n", ret); + sndbg ("i2c_read failed: %d\n", ret); return ret; } @@ -173,7 +232,7 @@ static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, I2C_SETADDRESS(priv->i2c, priv->addr, 7); - return I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE); + return mcp9844_i2c_write(priv, buffer, BUFFER_SIZE); } /**************************************************************************** diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 36c6ac07ef..a6e880d59e 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -6,6 +6,9 @@ * Author: Paul Alexander Patience * Updated by: Karim Keddam * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -56,6 +59,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + +#ifndef CONFIG_MS58XX_I2C_FREQUENCY +# define CONFIG_MS58XX_I2C_FREQUENCY 400000 +#endif + /* Register Definitions *****************************************************/ /* Register Addresses */ @@ -135,6 +143,10 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex); /* I2C Helpers */ +static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, + FAR const uint8_t *buffer, int buflen); +static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv, + FAR uint8_t *buffer, int buflen); static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, FAR uint16_t *regval); static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc); @@ -228,6 +240,50 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) return (n_rem ^ 0x00); } +/**************************************************************************** + * Name: ms58xx_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_write(priv->i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: ms58xx_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + return i2c_read(priv->i2c, &config, buffer, buflen); +} + /**************************************************************************** * Name: ms58xx_readu16 * @@ -247,19 +303,19 @@ static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 16 bits from the register */ - ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + ret = ms58xx_i2c_read(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -288,19 +344,19 @@ static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc) /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } /* Restart and read 24 bits from the register */ - ret = I2C_READ(priv->i2c, buffer, sizeof(buffer)); + ret = ms58xx_i2c_read(priv, buffer, sizeof(buffer)); if (ret < 0) { - sndbg("I2C_READ failed: %d\n", ret); + sndbg("i2c_read failed: %d\n", ret); return ret; } @@ -496,10 +552,10 @@ static int ms58xx_reset(FAR struct ms58xx_dev_s *priv) /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); return ret; } @@ -533,10 +589,10 @@ static int ms58xx_convert(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, /* Write the register address */ I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr)); + ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { - sndbg("I2C_WRITE failed: %d\n", ret); + sndbg("i2c_write failed: %d\n", ret); } /* Wait for the conversion to end */ diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index bff34b437a..32f87863a9 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -547,9 +547,8 @@ int up_rtc_settime(FAR const struct timespec *tp) I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_READ). This transfer - * will be repeated if the seconds count rolls over to a smaller value - * while writing. + /* Perform the transfer. This transfer will be repeated if the seconds + * count rolls over to a smaller value while writing. */ do diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index d6318820ef..201179199a 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -511,9 +511,8 @@ int up_rtc_settime(FAR const struct timespec *tp) I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); - /* Perform the transfer (This could be done with I2C_READ). This transfer - * will be repeated if the seconds count rolls over to a smaller value - * while writing. + /* Perform the transfer. This transfer will be repeated if the seconds + * count rolls over to a smaller value while writing. */ do diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 67322ff3b7..04c431c24a 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -670,6 +670,51 @@ static const struct ovr2640_reg_s g_ov2640_jpeg_uxga_resolution[] = /**************************************************************************** * Private Functions ****************************************************************************/ + +/**************************************************************************** + * Name: ov2640_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int ov2640_i2c_write(FAR struct i2c_master_s *i2c, + FAR const uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_OV2640_FREQUENCY; + config.address = CONFIG_OV2640_I2CADDR; + config.addrlen = 7; + + return i2c_write(i2c, &config, buffer, buflen); +} + +/**************************************************************************** + * Name: ov2640_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int ov2640_i2c_read(FAR struct i2c_master_s *i2c, + FAR uint8_t *buffer, int buflen) +{ + struct i2c_config_s config; + + /* Set up the configuration and perform the write-read operation */ + + config.frequency = CONFIG_OV2640_FREQUENCY; + config.address = CONFIG_OV2640_I2CADDR; + config.addrlen = 7; + + return i2c_read(i2c, &config, buffer, buflen); +} + /**************************************************************************** * Function: ov2640_putreg * @@ -704,10 +749,10 @@ static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, /* And do it */ - ret = I2C_WRITE(i2c, buffer, 2); + ret = ov2640_i2c_write(i2c, buffer, 2); if (ret < 0) { - gdbg("ERROR: I2C_WRITE failed: %d\n", ret); + gdbg("ERROR: i2c_write failed: %d\n", ret); return ret; } @@ -738,19 +783,19 @@ static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr) /* Write the register address */ - ret = I2C_WRITE(i2c, ®addr, 1); + ret = ov2640_i2c_write(i2c, ®addr, 1); if (ret < 0) { - gdbg("ERROR: I2C_WRITE failed: %d\n", ret); + gdbg("ERROR: i2c_write failed: %d\n", ret); return 0; } /* Restart and read 8-bits from the register */ - ret = I2C_READ(i2c, ®val, 1); + ret = ov2640_i2c_read(i2c, ®val, 1); if (ret < 0) { - gdbg("ERROR: I2C_READ failed: %d\n", ret); + gdbg("ERROR: i2c_read failed: %d\n", ret); return 0; } #ifdef CONFIG_OV2640_REGDEBUG diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index a8b91f8226..9ff3357a30 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -117,48 +117,6 @@ #define I2C_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n)) -/**************************************************************************** - * Name: I2C_WRITE - * - * Description: - * Send a block of data on I2C using the previously selected I2C - * frequency and slave address. Each write operational will be an 'atomic' - * operation in the sense that any other I2C actions will be serialized - * and pend until this write completes. Required. - * - * Input Parameters: - * dev - Device-specific state data - * buffer - A pointer to the read-only buffer of data to be written to device - * buflen - The number of bytes to send from the buffer - * - * Returned Value: - * 0: success, <0: A negated errno - * - ****************************************************************************/ - -#define I2C_WRITE(d,b,l) ((d)->ops->write(d,b,l)) - -/**************************************************************************** - * Name: I2C_READ - * - * Description: - * Receive a block of data from I2C using the previously selected I2C - * frequency and slave address. Each read operational will be an 'atomic' - * operation in the sense that any other I2C actions will be serialized - * and pend until this read completes. Required. - * - * Input Parameters: - * dev - Device-specific state data - * buffer - A pointer to a buffer of data to receive the data from the device - * buflen - The requested number of bytes to be read - * - * Returned Value: - * 0: success, <0: A negated errno - * - ****************************************************************************/ - -#define I2C_READ(d,b,l) ((d)->ops->read(d,b,l)) - /**************************************************************************** * Name: I2C_TRANSFER * @@ -166,12 +124,15 @@ * Perform a sequence of I2C transfers, each transfer is started with a * START and the final transfer is completed with a STOP. Each sequence * will be an 'atomic' operation in the sense that any other I2C actions - * will be serialized and pend until this read completes. Optional. + * will be serialized and pend until this sequence of transfers completes. + * Required. * * Input Parameters: - * dev - Device-specific state data - * msgs - A pointer to a set of message descriptors - * msgcount - The number of transfers to perform + * dev + + - Device-specific state data + * msgs - A pointer to a set of message descriptors + * count - The number of transfers to perform * * Returned Value: * The number of transfers completed @@ -191,13 +152,13 @@ struct i2c_msg_s; struct i2c_ops_s { uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency); - int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits); - int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer, - int buflen); - int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer, - int buflen); - int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, - int count); + int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits); + int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer, + int buflen); + int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer, + int buflen); + int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, + int count); }; /* This structure contains the full state of I2C as needed for a specific -- GitLab From ecdc428086efa8bc26d4443ef7f1c330f6b5ec88 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 09:22:22 -0600 Subject: [PATCH 662/858] Remove the read and write methods from the I2C interface --- arch | 2 +- include/nuttx/i2c/i2c_master.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/arch b/arch index 6e62a82efb..fab7376e23 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6e62a82efb16b69c704888c98a4c44442c69b803 +Subproject commit fab7376e230534ef45d55f4a575da24f86b01360 diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 9ff3357a30..1c5ddb0d93 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -153,10 +153,6 @@ struct i2c_ops_s { uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency); int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits); - int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer, - int buflen); - int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer, - int buflen); int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count); }; -- GitLab From f9053182d342504a77d06942d79be2f0cc4450ba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 12:14:31 -0600 Subject: [PATCH 663/858] I2C: Remove setaddress method --- Documentation | 2 +- arch | 2 +- drivers/audio/wm8904.c | 1 - drivers/input/stmpe811_base.c | 1 - drivers/input/tsc2007.c | 9 ---- drivers/ioexpander/pca9555.c | 3 +- drivers/lcd/ssd1306_base.c | 3 +- drivers/mtd/at24xx.c | 64 +++++++++++++------------- drivers/power/bq2425x.c | 68 ++++++--------------------- drivers/power/max1704x.c | 64 ++++++-------------------- drivers/sensors/adxl345_base.c | 1 - drivers/sensors/as5048b.c | 64 +++++++------------------- drivers/sensors/bmp180.c | 84 ++++++++++++---------------------- drivers/sensors/lm75.c | 10 ++-- drivers/sensors/lm92.c | 13 ++---- drivers/sensors/lsm9ds1.c | 72 ++++++++--------------------- drivers/sensors/mb7040.c | 79 ++++++++++---------------------- drivers/sensors/mcp9844.c | 75 ++++++++---------------------- drivers/sensors/ms58xx.c | 4 -- drivers/timers/ds3231.c | 5 +- drivers/timers/pcf85263.c | 5 +- drivers/video/ov2640.c | 65 +++++++------------------- include/nuttx/i2c/i2c_master.h | 23 +--------- 23 files changed, 201 insertions(+), 516 deletions(-) diff --git a/Documentation b/Documentation index 443f68d553..4d7a277708 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 443f68d553a2dbc7514366a4b05c81ee2ebb6350 +Subproject commit 4d7a2777081a9773029829531c12b18059fd71e8 diff --git a/arch b/arch index fab7376e23..490bbe2d7b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fab7376e230534ef45d55f4a575da24f86b01360 +Subproject commit 490bbe2d7b5b67ff7efc052abb2e2071ff0aac5c diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index 6b298b079c..a37c2cf5d4 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -2503,7 +2503,6 @@ FAR struct audio_lowerhalf_s * auddbg("address=%02x frequency=%d\n", lower->address, lower->frequency); I2C_SETFREQUENCY(i2c, lower->frequency); - I2C_SETADDRESS(i2c, lower->address, 7); /* Software reset. This puts all WM8904 registers back in their * default state. diff --git a/drivers/input/stmpe811_base.c b/drivers/input/stmpe811_base.c index 9a9ad6caac..72fa6c20f4 100644 --- a/drivers/input/stmpe811_base.c +++ b/drivers/input/stmpe811_base.c @@ -330,7 +330,6 @@ STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev, * modify the address and frequency. */ - I2C_SETADDRESS(dev, config->address, 7); I2C_SETFREQUENCY(dev, config->frequency); #endif diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index 9bc56706e7..82f2d74103 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -1254,15 +1254,6 @@ int tsc2007_register(FAR struct i2c_master_s *dev, config->frequency = I2C_SETFREQUENCY(dev, config->frequency); - /* Set the I2C address and address size */ - - ret = I2C_SETADDRESS(dev, config->address, 7); - if (ret < 0) - { - idbg("I2C_SETADDRESS failed: %d\n", ret); - goto errout_with_priv; - } - /* Make sure that interrupts are disabled */ config->clear(config); diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 7aafe3d9ae..0348ca7ade 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -618,12 +618,11 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *i2cdev, pcadev->dev.ops = &g_pca9555_ops; pcadev->config = config; - /* Set the I2C address and frequency. REVISIT: This logic would be + /* Set the I2C frequency. REVISIT: This logic would be * insufficient if we share the I2C bus with any other devices that also * modify the address and frequency. */ - I2C_SETADDRESS(i2cdev, config->address, 7); I2C_SETFREQUENCY(i2cdev, config->frequency); #ifdef CONFIG_PCA9555_INT_ENABLE diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index 95394e6609..8bb511ee83 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -828,12 +828,11 @@ FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_master_s *dev, unsigned priv->i2c = dev; priv->addr = CONFIG_SSD1306_I2CADDR; - /* Set the I2C address and frequency. REVISIT: This logic would be + /* Set the I2C frequency. REVISIT: This logic would be * insufficient if we share the I2C bus with any other devices that also * modify the address and frequency. */ - I2C_SETADDRESS(priv->i2c, CONFIG_SSD1306_I2CADDR, 7); I2C_SETFREQUENCY(priv->i2c, CONFIG_SSD1306_I2CFREQ); #endif diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 5cfe754dd4..aa235c346a 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -200,15 +200,15 @@ static struct at24c_dev_s g_at24c; * ****************************************************************************/ -static int at24c_i2c_write(FAR struct at24c_dev_s *priv, +static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR const uint8_t *buffer, int buflen) { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = priv->addr; + config.address = at24addr; config.addrlen = 7; return i2c_write(priv->dev, &config, buffer, buflen); @@ -222,15 +222,15 @@ static int at24c_i2c_write(FAR struct at24c_dev_s *priv, * ****************************************************************************/ -static int at24c_i2c_read(FAR struct at24c_dev_s *priv, +static int at24c_i2c_read(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR uint8_t *buffer, int buflen) { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = priv->addr; + config.address = at24addr; config.addrlen = 7; return i2c_read(priv->dev, &config, buffer, buflen); @@ -242,30 +242,32 @@ static int at24c_i2c_read(FAR struct at24c_dev_s *priv, static int at24c_eraseall(FAR struct at24c_dev_s *priv) { - int startblock = 0; uint8_t buf[AT24XX_PAGESIZE + AT24XX_ADDRSIZE]; + int startblock = 0; memset(&buf[AT24XX_ADDRSIZE], 0xff, priv->pagesize); - I2C_SETADDRESS(priv->dev, priv->addr, 7); I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); for (startblock = 0; startblock < priv->npages; startblock++) { uint16_t offset = startblock * priv->pagesize; + uint16_t at24addr; + #if AT24XX_ADDRSIZE == 2 - buf[1] = offset & 0xff; - buf[0] = (offset >> 8) & 0xff; + buf[1] = offset & 0xff; + buf[0] = (offset >> 8) & 0xff; + at24addr = priv->addr; #else - buf[0] = offset & 0xff; - I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); + buf[0] = offset & 0xff; + at24addr = (priv->addr | ((offset >> 8) & 0x07)); #endif - while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, at24addr, buf, AT24XX_ADDRSIZE) < 0) { usleep(1000); } - at24c_i2c_write(priv, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE); + at24c_i2c_write(priv, at24addr, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE); } return OK; @@ -291,6 +293,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, uint8_t address) { uint8_t buf[AT24XX_ADDRSIZE]; + uint16_t at24addr; fvdbg("offset: %lu nbytes: %lu address: %02x\n", (unsigned long)offset, (unsigned long)nbytes, address); @@ -311,17 +314,15 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, */ #if AT24XX_ADDRSIZE == 2 - buf[1] = offset & 0xff; - buf[0] = (offset >> 8) & 0xff; - - I2C_SETADDRESS(priv->dev, address, 7); + buf[1] = offset & 0xff; + buf[0] = (offset >> 8) & 0xff; + at24addr = address; #else - buf[0] = offset & 0xff; - - I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7); + buf[0] = offset & 0xff; + at24addr = (address | ((offset >> 8) & 0x07)); #endif - while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, at24addr, buf, AT24XX_ADDRSIZE) < 0) { fvdbg("wait\n"); usleep(1000); @@ -329,7 +330,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, /* Then transfer the following bytes */ - at24c_i2c_read(priv, buffer, nbytes); + at24c_i2c_read(priv, at24addr, buffer, nbytes); return nbytes; } @@ -421,22 +422,23 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t } fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); - I2C_SETADDRESS(priv->dev, priv->addr, 7); I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); while (blocksleft-- > 0) { uint16_t offset = startblock * priv->pagesize; + uint16_t at24addr; + #if AT24XX_ADDRSIZE == 2 - buf[1] = offset & 0xff; - buf[0] = (offset >> 8) & 0xff; + buf[1] = offset & 0xff; + buf[0] = (offset >> 8) & 0xff; + at24addr = priv->addr; #else - buf[0] = offset & 0xff; - - I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7); + buf[0] = offset & 0xff; + at24addr = (priv->addr | ((offset >> 8) & 0x07)); #endif - while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0) + while (at24c_i2c_write(priv, at24addr, buf, AT24XX_ADDRSIZE) < 0) { fvdbg("wait\n"); usleep(1000); @@ -444,7 +446,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t memcpy(&buf[AT24XX_ADDRSIZE], buffer, priv->pagesize); - at24c_i2c_write(priv, buf, priv->pagesize + AT24XX_ADDRSIZE); + at24c_i2c_write(priv, at24addr, buf, priv->pagesize + AT24XX_ADDRSIZE); startblock++; buffer += priv->pagesize; } diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c index 3a00dc6f1b..3927ce27d4 100644 --- a/drivers/power/bq2425x.c +++ b/drivers/power/bq2425x.c @@ -147,50 +147,6 @@ static const struct battery_charger_operations_s g_bq2425xops = * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: bq2425x_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int bq2425x_i2c_write(FAR struct bq2425x_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->frequency; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: bq2425x_i2c_read - * - * Description: - * Read from the I2C device. - * - ****************************************************************************/ - -static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv, - FAR uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->frequency; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_read(priv->i2c, &config, buffer, buflen); -} - /**************************************************************************** * Name: bq2425x_getreg8 * @@ -205,16 +161,19 @@ static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv, static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval) { + struct i2c_config_s config; uint8_t val; int ret; - /* Set the I2C address and address size */ + /* Set up the I2C configuration */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; /* Write the register address */ - ret = bq2425x_i2c_write(priv, ®addr, 1); + ret = i2c_write(priv->i2c, &config, ®addr, 1); if (ret < 0) { batdbg("i2c_write failed: %d\n", ret); @@ -223,7 +182,7 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, /* Restart and read 8-bits from the register */ - ret = bq2425x_i2c_read(priv, &val, 1); + ret = i2c_read(priv->i2c, &config, &val, 1); if (ret < 0) { batdbg("i2c_read failed: %d\n", ret); @@ -249,8 +208,15 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, uint8_t regval) { + struct i2c_config_s config; uint8_t buffer[2]; + /* Set up the I2C configuration */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + batdbg("addr: %02x regval: %08x\n", regaddr, regval); /* Set up a 3 byte message to send */ @@ -258,13 +224,9 @@ static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr, buffer[0] = regaddr; buffer[1] = regval; - /* Set the I2C address and address size */ - - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - /* Write the register address followed by the data (no RESTART) */ - return bq2425x_i2c_write(priv, buffer, 2); + return i2c_write(priv->i2c, &config, buffer, 2); } /**************************************************************************** diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 5ced5cfc09..8228413409 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -229,50 +229,6 @@ static const struct battery_gauge_operations_s g_max1704xops = * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: max1704x_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int max1704x_i2c_write(FAR struct max1704x_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->frequency; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: max1704x_i2c_read - * - * Description: - * Read from the I2C device. - * - ****************************************************************************/ - -static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv, - FAR uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->frequency; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_read(priv->i2c, &config, buffer, buflen); -} - /**************************************************************************** * Name: max1704x_getreg16 * @@ -287,16 +243,19 @@ static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv, static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, FAR uint16_t *regval) { + struct i2c_config_s config; uint8_t buffer[2]; int ret; - /* Set the I2C address and address size */ + /* Set up the configuration and perform the write-read operation */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; /* Write the register address */ - ret = max1704x_i2c_write(priv, ®addr, 1); + ret = i2c_write(priv->i2c, &config, ®addr, 1); if (ret < 0) { batdbg("i2c_write failed: %d\n", ret); @@ -305,7 +264,7 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, /* Restart and read 16-bits from the register */ - ret = max1704x_i2c_read(priv, buffer, 2); + ret = i2c_read(priv->i2c, &config, buffer, 2); if (ret < 0) { batdbg("i2c_read failed: %d\n", ret); @@ -330,6 +289,7 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, uint16_t regval) { + struct i2c_config_s config; uint8_t buffer[3]; batdbg("addr: %02x regval: %08x\n", regaddr, regval); @@ -340,13 +300,15 @@ static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr, buffer[1] = (uint8_t)(regval >> 8); buffer[2] = (uint8_t)(regval & 0xff); - /* Set the I2C address and address size */ + /* Set up the configuration and perform the write-read operation */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; /* Write the register address followed by the data (no RESTART) */ - return max1704x_i2c_write(priv, buffer, 3); + return i2c_write(priv->i2c, &config, buffer, 3); } /**************************************************************************** diff --git a/drivers/sensors/adxl345_base.c b/drivers/sensors/adxl345_base.c index ff5789e339..d2c9362314 100644 --- a/drivers/sensors/adxl345_base.c +++ b/drivers/sensors/adxl345_base.c @@ -417,7 +417,6 @@ ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_master_s *dev, * modify the address and frequency. */ - I2C_SETADDRESS(dev, config->address, 7); I2C_SETFREQUENCY(dev, config->frequency); #endif diff --git a/drivers/sensors/as5048b.c b/drivers/sensors/as5048b.c index 154f82bd63..96b3d4d19f 100644 --- a/drivers/sensors/as5048b.c +++ b/drivers/sensors/as5048b.c @@ -115,66 +115,28 @@ static const struct qe_ops_s g_qeops = ****************************************************************************/ /**************************************************************************** - * Name: as5048b_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int as5048b_i2c_write(FAR struct as5048b_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->frequency; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: as5048b_i2c_read + * Name: as5048b_readu8 * * Description: - * Read from the I2C device. + * Read from an 8-bit register * ****************************************************************************/ -static int as5048b_i2c_read(FAR struct as5048b_dev_s *priv, - FAR uint8_t *buffer, int buflen) +static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, + FAR uint8_t *regval) { + int ret; struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = priv->frequency; config.address = priv->addr; config.addrlen = 7; - return i2c_read(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: as5048b_readu8 - * - * Description: - * Read from an 8-bit register - * - ****************************************************************************/ - -static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, - FAR uint8_t *regval) -{ - int ret; - /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = as5048b_i2c_write(priv, ®addr, sizeof(regaddr)); + ret = i2c_write(priv->i2c, &config, ®addr, sizeof(regaddr)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); @@ -183,7 +145,7 @@ static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, /* Restart and read 8 bits from the register */ - ret = as5048b_i2c_read(priv, regval, sizeof(*regval)); + ret = i2c_read(priv->i2c, &config, regval, sizeof(*regval)); if (ret < 0) { sndbg("i2c_read failed: %d\n", ret); @@ -243,11 +205,18 @@ static int as5048b_readu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, uint8_t regval) { + struct i2c_config_s config; uint8_t buffer[2]; int ret; sndbg("addr: %02x value: %02x\n", regaddr, regval); + /* Set up the I2C configuration */ + + config.frequency = priv->frequency; + config.address = priv->addr; + config.addrlen = 7; + /* Set up a 2-byte message to send */ buffer[0] = regaddr; @@ -255,8 +224,7 @@ static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = as5048b_i2c_write(priv, buffer, sizeof(buffer)); + ret = i2c_write(priv->i2c, &config, buffer, sizeof(buffer)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index 97fda6221a..3279647ef9 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -174,74 +174,37 @@ static const struct file_operations g_bmp180fops = ****************************************************************************/ /**************************************************************************** - * Name: bmp180_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int bmp180_i2c_write(FAR struct bmp180_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = priv->freq; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: bmp180_i2c_read + * Name: bmp180_getreg8 * * Description: - * Read from the I2C device. + * Read from an 8-bit BMP180 register * ****************************************************************************/ -static int bmp180_i2c_read(FAR struct bmp180_dev_s *priv, - FAR uint8_t *buffer, int buflen) +static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr) { struct i2c_config_s config; + uint8_t regval = 0; + int ret; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = priv->freq; config.address = priv->addr; config.addrlen = 7; - return i2c_read(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: bmp180_getreg8 - * - * Description: - * Read from an 8-bit BMP180 register - * - ****************************************************************************/ - -static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr) -{ - int ret; - uint8_t regval = 0; - - /* Restart the register */ + /* Write the register address */ - ret = bmp180_i2c_write(priv, ®addr, 1); + ret = i2c_write(priv->i2c, &config, ®addr, 1); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); return ret; } - /* Restart the register */ + /* Read the register value */ - ret = bmp180_i2c_read(priv, ®val, 1); + ret = i2c_read(priv->i2c, &config, ®val, 1); if (ret < 0) { sndbg("i2c_read failed: %d\n", ret); @@ -261,13 +224,20 @@ static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr) static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr) { - int ret; + struct i2c_config_s config; uint16_t msb, lsb; uint16_t regval = 0; + int ret; + + /* Set up the I2C configuration */ + + config.frequency = priv->freq; + config.address = priv->addr; + config.addrlen = 7; /* Register to read */ - ret = bmp180_i2c_write(priv, ®addr, 1); + ret = i2c_write(priv->i2c, &config, ®addr, 1); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); @@ -276,7 +246,7 @@ static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr) /* Read register */ - ret = bmp180_i2c_read(priv, (uint8_t *)®val, 2); + ret = i2c_read(priv->i2c, &config, (uint8_t *)®val, 2); if (ret < 0) { sndbg("i2c_read failed: %d\n", ret); @@ -304,15 +274,22 @@ static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr) static void bmp180_putreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr, uint8_t regval) { - int ret; + struct i2c_config_s config; uint8_t data[2]; + int ret; + + /* Set up the I2C configuration */ + + config.frequency = priv->freq; + config.address = priv->addr; + config.addrlen = 7; data[0] = regaddr; data[1] = regval; - /* Restart the register */ + /* Write the register address and value */ - ret = bmp180_i2c_write(priv, (uint8_t *) &data, 2); + ret = i2c_write(priv->i2c, &config, (uint8_t *) &data, 2); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); @@ -635,7 +612,6 @@ int bmp180_register(FAR const char *devpath, FAR struct i2c_master_s *i2c) /* Configure I2C before using it */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); I2C_SETFREQUENCY(priv->i2c, priv->freq); /* Check Device ID */ diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index f70c61bfd1..4affac4554 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -137,7 +137,7 @@ static int lm75_i2c_write(FAR struct lm75_dev_s *priv, { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_LM75_I2C_FREQUENCY; config.address = priv->addr; @@ -159,7 +159,7 @@ static int lm75_i2c_read(FAR struct lm75_dev_s *priv, { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_LM75_I2C_FREQUENCY; config.address = priv->addr; @@ -184,7 +184,6 @@ static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = lm75_i2c_write(priv, ®addr, 1); if (ret < 0) { @@ -237,7 +236,6 @@ static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); return lm75_i2c_write(priv, buffer, 3); } @@ -294,9 +292,8 @@ static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf) /* Write the configuration register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - buffer = LM75_CONF_REG; + ret = lm75_i2c_write(priv, &buffer, 1); if (ret < 0) { @@ -332,7 +329,6 @@ static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf) /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); return lm75_i2c_write(priv, buffer, 2); } diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index e168e90a51..6d8bf190c0 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -139,7 +139,7 @@ static int lm92_i2c_write(FAR struct lm92_dev_s *priv, { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_LM92_I2C_FREQUENCY; config.address = priv->addr; @@ -161,7 +161,7 @@ static int lm92_i2c_read(FAR struct lm92_dev_s *priv, { struct i2c_config_s config; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_LM92_I2C_FREQUENCY; config.address = priv->addr; @@ -187,7 +187,6 @@ static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = lm92_i2c_write(priv, ®addr, 1); if (ret < 0) { @@ -240,7 +239,6 @@ static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr, /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); return lm92_i2c_write(priv, buffer, 3); } @@ -297,9 +295,8 @@ static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf) /* Write the configuration register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - buffer = LM92_CONF_REG; + ret = lm92_i2c_write(priv, &buffer, 1); if (ret < 0) { @@ -335,7 +332,6 @@ static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf) /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); return lm92_i2c_write(priv, buffer, 2); } @@ -355,9 +351,8 @@ static int lm92_readid(FAR struct lm92_dev_s *priv, FAR uint16_t *id) /* Write the identification register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - regaddr = LM92_ID_REG; + ret = lm92_i2c_write(priv, ®addr, 1); if (ret < 0) { diff --git a/drivers/sensors/lsm9ds1.c b/drivers/sensors/lsm9ds1.c index 3977cafeb1..10f902aeaa 100644 --- a/drivers/sensors/lsm9ds1.c +++ b/drivers/sensors/lsm9ds1.c @@ -522,10 +522,6 @@ struct lsm9ds1_dev_s ****************************************************************************/ /* I2C Helpers */ -static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv, - FAR const uint8_t *buffer, int buflen); -static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv, - FAR uint8_t *buffer, int buflen); static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval); static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, @@ -634,50 +630,6 @@ static const struct lsm9ds1_ops_s g_lsm9ds1mag_ops = * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: lsm9ds1_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: lsm9ds1_i2c_read - * - * Description: - * Read from the I2C device. - * - ****************************************************************************/ - -static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv, - FAR uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_read(priv->i2c, &config, buffer, buflen); -} - /**************************************************************************** * Name: lsm9ds1_readreg8 * @@ -689,6 +641,7 @@ static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv, static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, FAR uint8_t *regval) { + struct i2c_config_s config; int ret; /* Sanity check */ @@ -696,10 +649,15 @@ static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, DEBUGASSERT(priv != NULL); DEBUGASSERT(regval != NULL); + /* Set up the I2C configuration */ + + config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = lsm9ds1_i2c_write(priv, ®addr, sizeof(regaddr)); + ret = i2c_write(priv->i2c, &config, ®addr, sizeof(regaddr)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); @@ -708,7 +666,7 @@ static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, /* Restart and read 8 bits from the register */ - ret = lsm9ds1_i2c_read(priv, regval, sizeof(*regval)); + ret = i2c_read(priv->i2c, &config, regval, sizeof(*regval)); if (ret < 0) { sndbg("i2c_read failed: %d\n", ret); @@ -730,8 +688,9 @@ static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, uint8_t regval) { - int ret; + struct i2c_config_s config; uint8_t buffer[2]; + int ret; /* Sanity check */ @@ -742,10 +701,15 @@ static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr, buffer[0] = regaddr; buffer[1] = regval; + /* Set up the I2C configuration */ + + config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = lsm9ds1_i2c_write(priv, buffer, sizeof(buffer)); + ret = i2c_write(priv->i2c, &config, buffer, sizeof(buffer)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); diff --git a/drivers/sensors/mb7040.c b/drivers/sensors/mb7040.c index 5840204e0a..4308b2f73e 100644 --- a/drivers/sensors/mb7040.c +++ b/drivers/sensors/mb7040.c @@ -77,10 +77,6 @@ struct mb7040_dev_s ****************************************************************************/ /* I2C Helpers */ -static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv, - FAR const uint8_t *buffer, int buflen); -static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv, - FAR uint8_t *buffer, int buflen); static int mb7040_measurerange(FAR struct mb7040_dev_s *priv); static int mb7040_readrange(FAR struct mb7040_dev_s *priv, FAR uint16_t *range); @@ -122,69 +118,32 @@ static const struct file_operations g_fops = ****************************************************************************/ /**************************************************************************** - * Name: mb7040_i2c_write + * Name: mb7040_measurerange * * Description: - * Write to the I2C device. + * Command the device to measure the range. * ****************************************************************************/ -static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv, - FAR const uint8_t *buffer, int buflen) +static int mb7040_measurerange(FAR struct mb7040_dev_s *priv) { struct i2c_config_s config; + uint8_t regaddr; + int ret; - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_MB7040_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: mb7040_i2c_read - * - * Description: - * Read from the I2C device. - * - ****************************************************************************/ - -static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv, - FAR uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; + sndbg("addr: %02x\n", regaddr); - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_MB7040_I2C_FREQUENCY; config.address = priv->addr; config.addrlen = 7; - return i2c_read(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: mb7040_measurerange - * - * Description: - * Command the device to measure the range. - * - ****************************************************************************/ - -static int mb7040_measurerange(FAR struct mb7040_dev_s *priv) -{ - uint8_t regaddr; - int ret; + /* Write the register address */ regaddr = MB7040_RANGE_REG; - sndbg("addr: %02x\n", regaddr); - - /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = mb7040_i2c_write(priv, ®addr, sizeof(regaddr)); + ret = i2c_write(priv->i2c, &config, ®addr, sizeof(regaddr)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); @@ -204,13 +163,19 @@ static int mb7040_measurerange(FAR struct mb7040_dev_s *priv) static int mb7040_readrange(FAR struct mb7040_dev_s *priv, FAR uint16_t *range) { + struct i2c_config_s config; uint8_t buffer[2]; int ret; + /* Set up the I2C configuration */ + + config.frequency = CONFIG_MB7040_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + /* Read two bytes */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = mb7040_i2c_read(priv, buffer, sizeof(buffer)); + ret = i2c_read(priv->i2c, &config, buffer, sizeof(buffer)); if (ret < 0) { sndbg("i2c_read failed: %d\n", ret); @@ -232,6 +197,7 @@ static int mb7040_readrange(FAR struct mb7040_dev_s *priv, static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr) { + struct i2c_config_s config; uint8_t buffer[3]; int ret; @@ -248,10 +214,15 @@ static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr) buffer[1] = MB7040_ADDRUNLOCK2_REG; buffer[2] = addr; + /* Set up the I2C configuration */ + + config.frequency = CONFIG_MB7040_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + /* Write the register address followed by the data (no RESTART) */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - ret = mb7040_i2c_write(priv, buffer, sizeof(buffer)); + ret = i2c_write(priv->i2c, &config, buffer, sizeof(buffer)); if (ret < 0) { sndbg("i2c_write failed: %d\n", ret); diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c index 1c4b044e5d..c21e415560 100644 --- a/drivers/sensors/mcp9844.c +++ b/drivers/sensors/mcp9844.c @@ -77,10 +77,6 @@ struct mcp9844_dev_s /* I2C helper functions */ -static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv, - FAR const uint8_t *buffer, int buflen); -static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv, - FAR uint8_t *buffer, int buflen); static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, uint8_t const regaddr, FAR uint16_t *value); static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, @@ -119,67 +115,29 @@ static const struct file_operations g_mcp9844_fops = ****************************************************************************/ /**************************************************************************** - * Name: mcp9844_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_MCP9844_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; - - return i2c_write(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: mcp9844_i2c_read + * Name: mcp9844_read_u16 * * Description: - * Read from the I2C device. + * Read a 16 bit valie from the MCP9844 at the address regaddr. * ****************************************************************************/ -static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv, - FAR uint8_t *buffer, int buflen) +static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, + uint8_t const regaddr, FAR uint16_t *value) { struct i2c_config_s config; + uint8_t buffer[2]; + int ret = -1; - /* Set up the configuration and perform the write-read operation */ + /* Set up the I2C configuration */ config.frequency = CONFIG_MCP9844_I2C_FREQUENCY; config.address = priv->addr; config.addrlen = 7; - return i2c_read(priv->i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: mcp9844_read_u16 - * - * Description: - * Read a 16 bit valie from the MCP9844 at the address regaddr. - * - ****************************************************************************/ - -static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, - uint8_t const regaddr, FAR uint16_t *value) -{ - int ret = -1; - /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); - - ret = mcp9844_i2c_write(priv, ®addr, 1); + ret = i2c_write(priv->i2c, &config, ®addr, 1); if (ret < 0) { sndbg ("i2c_write failed: %d\n", ret); @@ -188,9 +146,7 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, /* Restart and read 16-bits from the register */ - uint8_t const BUFFER_SIZE = 2; - uint8_t buffer[BUFFER_SIZE]; - ret = mcp9844_i2c_read(priv, buffer, BUFFER_SIZE); + ret = i2c_read(priv->i2c, &config, buffer, 2); if (ret < 0) { sndbg ("i2c_read failed: %d\n", ret); @@ -202,7 +158,6 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, *value = (((uint16_t)(buffer[0]))<<8) + ((uint16_t)(buffer[1])); sndbg("addr: %02x value: %08x ret: %d\n", regaddr, *value, ret); - return OK; } @@ -217,6 +172,8 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv, static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, uint8_t const regaddr, uint16_t const regval) { + struct i2c_config_s config; + sndbg("addr: %02x value: %08x\n", regaddr, regval); /* Set up a 3 byte message to send */ @@ -228,11 +185,15 @@ static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv, buffer[1] = (uint8_t)(regval >> 8); buffer[2] = (uint8_t)(regval); - /* Write the register address followed by the data (no RESTART) */ + /* Set up the I2C configuration */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); + config.frequency = CONFIG_MCP9844_I2C_FREQUENCY; + config.address = priv->addr; + config.addrlen = 7; + + /* Write the register address followed by the data (no RESTART) */ - return mcp9844_i2c_write(priv, buffer, BUFFER_SIZE); + return i2c_write(priv->i2c, &config, buffer, BUFFER_SIZE); } /**************************************************************************** diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index a6e880d59e..1d4bfdd68c 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -302,7 +302,6 @@ static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { @@ -343,7 +342,6 @@ static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc) /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { @@ -551,7 +549,6 @@ static int ms58xx_reset(FAR struct ms58xx_dev_s *priv) /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { @@ -588,7 +585,6 @@ static int ms58xx_convert(FAR struct ms58xx_dev_s *priv, uint8_t regaddr, /* Write the register address */ - I2C_SETADDRESS(priv->i2c, priv->addr, 7); ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr)); if (ret < 0) { diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 32f87863a9..19c3a3e237 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -330,9 +330,8 @@ int up_rtc_getdatetime(FAR struct tm *tp) I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer (This could be done with i2c_writeread()). The - * transfer may be performed repeatedly of the seconds values decreases, - * meaning that that was a rollover in the seconds. + /* Perform the transfer. The transfer may be performed repeatedly of the + * seconds values decreases, meaning that that was a rollover in the seconds. */ do diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 201179199a..eaf8b6d10f 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -329,9 +329,8 @@ int up_rtc_getdatetime(FAR struct tm *tp) I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); - /* Perform the transfer (This could be done with i2c_writeread()). The - * transfer may be performed repeatedly of the seconds values decreases, - * meaning that that was a rollover in the seconds. + /* Perform the transfer. The transfer may be performed repeatedly of the + * seconds values decreases, meaning that that was a rollover in the seconds. */ do diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 04c431c24a..19812e3224 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -671,50 +671,6 @@ static const struct ovr2640_reg_s g_ov2640_jpeg_uxga_resolution[] = * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: ov2640_i2c_write - * - * Description: - * Write to the I2C device. - * - ****************************************************************************/ - -static int ov2640_i2c_write(FAR struct i2c_master_s *i2c, - FAR const uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_OV2640_FREQUENCY; - config.address = CONFIG_OV2640_I2CADDR; - config.addrlen = 7; - - return i2c_write(i2c, &config, buffer, buflen); -} - -/**************************************************************************** - * Name: ov2640_i2c_read - * - * Description: - * Read from the I2C device. - * - ****************************************************************************/ - -static int ov2640_i2c_read(FAR struct i2c_master_s *i2c, - FAR uint8_t *buffer, int buflen) -{ - struct i2c_config_s config; - - /* Set up the configuration and perform the write-read operation */ - - config.frequency = CONFIG_OV2640_FREQUENCY; - config.address = CONFIG_OV2640_I2CADDR; - config.addrlen = 7; - - return i2c_read(i2c, &config, buffer, buflen); -} - /**************************************************************************** * Function: ov2640_putreg * @@ -735,6 +691,7 @@ static int ov2640_i2c_read(FAR struct i2c_master_s *i2c, static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, uint8_t regval) { + struct i2c_config_s config; uint8_t buffer[2]; int ret; @@ -747,9 +704,15 @@ static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, buffer[0] = regaddr; /* Register address */ buffer[1] = regval; /* New register value */ + /* Set up the I2C configuration */ + + config.frequency = CONFIG_OV2640_FREQUENCY; + config.address = CONFIG_OV2640_I2CADDR; + config.addrlen = 7; + /* And do it */ - ret = ov2640_i2c_write(i2c, buffer, 2); + ret = i2c_write(i2c, &config, buffer, 2); if (ret < 0) { gdbg("ERROR: i2c_write failed: %d\n", ret); @@ -778,12 +741,19 @@ static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr, static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr) { + struct i2c_config_s config; uint8_t regval; int ret; + /* Set up the I2C configuration */ + + config.frequency = CONFIG_OV2640_FREQUENCY; + config.address = CONFIG_OV2640_I2CADDR; + config.addrlen = 7; + /* Write the register address */ - ret = ov2640_i2c_write(i2c, ®addr, 1); + ret = i2c_write(i2c, &config, ®addr, 1); if (ret < 0) { gdbg("ERROR: i2c_write failed: %d\n", ret); @@ -792,7 +762,7 @@ static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr) /* Restart and read 8-bits from the register */ - ret = ov2640_i2c_read(i2c, ®val, 1); + ret = i2c_read(i2c, &config, ®val, 1); if (ret < 0) { gdbg("ERROR: i2c_read failed: %d\n", ret); @@ -954,7 +924,6 @@ int ov2640_initialize(FAR struct i2c_master_s *i2c) /* Configure I2C bus for the OV2640 */ - I2C_SETADDRESS(i2c, CONFIG_OV2640_I2CADDR, 7); I2C_SETFREQUENCY(i2c, CONFIG_OV2640_FREQUENCY); /* Reset the OVR2640 */ diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 1c5ddb0d93..dee94a5e7a 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -98,25 +98,6 @@ #define I2C_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) -/**************************************************************************** - * Name: I2C_SETADDRESS - * - * Description: - * Set the I2C slave address. This frequency will be retained in the struct - * i2c_master_s instance and will be used with all transfers. Required. - * - * Input Parameters: - * dev - Device-specific state data - * address - The I2C slave address - * nbits - The number of address bits provided (7 or 10) - * - * Returned Value: - * Returns OK on success; a negated errno on failure. - * - ****************************************************************************/ - -#define I2C_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n)) - /**************************************************************************** * Name: I2C_TRANSFER * @@ -125,7 +106,6 @@ * START and the final transfer is completed with a STOP. Each sequence * will be an 'atomic' operation in the sense that any other I2C actions * will be serialized and pend until this sequence of transfers completes. - * Required. * * Input Parameters: * dev @@ -152,9 +132,8 @@ struct i2c_msg_s; struct i2c_ops_s { uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency); - int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits); int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, - int count); + int count); }; /* This structure contains the full state of I2C as needed for a specific -- GitLab From 6ad641888b95e5a9b211dff0acac480d5914bde8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 14:17:20 -0600 Subject: [PATCH 664/858] Add I2C frequency to the i2c_msg_s structure --- ChangeLog | 6 +++ Documentation | 2 +- TODO | 12 ++--- arch | 2 +- configs | 2 +- drivers/audio/wm8904.c | 18 ++++---- drivers/i2c/i2c_read.c | 15 +++---- drivers/i2c/i2c_write.c | 15 +++---- drivers/i2c/i2c_writeread.c | 22 +++++---- drivers/input/mxt.c | 51 ++++++++++++--------- drivers/input/stmpe811_base.c | 53 ++++++++++++---------- drivers/input/tsc2007.c | 43 ++++++++++-------- drivers/lcd/ssd1306_i2c.c | 22 ++++----- drivers/sensors/Kconfig | 7 ++- drivers/sensors/adxl345_i2c.c | 55 ++++++++++++----------- drivers/sensors/lis331dl.c | 23 ++++++---- drivers/timers/cs2100-cp.c | 76 ++++++++++++++++++-------------- drivers/timers/ds3231.c | 67 +++++++++++++++------------- drivers/timers/pcf85263.c | 67 +++++++++++++++------------- include/nuttx/i2c/i2c_master.h | 3 +- include/nuttx/timers/cs2100-cp.h | 1 + 21 files changed, 309 insertions(+), 253 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f05f87921..78aa885aab 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11429,3 +11429,9 @@ board with NXP LPCExpresso LPC1768. The GSM module is one of LISA-C200, LISA-U200 or SARA-G350. The GPS module is one of MAX-M7 or MAX-M8. From Vladimir Komendantskiy (2016-01-31). + * drivers/, arch/, include/, numerous files: May restructuring of the I2C + interface necessary to eliminate some thread-safety issues inherent in + the legacy I2C interface design. This effects the interface definition, + all I2C clients, and all low-level I2C drivers. I have used caution, + but I still expect a change of this magnitude to introduce some errors. + Any bug reports of bug fixes will be much appreciated (2016-02-01). diff --git a/Documentation b/Documentation index 4d7a277708..7d40326c7f 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 4d7a2777081a9773029829531c12b18059fd71e8 +Subproject commit 7d40326c7f8ca77993caaa7bb940e3ae2a631f9d diff --git a/TODO b/TODO index 854b3996e4..57f3b74f8b 100644 --- a/TODO +++ b/TODO @@ -1614,18 +1614,14 @@ o Other drivers (drivers/) in a multi-tasking I2C environment: - I2C_SETFREQUENCY: Frequency setting can be overwritten by other I2C usage. - - I2C_SETADDRESS: The I2C address can and will be changed by other - I2C usage. NOTE also that I2C_SETADDRESS also sets the address width - (either 7 or 10 bits). - - I2C_TRANSFER: This is the only interface that is properly self - contained and protected from most mult-tasking issues. But even - this interface can suffer if there are differing frequency settings. + - I2C_TRANSFER: This interface is almost self but even can suffer + if there are differing frequency settings. Status: Open Priority: Medium-High. The fix is easy but effects a lot of software. There are two ways to fix theses problems: (1) Add a locking method such as is provided with the SPI interface, or (2) make each interface - self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS - methods; Add frequency to the I2C_TRANSFER message structure. + self-contained and atomic: Remove the I2C_FREQUENCY and add + frequency to the I2C_TRANSFER message structure. o Linux/Cywgin simulation (arch/sim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/arch b/arch index 490bbe2d7b..18c2083af2 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 490bbe2d7b5b67ff7efc052abb2e2071ff0aac5c +Subproject commit 18c2083af2a73f710e2777c42ccd7ca8ae4096bf diff --git a/configs b/configs index 7286dea76c..5888111526 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7286dea76c9a19895a14d02b593c4c6356461a9d +Subproject commit 588811152643ca752381a52ec57986c0c4b1a376 diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index a37c2cf5d4..cfc04a3ddc 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -266,17 +266,19 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr) /* Set up to write the address */ - msg[0].addr = priv->lower->address; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; + msg[0].frequency = priv->lower->frequency; + msg[0].addr = priv->lower->address; + msg[0].flags = 0; + msg[0].buffer = ®addr; + msg[0].length = 1; /* Followed by the read data */ - msg[1].addr = priv->lower->address; - msg[1].flags = I2C_M_READ; - msg[1].buffer = data; - msg[1].length = 2; + msg[1].frequency = priv->lower->frequency; + msg[1].addr = priv->lower->address; + msg[1].flags = I2C_M_READ; + msg[1].buffer = data; + msg[1].length = 2; /* Read the register data. The returned value is the number messages * completed. diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 1c0a840cd4..72134c2c50 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -79,16 +79,13 @@ int i2c_read(FAR struct i2c_master_s *dev, /* Setup for the transfer */ - msg.addr = config->address, - msg.flags = (flags | I2C_M_READ); - msg.buffer = buffer; - msg.length = buflen; + msg.frequency = config->frequency, + msg.addr = config->address, + msg.flags = (flags | I2C_M_READ); + msg.buffer = buffer; + msg.length = buflen; - /* Then perform the transfer - * - * REVISIT: The following two operations must become atomic in order to - * assure thread safety. - */ + /* Then perform the transfer. */ I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, &msg, 1); diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index d98be5e293..11eb25cc7d 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -74,16 +74,13 @@ int i2c_write(FAR struct i2c_master_s *dev, /* Setup for the transfer */ - msg.addr = config->address; - msg.flags = (config->addrlen == 10) ? I2C_M_TEN : 0; - msg.buffer = (FAR uint8_t *)buffer; /* Override const */ - msg.length = buflen; + msg.frequency = config->frequency, + msg.addr = config->address; + msg.flags = (config->addrlen == 10) ? I2C_M_TEN : 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - /* Then perform the transfer - * - * REVISIT: The following two operations must become atomic in order to - * assure thread safety. - */ + /* Then perform the transfer. */ I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, &msg, 1); diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index da421680f6..265f272d1d 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -82,10 +82,11 @@ int i2c_writeread(FAR struct i2c_master_s *dev, /* Format two messages: The first is a write */ - msg[0].addr = config->address; - msg[0].flags = flags; - msg[0].buffer = (FAR uint8_t *)wbuffer; /* Override const */ - msg[0].length = wbuflen; + msg[0].frequency = config->frequency, + msg[0].addr = config->address; + msg[0].flags = flags; + msg[0].buffer = (FAR uint8_t *)wbuffer; /* Override const */ + msg[0].length = wbuflen; /* The second is either a read (rbuflen > 0) or a write (rbuflen < 0) with * no restart. @@ -101,15 +102,12 @@ int i2c_writeread(FAR struct i2c_master_s *dev, rbuflen = -rbuflen; } - msg[1].addr = config->address; - msg[1].buffer = rbuffer; - msg[1].length = rbuflen; + msg[1].frequency = config->frequency, + msg[1].addr = config->address; + msg[1].buffer = rbuffer; + msg[1].length = rbuflen; - /* Then perform the transfer - * - * REVISIT: The following two operations must become atomic in order to - * assure thread safety. - */ + /* Then perform the transfer. */ I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, msg, 2); diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index f5ebec8e89..768ebe095b 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -315,20 +315,22 @@ static int mxt_getreg(FAR struct mxt_dev_s *priv, uint16_t regaddr, /* Set up to write the address */ - addrbuf[0] = regaddr & 0xff; - addrbuf[1] = (regaddr >> 8) & 0xff; + addrbuf[0] = regaddr & 0xff; + addrbuf[1] = (regaddr >> 8) & 0xff; - msg[0].addr = priv->lower->address; - msg[0].flags = 0; - msg[0].buffer = addrbuf; - msg[0].length = 2; + msg[0].frequency = priv->frequency; + msg[0].addr = priv->lower->address; + msg[0].flags = 0; + msg[0].buffer = addrbuf; + msg[0].length = 2; /* Followed by the read data */ - msg[1].addr = priv->lower->address; - msg[1].flags = I2C_M_READ; - msg[1].buffer = buffer; - msg[1].length = buflen; + msg[1].frequency = priv->frequency; + msg[1].addr = priv->lower->address; + msg[1].flags = I2C_M_READ; + msg[1].buffer = buffer; + msg[1].length = buflen; /* Read the register data. The returned value is the number messages * completed. @@ -387,20 +389,22 @@ static int mxt_putreg(FAR struct mxt_dev_s *priv, uint16_t regaddr, /* Set up to write the address */ - addrbuf[0] = regaddr & 0xff; - addrbuf[1] = (regaddr >> 8) & 0xff; + addrbuf[0] = regaddr & 0xff; + addrbuf[1] = (regaddr >> 8) & 0xff; - msg[0].addr = priv->lower->address; - msg[0].flags = 0; - msg[0].buffer = addrbuf; - msg[0].length = 2; + msg[0].frequency = priv->frequency; + msg[0].addr = priv->lower->address; + msg[0].flags = 0; + msg[0].buffer = addrbuf; + msg[0].length = 2; /* Followed by the write data (with no repeated start) */ - msg[1].addr = priv->lower->address; - msg[1].flags = I2C_M_NORESTART; - msg[1].buffer = (FAR uint8_t *)buffer; - msg[1].length = buflen; + msg[1].frequency = priv->frequency; + msg[1].addr = priv->lower->address; + msg[1].flags = I2C_M_NORESTART; + msg[1].buffer = (FAR uint8_t *)buffer; + msg[1].length = buflen; /* Write the register data. The returned value is the number messages * completed. @@ -1511,7 +1515,9 @@ static int mxt_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(priv->lower != NULL && ptr != NULL); - priv->frequency = I2C_SETFREQUENCY(priv->i2c, *ptr); + + priv->frequency = *ptr; + (void)I2C_SETFREQUENCY(priv->i2c, *ptr); } break; @@ -1734,7 +1740,8 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv) /* Set the selected I2C frequency */ - priv->frequency = I2C_SETFREQUENCY(priv->i2c, priv->lower->frequency); + priv->frequency = priv->lower->frequency; + (void)I2C_SETFREQUENCY(priv->i2c, priv->lower->frequency); /* Read the info registers from the device */ diff --git a/drivers/input/stmpe811_base.c b/drivers/input/stmpe811_base.c index 72fa6c20f4..c115d985fe 100644 --- a/drivers/input/stmpe811_base.c +++ b/drivers/input/stmpe811_base.c @@ -408,19 +408,21 @@ uint8_t stmpe811_getreg8(FAR struct stmpe811_dev_s *priv, uint8_t regaddr) /* Setup 8-bit STMPE811 address write message */ - msg[0].addr = priv->config->address; /* 7-bit address */ - msg[0].flags = 0; /* Write transaction, beginning with START */ - msg[0].buffer = ®addr; /* Transfer from this address */ - msg[0].length = 1; /* Send one byte following the address - * (no STOP) */ + msg[0].frequency = priv->config->frequency; /* I2C frequency */ + msg[0].addr = priv->config->address; /* 7-bit address */ + msg[0].flags = 0; /* Write transaction, beginning with START */ + msg[0].buffer = ®addr; /* Transfer from this address */ + msg[0].length = 1; /* Send one byte following the address + * (no STOP) */ /* Set up the 8-bit STMPE811 data read message */ - msg[1].addr = priv->config->address; /* 7-bit address */ - msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ - msg[1].buffer = ®val; /* Transfer to this address */ - msg[1].length = 1; /* Receive one byte following the address - * (then STOP) */ + msg[1].frequency = priv->config->frequency; /* I2C frequency */ + msg[1].addr = priv->config->address; /* 7-bit address */ + msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ + msg[1].buffer = ®val; /* Transfer to this address */ + msg[1].length = 1; /* Receive one byte following the address + * (then STOP) */ /* Perform the transfer */ @@ -472,10 +474,11 @@ void stmpe811_putreg8(FAR struct stmpe811_dev_s *priv, /* Setup 8-bit STMPE811 address write message */ - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = txbuffer; /* Transfer from this address */ - msg.length = 2; /* Send two byte following the address + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = txbuffer; /* Transfer from this address */ + msg.length = 2; /* Send two byte following the address * (then STOP) */ /* Perform the transfer */ @@ -513,19 +516,21 @@ uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr) /* Setup 8-bit STMPE811 address write message */ - msg[0].addr = priv->config->address; /* 7-bit address */ - msg[0].flags = 0; /* Write transaction, beginning with START */ - msg[0].buffer = ®addr; /* Transfer from this address */ - msg[0].length = 1; /* Send one byte following the address - * (no STOP) */ + msg[0].frequency = priv->config->frequency; /* I2C frequency */ + msg[0].addr = priv->config->address; /* 7-bit address */ + msg[0].flags = 0; /* Write transaction, beginning with START */ + msg[0].buffer = ®addr; /* Transfer from this address */ + msg[0].length = 1; /* Send one byte following the address + * (no STOP) */ /* Set up the 8-bit STMPE811 data read message */ - msg[1].addr = priv->config->address; /* 7-bit address */ - msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ - msg[1].buffer = rxbuffer; /* Transfer to this address */ - msg[1].length = 2; /* Receive two bytes following the address - * (then STOP) */ + msg[1].frequency = priv->config->frequency; /* I2C frequency */ + msg[1].addr = priv->config->address; /* 7-bit address */ + msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ + msg[1].buffer = rxbuffer; /* Transfer to this address */ + msg[1].length = 2; /* Receive two bytes following the address + * (then STOP) */ /* Perform the transfer */ diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index 82f2d74103..e3ae851688 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -430,12 +430,13 @@ static int tsc2007_activate(FAR struct tsc2007_dev_s *priv, uint8_t cmd) * activation command (ACKed). */ - data = TSC2007_SETUP; + data = TSC2007_SETUP; - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = &data; /* Transfer from this address */ - msg.length = 1; /* Send one byte following the address */ + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = &data; /* Transfer from this address */ + msg.length = 1; /* Send one byte following the address */ /* Ignore errors from the setup command (because it is not ACKed) */ @@ -443,12 +444,13 @@ static int tsc2007_activate(FAR struct tsc2007_dev_s *priv, uint8_t cmd) /* Now activate the A/D converter */ - data = cmd; + data = cmd; - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = &data; /* Transfer from this address */ - msg.length = 1; /* Send one byte following the address */ + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = &data; /* Transfer from this address */ + msg.length = 1; /* Send one byte following the address */ ret = I2C_TRANSFER(priv->i2c, &msg, 1); if (ret < 0) @@ -483,10 +485,11 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd) * STOP condition... */ - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = &cmd; /* Transfer from this address */ - msg.length = 1; /* Send one byte following the address */ + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = &cmd; /* Transfer from this address */ + msg.length = 1; /* Send one byte following the address */ ret = I2C_TRANSFER(priv->i2c, &msg, 1); if (ret < 0) @@ -527,10 +530,11 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd) * data byte has been received... */ - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = I2C_M_READ; /* Read transaction, beginning with START */ - msg.buffer = data12; /* Transfer to this address */ - msg.length = 2; /* Read two bytes following the address */ + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = I2C_M_READ; /* Read transaction, beginning with START */ + msg.buffer = data12; /* Transfer to this address */ + msg.length = 2; /* Read two bytes following the address */ ret = I2C_TRANSFER(priv->i2c, &msg, 1); if (ret < 0) @@ -1068,7 +1072,8 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(priv->config != NULL && ptr != NULL); - priv->config->frequency = I2C_SETFREQUENCY(priv->i2c, *ptr); + priv->config->frequency = *ptr; + (void)I2C_SETFREQUENCY(priv->i2c, *ptr); } break; diff --git a/drivers/lcd/ssd1306_i2c.c b/drivers/lcd/ssd1306_i2c.c index ffc72b075e..1a5edaa6d1 100644 --- a/drivers/lcd/ssd1306_i2c.c +++ b/drivers/lcd/ssd1306_i2c.c @@ -82,11 +82,12 @@ void ssd1306_sendbyte(FAR struct ssd1306_dev_s *priv, uint8_t regval) /* Setup 8-bit SSD1306 address write message */ - msg.addr = priv->addr; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = txbuffer; /* Transfer from this address */ - msg.length = 1; /* Send one byte following the address - * (then STOP) */ + msg.frequency = CONFIG_SSD1306_I2CFREQ; /* I2C frequency */ + msg.addr = priv->addr; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = txbuffer; /* Transfer from this address */ + msg.length = 1; /* Send one byte following the address + * (then STOP) */ /* Perform the transfer */ @@ -117,11 +118,12 @@ void ssd1306_sendblk(FAR struct ssd1306_dev_s *priv, uint8_t *data, uint8_t len) /* Setup 8-bit SSD1306 address write message */ - msg.addr = priv->addr; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = data; /* Transfer from this address */ - msg.length = len; /* Send one byte following the address - * (then STOP) */ + msg.frequency = CONFIG_SSD1306_I2CFREQ; /* I2C frequency */ + msg.addr = priv->addr; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = data; /* Transfer from this address */ + msg.length = len; /* Send one byte following the address + * (then STOP) */ /* Perform the transfer */ diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index 46f0e3b2c9..abbe171699 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -22,7 +22,12 @@ config LIS331DL bool "ST LIS331DL device support" default n select I2C - select I2C_TRANSFER + +config LIS331DL_I2C_FREQUENCY + bool "LIS331DL I2C frequency" + default 100000 + range 1 100000 + depends on LIS331DL config SN_LSM9DS1 bool "STMicro LSM9DS1 support" diff --git a/drivers/sensors/adxl345_i2c.c b/drivers/sensors/adxl345_i2c.c index b5ece68727..a2dfd81961 100644 --- a/drivers/sensors/adxl345_i2c.c +++ b/drivers/sensors/adxl345_i2c.c @@ -76,19 +76,21 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Setup 8-bit ADXL345 address write message */ - msg[0].addr = priv->config->address; /* 7-bit address */ - msg[0].flags = 0; /* Write transaction, beginning with START */ - msg[0].buffer = ®addr; /* Transfer from this address */ - msg[0].length = 1; /* Send one byte following the address - * (no STOP) */ + msg[0].frequency = priv->config->frequency; /* I2C frequency */ + msg[0].addr = priv->config->address; /* 7-bit address */ + msg[0].flags = 0; /* Write transaction, beginning with START */ + msg[0].buffer = ®addr; /* Transfer from this address */ + msg[0].length = 1; /* Send one byte following the address + * (no STOP) */ /* Set up the 8-bit ADXL345 data read message */ - msg[1].addr = priv->config->address; /* 7-bit address */ - msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ - msg[1].buffer = ®val; /* Transfer to this address */ - msg[1].length = 1; /* Receive one byte following the address - * (then STOP) */ + msg[1].frequency = priv->config->frequency; /* I2C frequency */ + msg[1].addr = priv->config->address; /* 7-bit address */ + msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ + msg[1].buffer = ®val; /* Transfer to this address */ + msg[1].length = 1; /* Receive one byte following the address + * (then STOP) */ /* Perform the transfer */ @@ -140,11 +142,12 @@ void adxl345_putreg8(FAR struct adxl345_dev_s *priv, /* Setup 8-bit ADXL345 address write message */ - msg.addr = priv->config->address; /* 7-bit address */ - msg.flags = 0; /* Write transaction, beginning with START */ - msg.buffer = txbuffer; /* Transfer from this address */ - msg.length = 2; /* Send two byte following the address - * (then STOP) */ + msg.frequency = priv->config->frequency; /* I2C frequency */ + msg.addr = priv->config->address; /* 7-bit address */ + msg.flags = 0; /* Write transaction, beginning with START */ + msg.buffer = txbuffer; /* Transfer from this address */ + msg.length = 2; /* Send two byte following the address + * (then STOP) */ /* Perform the transfer */ @@ -180,19 +183,21 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr) /* Setup 8-bit ADXL345 address write message */ - msg[0].addr = priv->config->address; /* 7-bit address */ - msg[0].flags = 0; /* Write transaction, beginning with START */ - msg[0].buffer = ®addr; /* Transfer from this address */ - msg[0].length = 1; /* Send one byte following the address - * (no STOP) */ + msg[0].frequency = priv->config->frequency; /* I2C frequency */ + msg[0].addr = priv->config->address; /* 7-bit address */ + msg[0].flags = 0; /* Write transaction, beginning with START */ + msg[0].buffer = ®addr; /* Transfer from this address */ + msg[0].length = 1; /* Send one byte following the address + * (no STOP) */ /* Set up the 8-bit ADXL345 data read message */ - msg[1].addr = priv->config->address; /* 7-bit address */ - msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ - msg[1].buffer = rxbuffer; /* Transfer to this address */ - msg[1].length = 2; /* Receive two bytes following the address - * (then STOP) */ + msg[1].frequency = priv->config->frequency; /* I2C frequency */ + msg[1].addr = priv->config->address; /* 7-bit address */ + msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ + msg[1].buffer = rxbuffer; /* Transfer to this address */ + msg[1].length = 2; /* Receive two bytes following the address + * (then STOP) */ /* Perform the transfer */ diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index de4887ef2d..c563d53080 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -54,6 +54,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + +#ifndef CONFIG_LIS331DL_I2C_FREQUENCY +# define CONFIG_LIS331DL_I2C_FREQUENCY +#endif + /* LIS331DL Internal Registers **********************************************/ #define ST_LIS331DL_WHOAMI 0x0F /* who am I register */ @@ -182,16 +187,18 @@ static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr, struct i2c_msg_s msgv[2] = { { - .addr = dev->address, - .flags = 0, - .buffer = &subaddr, - .length = 1 + .frequency = CONFIG_LIS331DL_I2C_FREQUENCY, + .addr = dev->address, + .flags = 0, + .buffer = &subaddr, + .length = 1 }, { - .addr = dev->address, - .flags = flags, - .buffer = buf, - .length = length + .frequency = CONFIG_LIS331DL_I2C_FREQUENCY, + .addr = dev->address, + .flags = flags, + .buffer = buf, + .length = length } }; diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index 10da98d4b3..11ed144cb4 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -54,6 +54,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Driver Definitions *******************************************************/ #define MAX_REFCLK_FREQ 75000000 @@ -133,15 +134,17 @@ static int cs2100_write_reg(FAR const struct cs2100_config_s *config, /* Construct the I2C message (write N+1 bytes with no restart) */ - msgs[0].addr = config->i2caddr; - msgs[0].flags = 0; - msgs[0].buffer = ®addr; - msgs[0].length = 1; + msga[0].frequency = config->i2cfreq; + msgs[0].addr = config->i2caddr; + msgs[0].flags = 0; + msgs[0].buffer = ®addr; + msgs[0].length = 1; - msgs[1].addr = config->i2caddr; - msgs[1].flags = I2C_M_NORESTART; - msgs[1].buffer = ®val; - msgs[1].length = 1; + msga[1].frequency = config->i2cfreq; + msgs[1].addr = config->i2caddr; + msgs[1].flags = I2C_M_NORESTART; + msgs[1].buffer = ®val; + msgs[1].length = 1; /* Send the message */ @@ -175,20 +178,22 @@ static int cs2100_read_reg(FAR const struct cs2100_config_s *config, /* Construct the I2C message (write 1 bytes, restart, read N bytes) */ - msg.addr = config->i2caddr; - msg.flags = 0; - msg.buffer = ®addr; - msg.length = 1; + msg.frequency = config->i2cfreq; + msg.addr = config->i2caddr; + msg.flags = 0; + msg.buffer = ®addr; + msg.length = 1; /* Send the address followed by a STOP */ ret = I2C_TRANSFER(config->i2c, &msg, 1); if (ret == OK) { - msg.addr = config->i2caddr; - msg.flags = I2C_M_READ; - msg.buffer = regval; - msg.length = 1; + msg.frequency = config->i2cfreq; + msg.addr = config->i2caddr; + msg.flags = I2C_M_READ; + msg.buffer = regval; + msg.length = 1; /* Read the register beginning with another START */ @@ -229,16 +234,17 @@ static int cs2100_write_ratio(FAR const struct cs2100_config_s *config, /* Construct the I2C message (write N+1 bytes with no restart) */ - buffer[0] = CS2100_RATIO0; - buffer[1] = (uint8_t)(ratio >> 24); - buffer[2] = (uint8_t)((ratio >> 16) & 0xff); - buffer[3] = (uint8_t)((ratio >> 8) & 0xff); - buffer[4] = (uint8_t)(ratio & 0xff); + buffer[0] = CS2100_RATIO0; + buffer[1] = (uint8_t)(ratio >> 24); + buffer[2] = (uint8_t)((ratio >> 16) & 0xff); + buffer[3] = (uint8_t)((ratio >> 8) & 0xff); + buffer[4] = (uint8_t)(ratio & 0xff); - msg.addr = config->i2caddr; - msg.flags = 0; - msg.buffer = buffer; - msg.length = 5; + msg.frequency = config->i2cfreq; + msg.addr = config->i2caddr; + msg.flags = 0; + msg.buffer = buffer; + msg.length = 5; /* Send the message */ @@ -272,22 +278,24 @@ static int cs2100_read_ratio(FAR const struct cs2100_config_s *config, /* Construct the I2C message (write N+1 bytes with no restart) */ - buffer[0] = CS2100_RATIO0; + buffer[0] = CS2100_RATIO0; - msg.addr = config->i2caddr; - msg.flags = 0; - msg.buffer = buffer; - msg.length = 1; + msg.frequency = config->i2cfreq; + msg.addr = config->i2caddr; + msg.flags = 0; + msg.buffer = buffer; + msg.length = 1; /* Send the address followed by a STOP */ ret = I2C_TRANSFER(config->i2c, &msg, 1); if (ret == OK) { - msg.addr = config->i2caddr; - msg.flags = I2C_M_READ; - msg.buffer = buffer; - msg.length = 4; + msg.frequency = config->i2cfreq; + msg.addr = config->i2caddr; + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = 4; /* Read the ratio registers beginning with another START */ diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 19c3a3e237..60292c4fed 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -298,33 +298,37 @@ int up_rtc_getdatetime(FAR struct tm *tp) /* Select to begin reading at the seconds register */ - secaddr = DSXXXX_TIME_SECR; + secaddr = DSXXXX_TIME_SECR; - msg[0].addr = DS3231_I2C_ADDRESS; - msg[0].flags = 0; - msg[0].buffer = &secaddr; - msg[0].length = 1; + msg[0].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[0].addr = DS3231_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = &secaddr; + msg[0].length = 1; /* Set up to read 7 registers: secondss, minutes, hour, day-of-week, date, * month, year */ - msg[1].addr = DS3231_I2C_ADDRESS; - msg[1].flags = I2C_M_READ; - msg[1].buffer = buffer; - msg[1].length = 7; + msg[1].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[1].addr = DS3231_I2C_ADDRESS; + msg[1].flags = I2C_M_READ; + msg[1].buffer = buffer; + msg[1].length = 7; /* Read the seconds register again */ - msg[2].addr = DS3231_I2C_ADDRESS; - msg[2].flags = 0; - msg[2].buffer = &secaddr; - msg[2].length = 1; + msg[2].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[2].addr = DS3231_I2C_ADDRESS; + msg[2].flags = 0; + msg[2].buffer = &secaddr; + msg[2].length = 1; - msg[3].addr = DS3231_I2C_ADDRESS; - msg[3].flags = I2C_M_READ; - msg[3].buffer = &seconds; - msg[3].length = 1; + msg[3].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[3].addr = DS3231_I2C_ADDRESS; + msg[3].flags = I2C_M_READ; + msg[3].buffer = &seconds; + msg[3].length = 1; /* Configure I2C before using it */ @@ -525,22 +529,25 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Setup the I2C message */ - msg[0].addr = DS3231_I2C_ADDRESS; - msg[0].flags = 0; - msg[0].buffer = buffer; - msg[0].length = 8; + msg[0].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[0].addr = DS3231_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = buffer; + msg[0].length = 8; /* Read back the seconds register */ - msg[1].addr = DS3231_I2C_ADDRESS; - msg[1].flags = 0; - msg[1].buffer = buffer; - msg[1].length = 1; - - msg[2].addr = DS3231_I2C_ADDRESS; - msg[2].flags = I2C_M_READ; - msg[2].buffer = &seconds; - msg[2].length = 1; + msg[1].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[1].addr = DS3231_I2C_ADDRESS; + msg[1].flags = 0; + msg[1].buffer = buffer; + msg[1].length = 1; + + msg[2].frequency = CONFIG_DS3231_I2C_FREQUENCY; + msg[2].addr = DS3231_I2C_ADDRESS; + msg[2].flags = I2C_M_READ; + msg[2].buffer = &seconds; + msg[2].length = 1; /* Configure I2C before using it */ diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index eaf8b6d10f..c8b85f1162 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -297,33 +297,37 @@ int up_rtc_getdatetime(FAR struct tm *tp) /* Select to begin reading at the seconds register */ - secaddr = PCF85263_RTC_SECONDS; + secaddr = PCF85263_RTC_SECONDS; - msg[0].addr = PCF85263_I2C_ADDRESS; - msg[0].flags = 0; - msg[0].buffer = &secaddr; - msg[0].length = 1; + msg[0].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[0].addr = PCF85263_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = &secaddr; + msg[0].length = 1; /* Set up to read 7 registers: secondss, minutes, hour, day-of-week, date, * month, year */ - msg[1].addr = PCF85263_I2C_ADDRESS; - msg[1].flags = I2C_M_READ; - msg[1].buffer = buffer; - msg[1].length = 7; + msg[1].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[1].addr = PCF85263_I2C_ADDRESS; + msg[1].flags = I2C_M_READ; + msg[1].buffer = buffer; + msg[1].length = 7; /* Read the seconds register again */ - msg[2].addr = PCF85263_I2C_ADDRESS; - msg[2].flags = 0; - msg[2].buffer = &secaddr; - msg[2].length = 1; + msg[2].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[2].addr = PCF85263_I2C_ADDRESS; + msg[2].flags = 0; + msg[2].buffer = &secaddr; + msg[2].length = 1; - msg[3].addr = PCF85263_I2C_ADDRESS; - msg[3].flags = I2C_M_READ; - msg[3].buffer = &seconds; - msg[3].length = 1; + msg[3].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[3].addr = PCF85263_I2C_ADDRESS; + msg[3].flags = I2C_M_READ; + msg[3].buffer = &seconds; + msg[3].length = 1; /* Configure I2C before using it */ @@ -487,24 +491,27 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Setup the I2C message */ - msg[0].addr = PCF85263_I2C_ADDRESS; - msg[0].flags = 0; - msg[0].buffer = buffer; - msg[0].length = 9; + msg[0].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[0].addr = PCF85263_I2C_ADDRESS; + msg[0].flags = 0; + msg[0].buffer = buffer; + msg[0].length = 9; /* Read back the seconds register */ - cmd = PCF85263_RTC_SECONDS; + cmd = PCF85263_RTC_SECONDS; - msg[1].addr = PCF85263_I2C_ADDRESS; - msg[1].flags = 0; - msg[1].buffer = &cmd; - msg[1].length = 1; + msg[1].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[1].addr = PCF85263_I2C_ADDRESS; + msg[1].flags = 0; + msg[1].buffer = &cmd; + msg[1].length = 1; - msg[2].addr = PCF85263_I2C_ADDRESS; - msg[2].flags = I2C_M_READ; - msg[2].buffer = &seconds; - msg[2].length = 1; + msg[2].frequency = CONFIG_PCF85263_I2C_FREQUENCY; + msg[2].addr = PCF85263_I2C_ADDRESS; + msg[2].flags = I2C_M_READ; + msg[2].buffer = &seconds; + msg[2].length = 1; /* Configure I2C before using it */ diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index dee94a5e7a..4040efa24e 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -155,10 +155,11 @@ struct i2c_config_s struct i2c_msg_s { + uint32_t frequency; /* I2C frequency */ uint16_t addr; /* Slave address (7- or 10-bit) */ uint16_t flags; /* See I2C_M_* definitions */ uint8_t *buffer; /* Buffer to be transferred */ - ssize_t length; /* Length of the buffer in byetes */ + ssize_t length; /* Length of the buffer in bytes */ }; /* I2C private data. This structure only defines the initial fields of the diff --git a/include/nuttx/timers/cs2100-cp.h b/include/nuttx/timers/cs2100-cp.h index 5d62149134..fe72836770 100644 --- a/include/nuttx/timers/cs2100-cp.h +++ b/include/nuttx/timers/cs2100-cp.h @@ -160,6 +160,7 @@ struct cs2100_config_s { FAR struct i2c_master_s *i2c; /* Instance of an I2C interface */ + uint32_t i2cfreq; /* I2C frequency */ uint32_t refclk; /* RefClk/XTAL frequency */ uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */ uint32_t clkout; /* Desired CLK_OUT frequency */ -- GitLab From 69ce24c70ca303713d54d86da172f2a2f8b07bee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 16:31:13 -0600 Subject: [PATCH 665/858] I2C: Remove the setfrequency method from the interface --- Documentation | 2 +- arch | 2 +- drivers/audio/wm8904.c | 5 ----- drivers/i2c/i2c_read.c | 1 - drivers/i2c/i2c_write.c | 1 - drivers/i2c/i2c_writeread.c | 1 - drivers/input/mxt.c | 2 -- drivers/input/stmpe811_base.c | 7 ------- drivers/input/stmpe811_tsc.c | 2 +- drivers/input/tsc2007.c | 5 ----- drivers/ioexpander/pca9555.c | 7 ------- drivers/lcd/ssd1306_base.c | 7 ------- drivers/leds/pca9635pw.c | 4 ---- drivers/mtd/at24xx.c | 4 ---- drivers/power/bq2425x.c | 4 ---- drivers/power/max1704x.c | 4 ---- drivers/sensors/adxl345_base.c | 7 ------- drivers/sensors/bmp180.c | 4 ---- drivers/timers/ds3231.c | 8 -------- drivers/timers/pcf85263.c | 8 -------- drivers/video/ov2640.c | 4 ---- include/nuttx/i2c/i2c_master.h | 23 ++--------------------- 22 files changed, 5 insertions(+), 107 deletions(-) diff --git a/Documentation b/Documentation index 7d40326c7f..527fb2f925 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 7d40326c7f8ca77993caaa7bb940e3ae2a631f9d +Subproject commit 527fb2f92536a8dad7dee60da49281049dc545bb diff --git a/arch b/arch index 18c2083af2..867f8d6f49 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 18c2083af2a73f710e2777c42ccd7ca8ae4096bf +Subproject commit 867f8d6f49f9bec687e98bfb2bedba81e017e90a diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index cfc04a3ddc..6f1694fbe6 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -2501,11 +2501,6 @@ FAR struct audio_lowerhalf_s * dq_init(&priv->pendq); dq_init(&priv->doneq); - /* Initialize I2C */ - - auddbg("address=%02x frequency=%d\n", lower->address, lower->frequency); - I2C_SETFREQUENCY(i2c, lower->frequency); - /* Software reset. This puts all WM8904 registers back in their * default state. */ diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 72134c2c50..54291dc1aa 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -87,7 +87,6 @@ int i2c_read(FAR struct i2c_master_s *dev, /* Then perform the transfer. */ - I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, &msg, 1); } diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index 11eb25cc7d..f72bc97a33 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -82,7 +82,6 @@ int i2c_write(FAR struct i2c_master_s *dev, /* Then perform the transfer. */ - I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, &msg, 1); } diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index 265f272d1d..1b5c2060c5 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -109,7 +109,6 @@ int i2c_writeread(FAR struct i2c_master_s *dev, /* Then perform the transfer. */ - I2C_SETFREQUENCY(dev, config->frequency); return I2C_TRANSFER(dev, msg, 2); } diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index 768ebe095b..d7444a5522 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -1517,7 +1517,6 @@ static int mxt_ioctl(FAR struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(priv->lower != NULL && ptr != NULL); priv->frequency = *ptr; - (void)I2C_SETFREQUENCY(priv->i2c, *ptr); } break; @@ -1741,7 +1740,6 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv) /* Set the selected I2C frequency */ priv->frequency = priv->lower->frequency; - (void)I2C_SETFREQUENCY(priv->i2c, priv->lower->frequency); /* Read the info registers from the device */ diff --git a/drivers/input/stmpe811_base.c b/drivers/input/stmpe811_base.c index c115d985fe..224b9eaefc 100644 --- a/drivers/input/stmpe811_base.c +++ b/drivers/input/stmpe811_base.c @@ -324,13 +324,6 @@ STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev, priv->spi = dev; #else priv->i2c = dev; - - /* Set the I2C address and frequency. REVISIT: This logic would be - * insufficient if we share the I2C bus with any other devices that also - * modify the address and frequency. - */ - - I2C_SETFREQUENCY(dev, config->frequency); #endif /* Read and verify the STMPE811 chip ID */ diff --git a/drivers/input/stmpe811_tsc.c b/drivers/input/stmpe811_tsc.c index fa701e0710..55dce44272 100644 --- a/drivers/input/stmpe811_tsc.c +++ b/drivers/input/stmpe811_tsc.c @@ -615,7 +615,7 @@ static int stmpe811_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(priv->config != NULL && ptr != NULL); - priv->config->frequency = I2C_SETFREQUENCY(priv->i2c, *ptr); + priv->config->frequency = *ptr; } break; diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index e3ae851688..0c1991b351 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -1073,7 +1073,6 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg) FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(priv->config != NULL && ptr != NULL); priv->config->frequency = *ptr; - (void)I2C_SETFREQUENCY(priv->i2c, *ptr); } break; @@ -1255,10 +1254,6 @@ int tsc2007_register(FAR struct i2c_master_s *dev, sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */ sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */ - /* Set the I2C frequency (saving the actual frequency) */ - - config->frequency = I2C_SETFREQUENCY(dev, config->frequency); - /* Make sure that interrupts are disabled */ config->clear(config); diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 0348ca7ade..2d9f213304 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -618,13 +618,6 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *i2cdev, pcadev->dev.ops = &g_pca9555_ops; pcadev->config = config; - /* Set the I2C frequency. REVISIT: This logic would be - * insufficient if we share the I2C bus with any other devices that also - * modify the address and frequency. - */ - - I2C_SETFREQUENCY(i2cdev, config->frequency); - #ifdef CONFIG_PCA9555_INT_ENABLE pcadev->config->attach(pcadev->config, pca9555_interrupt); pcadev->config->enable(pcadev->config, TRUE); diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c index 8bb511ee83..db94d9ea83 100644 --- a/drivers/lcd/ssd1306_base.c +++ b/drivers/lcd/ssd1306_base.c @@ -827,13 +827,6 @@ FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_master_s *dev, unsigned priv->i2c = dev; priv->addr = CONFIG_SSD1306_I2CADDR; - - /* Set the I2C frequency. REVISIT: This logic would be - * insufficient if we share the I2C bus with any other devices that also - * modify the address and frequency. - */ - - I2C_SETFREQUENCY(priv->i2c, CONFIG_SSD1306_I2CFREQ); #endif /* Lock and select device */ diff --git a/drivers/leds/pca9635pw.c b/drivers/leds/pca9635pw.c index b4a8419061..452891555a 100644 --- a/drivers/leds/pca9635pw.c +++ b/drivers/leds/pca9635pw.c @@ -381,10 +381,6 @@ int pca9635pw_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, return ret; } - /* setup i2c frequency */ - - I2C_SETFREQUENCY(priv->i2c, I2C_BUS_FREQ_HZ); - return OK; } diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index aa235c346a..85299baada 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -246,7 +246,6 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv) int startblock = 0; memset(&buf[AT24XX_ADDRSIZE], 0xff, priv->pagesize); - I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); for (startblock = 0; startblock < priv->npages; startblock++) { @@ -298,8 +297,6 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset, fvdbg("offset: %lu nbytes: %lu address: %02x\n", (unsigned long)offset, (unsigned long)nbytes, address); - I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); - /* "Random Read: A Random Read requires a dummy byte write sequence to load in the * data word address. Once the device address word and data word address are clocked * in and acknowledged by the EEPROM, the microcontroller must generate another @@ -422,7 +419,6 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t } fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); - I2C_SETFREQUENCY(priv->dev, CONFIG_AT24XX_FREQUENCY); while (blocksleft-- > 0) { diff --git a/drivers/power/bq2425x.c b/drivers/power/bq2425x.c index 3927ce27d4..073c3ce379 100644 --- a/drivers/power/bq2425x.c +++ b/drivers/power/bq2425x.c @@ -744,10 +744,6 @@ FAR struct battery_charger_dev_s * priv->addr = addr; priv->frequency = frequency; - /* Set the I2C frequency (ignoring the returned, actual frequency) */ - - (void)I2C_SETFREQUENCY(i2c, priv->frequency); - /* Reset the BQ2425x */ ret = bq2425x_reset(priv); diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 8228413409..7fa3f85060 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -548,10 +548,6 @@ FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_master_s *i2c priv->addr = addr; priv->frequency = frequency; - /* Set the I2C frequency (ignoring the returned, actual frequency) */ - - (void)I2C_SETFREQUENCY(i2c, priv->frequency); - /* Reset the MAX1704x (mostly just to make sure that we can talk to it) */ #if 0 diff --git a/drivers/sensors/adxl345_base.c b/drivers/sensors/adxl345_base.c index d2c9362314..4cf667807d 100644 --- a/drivers/sensors/adxl345_base.c +++ b/drivers/sensors/adxl345_base.c @@ -411,13 +411,6 @@ ADXL345_HANDLE adxl345_instantiate(FAR struct i2c_master_s *dev, #else priv->i2c = dev; - - /* Set the I2C address and frequency. REVISIT: This logic would be - * insufficient if we share the I2C bus with any other devices that also - * modify the address and frequency. - */ - - I2C_SETFREQUENCY(dev, config->frequency); #endif /* Read and verify the ADXL345 device ID */ diff --git a/drivers/sensors/bmp180.c b/drivers/sensors/bmp180.c index 3279647ef9..2124066fe9 100644 --- a/drivers/sensors/bmp180.c +++ b/drivers/sensors/bmp180.c @@ -610,10 +610,6 @@ int bmp180_register(FAR const char *devpath, FAR struct i2c_master_s *i2c) priv->addr = BMP180_ADDR; priv->freq = BMP180_FREQ; - /* Configure I2C before using it */ - - I2C_SETFREQUENCY(priv->i2c, priv->freq); - /* Check Device ID */ ret = bmp180_checkid(priv); diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 60292c4fed..7efaaecb03 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -330,10 +330,6 @@ int up_rtc_getdatetime(FAR struct tm *tp) msg[3].buffer = &seconds; msg[3].length = 1; - /* Configure I2C before using it */ - - I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer. The transfer may be performed repeatedly of the * seconds values decreases, meaning that that was a rollover in the seconds. */ @@ -549,10 +545,6 @@ int up_rtc_settime(FAR const struct timespec *tp) msg[2].buffer = &seconds; msg[2].length = 1; - /* Configure I2C before using it */ - - I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY); - /* Perform the transfer. This transfer will be repeated if the seconds * count rolls over to a smaller value while writing. */ diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index c8b85f1162..0128e354f2 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -329,10 +329,6 @@ int up_rtc_getdatetime(FAR struct tm *tp) msg[3].buffer = &seconds; msg[3].length = 1; - /* Configure I2C before using it */ - - I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); - /* Perform the transfer. The transfer may be performed repeatedly of the * seconds values decreases, meaning that that was a rollover in the seconds. */ @@ -513,10 +509,6 @@ int up_rtc_settime(FAR const struct timespec *tp) msg[2].buffer = &seconds; msg[2].length = 1; - /* Configure I2C before using it */ - - I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY); - /* Perform the transfer. This transfer will be repeated if the seconds * count rolls over to a smaller value while writing. */ diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 19812e3224..ebf37f002c 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -922,10 +922,6 @@ int ov2640_initialize(FAR struct i2c_master_s *i2c) { int ret; - /* Configure I2C bus for the OV2640 */ - - I2C_SETFREQUENCY(i2c, CONFIG_OV2640_FREQUENCY); - /* Reset the OVR2640 */ ret = ov2640_reset(i2c); diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 4040efa24e..2b9271dced 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -80,24 +80,6 @@ /* Access macros ************************************************************/ -/**************************************************************************** - * Name: I2C_SETFREQUENCY - * - * Description: - * Set the I2C frequency. This frequency will be retained in the struct - * i2c_master_s instance and will be used with all transfers. Required. - * - * Input Parameters: - * dev - Device-specific state data - * frequency - The I2C frequency requested - * - * Returned Value: - * Returns the actual frequency selected - * - ****************************************************************************/ - -#define I2C_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) - /**************************************************************************** * Name: I2C_TRANSFER * @@ -131,9 +113,8 @@ struct i2c_master_s; struct i2c_msg_s; struct i2c_ops_s { - uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency); - int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, - int count); + int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, + int count); }; /* This structure contains the full state of I2C as needed for a specific -- GitLab From 2ec738d7ed829cffc48b15f11f94fada39f1483a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 16:34:18 -0600 Subject: [PATCH 666/858] Update TODO --- TODO | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/TODO b/TODO index 57f3b74f8b..b2ad032089 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 13, 2016) +NuttX TODO List (Last updated February 1, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -19,7 +19,7 @@ nuttx/ (6) Binary loaders (binfmt/) (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) - (1) Other drivers (drivers/) + (0) Other drivers (drivers/) (11) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) (8) Graphics subsystem (graphics/) @@ -1608,21 +1608,6 @@ o Build system o Other drivers (drivers/) ^^^^^^^^^^^^^^^^^^^^^^^^ - Title: I2C NOT THREAD SAFE - Description: Unlike the SPI interface, the I2C interface has no method to lock - the interface. This is a problem for all non-atomic I2C operations - in a multi-tasking I2C environment: - - I2C_SETFREQUENCY: Frequency setting can be overwritten by other - I2C usage. - - I2C_TRANSFER: This interface is almost self but even can suffer - if there are differing frequency settings. - Status: Open - Priority: Medium-High. The fix is easy but effects a lot of software. There - are two ways to fix theses problems: (1) Add a locking method such - as is provided with the SPI interface, or (2) make each interface - self-contained and atomic: Remove the I2C_FREQUENCY and add - frequency to the I2C_TRANSFER message structure. - o Linux/Cywgin simulation (arch/sim) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- GitLab From 4cfbe50c0d27211c28750900f3592523cda3be5d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 18:02:56 -0600 Subject: [PATCH 667/858] I2C: Fix some compile time issues found with tools/testbuild.sh --- arch | 2 +- drivers/sensors/lis331dl.c | 49 ++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/arch b/arch index 867f8d6f49..af40d03532 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 867f8d6f49f9bec687e98bfb2bedba81e017e90a +Subproject commit af40d03532135c9010c508336828cd09c3c9b273 diff --git a/drivers/sensors/lis331dl.c b/drivers/sensors/lis331dl.c index c563d53080..f94a3b2ec2 100644 --- a/drivers/sensors/lis331dl.c +++ b/drivers/sensors/lis331dl.c @@ -56,7 +56,7 @@ ****************************************************************************/ #ifndef CONFIG_LIS331DL_I2C_FREQUENCY -# define CONFIG_LIS331DL_I2C_FREQUENCY +# define CONFIG_LIS331DL_I2C_FREQUENCY 100000 #endif /* LIS331DL Internal Registers **********************************************/ @@ -111,7 +111,10 @@ struct lis331dl_dev_s ****************************************************************************/ /**************************************************************************** - * LIS331DL Access with range check + * Name: lis331dl_access + * + * Description: + * LIS331DL Access with range check * * Input Parameters: * dev LIS331 DL Private Structure @@ -128,16 +131,16 @@ struct lis331dl_dev_s static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr, FAR uint8_t *buf, int length) { - uint16_t flags = 0; + uint16_t flags; int retval; if (length > 0) { - flags = I2C_M_READ; + flags = I2C_M_READ; } else { - flags = I2C_M_NORESTART; + flags = I2C_M_NORESTART; length = -length; } @@ -210,6 +213,10 @@ static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr, return retval; } +/**************************************************************************** + * Name: lis331dl_readregs + ****************************************************************************/ + static int lis331dl_readregs(FAR struct lis331dl_dev_s *dev) { if (lis331dl_access(dev, ST_LIS331DL_CTRL_REG1, &dev->cr1, 3) != 3) @@ -224,6 +231,10 @@ static int lis331dl_readregs(FAR struct lis331dl_dev_s *dev) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: lis331dl_init + ****************************************************************************/ + FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c, uint16_t address) { @@ -285,6 +296,10 @@ FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c, return NULL; } +/**************************************************************************** + * Name: lis331dl_deinit + ****************************************************************************/ + int lis331dl_deinit(FAR struct lis331dl_dev_s * dev) { ASSERT(dev); @@ -295,6 +310,10 @@ int lis331dl_deinit(FAR struct lis331dl_dev_s * dev) return OK; } +/**************************************************************************** + * Name: lis331dl_powerup + ****************************************************************************/ + int lis331dl_powerup(FAR struct lis331dl_dev_s * dev) { dev->cr1 = ST_LIS331DL_CR1_PD | @@ -310,6 +329,10 @@ int lis331dl_powerup(FAR struct lis331dl_dev_s * dev) return ERROR; } +/**************************************************************************** + * Name: lis331dl_powerdown + ****************************************************************************/ + int lis331dl_powerdown(FAR struct lis331dl_dev_s * dev) { dev->cr1 = ST_LIS331DL_CR1_ZEN | ST_LIS331DL_CR1_YEN | ST_LIS331DL_CR1_XEN; @@ -324,6 +347,10 @@ int lis331dl_powerdown(FAR struct lis331dl_dev_s * dev) return ERROR; } +/**************************************************************************** + * Name: lis331dl_setconversion + ****************************************************************************/ + int lis331dl_setconversion(FAR struct lis331dl_dev_s * dev, bool full, bool fast) { dev->cr1 = ST_LIS331DL_CR1_PD | @@ -338,6 +365,10 @@ int lis331dl_setconversion(FAR struct lis331dl_dev_s * dev, bool full, bool fast return ERROR; } +/**************************************************************************** + * Name: lis331dl_getprecision + ****************************************************************************/ + int lis331dl_getprecision(FAR struct lis331dl_dev_s * dev) { if (dev->cr1 & ST_LIS331DL_CR1_FS) @@ -348,6 +379,10 @@ int lis331dl_getprecision(FAR struct lis331dl_dev_s * dev) return 2300/127; /* typ. 2.3g full scale */ } +/**************************************************************************** + * Name: lis331dl_getsamplerate + ****************************************************************************/ + int lis331dl_getsamplerate(FAR struct lis331dl_dev_s * dev) { if (dev->cr1 & ST_LIS331DL_CR1_DR) @@ -358,6 +393,10 @@ int lis331dl_getsamplerate(FAR struct lis331dl_dev_s * dev) return 100; } +/**************************************************************************** + * Name: lis331dl_getreadings + ****************************************************************************/ + FAR const struct lis331dl_vector_s * lis331dl_getreadings(FAR struct lis331dl_dev_s * dev) { -- GitLab From 456b5f06dcf42a0bf63c77d8e590ecc7f3a5586c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Feb 2016 19:52:16 -0600 Subject: [PATCH 668/858] Clean up some comments --- arch | 2 +- drivers/i2c/i2c_read.c | 7 +++---- drivers/i2c/i2c_write.c | 2 +- drivers/i2c/i2c_writeread.c | 4 ++-- include/nuttx/i2c/i2c_master.h | 26 +++++++++++++------------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/arch b/arch index af40d03532..cb55e30476 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit af40d03532135c9010c508336828cd09c3c9b273 +Subproject commit cb55e3047693dca56aaf2aaa2e932f6b83d148c5 diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 54291dc1aa..83b0e681b2 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -51,10 +51,9 @@ * Name: i2c_read * * Description: - * Receive a block of data from I2C using the previously selected I2C - * frequency and slave address. Each read operational will be an 'atomic' - * operation in the sense that any other I2C actions will be serialized - * and pend until this read completes. Required. + * Receive a block of data from I2C. Each read operation will be an + * 'atomic' operation in the sense that any other I2C actions will be + * serialized and pend until this read completes. * * Input Parameters: * dev - Device-specific state data diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index f72bc97a33..0638486d65 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -51,7 +51,7 @@ * Name: i2c_write * * Description: - * Send a block of data on I2C. Each write operational will be an 'atomic' + * Send a block of data on I2C. Each write operation will be an 'atomic' * operation in the sense that any other I2C actions will be serialized * and pend until this write completes. * diff --git a/drivers/i2c/i2c_writeread.c b/drivers/i2c/i2c_writeread.c index 1b5c2060c5..d5a09fd9e0 100644 --- a/drivers/i2c/i2c_writeread.c +++ b/drivers/i2c/i2c_writeread.c @@ -51,8 +51,8 @@ * Name: i2c_writeread * * Description: - * Send a block of data on I2C using the previously, followed by restarted - * read access. This provides a convenient wrapper to the transfer function. + * Send a block of data on I2C followed by restarted read access. This + * provides a convenient wrapper to the transfer function. * * Input Parameters: * dev - Device-specific state data diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 2b9271dced..657703099f 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -90,9 +90,7 @@ * will be serialized and pend until this sequence of transfers completes. * * Input Parameters: - * dev - - - Device-specific state data + * dev - Device-specific state data * msgs - A pointer to a set of message descriptors * count - The number of transfers to perform * @@ -218,8 +216,8 @@ int up_i2creset(FAR struct i2c_master_s *dev); * Name: i2c_writeread * * Description: - * Send a block of data on I2C using the previously, followed by restarted - * read access. This provides a convenient wrapper to the transfer function. + * Send a block of data on I2C followed by restarted read access. This + * provides a convenient wrapper to the transfer function. * * Input Parameters: * dev - Device-specific state data @@ -234,7 +232,8 @@ int up_i2creset(FAR struct i2c_master_s *dev); * ****************************************************************************/ -int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, +int i2c_writeread(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR const uint8_t *wbuffer, int wbuflen, FAR uint8_t *rbuffer, int rbuflen); @@ -242,7 +241,7 @@ int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *c * Name: i2c_write * * Description: - * Send a block of data on I2C. Each write operational will be an 'atomic' + * Send a block of data on I2C. Each write operation will be an 'atomic' * operation in the sense that any other I2C actions will be serialized * and pend until this write completes. * @@ -257,17 +256,17 @@ int i2c_writeread(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *c * ****************************************************************************/ -int i2c_write(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, +int i2c_write(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR const uint8_t *buffer, int buflen); /**************************************************************************** * Name: i2c_read * * Description: - * Receive a block of data from I2C using the previously selected I2C - * frequency and slave address. Each read operational will be an 'atomic' - * operation in the sense that any other I2C actions will be serialized - * and pend until this read completes. Required. + * Receive a block of data from I2C. Each read operation will be an + * 'atomic' operation in the sense that any other I2C actions will be + * serialized and pend until this read completes. * * Input Parameters: * dev - Device-specific state data @@ -279,7 +278,8 @@ int i2c_write(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *confi * ****************************************************************************/ -int i2c_read(FAR struct i2c_master_s *dev, FAR const struct i2c_config_s *config, +int i2c_read(FAR struct i2c_master_s *dev, + FAR const struct i2c_config_s *config, FAR uint8_t *buffer, int buflen); #undef EXTERN -- GitLab From 4304405bba84f2b718469a09ce914284e506caf9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 06:07:51 -0600 Subject: [PATCH 669/858] I2C Slave: I don't think that the setfrequency method makes sense in a slave interface. --- include/nuttx/i2c/i2c_slave.h | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/include/nuttx/i2c/i2c_slave.h b/include/nuttx/i2c/i2c_slave.h index 7f43316497..048d88bca1 100644 --- a/include/nuttx/i2c/i2c_slave.h +++ b/include/nuttx/i2c/i2c_slave.h @@ -74,24 +74,6 @@ /* Access macros ************************************************************/ -/**************************************************************************** - * Name: I2CS_SETFREQUENCY - * - * Description: - * Set the I2C frequency. This frequency will be retained in the struct - * i2c_slave_s instance and will be used with all transfers. Required. - * - * Input Parameters: - * dev - Device-specific state data - * frequency - The I2C frequency requested - * - * Returned Value: - * Returns the actual frequency selected - * - ****************************************************************************/ - -#define I2CS_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) - /**************************************************************************** * Name: I2CS_SETOWNADDRESS * @@ -187,14 +169,13 @@ struct i2c_slave_s; struct i2c_slaveops_s { - uint32_t (*setfrequency)(FAR struct i2c_slave_s *dev, uint32_t frequency); - int (*setownaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); - int (*write)(FAR struct i2c_slave_s *dev, FAR const uint8_t *buffer, - int buflen); - int (*read)(FAR struct i2c_slave_s *dev, FAR uint8_t *buffer, - int buflen); - int (*registercallback)(FAR struct i2c_slave_s *dev, - int (*callback)(FAR void *arg), FAR void *arg); + int (*setownaddress)(FAR struct i2c_slave_s *dev, int addr, int nbits); + int (*write)(FAR struct i2c_slave_s *dev, FAR const uint8_t *buffer, + int buflen); + int (*read)(FAR struct i2c_slave_s *dev, FAR uint8_t *buffer, + int buflen); + int (*registercallback)(FAR struct i2c_slave_s *dev, + int (*callback)(FAR void *arg), FAR void *arg); }; /* I2C private data. This structure only defines the initial fields of the -- GitLab From 009e9f76cbf72d747e51fe12bb72d3c26c97c1cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 07:13:03 -0600 Subject: [PATCH 670/858] I2C: Fixes/improvements from last massive I2C commits --- arch | 2 +- drivers/i2c/i2c_read.c | 1 - drivers/i2c/i2c_write.c | 1 - drivers/ioexpander/pca9555.c | 18 +++++++++++------- drivers/mtd/at24xx.c | 32 ++++++++++++++++++++------------ drivers/sensors/Kconfig | 14 +++++++------- drivers/sensors/lm75.c | 32 ++++++++++++++++++++------------ drivers/sensors/lm92.c | 32 ++++++++++++++++++++------------ drivers/sensors/ms58xx.c | 32 ++++++++++++++++++++------------ 9 files changed, 99 insertions(+), 65 deletions(-) diff --git a/arch b/arch index cb55e30476..f80912e0ce 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cb55e3047693dca56aaf2aaa2e932f6b83d148c5 +Subproject commit f80912e0ceb3ff4c83eb86a3d128df81b2bc9a85 diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 83b0e681b2..b72523b4ee 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -88,4 +88,3 @@ int i2c_read(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } - diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index 0638486d65..30939806c3 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -84,4 +84,3 @@ int i2c_write(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } - diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 2d9f213304..bdfb9c6c79 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -136,17 +136,21 @@ static const struct ioexpander_ops_s g_pca9555_ops = ****************************************************************************/ static inline int pca9555_write(FAR struct pca9555_dev_s *pca, - FAR const uint8_t *wbuffer, int wbuflen) + FAR const uint8_t *, int wbuflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the configuration and perform the write-read operation */ + /* Setup for the transfer */ - config.frequency = pca->config->frequency; - config.address = pca->config->address; - config.addrlen = 7; + msg.frequency = pca->config->frequency; + msg.addr = pca->config->address; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)wbuffer; /* Override const */ + msg.length = wbuflen; + + /* Then perform the transfer. */ - return i2c_write(pca->i2c, &config, wbuffer, wbuflen); + return I2C_TRANSFER((pca->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 85299baada..fdecf95b80 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -203,15 +203,19 @@ static struct at24c_dev_s g_at24c; static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = at24addr; - config.addrlen = 7; + msg.frequency = CONFIG_AT24XX_FREQUENCY, + msg.addr = at24addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->dev, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->dev, &msg, 1); } /**************************************************************************** @@ -225,15 +229,19 @@ static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr, static int at24c_i2c_read(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; + + /* Setup for the transfer */ - /* Set up the I2C configuration */ + msg.frequency = CONFIG_AT24XX_FREQUENCY, + msg.addr = at24addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = at24addr; - config.addrlen = 7; + /* Then perform the transfer. */ - return i2c_read(priv->dev, &config, buffer, buflen); + return I2C_TRANSFER(priv->dev, &msg, 1); } /************************************************************************************ diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index abbe171699..c73e1abae0 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -24,7 +24,7 @@ config LIS331DL select I2C config LIS331DL_I2C_FREQUENCY - bool "LIS331DL I2C frequency" + int "LIS331DL I2C frequency" default 100000 range 1 100000 depends on LIS331DL @@ -37,7 +37,7 @@ config SN_LSM9DS1 Enable driver support for the STMicro LSM9DS1. config LSM9DS1_I2C_FREQUENCY - bool "LSM9DS1 I2C frequency" + int "LSM9DS1 I2C frequency" default 400000 range 1 400000 depends on SN_LSM9DS1 @@ -50,7 +50,7 @@ config MB7040 Enable driver support for the MaxBotix MB7040 sonar. config MB7040_I2C_FREQUENCY - bool "MB7040 I2C frequency" + int "MB7040 I2C frequency" default 400000 range 1 400000 depends on MB7040 @@ -63,7 +63,7 @@ config MCP9844 Enable driver support for the MCP9844 I2C Temperature sensor. config MCP9844_I2C_FREQUENCY - bool "MCP9844 I2C frequency" + int "MCP9844 I2C frequency" default 400000 range 1 400000 depends on MCP9844 @@ -76,7 +76,7 @@ config MS58XX Enable driver support for MEAS MS58XX altimeters. config MS58XX_I2C_FREQUENCY - bool "MS58XX I2C frequency" + int "MS58XX I2C frequency" default 400000 range 1 400000 depends on MS58XX @@ -164,7 +164,7 @@ config LM75 the TI TMP100/101. config LM75_I2C_FREQUENCY - bool "LM75 I2C frequency" + int "LM75 I2C frequency" default 100000 range 1 100000 depends on I2C_LM75 @@ -177,7 +177,7 @@ config LM92 Enable driver support for the TI LM92 Temperature Sensor. config LM92_I2C_FREQUENCY - bool "LM92 I2C frequency" + int "LM92 I2C frequency" default 400000 range 1 400000 depends on LM92 diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 4affac4554..f3fad73972 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -135,15 +135,19 @@ static const struct file_operations g_lm75fops = static int lm75_i2c_write(FAR struct lm75_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM75_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM75_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -157,15 +161,19 @@ static int lm75_i2c_write(FAR struct lm75_dev_s *priv, static int lm75_i2c_read(FAR struct lm75_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; + + /* Setup for the transfer */ - /* Set up the I2C configuration */ + msg.frequency = CONFIG_LM75_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - config.frequency = CONFIG_LM75_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + /* Then perform the transfer. */ - return i2c_read(priv->i2c, &config, buffer, buflen); + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 6d8bf190c0..73f4d54634 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -137,15 +137,19 @@ static const struct file_operations g_lm92fops = static int lm92_i2c_write(FAR struct lm92_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM92_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM92_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -159,15 +163,19 @@ static int lm92_i2c_write(FAR struct lm92_dev_s *priv, static int lm92_i2c_read(FAR struct lm92_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; + + /* Setup for the transfer */ - /* Set up the I2C configuration */ + msg.frequency = CONFIG_LM92_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - config.frequency = CONFIG_LM92_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + /* Then perform the transfer. */ - return i2c_read(priv->i2c, &config, buffer, buflen); + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 1d4bfdd68c..410a391a72 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -251,15 +251,19 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the configuration and perform the write-read operation */ + /* Setup for the transfer */ - config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_MS58XX_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -273,15 +277,19 @@ static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; + + /* Setup for the transfer */ - /* Set up the configuration and perform the write-read operation */ + msg.frequency = CONFIG_MS58XX_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + /* Then perform the transfer. */ - return i2c_read(priv->i2c, &config, buffer, buflen); + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** -- GitLab From 4a34a199ddabac39cb17d9af6b3795cc91e65614 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 08:30:54 -0600 Subject: [PATCH 671/858] I2C: Add an I2C character driver --- ChangeLog | 3 + drivers/i2c/Kconfig | 10 +- drivers/i2c/Make.defs | 4 + drivers/i2c/i2c_driver.c | 413 +++++++++++++++++++++++++++++++++ include/nuttx/fs/ioctl.h | 7 + include/nuttx/i2c/i2c_master.h | 48 ++++ 6 files changed, 482 insertions(+), 3 deletions(-) create mode 100644 drivers/i2c/i2c_driver.c diff --git a/ChangeLog b/ChangeLog index 78aa885aab..e770ca9318 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11435,3 +11435,6 @@ all I2C clients, and all low-level I2C drivers. I have used caution, but I still expect a change of this magnitude to introduce some errors. Any bug reports of bug fixes will be much appreciated (2016-02-01). + * drivers/i2c/i2c_driver.c: Add an I2C character drivers to support + raw I2C data transfers for test applications (2016-02-02). + diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 9f4e625dd7..c80954b37b 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -13,6 +13,11 @@ config I2C_POLLED bool "Polled I2C (no interrupts)" default n +config I2C_RESET + bool "Support up_i2creset" + default n + depends on ARCH_HAVE_I2CRESET + config I2C_TRACE bool "Enable I2C trace debug" default n @@ -22,9 +27,8 @@ config I2C_NTRACE default 32 depends on I2C_TRACE -config I2C_RESET - bool "Support up_i2creset" +config I2C_DRIVER + bool "I2C character driver" default n - depends on ARCH_HAVE_I2CRESET endif # I2C diff --git a/drivers/i2c/Make.defs b/drivers/i2c/Make.defs index 8036cbcb75..d7d708bdf2 100644 --- a/drivers/i2c/Make.defs +++ b/drivers/i2c/Make.defs @@ -39,6 +39,10 @@ ifeq ($(CONFIG_I2C),y) CSRCS += i2c_read.c i2c_write.c i2c_writeread.c +ifeq ($(CONFIG_I2C_DRIVER),y) +CSRCS += i2c_driver.c +endif + # Include I2C device driver build support DEPPATH += --dep-path i2c diff --git a/drivers/i2c/i2c_driver.c b/drivers/i2c/i2c_driver.c new file mode 100644 index 0000000000..05331dc866 --- /dev/null +++ b/drivers/i2c/i2c_driver.c @@ -0,0 +1,413 @@ +/**************************************************************************** + * drivers/i2c/i2c_driver.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef CONFIG_I2C_DRIVER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Device naming ************************************************************/ + +#define DEVNAME_FMT "/dev/i2c%d" +#define DEVNAME_FMTLEN (8 + 3 + 1) + +/* Debug ********************************************************************/ +/* CONFIG_DEBUG_I2C + CONFIG_DEBUG enables general I2C debug output. */ + +#ifdef CONFIG_DEBUG_I2C +# define i2cdbg dbg +# define i2cvdbg vdbg +#else +# define i2cdbg(x...) +# define i2cvdbg(x...) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* Driver state structure */ + +struct i2c_driver_s +{ + FAR struct i2c_master_s *i2c; /* Contained I2C lower half driver */ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + sem_t exclsem; /* Mutual exclusion */ + int16_t crefs; /* Number of open references */ + bool unlinked; /* True, driver has been unlinked */ +#endif +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int i2cdrvr_open(FAR struct file *filep); +static int i2cdrvr_close(FAR struct file *filep); +static ssize_t i2cdrvr_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t i2cdrvr_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); +static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int i2cdrvr_unlink(FAR struct inode *inode); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations i2cdrvr_fops = +{ +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + i2cdrvr_open, /* open */ + i2cdrvr_close, /* close */ +#else + 0, /* open */ + 0, /* close */ +#endif + i2cdrvr_read, /* read */ + i2cdrvr_write, /* write */ + 0, /* seek */ + i2cdrvr_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , i2cdrvr_unlink /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2cdrvr_open + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int i2cdrvr_open(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct i2c_driver_s *priv; + int ret; + + /* Get our private data structure */ + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + + priv = (FAR struct i2c_driver_s *)inode->i_private; + DEBUGASSERT(priv); + + /* Get exclusive access to the I2C driver state structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode < 0); + return -errcode; + } + + /* Increment the count of open references on the RTC driver */ + + priv->crefs++; + DEBUGASSERT(priv->crefs > 0); + + sem_post(&priv->exclsem); + return OK; +} +#endif + +/**************************************************************************** + * Name: i2cdrvr_close + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int i2cdrvr_close(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct i2c_driver_s *priv; + int ret; + + /* Get our private data structure */ + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + + priv = (FAR struct i2c_driver_s *)inode->i_private; + DEBUGASSERT(priv); + + /* Get exclusive access to the I2C driver state structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode < 0); + return -errcode; + } + + /* Decrement the count of open references on the RTC driver */ + + DEBUGASSERT(priv->crefs > 0); + priv->crefs--; + + /* If the count has decremented to zero and the driver has been unlinked, + * then commit Hara-Kiri now. + */ + + if (priv->crefs <= 0 && priv->unlinked) + { + sem_destroy(&priv->exclsem); + kmm_free(priv); + return OK; + } + + sem_post(&priv->exclsem); + return OK; +} +#endif + +/**************************************************************************** + * Name: i2cdrvr_read + ****************************************************************************/ + +static ssize_t i2cdrvr_read(FAR struct file *filep, FAR char *buffer, + size_t len) +{ + return 0; /* Return EOF */ +} + +/**************************************************************************** + * Name: i2cdrvr_write + ****************************************************************************/ + +static ssize_t i2cdrvr_write(FAR struct file *filep, FAR const char *buffer, + size_t len) +{ + return len; /* Say that everything was written */ +} + +/**************************************************************************** + * Name: i2cdrvr_ioctl + ****************************************************************************/ + +static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + i2cvdbg("cmd=%d arg=%lu\n", cmd, arg); + + /* Only one command is supported */ + + if (cmd == I2CIOC_TRANSFER) + { + FAR struct inode *inode = filep->f_inode; + FAR struct i2c_driver_s *priv; + FAR struct i2c_transfer_s *transfer; + int ret; + + /* Get our private data structure */ + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + + priv = (FAR struct i2c_driver_s *)inode->i_private; + DEBUGASSERT(priv); + + /* Get the reference to the i2c_transfer_s structure */ + + transfer = (FAR struct i2c_transfer_s *)((uintptr_t)arg); + DEBUGASSERT(transfer != NULL); + + /* Get exclusive access to the I2C driver state structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode < 0); + return -errcode; + } + + /* Perform the transfer */ + + ret = I2C_TRANSFER(priv->i2c, transfer->msgv, transfer->msgc); + + sem_post(&priv->exclsem); + return ret; + } + else + { + return -ENOTTY; + } +} + +/**************************************************************************** + * Name: i2cdrvr_unlink + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int i2cdrvr_unlink(FAR struct inode *inode) +{ + FAR struct i2c_driver_s *priv; + int ret; + + /* Get our private data structure */ + + DEBUGASSERT(inde != NULL && inode->i_private != NULL); + priv = (FAR struct i2c_driver_s *)inode->i_private; + + /* Get exclusive access to the I2C driver state structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode < 0); + return -errcode; + } + + /* Are there open references to the driver data structure? */ + + if (priv->crefs <= 0) + { + sem_destroy(&priv->exclsem); + kmm_free(priv); + return OK; + } + + /* No... just mark the driver as unlinked and free the resouces when the + * last client closes their reference to the driver. + */ + + priv->unlinked = true; + sem_post(&priv->exclsem); + return ret; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2c_register + * + * Description: + * Create and register the I2C character driver. + * + * The I2C character driver is a simple character driver that supports I2C + * transfers. The intent of this driver is to support I2C testing. It is + * not suitable for use in any real driver application. + * + * Input Parameters: + * i2c - An instance of the lower half I2C driver + * bus - The I2C bus number. This will be used as the I2C device minor + * number. The I2C character device will be registered as /dev/i2cN + * where N is the minor number + * + * Returned Value: + * OK if the driver was successfully register; A negated errno value is + * returned on any failure. + * + ****************************************************************************/ + +int i2c_register(FAR struct i2c_master_s *i2c, int bus) +{ + FAR struct i2c_driver_s *priv; + char devname[DEVNAME_FMTLEN]; + int ret; + + /* Sanity check */ + + DEBUGASSERT(i2c != NULL && (unsigned)bus < 1000); + + /* Allocate a I2C character device structure */ + + priv = (FAR struct i2c_driver_s *)kmm_zalloc(sizeof(struct i2c_driver_s)); + if (priv) + { + /* Initialize the I2C character device structure */ + + priv->i2c = i2c; +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + sem_init(&priv->exclsem, 0, 1); +#endif + + /* Create the character device name */ + + snprintf(devname, DEVNAME_FMTLEN, DEVNAME_FMT, bus); + ret = register_driver(devname, &i2cdrvr_fops, 0666, priv); + if (ret < 0) + { + /* Free the device structure if we failed to create the character + * device. + */ + + kmm_free(priv); + } + + /* Return the result of the registration */ + + return OK; + } + + + return -ENOMEM; +} + +#endif /* CONFIG_I2C_DRIVER */ \ No newline at end of file diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 09893a63f8..e404057d7e 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -82,6 +82,7 @@ #define _ZCBASE (0x1d00) /* Zero Cross ioctl commands */ #define _LOOPBASE (0x1e00) /* Loop device commands */ #define _MODEMBASE (0x1f00) /* Modem ioctl commands */ +#define _I2CBASE (0x2000) /* I2C driver commands */ /* boardctl commands share the same number space */ @@ -374,6 +375,12 @@ #define _MODEMIOCVALID(c) (_IOC_TYPE(c)==_MODEMBASE) #define _MODEMIOC(nr) _IOC(_MODEMBASE,nr) +/* I2C driver ioctl definitions **********************************************/ +/* see nuttx/include/i2c/i2c_master.h */ + +#define _I2CIOCVALID(c) (_IOC_TYPE(c)==_I2CBASE) +#define _I2CIOC(nr) _IOC(_I2CBASE,nr) + /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 657703099f..d6a998ade6 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -45,6 +45,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -78,6 +80,16 @@ #define I2C_M_NORESTART 0x0080 /* Message should not begin with * (re-)start of transfer */ +/* I2C Character Driver IOCTL Commands **************************************/ + +/* Command: I2CIOC_TRANSFER + * Description: Perform an I2C transfer + * Argument: A reference to an instance of struct i2c_transfer_s. + * Dependencies: CONFIG_I2C_DRIVER + */ + +#define I2CIOC_TRANSFER _I2CIOC(0x0001) + /* Access macros ************************************************************/ /**************************************************************************** @@ -151,6 +163,16 @@ struct i2c_master_s const struct i2c_ops_s *ops; /* I2C vtable */ }; +/* This structure is used to communicate with the I2C character driver in + * order to perform IOCTL transfers. + */ + +struct i2c_transfer_s +{ + FAR struct i2c_msg_s *msgv; /* Array of I2C messages for the transfer */ + size_t msgc; /* Number of messges in the array. */ +}; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -212,6 +234,32 @@ int up_i2cuninitialize(FAR struct i2c_master_s *dev); int up_i2creset(FAR struct i2c_master_s *dev); #endif +/**************************************************************************** + * Name: i2c_register + * + * Description: + * Create and register the I2C character driver. + * + * The I2C character driver is a simple character driver that supports I2C + * transfers. The intent of this driver is to support I2C testing. It is + * not suitable for use in any real driver application. + * + * Input Parameters: + * i2c - An instance of the lower half I2C driver + * bus - The I2C bus number. This will be used as the I2C device minor + * number. The I2C character device will be registered as /dev/i2cN + * where N is the minor number + * + * Returned Value: + * OK if the driver was successfully register; A negated errno value is + * returned on any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_I2C_DRIVER +int i2schar_register(FAR struct i2c_master_s *i2c, int bus); +#endif + /**************************************************************************** * Name: i2c_writeread * -- GitLab From 52ef3b2d237c8c9196c01b10dc0059f9ad7ecb3e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 10:24:49 -0600 Subject: [PATCH 672/858] I2CTOOL: Now uses the I2C driver instead of direct calls into the OS --- TODO | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index b2ad032089..e4b9dfd569 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated February 1, 2016) +NuttX TODO List (Last updated February 2, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -14,7 +14,7 @@ nuttx/ (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) - (8) Kernel/Protected Build + (7) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) (12) Network (net/, drivers/net) @@ -480,16 +480,6 @@ o Kernel/Protected Build Status: Open Priority: Medium - Title: I2C TOOL PATITIONING - Description: The tool at apps/system/i2c makes direct calls into MCU level - I2C logic within the OS and, hence, violates the OS/application - interface. An I2C character driver will need to be developed - to perform the I2C interactions within the OS; the I2C tools - will need to be modified to use that driver to perform the - I2C accesses. - Status: Open - Priority: Medium. Until this change is made, the I2C tool will not be - availabel in protected or kernel builds. Title: C++ CONSTRUCTORS HAVE TOO MANY PRIVILEGES (PROTECTED MODE) Description: When a C++ ELF module is loaded, its C++ constructors are called via sched/task_starthook.c logic. This logic runs in protected mode. -- GitLab From 9ce58ad5b7b8965b4700ae81eda4e3af14d19e06 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 11:21:48 -0600 Subject: [PATCH 673/858] I2C: up_i2creset should not be a global function; Now it is an I2C interface method --- ChangeLog | 2 + arch | 2 +- drivers/audio/wm8904.c | 8 ++-- drivers/i2c/Kconfig | 2 +- drivers/input/mxt.c | 8 ++-- include/nuttx/i2c/i2c_master.h | 69 +++++++++++----------------------- 6 files changed, 33 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index e770ca9318..36e560c172 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11437,4 +11437,6 @@ Any bug reports of bug fixes will be much appreciated (2016-02-01). * drivers/i2c/i2c_driver.c: Add an I2C character drivers to support raw I2C data transfers for test applications (2016-02-02). + * I2C_RESET: Eliminate up_i2creset(). It should not be a global function; + Now it is an I2C interface method (2016-02-02). diff --git a/arch b/arch index f80912e0ce..263fa48aae 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit f80912e0ceb3ff4c83eb86a3d128df81b2bc9a85 +Subproject commit 263fa48aae03da290b64ee43a31e321722e32ee1 diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index 6f1694fbe6..8d441e00ce 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -292,10 +292,10 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr) auddbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret); - ret = up_i2creset(priv->i2c); + ret = I2C_RESET(priv->i2c); if (ret < 0) { - auddbg("ERROR: up_i2creset failed: %d\n", ret); + auddbg("ERROR: I2C_RESET failed: %d\n", ret); break; } #else @@ -368,10 +368,10 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr, auddbg("WARNING: i2c_write failed: %d ... Resetting\n", ret); - ret = up_i2creset(priv->i2c); + ret = I2C_RESET(priv->i2c); if (ret < 0) { - auddbg("ERROR: up_i2creset failed: %d\n", ret); + auddbg("ERROR: I2C_RESET failed: %d\n", ret); break; } #else diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index c80954b37b..95bd112500 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -14,7 +14,7 @@ config I2C_POLLED default n config I2C_RESET - bool "Support up_i2creset" + bool "Support I2C reset interface method" default n depends on ARCH_HAVE_I2CRESET diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index d7444a5522..b37c49a622 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -344,10 +344,10 @@ static int mxt_getreg(FAR struct mxt_dev_s *priv, uint16_t regaddr, idbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret); - ret = up_i2creset(priv->i2c); + ret = I2C_RESET(priv->i2c); if (ret < 0) { - idbg("ERROR: up_i2creset failed: %d\n", ret); + idbg("ERROR: I2C_RESET failed: %d\n", ret); break; } #else @@ -418,10 +418,10 @@ static int mxt_putreg(FAR struct mxt_dev_s *priv, uint16_t regaddr, idbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret); - ret = up_i2creset(priv->i2c); + ret = I2C_RESET(priv->i2c); if (ret < 0) { - idbg("ERROR: up_i2creset failed: %d\n", ret); + idbg("ERROR: I2C_RESET failed: %d\n", ret); } #else idbg("ERROR: I2C_TRANSFER failed: %d\n", ret); diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index d6a998ade6..7249417bcf 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -113,6 +113,24 @@ #define I2C_TRANSFER(d,m,c) ((d)->ops->transfer(d,m,c)) +/************************************************************************************ + * Name: I2C_RESET + * + * Description: + * Perform an I2C bus reset in an attempt to break loose stuck I2C devices. + * + * Input Parameters: + * dev - Device-specific state data + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ************************************************************************************/ + +#ifdef CONFIG_I2C_RESET +# define I2C_RESET(d) ((d)->ops->reset(d)) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -125,6 +143,9 @@ struct i2c_ops_s { int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count); +#ifdef CONFIG_I2C_RESET + int (*reset)(FAR struct i2c_master_s *dev); +#endif }; /* This structure contains the full state of I2C as needed for a specific @@ -186,54 +207,6 @@ extern "C" #define EXTERN extern #endif -/**************************************************************************** - * Name: up_i2cinitialize - * - * Description: - * Initialize the selected I2C port. And return a unique instance of struct - * struct i2c_master_s. This function may be called to obtain multiple - * instances of the interface, each of which may be set up with a - * different frequency and slave address. - * - * Input Parameter: - * Port number (for hardware that has multiple I2C interfaces) - * - * Returned Value: - * Valid I2C device structure reference on succcess; a NULL on failure - * - ****************************************************************************/ - -FAR struct i2c_master_s *up_i2cinitialize(int port); - -/**************************************************************************** - * Name: up_i2cuninitialize - * - * Description: - * De-initialize the selected I2C port, and power down the device. - * - * Input Parameter: - * Device structure as returned by the up_i2cinitialize() - * - * Returned Value: - * OK on success, ERROR when internal reference count mismatch or dev - * points to invalid hardware device. - * - ****************************************************************************/ - -int up_i2cuninitialize(FAR struct i2c_master_s *dev); - -/************************************************************************************ - * Name: up_i2creset - * - * Description: - * Reset an I2C bus - * - ************************************************************************************/ - -#ifdef CONFIG_I2C_RESET -int up_i2creset(FAR struct i2c_master_s *dev); -#endif - /**************************************************************************** * Name: i2c_register * -- GitLab From 95df32a5ceb4e8309f6bb8a3fa5a3ba72683a172 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 12:27:26 -0600 Subject: [PATCH 674/858] Update ChangeLog --- ChangeLog | 5 +++++ arch | 2 +- configs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36e560c172..7712850411 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11439,4 +11439,9 @@ raw I2C data transfers for test applications (2016-02-02). * I2C_RESET: Eliminate up_i2creset(). It should not be a global function; Now it is an I2C interface method (2016-02-02). + * I2C: Rename up_i2cinitialize and up_i2cuninitilize to follow the correct + naming convention. These are not common interfaces used by the OS; + these are MCU-specific interfaces used only be MCU-specific code. The + the correct naming is xyz_i2cbus_initialize and xzy_i2cbus_uninitialize + where xzy is the MCU mnemonic (2016-02-02). diff --git a/arch b/arch index 263fa48aae..403b4e70eb 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 263fa48aae03da290b64ee43a31e321722e32ee1 +Subproject commit 403b4e70ebbca5c938ed0bd4531a0972ec736c7e diff --git a/configs b/configs index 5888111526..13812e17cb 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 588811152643ca752381a52ec57986c0c4b1a376 +Subproject commit 13812e17cb6b800394d241cae3879032ce0643af -- GitLab From e5d86dd3fced2addf1626e33c096f9f983b82811 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 12:53:32 -0600 Subject: [PATCH 675/858] Oops. Apparently a copy'n'paste was accidentally a cut'n'paste --- drivers/ioexpander/pca9555.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index bdfb9c6c79..26dc762d93 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -136,7 +136,7 @@ static const struct ioexpander_ops_s g_pca9555_ops = ****************************************************************************/ static inline int pca9555_write(FAR struct pca9555_dev_s *pca, - FAR const uint8_t *, int wbuflen) + FAR const uint8_t *wbuffer, int wbuflen) { struct i2c_msg_s msg; -- GitLab From 03d868be3c3ae360b55242fc4aa0190a2123d14a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 14:23:33 -0600 Subject: [PATCH 676/858] I2C: Fix a naming error --- configs | 2 +- include/nuttx/i2c/i2c_master.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs b/configs index 13812e17cb..3f185b5937 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 13812e17cb6b800394d241cae3879032ce0643af +Subproject commit 3f185b593758ca2ddbdb3f245e0d595ea66934c2 diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 7249417bcf..330e2e0e9b 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -230,7 +230,7 @@ extern "C" ****************************************************************************/ #ifdef CONFIG_I2C_DRIVER -int i2schar_register(FAR struct i2c_master_s *i2c, int bus); +int i2c_register(FAR struct i2c_master_s *i2c, int bus); #endif /**************************************************************************** -- GitLab From be3e86ec89e055eb1921c7a5f8c7431f8aa6dfb4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 14:41:25 -0600 Subject: [PATCH 677/858] Fix a typo in a DEBUGASSERT statement --- drivers/i2c/i2c_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_driver.c b/drivers/i2c/i2c_driver.c index 05331dc866..d720ef3d38 100644 --- a/drivers/i2c/i2c_driver.c +++ b/drivers/i2c/i2c_driver.c @@ -308,7 +308,7 @@ static int i2cdrvr_unlink(FAR struct inode *inode) /* Get our private data structure */ - DEBUGASSERT(inde != NULL && inode->i_private != NULL); + DEBUGASSERT(inode != NULL && inode->i_private != NULL); priv = (FAR struct i2c_driver_s *)inode->i_private; /* Get exclusive access to the I2C driver state structure */ -- GitLab From 8fa9b99e7c28e2f133a25727d6261c7845439b31 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 07:32:25 -0600 Subject: [PATCH 678/858] I2C driver should support the RESET method as well --- drivers/i2c/i2c_driver.c | 85 ++++++++++++++++++++++------------ include/nuttx/i2c/i2c_master.h | 14 ++++++ 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/drivers/i2c/i2c_driver.c b/drivers/i2c/i2c_driver.c index d720ef3d38..ac53f0f1f1 100644 --- a/drivers/i2c/i2c_driver.c +++ b/drivers/i2c/i2c_driver.c @@ -249,51 +249,76 @@ static ssize_t i2cdrvr_write(FAR struct file *filep, FAR const char *buffer, static int i2cdrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { - i2cvdbg("cmd=%d arg=%lu\n", cmd, arg); + FAR struct inode *inode = filep->f_inode; + FAR struct i2c_driver_s *priv; + FAR struct i2c_transfer_s *transfer; + int ret; - /* Only one command is supported */ + i2cvdbg("cmd=%d arg=%lu\n", cmd, arg); - if (cmd == I2CIOC_TRANSFER) - { - FAR struct inode *inode = filep->f_inode; - FAR struct i2c_driver_s *priv; - FAR struct i2c_transfer_s *transfer; - int ret; + /* Get our private data structure */ - /* Get our private data structure */ + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; + priv = (FAR struct i2c_driver_s *)inode->i_private; + DEBUGASSERT(priv); - priv = (FAR struct i2c_driver_s *)inode->i_private; - DEBUGASSERT(priv); + /* Get exclusive access to the I2C driver state structure */ - /* Get the reference to the i2c_transfer_s structure */ + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode < 0); + return -errcode; + } - transfer = (FAR struct i2c_transfer_s *)((uintptr_t)arg); - DEBUGASSERT(transfer != NULL); + /* Process the IOCTL command */ - /* Get exclusive access to the I2C driver state structure */ + switch (cmd) + { + /* Command: I2CIOC_TRANSFER + * Description: Perform an I2C transfer + * Argument: A reference to an instance of struct i2c_transfer_s. + * Dependencies: CONFIG_I2C_DRIVER + */ - ret = sem_wait(&priv->exclsem); - if (ret < 0) + case I2CIOC_TRANSFER: { - int errcode = errno; - DEBUGASSERT(errcode < 0); - return -errcode; + /* Get the reference to the i2c_transfer_s structure */ + + transfer = (FAR struct i2c_transfer_s *)((uintptr_t)arg); + DEBUGASSERT(transfer != NULL); + + /* Perform the transfer */ + + ret = I2C_TRANSFER(priv->i2c, transfer->msgv, transfer->msgc); } + break; - /* Perform the transfer */ +#ifdef CONFIG_I2C_RESET + /* Command: I2CIOC_RESET + * Description: Perform an I2C bus reset in an attempt to break loose + * stuck I2C devices. + * Argument: None + * Dependencies: CONFIG_I2C_DRIVER && CONFIG_I2C_RESET + */ - ret = I2C_TRANSFER(priv->i2c, transfer->msgv, transfer->msgc); + case I2CIOC_RESET: + { + ret = I2C_RESET(priv->i2c); + } + break; +#endif - sem_post(&priv->exclsem); - return ret; - } - else - { - return -ENOTTY; + default: + ret = -ENOTTY; + break; } + + sem_post(&priv->exclsem); + return ret; } /**************************************************************************** diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 330e2e0e9b..868dad15b9 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -81,6 +81,11 @@ * (re-)start of transfer */ /* I2C Character Driver IOCTL Commands **************************************/ +/* The I2C driver is intended to support application testing of the I2C bus. + * The I2C driver simply wraps an instance of struct i2c_dev_s and then + * provides the following IOCTL commands to access each method of the I2c + * interface. + */ /* Command: I2CIOC_TRANSFER * Description: Perform an I2C transfer @@ -90,6 +95,15 @@ #define I2CIOC_TRANSFER _I2CIOC(0x0001) +/* Command: I2CIOC_RESET + * Description: Perform an I2C bus reset in an attempt to break loose stuck + * I2C devices. + * Argument: None + * Dependencies: CONFIG_I2C_DRIVER && CONFIG_I2C_RESET + */ + +#define I2CIOC_RESET _I2CIOC(0x0002) + /* Access macros ************************************************************/ /**************************************************************************** -- GitLab From 42c365aab1aa030e9147e5d2e85a2a7193bd58fc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 10:34:10 -0600 Subject: [PATCH 679/858] Duplicate Manuel's EMAC driver fix to every other driver that supports CONFIG_NET_NOINTS --- arch | 2 +- drivers/net/e1000.c | 6 ------ drivers/net/encx24j600.c | 8 ++++++++ drivers/net/ftmac100.c | 9 +++++++++ drivers/net/skeleton.c | 17 +++++++++++++++-- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/arch b/arch index 403b4e70eb..be6af64502 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 403b4e70ebbca5c938ed0bd4531a0972ec736c7e +Subproject commit be6af64502d5520799fcba3ed20b6fff13f88ca0 diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index e0b063af1a..cbed8d5656 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -1018,11 +1018,6 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) wd_cancel(e1000->txtimeout); } - /* Check is a packet transmission just completed. If so, call skel_txdone. - * This may disable further Tx interrupts if there are no pending - * tansmissions. - */ - /* Tx-descriptor Written back */ if (intr_cause & (1 << 0)) @@ -1030,7 +1025,6 @@ static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) devif_poll(&e1000->netdev, e1000_txpoll); } - /* Rx-Descriptors Low */ if (intr_cause & (1 << 4)) diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 9a94ac005d..d5846c752b 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1288,6 +1288,14 @@ static void enc_txif(FAR struct enc_driver_s *priv) wd_cancel(priv->txtimeout); + /* Then make sure that the TX poll timer is running (if it is already + * running, the following would restart it). This is necessary to + * avoid certain race conditions where the polling sequence can be + * interrupted. + */ + + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + /* Poll for TX packets from the networking layer */ devif_poll(&priv->dev, enc_txpoll); diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index eecc4c9615..9e2ada57ff 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -838,8 +838,17 @@ static void ftmac100_txdone(FAR struct ftmac100_driver_s *priv) nvdbg("txpending=%d\n", priv->tx_pending); + /* Cancel the TX timeout */ + wd_cancel(priv->ft_txtimeout); + /* Then make sure that the TX poll timer is running (if it is already + * running, the following would restart it). This is necessary to avoid + * certain race conditions where the polling sequence can be interrupted. + */ + + (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, priv); + /* Then poll uIP for new XMIT data */ (void)devif_poll(&priv->ft_dev, ftmac100_txpoll); diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index a395b2eda1..516b6f0e8c 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -458,13 +458,26 @@ static void skel_txdone(FAR struct skel_driver_s *priv) NETDEV_TXDONE(priv->sk_dev); - /* If no further xmits are pending, then cancel the TX timeout and + /* Check if there are pending transmissions */ + + /* If no further transmissions are pending, then cancel the TX timeout and * disable further Tx interrupts. */ wd_cancel(priv->sk_txtimeout); - /* Then poll the network for new XMIT data */ + /* Then make sure that the TX poll timer is running (if it is already + * running, the following would restart it). This is necessary to + * avoid certain race conditions where the polling sequence can be + * interrupted. + */ + + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); + + /* And disable further TX interrupts. */ + + /* In any event, poll the network for new TX data */ (void)devif_poll(&priv->sk_dev, skel_txpoll); } -- GitLab From ff1e057364adbca3ab9b8be0237ce2183adbc53c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 10:55:51 -0600 Subject: [PATCH 680/858] Missed one EMAC driver in the last commit --- drivers/net/enc28j60.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 842d18cc2a..db3bbb2de5 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1279,6 +1279,14 @@ static void enc_txif(FAR struct enc_driver_s *priv) wd_cancel(priv->txtimeout); + /* Then make sure that the TX poll timer is running (if it is already + * running, the following would restart it). This is necessary to + * avoid certain race conditions where the polling sequence can be + * interrupted. + */ + + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + /* Then poll uIP for new XMIT data */ (void)devif_poll(&priv->dev, enc_txpoll); -- GitLab From dea24c503a073a2200d27e039c9a15c428d96d7a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 12:12:41 -0600 Subject: [PATCH 681/858] Networking: Remove the HSEC argument from devif_timer. --- ChangeLog | 6 ++- arch | 2 +- drivers/net/cs89x0.c | 3 +- drivers/net/dm90x0.c | 3 +- drivers/net/e1000.c | 3 +- drivers/net/enc28j60.c | 3 +- drivers/net/encx24j600.c | 3 +- drivers/net/ftmac100.c | 3 +- drivers/net/loopback.c | 3 +- drivers/net/skeleton.c | 3 +- drivers/net/slip.c | 2 +- drivers/net/tun.c | 3 +- drivers/net/vnet.c | 3 +- include/nuttx/clock.h | 20 ++++++-- include/nuttx/net/netdev.h | 5 +- net/arp/arp_poll.c | 8 ---- net/devif/devif.h | 5 ++ net/devif/devif_initialize.c | 13 ++---- net/devif/devif_poll.c | 73 ++++++++++++++++++++++-------- net/neighbor/neighbor.h | 30 ++---------- net/neighbor/neighbor_initialize.c | 33 +------------- net/neighbor/neighbor_periodic.c | 51 +++++++-------------- net/net_initialize.c | 8 +--- 23 files changed, 122 insertions(+), 164 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7712850411..a74d8a4917 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11444,4 +11444,8 @@ these are MCU-specific interfaces used only be MCU-specific code. The the correct naming is xyz_i2cbus_initialize and xzy_i2cbus_uninitialize where xzy is the MCU mnemonic (2016-02-02). - + * Networking drivers that support CONFIG_NET_NOINTS: Fix a race condition + that can cause the TX poll timer to stop running. From Manuel Stuhn + (2016-02-03). + * All Network drivers: Remove the hsec parameter from devif_timer(). + We can get better timing accuracy without it (2016-02-03). diff --git a/arch b/arch index be6af64502..757fb2224a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit be6af64502d5520799fcba3ed20b6fff13f88ca0 +Subproject commit 757fb2224ae99916b8b46695a007a6be06f33dfb diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index 5adbe42135..f27c0a077d 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -76,7 +76,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define CS89x0_WDDELAY (1*CLK_TCK) -#define CS89x0_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -790,7 +789,7 @@ static void cs89x0_polltimer(int argc, uint32_t arg, ...) /* If so, update TCP timing states and poll uIP for new XMIT data */ - (void)devif_timer(&cs89x0->cs_dev, cs89x0_txpoll, CS89x0_POLLHSEC); + (void)devif_timer(&cs89x0->cs_dev, cs89x0_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index e810c6b672..37e49d3bae 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -266,7 +266,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define DM6X_WDDELAY (1*CLK_TCK) -#define DM6X_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1266,7 +1265,7 @@ static void dm9x_polltimer(int argc, uint32_t arg, ...) { /* If so, update TCP timing states and poll uIP for new XMIT data */ - (void)devif_timer(&dm9x->dm_dev, dm9x_txpoll, DM6X_POLLHSEC); + (void)devif_timer(&dm9x->dm_dev, dm9x_txpoll); } /* Setup the watchdog poll timer again */ diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index cbed8d5656..cdc8f236e0 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -78,7 +78,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define E1000_WDDELAY (1*CLK_TCK) -#define E1000_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -770,7 +769,7 @@ static void e1000_polltimer(int argc, uint32_t arg, ...) * we will missing TCP time state updates? */ - (void)devif_timer(&e1000->netdev, e1000_txpoll, E1000_POLLHSEC); + (void)devif_timer(&e1000->netdev, e1000_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index db3bbb2de5..e1665ea86b 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -144,7 +144,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define ENC_WDDELAY (1*CLK_TCK) -#define ENC_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1990,7 +1989,7 @@ static void enc_pollworker(FAR void *arg) * in progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->dev, enc_txpoll, ENC_POLLHSEC); + (void)devif_timer(&priv->dev, enc_txpoll); } /* Release lock on the SPI bus and uIP */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index d5846c752b..baa18cc438 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -149,7 +149,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define ENC_WDDELAY (1*CLK_TCK) -#define ENC_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -2156,7 +2155,7 @@ static void enc_pollworker(FAR void *arg) * in progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->dev, enc_txpoll, ENC_POLLHSEC); + (void)devif_timer(&priv->dev, enc_txpoll); } /* Release lock on the SPI bus and uIP */ diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 9e2ada57ff..6a9f53ed13 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -91,7 +91,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define FTMAC100_WDDELAY (1*CLK_TCK) -#define FTMAC100_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -1200,7 +1199,7 @@ static inline void ftmac100_poll_process(FAR struct ftmac100_driver_s *priv) * we will missing TCP time state updates? */ - (void)devif_timer(&priv->ft_dev, ftmac100_txpoll, FTMAC100_POLLHSEC); + (void)devif_timer(&priv->ft_dev, ftmac100_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 7bb99c1744..3b750b8051 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -78,7 +78,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define LO_WDDELAY (1*CLK_TCK) -#define LO_POLLHSEC (1*2) /* This is a helper pointer for accessing the contents of the Ethernet header */ @@ -242,7 +241,7 @@ static void lo_poll_work(FAR void *arg) state = net_lock(); priv->lo_txdone = false; - (void)devif_timer(&priv->lo_dev, lo_txpoll, LO_POLLHSEC); + (void)devif_timer(&priv->lo_dev, lo_txpoll); /* Was something received and looped back? */ diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 516b6f0e8c..ef6f2bf595 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -86,7 +86,6 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define skeleton_WDDELAY (1*CLK_TCK) -#define skeleton_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -746,7 +745,7 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->sk_dev, skel_txpoll, skeleton_POLLHSEC); + (void)devif_timer(&priv->sk_dev, skel_txpoll); /* Setup the watchdog poll timer again */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index d1ecef3aca..c02ebb0e93 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -490,7 +490,7 @@ static void slip_txtask(int argc, FAR char *argv[]) { /* Yes, perform the timer poll */ - (void)devif_timer(&priv->dev, slip_txpoll, hsec); + (void)devif_timer(&priv->dev, slip_txpoll); msec_start += hsec * (MSEC_PER_SEC / 2); } else diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 97a4fd7d26..1221b56ad8 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -96,7 +96,6 @@ */ #define TUN_WDDELAY (1*CLK_TCK) -#define TUN_POLLHSEC (1*2) /**************************************************************************** * Private Types @@ -533,7 +532,7 @@ static void tun_poll_process(FAR struct tun_device_s *priv) /* If so, poll uIP for new XMIT data. */ priv->dev.d_buf = priv->read_buf; - (void)devif_timer(&priv->dev, tun_txpoll, TUN_POLLHSEC); + (void)devif_timer(&priv->dev, tun_txpoll); } /* Setup the watchdog poll timer again */ diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index d8849d8194..e57b654a9d 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -81,7 +81,6 @@ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define VNET_WDDELAY (1*CLK_TCK) -#define VNET_POLLHSEC (1*2) /* TX timeout = 1 minute */ @@ -518,7 +517,7 @@ static void vnet_polltimer(int argc, uint32_t arg, ...) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&vnet->sk_dev, vnet_txpoll, VNET_POLLHSEC); + (void)devif_timer(&vnet->sk_dev, vnet_txpoll); /* Setup the watchdog poll timer again */ diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 501545fac9..c0fcc35b75 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -99,16 +99,25 @@ /* Timing constants *********************************************************/ -#define NSEC_PER_SEC 1000000000L +#define NSEC_PER_SEC 1000000000L /* Seconds */ #define USEC_PER_SEC 1000000L #define MSEC_PER_SEC 1000L #define DSEC_PER_SEC 10L -#define NSEC_PER_DSEC 100000000L +#define HSEC_PER_SEC 2L + +#define NSEC_PER_HSEC 500000000L /* Half seconds */ +#define USEC_PER_HSEC 500000L +#define MSEC_PER_HSEC 500L +#define DSEC_PER_HSEC 5L + +#define NSEC_PER_DSEC 100000000L /* Deciseconds */ #define USEC_PER_DSEC 100000L #define MSEC_PER_DSEC 100L -#define NSEC_PER_MSEC 1000000L + +#define NSEC_PER_MSEC 1000000L /* Milliseconds */ #define USEC_PER_MSEC 1000L -#define NSEC_PER_USEC 1000L + +#define NSEC_PER_USEC 1000L /* Microseconds */ /* If CONFIG_SCHED_TICKLESS is not defined, then the interrupt interval of * the system timer is given by USEC_PER_TICK. This is the expected number @@ -136,6 +145,7 @@ */ #define TICK_PER_DSEC (USEC_PER_DSEC / USEC_PER_TICK) /* Truncates! */ +#define TICK_PER_HSEC (USEC_PER_HSEC / USEC_PER_TICK) /* Truncates! */ #define TICK_PER_SEC (USEC_PER_SEC / USEC_PER_TICK) /* Truncates! */ #define TICK_PER_MSEC (USEC_PER_MSEC / USEC_PER_TICK) /* Truncates! */ #define MSEC_PER_TICK (USEC_PER_TICK / USEC_PER_MSEC) /* Truncates! */ @@ -151,6 +161,7 @@ #endif #define DSEC2TICK(dsec) MSEC2TICK((dsec) * MSEC_PER_DSEC) /* Rounds */ +#define HSEC2TICK(dsec) MSEC2TICK((dsec) * MSEC_PER_HSEC) /* Rounds */ #define SEC2TICK(sec) MSEC2TICK((sec) * MSEC_PER_SEC) /* Rounds */ #define TICK2NSEC(tick) ((tick) * NSEC_PER_TICK) /* Exact */ @@ -163,6 +174,7 @@ #endif #define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ +#define TICK2HSEC(tick) (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ /**************************************************************************** diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 3182e7f80b..de6e997faf 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -2,7 +2,7 @@ * include/nuttx/net/netdev.h * Defines architecture-specific device driver interfaces to the uIP network. * - * Copyright (C) 2007, 2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Derived largely from portions of uIP with has a similar BSD-styple license: @@ -475,8 +475,7 @@ int ipv6_input(FAR struct net_driver_s *dev); ****************************************************************************/ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback); -int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, - int hsec); +int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback); /**************************************************************************** * Name: neighbor_out diff --git a/net/arp/arp_poll.c b/net/arp/arp_poll.c index 85cc2b38c0..424d0fe2e7 100644 --- a/net/arp/arp_poll.c +++ b/net/arp/arp_poll.c @@ -48,14 +48,6 @@ #ifdef CONFIG_NET_ARP_SEND -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/devif/devif.h b/net/devif/devif.h index a7c26d3437..58f7fffa9d 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -51,6 +51,7 @@ #include #include +#include #include /**************************************************************************** @@ -256,6 +257,10 @@ extern uint16_t g_ipid; extern uint8_t g_reassembly_timer; #endif +/* Time of last poll */ + +extern systime_t g_polltime; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/net/devif/devif_initialize.c b/net/devif/devif_initialize.c index 606a22f9b7..4142019e2c 100644 --- a/net/devif/devif_initialize.c +++ b/net/devif/devif_initialize.c @@ -46,6 +46,7 @@ #include +#include #include #include @@ -139,14 +140,6 @@ const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */ #endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER */ #endif /* CONFIG_NET_IPv4 */ -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -167,6 +160,10 @@ const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */ void devif_initialize(void) { + /* Initialize the time of the last timer poll */ + + g_polltime = clock_systimer(); + /* Initialize callback support */ devif_callback_init(); diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 67f7e05c02..32a2eb51ab 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/devif/devif_poll.c * - * Copyright (C) 2007-2010, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include +#include #include #include @@ -56,9 +57,13 @@ #include "igmp/igmp.h" /**************************************************************************** - * Private Data + * Public Data ****************************************************************************/ +/* Time of last poll */ + +systime_t g_polltime; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -258,22 +263,30 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_TCP static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev, - devif_poll_callback_t callback, int hsec) + devif_poll_callback_t callback, + int hsec) { FAR struct tcp_conn_s *conn = NULL; int bstop = 0; - /* Traverse all of the active TCP connections and perform the poll action */ + /* Don't do anything is less a half second has elapsed */ - while (!bstop && (conn = tcp_nextconn(conn))) + if (hsec > 0) { - /* Perform the TCP timer poll */ + /* Traverse all of the active TCP connections and perform the poll + * action. + */ - tcp_timer(dev, conn, hsec); + while (!bstop && (conn = tcp_nextconn(conn))) + { + /* Perform the TCP timer poll */ - /* Call back into the driver */ + tcp_timer(dev, conn, hsec); - bstop = callback(dev); + /* Call back into the driver */ + + bstop = callback(dev); + } } return bstop; @@ -414,26 +427,46 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) * ****************************************************************************/ -int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, - int hsec) +int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { + systime_t now; + systime_t elpased; int bstop = false; + int hsec; - /* Increment the timer used by the IP reassembly logic */ + /* Get the elapsed time since the last poll in units of half seconds + * (truncating). + */ -#if defined(CONFIG_NET_TCP_REASSEMBLY) && defined(CONFIG_NET_IPv4) - if (g_reassembly_timer != 0 && - g_reassembly_timer < CONFIG_NET_TCP_REASS_MAXAGE) + now = clock_systimer(); + hsec = (now - g_polltime) / TICK_PER_HSEC; + + /* Update the time only when more than one half second elapses */ + + if (hsec > 0) { - g_reassembly_timer += hsec; - } + /* Save the current time */ + + g_polltime = now; + + /* Perform periodic activitives that depend on hsec > 0 */ + +#if defined(CONFIG_NET_TCP_REASSEMBLY) && defined(CONFIG_NET_IPv4) + /* Increment the timer used by the IP reassembly logic */ + + if (g_reassembly_timer != 0 && + g_reassembly_timer < CONFIG_NET_TCP_REASS_MAXAGE) + { + g_reassembly_timer += hsec; + } #endif #ifdef CONFIG_NET_IPv6 - /* Perform ageing on the entries in the Neighbor Table */ + /* Perform aging on the entries in the Neighbor Table */ - neighbor_periodic(); + neighbor_periodic(hsec); #endif + } /* Traverse all of the active packet connections and perform the poll * action. @@ -467,6 +500,8 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback, { /* Traverse all of the active TCP connections and perform the * timer action. + * + * NOTE: devif_poll_tcp_timer will handle the case where hsec <= 0. */ bstop = devif_poll_tcp_timer(dev, callback, hsec); diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index d6330f16a9..a8317f6d36 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -99,16 +99,12 @@ struct neighbor_entry extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; -/* This is the time, in clock ticks, of the last poll */ - -extern systime_t g_neighbor_polltime; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: neighbor_setup + * Name: neighbor_initialize * * Description: * Initialize Neighbor table data structures. This function is called @@ -124,26 +120,6 @@ extern systime_t g_neighbor_polltime; * ****************************************************************************/ -void neighbor_setup(void); - -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor ageing. This function is called from the OS - * initialization logic at power-up reset AFTER initialization of hardware - * facilities such as timers and interrupts. This logic completes the - * initialization started by neighbor_setup. - * - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - void neighbor_initialize(void); /**************************************************************************** @@ -226,14 +202,14 @@ void neighbor_update(const net_ipv6addr_t ipaddr); * entries in the Neighbor Table * * Input Parameters: - * None + * hsec - Elapsed time in half seconds since the last check * * Returned Value: * None * ****************************************************************************/ -void neighbor_periodic(void); +void neighbor_periodic(int hsec); #endif /* CONFIG_NET_IPv6 */ #endif /* __NET_NEIGHBOR_NEIGHBOR_H */ diff --git a/net/neighbor/neighbor_initialize.c b/net/neighbor/neighbor_initialize.c index 124e0f9a89..d25fb782f3 100644 --- a/net/neighbor/neighbor_initialize.c +++ b/net/neighbor/neighbor_initialize.c @@ -56,16 +56,12 @@ struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; -/* This is the time, in clock ticks, of the last poll */ - -systime_t g_neighbor_polltime; - /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: neighbor_setup + * Name: neighbor_initialize * * Description: * Initialize Neighbor table data structures. This function is called @@ -81,7 +77,7 @@ systime_t g_neighbor_polltime; * ****************************************************************************/ -void neighbor_setup(void) +void neighbor_initialize(void) { int i; @@ -90,28 +86,3 @@ void neighbor_setup(void) g_neighbors[i].ne_time = NEIGHBOR_MAXTIME; } } - -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor ageing. This function is called from the OS - * initialization logic at power-up reset AFTER initialization of hardware - * facilities such as timers and interrupts. This logic completes the - * initialization started by neighbor_setup. - * - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_initialize(void) -{ - /* Initialize the time of the last poll */ - - g_neighbor_polltime = clock_systimer(); -} diff --git a/net/neighbor/neighbor_periodic.c b/net/neighbor/neighbor_periodic.c index c242b099d2..2ca0a5b3ca 100644 --- a/net/neighbor/neighbor_periodic.c +++ b/net/neighbor/neighbor_periodic.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/neighbor/neighbor_periodic.c * - * Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * A leverage of logic from uIP which also has a BSD style license @@ -42,18 +42,9 @@ ****************************************************************************/ #include -#include #include "neighbor/neighbor.h" -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#define USEC_PER_HSEC 500000 -#define TICK_PER_HSEC (USEC_PER_HSEC / USEC_PER_TICK) /* Truncates! */ -#define TICK2HSEC(tick) (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* Rounds */ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -66,42 +57,34 @@ * entries in the Neighbor Table * * Input Parameters: - * None + * hsec - Elapsed time in half seconds since the last check * * Returned Value: * None * ****************************************************************************/ -void neighbor_periodic(void) +void neighbor_periodic(int hsec) { - systime_t now; - systime_t ticks; - uint32_t hsecs; int i; - /* Get the elapsed time in units of half seconds */ - - now = clock_systimer(); - ticks = now - g_neighbor_polltime; - hsecs = (uint32_t)TICK2HSEC(ticks); + /* Only perform the aging when more than a half second has elapsed */ - /* Reset the time of the last poll */ - - g_neighbor_polltime = now; - - /* Add the elapsed half seconds from each activate entry in the - * Neighbor table. - */ - - for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) + if (hsec > 0) { - uint32_t newtime = g_neighbors[i].ne_time + hsecs; - if (newtime > NEIGHBOR_MAXTIME) + /* Add the elapsed half seconds from each activate entry in the + * Neighbor table. + */ + + for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) { - newtime = NEIGHBOR_MAXTIME; - } + uint32_t newtime = g_neighbors[i].ne_time + hsec; + if (newtime > NEIGHBOR_MAXTIME) + { + newtime = NEIGHBOR_MAXTIME; + } - g_neighbors[i].ne_time = newtime; + g_neighbors[i].ne_time = newtime; + } } } diff --git a/net/net_initialize.c b/net/net_initialize.c index 99090c650a..6de3a97c10 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -118,7 +118,7 @@ void net_setup(void) #ifdef CONFIG_NET_IPv6 /* Initialize the Neighbor Table data structures */ - neighbor_setup(); + neighbor_initialize(); #endif #ifdef CONFIG_NET_IOB @@ -197,12 +197,6 @@ void net_setup(void) void net_initialize(void) { -#ifdef CONFIG_NET_IPv6 - /* Configure Neighbor Table ageing */ - - neighbor_initialize(); -#endif - /* Initialize the periodic ARP timer */ arp_timer_initialize(); -- GitLab From cea3854deab32dab14f4f4eafc64aef74211bf3b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 12:39:11 -0600 Subject: [PATCH 682/858] PCA5555: Add logic to make the driver thread safe. Problem noted by Stefan Kolb. --- ChangeLog | 3 + drivers/ioexpander/pca9555.c | 126 +++++++++++++++++++++++++++++------ drivers/ioexpander/pca9555.h | 13 ++-- 3 files changed, 117 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index a74d8a4917..e4086e60d2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11449,3 +11449,6 @@ (2016-02-03). * All Network drivers: Remove the hsec parameter from devif_timer(). We can get better timing accuracy without it (2016-02-03). + * drivers/ioexpander/pca555.c: Add logic to make the PCA555 driver + thread safe (2016-02-03). + diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 26dc762d93..422852cd26 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -43,6 +43,7 @@ #include +#include #include #include #include @@ -127,6 +128,26 @@ static const struct ioexpander_ops_s g_pca9555_ops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: pca9555_lock + * + * Description: + * Get exclusive access to the PCA9555 + * + ****************************************************************************/ + +static void pca9555_lock(FAR struct pca9555_dev_s *pca) +{ + while (sem_wait(&pca->exclsem) < 0) + { + /* EINTR is the only expected error from sem_wait() */ + + DEBUGASSERT(errno == EINTR); + } +} + +#define pca9555_unlock(p) sem_post(&(p)->exclsem) + /**************************************************************************** * Name: pca9555_write * @@ -150,7 +171,7 @@ static inline int pca9555_write(FAR struct pca9555_dev_s *pca, /* Then perform the transfer. */ - return I2C_TRANSFER((pca->i2c, &msg, 1); + return I2C_TRANSFER(pca->i2c, &msg, 1); } /**************************************************************************** @@ -184,10 +205,9 @@ static inline int pca9555_writeread(FAR struct pca9555_dev_s *pca, * ****************************************************************************/ -static int pca9555_setbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, +static int pca9555_setbit(FAR struct pca9555_dev_s *pca, uint8_t addr, uint8_t pin, int bitval) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf[2]; int ret; @@ -229,10 +249,9 @@ static int pca9555_setbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, * ****************************************************************************/ -static int pca9555_getbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, +static int pca9555_getbit(FAR struct pca9555_dev_s *pca, uint8_t addr, uint8_t pin, FAR bool *val) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf; int ret; @@ -267,8 +286,16 @@ static int pca9555_getbit(FAR struct ioexpander_dev_s *dev, uint8_t addr, static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, int direction) { - return pca9555_setbit(dev, PCA9555_REG_CONFIG, pin, - (direction == IOEXPANDER_DIRECTION_IN)); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_setbit(pca, PCA9555_REG_CONFIG, pin, + (direction == IOEXPANDER_DIRECTION_IN)); + pca9555_unlock(pca); + return ret; } /**************************************************************************** @@ -282,14 +309,20 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, int opt, FAR void *val) { + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; int ival = (int)val; + int ret = -EINVAL; if (opt == IOEXPANDER_OPTION_INVERT) { - return pca9555_setbit(dev, PCA9555_REG_POLINV, pin, ival); + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_setbit(pca, PCA9555_REG_POLINV, pin, ival); + pca9555_unlock(pca); } - return -EINVAL; + return ret; } /**************************************************************************** @@ -303,7 +336,15 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, bool value) { - return pca9555_setbit(dev, PCA9555_REG_OUTPUT, pin, value); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_setbit(pca, PCA9555_REG_OUTPUT, pin, value); + pca9555_unlock(pca); + return ret; } /**************************************************************************** @@ -317,7 +358,15 @@ static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - return pca9555_getbit(dev, PCA9555_REG_INPUT, pin, value); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_getbit(pca, PCA9555_REG_INPUT, pin, value); + pca9555_unlock(pca); + return ret; } /**************************************************************************** @@ -331,7 +380,15 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin, static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, FAR bool *value) { - return pca9555_getbit(dev, PCA9555_REG_OUTPUT, pin, value); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_getbit(pca, PCA9555_REG_OUTPUT, pin, value); + pca9555_unlock(pca); + return ret; } #ifdef CONFIG_IOEXPANDER_MULTIPIN @@ -344,11 +401,10 @@ static int pca9555_readbuf(FAR struct ioexpander_dev_s *dev, uint8_t pin, * ****************************************************************************/ -static int pca9555_getmultibits(FAR struct ioexpander_dev_s *dev, uint8_t addr, +static int pca9555_getmultibits(FAR struct pca9555_dev_s *pca, uint8_t addr, FAR uint8_t *pins, FAR bool *values, int count) { - FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; uint8_t buf[2]; int ret = OK; int i; @@ -403,6 +459,12 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, int index; int pin; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + /* Start by reading both registers, whatever the pins to change. We could * attempt to read one port only if all pins were on the same port, but * this would not save much. */ @@ -410,6 +472,8 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, ret = pca9555_writeread(pca, &addr, 1, &buf[1], 2); if (ret < 0) { + + pca9555_unlock(pca); return ret; } @@ -421,6 +485,7 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, pin = pins[i]; if (pin > 15) { + pca9555_unlock(pca); return -ENXIO; } else if(pin > 7) @@ -442,7 +507,10 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, /* Now write back the new pins states */ buf[0] = addr; - return pca9555_write(pca, buf, 3); + ret = pca9555_write(pca, buf, 3); + + pca9555_unlock(pca); + return ret; } /**************************************************************************** @@ -457,8 +525,16 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - return pca9555_getmultibits(dev, PCA9555_REG_INPUT, - pins, values, count); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_getmultibits(pca, PCA9555_REG_INPUT, + pins, values, count); + pca9555_unlock(pca); + return ret; } /**************************************************************************** @@ -473,8 +549,16 @@ static int pca9555_multireadbuf(FAR struct ioexpander_dev_s *dev, FAR uint8_t *pins, FAR bool *values, int count) { - return pca9555_getmultibits(dev, PCA9555_REG_OUTPUT, - pins, values, count); + FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; + int ret; + + /* Get exclusive access to the PCA555 */ + + pca9555_lock(pca); + ret = pca9555_getmultibits(pca, PCA9555_REG_OUTPUT, + pins, values, count); + pca9555_unlock(pca); + return ret; } #endif @@ -544,7 +628,7 @@ static int pca9555_interrupt(int irq, FAR void *context) { #ifdef CONFIG_PCA9555_MULTIPLE /* To support multiple devices, - * retrieve the priv structure using the irq number. + * retrieve the pca structure using the irq number. */ # warning Missing logic @@ -626,6 +710,8 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *i2cdev, pcadev->config->attach(pcadev->config, pca9555_interrupt); pcadev->config->enable(pcadev->config, TRUE); #endif + + sem_init(&pcadev->exclsem, 0, 1); return &pcadev->dev; } diff --git a/drivers/ioexpander/pca9555.h b/drivers/ioexpander/pca9555.h index cb81eb27dd..39435f23d6 100644 --- a/drivers/ioexpander/pca9555.h +++ b/drivers/ioexpander/pca9555.h @@ -46,6 +46,8 @@ #include +#include + #include #include #include @@ -114,15 +116,16 @@ struct pca9555_dev_s { - struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio expander. */ + struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio + * expander. */ #ifdef CONFIG_PCA9555_MULTIPLE - FAR struct pca9555_dev_s *flink; /* Supports a singly linked list of drivers */ + FAR struct pca9555_dev_s *flink; /* Supports a singly linked list of drivers */ #endif - FAR struct pca9555_config_s *config; /* Board configuration data */ - FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ - + FAR struct pca9555_config_s *config; /* Board configuration data */ + FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */ + sem_t exclsem; /* Mutual exclusion */ }; #endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9555 */ -- GitLab From 41164740a51062936ed656ba3be1b7e44389c70b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 13:08:19 -0600 Subject: [PATCH 683/858] Network: Improve half-second conversion --- net/devif/devif_poll.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 32a2eb51ab..38d57e725e 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -430,7 +430,6 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { systime_t now; - systime_t elpased; int bstop = false; int hsec; @@ -441,13 +440,15 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) now = clock_systimer(); hsec = (now - g_polltime) / TICK_PER_HSEC; - /* Update the time only when more than one half second elapses */ + /* Process time-related events only when more than one half second elapses. */ if (hsec > 0) { - /* Save the current time */ + /* Update the current poll time (truncating to the last half second + * boundary to avoid error build-up). + */ - g_polltime = now; + g_polltime += (TICK_PER_HSEC * (systime_t)hsec); /* Perform periodic activitives that depend on hsec > 0 */ -- GitLab From b5024263e93670c937fc1c16d5531524c41654f3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Feb 2016 18:12:19 -0600 Subject: [PATCH 684/858] Networking: Add a trivial cast --- arch | 2 +- net/devif/devif_poll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 757fb2224a..82ecebee6a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 757fb2224ae99916b8b46695a007a6be06f33dfb +Subproject commit 82ecebee6adc0b90660cc3dec4a386719192f3ed diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 38d57e725e..c8263f0d9c 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -438,7 +438,7 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) */ now = clock_systimer(); - hsec = (now - g_polltime) / TICK_PER_HSEC; + hsec = (int)((now - g_polltime) / TICK_PER_HSEC); /* Process time-related events only when more than one half second elapses. */ -- GitLab From 216eea45434998816e2a8b853d67f1c761578186 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 Feb 2016 08:55:10 -0600 Subject: [PATCH 685/858] Net: Fix some errors introduced into the ENC28J60 driver; fix type of wd_start arguments. --- drivers/net/cs89x0.c | 9 ++++++--- drivers/net/dm90x0.c | 9 ++++++--- drivers/net/e1000.c | 9 ++++++--- drivers/net/enc28j60.c | 12 ++++++++---- drivers/net/encx24j600.c | 10 ++++++---- drivers/net/ftmac100.c | 14 +++++++++----- drivers/net/vnet.c | 6 ++++-- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index f27c0a077d..4ccc95ee73 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -305,7 +305,8 @@ static int cs89x0_transmit(struct cs89x0_driver_s *cs89x0) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(cs89x0->cs_txtimeout, CS89x0_TXTIMEOUT, cs89x0_txtimeout, 1, (uint32_t)cs89x0); + (void)wd_start(cs89x0->cs_txtimeout, CS89x0_TXTIMEOUT, cs89x0_txtimeout, + 1, (wdparm_t)cs89x0); return OK; } @@ -793,7 +794,8 @@ static void cs89x0_polltimer(int argc, uint32_t arg, ...) /* Setup the watchdog poll timer again */ - (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, arg); + (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, + (wdparm_t)arg); } /**************************************************************************** @@ -826,7 +828,8 @@ static int cs89x0_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, (uint32_t)cs89x0); + (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, + (wdparm_t)cs89x0); /* Enable the Ethernet interrupt */ diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index 37e49d3bae..aa3efbaf18 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -726,7 +726,8 @@ static int dm9x_transmit(struct dm9x_driver_s *dm9x) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(dm9x->dm_txtimeout, DM6X_TXTIMEOUT, dm9x_txtimeout, 1, (uint32_t)dm9x); + (void)wd_start(dm9x->dm_txtimeout, DM6X_TXTIMEOUT, dm9x_txtimeout, 1, + (wdparm_t)dm9x); return OK; } return -EBUSY; @@ -1270,7 +1271,8 @@ static void dm9x_polltimer(int argc, uint32_t arg, ...) /* Setup the watchdog poll timer again */ - (void)wd_start(dm9x->dm_txpoll, DM6X_WDDELAY, dm9x_polltimer, 1, arg); + (void)wd_start(dm9x->dm_txpoll, DM6X_WDDELAY, dm9x_polltimer, 1, + (wdparm_t)arg); } /**************************************************************************** @@ -1374,7 +1376,8 @@ static int dm9x_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(dm9x->dm_txpoll, DM6X_WDDELAY, dm9x_polltimer, 1, (uint32_t)dm9x); + (void)wd_start(dm9x->dm_txpoll, DM6X_WDDELAY, dm9x_polltimer, 1, + (wdparm_t)dm9x); /* Enable the DM9X interrupt */ diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index cdc8f236e0..cf3b860aca 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -453,7 +453,8 @@ static int e1000_transmit(struct e1000_dev *e1000) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - wd_start(e1000->txtimeout, E1000_TXTIMEOUT, e1000_txtimeout, 1, (uint32_t)e1000); + wd_start(e1000->txtimeout, E1000_TXTIMEOUT, e1000_txtimeout, 1, + (wdparm_t)e1000); return OK; } @@ -773,7 +774,8 @@ static void e1000_polltimer(int argc, uint32_t arg, ...) /* Setup the watchdog poll timer again */ - (void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, arg); + (void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, + (wdparm_t)arg); } /**************************************************************************** @@ -807,7 +809,8 @@ static int e1000_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, (uint32_t)e1000); + (void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, + (wdparm_t)e1000); if (e1000_inl(e1000, E1000_STATUS) & 2) { diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index e1665ea86b..37f94b867f 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1145,7 +1145,8 @@ static int enc_transmit(FAR struct enc_driver_s *priv) * the timer is started? */ - (void)wd_start(priv->txtimeout, ENC_TXTIMEOUT, enc_txtimeout, 1, (uint32_t)priv); + (void)wd_start(priv->txtimeout, ENC_TXTIMEOUT, enc_txtimeout, 1, + (wdparm_t)priv); return OK; } @@ -1284,7 +1285,8 @@ static void enc_txif(FAR struct enc_driver_s *priv) * interrupted. */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, + (wdparm_t)priv); /* Then poll uIP for new XMIT data */ @@ -1999,7 +2001,8 @@ static void enc_pollworker(FAR void *arg) /* Setup the watchdog poll timer again */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, + (wdparm_t)arg); } /**************************************************************************** @@ -2097,7 +2100,8 @@ static int enc_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, (uint32_t)priv); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, + (wdparm_t)priv); /* Mark the interface up and enable the Ethernet interrupt at the * controller diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index baa18cc438..360684fbac 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1057,7 +1057,7 @@ static int enc_transmit(FAR struct enc_driver_s *priv) */ (void)wd_start(priv->txtimeout, ENC_TXTIMEOUT, enc_txtimeout, 1, - (uint32_t)priv); + (wdparm_t)priv); /* free the descriptor */ @@ -1293,7 +1293,8 @@ static void enc_txif(FAR struct enc_driver_s *priv) * interrupted. */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, + (wdparm_t)priv); /* Poll for TX packets from the networking layer */ @@ -2165,7 +2166,7 @@ static void enc_pollworker(FAR void *arg) /* Setup the watchdog poll timer again */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, (wdparm_t)arg); } /**************************************************************************** @@ -2266,7 +2267,8 @@ static int enc_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, (uint32_t)priv); + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, + (wdparm_t)priv); /* Mark the interface up and enable the Ethernet interrupt at the * controller diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 6a9f53ed13..6f40eee1e0 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -321,7 +321,7 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ (void)wd_start(priv->ft_txtimeout, FTMAC100_TXTIMEOUT, - ftmac100_txtimeout_expiry, 1, (uint32_t)priv); + ftmac100_txtimeout_expiry, 1, (wdparm_t)priv); //irqrestore(flags); return OK; @@ -846,7 +846,8 @@ static void ftmac100_txdone(FAR struct ftmac100_driver_s *priv) * certain race conditions where the polling sequence can be interrupted. */ - (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, priv); + (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, + (wdparm_t)priv); /* Then poll uIP for new XMIT data */ @@ -1203,7 +1204,8 @@ static inline void ftmac100_poll_process(FAR struct ftmac100_driver_s *priv) /* Setup the watchdog poll timer again */ - (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, priv); + (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, + (wdparm_t)priv); } /**************************************************************************** @@ -1276,7 +1278,8 @@ static void ftmac100_poll_expiry(int argc, uint32_t arg, ...) * cycle. */ - (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, arg); + (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, + 1, (wdparm_t)arg); } #else @@ -1337,7 +1340,8 @@ static int ftmac100_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, (uint32_t)priv); + (void)wd_start(priv->ft_txpoll, FTMAC100_WDDELAY, ftmac100_poll_expiry, 1, + (wdparm_t)priv); /* Enable the Ethernet interrupt */ diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index e57b654a9d..06df87098b 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -521,7 +521,8 @@ static void vnet_polltimer(int argc, uint32_t arg, ...) /* Setup the watchdog poll timer again */ - (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, arg); + (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, + (wdparm_t)arg); } /**************************************************************************** @@ -553,7 +554,8 @@ static int vnet_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, (uint32_t)vnet); + (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, + (wdparm_t)vnet); vnet->sk_bifup = true; return OK; -- GitLab From e8a39c5effc129bdd4c4280719e32af3ba3a31ee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 Feb 2016 12:17:54 -0600 Subject: [PATCH 686/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 82ecebee6a..e07f315ee5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 82ecebee6adc0b90660cc3dec4a386719192f3ed +Subproject commit e07f315ee55ee760cc5030f09c986329ed189fdc diff --git a/configs b/configs index 3f185b5937..0fa4947076 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3f185b593758ca2ddbdb3f245e0d595ea66934c2 +Subproject commit 0fa4947076e72fe7b1b5d70b9a8edaa60f21859a -- GitLab From 53895b9ddc3e328ae68be1ee5deb38817e8633f1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 Feb 2016 12:27:11 -0600 Subject: [PATCH 687/858] Update submodules --- Documentation | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index 527fb2f925..5acd332e57 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 527fb2f92536a8dad7dee60da49281049dc545bb +Subproject commit 5acd332e570f2454d98bce9dfa873770a3856dd0 diff --git a/configs b/configs index 0fa4947076..ca775f0c4b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0fa4947076e72fe7b1b5d70b9a8edaa60f21859a +Subproject commit ca775f0c4bca6c6b55d866c0d9827979e9990e17 -- GitLab From 0554de6c50257d7fff52136b07667289f7abcd78 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 07:36:07 -0600 Subject: [PATCH 688/858] Networking: Simply devif_timer; Consolidate duplicated devif_poll logic --- configs | 2 +- net/devif/devif_poll.c | 98 +++++++++--------------------------------- 2 files changed, 21 insertions(+), 79 deletions(-) diff --git a/configs b/configs index ca775f0c4b..e18941d4d5 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ca775f0c4bca6c6b55d866c0d9827979e9990e17 +Subproject commit e18941d4d5e4de5b3ce581911a4296a8206830a3 diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index c8263f0d9c..3ec68be4f3 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -269,24 +269,17 @@ static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn = NULL; int bstop = 0; - /* Don't do anything is less a half second has elapsed */ + /* Traverse all of the active TCP connections and perform the poll action. */ - if (hsec > 0) + while (!bstop && (conn = tcp_nextconn(conn))) { - /* Traverse all of the active TCP connections and perform the poll - * action. - */ + /* Perform the TCP timer poll */ - while (!bstop && (conn = tcp_nextconn(conn))) - { - /* Perform the TCP timer poll */ + tcp_timer(dev, conn, hsec); - tcp_timer(dev, conn, hsec); - - /* Call back into the driver */ + /* Call back into the driver */ - bstop = callback(dev); - } + bstop = callback(dev); } return bstop; @@ -430,20 +423,26 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { systime_t now; + systime_t elapsed; int bstop = false; - int hsec; /* Get the elapsed time since the last poll in units of half seconds * (truncating). */ - now = clock_systimer(); - hsec = (int)((now - g_polltime) / TICK_PER_HSEC); + now = clock_systimer(); + elapsed = now - g_polltime; /* Process time-related events only when more than one half second elapses. */ - if (hsec > 0) + if (elapsed >= TICK_PER_HSEC) { + /* Calculate the elpased time in units of half seconds (truncating to + * number of whole half seconds). + */ + + int hsec = (int)(elapsed / TICK_PER_HSEC); + /* Update the current poll time (truncating to the last half second * boundary to avoid error build-up). */ @@ -467,80 +466,23 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) neighbor_periodic(hsec); #endif - } - - /* Traverse all of the active packet connections and perform the poll - * action. - */ - -#ifdef CONFIG_NET_ARP_SEND - /* Check for pending ARP requests */ - - bstop = arp_poll(dev, callback); - if (!bstop) -#endif -#ifdef CONFIG_NET_PKT - { - /* Check for pending packet socket transfer */ - - bstop = devif_poll_pkt_connections(dev, callback); - } - - if (!bstop) -#endif -#ifdef CONFIG_NET_IGMP - { - /* Check for pending IGMP messages */ - - bstop = devif_poll_igmp(dev, callback); - } - if (!bstop) -#endif #ifdef CONFIG_NET_TCP - { /* Traverse all of the active TCP connections and perform the * timer action. - * - * NOTE: devif_poll_tcp_timer will handle the case where hsec <= 0. */ bstop = devif_poll_tcp_timer(dev, callback, hsec); - } - - if (!bstop) -#endif -#ifdef CONFIG_NET_UDP - { - /* Traverse all of the allocated UDP connections and perform - * the timer action. - */ - - bstop = devif_poll_udp_connections(dev, callback); - } - - if (!bstop) #endif -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) - { - /* Traverse all of the tasks waiting to send an ICMP ECHO request. */ - - bstop = devif_poll_icmp(dev, callback); } - if (!bstop) -#endif -#if defined(CONFIG_NET_ICMPv6) && defined(CONFIG_NET_ICMPv6_PING) - { - /* Traverse all of the tasks waiting to send an ICMP ECHO request. */ - - bstop = devif_poll_icmpv6(dev, callback); - } + /* If possible, continue with a normal poll checking for pending + * network driver actions. + */ if (!bstop) -#endif { - /* Nothing to do */ + bstop = devif_poll(dev, callback); } return bstop; -- GitLab From 2dc258986d56c489b80822830a1613a0db248699 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 08:34:03 -0600 Subject: [PATCH 689/858] Add a state variable that provides the current level of OS initialization. This is needed by some logic that may attempt to run early in the start-up sequence, but cannot run if a sufficient level of initializaitn has not not yet occurred --- ChangeLog | 6 +++++- include/nuttx/init.h | 39 ++++++++++++++++++++++++++++++++++++++- sched/init/os_start.c | 33 ++++++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4086e60d2..3264c420e8 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11451,4 +11451,8 @@ We can get better timing accuracy without it (2016-02-03). * drivers/ioexpander/pca555.c: Add logic to make the PCA555 driver thread safe (2016-02-03). - + * sched/init/os_start.c and include/nuttx/init.h: Add a state variable + that provides the current level of OS initialization. This is needed by + some logic that may attempt to run early in the start-up sequence but + cannot run if a sufficient level of initialization has not yet occurred + (2016-02-05). diff --git a/include/nuttx/init.h b/include/nuttx/init.h index 553dc3a4af..fcf4245030 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/init.h * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2011, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,10 +43,40 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#define OSINIT_MM_READY() (g_os_initstate >= OSINIT_MEMORY) +#define OSINIT_HW_READY() (g_os_initstate >= OSINIT_HARDWARE) +#define OSINIT_OS_READY() (g_os_initstate >= OSINIT_OSREADY) +#define OSINIT_OS_INITIALIZING() (g_os_initstate < OSINIT_OSREADY) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Initialization state. OS bring-up occurs in several phases: */ + +enum os_initstate_e +{ + OSINIT_POWERUP = 0, /* 1. Power-up. No initialization yet performed */ + OSINIT_BOOT, /* 2. Basic boot up initialization is complete. OS + * services and hardware resources are not yet + * available. */ + OSINIT_MEMORY, /* 3. The memory manager has been initialized */ + OSINIT_HARDWARE, /* 4. MCU-specific hardware is complete. Hardware + * resources such as timers and device drivers + * are now avaiable. Low-level OS services + * sufficient to support the hardware are + * also avaialable but the OS has not yet + * completed its full initialization. */ + OSINIT_OSREADY /* 5. The OS is fully initialized and multi-tasking + * is active. */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -59,6 +89,13 @@ extern "C" #define EXTERN extern #endif +/* This is the current initialization state. The level of initialization + * is only important early in the start-up sequence when certain OS or + * hardware resources may not yet be available to the kernel logic. + */ + +EXTERN uint8_t g_os_initstate; /* See enum os_initstate_e */ + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 8e5d52cf06..c97b53b034 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/init/os_start.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -72,14 +72,6 @@ #endif #include "init/init.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -215,6 +207,13 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] = #endif }; +/* This is the current initialization state. The level of initialization + * is only important early in the start-up sequence when certain OS or + * hardware resources may not yet be available to the kernel logic. + */ + +uint8_t g_os_initstate; /* See enum os_initstate_e */ + /**************************************************************************** * Private Variables ****************************************************************************/ @@ -264,6 +263,10 @@ void os_start(void) slldbg("Entry\n"); + /* Boot up is complete */ + + g_os_initstate = OSINIT_BOOT; + /* Initialize RTOS Data ***************************************************/ /* Initialize all task lists */ @@ -391,6 +394,10 @@ void os_start(void) } #endif + /* The memory manager is available */ + + g_os_initstate = OSINIT_MEMORY; + #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) /* Initialize tasking data structures */ @@ -497,6 +504,10 @@ void os_start(void) up_initialize(); + /* Hardware resources are available */ + + g_os_initstate = OSINIT_HARDWARE; + #ifdef CONFIG_NET /* Complete initialization the networking system now that interrupts * and timers have been configured by up_initialize(). @@ -542,6 +553,10 @@ void os_start(void) #endif /* Bring Up the System ****************************************************/ + /* The OS is fully initialized and we are beginning multi-tasking */ + + g_os_initstate = OSINIT_OSREADY; + /* Create initial tasks and bring-up the system */ DEBUGVERIFY(os_bringup()); -- GitLab From 8a9fa634bfa0d4b7759ddbf05d1b3b3df42635d4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 08:36:43 -0600 Subject: [PATCH 690/858] syslog: If syslog timestamping is enabled, don't try to get the time if the timer hardware has not yet been initialized. --- ChangeLog | 3 ++ libc/syslog/lib_syslog.c | 82 ++++++++++++---------------------------- 2 files changed, 28 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3264c420e8..521dc32c22 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11456,3 +11456,6 @@ some logic that may attempt to run early in the start-up sequence but cannot run if a sufficient level of initialization has not yet occurred (2016-02-05). + * libc/syslog/lib_syslog.c: If syslog timestamping is enabled, don't try to + get the time if the timer hardware has not yet been initialized + (2016-02-05). diff --git a/libc/syslog/lib_syslog.c b/libc/syslog/lib_syslog.c index ca9ee014fc..f6e35b35b5 100644 --- a/libc/syslog/lib_syslog.c +++ b/libc/syslog/lib_syslog.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/syslog/lib_syslog.c * - * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,43 +42,12 @@ #include #include +#include #include #include #include "syslog/syslog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -104,11 +73,19 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap) #if defined(CONFIG_SYSLOG_TIMESTAMP) struct timespec ts; - int ret; - /* Get the current time */ + /* Get the current time. Since debug output may be generated very early + * in the start-up sequence, hardware timer support may not yet be + * available. + */ - ret = clock_systimespec(&ts); + if (!OSINIT_HW_READY() || clock_systimespec(&ts) < 0) + { + /* Timer hardware is not available, or clock_systimespec failed */ + + ts.tv_sec = 0; + ts.tv_nsec = 0; + } #endif #if defined(CONFIG_SYSLOG) @@ -119,14 +96,11 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap) lib_syslogstream((FAR struct lib_outstream_s *)&stream); #if defined(CONFIG_SYSLOG_TIMESTAMP) - /* Pre-pend the message with the current time */ + /* Pre-pend the message with the current time, if available */ + + (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, + "[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000); - if (ret == OK) - { - (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, - "[%6d.%06d]", - ts.tv_sec, ts.tv_nsec/1000); - } #endif return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); @@ -139,14 +113,10 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap) lib_rawoutstream(&stream, 1); #if defined(CONFIG_SYSLOG_TIMESTAMP) - /* Pre-pend the message with the current time */ + /* Pre-pend the message with the current time, if available */ - if (ret == OK) - { - (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, - "[%6d.%06d]", - ts.tv_sec, ts.tv_nsec/1000); - } + (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, + "[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000); #endif return lib_vsprintf(&stream.public, fmt, ap); @@ -159,20 +129,18 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap) lib_lowoutstream((FAR struct lib_outstream_s *)&stream); #if defined(CONFIG_SYSLOG_TIMESTAMP) - /* Pre-pend the message with the current time */ + /* Pre-pend the message with the current time, if available */ - if (ret == OK) - { - (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, - "[%6d.%06d]", - ts.tv_sec, ts.tv_nsec/1000); - } + (void)lib_sprintf((FAR struct lib_outstream_s *)&stream, + "[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000); #endif return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); #else /* CONFIG_SYSLOG */ + return 0; + #endif /* CONFIG_SYSLOG */ } -- GitLab From 0984104a9a41e799cc347daf559c6fd025b26ec4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 09:25:12 -0600 Subject: [PATCH 691/858] init.h: Trivial clean-up --- include/nuttx/init.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/include/nuttx/init.h b/include/nuttx/init.h index fcf4245030..5c483337f8 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -48,6 +48,9 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Macros for testing which OS services are available at this phase of + * initialization. + */ #define OSINIT_MM_READY() (g_os_initstate >= OSINIT_MEMORY) #define OSINIT_HW_READY() (g_os_initstate >= OSINIT_HARDWARE) @@ -62,19 +65,21 @@ enum os_initstate_e { - OSINIT_POWERUP = 0, /* 1. Power-up. No initialization yet performed */ - OSINIT_BOOT, /* 2. Basic boot up initialization is complete. OS - * services and hardware resources are not yet - * available. */ - OSINIT_MEMORY, /* 3. The memory manager has been initialized */ - OSINIT_HARDWARE, /* 4. MCU-specific hardware is complete. Hardware - * resources such as timers and device drivers - * are now avaiable. Low-level OS services - * sufficient to support the hardware are - * also avaialable but the OS has not yet - * completed its full initialization. */ - OSINIT_OSREADY /* 5. The OS is fully initialized and multi-tasking - * is active. */ + OSINIT_POWERUP = 0, /* Power-up. No initialization yet performed. + * Depends on .bss initialization logic for this + * value. */ + OSINIT_BOOT = 1, /* Basic boot up initialization is complete. OS + * services and hardware resources are not yet + * available. */ + OSINIT_MEMORY = 2, /* The memory manager has been initialized */ + OSINIT_HARDWARE = 3, /* MCU-specific hardware is initialized. Hardware + * resources such as timers and device drivers are + * now avaiable. Low-level OS services sufficient + * to support the hardware are also avaialable but + * the OS has not yet completed its full + * initialization. */ + OSINIT_OSREADY = 4 /* The OS is fully initialized and multi-tasking is + * active. */ }; /**************************************************************************** -- GitLab From 50cf53914c2785999abdfc9f8ef6b2c5c6c1584d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 10:23:39 -0600 Subject: [PATCH 692/858] Update submodule; Improve some comments --- arch | 2 +- include/nuttx/init.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index e07f315ee5..e15b5dec6a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e07f315ee55ee760cc5030f09c986329ed189fdc +Subproject commit e15b5dec6a20cce69ce6bfc18c808b92638a7bd3 diff --git a/include/nuttx/init.h b/include/nuttx/init.h index 5c483337f8..cc1f4f72a9 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -75,7 +75,7 @@ enum os_initstate_e OSINIT_HARDWARE = 3, /* MCU-specific hardware is initialized. Hardware * resources such as timers and device drivers are * now avaiable. Low-level OS services sufficient - * to support the hardware are also avaialable but + * to support the hardware are also available but * the OS has not yet completed its full * initialization. */ OSINIT_OSREADY = 4 /* The OS is fully initialized and multi-tasking is @@ -96,7 +96,7 @@ extern "C" /* This is the current initialization state. The level of initialization * is only important early in the start-up sequence when certain OS or - * hardware resources may not yet be available to the kernel logic. + * hardware resources may not yet be available to the OS-internal logic. */ EXTERN uint8_t g_os_initstate; /* See enum os_initstate_e */ -- GitLab From 12f95c6f6becfc63c607fd9ccb7ce4bbc8b472ae Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 Feb 2016 11:35:30 -0600 Subject: [PATCH 693/858] Add procfs/kmm to show the state of the kernel heap --- ChangeLog | 4 + TODO | 28 +--- fs/procfs/Kconfig | 5 + fs/procfs/Make.defs | 4 +- fs/procfs/fs_procfs.c | 7 +- fs/procfs/fs_procfskmm.c | 326 +++++++++++++++++++++++++++++++++++++++ include/nuttx/mm/mm.h | 2 +- 7 files changed, 347 insertions(+), 29 deletions(-) create mode 100644 fs/procfs/fs_procfskmm.c diff --git a/ChangeLog b/ChangeLog index 521dc32c22..462393b89d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11459,3 +11459,7 @@ * libc/syslog/lib_syslog.c: If syslog timestamping is enabled, don't try to get the time if the timer hardware has not yet been initialized (2016-02-05). + * fs/procfs/fs_procfskmm.c: Add /proc/kmm entry that shows that state of + the kernel heap. Only useful in PROTECTED and KERNEL build modes where + there is a kernel heap (2016-02-06). + diff --git a/TODO b/TODO index e4b9dfd569..a84666321a 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated February 2, 2016) +NuttX TODO List (Last updated February 6, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -14,8 +14,8 @@ nuttx/ (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) - (7) Kernel/Protected Build - (4) C++ Support + (6) Kernel/Protected Build + (3) C++ Support (6) Binary loaders (binfmt/) (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) @@ -463,14 +463,6 @@ o Kernel/Protected Build Priority: Medium/High -- the kernel build configuration is not fully fielded yet. - Title: NSH free COMMAND LIMITATION - Description: The NSH 'free' command only shows memory usage in the user - heap only, not usage in the kernel heap. I am thinking that - kernel heap memory usage should be available in /proc/memory. - Better /proc/kmm - Status: Open - Priority: Medium/High - Title: NxTERM PARTITIONING. Description: NxTerm is implemented (correctly) as a driver that resides in the nuttx/ directory. However, the user interfaces must be @@ -590,20 +582,6 @@ o C++ Support would be to get a hold of the compilers definition of size_t. Priority: Low. - Title: STATIC CONSTRUCTORS - Description: Need to call static constructors - Update: Static constructors are implemented for the STM32 F4 and - this will provide the model for all solutions. Basically, if - CONFIG_HAVE_CXXINITIALIZE=y is defined in the configuration, then - board-specific code must provide the interface up_cxxinitialize(). - up_cxxinitialize() is called from application logic to initialize - all static class instances. This TODO item probably has to stay - open because this solution is only available on STM32 F4. - Status: Open - Priority: Low, depends on toolchain. Call to gcc's built-in static - constructor logic will probably have to be performed by - user logic in the application. - Title: STATIC CONSTRUCTORS AND MULTITASKING Description: The logic that calls static constructors operates on the main thread of the initial user application task. Any static diff --git a/fs/procfs/Kconfig b/fs/procfs/Kconfig index 7f3620f9c8..b218c405b9 100644 --- a/fs/procfs/Kconfig +++ b/fs/procfs/Kconfig @@ -48,6 +48,11 @@ config FS_PROCFS_EXCLUDE_CPULOAD default n depends on SCHED_CPULOAD +config FS_PROCFS_EXCLUDE_KMM + bool "Exclude kmm" + default n + depends on MM_KERNEL_HEAP + config FS_PROCFS_EXCLUDE_MOUNTS bool "Exclude mounts" default n diff --git a/fs/procfs/Make.defs b/fs/procfs/Make.defs index 63cd07eb91..434e85799e 100644 --- a/fs/procfs/Make.defs +++ b/fs/procfs/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # fs/procfs/Make.defs # -# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ ifeq ($(CONFIG_FS_PROCFS),y) ASRCS += CSRCS += fs_procfs.c fs_procfsutil.c fs_procfsproc.c fs_procfsuptime.c -CSRCS += fs_procfscpuload.c +CSRCS += fs_procfscpuload.c fs_procfskmm.c # Include procfs build support diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 8da8842fb4..7f86a17a8d 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/procfs/fs_procfs.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -77,6 +77,7 @@ extern const struct procfs_operations proc_operations; extern const struct procfs_operations cpuload_operations; +extern const struct procfs_operations kmm_operations; extern const struct procfs_operations module_operations; extern const struct procfs_operations uptime_operations; @@ -120,6 +121,10 @@ static const struct procfs_entry_s g_procfs_entries[] = { "cpuload", &cpuload_operations }, #endif +#if defined(CONFIG_MM_KERNEL_HEAP) && !defined(CONFIG_FS_PROCFS_EXCLUDE_KMM) + { "kmm", &kmm_operations }, +#endif + #if defined(CONFIG_MODULE) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) { "modules", &module_operations }, #endif diff --git a/fs/procfs/fs_procfskmm.c b/fs/procfs/fs_procfskmm.c new file mode 100644 index 0000000000..edfe3933e8 --- /dev/null +++ b/fs/procfs/fs_procfskmm.c @@ -0,0 +1,326 @@ +/**************************************************************************** + * fs/procfs/fs_procfskmm.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_FS_PROCFS) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_KMM) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Determines the size of an intermediate buffer that must be large enough + * to handle the longest line generated by this logic. + */ + +#define KMM_LINELEN 54 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure describes one open "file" */ + +struct kmm_file_s +{ + struct procfs_file_s base; /* Base open file structure */ + unsigned int linesize; /* Number of valid characters in line[] */ + char line[KMM_LINELEN]; /* Pre-allocated buffer for formatted lines */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* File system methods */ + +static int kmm_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode); +static int kmm_close(FAR struct file *filep); +static ssize_t kmm_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static int kmm_dup(FAR const struct file *oldp, + FAR struct file *newp); +static int kmm_stat(FAR const char *relpath, FAR struct stat *buf); + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* See fs_mount.c -- this structure is explicitly externed there. + * We use the old-fashioned kind of initializers so that this will compile + * with any compiler. + */ + +const struct procfs_operations kmm_operations = +{ + kmm_open, /* open */ + kmm_close, /* close */ + kmm_read, /* read */ + NULL, /* write */ + kmm_dup, /* dup */ + NULL, /* opendir */ + NULL, /* closedir */ + NULL, /* readdir */ + NULL, /* rewinddir */ + kmm_stat /* stat */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_open + ****************************************************************************/ + +static int kmm_open(FAR struct file *filep, FAR const char *relpath, + int oflags, mode_t mode) +{ + FAR struct kmm_file_s *procfile; + + fvdbg("Open '%s'\n", relpath); + + /* PROCFS is read-only. Any attempt to open with any kind of write + * access is not permitted. + * + * REVISIT: Write-able proc files could be quite useful. + */ + + if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + { + fdbg("ERROR: Only O_RDONLY supported\n"); + return -EACCES; + } + + /* "kmm" is the only acceptable value for the relpath */ + + if (strcmp(relpath, "kmm") != 0) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* Allocate a container to hold the file attributes */ + + procfile = (FAR struct kmm_file_s *)kmm_zalloc(sizeof(struct kmm_file_s)); + if (!procfile) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* Save the attributes as the open-specific state in filep->f_priv */ + + filep->f_priv = (FAR void *)procfile; + return OK; +} + +/**************************************************************************** + * Name: kmm_close + ****************************************************************************/ + +static int kmm_close(FAR struct file *filep) +{ + FAR struct kmm_file_s *procfile; + + /* Recover our private data from the struct file instance */ + + procfile = (FAR struct kmm_file_s *)filep->f_priv; + DEBUGASSERT(procfile); + + /* Release the file attributes structure */ + + kmm_free(procfile); + filep->f_priv = NULL; + return OK; +} + +/**************************************************************************** + * Name: kmm_read + ****************************************************************************/ + +static ssize_t kmm_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + FAR struct kmm_file_s *procfile; + struct mallinfo mem; + size_t linesize; + size_t copysize; + size_t totalsize; + off_t offset; + + fvdbg("buffer=%p buflen=%d\n", buffer, (int)buflen); + + DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0); + offset = filep->f_pos; + + /* Recover our private data from the struct file instance */ + + procfile = (FAR struct kmm_file_s *)filep->f_priv; + DEBUGASSERT(procfile); + + /* The first line is the headers */ + + linesize = snprintf(procfile->line, KMM_LINELEN, + " total used free largest\n"); + copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen, + &offset); + totalsize = copysize; + + if (totalsize < buflen) + { + buffer += copysize; + buflen -= copysize; + + /* The second line is the memory data */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mem = kmm_mallinfo(); +#else + (void)kmm_mallinfo(&mem); +#endif + + linesize = snprintf(procfile->line, KMM_LINELEN, + "Mem: %11d%11d%11d%11d\n", + mem.arena, mem.uordblks, mem.fordblks, + mem.mxordblk); + copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen, + &offset); + totalsize += copysize; + } + + /* Update the file offset */ + + filep->f_pos += totalsize; + return totalsize; +} + +/**************************************************************************** + * Name: kmm_dup + * + * Description: + * Duplicate open file data in the new file structure. + * + ****************************************************************************/ + +static int kmm_dup(FAR const struct file *oldp, FAR struct file *newp) +{ + FAR struct kmm_file_s *oldattr; + FAR struct kmm_file_s *newattr; + + fvdbg("Dup %p->%p\n", oldp, newp); + + /* Recover our private data from the old struct file instance */ + + oldattr = (FAR struct kmm_file_s *)oldp->f_priv; + DEBUGASSERT(oldattr); + + /* Allocate a new container to hold the task and attribute selection */ + + newattr = (FAR struct kmm_file_s *)kmm_malloc(sizeof(struct kmm_file_s)); + if (!newattr) + { + fdbg("ERROR: Failed to allocate file attributes\n"); + return -ENOMEM; + } + + /* The copy the file attributes from the old attributes to the new */ + + memcpy(newattr, oldattr, sizeof(struct kmm_file_s)); + + /* Save the new attributes in the new file structure */ + + newp->f_priv = (FAR void *)newattr; + return OK; +} + +/**************************************************************************** + * Name: kmm_stat + * + * Description: Return information about a file or directory + * + ****************************************************************************/ + +static int kmm_stat(FAR const char *relpath, FAR struct stat *buf) +{ + /* "kmm" is the only acceptable value for the relpath */ + + if (strcmp(relpath, "kmm") != 0) + { + fdbg("ERROR: relpath is '%s'\n", relpath); + return -ENOENT; + } + + /* "kmm" is the name for a read-only file */ + + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; + buf->st_size = 0; + buf->st_blksize = 0; + buf->st_blocks = 0; + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_MM_KERNEL_HEAP && CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_KMM */ diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index a18f12c6fa..7d2e102f31 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -491,8 +491,8 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info); struct mallinfo kmm_mallinfo(void); #else int kmm_mallinfo(struct mallinfo *info); -#endif #endif /* CONFIG_CAN_PASS_STRUCTS */ +#endif /* CONFIG_MM_KERNEL_HEAP */ /* Functions contained in mm_shrinkchunk.c **********************************/ -- GitLab From 74db48202eb879a0aec564a48129a1db28416c1a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 Feb 2016 17:44:41 -0600 Subject: [PATCH 694/858] sched/: Replace explict references to g_readytorun with indirect references via the this_task() macro --- ChangeLog | 4 ++++ TODO | 8 ++------ arch | 2 +- sched/environ/env_clearenv.c | 2 +- sched/environ/env_dup.c | 2 +- sched/environ/env_getenv.c | 2 +- sched/environ/env_getenvironptr.c | 2 +- sched/environ/env_setenv.c | 2 +- sched/environ/env_unsetenv.c | 2 +- sched/errno/errno_getptr.c | 4 ++-- sched/group/group_addrenv.c | 2 +- sched/group/group_free.c | 2 +- sched/group/group_join.c | 2 +- sched/group/group_malloc.c | 2 +- sched/group/group_setuptaskfiles.c | 4 ++-- sched/mqueue/mq_notify.c | 8 ++++---- sched/mqueue/mq_rcvinternal.c | 2 +- sched/mqueue/mq_sndinternal.c | 2 +- sched/mqueue/mq_timedreceive.c | 2 +- sched/mqueue/mq_timedsend.c | 2 +- sched/paging/pg_miss.c | 2 +- sched/paging/pg_worker.c | 4 ++-- sched/pthread/pthread_cancel.c | 28 ++------------------------ sched/pthread/pthread_condtimedwait.c | 2 +- sched/pthread/pthread_create.c | 5 ++--- sched/pthread/pthread_detach.c | 2 +- sched/pthread/pthread_exit.c | 2 +- sched/pthread/pthread_getspecific.c | 2 +- sched/pthread/pthread_join.c | 2 +- sched/pthread/pthread_keycreate.c | 2 +- sched/pthread/pthread_kill.c | 2 +- sched/pthread/pthread_setcancelstate.c | 2 +- sched/pthread/pthread_setspecific.c | 2 +- sched/sched/sched.h | 8 ++++++++ sched/sched/sched_addreadytorun.c | 2 +- sched/sched/sched_cpuload.c | 2 +- sched/sched/sched_getfiles.c | 2 +- sched/sched/sched_getparam.c | 2 +- sched/sched/sched_getscheduler.c | 2 +- sched/sched/sched_getsockets.c | 6 +----- sched/sched/sched_getstreams.c | 6 +----- sched/sched/sched_lock.c | 26 +----------------------- sched/sched/sched_lockcount.c | 27 +------------------------ sched/sched/sched_mergepending.c | 22 +------------------- sched/sched/sched_processtimer.c | 14 +------------ sched/sched/sched_rrgetinterval.c | 2 +- sched/sched/sched_self.c | 24 +--------------------- sched/sched/sched_setparam.c | 2 +- sched/sched/sched_setpriority.c | 2 +- sched/sched/sched_timerexpiration.c | 6 +++--- sched/sched/sched_unlock.c | 6 +++--- sched/sched/sched_waitid.c | 2 +- sched/sched/sched_waitpid.c | 2 +- sched/sched/sched_yield.c | 26 +----------------------- sched/semaphore/sem_holder.c | 12 +++++------ sched/semaphore/sem_tickwait.c | 2 +- sched/semaphore/sem_timedwait.c | 2 +- sched/semaphore/sem_trywait.c | 22 +------------------- sched/semaphore/sem_wait.c | 2 +- sched/signal/sig_action.c | 14 +------------ sched/signal/sig_kill.c | 2 +- sched/signal/sig_mqnotempty.c | 22 +------------------- sched/signal/sig_pending.c | 22 +------------------- sched/signal/sig_procmask.c | 22 +------------------- sched/signal/sig_queue.c | 22 +------------------- sched/signal/sig_suspend.c | 22 +------------------- sched/signal/sig_timedwait.c | 14 +------------ sched/signal/sig_unmaskpendingsignal.c | 22 +------------------- sched/task/exit.c | 26 +----------------------- sched/task/task_atexit.c | 28 ++------------------------ sched/task/task_delete.c | 26 +----------------------- sched/task/task_exit.c | 28 ++------------------------ sched/task/task_getpid.c | 22 +------------------- sched/task/task_onexit.c | 28 ++------------------------ sched/task/task_prctl.c | 6 +----- sched/task/task_restart.c | 26 +----------------------- sched/task/task_setup.c | 14 +++---------- sched/task/task_start.c | 2 +- sched/task/task_vfork.c | 6 +++--- 79 files changed, 114 insertions(+), 606 deletions(-) diff --git a/ChangeLog b/ChangeLog index 462393b89d..f9b22e44a4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11462,4 +11462,8 @@ * fs/procfs/fs_procfskmm.c: Add /proc/kmm entry that shows that state of the kernel heap. Only useful in PROTECTED and KERNEL build modes where there is a kernel heap (2016-02-06). + * sched/ and arch/: Replace explicit access to the OS internal data structure + g_readytorun() with the wrapper this_task() which hides the implementation + and will permit such things as more scalable representations of task queues + and SMP (2016-02-06). diff --git a/TODO b/TODO index a84666321a..7710e0bc1c 100644 --- a/TODO +++ b/TODO @@ -228,13 +228,9 @@ o Task/Scheduler (sched/) hidden behind simple accessor functions and so the internal data structures can be changed if need with very little impact. - The only area are the list structure is not well contained is - in the sequence of code that finds the current running task: - FAR struct tcb_s *rtcb = (FAT struc tcb_s *)g_readytorun.head; - - That needs to be hidden behind a macro (it would also be a problem - for any SMP implementation). + Explicity refereence to the list strucutre are hidden behnid + the macro this_task(). Status: Open Priority: Low. Things are just the way that we want them for the way diff --git a/arch b/arch index e15b5dec6a..5c9c3dc73e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e15b5dec6a20cce69ce6bfc18c808b92638a7bd3 +Subproject commit 5c9c3dc73e2ae5e87203801c6ab82e44a3f8fbec diff --git a/sched/environ/env_clearenv.c b/sched/environ/env_clearenv.c index acfb6b2f46..4085fd20da 100644 --- a/sched/environ/env_clearenv.c +++ b/sched/environ/env_clearenv.c @@ -74,7 +74,7 @@ int clearenv(void) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb->group); env_release(tcb->group); diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 542774f892..ffb68e2eaa 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -81,7 +81,7 @@ int env_dup(FAR struct task_group_s *group) { - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); FAR char *envp = NULL; size_t envlen; int ret = OK; diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c index ae1408d045..0c28e6d970 100644 --- a/sched/environ/env_getenv.c +++ b/sched/environ/env_getenv.c @@ -94,7 +94,7 @@ FAR char *getenv(const char *name) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); group = rtcb->group; /* Check if the variable exists */ diff --git a/sched/environ/env_getenvironptr.c b/sched/environ/env_getenvironptr.c index 447fff2b89..b54c41a0e5 100644 --- a/sched/environ/env_getenvironptr.c +++ b/sched/environ/env_getenvironptr.c @@ -85,7 +85,7 @@ FAR char **get_environ_ptr(void) /* Return a reference to the thread-private environ in the TCB. */ - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); if (ptcb->envp) { return &ptcb->envp->ev_env; diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index 250a14c365..8f5b38b1ac 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -124,7 +124,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB. */ sched_lock(); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index 39a87265d9..ac96e49c1b 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -77,7 +77,7 @@ int unsetenv(FAR const char *name) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR char *pvar; FAR char *newenvp; diff --git a/sched/errno/errno_getptr.c b/sched/errno/errno_getptr.c index c24bed5a49..4e47895a0b 100644 --- a/sched/errno/errno_getptr.c +++ b/sched/errno/errno_getptr.c @@ -97,11 +97,11 @@ FAR int *get_errno_ptr(void) * logic (see, for example, task_exit.c). * * There is also a corner case early in the initialization sequence: - * The ready to run list may not yet be initialized and g_readytorun.head + * The ready to run list may not yet be initialized and this_task() * may be NULL. */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (rtcb && rtcb->task_state == TSTATE_TASK_RUNNING) { /* Yes.. the task is running normally. Return a reference to the diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index da25bdacdc..fcdd1a3e0c 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -114,7 +114,7 @@ int group_addrenv(FAR struct tcb_s *tcb) if (!tcb) { - tcb = (FAR struct tcb_s *)g_readytorun.head; + tcb = this_task(); } DEBUGASSERT(tcb && tcb->group); diff --git a/sched/group/group_free.c b/sched/group/group_free.c index c7b0342adb..3692b4495f 100644 --- a/sched/group/group_free.c +++ b/sched/group/group_free.c @@ -69,7 +69,7 @@ void group_free(FAR struct task_group_s *group, FAR void *mem) if (!group) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb && tcb->group); group = tcb->group; } diff --git a/sched/group/group_join.c b/sched/group/group_join.c index 0e16f317a7..eab5bdbcc7 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -172,7 +172,7 @@ static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) int group_bind(FAR struct pthread_tcb_s *tcb) { - FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ptcb = this_task(); DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->cmn.group); diff --git a/sched/group/group_malloc.c b/sched/group/group_malloc.c index f47a6f74aa..b8ed5c487e 100644 --- a/sched/group/group_malloc.c +++ b/sched/group/group_malloc.c @@ -92,7 +92,7 @@ FAR void *group_malloc(FAR struct task_group_s *group, size_t nbytes) if (!group) { - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb && tcb->group); group = tcb->group; } diff --git a/sched/group/group_setuptaskfiles.c b/sched/group/group_setuptaskfiles.c index c9b08cc934..e106871250 100644 --- a/sched/group/group_setuptaskfiles.c +++ b/sched/group/group_setuptaskfiles.c @@ -89,7 +89,7 @@ static inline void sched_dupfiles(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct file *parent; FAR struct file *child; int i; @@ -147,7 +147,7 @@ static inline void sched_dupsockets(FAR struct task_tcb_s *tcb) { /* The parent task is the one at the head of the ready-to-run list */ - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct socket *parent; FAR struct socket *child; int i; diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index cb7a3aaffc..eff00d1083 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -127,10 +127,10 @@ * ****************************************************************************/ -int mq_notify(mqd_t mqdes, const struct sigevent *notification) +int mq_notify(mqd_t mqdes, FAR const struct sigevent *notification) { - struct tcb_s *rtcb; - struct mqueue_inode_s *msgq; + FAR struct tcb_s *rtcb; + FAR struct mqueue_inode_s *msgq; int errval; /* Was a valid message queue descriptor provided? */ @@ -150,7 +150,7 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification) /* Get the current process ID */ - rtcb = (struct tcb_s *)g_readytorun.head; + rtcb = this_task(); /* Is there already a notification attached */ diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index bcc7059b86..7c019e7d38 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -176,7 +176,7 @@ FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes) { /* Yes.. Block and try again */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); rtcb->msgwaitq = msgq; msgq->nwaitnotempty++; diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index b6580d25bb..0aaa61dad5 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -280,7 +280,7 @@ int mq_waitsend(mqd_t mqdes) * When we are unblocked, we will try again */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); rtcb->msgwaitq = msgq; msgq->nwaitnotfull++; diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index 858bf60e96..1e3d50d163 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -182,7 +182,7 @@ static void mq_rcvtimeout(int argc, wdparm_t pid) ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_msg_s *mqmsg; irqstate_t saved_state; int ret = ERROR; diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 03fa03265e..90045436eb 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -183,7 +183,7 @@ static void mq_sndtimeout(int argc, wdparm_t pid) int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *mqmsg = NULL; irqstate_t saved_state; diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index d41821bc4f..945678f99a 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -121,7 +121,7 @@ void pg_miss(void) { - FAR struct tcb_s *ftcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *ftcb = this_task(); FAR struct tcb_s *wtcb; /* Sanity checking diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index a50f917d09..701076901a 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -279,7 +279,7 @@ static inline bool pg_dequeue(void) * if a new higher priority fill is required). */ - FAR struct tcb_s *wtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *wtcb = this_task(); if (wtcb->sched_priority > CONFIG_PAGING_DEFPRIO && wtcb->sched_priority > g_pftcb->sched_priority) { @@ -456,7 +456,7 @@ static inline bool pg_startfill(void) static inline void pg_alldone(void) { - FAR struct tcb_s *wtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *wtcb = this_task(); g_pftcb = NULL; pgllvdbg("New worker priority. %d->%d\n", wtcb->sched_priority, CONFIG_PAGING_DEFPRIO); diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 8892dc6a43..a8ba2ee4c9 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -47,37 +47,13 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ int pthread_cancel(pthread_t thread) { - struct tcb_s *tcb; + FAR struct tcb_s *tcb; /* First, make sure that the handle references a valid thread */ @@ -132,7 +108,7 @@ int pthread_cancel(pthread_t thread) * same as pthread_exit(PTHREAD_CANCELED). */ - if (tcb == (struct tcb_s *)g_readytorun.head) + if (tcb == this_task()) { pthread_exit(PTHREAD_CANCELED); } diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 9a02ef912a..9fb2673a5b 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -182,7 +182,7 @@ static void pthread_condtimedout(int argc, uint32_t pid, uint32_t signo) int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int ticks; int mypid = (int)getpid(); irqstate_t int_state; diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 41c2a85799..3354067c31 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -165,7 +165,7 @@ static inline void pthread_addjoininfo(FAR struct task_group_s *group, static void pthread_start(void) { - FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = ptcb->cmn.group; FAR struct join_s *pjoin = (FAR struct join_s *)ptcb->joininfo; pthread_addr_t exit_status; @@ -269,8 +269,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, #ifdef CONFIG_ARCH_ADDRENV /* Share the address environment of the parent task group. */ - ret = up_addrenv_attach(ptcb->cmn.group, - (FAR struct tcb_s *)g_readytorun.head); + ret = up_addrenv_attach(ptcb->cmn.group, this_task()); if (ret < 0) { errcode = -ret; diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 587502cd66..7d8c829221 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -97,7 +97,7 @@ int pthread_detach(pthread_t thread) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR struct join_s *pjoin; int ret; diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 1fda5c2755..a384fbedf3 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -95,7 +95,7 @@ void pthread_exit(FAR void *exit_value) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); int status; sdbg("exit_value=%p\n", exit_value); diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index 8a470455f0..e535600e0e 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -104,7 +104,7 @@ FAR void *pthread_getspecific(pthread_key_t key) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = rtcb->cmn.group; FAR void *ret = NULL; diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index 003f06ccef..7dbffe68ac 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -102,7 +102,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; FAR struct join_s *pjoin; int ret; diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c index 03d8486b48..3589dd61c8 100644 --- a/sched/pthread/pthread_keycreate.c +++ b/sched/pthread/pthread_keycreate.c @@ -112,7 +112,7 @@ int pthread_key_create(FAR pthread_key_t *key, CODE void (*destructor)(FAR void *)) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; int ret = EAGAIN; diff --git a/sched/pthread/pthread_kill.c b/sched/pthread/pthread_kill.c index 870cb15a41..a53842308a 100644 --- a/sched/pthread/pthread_kill.c +++ b/sched/pthread/pthread_kill.c @@ -94,7 +94,7 @@ int pthread_kill(pthread_t thread, int signo) */ #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif FAR struct tcb_s *stcb; siginfo_t info; diff --git a/sched/pthread/pthread_setcancelstate.c b/sched/pthread/pthread_setcancelstate.c index 4d4ba360f9..d05e9c6acd 100644 --- a/sched/pthread/pthread_setcancelstate.c +++ b/sched/pthread/pthread_setcancelstate.c @@ -75,7 +75,7 @@ int pthread_setcancelstate(int state, FAR int *oldstate) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); int ret = OK; /* Suppress context changes for a bit so that the flags are stable. (the diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c index a91dc5e137..f78141c539 100644 --- a/sched/pthread/pthread_setspecific.c +++ b/sched/pthread/pthread_setspecific.c @@ -115,7 +115,7 @@ int pthread_setspecific(pthread_key_t key, FAR const void *value) { #if CONFIG_NPTHREAD_KEYS > 0 - FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)g_readytorun.head; + FAR struct pthread_tcb_s *rtcb = (FAR struct pthread_tcb_s *)this_task(); FAR struct task_group_s *group = rtcb->cmn.group; int ret = EINVAL; diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 2924e5bef7..772711cc42 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -64,6 +64,14 @@ #define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) #define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) +/* These are macros to access the current CPU and the current task on a CPU. + * These macros are intended to support a future SMP implementation. + */ + +#define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) +#define this_cpu() (0) +#define this_task() (current_task(this_cpu)) + /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2ebfcc49fe..25f9e00e6c 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -100,7 +100,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); bool ret; /* Check if pre-emption is disabled for the current running task and if diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index 2cbef4c739..2c3d629c19 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -111,7 +111,7 @@ volatile uint32_t g_cpuload_total; void weak_function sched_process_cpuload(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int hash_index; int i; diff --git a/sched/sched/sched_getfiles.c b/sched/sched/sched_getfiles.c index f0608a465d..7e634053d9 100644 --- a/sched/sched/sched_getfiles.c +++ b/sched/sched/sched_getfiles.c @@ -69,7 +69,7 @@ FAR struct filelist *sched_getfiles(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; /* The group may be NULL under certain conditions. For example, if diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 44f9e885fa..0ab047f984 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -110,7 +110,7 @@ int sched_getparam (pid_t pid, FAR struct sched_param *param) /* Check if the task to restart is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if ((pid == 0) || (pid == rtcb->pid)) { /* Return the priority if the calling task. */ diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index dfbb0e2818..a1afddf28e 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -107,7 +107,7 @@ int sched_getscheduler(pid_t pid) if (!pid) { - tcb = (struct tcb_s *)g_readytorun.head; + tcb = this_task(); } else { diff --git a/sched/sched/sched_getsockets.c b/sched/sched/sched_getsockets.c index b292cd38ed..2601f90783 100644 --- a/sched/sched/sched_getsockets.c +++ b/sched/sched/sched_getsockets.c @@ -44,10 +44,6 @@ #if CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,7 +66,7 @@ FAR struct socketlist *sched_getsockets(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_getstreams.c b/sched/sched/sched_getstreams.c index 29f3074b7a..91f3c9f6f3 100644 --- a/sched/sched/sched_getstreams.c +++ b/sched/sched/sched_getstreams.c @@ -41,10 +41,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -69,7 +65,7 @@ FAR struct streamlist *sched_getstreams(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; DEBUGASSERT(group); diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index b01134d5c7..3f5020789c 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -45,30 +45,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,7 +69,7 @@ int sched_lock(void) { - struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_lock() should have no diff --git a/sched/sched/sched_lockcount.c b/sched/sched/sched_lockcount.c index b7f7730a73..c3a8ef1903 100644 --- a/sched/sched/sched_lockcount.c +++ b/sched/sched/sched_lockcount.c @@ -43,30 +43,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -91,7 +67,6 @@ int sched_lockcount(void) { - struct tcb_s *rtcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); return (int)rtcb->lockcount; } - diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index b5028e2008..c62bb70b55 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -46,26 +46,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,7 +82,7 @@ bool sched_mergepending(void) /* Initialize the inner search loop */ - rtrtcb = (FAR struct tcb_s *)g_readytorun.head; + rtrtcb = this_task(); /* Process every TCB in the g_pendingtasks list */ diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index 4a7b246434..33c3f583ac 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -58,18 +58,6 @@ # define CONFIG_SCHED_CPULOAD_TIMECONSTANT 2 #endif -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -92,7 +80,7 @@ #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline void sched_process_scheduler(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #if CONFIG_RR_INTERVAL > 0 /* Check if the currently executing task uses round robin scheduling. */ diff --git a/sched/sched/sched_rrgetinterval.c b/sched/sched/sched_rrgetinterval.c index 5347f64166..3faefb44d2 100644 --- a/sched/sched/sched_rrgetinterval.c +++ b/sched/sched/sched_rrgetinterval.c @@ -91,7 +91,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) if (!pid) { - rrtcb = (FAR struct tcb_s *)g_readytorun.head; + rrtcb = this_task(); } /* Return a special error code on invalid PID */ diff --git a/sched/sched/sched_self.c b/sched/sched/sched_self.c index 6302aa2208..97ba42d604 100644 --- a/sched/sched/sched_self.c +++ b/sched/sched/sched_self.c @@ -41,26 +41,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +57,5 @@ FAR struct tcb_s *sched_self(void) { - return (FAR struct tcb_s *)g_readytorun.head; + return this_task(); } - - diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index cadda71bd3..2af8d82405 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -106,7 +106,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param) /* Check if the task to reprioritize is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (pid == 0 || pid == rtcb->pid) { tcb = rtcb; diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index abb660cb3c..3089756eec 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -103,7 +103,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); tstate_t task_state; irqstate_t saved_state; diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 41b12c4022..0c329e23cc 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -164,8 +164,8 @@ static struct timespec g_stop_time; #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; - FAR struct tcb_s *ntcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); + FAR struct tcb_s *ntcb = this_task(); uint32_t ret = 0; #if CONFIG_RR_INTERVAL > 0 @@ -212,7 +212,7 @@ static inline uint32_t sched_process_scheduler(uint32_t ticks, bool noswitches) * the new task at the head of the ready to run list. */ - ntcb = (FAR struct tcb_s *)g_readytorun.head; + ntcb = this_task(); /* Check if the new task at the head of the ready-to-run has changed. */ diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 8c18aac6f1..15a5e9adb4 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -63,7 +63,7 @@ int sched_unlock(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_unlock() should have no @@ -118,7 +118,7 @@ int sched_unlock(void) * maximum. */ - if (rtcb != (FAR struct tcb_s *)g_readytorun.head) + if (rtcb != this_task()) { rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } @@ -156,7 +156,7 @@ int sched_unlock(void) * change the currently active task. */ - if (rtcb == (FAR struct tcb_s *)g_readytorun.head) + if (rtcb == this_task()) { sched_timer_reassess(); } diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 8c24744945..c6fd8d4501 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -154,7 +154,7 @@ static void exited_child(FAR struct tcb_s *rtcb, FAR struct child_status_s *chil int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *ctcb; #ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 84e197a288..4a669958c7 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -294,7 +294,7 @@ errout: #else pid_t waitpid(pid_t pid, int *stat_loc, int options) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *ctcb; #ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; diff --git a/sched/sched/sched_yield.c b/sched/sched/sched_yield.c index 17d3bb0bbf..c55a925dac 100644 --- a/sched/sched/sched_yield.c +++ b/sched/sched/sched_yield.c @@ -43,30 +43,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,7 +66,7 @@ int sched_yield(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* This equivalent to just resetting the task priority to its current value * since this will cause the task to be rescheduled behind any other tasks diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 3b5b2b7286..854747cb01 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -565,7 +565,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (pholder->htcb != rtcb) { return sem_restoreholderprio(pholder, sem, arg); @@ -585,7 +585,7 @@ static int sem_restoreholderprioA(FAR struct semholder_s *pholder, static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (pholder->htcb == rtcb) { (void)sem_restoreholderprio(pholder, sem, arg); @@ -691,7 +691,7 @@ static inline void sem_restorebaseprio_irq(FAR struct tcb_s *stcb, static inline void sem_restorebaseprio_task(FAR struct tcb_s *stcb, FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Perform the following actions only if a new thread was given a count. @@ -850,7 +850,7 @@ void sem_destroyholder(FAR sem_t *sem) void sem_addholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Find or allocate a container for this new holder */ @@ -885,7 +885,7 @@ void sem_addholder(FAR sem_t *sem) void sem_boostpriority(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); /* Boost the priority of every thread holding counts on this semaphore * that are lower in priority than the new thread that is waiting for a @@ -914,7 +914,7 @@ void sem_boostpriority(FAR sem_t *sem) void sem_releaseholder(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR struct semholder_s *pholder; /* Find the container for this holder */ diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 804e1ed83c..66d4f446d7 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -82,7 +82,7 @@ int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; systime_t elapsed; int ret; diff --git a/sched/semaphore/sem_timedwait.c b/sched/semaphore/sem_timedwait.c index 106a8bc404..e5722d401b 100644 --- a/sched/semaphore/sem_timedwait.c +++ b/sched/semaphore/sem_timedwait.c @@ -94,7 +94,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; int ticks; int errcode; diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index 75c92dd7b5..e6d8830519 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,7 +76,7 @@ int sem_trywait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t saved_state; int ret = ERROR; diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index b7d5378295..7e88140b72 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -76,7 +76,7 @@ int sem_wait(FAR sem_t *sem) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); irqstate_t saved_state; int ret = ERROR; diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 99b8aa51e8..8c88f55e12 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -58,18 +58,6 @@ (t)->sa_mask = (f)->sa_mask; \ (t)->sa_flags = (f)->sa_flags; } -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -165,7 +153,7 @@ static FAR sigactq_t *sig_allocateaction(void) int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction *oact) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); FAR sigactq_t *sigact; /* Since sigactions can only be installed from the running thread of diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 08416f3a3e..0fa9930e8a 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -85,7 +85,7 @@ int kill(pid_t pid, int signo) { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_mqnotempty.c b/sched/signal/sig_mqnotempty.c index 25ce0e3ae1..44b05b7aff 100644 --- a/sched/signal/sig_mqnotempty.c +++ b/sched/signal/sig_mqnotempty.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functionss - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,7 +70,7 @@ int sig_mqnotempty(int pid, int signo, void *sival_ptr) #endif { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index 7615096e41..fe0e537d1e 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -45,26 +45,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -89,7 +69,7 @@ int sigpending(FAR sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); int ret = ERROR; if (set) diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index 2e18c3cd9e..5f0c68e389 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -53,26 +53,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +93,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t oldsigprocmask; irqstate_t saved_state; int ret = OK; diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index 8b09528f80..3daa59c155 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -48,26 +48,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -112,7 +92,7 @@ int sigqueue(int pid, int signo, void *sival_ptr) #endif { #ifdef CONFIG_SCHED_HAVE_PARENT - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #endif siginfo_t info; int ret; diff --git a/sched/signal/sig_suspend.c b/sched/signal/sig_suspend.c index 6e9e964b70..56dc982991 100644 --- a/sched/signal/sig_suspend.c +++ b/sched/signal/sig_suspend.c @@ -49,26 +49,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,7 +90,7 @@ int sigsuspend(FAR const sigset_t *set) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t intersection; sigset_t saved_sigprocmask; FAR sigpendq_t *sigpend; diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 7443fd17fc..ecf0798f87 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -66,18 +66,6 @@ #define SIG_WAIT_TIMEOUT 0xff -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -175,7 +163,7 @@ static void sig_timeout(int argc, wdparm_t itcb) int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, FAR const struct timespec *timeout) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t intersection; FAR sigpendq_t *sigpend; irqstate_t saved_state; diff --git a/sched/signal/sig_unmaskpendingsignal.c b/sched/signal/sig_unmaskpendingsignal.c index 5b22af6765..7781515e00 100644 --- a/sched/signal/sig_unmaskpendingsignal.c +++ b/sched/signal/sig_unmaskpendingsignal.c @@ -44,26 +44,6 @@ #include "sched/sched.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,7 +60,7 @@ void sig_unmaskpendingsignal(void) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); sigset_t unmaskedset; FAR sigpendq_t *pendingsig; int signo; diff --git a/sched/task/exit.c b/sched/task/exit.c index f9011cb83c..582fe5a05c 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -49,30 +49,6 @@ #include "task/task.h" #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,7 +69,7 @@ void exit(int status) { - struct tcb_s *tcb = (struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); /* Only the lower 8-bits of status are used */ diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c index 07eab08644..ba26f3ab8c 100644 --- a/sched/task/task_atexit.c +++ b/sched/task/task_atexit.c @@ -52,30 +52,6 @@ #ifdef CONFIG_SCHED_ATEXIT -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -121,7 +97,7 @@ int atexit(void (*func)(void)) return on_exit((onexitfunc_t)func, NULL); #elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int index; int ret = ERROR; @@ -155,7 +131,7 @@ int atexit(void (*func)(void)) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int ret = ERROR; diff --git a/sched/task/task_delete.c b/sched/task/task_delete.c index fea823d5e8..5b4c0f747d 100644 --- a/sched/task/task_delete.c +++ b/sched/task/task_delete.c @@ -46,30 +46,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -117,7 +93,7 @@ int task_delete(pid_t pid) /* Check if the task to delete is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (pid == 0 || pid == rtcb->pid) { /* If it is, then what we really wanted to do was exit. Note that we diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index ce9c2ad38e..73eab8169f 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -48,30 +48,6 @@ #endif #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -106,7 +82,7 @@ int task_exit(void) { - FAR struct tcb_s *dtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *dtcb = this_task(); FAR struct tcb_s *rtcb; int ret; @@ -119,7 +95,7 @@ int task_exit(void) */ (void)sched_removereadytorun(dtcb); - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); /* We are now in a bad state -- the head of the ready to run task list * does not correspond to the thread that is running. Disabling pre- diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index e1400d6bfd..2d972b039d 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -44,26 +44,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -87,7 +67,7 @@ pid_t getpid(void) * with pid == 0 must be running. */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if (rtcb) { /* Return the task ID from the TCB at the head of the ready-to-run diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c index a1172abd06..6d3d47fce6 100644 --- a/sched/task/task_onexit.c +++ b/sched/task/task_onexit.c @@ -52,30 +52,6 @@ #ifdef CONFIG_SCHED_ONEXIT -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -116,7 +92,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) { #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1 - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int index; int ret = ENOSPC; @@ -151,7 +127,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) return ret; #else - FAR struct tcb_s *tcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *tcb = this_task(); FAR struct task_group_s *group = tcb->group; int ret = ENOSPC; diff --git a/sched/task/task_prctl.c b/sched/task/task_prctl.c index b89c578709..1908872536 100644 --- a/sched/task/task_prctl.c +++ b/sched/task/task_prctl.c @@ -50,10 +50,6 @@ #include "sched/sched.h" #include "task/task.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,7 +98,7 @@ int prctl(int option, ...) if (!pid) { - tcb = (FAR struct tcb_s *)g_readytorun.head; + tcb = this_task(); } else { diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index e6229adf4f..71c6f77adc 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -50,30 +50,6 @@ #include "signal/signal.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -115,7 +91,7 @@ int task_restart(pid_t pid) /* Check if the task to restart is the calling task */ - rtcb = (FAR struct tcb_s *)g_readytorun.head; + rtcb = this_task(); if ((pid == 0) || (pid == rtcb->pid)) { /* Not implemented */ diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index feb45b83fd..d7730c6509 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -63,15 +63,7 @@ #define MAX_STACK_ARGS 256 /**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* This is the name for un-named tasks */ @@ -183,7 +175,7 @@ static int task_assignpid(FAR struct tcb_s *tcb) #ifdef CONFIG_SCHED_HAVE_PARENT static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_SCHED_CHILD_STATUS) DEBUGASSERT(tcb && tcb->group && rtcb->group); @@ -288,7 +280,7 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) #ifdef CONFIG_PIC static inline void task_dupdspace(FAR struct tcb_s *tcb) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; + FAR struct tcb_s *rtcb = this_task(); if (rtcb->dspace != NULL) { /* Copy the D-Space structure reference and increment the reference diff --git a/sched/task/task_start.c b/sched/task/task_start.c index 6beeccff97..9737d2ddf3 100644 --- a/sched/task/task_start.c +++ b/sched/task/task_start.c @@ -100,7 +100,7 @@ void task_start(void) { - FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)g_readytorun.head; + FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)this_task(); int exitcode; int argc; diff --git a/sched/task/task_vfork.c b/sched/task/task_vfork.c index 65cdf481cf..b2fef61d36 100644 --- a/sched/task/task_vfork.c +++ b/sched/task/task_vfork.c @@ -240,7 +240,7 @@ static inline int vfork_argsetup(FAR struct tcb_s *parent, FAR struct task_tcb_s *task_vforksetup(start_t retaddr) { - struct tcb_s *parent = (FAR struct tcb_s *)g_readytorun.head; + struct tcb_s *parent = this_task(); struct task_tcb_s *child; uint8_t ttype; int priority; @@ -364,12 +364,12 @@ errout_with_tcb: pid_t task_vforkstart(FAR struct task_tcb_s *child) { - struct tcb_s *parent = (FAR struct tcb_s *)g_readytorun.head; + struct tcb_s *parent = this_task(); pid_t pid; int rc; int ret; - svdbg("Starting Child TCB=%p, parent=%p\n", child, g_readytorun.head); + svdbg("Starting Child TCB=%p, parent=%p\n", child, this_task()); DEBUGASSERT(child); /* Duplicate the original argument list in the forked child TCB */ -- GitLab From 0af9a197ac32ab55b6e7d53e6a81addb2a9b8d49 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 Feb 2016 11:17:22 -0600 Subject: [PATCH 695/858] ARP: Add IOCTL commands to manage the ARP table --- ChangeLog | 4 +- TODO | 2 +- include/nuttx/net/arp.h | 34 ++++++++- include/nuttx/net/ioctl.h | 155 ++++++++++++++++++++------------------ net/arp/arp.h | 33 +++++++- net/arp/arp_arpin.c | 4 +- net/arp/arp_ipin.c | 2 +- net/arp/arp_table.c | 40 +++++++++- net/netdev/netdev_ioctl.c | 137 +++++++++++++++++++++++++++++++++ 9 files changed, 324 insertions(+), 87 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9b22e44a4..44e9c3cc68 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11466,4 +11466,6 @@ g_readytorun() with the wrapper this_task() which hides the implementation and will permit such things as more scalable representations of task queues and SMP (2016-02-06). - + * include/nuttx/net/arp.h, include/nuttx/net/ioctl.h, net/netdev/netdev_ioctl.c, + and ARP-related files: Add support for IOCTL commands to manage the + ARP table (2016-02-08). diff --git a/TODO b/TODO index 7710e0bc1c..bd3bc69191 100644 --- a/TODO +++ b/TODO @@ -1740,7 +1740,7 @@ o Network Utilities (apps/netutils/) Priority: Low Title: DHCPD ACCESSES KERNEL PRIVATE INTERFACE - Description: arp_update() is referenced outside of nuttx/net. It is used in + Description: arp_hdr_update() is referenced outside of nuttx/net. It is used in in the netutils/ DHCPD logic to set entries in the ARP table. That is violation of the separation of kernel and OS functionality. As a consequence, dhcpd will not work with the diff --git a/include/nuttx/net/arp.h b/include/nuttx/net/arp.h index 502d89b0e6..dab5e27876 100644 --- a/include/nuttx/net/arp.h +++ b/include/nuttx/net/arp.h @@ -2,7 +2,7 @@ * include/nuttx/net/arp.h * Macros and definitions for the ARP module. * - * Copyright (C) 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2012, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Derived from uIP with has a similar BSD-styple license: @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -60,6 +61,15 @@ * Pre-processor Definitions ****************************************************************************/ +/* ARP protocol HARDWARE identifiers. Provided as the sa_family member of a + * struct sockaddr. + * + * When sa_family is ARPHRD_ETHER, the 6 byte Ethernet address is provided + * in the first 6-bytes of the sockaddr sa_data array. + */ + +#define ARPHRD_ETHER 1 /* Only Ethernet is supported */ + /**************************************************************************** * Public Types ****************************************************************************/ @@ -70,9 +80,29 @@ struct arp_entry { in_addr_t at_ipaddr; /* IP address */ struct ether_addr at_ethaddr; /* Hardware address */ - uint8_t at_time; + uint8_t at_time; /* Time of last usage */ }; +/* Used with the SIOCSARP, SIOCDARP, and SIOCGARP IOCTL commands to set, + * delete, or get an ARP table entry. + * + * SIOCSARP - Both values are inputs a define the new ARP table entry + * SIOCDARP - Only the protcol address is required as an input. The ARP + * table entry with that matching address will be deleted, + * regardless of the hardware address. + * SIOCGARP - The protocol address is an input an identifies the table + * entry to locate; The hardware address is an output and + * on a successful lookup, provides the matching hardware + * address. + */ + +struct arpreq +{ + struct sockaddr arp_pa; /* Protocol address */ + struct sockaddr arp_ha; /* Hardware address */ +}; + + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h index 4a13ed523f..a20d5e231b 100644 --- a/include/nuttx/net/ioctl.h +++ b/include/nuttx/net/ioctl.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/ioctl.h * - * Copyright (C) 2007-2008, 2010-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2010-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -94,97 +94,106 @@ #define SIOCGIPMSFILTER _SIOC(0x001a) /* Retrieve source filter addresses */ #define SIOCSIPMSFILTER _SIOC(0x001b) /* Set source filter content */ +/* ARP Table. Argument is a reference to sruct arpreq as defined + * include/nuttx/net/arp.h + */ + +#define SIOCSARP _SIOC(0x001c) /* Set an ARP mapping */ +#define SIOCDARP _SIOC(0x001d) /* Delete an ARP mapping */ +#define SIOCGARP _SIOC(0x001e) /* Get an ARP mapping */ + /* Routing table. Argument is a reference to struct rtentry as defined in * include/net/route.h */ -#define SIOCADDRT _SIOC(0x001c) /* Add an entry to the routing table */ -#define SIOCDELRT _SIOC(0x001d) /* Delete an entry from the routing table */ +#define SIOCADDRT _SIOC(0x001f) /* Add an entry to the routing table */ +#define SIOCDELRT _SIOC(0x0020) /* Delete an entry from the routing table */ /* Wireless ioctl commands **************************************************/ - -#define SIOCSIWCOMMIT _SIOC(0x001e) /* Commit pending changes to driver */ -#define SIOCGIWNAME _SIOC(0x001f) /* Get name of wireless protocol */ - -#define SIOCSIWNWID _SIOC(0x0020) /* Set network ID (pre-802.11) */ -#define SIOCGIWNWID _SIOC(0x0021) /* Get network ID (the cell) */ -#define SIOCSIWFREQ _SIOC(0x0022) /* Set channel/frequency (Hz) */ -#define SIOCGIWFREQ _SIOC(0x0023) /* Get channel/frequency (Hz) */ -#define SIOCSIWMODE _SIOC(0x0024) /* Set operation mode */ -#define SIOCGIWMODE _SIOC(0x0025) /* Get operation mode */ -#define SIOCSIWSENS _SIOC(0x0026) /* Set sensitivity (dBm) */ -#define SIOCGIWSENS _SIOC(0x0027) /* Get sensitivity (dBm) */ - -#define SIOCGIWRANGE _SIOC(0x0028) /* Get range of parameters */ -#define SIOCGIWPRIV _SIOC(0x0029) /* Get private ioctl interface info */ -#define SIOCGIWSTATS _SIOC(0x002a) /* Get wireless stats */ - -#define SIOCSIWSPY _SIOC(0x002b) /* Set spy addresses */ -#define SIOCGIWSPY _SIOC(0x002c) /* Get spy info (quality of link) */ -#define SIOCSIWTHRSPY _SIOC(0x002d) /* Set spy threshold (spy event) */ -#define SIOCGIWTHRSPY _SIOC(0x002e) /* Get spy threshold */ - -#define SIOCSIWAP _SIOC(0x002f) /* Set access point MAC addresses */ -#define SIOCGIWAP _SIOC(0x0030) /* Get access point MAC addresses */ -#define SIOCGIWAPLIST _SIOC(0x0031) /* Deprecated in favor of scanning */ -#define SIOCSIWSCAN _SIOC(0x0032) /* Trigger scanning (list cells) */ -#define SIOCGIWSCAN _SIOC(0x0033) /* Get scanning results */ - -#define SIOCSIWESSID _SIOC(0x0034) /* Set ESSID (network name) */ -#define SIOCGIWESSID _SIOC(0x0035) /* Get ESSID */ -#define SIOCSIWNICKN _SIOC(0x0036) /* Set node name/nickname */ -#define SIOCGIWNICKN _SIOC(0x0037) /* Get node name/nickname */ - -#define SIOCSIWRATE _SIOC(0x0038) /* Set default bit rate (bps) */ -#define SIOCGIWRATE _SIOC(0x0039) /* Get default bit rate (bps) */ -#define SIOCSIWRTS _SIOC(0x003a) /* Set RTS/CTS threshold (bytes) */ -#define SIOCGIWRTS _SIOC(0x003b) /* Get RTS/CTS threshold (bytes) */ -#define SIOCSIWFRAG _SIOC(0x003c) /* Set fragmentation thr (bytes) */ -#define SIOCGIWFRAG _SIOC(0x003d) /* Get fragmentation thr (bytes) */ -#define SIOCSIWTXPOW _SIOC(0x003e) /* Set transmit power (dBm) */ -#define SIOCGIWTXPOW _SIOC(0x003f) /* Get transmit power (dBm) */ -#define SIOCSIWRETRY _SIOC(0x0040) /* Set retry limits and lifetime */ -#define SIOCGIWRETRY _SIOC(0x0041) /* Get retry limits and lifetime */ - -#define SIOCSIWPOWER _SIOC(0x0042) /* Set Power Management settings */ -#define SIOCGIWPOWER _SIOC(0x0043) /* Get Power Management settings */ - -#define SIOCSIWGENIE _SIOC(0x0044) /* Set generic IE */ -#define SIOCGIWGENIE _SIOC(0x0045) /* Get generic IE */ - -#define SIOCSIWMLME _SIOC(0x0046) /* Request MLME operation */ - -#define SIOCSIWAUTH _SIOC(0x0047) /* Set authentication mode params */ -#define SIOCGIWAUTH _SIOC(0x0048) /* Get authentication mode params */ - -#define SIOCSIWENCODEEXT _SIOC(0x0049) /* Set encoding token & mode */ -#define SIOCGIWENCODEEXT _SIOC(0x004a) /* Get encoding token & mode */ - -#define SIOCSIWPMKSA _SIOC(0x004b) /* PMKSA cache operation */ +/* Not currently used */ + +#define SIOCSIWCOMMIT _SIOC(0x0021) /* Commit pending changes to driver */ +#define SIOCGIWNAME _SIOC(0x0022) /* Get name of wireless protocol */ + +#define SIOCSIWNWID _SIOC(0x0023) /* Set network ID (pre-802.11) */ +#define SIOCGIWNWID _SIOC(0x0024) /* Get network ID (the cell) */ +#define SIOCSIWFREQ _SIOC(0x0025) /* Set channel/frequency (Hz) */ +#define SIOCGIWFREQ _SIOC(0x0026) /* Get channel/frequency (Hz) */ +#define SIOCSIWMODE _SIOC(0x0027) /* Set operation mode */ +#define SIOCGIWMODE _SIOC(0x0028) /* Get operation mode */ +#define SIOCSIWSENS _SIOC(0x0029) /* Set sensitivity (dBm) */ +#define SIOCGIWSENS _SIOC(0x002a) /* Get sensitivity (dBm) */ + +#define SIOCGIWRANGE _SIOC(0x002b) /* Get range of parameters */ +#define SIOCGIWPRIV _SIOC(0x002c) /* Get private ioctl interface info */ +#define SIOCGIWSTATS _SIOC(0x002d) /* Get wireless stats */ + +#define SIOCSIWSPY _SIOC(0x002e) /* Set spy addresses */ +#define SIOCGIWSPY _SIOC(0x002f) /* Get spy info (quality of link) */ +#define SIOCSIWTHRSPY _SIOC(0x0030) /* Set spy threshold (spy event) */ +#define SIOCGIWTHRSPY _SIOC(0x0031) /* Get spy threshold */ + +#define SIOCSIWAP _SIOC(0x0032) /* Set access point MAC addresses */ +#define SIOCGIWAP _SIOC(0x0033) /* Get access point MAC addresses */ +#define SIOCGIWAPLIST _SIOC(0x0034) /* Deprecated in favor of scanning */ +#define SIOCSIWSCAN _SIOC(0x0035) /* Trigger scanning (list cells) */ +#define SIOCGIWSCAN _SIOC(0x0036) /* Get scanning results */ + +#define SIOCSIWESSID _SIOC(0x0037) /* Set ESSID (network name) */ +#define SIOCGIWESSID _SIOC(0x0038) /* Get ESSID */ +#define SIOCSIWNICKN _SIOC(0x0039) /* Set node name/nickname */ +#define SIOCGIWNICKN _SIOC(0x003a) /* Get node name/nickname */ + +#define SIOCSIWRATE _SIOC(0x003b) /* Set default bit rate (bps) */ +#define SIOCGIWRATE _SIOC(0x003c) /* Get default bit rate (bps) */ +#define SIOCSIWRTS _SIOC(0x003d) /* Set RTS/CTS threshold (bytes) */ +#define SIOCGIWRTS _SIOC(0x003e) /* Get RTS/CTS threshold (bytes) */ +#define SIOCSIWFRAG _SIOC(0x003f) /* Set fragmentation thr (bytes) */ +#define SIOCGIWFRAG _SIOC(0x0040) /* Get fragmentation thr (bytes) */ +#define SIOCSIWTXPOW _SIOC(0x0041) /* Set transmit power (dBm) */ +#define SIOCGIWTXPOW _SIOC(0x0042) /* Get transmit power (dBm) */ +#define SIOCSIWRETRY _SIOC(0x0043) /* Set retry limits and lifetime */ +#define SIOCGIWRETRY _SIOC(0x0044) /* Get retry limits and lifetime */ + +#define SIOCSIWPOWER _SIOC(0x0045) /* Set Power Management settings */ +#define SIOCGIWPOWER _SIOC(0x0046) /* Get Power Management settings */ + +#define SIOCSIWGENIE _SIOC(0x0047) /* Set generic IE */ +#define SIOCGIWGENIE _SIOC(0x0048) /* Get generic IE */ + +#define SIOCSIWMLME _SIOC(0x0049) /* Request MLME operation */ + +#define SIOCSIWAUTH _SIOC(0x004a) /* Set authentication mode params */ +#define SIOCGIWAUTH _SIOC(0x004b) /* Get authentication mode params */ + +#define SIOCSIWENCODEEXT _SIOC(0x004c) /* Set encoding token & mode */ +#define SIOCGIWENCODEEXT _SIOC(0x004d) /* Get encoding token & mode */ + +#define SIOCSIWPMKSA _SIOC(0x004e) /* PMKSA cache operation */ /* MDIO/MCD *****************************************************************/ -#define SIOCMIINOTIFY _SIOC(0x004b) /* Receive notificaion via signal on - * PHY state change */ -#define SIOCGMIIPHY _SIOC(0x004c) /* Get address of MII PHY in use */ -#define SIOCGMIIREG _SIOC(0x004d) /* Get a MII register via MDIO */ -#define SIOCSMIIREG _SIOC(0x004e) /* Set a MII register via MDIO */ +#define SIOCMIINOTIFY _SIOC(0x004f) /* Receive notificaion via signal on + * PHY state change */ +#define SIOCGMIIPHY _SIOC(0x0050) /* Get address of MII PHY in use */ +#define SIOCGMIIREG _SIOC(0x0051) /* Get a MII register via MDIO */ +#define SIOCSMIIREG _SIOC(0x0052) /* Set a MII register via MDIO */ /* Unix domain sockets ******************************************************/ -#define SIOCINQ _SIOC(0x004f) /* Returns the amount of queued unread - * data in the receive */ +#define SIOCINQ _SIOC(0x0053) /* Returns the amount of queued unread + * data in the receive */ /* Telnet driver ************************************************************/ -#define SIOCTELNET _SIOC(0x0050) /* Create a Telnet sessions. - * See include/nuttx/net/telnet.h */ +#define SIOCTELNET _SIOC(0x0054) /* Create a Telnet sessions. + * See include/nuttx/net/telnet.h */ /**************************************************************************** - * Type Definitions + * Pulbic Type Definitions ****************************************************************************/ -/* See include/net/if.h */ +/* See include/net/if.h, include/net/route.h, and include/net/arp.h */ /**************************************************************************** * Public Function Prototypes diff --git a/net/arp/arp.h b/net/arp/arp.h index 65846b0015..b32490b411 100644 --- a/net/arp/arp.h +++ b/net/arp/arp.h @@ -1,7 +1,7 @@ /**************************************************************************** * net/arp/arp.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -420,15 +420,41 @@ FAR struct arp_entry *arp_find(in_addr_t ipaddr); * address of an existing association. * * Input parameters: + * ipaddr - The IP address as an inaddr_t + * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] + * + * Returned Value: + * Zero (OK) if the ARP table entry was successfully modified. A negated + * errno value is returned on any error. + * + * Assumptions + * The network is locked to assure exclusive access to the ARP table + * + ****************************************************************************/ + +int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr); + +/**************************************************************************** + * Name: arp_hdr_update + * + * Description: + * Add the IP/HW address mapping to the ARP table -OR- change the IP + * address of an existing association. + * + * Input parameters: * pipaddr - Refers to an IP address uint16_t[2] in network order * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] * + * Returned Value: + * Zero (OK) if the ARP table entry was successfully modified. A negated + * errno value is returned on any error. + * * Assumptions - * Interrupts are disabled to assure exclusive access to the ARP table. + * The network is locked to assure exclusive access to the ARP table * ****************************************************************************/ -void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr); +void arp_hdr_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr); /**************************************************************************** * Name: arp_dump @@ -467,6 +493,7 @@ void arp_dump(FAR struct arp_hdr_s *arp); # define arp_find(i) (NULL) # define arp_delete(i) # define arp_update(i,m); +# define arp_hdr_update(i,m); # define arp_dump(arp) #endif /* CONFIG_NET_ARP */ diff --git a/net/arp/arp_arpin.c b/net/arp/arp_arpin.c index feb2dc0a06..883d2f2a42 100644 --- a/net/arp/arp_arpin.c +++ b/net/arp/arp_arpin.c @@ -132,7 +132,7 @@ void arp_arpin(FAR struct net_driver_s *dev) * with this host in the future. */ - arp_update(arp->ah_sipaddr, arp->ah_shwaddr); + arp_hdr_update(arp->ah_sipaddr, arp->ah_shwaddr); arp->ah_opcode = HTONS(ARP_REPLY); memcpy(arp->ah_dhwaddr, arp->ah_shwaddr, ETHER_ADDR_LEN); @@ -161,7 +161,7 @@ void arp_arpin(FAR struct net_driver_s *dev) { /* Yes... Insert the address mapping in the ARP table */ - arp_update(arp->ah_sipaddr, arp->ah_shwaddr); + arp_hdr_update(arp->ah_sipaddr, arp->ah_shwaddr); /* Then notify any logic waiting for the ARP result */ diff --git a/net/arp/arp_ipin.c b/net/arp/arp_ipin.c index 558af73f3a..febcaf82dc 100644 --- a/net/arp/arp_ipin.c +++ b/net/arp/arp_ipin.c @@ -101,7 +101,7 @@ void arp_ipin(FAR struct net_driver_s *dev) srcipaddr = net_ip4addr_conv32(IPBUF->eh_srcipaddr); if (net_ipv4addr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask)) { - arp_update(IPBUF->eh_srcipaddr, ETHBUF->src); + arp_hdr_update(IPBUF->eh_srcipaddr, ETHBUF->src); } } diff --git a/net/arp/arp_table.c b/net/arp/arp_table.c index a9e201c733..9113cf8e25 100644 --- a/net/arp/arp_table.c +++ b/net/arp/arp_table.c @@ -142,18 +142,21 @@ void arp_timer(void) * address of an existing association. * * Input parameters: - * pipaddr - Refers to an IP address uint16_t[2] + * ipaddr - The IP address as an inaddr_t * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] * + * Returned Value: + * Zero (OK) if the ARP table entry was successfully modified. A negated + * errno value is returned on any error. + * * Assumptions - * Interrupts are disabled + * The network is locked to assure exclusive access to the ARP table * ****************************************************************************/ -void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr) +int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr) { struct arp_entry *tabptr = NULL; - in_addr_t ipaddr = net_ip4addr_conv32(pipaddr); int i; /* Walk through the ARP mapping table and try to find an entry to @@ -229,6 +232,35 @@ void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr) tabptr->at_time = g_arptime; } +/**************************************************************************** + * Name: arp_hdr_update + * + * Description: + * Add the IP/HW address mapping to the ARP table -OR- change the IP + * address of an existing association. + * + * Input parameters: + * pipaddr - Refers to an IP address uint16_t[2] in network order + * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] + * + * Returned Value: + * Zero (OK) if the ARP table entry was successfully modified. A negated + * errno value is returned on any error. + * + * Assumptions + * The network is locked to assure exclusive access to the ARP table + * + ****************************************************************************/ + +void arp_hdr_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr) +{ + in_addr_t ipaddr = net_ip4addr_conv32(pipaddr); + + /* Update the ARP table */ + + (void)arp_update(ipaddr, ethaddr); +} + /**************************************************************************** * Name: arp_find * diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 24578e9f85..077cfa7b13 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -57,12 +57,14 @@ #include #include +#include #ifdef CONFIG_NET_IGMP # include "sys/sockio.h" # include "nuttx/net/igmp.h" #endif +#include "arp/arp.h" #include "socket/socket.h" #include "netdev/netdev.h" #include "devif/devif.h" @@ -808,6 +810,129 @@ static int netdev_imsfioctl(FAR struct socket *psock, int cmd, } #endif +/**************************************************************************** + * Name: netdev_arpioctl + * + * Description: + * Perform ARP table specific operations. + * + * Parameters: + * psock Socket structure + * dev Ethernet driver device structure + * cmd The ioctl command + * req The argument of the ioctl cmd + * + * Return: + * >=0 on success (positive non-zero values are cmd-specific) + * Negated errno returned on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ARP +static int netdev_arpioctl(FAR struct socket *psock, int cmd, + FAR struct arpreq *req) +{ + int ret; + + /* Execute the command */ + + switch (cmd) + { + case SIOCSARP: /* Set an ARP mapping */ + { + if (req != NULL && + req->arp_pa.sa_family == AF_INET && + req->arp_ha.sa_family == ARPHRD_ETHER) + { + FAR struct sockaddr_in *addr = + (FAR struct sockaddr_in *)&req->arp_pa; + + /* Update any existing ARP table entry for this protocol + * address -OR- add a new ARP table entry if there is not. + */ + + ret = arp_update(addr->sin_addr.s_addr, + (FAR uint8_t *)req->arp_ha.sa_data); + } + else + { + ret = -EINVAL; + } + } + break; + + case SIOCDARP: /* Delete an ARP mapping */ + { + if (req != NULL && req->arp_pa.sa_family == AF_INET) + { + FAR struct sockaddr_in *addr = + (FAR struct sockaddr_in *)&req->arp_pa; + + /* Find the existing ARP table entry for this protocol address. */ + + FAR struct arp_entry *entry = arp_find(addr->sin_addr.s_addr); + if (entry != NULL) + { + /* The ARP table is fixed size; an entry is deleted + * by nullifying its protocol address. + */ + + entry->at_ipaddr = 0; + ret = OK; + } + else + { + ret = -ENOENT; + } + } + else + { + ret = -EINVAL; + } + } + break; + + case SIOCGARP: /* Get an ARP mapping */ + { + if (req != NULL && req->arp_pa.sa_family == AF_INET) + { + FAR struct sockaddr_in *addr = + (FAR struct sockaddr_in *)&req->arp_pa; + + /* Find the existing ARP table entry for this protocol address. */ + + FAR struct arp_entry *entry = arp_find(addr->sin_addr.s_addr); + if (entry != NULL) + { + /* Return the mapped hardware address. */ + + req->arp_ha.sa_family = ARPHRD_ETHER; + memcpy(req->arp_ha.sa_data, + entry->at_ethaddr.ether_addr_octet, + ETHER_ADDR_LEN); + ret = OK; + } + else + { + ret = -ENOENT; + } + } + else + { + ret = -EINVAL; + } + } + break; + + default: + ret = -ENOTTY; + break; + } + + return ret; +} +#endif + /**************************************************************************** * Name: netdev_rtioctl * @@ -972,6 +1097,18 @@ int netdev_ioctl(int sockfd, int cmd, unsigned long arg) ret = netdev_imsfioctl(psock, cmd, (FAR struct ip_msfilter *)((uintptr_t)arg)); } #endif + + /* Check for ARP table IOCTL commands */ + +#ifdef CONFIG_NET_ARP + if (ret == -ENOTTY) + { + ret = netdev_arpioctl(psock, cmd, (FAR struct arpreq *)((uintptr_t)arg)); + } +#endif + + /* Check for Routing table IOCTL commands */ + #ifdef CONFIG_NET_ROUTE if (ret == -ENOTTY) { -- GitLab From 166ad5884992414548042310685660c4c274aff5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 Feb 2016 12:08:18 -0600 Subject: [PATCH 696/858] DHCPD no longer calls directly into the OS, but uses network IOCTL commands to modify the ARP table. Plus, fix a warning. --- TODO | 16 ++-------------- net/arp/arp_table.c | 4 ++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index bd3bc69191..61c307700c 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated February 6, 2016) +NuttX TODO List (Last updated February 8, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -30,7 +30,7 @@ nuttx/ apps/ - (4) Network Utilities (apps/netutils/) + (3) Network Utilities (apps/netutils/) (3) NuttShell (NSH) (apps/nshlib) (1) System libraries apps/system (apps/system) (4) Other Applications & Tests (apps/examples/) @@ -1739,18 +1739,6 @@ o Network Utilities (apps/netutils/) Status: Open. An annoyance, but not a real problem. Priority: Low - Title: DHCPD ACCESSES KERNEL PRIVATE INTERFACE - Description: arp_hdr_update() is referenced outside of nuttx/net. It is used in - in the netutils/ DHCPD logic to set entries in the ARP table. - That is violation of the separation of kernel and OS - functionality. As a consequence, dhcpd will not work with the - NuttX kernel built. - - This direct OS call needs to be replaced with a network ioctl() - call. - Status: Open - Priority: Medium. Important for full functionality with kernel build. - Title: NETWORK MONITOR NOT GENERALLY AVAILABLE Description: The NSH network management logic has general applicability but is currently useful only because it is embedded in the NSH diff --git a/net/arp/arp_table.c b/net/arp/arp_table.c index 9113cf8e25..a89e445fa1 100644 --- a/net/arp/arp_table.c +++ b/net/arp/arp_table.c @@ -182,13 +182,12 @@ int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr) memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); tabptr->at_time = g_arptime; - return; + return OK; } } } /* If we get here, no existing ARP table entry was found, so we create one. */ - /* First, we try to find an unused entry in the ARP table. */ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) @@ -230,6 +229,7 @@ int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr) tabptr->at_ipaddr = ipaddr; memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); tabptr->at_time = g_arptime; + return OK; } /**************************************************************************** -- GitLab From 68ee9bcaedfeb76a7eaf8bad7833ffbad373e9c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 Feb 2016 15:13:14 -0600 Subject: [PATCH 697/858] Refresh modules + plus minor clean-up from previous commits --- Documentation | 2 +- TODO | 8 +------- configs | 2 +- libc/net/lib_inetntoa.c | 2 +- net/netdev/netdev_ioctl.c | 7 ------- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/Documentation b/Documentation index 5acd332e57..f1517cb0bb 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 5acd332e570f2454d98bce9dfa873770a3856dd0 +Subproject commit f1517cb0bb3fe10986030cd57b5bed1cf48e90b0 diff --git a/TODO b/TODO index 61c307700c..31bd58e955 100644 --- a/TODO +++ b/TODO @@ -31,7 +31,7 @@ nuttx/ apps/ (3) Network Utilities (apps/netutils/) - (3) NuttShell (NSH) (apps/nshlib) + (2) NuttShell (NSH) (apps/nshlib) (1) System libraries apps/system (apps/system) (4) Other Applications & Tests (apps/examples/) @@ -1758,12 +1758,6 @@ o NuttShell (NSH) (apps/nshlib) Status: Open Priority: Low - Title: ARP COMMAND - Description: Add an ARP command so that we can see and modify the contents of - the ARP table. - Status: Open - Priority: Low (enhancement) - Title: ARPPING COMMAND Description: Add an arping command Status: Open diff --git a/configs b/configs index e18941d4d5..df66c8b70c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e18941d4d5e4de5b3ce581911a4296a8206830a3 +Subproject commit df66c8b70c69689c9adf46c5d8188c9a5613e2e5 diff --git a/libc/net/lib_inetntoa.c b/libc/net/lib_inetntoa.c index 4bd49db921..a25364ce2d 100644 --- a/libc/net/lib_inetntoa.c +++ b/libc/net/lib_inetntoa.c @@ -54,7 +54,7 @@ * Name: inet_ntoa * * Description: - * The inet_ntoa() function converts the Internet host address in given in + * The inet_ntoa() function converts the Internet host address given in * network byte order to a string in standard numbers-and-dots notation. * The string is returned in a statically allocated buffer, which subsequent * calls will overwrite. diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 077cfa7b13..d54c3f6b05 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -676,13 +676,6 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, } break; -#ifdef CONFIG_NET_ARPIOCTLS - case SIOCSARP: /* Set a ARP mapping */ - case SIOCDARP: /* Delete an ARP mapping */ - case SIOCGARP: /* Get an ARP mapping */ -# error "IOCTL Commands not implemented" -#endif - #ifdef CONFIG_NETDEV_PHY_IOCTL #ifdef CONFIG_ARCH_PHY_INTERRUPT case SIOCMIINOTIFY: /* Set up for PHY event notifications */ -- GitLab From 7aa237973c36194ffc1d2ec89b97162fdb82b98f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 9 Feb 2016 11:25:29 -0600 Subject: [PATCH 698/858] Update TODO --- Documentation | 2 +- TODO | 27 +-------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/Documentation b/Documentation index f1517cb0bb..0d2a964b20 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit f1517cb0bb3fe10986030cd57b5bed1cf48e90b0 +Subproject commit 0d2a964b20c73ca7c67f6602345f903055c02623 diff --git a/TODO b/TODO index 31bd58e955..e8bf3a1a8b 100644 --- a/TODO +++ b/TODO @@ -26,7 +26,7 @@ nuttx/ (1) Pascal add-on (pcode/) (1) Build system / Toolchains (3) Linux/Cywgin simulation (arch/sim) - (5) ARM (arch/arm/) + (4) ARM (arch/arm/) apps/ @@ -1675,31 +1675,6 @@ o ARM (arch/arm/) If your design needs continuous interrupts like this, please try the above change and, please, submit a patch with the working fix. - Title: STACK ALIGNMENT IN INTERRUPT HANDLERS - Description: The EABI standard requires that the stack always have a 32-byte - alignment. There is no guarantee at present that the stack will be - so aligned in an interrupt handler. Therefore, I would expect some - issues if, for example, floating point or perhaps long long operations - were performed in an interrupt handler. - - This issue exists for ARM7, ARM9, and Cortex-M0 but has been - addressed for the Cortex-M3/4/7 and Cortex-A5/8. The fix - is really simple but cannot be incorporated without some - substantial testing. For ARM, the fix is the following logic - arround each call into C code from assembly: - - mov r4, sp /* Save the SP in a preserved register */ - bic sp, sp, #7 /* Force 8-byte alignment */ - bl cfunction /* Call the C function */ - mov sp, r4 /* Restore the possibly unaligned stack pointer */ - - This same issue applies to the interrupt stack which is, I think - improperly aligned in almost all cases (except Cortex-A5). - - Status: Open - Priority: Low for me because I never do floating point operations in - interrupt handlers. - Title: IMPROVED TASK START-UP AND SYSCALL RETURN Description: Couldn't up_start_task and up_start_pthread syscalls be eliminated. Wouldn't this work to get us from kernel- -- GitLab From b022f1e9d806f172d0afbba168aac0fb723e6149 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 9 Feb 2016 13:48:59 -0600 Subject: [PATCH 699/858] Add basic support for spinlocks (not currently used by anything) --- ChangeLog | 5 ++ arch | 2 +- configs | 2 +- include/nuttx/spinlock.h | 102 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 include/nuttx/spinlock.h diff --git a/ChangeLog b/ChangeLog index 44e9c3cc68..36077eb2d4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11469,3 +11469,8 @@ * include/nuttx/net/arp.h, include/nuttx/net/ioctl.h, net/netdev/netdev_ioctl.c, and ARP-related files: Add support for IOCTL commands to manage the ARP table (2016-02-08). + * ARMv7-A, ARMv7-R, and ARMv7-A: Add test-and-set logic and definitions + needed to supports spinlocks (2016-02-09). + * include/nuttx/spinlock.h: Add basic definitions for spinlocks. Not yet + used by NuttX (2016-02-09). + diff --git a/arch b/arch index 5c9c3dc73e..958e4d09fc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5c9c3dc73e2ae5e87203801c6ab82e44a3f8fbec +Subproject commit 958e4d09fc413d88893881eee612d901b779e057 diff --git a/configs b/configs index df66c8b70c..05856eb712 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit df66c8b70c69689c9adf46c5d8188c9a5613e2e5 +Subproject commit 05856eb712badecadbdbd7803c868ebd0b2de451 diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h new file mode 100644 index 0000000000..b58d7568be --- /dev/null +++ b/include/nuttx/spinlock.h @@ -0,0 +1,102 @@ +/**************************************************************************** + * include/nuttx/spinlock.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SPINLOCK_H +#define __INCLUDE_NUTTX_SPINLOCK_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/* The architecture specific spinlock.h header file must also provide the + * following: + * + * SP_LOCKED - A definition of the locked state value (usually 1) + * SP_UNLOCKED - A definition of the unlocked state value (usually 0) + * spinlock_t - The type of a spinlock memory object. + * + * SP_LOCKED and SP_UNLOCKED must constants of type spinlock_t. + */ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: up_testset + * + * Description: + * Perform and atomic test and set operation on the provided spinlock. + * + * This function must be provided via the architecture-specific logoic. + * + * Input Parameters: + * lock - The address of spinlock object. + * + * Returned Value: + * The spinlock is always locked upon return. The value of previous value + * of the spinlock variable is returned, either SP_LOCKED if the spinlock + * as previously locked (meaning that the test-and-set operation failed to + * obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked + * (meaning that we successfully obtained the lock) + * + ****************************************************************************/ + +spinlock_t up_testset(FAR spinlock_t *lock); + +/**************************************************************************** + * Name: spinlock + * + * Description: + * Loop until the spinlock is successfully locked. + * + * Input Parameters: + * lock - The address of spinlock object. + * + * Returned Value: + * None. When the function returned, the spinlocked was successfully + * locked by this CPU. + * + ****************************************************************************/ + +#define spinlock(l) while (up_testset(l) == SP_LOCKED) (void)sched_yield() + +#endif /* CONFIG_SIG_EVTHREAD && CONFIG_BUILD_FLAT */ +#endif /* __INCLUDE_NUTTX_SPINLOCK_H */ -- GitLab From 2c0ad2564f893e722bdf64944e95c9f42b4f2aaf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 9 Feb 2016 15:31:14 -0600 Subject: [PATCH 700/858] Add CONFIG_SPINLOCK. Also need spinunlock() and spinlock_initialize() --- include/nuttx/spinlock.h | 67 +++++++++-- sched/Kconfig | 5 + sched/semaphore/Make.defs | 4 + sched/semaphore/spinlock.c | 227 +++++++++++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+), 7 deletions(-) create mode 100644 sched/semaphore/spinlock.c diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index b58d7568be..e7041f5df9 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -41,7 +41,9 @@ ****************************************************************************/ #include -#include +#include + +#ifdef CONFIG_SPINLOCK /* The architecture specific spinlock.h header file must also provide the * following: @@ -55,6 +57,18 @@ #include +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct spinlock_s +{ + spinlock_t sp_lock; /* Indicates if the spinlock is locked or not. See the + * values SP_LOCKED and SP_UNLOCKED. */ + uint8_t sp_cpu; /* CPU holding the lock */ + uint16_t sp_count; /* The count of references by this CPU on the lock */ +}; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -81,22 +95,61 @@ spinlock_t up_testset(FAR spinlock_t *lock); +/**************************************************************************** + * Name: spinlock_initialize + * + * Description: + * Initialize a spinlock object to its initial, unlocked state. + * + * Input Parameters: + * lock - A reference to the spinlock object to be initialized. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void spinlock_initialize(FAR struct spinlock_s *lock); + /**************************************************************************** * Name: spinlock * * Description: - * Loop until the spinlock is successfully locked. + * If this CPU does not already hold the spinlock, then loop until the + * spinlock is successfully locked. * * Input Parameters: - * lock - The address of spinlock object. + * lock - A reference to the spinlock object to lock. * * Returned Value: - * None. When the function returned, the spinlocked was successfully - * locked by this CPU. + * None. When the function returns, the spinlock was successfully locked + * by this CPU. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spinlock(FAR struct spinlock_s *lock); + +/**************************************************************************** + * Name: spinunlock + * + * Description: + * Release one count on a spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to unlock. + * + * Returned Value: + * None. + * + * Assumptions: + * Not running at the interrupt level. * ****************************************************************************/ -#define spinlock(l) while (up_testset(l) == SP_LOCKED) (void)sched_yield() +void spinunlock(FAR struct spinlock_s *lock); -#endif /* CONFIG_SIG_EVTHREAD && CONFIG_BUILD_FLAT */ +#endif /* CONFIG_SPINLOCK */ #endif /* __INCLUDE_NUTTX_SPINLOCK_H */ diff --git a/sched/Kconfig b/sched/Kconfig index 26e3237642..12b1c298a1 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -307,6 +307,11 @@ config RR_INTERVAL Round roben scheduling (SCHED_RR) is enabled by setting this interval to a positive, non-zero value. +config SPINLOCK + bool "Support Spinlocks" + default n + depends on EXPERIMENTAL + config SCHED_SPORADIC bool "Support sporadic scheduling" default n diff --git a/sched/semaphore/Make.defs b/sched/semaphore/Make.defs index 53b6a540ef..e9624282c9 100644 --- a/sched/semaphore/Make.defs +++ b/sched/semaphore/Make.defs @@ -41,6 +41,10 @@ ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) CSRCS += sem_initialize.c sem_holder.c endif +ifeq ($(CONFIG_SPINLOCK),y) +CSRCS += spinlock.c +endif + # Include semaphore build support DEPPATH += --dep-path semaphore diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c new file mode 100644 index 0000000000..c251b5f747 --- /dev/null +++ b/sched/semaphore/spinlock.c @@ -0,0 +1,227 @@ +/**************************************************************************** + * sched/semaphore/spinlock.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "sched/sched.h" + +#ifdef CONFIG_SPINLOCK + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define IMPOSSIBLE_CPU 0xff + +/* REVISIT: What happens if a thread taks a spinlock while running on one + * CPU, but is suspended, then reassigned to another CPU where it runs and + * eventually calls spinunlock(). One solution might be to lock a thread to + * a CPU if it holds a spinlock. That would assure that it never runs on + * any other CPU and avoids such complexities. + */ + +#undef CONFIG_SPINLOCK_LOCKDOWN /* Feature not yet available */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: spinlock_initialize + * + * Description: + * Initialize a spinlock object to its initial, unlocked state. + * + * Input Parameters: + * lock - A reference to the spinlock object to be initialized. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void spinlock_initialize(FAR struct spinlock_s *lock) +{ + DEBUGASSERT(lock != NULL); + + lock->sp_lock = SP_UNLOCKED; + lock->sp_cpu = IMPOSSIBLE_CPU; + lock->sp_count = 0; +} + +/**************************************************************************** + * Name: spinlock + * + * Description: + * If this CPU does not already hold the spinlock, then loop until the + * spinlock is successfully locked. + * + * Input Parameters: + * lock - A reference to the spinlock object to lock. + * + * Returned Value: + * None. When the function returns, the spinlock was successfully locked + * by this CPU. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spinlock(FAR struct spinlock_s *lock) +{ + irqstate_t flags; + uint8_t cpu = this_cpu(); + + /* Disable interrupts (all CPUs) */ + + flags = irqsave(); + + /* Do we already hold the lock on this CPU? */ + + if (lock->sp_cpu == cpu) + { + /* Yes... just increment the number of references we have on the lock */ + + lock->sp_count++; + DEBUGASSERT(lock->sp_lock = SP_LOCKED && lock->sp_count > 0); + } + else + { +#ifdef CONFIG_SPINLOCK_LOCKDOWN + /* REVISIT: What happens if this thread is suspended, then reassigned + * to another CPU where it runs and eventually calls spinunlock(). + * One solution might be to lock a thread to a CPU if it holds a + * spinlock. That would assure that it never runs on any other CPU + * and avoids such complexities. + */ + +# warning Missing logic +#endif + /* Take the lock */ + + while (up_testset(&lock->sp_lock) == SP_LOCKED) + { + irqrestore(flags); + sched_yield(); + flags = irqsave(); + } + + /* Take one count on the lock */ + + lock->sp_cpu = cpu; + lock->sp_count = 1; + } + + irqrestore(flags); +} + +/**************************************************************************** + * Name: spinunlock + * + * Description: + * Release one count on a spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to unlock. + * + * Returned Value: + * None. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spinunlock(FAR struct spinlock_s *lock) +{ + irqstate_t flags; +#ifdef CONFIG_SPINLOCK_LOCKDOWN + uint8_t cpu = this_cpu(); +#endif + + /* Disable interrupts (all CPUs) */ + + flags = irqsave(); + +#ifdef CONFIG_SPINLOCK_LOCKDOWN + /* REVISIT: What happens if this thread took the lock on a different CPU, + * was suspended, then reassigned to this CPU where it runs and eventually + * calls spinunlock(). One solution might be to lock a thread to a CPU if + * it holds a spinlock. That would assure that it never runs on any other + * CPU and avoids such complexities. + */ + + DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED && + lock->sp_cpu == this_cpu() && lock->sp_count > 0); + + /* Do we already hold the lock? */ + + if (lock->sp_cpu == cpu) +#else + DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED && + lock->sp_count > 0); +#endif + + { + /* Yes... just decrement the number of references we have on the lock */ + + if (lock->sp_count <= 1) + { + /* The count must decremented to zero */ + + lock->sp_count = 0; + lock->sp_cpu = IMPOSSIBLE_CPU; + lock->sp_lock = SP_UNLOCKED; + } + else + { + lock->sp_count--; + } + } + + irqrestore(flags); +} + +#endif /* CONFIG_SPINLOCK */ -- GitLab From bf8120d51d77ed7bdab646227ceb165d10581d74 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 09:50:28 -0600 Subject: [PATCH 701/858] Fix some odd logic in CC3000 semaphore handling. Noted by Vladimir Komendantskiy --- drivers/wireless/cc3000/cc3000.c | 92 ++++++++------------------------ sched/semaphore/spinlock.c | 5 +- 2 files changed, 25 insertions(+), 72 deletions(-) diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index 29b6ad84b1..68924193f2 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -211,27 +211,23 @@ uint8_t spi_readCommand[] = READ_COMMAND; * ****************************************************************************/ -static int cc3000_devtake(FAR struct cc3000_dev_s *priv) +static inline void cc3000_devtake(FAR struct cc3000_dev_s *priv) { - int rv; - /* Take the semaphore (perhaps waiting) */ - while ((rv = sem_wait(&priv->devsem)) != 0) + while (sem_wait(&priv->devsem) < 0) { - /* The only case that an error should occur here is if the wait was awakened - * by a signal. + /* The only case that an error should occur here is if the wait was + * awakened by a signal. */ - DEBUGASSERT(rv == OK || errno == EINTR); + DEBUGASSERT(errno == EINTR); } - - return rv; } -static inline int cc3000_devgive(FAR struct cc3000_dev_s *priv) +static inline void cc3000_devgive(FAR struct cc3000_dev_s *priv) { - return sem_post(&priv->devsem); + (void)sem_post(&priv->devsem); } /**************************************************************************** @@ -354,27 +350,16 @@ static int cc3000_wait(FAR struct cc3000_dev_s *priv, sem_t *psem) /* Wait on first psem to become signaled */ ret = sem_wait(psem); - if (ret >= 0) - { - /* Yes... then retake the mutual exclusion semaphore */ - - ret = cc3000_devtake(priv); - } - - sched_unlock(); - - /* Was the semaphore wait successful? Did we successful re-take the - * mutual exclusion semaphore? - */ - if (ret < 0) { - /* No.. One of the two sem_wait's failed. */ - - ret = -errno; + return -errno; } - return ret; + /* Then retake the mutual exclusion semaphore */ + + cc3000_devtake(priv); + sched_unlock(); + return OK; } /**************************************************************************** @@ -820,11 +805,7 @@ static int cc3000_open(FAR struct file *filep) /* Get exclusive access to the driver data structure */ - ret = cc3000_devtake(priv); - if (ret < 0) - { - return -ret; - } + cc3000_devtake(priv); /* Increment the reference count */ @@ -986,9 +967,8 @@ out_with_sem: static int cc3000_close(FAR struct file *filep) { - FAR struct inode *inode; + FAR struct inode *inode; FAR struct cc3000_dev_s *priv; - int ret; #ifdef CONFIG_CC3000_MT int s; #endif @@ -1005,11 +985,7 @@ static int cc3000_close(FAR struct file *filep) /* Get exclusive access to the driver data structure */ - ret = cc3000_devtake(priv); - if (ret < 0) - { - return -EINTR; - } + cc3000_devtake(priv); /* Decrement the reference count unless it would decrement a negative * value. When the count decrements to zero, there are no further @@ -1086,13 +1062,7 @@ static ssize_t cc3000_read(FAR struct file *filep, FAR char *buffer, size_t len) /* Get exclusive access to the driver data structure */ - ret = cc3000_devtake(priv); - - if (ret < 0) - { - nread = -errno; - goto errout_without_sem; - } + cc3000_devtake(priv); /* Verify that the caller has provided a buffer large enough to receive * the maximum data. @@ -1152,7 +1122,7 @@ static ssize_t cc3000_read(FAR struct file *filep, FAR char *buffer, size_t len) { /* Yes... then retake the mutual exclusion semaphore */ - ret = cc3000_devtake(priv); + cc3000_devtake(priv); } /* Was the semaphore wait successful? Did we successful re-take the @@ -1239,15 +1209,7 @@ static ssize_t cc3000_write(FAR struct file *filep, FAR const char *usrbuffer, s /* Get exclusive access to the driver data structure */ - ret = cc3000_devtake(priv); - if (ret < 0) - { - /* This should only happen if the wait was canceled by an signal */ - - ndbg("sem_wait: %d\n", errno); - nwritten = -errno; - goto errout_without_sem; - } + cc3000_devtake(priv); /* Figure out the total length of the packet in order to figure out if there is padding or not */ @@ -1352,13 +1314,7 @@ static int cc3000_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Get exclusive access to the driver data structure */ - ret = cc3000_devtake(priv); - if (ret < 0) - { - /* This should only happen if the wait was canceled by an signal */ - - return -errno; - } + cc3000_devtake(priv); /* Process the IOCTL by command */ @@ -1463,13 +1419,7 @@ static int cc3000_poll(FAR struct file *filep, FAR struct pollfd *fds, /* Are we setting up the poll? Or tearing it down? */ - ret = cc3000_devtake(priv); - if (ret < 0) - { - /* This should only happen if the wait was canceled by an signal */ - - return -errno; - } + cc3000_devtake(priv); if (setup) { diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index c251b5f747..b39cfe4d9a 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -139,7 +139,10 @@ void spinlock(FAR struct spinlock_s *lock) # warning Missing logic #endif - /* Take the lock */ + /* Take the lock. REVISIT: We should set an indication in the TCB + * that the thread is spinning. This might be useful in determining + * some scheduling actions? + */ while (up_testset(&lock->sp_lock) == SP_LOCKED) { -- GitLab From f5a3b1e89d2fb4654b0cbb33870bfd9eada17b9f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 10:27:48 -0600 Subject: [PATCH 702/858] Add EXPERIMENTAL configuration option to investigate some SMP issues --- include/nuttx/spinlock.h | 14 +++++++++----- sched/Kconfig | 34 +++++++++++++++++++++++++++++----- sched/semaphore/spinlock.c | 26 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index e7041f5df9..640a639a6d 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -63,10 +63,14 @@ struct spinlock_s { - spinlock_t sp_lock; /* Indicates if the spinlock is locked or not. See the - * values SP_LOCKED and SP_UNLOCKED. */ - uint8_t sp_cpu; /* CPU holding the lock */ - uint16_t sp_count; /* The count of references by this CPU on the lock */ + volatile spinlock_t sp_lock; /* Indicates if the spinlock is locked or + * not. See the* values SP_LOCKED and + * SP_UNLOCKED. */ +#ifdef CONFIG_SMP + uint8_t sp_cpu; /* CPU holding the lock */ + uint16_t sp_count; /* The count of references by this CPU on + * the lock */ +#endif }; /**************************************************************************** @@ -93,7 +97,7 @@ struct spinlock_s * ****************************************************************************/ -spinlock_t up_testset(FAR spinlock_t *lock); +spinlock_t up_testset(volatile FAR spinlock_t *lock); /**************************************************************************** * Name: spinlock_initialize diff --git a/sched/Kconfig b/sched/Kconfig index 12b1c298a1..45e14fd095 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -229,6 +229,35 @@ endmenu # Clocks and Timers menu "Tasks and Scheduling" +config SPINLOCK + bool "Support Spinlocks" + default n + depends on EXPERIMENTAL + ---help--- + Enables suppport for spinlocks. Spinlocks are current used only for + SMP suppport. + +config SMP + bool "Symmetric Multi-Processing (SMP)" + default n + depends on EXPERIMENTAL + select SPINLOCK + ---help--- + Enable support for Symmetric Multi-Processing (SMP) on a multi-CPU + platform. + +if SMP + +config SMP_NCPUS + int "Number of CPUs" + default 4 + range 2 32 + ---help--- + This value identifies the number of CPUs support by the processor + that will be used for SMP. + +endif # SMP + choice prompt "Initialization Task" default INIT_ENTRYPOINT if !BUILD_KERNEL @@ -307,11 +336,6 @@ config RR_INTERVAL Round roben scheduling (SCHED_RR) is enabled by setting this interval to a positive, non-zero value. -config SPINLOCK - bool "Support Spinlocks" - default n - depends on EXPERIMENTAL - config SCHED_SPORADIC bool "Support sporadic scheduling" default n diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index b39cfe4d9a..20bb3d048a 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -86,8 +86,10 @@ void spinlock_initialize(FAR struct spinlock_s *lock) DEBUGASSERT(lock != NULL); lock->sp_lock = SP_UNLOCKED; +#ifdef CONFIG_SMP lock->sp_cpu = IMPOSSIBLE_CPU; lock->sp_count = 0; +#endif } /**************************************************************************** @@ -111,6 +113,7 @@ void spinlock_initialize(FAR struct spinlock_s *lock) void spinlock(FAR struct spinlock_s *lock) { +#ifdef CONFIG_SMP irqstate_t flags; uint8_t cpu = this_cpu(); @@ -158,6 +161,20 @@ void spinlock(FAR struct spinlock_s *lock) } irqrestore(flags); + +#else /* CONFIG_SMP */ + + /* Take the lock. REVISIT: We should set an indication in the TCB that + * the thread is spinning. This might be useful in determining some + * scheduling actions? + */ + + while (up_testset(&lock->sp_lock) == SP_LOCKED) + { + sched_yield(); + } + +#endif /* CONFIG_SMP */ } /**************************************************************************** @@ -179,6 +196,7 @@ void spinlock(FAR struct spinlock_s *lock) void spinunlock(FAR struct spinlock_s *lock) { +#ifdef CONFIG_SMP irqstate_t flags; #ifdef CONFIG_SPINLOCK_LOCKDOWN uint8_t cpu = this_cpu(); @@ -225,6 +243,14 @@ void spinunlock(FAR struct spinlock_s *lock) } irqrestore(flags); + +#else /* CONFIG_SMP */ + /* Just mark the spinlock unlocked */ + + DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED); + lock->sp_lock = SP_UNLOCKED; + +#endif /* CONFIG_SMP */ } #endif /* CONFIG_SPINLOCK */ -- GitLab From 47a5663f8c2e8e3a5f15d2612ec636026d81af02 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 11:45:26 -0600 Subject: [PATCH 703/858] SMP: A few preliminary data structure definitions --- arch | 2 +- configs | 2 +- include/nuttx/arch.h | 48 +++++++++++++++++++++++++++++++++- sched/init/os_start.c | 46 +++++++++++++++++++++++++++++---- sched/sched/sched.h | 60 ++++++++++++++++++++++++++++++++++++------- 5 files changed, 141 insertions(+), 17 deletions(-) diff --git a/arch b/arch index 958e4d09fc..0ddf09674e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 958e4d09fc413d88893881eee612d901b779e057 +Subproject commit 0ddf09674eb2115ecfedaa82e21a2c43fc09d127 diff --git a/configs b/configs index 05856eb712..81a10b64ed 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 05856eb712badecadbdbd7803c868ebd0b2de451 +Subproject commit 81a10b64ed544684bb975e218e09ab5bc8aaf445 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index a28e7767ba..bbca284eab 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/arch.h * - * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1636,6 +1636,52 @@ int up_timer_cancel(FAR struct timespec *ts); int up_timer_start(FAR const struct timespec *ts); #endif +/**************************************************************************** + * Multiple CPU support + ****************************************************************************/ + +/**************************************************************************** + * Name: up_testset + * + * Description: + * Perform and atomic test and set operation on the provided spinlock. + * + * Input Parameters: + * lock - The address of spinlock object. + * + * Returned Value: + * The spinlock is always locked upon return. The value of previous value + * of the spinlock variable is returned, either SP_LOCKED if the spinlock + * as previously locked (meaning that the test-and-set operation failed to + * obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked + * (meaning that we successfully obtained the lock) + * + ****************************************************************************/ + +/* See prototype in include/nuttx/spinlock.h */ + +/**************************************************************************** + * Name: up_cpundx + * + * Description: + * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. + * + * Input Parameters: + * None + * + * Returned Value: + * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int up_cpundx(void); +#else +# define up_cpundx() (0) +#endif + /**************************************************************************** * Name: up_romgetc * diff --git a/sched/init/os_start.c b/sched/init/os_start.c index c97b53b034..f64a33bae9 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -81,17 +81,53 @@ * and by a series of task lists. All of these tasks lists are declared * below. Although it is not always necessary, most of these lists are * prioritized so that common list handling logic can be used (only the - * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists need - * to be prioritized). + * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists + * need to be prioritized). */ -/* This is the list of all tasks that are ready to run. The head of this - * list is the currently active task; the tail of this list is always the - * IDLE task. +/* This is the list of all tasks that are ready to run. This is a + * prioritized list with head of the list holding the highest priority + * (unassigned) task. In the non-SMP cae, the head of this list is the + * currently active task and the tail of this list, the lowest priority + * task, is always the IDLE task. */ volatile dq_queue_t g_readytorun; +#ifdef CONFIG_SMP +/* In order to support SMP, the function of the g_readytorun list changes, + * The g_readytorun is still used but in the SMP cae it will contain only: + * + * - Only tasks/threads that are eligible to run, but not currently running, + * and + * - Tasks/threads that have not been assigned to a CPU. + * + * Otherwise, the TCB will be reatined in an assigned task list, + * g_assignedtasks. As its name suggests, on 'g_assignedtasks queue for CPU + * 'n' would contain only tasks/threads that are assigned to CPU 'n'. Tasks/ + * threads would be assigned a particular CPU by one of two mechanisms: + * + * - (Semi-)permanently through an RTOS interfaces such as + * pthread_attr_setaffinity(), or + * - Temporarily through scheduling logic when a previously unassigned task + * is made to run. + * + * Tasks/threads that are assigned to a CPU via an interface like + * pthread_attr_setaffinity() would never go into the g_readytorun list, but + * would only go into the g_assignedtasks[n] list for the CPU 'n' to which + * the thread has been assigned. Hence, the g_readytorun list would hold + * only unassigned tasks/threads. + * + * Like the g_readytorun list in in non-SMP case, each g_assignedtask[] list + * is prioritized: The head of the list is the currently active task on this + * CPU. Tasks after the active task are ready-to-run and assigned to this + * CPU. The tail of this assigned task list, the lowest priority task, is + * always the CPU's IDLE task. + */ + +volatile dq_queue_t g_assignedtasks[CONFIG_SMP_NCPUS]; +#endif + /* This is the list of all tasks that are ready-to-run, but cannot be placed * in the g_readytorun list because: (1) They are higher priority than the * currently active task at the head of the g_readytorun list, and (2) the diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 772711cc42..e97e66f265 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched.h * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include /**************************************************************************** @@ -68,9 +69,14 @@ * These macros are intended to support a future SMP implementation. */ -#define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) -#define this_cpu() (0) -#define this_task() (current_task(this_cpu)) +#ifdef CONFIG_SMP +# define current_task(cpu) ((FAR struct tcb_s *)g_assignedtasks[cpu].head) +# define this_cpu() up_cpundx() +#else +# define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) +# define this_cpu() (0) +#endif +#define this_task() (current_task(this_cpu())) /**************************************************************************** * Public Type Definitions @@ -117,17 +123,53 @@ struct tasklist_s * and by a series of task lists. All of these tasks lists are declared * below. Although it is not always necessary, most of these lists are * prioritized so that common list handling logic can be used (only the - * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists need - * to be prioritized). + * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists + * need to be prioritized). */ -/* This is the list of all tasks that are ready to run. The head of this - * list is the currently active task; the tail of this list is always the - * IDLE task. +/* This is the list of all tasks that are ready to run. This is a + * prioritized list with head of the list holding the highest priority + * (unassigned) task. In the non-SMP cae, the head of this list is the + * currently active task and the tail of this list, the lowest priority + * task, is always the IDLE task. */ extern volatile dq_queue_t g_readytorun; +#ifdef CONFIG_SMP +/* In order to support SMP, the function of the g_readytorun list changes, + * The g_readytorun is still used but in the SMP cae it will contain only: + * + * - Only tasks/threads that are eligible to run, but not currently running, + * and + * - Tasks/threads that have not been assigned to a CPU. + * + * Otherwise, the TCB will be reatined in an assigned task list, + * g_assignedtasks. As its name suggests, on 'g_assignedtasks queue for CPU + * 'n' would contain only tasks/threads that are assigned to CPU 'n'. Tasks/ + * threads would be assigned a particular CPU by one of two mechanisms: + * + * - (Semi-)permanently through an RTOS interfaces such as + * pthread_attr_setaffinity(), or + * - Temporarily through scheduling logic when a previously unassigned task + * is made to run. + * + * Tasks/threads that are assigned to a CPU via an interface like + * pthread_attr_setaffinity() would never go into the g_readytorun list, but + * would only go into the g_assignedtasks[n] list for the CPU 'n' to which + * the thread has been assigned. Hence, the g_readytorun list would hold + * only unassigned tasks/threads. + * + * Like the g_readytorun list in in non-SMP case, each g_assignedtask[] list + * is prioritized: The head of the list is the currently active task on this + * CPU. Tasks after the active task are ready-to-run and assigned to this + * CPU. The tail of this assigned task list, the lowest priority task, is + * always the CPU's IDLE task. + */ + +extern volatile dq_queue_t g_assignedtasks[CONFIG_SMP_NCPUS]; +#endif + /* This is the list of all tasks that are ready-to-run, but cannot be placed * in the g_readytorun list because: (1) They are higher priority than the * currently active task at the head of the g_readytorun list, and (2) the -- GitLab From 3147dfc7d5fe2cad80afa016db691f2eff697852 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 13:49:27 -0600 Subject: [PATCH 704/858] SMP: Add some tentative initialization logic --- include/nuttx/arch.h | 29 +++++++ include/sys/types.h | 2 +- sched/init/Make.defs | 4 + sched/init/init.h | 36 +++++---- sched/init/os_bringup.c | 16 ---- sched/init/os_smpstart.c | 156 +++++++++++++++++++++++++++++++++++++ sched/init/os_start.c | 10 ++- sched/semaphore/spinlock.c | 4 +- 8 files changed, 224 insertions(+), 33 deletions(-) create mode 100644 sched/init/os_smpstart.c diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index bbca284eab..580ba4bd5e 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1682,6 +1682,35 @@ int up_cpundx(void); # define up_cpundx() (0) #endif +/**************************************************************************** + * Name: up_cpustart + * + * Description: + * In an SMP configution, only one CPU is initially active (CPU 0). System + * initialization occurs on that single thread. At the completion of the + * initialization of the OS, just before beginning normal multitasking, + * the additional CPUs would be started by calling this function. + * + * Each CPU is provided the entry point to is IDLE task when started. The + * OS initialization logic calls this function repeatedly until each CPU + * has been started. + * + * Input Parameters: + * cpu - The index of the CPU being started. This will be a numeric + * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU + * 0 is already active) + * idletask - The entry point to the IDLE task. + * + * Returned Value: + * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int up_cpustart(int cpu, main_t idletask); +#endif + /**************************************************************************** * Name: up_romgetc * diff --git a/include/sys/types.h b/include/sys/types.h index 298414c408..cc6672d2c0 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -262,7 +262,7 @@ typedef FAR char *caddr_t; /* Task entry point */ -typedef CODE int (*main_t)(int argc, char *argv[]); +typedef CODE int (*main_t)(int argc, FAR char *argv[]); #endif /* __ASSEMBLY__ */ diff --git a/sched/init/Make.defs b/sched/init/Make.defs index eae5e2fa87..46c0718c8e 100644 --- a/sched/init/Make.defs +++ b/sched/init/Make.defs @@ -35,6 +35,10 @@ CSRCS += os_start.c os_bringup.c +ifeq ($(CONFIG_SMP),y) +CSRCS += os_smpstart.c +endif + # Include init build support DEPPATH += --dep-path init diff --git a/sched/init/init.h b/sched/init/init.h index 8d60a71694..d87b0341f3 100644 --- a/sched/init/init.h +++ b/sched/init/init.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/init/init.h * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,21 +42,10 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ + /**************************************************************************** * Name: os_start * @@ -75,6 +64,27 @@ void os_start(void); +/**************************************************************************** + * Name: os_smpstart + * + * Description: + * In an SMP configution, only one CPU is initially active (CPU 0). System + * initialization occurs on that single thread. At the completion of the + * initialization of the OS, just before beginning normal multitasking, + * the additional CPUs would be started by calling this function. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero on success; a negater errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int os_smpstart(void); +#endif + /**************************************************************************** * Name: os_bringup * diff --git a/sched/init/os_bringup.c b/sched/init/os_bringup.c index 405b93d0a9..1652a36b7f 100644 --- a/sched/init/os_bringup.c +++ b/sched/init/os_bringup.c @@ -124,22 +124,6 @@ # undef CONFIG_LIB_USRWORK #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c new file mode 100644 index 0000000000..0bd33ffb8e --- /dev/null +++ b/sched/init/os_smpstart.c @@ -0,0 +1,156 @@ +/**************************************************************************** + * sched/init/os_smpstart.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +# include "init/init.h" + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: os_idletask + * + * Description: + * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). + * It is equivalent to the CPU 0 IDLE logic in os_start.c + * + * Input Parameters: + * Standard task arguments. + * + * Returned Value: + * This function does not return. + * + ****************************************************************************/ + +int os_idletask(int argc, FAR char *argv[]) +{ + sdbg("CPU%d: Beginning Idle Loop\n"); + for (; ; ) + { + /* Perform garbage collection (if it is not being done by the worker + * thread). This cleans-up memory de-allocations that were queued + * because they could not be freed in that execution context (for + * example, if the memory was freed from an interrupt handler). + */ + +#ifndef CONFIG_SCHED_WORKQUEUE + /* We must have exclusive access to the memory manager to do this + * BUT the idle task cannot wait on a semaphore. So we only do + * the cleanup now if we can get the semaphore -- this should be + * possible because if the IDLE thread is running, no other task is! + * + * WARNING: This logic could have undesirable side-effects if priority + * inheritance is enabled. Imaginee the possible issues if the + * priority of the IDLE thread were to get boosted! Moral: If you + * use priority inheritance, then you should also enable the work + * queue so that is done in a safer context. + */ + + if (kmm_trysemaphore() == 0) + { + sched_garbagecollection(); + kmm_givesemaphore(); + } +#endif + + /* Perform any processor-specific idle state operations */ + + up_idle(); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: os_smpstart + * + * Description: + * In an SMP configution, only one CPU is initially active (CPU 0). System + * initialization occurs on that single thread. At the completion of the + * initialization of the OS, just before beginning normal multitasking, + * the additional CPUs would be started by calling this function. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero on success; a negater errno value on failure. + * + ****************************************************************************/ + +int os_smpstart(void) +{ + int ret; + int i; + + for (i = 1; i < CONFIG_SMP_NCPUS; i++) + { + ret = up_cpustart(i, os_idletask); +#ifdef CONFIG_DEBUG + if (ret < 0) + { + sdbg("ERROR: Failed to start CPU%d: %d\n", i, ret); + return ret; + } +#else + UNUSED(ret); +#endif + } + + return OK; +} + +#endif /* CONFIG_SMP */ diff --git a/sched/init/os_start.c b/sched/init/os_start.c index f64a33bae9..a9696c8943 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -588,6 +588,14 @@ void os_start(void) g_idletcb.cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT; #endif +#ifdef CONFIG_SMP + /* Start all CPUs *********************************************************/ + + DEBUGASSERT(this_cpu() == 0); + DEBUGVERIFY(os_smpstart()); + +#endif /* CONFIG_SMP */ + /* Bring Up the System ****************************************************/ /* The OS is fully initialized and we are beginning multi-tasking */ @@ -600,7 +608,7 @@ void os_start(void) /* The IDLE Loop **********************************************************/ /* When control is return to this point, the system is idle. */ - sdbg("Beginning Idle Loop\n"); + sdbg("CPU0: Beginning Idle Loop\n"); for (; ; ) { /* Perform garbage collection (if it is not being done by the worker diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index 20bb3d048a..ef6dd021a4 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -234,7 +234,7 @@ void spinunlock(FAR struct spinlock_s *lock) lock->sp_count = 0; lock->sp_cpu = IMPOSSIBLE_CPU; - lock->sp_lock = SP_UNLOCKED; + lock->sp_lock = SP_UNLOCKED; } else { @@ -248,7 +248,7 @@ void spinunlock(FAR struct spinlock_s *lock) /* Just mark the spinlock unlocked */ DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED); - lock->sp_lock = SP_UNLOCKED; + lock->sp_lock = SP_UNLOCKED; #endif /* CONFIG_SMP */ } -- GitLab From 8a1789ba11fac5f70e4f3764354c2ffcac92f46b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 14:58:55 -0600 Subject: [PATCH 705/858] Update ChangeLog --- ChangeLog | 7 +++++++ arch | 2 +- include/nuttx/arch.h | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36077eb2d4..c8209c9b9b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11473,4 +11473,11 @@ needed to supports spinlocks (2016-02-09). * include/nuttx/spinlock.h: Add basic definitions for spinlocks. Not yet used by NuttX (2016-02-09). + * include/nuttx/arch.h, sched/sched/sched.h: Add some basic definitions + that may be needed for SMP support (2016-02-10). + * sched/init/os_start.c, sched/init/os_smpstart.c, and include/nuttx/arch.h: + Add some tentative SMP start-up logic (2016-02-10). + * arch/arm/sim/up_head.c and up_simsmp.c: Add multi-CPU support to the + simulation to support SMP investigation.. Currently crashes when CONFIG_SMP + is enabled as expected (2016-02-10). diff --git a/arch b/arch index 0ddf09674e..d0e073560a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0ddf09674eb2115ecfedaa82e21a2c43fc09d127 +Subproject commit d0e073560a899d50196e487247ccab7d7f74abec diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 580ba4bd5e..488cbb9815 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1702,8 +1702,7 @@ int up_cpundx(void); * idletask - The entry point to the IDLE task. * * Returned Value: - * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that - * corresponds to the currently executing CPU. + * Zero on success; a negated errno value on failure. * ****************************************************************************/ -- GitLab From 96223cedf173040c9435b088cc6126f59eae2f2e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 15:43:05 -0600 Subject: [PATCH 706/858] SMP: A little more --- include/nuttx/sched.h | 12 ++++++++---- sched/init/os_start.c | 15 +++++++++++++++ sched/sched/sched.h | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index b25f64e219..7372db28b0 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -137,9 +137,9 @@ #define TCB_FLAG_TTYPE_SHIFT (0) /* Bits 0-1: thread type */ #define TCB_FLAG_TTYPE_MASK (3 << TCB_FLAG_TTYPE_SHIFT) -# define TCB_FLAG_TTYPE_TASK (0 << TCB_FLAG_TTYPE_SHIFT) /* Normal user task */ -# define TCB_FLAG_TTYPE_PTHREAD (1 << TCB_FLAG_TTYPE_SHIFT) /* User pthread */ -# define TCB_FLAG_TTYPE_KERNEL (2 << TCB_FLAG_TTYPE_SHIFT) /* Kernel thread */ +# define TCB_FLAG_TTYPE_TASK (0 << TCB_FLAG_TTYPE_SHIFT) /* Normal user task */ +# define TCB_FLAG_TTYPE_PTHREAD (1 << TCB_FLAG_TTYPE_SHIFT) /* User pthread */ +# define TCB_FLAG_TTYPE_KERNEL (2 << TCB_FLAG_TTYPE_SHIFT) /* Kernel thread */ #define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */ #define TCB_FLAG_CANCEL_PENDING (1 << 3) /* Bit 3: Pthread cancel is pending */ #define TCB_FLAG_POLICY_SHIFT (4) /* Bit 4-5: Scheduling policy */ @@ -148,7 +148,8 @@ # define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */ # define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */ # define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */ -#define TCB_FLAG_EXIT_PROCESSING (1 << 6) /* Bit 6: Exitting */ +#define TCB_FLAG_EXIT_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */ +#define TCB_FLAG_EXIT_PROCESSING (1 << 7) /* Bit 7: Exitting */ /* Values for struct task_group tg_flags */ @@ -547,6 +548,9 @@ struct tcb_s #endif uint8_t task_state; /* Current state of the thread */ +#ifdef CONFIG_SMP + uint8_t cpu; /* CPU index if running or assigned */ +#endif uint16_t flags; /* Misc. general status flags */ int16_t lockcount; /* 0=preemptable (not-locked) */ diff --git a/sched/init/os_start.c b/sched/init/os_start.c index a9696c8943..9bfcc9c7c2 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -328,6 +328,13 @@ void os_start(void) sq_init(&g_delayed_kufree); #endif +#ifdef CONFIG_SMP + for (i = 0; i < CONFIG_SMP_NCPUS; i++) + { + dq_init(&g_assignedtasks[i]); + } +#endif + /* Initialize the logic that determine unique process IDs. */ g_lastpid = 0; @@ -380,7 +387,15 @@ void os_start(void) /* Then add the idle task's TCB to the head of the ready to run list */ +#ifdef CONFIG_SMP + /* Use the list a ready-to-run tasks assigned to CPU0 */ + + dq_addfirst((FAR dq_entry_t *)&g_idletcb, (FAR dq_queue_t *)&g_assignedtasks[0]); +#else + /* Use the common, unassigned ready-to-run list */ + dq_addfirst((FAR dq_entry_t *)&g_idletcb, (FAR dq_queue_t *)&g_readytorun); +#endif /* Initialize the processor-specific portion of the TCB */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index e97e66f265..793de67a24 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -138,7 +138,7 @@ extern volatile dq_queue_t g_readytorun; #ifdef CONFIG_SMP /* In order to support SMP, the function of the g_readytorun list changes, - * The g_readytorun is still used but in the SMP cae it will contain only: + * The g_readytorun is still used but in the SMP case it will contain only: * * - Only tasks/threads that are eligible to run, but not currently running, * and -- GitLab From 292d2fe64821039ba09bda02d04adc06050f9800 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 16:53:34 -0600 Subject: [PATCH 707/858] Correct naming of a TCB flag; update some comments --- include/nuttx/sched.h | 2 +- sched/sched/sched.h | 12 ++++++++++++ sched/task/task_getpid.c | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 7372db28b0..61381b0682 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -148,7 +148,7 @@ # define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */ # define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */ # define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */ -#define TCB_FLAG_EXIT_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */ +#define TCB_FLAG_CPU_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */ #define TCB_FLAG_EXIT_PROCESSING (1 << 7) /* Bit 7: Exitting */ /* Values for struct task_group tg_flags */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 793de67a24..ed03755dc7 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -275,6 +275,8 @@ extern volatile uint32_t g_cpuload_total; * Public Function Prototypes ****************************************************************************/ +/* Task list manipulation functions */ + bool sched_addreadytorun(FAR struct tcb_s *rtrtcb); bool sched_removereadytorun(FAR struct tcb_s *rtrtcb); bool sched_addprioritized(FAR struct tcb_s *newTcb, DSEG dq_queue_t *list); @@ -283,6 +285,8 @@ void sched_addblocked(FAR struct tcb_s *btcb, tstate_t task_state); void sched_removeblocked(FAR struct tcb_s *btcb); int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority); +/* Priority inheritance support */ + #ifdef CONFIG_PRIORITY_INHERITANCE int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority); #else @@ -290,6 +294,8 @@ int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority); sched_setpriority(tcb,sched_priority) #endif +/* Support for tickless operation */ + #ifdef CONFIG_SCHED_TICKLESS unsigned int sched_timer_cancel(void); void sched_timer_resume(void); @@ -300,6 +306,8 @@ void sched_timer_reassess(void); # define sched_timer_reassess() #endif +/* Scheduler policy support */ + #if CONFIG_RR_INTERVAL > 0 uint32_t sched_roundrobin_process(FAR struct tcb_s *tcb, uint32_t ticks, bool noswitches); @@ -317,10 +325,14 @@ uint32_t sched_sporadic_process(FAR struct tcb_s *tcb, uint32_t ticks, void sched_sporadic_lowpriority(FAR struct tcb_s *tcb); #endif +/* CPU load measurement support */ + #if defined(CONFIG_SCHED_CPULOAD) && !defined(CONFIG_SCHED_CPULOAD_EXTCLK) void weak_function sched_process_cpuload(void); #endif +/* TCB operations */ + bool sched_verifytcb(FAR struct tcb_s *tcb); int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype); diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index 2d972b039d..29ae703e87 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -62,9 +62,9 @@ pid_t getpid(void) /* Get the the TCB at the head of the ready-to-run task list. That * will be the currently executing task. There is an exception to - * this: Verify early in the start-up sequence, the g_readytorun - * list may be empty! This case, of course, the start-up/IDLE thread - * with pid == 0 must be running. + * this: Early in the start-up sequence, the ready-to-run list may be + * empty! This case, of course, the start-up/IDLE thread with pid == 0 + * must be running. */ rtcb = this_task(); @@ -78,7 +78,7 @@ pid_t getpid(void) } /* We must have been called earlier in the start up sequence from the - * start-up/IDLE thread before the g_readytorun list has been initialized. + * start-up/IDLE thread before the ready-to-run list has been initialized. */ return 0; -- GitLab From baac92cda2ba8021d0e0d4319140a2599b52572e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 16:55:37 -0600 Subject: [PATCH 708/858] Correct some columnar alignment --- include/nuttx/sched.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 61381b0682..d20a264895 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -126,8 +126,8 @@ /* Task Management Definitions **************************************************/ /* Special task IDS. Any negative PID is invalid. */ -#define NULL_TASK_PROCESS_ID (pid_t)0 -#define INVALID_PROCESS_ID (pid_t)-1 +#define NULL_TASK_PROCESS_ID (pid_t)0 +#define INVALID_PROCESS_ID (pid_t)-1 /* This is the maximum number of times that a lock can be set */ @@ -169,9 +169,9 @@ /* Sporadic scheduler flags */ -#define SPORADIC_FLAG_ALLOCED (1 << 0) /* Bit 0: Timer is allocated */ -#define SPORADIC_FLAG_MAIN (1 << 1) /* Bit 1: The main timer */ -#define SPORADIC_FLAG_REPLENISH (1 << 2) /* Bit 2: Replenishment cycle */ +#define SPORADIC_FLAG_ALLOCED (1 << 0) /* Bit 0: Timer is allocated */ +#define SPORADIC_FLAG_MAIN (1 << 1) /* Bit 1: The main timer */ +#define SPORADIC_FLAG_REPLENISH (1 << 2) /* Bit 2: Replenishment cycle */ /******************************************************************************** * Public Type Definitions @@ -211,10 +211,10 @@ typedef enum tstate_e tstate_t; /* The following definitions are determined by tstate_t */ -#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN -#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING -#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE -#define LAST_BLOCKED_STATE (NUM_TASK_STATES-1) +#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN +#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING +#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE +#define LAST_BLOCKED_STATE (NUM_TASK_STATES-1) /* The following is the form of a thread start-up function */ -- GitLab From 89bea6917c0e6b83a3e99a3016151aae60a26d75 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Feb 2016 17:31:16 -0600 Subject: [PATCH 709/858] Kconfig: Architecture must indicate that it support multiple CPUs in order to enable SMP --- arch | 2 +- sched/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index d0e073560a..7451a16948 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d0e073560a899d50196e487247ccab7d7f74abec +Subproject commit 7451a16948db82ad2a75723df73160357d816577 diff --git a/sched/Kconfig b/sched/Kconfig index 45e14fd095..5a31c6727d 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -240,7 +240,7 @@ config SPINLOCK config SMP bool "Symmetric Multi-Processing (SMP)" default n - depends on EXPERIMENTAL + depends on ARCH_HAVE_MULTICPU && EXPERIMENTAL select SPINLOCK ---help--- Enable support for Symmetric Multi-Processing (SMP) on a multi-CPU -- GitLab From 0a7e136a5a674fec18bb5ceeb4e4f588f99b2ea1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 08:01:09 -0600 Subject: [PATCH 710/858] SMP: Idle thread must be assigned to a CPU --- sched/init/os_smpstart.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 0bd33ffb8e..bfbc49d509 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -46,14 +46,11 @@ #include #include +# include "sched/sched.h" # include "init/init.h" #ifdef CONFIG_SMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -75,6 +72,23 @@ int os_idletask(int argc, FAR char *argv[]) { + FAR struct tcb_s *rtcb = this_task(); + irqstate_t flags; + int cpu = this_cpu(); + + /* Make sure that this thread is assigned to the current CPU */ + + DEBUGASSERT(rtcb->cpu == cpu); + + /* REVISIT: disabling interrupts is not sufficient protection */ + + flags = irqsave(); + rtcb->flags |= TCB_FLAG_CPU_ASSIGNED; + rtcb->cpu = cpu; + irqrestore(flags); + + /* Then enter the IDLE loop */ + sdbg("CPU%d: Beginning Idle Loop\n"); for (; ; ) { -- GitLab From 49227fa554e327f03334ad204ab3ccb4bcca18f7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 08:06:33 -0600 Subject: [PATCH 711/858] Scheduler: Replace the boolean 'prioritized' with a uint8_t bit set so that additional attributes of a list can be specified without adding more boolean values. --- ChangeLog | 3 + include/nuttx/sched.h | 7 ++ sched/init/os_start.c | 84 +++++++++++++++++----- sched/sched/sched.h | 51 +++++++++---- sched/sched/sched_addblocked.c | 45 ++++-------- sched/sched/sched_removeblocked.c | 30 ++------ sched/sched/sched_setpriority.c | 49 ++++--------- sched/task/task_restart.c | 115 +++++++++++++++++------------- sched/task/task_terminate.c | 46 +++++------- 9 files changed, 230 insertions(+), 200 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8209c9b9b..a994b05c15 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11480,4 +11480,7 @@ * arch/arm/sim/up_head.c and up_simsmp.c: Add multi-CPU support to the simulation to support SMP investigation.. Currently crashes when CONFIG_SMP is enabled as expected (2016-02-10). + * sched/sched.h and other files: Replace the bool 'prioritized' in the task + list table with a uint8_t bit set so that additional attributes of a task + list can be provided without adding more booleans (2016-10-11). diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index d20a264895..a0f3d13792 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -150,6 +150,7 @@ # define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */ #define TCB_FLAG_CPU_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */ #define TCB_FLAG_EXIT_PROCESSING (1 << 7) /* Bit 7: Exitting */ + /* Bits 8-15: Available */ /* Values for struct task_group tg_flags */ @@ -157,6 +158,7 @@ #define GROUP_FLAG_ADDRENV (1 << 1) /* Bit 1: Group has an address environment */ #define GROUP_FLAG_PRIVILEGED (1 << 2) /* Bit 2: Group is privileged */ #define GROUP_FLAG_DELETED (1 << 3) /* Bit 3: Group has been deleted but not yet freed */ + /* Bits 4-7: Available */ /* Values for struct child_status_s ch_flags */ @@ -166,12 +168,14 @@ # define CHILD_FLAG_TTYPE_PTHREAD (1 << CHILD_FLAG_TTYPE_SHIFT) /* User pthread */ # define CHILD_FLAG_TTYPE_KERNEL (2 << CHILD_FLAG_TTYPE_SHIFT) /* Kernel thread */ #define CHILD_FLAG_EXITED (1 << 0) /* Bit 2: The child thread has exit'ed */ + /* Bits 3-7: Available */ /* Sporadic scheduler flags */ #define SPORADIC_FLAG_ALLOCED (1 << 0) /* Bit 0: Timer is allocated */ #define SPORADIC_FLAG_MAIN (1 << 1) /* Bit 1: The main timer */ #define SPORADIC_FLAG_REPLENISH (1 << 2) /* Bit 2: Replenishment cycle */ + /* Bits 3-7: Available */ /******************************************************************************** * Public Type Definitions @@ -191,6 +195,9 @@ enum tstate_e TSTATE_TASK_INVALID = 0, /* INVALID - The TCB is uninitialized */ TSTATE_TASK_PENDING, /* READY_TO_RUN - Pending preemption unlock */ TSTATE_TASK_READYTORUN, /* READY-TO-RUN - But not running */ +#ifdef CONFIG_SMP + TSTATE_TASK_ASSIGNED, /* READY-TO-RUN - Not running, but assigned to a CPU */ +#endif TSTATE_TASK_RUNNING, /* READY_TO_RUN - And running */ TSTATE_TASK_INACTIVE, /* BLOCKED - Initialized but not yet activated */ diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 9bfcc9c7c2..95fd9526c9 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -203,8 +203,8 @@ volatile pid_t g_lastpid; /* The following hash table is used for two things: * - * 1. This hash table greatly speeds the determination of - * a new unique process ID for a task, and + * 1. This hash table greatly speeds the determination of a new unique + * process ID for a task, and * 2. Is used to quickly map a process ID into a TCB. * It has the side effects of using more memory and limiting * @@ -213,33 +213,74 @@ volatile pid_t g_lastpid; struct pidhash_s g_pidhash[CONFIG_MAX_TASKS]; -/* This is a table of task lists. This table is indexed by - * the task state enumeration type (tstate_t) and provides - * a pointer to the associated static task list (if there - * is one) as well as a boolean indication as to if the list - * is an ordered list or not. +/* This is a table of task lists. This table is indexed by the task stat + * enumeration type (tstate_t) and provides a pointer to the associated + * static task list (if there is one) as well as a a set of attribute flags + * indicating properities of the list, for example, if the list is an + * ordered list or not. */ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] = { - { NULL, false }, /* TSTATE_TASK_INVALID */ - { &g_pendingtasks, true }, /* TSTATE_TASK_PENDING */ - { &g_readytorun, true }, /* TSTATE_TASK_READYTORUN */ - { &g_readytorun, true }, /* TSTATE_TASK_RUNNING */ - { &g_inactivetasks, false }, /* TSTATE_TASK_INACTIVE */ - { &g_waitingforsemaphore, true } /* TSTATE_WAIT_SEM */ + { /* TSTATE_TASK_INVALID */ + NULL, + 0 + }, + { /* TSTATE_TASK_PENDING */ + &g_pendingtasks, + TLIST_ATTR_PRIORITIZED + }, + { /* TSTATE_TASK_READYTORUN */ + &g_readytorun, + TLIST_ATTR_PRIORITIZED + }, +#ifdef CONFIG_SMP + { /* TSTATE_TASK_ASSIGNED */ + g_assignedtasks, + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED + }, + { /* TSTATE_TASK_RUNNING */ + g_assignedtasks, + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED + }, +#else + { /* TSTATE_TASK_RUNNING */ + &g_readytorun, + TLIST_ATTR_PRIORITIZED + }, +#endif + { /* TSTATE_TASK_INACTIVE */ + &g_inactivetasks, + 0 + }, + { /* TSTATE_WAIT_SEM */ + &g_waitingforsemaphore, + TLIST_ATTR_PRIORITIZED + } #ifndef CONFIG_DISABLE_SIGNALS , - { &g_waitingforsignal, false } /* TSTATE_WAIT_SIG */ + { /* TSTATE_WAIT_SIG */ + &g_waitingforsignal, + 0 + } #endif #ifndef CONFIG_DISABLE_MQUEUE , - { &g_waitingformqnotempty, true }, /* TSTATE_WAIT_MQNOTEMPTY */ - { &g_waitingformqnotfull, true } /* TSTATE_WAIT_MQNOTFULL */ + { /* TSTATE_WAIT_MQNOTEMPTY */ + &g_waitingformqnotempty, + TLIST_ATTR_PRIORITIZED + }, + { /* TSTATE_WAIT_MQNOTFULL */ + &g_waitingformqnotfull, + TLIST_ATTR_PRIORITIZED + } #endif #ifdef CONFIG_PAGING , - { &g_waitingforfill, true } /* TSTATE_WAIT_PAGEFILL */ + { /* TSTATE_WAIT_PAGEFILL */ + &g_waitingforfill, + TLIST_ATTR_PRIORITIZED + } #endif }; @@ -360,7 +401,16 @@ void os_start(void) bzero((void *)&g_idletcb, sizeof(struct task_tcb_s)); g_idletcb.cmn.task_state = TSTATE_TASK_RUNNING; g_idletcb.cmn.entry.main = (main_t)os_start; + + /* Set the task flags to indicate that this is a kernel thread and, if + * configured for SMP, that this task is assigned to CPU0. + */ + +#ifdef CONFIG_SMP + g_idletcb.cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); +#else g_idletcb.cmn.flags = TCB_FLAG_TTYPE_KERNEL; +#endif /* Set the IDLE task name */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index ed03755dc7..1838a559e6 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -62,21 +62,44 @@ * tasks built into the design). */ -#define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) -#define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) +#define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) +#define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) /* These are macros to access the current CPU and the current task on a CPU. * These macros are intended to support a future SMP implementation. */ #ifdef CONFIG_SMP -# define current_task(cpu) ((FAR struct tcb_s *)g_assignedtasks[cpu].head) -# define this_cpu() up_cpundx() +# define current_task(cpu) ((FAR struct tcb_s *)g_assignedtasks[cpu].head) +# define this_cpu() up_cpundx() #else -# define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) -# define this_cpu() (0) +# define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) +# define this_cpu() (0) +#endif +#define this_task() (current_task(this_cpu())) + +/* List attribute flags */ + +#define TLIST_ATTR_PRIORITIZED (1 << 0) /* Bit 0: List is prioritized */ +#define TLIST_ATTR_INDEXED (1 << 1) /* Bit 1: List is indexed by CPU */ + +#define __TLIST_ATTR(s) g_tasklisttable[s].attr +#define TLIST_ISPRIORITIZED(s) ((__TLIST_ATTR(s) & TLIST_ATTR_PRIORITIZED) != 0) +#define TLIST_ISINDEXED(s) ((__TLIST_ATTR(s) & TLIST_ATTR_INDEXED) != 0) + +#define __TLIST_HEAD(s) (FAR dq_queue_t *)g_tasklisttable[s].list +#define __TLIST_HEADINDEXED(s,c) (&(__TLIST_HEAD(s))[c]) + +#ifdef CONFIG_SMP +# define TLIST_HEAD(s,c) \ + ((TLIST_ISINDEXED(s)) ? __TLIST_HEADINDEXED(s,c) : __TLIST_HEAD(s)) +# define TLIST_READYTORUN(s,c) __TLIST_HEADINDEXED(s,c) +# define TLIST_BLOCKED(s) __TLIST_HEAD(s) +#else +# define TLIST_HEAD(s) __TLIST_HEAD(s) +# define TLIST_READYTORUN(s) __TLIST_HEAD(s) +# define TLIST_BLOCKED(s) __TLIST_HEAD(s) #endif -#define this_task() (current_task(this_cpu())) /**************************************************************************** * Public Type Definitions @@ -102,15 +125,14 @@ struct pidhash_s #endif }; -/* This structure defines an element of the g_tasklisttable[]. - * This table is used to map a task_state enumeration to the - * corresponding task list. +/* This structure defines an element of the g_tasklisttable[]. This table + * is used to map a task_state enumeration to the corresponding task list. */ struct tasklist_s { DSEG volatile dq_queue_t *list; /* Pointer to the task list */ - bool prioritized; /* true if the list is prioritized */ + uint8_t attr; /* List attribute flags */ }; /**************************************************************************** @@ -255,10 +277,11 @@ extern volatile pid_t g_lastpid; extern struct pidhash_s g_pidhash[CONFIG_MAX_TASKS]; -/* This is a table of task lists. This table is indexed by the task state +/* This is a table of task lists. This table is indexed by the task stat * enumeration type (tstate_t) and provides a pointer to the associated - * static task list (if there is one) as well as a boolean indication as to - * if the list is an ordered list or not. + * static task list (if there is one) as well as a a set of attribute flags + * indicating properities of the list, for example, if the list is an + * ordered list or not. */ extern const struct tasklist_s g_tasklisttable[NUM_TASK_STATES]; diff --git a/sched/sched/sched_addblocked.c b/sched/sched/sched_addblocked.c index 05a8742431..34303681c5 100644 --- a/sched/sched/sched_addblocked.c +++ b/sched/sched/sched_addblocked.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_addblocked.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,26 +44,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,29 +70,30 @@ void sched_addblocked(FAR struct tcb_s *btcb, tstate_t task_state) { + FAR dq_queue_t *tasklist; + /* Make sure that we received a valid blocked state */ - ASSERT(task_state >= FIRST_BLOCKED_STATE && - task_state <= LAST_BLOCKED_STATE); + DEBUGASSERT(task_state >= FIRST_BLOCKED_STATE && + task_state <= LAST_BLOCKED_STATE); + + /* Add the TCB to the blocked task list associated with this state. */ + + tasklist = TLIST_BLOCKED(task_state); - /* Add the TCB to the blocked task list associated with this state. - * First, determine if the task is to be added to a prioritized task - * list - */ + /* Determine if the task is to be added to a prioritized task list. */ - if (g_tasklisttable[task_state].prioritized) + if (TLIST_ISPRIORITIZED(task_state)) { /* Add the task to a prioritized list */ - sched_addprioritized(btcb, - (FAR dq_queue_t *)g_tasklisttable[task_state].list); + sched_addprioritized(btcb, tasklist); } else { /* Add the task to a non-prioritized list */ - dq_addlast((FAR dq_entry_t *)btcb, - (FAR dq_queue_t *)g_tasklisttable[task_state].list); + dq_addlast((FAR dq_entry_t *)btcb, tasklist); } /* Make sure the TCB's state corresponds to the list */ diff --git a/sched/sched/sched_removeblocked.c b/sched/sched/sched_removeblocked.c index 7b6b983b04..36c92e96f0 100644 --- a/sched/sched/sched_removeblocked.c +++ b/sched/sched/sched_removeblocked.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_removeblocked.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,26 +44,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,15 +73,14 @@ void sched_removeblocked(FAR struct tcb_s *btcb) /* Make sure the TCB is in a valid blocked state */ - ASSERT(task_state >= FIRST_BLOCKED_STATE && - task_state <= LAST_BLOCKED_STATE); + DEBUGASSERT(task_state >= FIRST_BLOCKED_STATE && + task_state <= LAST_BLOCKED_STATE); /* Remove the TCB from the blocked task list associated * with this state */ - dq_rem((FAR dq_entry_t *)btcb, - (FAR dq_queue_t *)g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t *)btcb, TLIST_BLOCKED(task_state)); /* Make sure the TCB's state corresponds to not being in * any list @@ -109,4 +88,3 @@ void sched_removeblocked(FAR struct tcb_s *btcb) btcb->task_state = TSTATE_TASK_INVALID; } - diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 3089756eec..5af005e2b7 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_setpriority.c * - * Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,30 +46,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -104,6 +80,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { FAR struct tcb_s *rtcb = this_task(); + FAR dq_queue_t *tasklist; tstate_t task_state; irqstate_t saved_state; @@ -127,8 +104,8 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) task_state = tcb->task_state; switch (task_state) { - /* CASE 1. The task is running or ready-to-run and a context switch - * may be caused by the re-prioritization + /* CASE 1. The task is and a context switch may be caused by the + * re-prioritization */ case TSTATE_TASK_RUNNING: @@ -155,11 +132,14 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) } break; - /* CASE 2. The task is running or ready-to-run and a context switch - * may be caused by the re-prioritization + /* CASE 2. The task is ready-to-run (but not running) and a context + * switch may be caused by the re-prioritization */ case TSTATE_TASK_READYTORUN: +#ifdef CONFIG_SMP + case TSTATE_TASK_ASSIGNED: +#endif /* A context switch will occur if the new priority of the ready-to * run task is (strictly) greater than the current running task @@ -188,7 +168,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) /* Put it back into the ready-to-run task list */ - ASSERT(!sched_addreadytorun(tcb)); + DEBUGASSERT(!sched_addreadytorun(tcb)); } break; @@ -200,12 +180,12 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) /* CASE 3a. The task resides in a prioritized list. */ - if (g_tasklisttable[task_state].prioritized) + tasklist = TLIST_BLOCKED(task_state); + if (TLIST_ISPRIORITIZED(task_state)) { /* Remove the TCB from the prioritized task list */ - dq_rem((FAR dq_entry_t *)tcb, - (FAR dq_queue_t *)g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t *)tcb, tasklist); /* Change the task priority */ @@ -215,8 +195,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) * position */ - sched_addprioritized(tcb, - (FAR dq_queue_t *)g_tasklisttable[task_state].list); + sched_addprioritized(tcb, tasklist); } /* CASE 3b. The task resides in a non-prioritized list. */ diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index 71c6f77adc..f72507756c 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_restart.c * - * Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -80,6 +80,7 @@ int task_restart(pid_t pid) { FAR struct tcb_s *rtcb; FAR struct task_tcb_s *tcb; + FAR dq_queue_t *tasklist; irqstate_t state; int status; @@ -100,84 +101,102 @@ int task_restart(pid_t pid) return ERROR; } - /* We are restarting some other task than ourselves */ +#ifdef CONFIG_SMP + /* There is currently no capability to restart a task that is actively + * running on another CPU either. This is not the calling cast so if it + * is running, then it could only be running a a different CPU. + * + * Also, will need some interlocks to assure that no tasks are rescheduled + * on any other CPU while we do this. + */ - else +#warning Missing SMP logic + if (rtcb->task_state == TSTATE_TASK_RUNNING) { - /* Find for the TCB associated with matching pid */ + /* Not implemented */ + + set_errno(ENOSYS); + return ERROR; + } +#endif + + /* We are restarting some other task than ourselves */ + /* Find for the TCB associated with matching pid */ - tcb = (FAR struct task_tcb_s *)sched_gettcb(pid); + tcb = (FAR struct task_tcb_s *)sched_gettcb(pid); #ifndef CONFIG_DISABLE_PTHREAD - if (!tcb || (tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) + if (!tcb || (tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) #else - if (!tcb) + if (!tcb) #endif - { - /* There is no TCB with this pid or, if there is, it is not a - * task. - */ + { + /* There is no TCB with this pid or, if there is, it is not a task. */ - set_errno(ESRCH); - return ERROR; - } + set_errno(ESRCH); + return ERROR; + } - /* Try to recover from any bad states */ + /* Try to recover from any bad states */ - task_recover((FAR struct tcb_s *)tcb); + task_recover((FAR struct tcb_s *)tcb); - /* Kill any children of this thread */ + /* Kill any children of this thread */ #ifdef HAVE_GROUP_MEMBERS - (void)group_killchildren(tcb); + (void)group_killchildren(tcb); #endif - /* Remove the TCB from whatever list it is in. At this point, the - * TCB should no longer be accessible to the system - */ + /* Remove the TCB from whatever list it is in. After this point, the TCB + * should no longer be accessible to the system + */ + +#ifdef CONFIG_SMP + tasklist = TLIST_HEAD(tcb->cmn.task_state, tcb->cmn.cpu); +#else + tasklist = TLIST_HEAD(tcb->cmn.task_state); +#endif - state = irqsave(); - dq_rem((FAR dq_entry_t *)tcb, - (FAR dq_queue_t *)g_tasklisttable[tcb->cmn.task_state].list); - tcb->cmn.task_state = TSTATE_TASK_INVALID; - irqrestore(state); + state = irqsave(); + dq_rem((FAR dq_entry_t *)tcb, tasklist); + tcb->cmn.task_state = TSTATE_TASK_INVALID; + irqrestore(state); - /* Deallocate anything left in the TCB's queues */ + /* Deallocate anything left in the TCB's queues */ - sig_cleanup((FAR struct tcb_s *)tcb); /* Deallocate Signal lists */ + sig_cleanup((FAR struct tcb_s *)tcb); /* Deallocate Signal lists */ - /* Reset the current task priority */ + /* Reset the current task priority */ - tcb->cmn.sched_priority = tcb->init_priority; + tcb->cmn.sched_priority = tcb->init_priority; - /* Reset the base task priority and the number of pending reprioritizations */ + /* Reset the base task priority and the number of pending reprioritizations */ #ifdef CONFIG_PRIORITY_INHERITANCE - tcb->cmn.base_priority = tcb->init_priority; + tcb->cmn.base_priority = tcb->init_priority; # if CONFIG_SEM_NNESTPRIO > 0 - tcb->cmn.npend_reprio = 0; + tcb->cmn.npend_reprio = 0; # endif #endif - /* Re-initialize the processor-specific portion of the TCB - * This will reset the entry point and the start-up parameters - */ + /* Re-initialize the processor-specific portion of the TCB. This will + * reset the entry point and the start-up parameters + */ - up_initial_state((FAR struct tcb_s *)tcb); + up_initial_state((FAR struct tcb_s *)tcb); - /* Add the task to the inactive task list */ + /* Add the task to the inactive task list */ - dq_addfirst((FAR dq_entry_t *)tcb, (FAR dq_queue_t *)&g_inactivetasks); - tcb->cmn.task_state = TSTATE_TASK_INACTIVE; + dq_addfirst((FAR dq_entry_t *)tcb, (FAR dq_queue_t *)&g_inactivetasks); + tcb->cmn.task_state = TSTATE_TASK_INACTIVE; - /* Activate the task */ + /* Activate the task */ - status = task_activate((FAR struct tcb_s *)tcb); - if (status != OK) - { - (void)task_delete(pid); - set_errno(-status); - return ERROR; - } + status = task_activate((FAR struct tcb_s *)tcb); + if (status != OK) + { + (void)task_delete(pid); + set_errno(-status); + return ERROR; } sched_unlock(); diff --git a/sched/task/task_terminate.c b/sched/task/task_terminate.c index 684c09da8d..f3abb7d825 100644 --- a/sched/task/task_terminate.c +++ b/sched/task/task_terminate.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_terminate.c * - * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -53,30 +53,6 @@ #endif #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -124,6 +100,7 @@ int task_terminate(pid_t pid, bool nonblocking) { FAR struct tcb_s *dtcb; + FAR dq_queue_t *tasklist; irqstate_t saved_state; /* Make sure the task does not become ready-to-run while we are futzing with @@ -143,6 +120,14 @@ int task_terminate(pid_t pid, bool nonblocking) return -ESRCH; } +#ifdef CONFIG_SMP + /* We will need some interlocks to assure that no tasks are rescheduled + * on any other CPU while we do this. + */ + +# warning Missing SMP logic +#endif + /* Verify our internal sanity */ if (dtcb->task_state == TSTATE_TASK_RUNNING || @@ -165,11 +150,16 @@ int task_terminate(pid_t pid, bool nonblocking) task_exithook(dtcb, EXIT_SUCCESS, nonblocking); - /* Remove the task from the OS's tasks lists. */ + /* Remove the task from the OS's task lists. */ + +#ifdef CONFIG_SMP + tasklist = TLIST_HEAD(dtcb->task_state, dtcb->cpu); +#else + tasklist = TLIST_HEAD(dtcb->task_state); +#endif saved_state = irqsave(); - dq_rem((FAR dq_entry_t *)dtcb, - (FAR dq_queue_t *)g_tasklisttable[dtcb->task_state].list); + dq_rem((FAR dq_entry_t *)dtcb, tasklist); dtcb->task_state = TSTATE_TASK_INVALID; irqrestore(saved_state); -- GitLab From ddbc94889509be9a9dfdb422f2da4bfd2f122834 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 12:18:54 -0600 Subject: [PATCH 712/858] SMP: Minor SMP-related clean-up/improvements --- arch | 2 +- configs | 2 +- sched/Kconfig | 9 +++++++++ sched/init/os_smpstart.c | 21 ++------------------- sched/init/os_start.c | 18 ++++++------------ 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/arch b/arch index 7451a16948..cf3c8382fa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7451a16948db82ad2a75723df73160357d816577 +Subproject commit cf3c8382fa36d28b1f153536368cfb07adfbb286 diff --git a/configs b/configs index 81a10b64ed..600d77e8b4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 81a10b64ed544684bb975e218e09ab5bc8aaf445 +Subproject commit 600d77e8b4631a67a6099b35a6959b6099b4a42b diff --git a/sched/Kconfig b/sched/Kconfig index 5a31c6727d..c30b672b1d 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -256,6 +256,15 @@ config SMP_NCPUS This value identifies the number of CPUs support by the processor that will be used for SMP. +config SMP_IDLETHREAD_STACKSIZE + int "CPU IDLE stack size" + default 2048 + ---help--- + Each CPU will have its own IDLE stack. System initialization occurs + on CPU0 and uses CONFIG_IDLETHREAD_STACKSIZE which will probably be + larger than is generally needed. This setting provides the STACK + size for the IDLE task on CPUS 1 through (CONFIG_SMP_NCPUS-1). + endif # SMP choice diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index bfbc49d509..351e90324a 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -40,14 +40,12 @@ #include #include -#include #include #include #include -# include "sched/sched.h" -# include "init/init.h" +#include "init/init.h" #ifdef CONFIG_SMP @@ -72,22 +70,7 @@ int os_idletask(int argc, FAR char *argv[]) { - FAR struct tcb_s *rtcb = this_task(); - irqstate_t flags; - int cpu = this_cpu(); - - /* Make sure that this thread is assigned to the current CPU */ - - DEBUGASSERT(rtcb->cpu == cpu); - - /* REVISIT: disabling interrupts is not sufficient protection */ - - flags = irqsave(); - rtcb->flags |= TCB_FLAG_CPU_ASSIGNED; - rtcb->cpu = cpu; - irqrestore(flags); - - /* Then enter the IDLE loop */ + /* Enter the IDLE loop */ sdbg("CPU%d: Beginning Idle Loop\n"); for (; ; ) diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 95fd9526c9..c0caabc8f7 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -300,20 +300,16 @@ uint8_t g_os_initstate; /* See enum os_initstate_e */ * initialization task is responsible for bringing up the rest of the system. */ -static FAR struct task_tcb_s g_idletcb; +static struct task_tcb_s g_idletcb; /* This is the name of the idle task */ -static FAR const char g_idlename[] = "Idle Task"; +static const char g_idlename[] = "Idle Task"; /* This the IDLE idle threads argument list. */ static FAR char *g_idleargv[2]; -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -336,6 +332,7 @@ static FAR char *g_idleargv[2]; void os_start(void) { + FAR dq_queue_t *tasklist; int i; slldbg("Entry\n"); @@ -438,14 +435,11 @@ void os_start(void) /* Then add the idle task's TCB to the head of the ready to run list */ #ifdef CONFIG_SMP - /* Use the list a ready-to-run tasks assigned to CPU0 */ - - dq_addfirst((FAR dq_entry_t *)&g_idletcb, (FAR dq_queue_t *)&g_assignedtasks[0]); + tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, 0); #else - /* Use the common, unassigned ready-to-run list */ - - dq_addfirst((FAR dq_entry_t *)&g_idletcb, (FAR dq_queue_t *)&g_readytorun); + tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING); #endif + dq_addfirst((FAR dq_entry_t *)&g_idletcb, tasklist); /* Initialize the processor-specific portion of the TCB */ -- GitLab From c315479a049e5bd0080b9ff0c32ddd1441acb6fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 14:11:26 -0600 Subject: [PATCH 713/858] SMP: Move IDLE thread init logic from sim to OS; need to assign unique IDs to each IDLE task --- arch | 2 +- include/nuttx/arch.h | 3 +- sched/init/os_smpstart.c | 190 +++++++++++++++++++++++++++++++++++++-- sched/init/os_start.c | 6 +- sched/task/task_create.c | 16 ---- sched/task/task_setup.c | 6 -- 6 files changed, 190 insertions(+), 33 deletions(-) diff --git a/arch b/arch index cf3c8382fa..df987248a7 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cf3c8382fa36d28b1f153536368cfb07adfbb286 +Subproject commit df987248a73f078f04d532f2b6d2b9ace867926d diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 488cbb9815..1eb455ee3d 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1700,6 +1700,7 @@ int up_cpundx(void); * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU * 0 is already active) * idletask - The entry point to the IDLE task. + * pid - Task ID of the IDLE task * * Returned Value: * Zero on success; a negated errno value on failure. @@ -1707,7 +1708,7 @@ int up_cpundx(void); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpustart(int cpu, main_t idletask); +int up_cpustart(int cpu, main_t idletask, pid_t pid); #endif /**************************************************************************** diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 351e90324a..63164845a3 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -40,15 +40,39 @@ #include #include +#include +#include +#include #include #include #include +#include +#include "group/group.h" +#include "sched/sched.h" #include "init/init.h" #ifdef CONFIG_SMP +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct os_tcballoc_s +{ + struct task_tcb_s tcb; /* IDLE task TCB */ + FAR char *idleargv[2]; /* Argument list */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if CONFIG_TASK_NAME_SIZE < 1 +static const char g_idlename[] = "CPUn Idle" +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -107,6 +131,130 @@ int os_idletask(int argc, FAR char *argv[]) } } +/**************************************************************************** + * Name: os_idletcb_setup + * + * Description: + * Initialize the IDLE task TCB for this CPU and add it to the correct OS + * task list. The calling sequence here is: + * + * 1. os_start() - Initializes the system and calls os_smpstart() + * 2. os_smpstart() - Calls up_cpustart() for each CPU 1..(CONFIG_SMP_NCPUS-1) + * 3. up_cpustart() - Calls os_idletcb_setup() when appropriate to configure + * the OS data structures. + * 4. up_cpustart() - may also call os_idletcb_teardown() to recover from + * from any errors. + * + * Input Parameters: + * cpu - The CPU to undel + * idle - Memory allocated by os_idletcb_setup + * pid - Task ID of the IDLE task + * + * Returned Value: + * Memory allocated by os_idletcb_setup (for error recovery). NULL is + * returned only a a failure to allocate memory. + * + ****************************************************************************/ + +static FAR void *os_idletcb_setup(int cpu, main_t idletask, pid_t pid) +{ + FAR struct os_tcballoc_s *alloc; + FAR struct task_tcb_s *itcb; + dq_queue_t *tasklist; + + /* IDLE TCB Initialization ************************************************/ + /* Allocate and clear the IDLE TCB */ + + alloc = (FAR struct os_tcballoc_s *)kmm_zalloc(sizeof(struct os_tcballoc_s)); + if (alloc == NULL) + { + return NULL; + } + + /* Initialize the TCB for the IDLE task on the stack. + * REVISIT: We should be able to use task_schedsetup() to do most of this + */ + + itcb = &alloc->tcb; + itcb->cmn.task_state = TSTATE_TASK_RUNNING; + itcb->cmn.entry.main = idletask; + itcb->cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); + itcb->cmn.cpu = cpu; + +#if CONFIG_TASK_NAME_SIZE > 0 + snprintf(itcb->cmn.name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", cpu); + alloc->idleargv[0] = itcb->cmn.name; +#else + alloc->idleargv[0] = (FAR char *)g_idlename; +#endif + alloc->idleargv[1] = NULL; + itcb->argv = alloc->idleargv; + + /* Add the IDLE task TCB to the end of the assigned task list */ + + tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, cpu); + dq_addfirst((FAR dq_entry_t *)itcb, tasklist); + + /* Initialize the processor-specific portion of the TCB */ + + up_initial_state(&itcb->cmn); + + /* PID assignment *********************************************************/ + + g_pidhash[PIDHASH(pid)].tcb = &itcb->cmn; + + /* IDLE Group Initialization **********************************************/ +#ifdef HAVE_TASK_GROUP + /* Allocate the IDLE group */ + + DEBUGVERIFY(group_allocate(itcb, itcb->cmn.flags)); +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Create stdout, stderr, stdin on the IDLE task. These will be + * inherited by all of the threads created by the IDLE task. + */ + + DEBUGVERIFY(group_setupidlefiles(itcb)); +#endif + +#ifdef HAVE_TASK_GROUP + /* Complete initialization of the IDLE group. Suppress retention + * of child status in the IDLE group. + */ + + DEBUGVERIFY(group_initialize(itcb)); + itcb->cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT; +#endif + + return alloc; +} + +/**************************************************************************** + * Name: os_idletcb_teardown + * + * Description: + * Undo what os_idletcb_setup() did. Necessary only for error recovery. + * + * Input Parameters: + * cpu - The CPU to undel + * alloc - Memory allocated by os_idletcb_setup + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void os_idletcb_teardown(int cpu, FAR void *alloc) +{ + /* Undo what os_idletcb_setup() did */ + + FAR dq_queue_t *tasklist= TLIST_HEAD(TSTATE_TASK_RUNNING, 0); + dq_init(tasklist); + + kmm_free(alloc); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -126,25 +274,51 @@ int os_idletask(int argc, FAR char *argv[]) * Returned Value: * Zero on success; a negater errno value on failure. * + * Assumption: + * Runs before the full initialization sequence has completed. Runs after + * all OS facilities are set up, but before multi-tasking has been started. + * ****************************************************************************/ int os_smpstart(void) { + FAR void *alloc; + pid_t pid; int ret; - int i; + int cpu; + + /* Reserve PIDs for IDLE tasks 1..(CONFIG_SMP_NCPUS-1). We do not have to + * be careful here because so far because there is only one CPU running and + * we have not yet started multi-tasking. + */ + + pid = g_lastpid + 1; /* Should be 1 */ + g_lastpid += CONFIG_SMP_NCPUS; /* Should be CONFIG_SMP_NCPUS */ + + /* CPU0 is already running. Start the remaining CPUs */ - for (i = 1; i < CONFIG_SMP_NCPUS; i++) + for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++, pid++) { - ret = up_cpustart(i, os_idletask); -#ifdef CONFIG_DEBUG + /* Assign a PID to the IDLE task and set up the IDLE thread TCB */ + + alloc = os_idletcb_setup(cpu, os_idletask, pid); + if (alloc == NULL) + { + return -ENOMEM; + } + + /* And start the CPU. */ + + ret = up_cpustart(cpu, os_idletask, pid); if (ret < 0) { - sdbg("ERROR: Failed to start CPU%d: %d\n", i, ret); + sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret); + + /* Undo what os_idletcb_setup() did and return the failure*/ + + os_idletcb_teardown(cpu, alloc); return ret; } -#else - UNUSED(ret); -#endif } return OK; diff --git a/sched/init/os_start.c b/sched/init/os_start.c index c0caabc8f7..4a5b776d93 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -304,7 +304,11 @@ static struct task_tcb_s g_idletcb; /* This is the name of the idle task */ +#ifdef CONFIG_SMP +static const char g_idlename[] = "CPU0 Idle"; +#else static const char g_idlename[] = "Idle Task"; +#endif /* This the IDLE idle threads argument list. */ @@ -650,7 +654,7 @@ void os_start(void) #ifdef CONFIG_SMP /* Start all CPUs *********************************************************/ - DEBUGASSERT(this_cpu() == 0); + DEBUGASSERT(this_cpu() == 0 && CONFIG_MAX_TASKS > CONFIG_SMP_NCPUS); DEBUGVERIFY(os_smpstart()); #endif /* CONFIG_SMP */ diff --git a/sched/task/task_create.c b/sched/task/task_create.c index e853b7d521..1ced3b9515 100644 --- a/sched/task/task_create.c +++ b/sched/task/task_create.c @@ -52,22 +52,6 @@ #include "group/group.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index d7730c6509..ee87fd93a9 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -70,12 +70,6 @@ static const char g_noname[] = ""; -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int task_assignpid(FAR struct tcb_s * tcb); - /**************************************************************************** * Private Functions ****************************************************************************/ -- GitLab From 76e88c896315b71ec761f01bc03557ff05ca72d5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 17:24:19 -0600 Subject: [PATCH 714/858] SMP: Removed unused macros, update comments, update sched_removereadytorun for SMP --- arch | 2 +- sched/sched/sched.h | 2 -- sched/sched/sched_addreadytorun.c | 45 ++++++++------------------- sched/sched/sched_removereadytorun.c | 46 +++++++++++----------------- 4 files changed, 31 insertions(+), 64 deletions(-) diff --git a/arch b/arch index df987248a7..717113268b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit df987248a73f078f04d532f2b6d2b9ace867926d +Subproject commit 717113268b97f16d755a11609a63526dfe71e4cf diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 1838a559e6..2abdb59dfa 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -93,11 +93,9 @@ #ifdef CONFIG_SMP # define TLIST_HEAD(s,c) \ ((TLIST_ISINDEXED(s)) ? __TLIST_HEADINDEXED(s,c) : __TLIST_HEAD(s)) -# define TLIST_READYTORUN(s,c) __TLIST_HEADINDEXED(s,c) # define TLIST_BLOCKED(s) __TLIST_HEAD(s) #else # define TLIST_HEAD(s) __TLIST_HEAD(s) -# define TLIST_READYTORUN(s) __TLIST_HEAD(s) # define TLIST_BLOCKED(s) __TLIST_HEAD(s) #endif diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 25f9e00e6c..23a0a2da91 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -45,26 +45,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -73,12 +53,11 @@ * Name: sched_addreadytorun * * Description: - * This function adds a TCB to the ready to run - * list. If the currently active task has preemption disabled - * and the new TCB would cause this task to be pre-empted, the - * new task is added to the g_pendingtasks list instead. The - * pending tasks will be made ready-to-run when preemption - * is unlocked. + * This function adds a TCB to the ready to run list. If the currently + * active task has preemption disabled and the new TCB would cause this + * task to be pre-empted, the new task is added to the g_pendingtasks list + * instead. Thepending tasks will be made ready-to-run when preemption is + * unlocked. * * Inputs: * btcb - Points to the blocked TCB that is ready-to-run @@ -88,13 +67,13 @@ * has changed. * * Assumptions: - * - The caller has established a critical section before - * calling this function (calling sched_lock() first is NOT - * a good idea -- use irqsave()). - * - The caller has already removed the input rtcb from - * whatever list it was in. - * - The caller handles the condition that occurs if the - * the head of the ready-to-run list is changed. + * - The caller has established a critical section before calling this + * function (calling sched_lock() first is NOT a good idea -- use + * irqsave()). + * - The caller has already removed the input rtcb from whatever list it + * was in. + * - The caller handles the condition that occurs if the head of the + * ready-to-run list is changed. * ****************************************************************************/ diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 9cad532f8c..eb71e63892 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -1,7 +1,7 @@ /**************************************************************************** * shced/sched_removereadytorun.c * - * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,26 +45,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -79,24 +59,25 @@ * rtcb - Points to the TCB that is ready-to-run * * Return Value: - * true if the currently active task (the head of the - * g_readytorun list) has changed. + * true if the currently active task (the head of the ready-to-run list) + * has changed. * * Assumptions: * - The caller has established a critical section before calling this * function (calling sched_lock() first is NOT a good idea -- use irqsave()). - * - The caller handles the condition that occurs if the - * the head of the g_readytorun list is changed. + * - The caller handles the condition that occurs if the head of the + * ready-to-run list is changed. * ****************************************************************************/ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { FAR struct tcb_s *ntcb = NULL; + FAR dq_queue_t *tasklist; bool ret = false; /* Check if the TCB to be removed is at the head of the ready to run list. - * In this case, we are removing the currently active task. + * In this case, we are removing the currently active task on this CPU. */ if (!rtcb->blink) @@ -113,9 +94,18 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) ret = true; } - /* Remove the TCB from the ready-to-run list */ + /* Remove the TCB from the ready-to-run list. In the non-SMP case, this + * is always the g_readytorun list; In the SMP case, however, this may be + * either the g_readytorun() or the g_assignedtasks[cpu] list. + */ + +#ifdef CONFIG_SMP + tasklist = TLIST_HEAD(rtcb->task_state, rtcb->cpu); +#else + tasklist = (FAR dq_queue_t *)&g_readytorun; +#endif - dq_rem((FAR dq_entry_t *)rtcb, (FAR dq_queue_t *)&g_readytorun); + dq_rem((FAR dq_entry_t *)rtcb, tasklist); /* Since the TCB is not in any list, it is now invalid */ -- GitLab From 7d7f4e140c8bd720d0cc25f86ed902c5a13a17aa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 12 Feb 2016 08:15:16 -0600 Subject: [PATCH 715/858] OS: Add a RUNNABLE attribute to the tasklists to indicate if the task list includes the currently executing task. Use this additional bit of information to determine if a context switch could really occur when removing a TCB from a task list --- arch | 2 +- configs | 2 +- sched/init/os_start.c | 12 ++++++++---- sched/sched/sched.h | 2 ++ sched/sched/sched_removereadytorun.c | 24 ++++++++++++++++++++++-- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/arch b/arch index 717113268b..a6ad88a85c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 717113268b97f16d755a11609a63526dfe71e4cf +Subproject commit a6ad88a85c9e4c6ab633fb53f53603539206a57c diff --git a/configs b/configs index 600d77e8b4..f9d09bf8c0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 600d77e8b4631a67a6099b35a6959b6099b4a42b +Subproject commit f9d09bf8c091cc2d8578ae572ad8f48bb93d062a diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 4a5b776d93..d201553387 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -230,23 +230,27 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] = &g_pendingtasks, TLIST_ATTR_PRIORITIZED }, +#ifdef CONFIG_SMP { /* TSTATE_TASK_READYTORUN */ &g_readytorun, TLIST_ATTR_PRIORITIZED }, -#ifdef CONFIG_SMP { /* TSTATE_TASK_ASSIGNED */ g_assignedtasks, - TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED | TLIST_ATTR_RUNNABLE }, { /* TSTATE_TASK_RUNNING */ g_assignedtasks, - TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED | TLIST_ATTR_RUNNABLE }, #else + { /* TSTATE_TASK_READYTORUN */ + &g_readytorun, + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE + }, { /* TSTATE_TASK_RUNNING */ &g_readytorun, - TLIST_ATTR_PRIORITIZED + TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE }, #endif { /* TSTATE_TASK_INACTIVE */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 2abdb59dfa..e48b421db6 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -82,10 +82,12 @@ #define TLIST_ATTR_PRIORITIZED (1 << 0) /* Bit 0: List is prioritized */ #define TLIST_ATTR_INDEXED (1 << 1) /* Bit 1: List is indexed by CPU */ +#define TLIST_ATTR_RUNNABLE (1 << 2) /* Bit 2: List includes running tasks */ #define __TLIST_ATTR(s) g_tasklisttable[s].attr #define TLIST_ISPRIORITIZED(s) ((__TLIST_ATTR(s) & TLIST_ATTR_PRIORITIZED) != 0) #define TLIST_ISINDEXED(s) ((__TLIST_ATTR(s) & TLIST_ATTR_INDEXED) != 0) +#define TLIST_ISRUNNABLE(s) ((__TLIST_ATTR(s) & TLIST_ATTR_RUNNABLE) != 0) #define __TLIST_HEAD(s) (FAR dq_queue_t *)g_tasklisttable[s].list #define __TLIST_HEADINDEXED(s,c) (&(__TLIST_HEAD(s))[c]) diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index eb71e63892..4fa2407040 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -76,11 +76,31 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) FAR dq_queue_t *tasklist; bool ret = false; - /* Check if the TCB to be removed is at the head of the ready to run list. - * In this case, we are removing the currently active task on this CPU. + /* Check if the TCB to be removed is at the head of a ready to run list. */ + +#ifdef CONFIG_SMP + /* For the case of SMP, there are two lists involved: (1) the + * g_readytorun list that holds non-running tasks that have not been + * assigned to a CPU, and (2) and the g_assignedtasks[] lists which hold + * tasks assigned a CPU, including the task that is currently running on + * that CPU. Only this latter list contains the currently active task + * only only removing the head of that list can result in a context + * switch. + * + * The tasklist RUNNABLE attribute will inform us if the list holds the + * currently executing and task and, hence, if a context switch could + * occur. + */ + + if (!rtcb->blink || TLIST_ISRUNNABLE(rtcb->task_state)) +#else + /* There is only one list, g_readytorun, and it always contains the + * currently running task. If we are removing the head of this list, + * then we are removing the currently active task. */ if (!rtcb->blink) +#endif { /* There must always be at least one task in the list (the idle task) */ -- GitLab From 85f663a8ee0783b5730f4e32ef92c27b818a899c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 12 Feb 2016 14:55:31 -0600 Subject: [PATCH 716/858] SMP: Add non-reentrant spinlocks, fix pre-emption controls with SMP, and most of the basic scheduler support for SMP (still missing a few things) --- include/nuttx/spinlock.h | 99 +++++++++++- sched/sched/sched.h | 79 +++++++++ sched/sched/sched_addreadytorun.c | 232 ++++++++++++++++++++++++++- sched/sched/sched_lock.c | 133 ++++++++++++++- sched/sched/sched_removereadytorun.c | 23 +++ sched/sched/sched_roundrobin.c | 4 +- sched/sched/sched_sporadic.c | 6 +- sched/sched/sched_unlock.c | 20 ++- sched/semaphore/spinlock.c | 57 +++++-- sched/task/task_exit.c | 24 ++- 10 files changed, 645 insertions(+), 32 deletions(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 640a639a6d..9305c40d50 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -100,7 +100,7 @@ struct spinlock_s spinlock_t up_testset(volatile FAR spinlock_t *lock); /**************************************************************************** - * Name: spinlock_initialize + * Name: spin_initialize * * Description: * Initialize a spinlock object to its initial, unlocked state. @@ -113,15 +113,46 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock); * ****************************************************************************/ -void spinlock_initialize(FAR struct spinlock_s *lock); +void spin_initialize(FAR struct spinlock_s *lock); /**************************************************************************** - * Name: spinlock + * Name: spin_lock * * Description: * If this CPU does not already hold the spinlock, then loop until the * spinlock is successfully locked. * + * This implementation is non-reentrant and is prone to deadlocks in + * the case that any logic on the same CPU attempts to take the lock + * more than one + * + * Input Parameters: + * lock - A reference to the spinlock object to lock. + * + * Returned Value: + * None. When the function returns, the spinlock was successfully locked + * by this CPU. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spin_lock(FAR volatile spinlock_t *lock); + +/**************************************************************************** + * Name: spin_lockr + * + * Description: + * If this CPU does not already hold the spinlock, then loop until the + * spinlock is successfully locked. + * + * This implementation is re-entrant in the sense that it can called + * numerous times from the same CPU without blocking. Of course, + * spin_unlock() must be called the same number of times. NOTE: the + * thread that originallly took the look may be executing on a different + * CPU when it unlocks the spinlock. + * * Input Parameters: * lock - A reference to the spinlock object to lock. * @@ -134,13 +165,13 @@ void spinlock_initialize(FAR struct spinlock_s *lock); * ****************************************************************************/ -void spinlock(FAR struct spinlock_s *lock); +void spin_lockr(FAR struct spinlock_s *lock); /**************************************************************************** - * Name: spinunlock + * Name: spin_unlock * * Description: - * Release one count on a spinlock. + * Release one count on a non-reentrant spinlock. * * Input Parameters: * lock - A reference to the spinlock object to unlock. @@ -153,7 +184,61 @@ void spinlock(FAR struct spinlock_s *lock); * ****************************************************************************/ -void spinunlock(FAR struct spinlock_s *lock); +/* void spin_unlock(FAR spinlock_t *lock); */ +#define spin_unlock(l) do { (l) = SP_UNLOCKED; } while (0) + +/**************************************************************************** + * Name: spin_unlockr + * + * Description: + * Release one count on a re-entrant spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to unlock. + * + * Returned Value: + * None. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spin_unlockr(FAR struct spinlock_s *lock); + +/**************************************************************************** + * Name: spin_islocked + * + * Description: + * Release one count on a renonentrant spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to test. + * + * Returned Value: + * A boolean value: true the spinlock is locked; false if it is unlocked. + * + ****************************************************************************/ + +/* bool spin_islocked(FAR spinlock_t lock); */ +#define spin_islocked(l) ((l) == SP_UNLOCKED) + +/**************************************************************************** + * Name: spin_islockedr + * + * Description: + * Release one count on a re-entrant spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to test. + * + * Returned Value: + * A boolean value: true the spinlock is locked; false if it is unlocked. + * + ****************************************************************************/ + +/* bool spin_islockedr(FAR struct spinlock_s *lock); */ +#define spin_islockedr(l) ((l)->sp_lock == SP_UNLOCKED) #endif /* CONFIG_SPINLOCK */ #endif /* __INCLUDE_NUTTX_SPINLOCK_H */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index e48b421db6..ecdc74a4ec 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -49,6 +49,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -294,6 +295,78 @@ extern const struct tasklist_s g_tasklisttable[NUM_TASK_STATES]; extern volatile uint32_t g_cpuload_total; #endif +/* Declared in sched_lock.c *************************************************/ +/* Pre-emption is disabled via the interface sched_lock(). sched_lock() + * works by preventing context switches from the currently executing tasks. + * This prevents other tasks from running (without disabling interrupts) and + * gives the currently executing task exclusive access to the (single) CPU + * resources. Thus, sched_lock() and its companion, sched_unlcok(), are + * used to implement some critical sections. + * + * In the single CPU case, Pre-emption is disabled using a simple lockcount + * in the TCB. When the scheduling is locked, the lockcount is incremented; + * when the scheduler is unlocked, the lockcount is decremented. If the + * lockcount for the task at the head of the g_readytorun list has a + * lockcount > 0, then pre-emption is disabled. + * + * No special protection is required since only the executing task can + * modify its lockcount. + */ + +#ifdef CONFIG_SMP +/* In the multiple CPU, SMP case, disabling context switches will not give a + * task exclusive access to the (multiple) CPU resources (at least without + * stopping the other CPUs): Even though pre-emption is disabled, other + * threads will still be executing on the other CPUS. + * + * There are additional rules for this multi-CPU case: + * + * 1. There is a global lock count 'g_cpu_lockset' that includes a bit for + * each CPU: If the bit is '1', then the corresponding CPU has the + * scheduler locked; if '0', then the CPU does not have the scheduler + * locked. + * 2. Scheduling logic would set the bit associated with the cpu in + * 'g_cpu_lockset' when the TCB at the head of the g_assignedtasks[cpu] + * list transitions has 'lockcount' > 0. This might happen when sched_lock() + * is called, or after a context switch that changes the TCB at the + * head of the g_assignedtasks[cpu] list. + * 3. Similarly, the cpu bit in the global 'g_cpu_lockset' would be cleared + * when the TCB at the head of the g_assignedtasks[cpu] list has + * 'lockcount' == 0. This might happen when sched_unlock() is called, or + * after a context switch that changes the TCB at the head of the + * g_assignedtasks[cpu] list. + * 4. Modification of the global 'g_cpu_lockset' must be protected by a + * spinlock, 'g_cpu_schedlock'. That spinlock would be taken when + * sched_lock() is called, and released when sched_unlock() is called. + * This assures that the scheduler does enforce the critical section. + * NOTE: Because of this spinlock, there should never be more than one + * bit set in 'g_cpu_lockset'; attempts to set additional bits should + * be cause the CPU to block on the spinlock. However, additional bits + * could get set in 'g_cpu_lockset' due to the context switches on the + * various CPUs. + * 5. Each the time the head of a g_assignedtasks[] list changes and the + * scheduler modifies 'g_cpu_lockset', it must also set 'g_cpu_schedlock' + * depending on the new state of 'g_cpu_lockset'. + * 5. Logic that currently uses the currently running tasks lockcount + * instead uses the global 'g_cpu_schedlock'. A value of SP_UNLOCKED + * means that no CPU has pre-emption disabled; SP_LOCKED means that at + * least one CPU has pre-emption disabled. + */ + +extern volatile spinlock_t g_cpu_schedlock; + +#if (CONFIG_SMP_NCPUS <= 8) +extern volatile uint8_t g_cpu_lockset; +#elif (CONFIG_SMP_NCPUS <= 16) +extern volatile uint16_t g_cpu_lockset; +#elif (CONFIG_SMP_NCPUS <= 32) +extern volatile uint32_t g_cpu_lockset; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif + +#endif /* CONFIG_SMP */ + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -348,6 +421,12 @@ uint32_t sched_sporadic_process(FAR struct tcb_s *tcb, uint32_t ticks, void sched_sporadic_lowpriority(FAR struct tcb_s *tcb); #endif +#ifdef CONFIG_SMP +# define sched_islocked(tcb) spin_islocked(g_cpu_schedlock) +#else +# define sched_islocked(tcb) ((tcb)->lockcount > 0) +#endif + /* CPU load measurement support */ #if defined(CONFIG_SCHED_CPULOAD) && !defined(CONFIG_SCHED_CPULOAD_EXTCLK) diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 23a0a2da91..ffe18acaf0 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_addreadytorun.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,7 @@ * This function adds a TCB to the ready to run list. If the currently * active task has preemption disabled and the new TCB would cause this * task to be pre-empted, the new task is added to the g_pendingtasks list - * instead. Thepending tasks will be made ready-to-run when preemption is + * instead. The pending tasks will be made ready-to-run when preemption is * unlocked. * * Inputs: @@ -77,6 +77,7 @@ * ****************************************************************************/ +#ifndef CONFIG_SMP bool sched_addreadytorun(FAR struct tcb_s *btcb) { FAR struct tcb_s *rtcb = this_task(); @@ -107,7 +108,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) sched_note_switch(rtcb, btcb); /* The new btcb was added at the head of the ready-to-run list. It - * is now to new active task! + * is now the new active task! */ ASSERT(!rtcb->lockcount && btcb->flink != NULL); @@ -126,3 +127,228 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) return ret; } +#endif /* !CONFIG_SMP */ + +/**************************************************************************** + * Name: sched_addreadytorun + * + * Description: + * This function adds a TCB to one of the ready to run lists. That might + * be: + * + * 1. The g_readytorun list if the task is ready-to-run but not running + * and not assigned to a CPU. + * 2. The g_assignedtask[cpu] list if the task is running or if has been + * assigned to a CPU. + * + * If the currently active task has preemption disabled and the new TCB + * would cause this task to be pre-empted, the new task is added to the + * g_pendingtasks list instead. Thepending tasks will be made + * ready-to-run when preemption isunlocked. + * + * Inputs: + * btcb - Points to the blocked TCB that is ready-to-run + * + * Return Value: + * true if the currently active task (the head of the ready-to-run list) + * has changed. + * + * Assumptions: + * - The caller has established a critical section before calling this + * function (calling sched_lock() first is NOT a good idea -- use + * irqsave()). + * - The caller has already removed the input rtcb from whatever list it + * was in. + * - The caller handles the condition that occurs if the head of the + * ready-to-run list is changed. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +bool sched_addreadytorun(FAR struct tcb_s *btcb) +{ + FAR struct tcb_s *rtcb; + FAR struct tcb_s *next; + FAR dq_queue_t *tasklist; + uint8_t minprio; + int task_state; + int cpu; + bool switched; + bool doswitch; + int i; + + /* Find the CPU that is executing the lowest priority task (possibly its + * IDLE task). + */ + + rtcb = NULL; + minprio = SCHED_PRIORITY_MAX; + cpu = 0; + + for (i = 0; i < CONFIG_SMP_NCPUS; i++) + { + FAR struct tcb_s *candidate = + (FAR struct tcb_s *)g_assignedtasks[i].head; + + /* If this thread is executing its IDLE task, the use it. The IDLE + * task is always the last task in the assigned task list. + */ + + if (candidate->flink == NULL) + { + /* The IDLE task should always be assigned to this CPU and have a + * priority zero. + */ + + DEBUGASSERT((candidate->flags & TCB_FLAG_CPU_ASSIGNED) != 0 && + candidate->sched_priority == 0); + + rtcb = candidate; + cpu = i; + break; + } + else if (candidate->sched_priority < minprio) + { + DEBUGASSERT(candidate->sched_priority > 0); + + rtcb = candidate; + cpu = i; + } + } + + /* Determine the desired new task state. First, if the new task priority + * is higher then the priority of the lowest priority, running task, then + * the new task will be running and a context switch switch will be required. + */ + + if (rtcb->sched_priority < btcb->sched_priority) + { + task_state = TSTATE_TASK_RUNNING; + } + + /* If it will not be running, but is assigned to a CPU, then it will be in + * the asssigned state. + */ + + else if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + { + task_state = TSTATE_TASK_ASSIGNED; + cpu = btcb->cpu; + } + + /* Otherwise, it will be ready-to-run, but not not yet running */ + + else + { + task_state = TSTATE_TASK_READYTORUN; + cpu = 0; /* CPU does not matter */ + } + + /* If the selected state is TSTATE_TASK_RUNNING, then we would like to + * start running the task. Be we cannot do that if pre-emption is disable. + */ + + if (spin_islocked(g_cpu_schedlock) && task_state == TSTATE_TASK_RUNNING) + { + /* Preemption would occur! Add the new ready-to-run task to the + * g_pendingtasks task list for now. + */ + + sched_addprioritized(btcb, (FAR dq_queue_t *)&g_pendingtasks); + btcb->task_state = TSTATE_TASK_PENDING; + doswitch = false; + } + else + { + /* Add the task to the list corresponding to the selected state + * and check if a context switch will occur + */ + + tasklist = TLIST_HEAD(task_state, cpu); + switched = sched_addprioritized(btcb, tasklist); + + /* If the selected task was the g_assignedtasks[] list, then a context + * swith will occur. + */ + + if (switched && task_state != TSTATE_TASK_READYTORUN) + { + /* The new btcb was added at the head of the ready-to-run list. It + * is now the new active task! + * + * Inform the instrumentation logic that we are switching tasks. + */ + + sched_note_switch(rtcb, btcb); + + /* Assign the CPU and set the running state */ + + DEBUGASSERT(task_state == TSTATE_TASK_RUNNING); + + btcb->cpu = cpu; + btcb->task_state = TSTATE_TASK_RUNNING; + + /* Adjust global pre-emption controls. */ + + if (btcb->lockcount > 0) + { + g_cpu_lockset |= (1 << cpu); + g_cpu_schedlock = SP_LOCKED; + } + else + { + g_cpu_lockset &= ~(1 << cpu); + if (g_cpu_lockset == 0) + { + g_cpu_schedlock = SP_UNLOCKED; + } + } + + /* If the following task is not assigned to this CPU, then it must + * be moved to the g_readytorun list. Since it cannot be at the + * head of the list, we can do this without invoking any heavy + * lifting machinery. + */ + + next = (FAR dq_queue_t *)btcb->flink; + ASSERT(!rtcb->lockcount && next != NULL); + + if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + { + next->task_state = TSTATE_TASK_ASSIGNED; + } + else + { + /* Remove the task from the assigned task list */ + + dq_rem((FAR dq_entry_t *)next, tasklist); + + /* Add the task to the g_readytorun list. It may be + * assigned to a different CPU the next time that it runs. + */ + + next->task_state = TSTATE_TASK_READYTORUN; + (void)sched_addprioritized(btcb, &g_readytorun); + } + + doswitch = true; + } + else + { + /* The new btcb was added either (1) in the middle of the assigned + * task list (the btcb->cpu field is already valid) or (2) was + * added to the ready-to-run list (the btcb->cpu field does not + * matter). Either way, it won't be running. + */ + + DEBUGASSERT(task_state != TSTATE_TASK_RUNNING); + + btcb->task_state = TSTATE_TASK_READYTORUN; + doswitch = false; + } + } + + return doswitch; +} + +#endif /* CONFIG_SMP */ diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 3f5020789c..9340d65ea5 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_lock.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,81 @@ #include #include "sched/sched.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Pre-emption is disabled via the interface sched_lock(). sched_lock() + * works by preventing context switches from the currently executing tasks. + * This prevents other tasks from running (without disabling interrupts) and + * gives the currently executing task exclusive access to the (single) CPU + * resources. Thus, sched_lock() and its companion, sched_unlcok(), are + * used to implement some critical sections. + * + * In the single CPU case, Pre-emption is disabled using a simple lockcount + * in the TCB. When the scheduling is locked, the lockcount is incremented; + * when the scheduler is unlocked, the lockcount is decremented. If the + * lockcount for the task at the head of the g_readytorun list has a + * lockcount > 0, then pre-emption is disabled. + * + * No special protection is required since only the executing task can + * modify its lockcount. + */ + +#ifdef CONFIG_SMP +/* In the multiple CPU, SMP case, disabling context switches will not give a + * task exclusive access to the (multiple) CPU resources (at least without + * stopping the other CPUs): Even though pre-emption is disabled, other + * threads will still be executing on the other CPUS. + * + * There are additional rules for this multi-CPU case: + * + * 1. There is a global lock count 'g_cpu_lockset' that includes a bit for + * each CPU: If the bit is '1', then the corresponding CPU has the + * scheduler locked; if '0', then the CPU does not have the scheduler + * locked. + * 2. Scheduling logic would set the bit associated with the cpu in + * 'g_cpu_lockset' when the TCB at the head of the g_assignedtasks[cpu] + * list transitions has 'lockcount' > 0. This might happen when sched_lock() + * is called, or after a context switch that changes the TCB at the + * head of the g_assignedtasks[cpu] list. + * 3. Similarly, the cpu bit in the global 'g_cpu_lockset' would be cleared + * when the TCB at the head of the g_assignedtasks[cpu] list has + * 'lockcount' == 0. This might happen when sched_unlock() is called, or + * after a context switch that changes the TCB at the head of the + * g_assignedtasks[cpu] list. + * 4. Modification of the global 'g_cpu_lockset' must be protected by a + * spinlock, 'g_cpu_schedlock'. That spinlock would be taken when + * sched_lock() is called, and released when sched_unlock() is called. + * This assures that the scheduler does enforce the critical section. + * NOTE: Because of this spinlock, there should never be more than one + * bit set in 'g_cpu_lockset'; attempts to set additional bits should + * be cause the CPU to block on the spinlock. However, additional bits + * could get set in 'g_cpu_lockset' due to the context switches on the + * various CPUs. + * 5. Each the time the head of a g_assignedtasks[] list changes and the + * scheduler modifies 'g_cpu_lockset', it must also set 'g_cpu_schedlock' + * depending on the new state of 'g_cpu_lockset'. + * 5. Logic that currently uses the currently running tasks lockcount + * instead uses the global 'g_cpu_schedlock'. A value of SP_UNLOCKED + * means that no CPU has pre-emption disabled; SP_LOCKED means that at + * least one CPU has pre-emption disabled. + */ + +volatile spinlock_t g_cpu_schedlock; + +#if (CONFIG_SMP_NCPUS <= 8) +volatile uint8_t g_cpu_lockset; +#elif (CONFIG_SMP_NCPUS <= 16) +volatile uint16_t g_cpu_lockset; +#elif (CONFIG_SMP_NCPUS <= 32) +volatile uint32_t g_cpu_lockset; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif + +#endif /* CONFIG_SMP */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -71,15 +146,61 @@ int sched_lock(void) { FAR struct tcb_s *rtcb = this_task(); - /* Check for some special cases: (1) rtcb may be NULL only during - * early boot-up phases, and (2) sched_lock() should have no - * effect if called from the interrupt level. + /* Check for some special cases: (1) rtcb may be NULL only during early + * boot-up phases, and (2) sched_lock() should have no effect if called + * from the interrupt level. */ if (rtcb && !up_interrupt_context()) { - ASSERT(rtcb->lockcount < MAX_LOCK_COUNT); - rtcb->lockcount++; + /* Catch attempts to increment the lockcount beyound the range of the + * integer type. + */ + + DEBUGASSERT(rtcb->lockcount < MAX_LOCK_COUNT); + +#ifdef CONFIG_SMP + /* We must hold the lock on this CPU before we increment the lockcount + * for the first time. Holding the lock is sufficient to lockout context + * switching. + */ + + if (rtcb->lockcount == 0) + { + /* We don't have the scheduler locked. But logic running on a + * different CPU may have the scheduler locked. It is not + * possible for some other task on this CPU to have the scheduler + * locked (or we would not be executing!). + * + * If the scheduler is locked on another CPU, then we for the lock. + */ + + spin_lock(&g_cpu_schedlock); + + /* Set a bit in g_cpu_lockset to indicate that this CPU holds the + * scheduler lock. This is mostly for debug purposes but should + * also handle few cornercases during context switching. + */ + + g_cpu_lockset |= (1 << this_cpu()); + } + else + { + /* If this thread already has the scheduler locked, then + * g_cpu_schedlock() should indicate that the scheduler is locked + * and g_cpu_lockset should include the bit setting for this CPU. + */ + + DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && + (g_cpu_lockset & (1 << this_cpu())) != 0); + } +#endif + + /* A counter is used to support locking. This allows nested lock + * operations on this thread (on any CPU) + */ + + rtcb->lockcount++; } return OK; diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 4fa2407040..1a175c7a0a 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -107,6 +107,29 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) ntcb = (FAR struct tcb_s *)rtcb->flink; DEBUGASSERT(ntcb != NULL); +#ifdef CONFIG_SMP + /* Will pre-emption be disabled after the switch? */ + + if (ntcb->lockcount > 0) + { + /* Yes... make sure that scheduling logic knows about this */ + + g_cpu_lockset |= (1 << this_cpu()); + g_cpu_schedlock = SP_LOCKED; + } + else + { + /* No.. we may need to perform release our hold on the lock. + * + * REVISIT: It might be possible for two CPUs to hold the logic in + * some strange cornercases like: + */ + + g_cpu_lockset &= ~(1 << this_cpu()); + g_cpu_schedlock = ((g_cpu_lockset == 0) ? SP_UNLOCKED : SP_LOCKED); + } +#endif + /* Inform the instrumentation layer that we are switching tasks */ sched_note_switch(rtcb, ntcb); diff --git a/sched/sched/sched_roundrobin.c b/sched/sched/sched_roundrobin.c index 8e4ea37f13..bf856004d6 100644 --- a/sched/sched/sched_roundrobin.c +++ b/sched/sched/sched_roundrobin.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_roundrobin.c * - * Copyright (C) 2007, 2009, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,7 +124,7 @@ uint32_t sched_roundrobin_process(FAR struct tcb_s *tcb, uint32_t ticks, */ ret = tcb->timeslice; - if (tcb->timeslice <= 0 && tcb->lockcount == 0) + if (tcb->timeslice <= 0 && !sched_islocked(tcb)) { /* We will also suppress context switches if we were called via one * of the unusual cases handled by sched_timer_reasses(). In that diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index 235d987044..d31837d3f1 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -452,7 +452,7 @@ static void sporadic_budget_expire(int argc, wdparm_t arg1, ...) * this operation is needed. */ - if (tcb->lockcount > 0) + if (sched_islocked(tcb)) { DEBUGASSERT((mrepl->flags && SPORADIC_FLAG_ALLOCED) != 0 && sporadic->nrepls > 0); @@ -600,7 +600,7 @@ static void sporadic_replenish_expire(int argc, wdparm_t arg1, ...) * this operation is needed. */ - if (tcb->lockcount > 0) + if (sched_islocked(tcb)) { /* Set the timeslice to the magic value */ @@ -1199,7 +1199,7 @@ uint32_t sched_sporadic_process(FAR struct tcb_s *tcb, uint32_t ticks, /* Does the thread have the scheduler locked? */ sporadic = tcb->sporadic; - if (tcb->lockcount > 0) + if (sched_islocked(tcb)) { /* Yes... then we have no option but to give the thread more * time at the higher priority. Dropping the priority could diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 15a5e9adb4..4d206c4f48 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_unlock.c * - * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -91,6 +91,24 @@ int sched_unlock(void) { rtcb->lockcount = 0; +#ifdef CONFIG_SMP + /* The lockcount has decremented to zero and we need to perform + * release our hold on the lock. + * + * REVISIT: It might be possible for two CPUs to hold the logic in + * some strange cornercases like: + */ + + DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && + (g_cpu_lockset & (1 << this_cpu())) != 0); + + g_cpu_lockset &= ~(1 << this_cpu()); + if (g_cpu_lockset == 0) + { + spin_unlock(g_cpu_schedlock); + } +#endif + /* Release any ready-to-run tasks that have collected in * g_pendingtasks. */ diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index ef6dd021a4..a31df567d8 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -56,7 +56,7 @@ /* REVISIT: What happens if a thread taks a spinlock while running on one * CPU, but is suspended, then reassigned to another CPU where it runs and - * eventually calls spinunlock(). One solution might be to lock a thread to + * eventually calls spin_unlock(). One solution might be to lock a thread to * a CPU if it holds a spinlock. That would assure that it never runs on * any other CPU and avoids such complexities. */ @@ -68,7 +68,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: spinlock_initialize + * Name: spin_initialize * * Description: * Initialize a spinlock object to its initial, unlocked state. @@ -81,7 +81,7 @@ * ****************************************************************************/ -void spinlock_initialize(FAR struct spinlock_s *lock) +void spin_initialize(FAR struct spinlock_s *lock) { DEBUGASSERT(lock != NULL); @@ -93,12 +93,16 @@ void spinlock_initialize(FAR struct spinlock_s *lock) } /**************************************************************************** - * Name: spinlock + * Name: spin_lock * * Description: * If this CPU does not already hold the spinlock, then loop until the * spinlock is successfully locked. * + * This implementation is non-reentrant and is prone to deadlocks in + * the case that any logic on the same CPU attempts to take the lock + * more than one + * * Input Parameters: * lock - A reference to the spinlock object to lock. * @@ -111,7 +115,40 @@ void spinlock_initialize(FAR struct spinlock_s *lock) * ****************************************************************************/ -void spinlock(FAR struct spinlock_s *lock) +void spin_lock(FAR volatile spinlock_t *lock) +{ + while (up_testset(lock) == SP_LOCKED) + { + sched_yield(); + } +} + +/**************************************************************************** + * Name: spin_lockr + * + * Description: + * If this CPU does not already hold the spinlock, then loop until the + * spinlock is successfully locked. + * + * This implementation is re-entrant in the sense that it can called + * numerous times from the same CPU without blocking. Of course, + * spin_unlock() must be called the same number of times. NOTE: the + * thread that originallly took the look may be executing on a different + * CPU when it unlocks the spinlock. + * + * Input Parameters: + * lock - A reference to the spinlock object to lock. + * + * Returned Value: + * None. When the function returns, the spinlock was successfully locked + * by this CPU. + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +void spin_lockr(FAR struct spinlock_s *lock) { #ifdef CONFIG_SMP irqstate_t flags; @@ -134,7 +171,7 @@ void spinlock(FAR struct spinlock_s *lock) { #ifdef CONFIG_SPINLOCK_LOCKDOWN /* REVISIT: What happens if this thread is suspended, then reassigned - * to another CPU where it runs and eventually calls spinunlock(). + * to another CPU where it runs and eventually calls spin_unlock(). * One solution might be to lock a thread to a CPU if it holds a * spinlock. That would assure that it never runs on any other CPU * and avoids such complexities. @@ -178,7 +215,7 @@ void spinlock(FAR struct spinlock_s *lock) } /**************************************************************************** - * Name: spinunlock + * Name: spin_unlockr * * Description: * Release one count on a spinlock. @@ -194,7 +231,7 @@ void spinlock(FAR struct spinlock_s *lock) * ****************************************************************************/ -void spinunlock(FAR struct spinlock_s *lock) +void spin_unlockr(FAR struct spinlock_s *lock) { #ifdef CONFIG_SMP irqstate_t flags; @@ -209,7 +246,7 @@ void spinunlock(FAR struct spinlock_s *lock) #ifdef CONFIG_SPINLOCK_LOCKDOWN /* REVISIT: What happens if this thread took the lock on a different CPU, * was suspended, then reassigned to this CPU where it runs and eventually - * calls spinunlock(). One solution might be to lock a thread to a CPU if + * calls spin_unlock(). One solution might be to lock a thread to a CPU if * it holds a spinlock. That would assure that it never runs on any other * CPU and avoids such complexities. */ @@ -221,6 +258,8 @@ void spinunlock(FAR struct spinlock_s *lock) if (lock->sp_cpu == cpu) #else + /* The alternative is to allow the lock to be released from any CPU */ + DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED && lock->sp_count > 0); #endif diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index 73eab8169f..a8de026ca8 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_exit.c * - * Copyright (C) 2008-2009, 2012-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -107,6 +107,14 @@ int task_exit(void) */ rtcb->lockcount++; + +#ifdef CONFIG_SMP + /* Make sure that the system knows about the locked state */ + + g_cpu_schedlock = SP_LOCKED; + g_cpu_lockset |= (1 << this_cpu()); +#endif + rtcb->task_state = TSTATE_TASK_READYTORUN; /* Move the TCB to the specified blocked task list and delete it. Calling @@ -137,5 +145,19 @@ int task_exit(void) */ rtcb->lockcount--; + +#ifdef CONFIG_SMP + if (rtcb->lockcount == 0) + { + /* Make sure that the system knows about the unlocked state */ + + g_cpu_lockset &= ~(1 << this_cpu()); + if (g_cpu_lockset == 0) + { + g_cpu_schedlock = SP_UNLOCKED; + } + } +#endif + return ret; } -- GitLab From 64b3ce8775047ea1c8890847130eed71460d72be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 12 Feb 2016 16:13:14 -0600 Subject: [PATCH 717/858] SMP: Add up_cpustart and up_cpurestart protoypes; fix some problems in sched_addreadytorun; first cut at SMP version of up_mergepending. --- include/nuttx/arch.h | 45 +++++++++++ sched/sched/sched_addprioritized.c | 20 ----- sched/sched/sched_addreadytorun.c | 123 +++++++++++++++++++--------- sched/sched/sched_mergepending.c | 125 ++++++++++++++++++++--------- 4 files changed, 217 insertions(+), 96 deletions(-) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 1eb455ee3d..de85b99d13 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1711,6 +1711,51 @@ int up_cpundx(void); int up_cpustart(int cpu, main_t idletask, pid_t pid); #endif +/**************************************************************************** + * Name: up_cpustop + * + * Description: + * Save the state of the current task at the head of the + * g_assignedtasks[cpu] task list and then stop the CPU. + * + * This function is called by the OS when the logic executing on one CPU + * needs to modify the state of the g_assignedtasks[cpu] list for another + * CPU. + * + * Input Parameters: + * cpu - The index of the CPU to be stopped/ + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int up_cpustop(int cpu); +#endif + +/**************************************************************************** + * Name: up_cpurestart + * + * Description: + * Restart the cpu, restoring the state of the task at the head of the + * g_assignedtasks[cpu] list. + * + * This function is called after up_cpustop in order resume operation of + * the CPU after modifying its g_assignedtasks[cpu] list. + * + * Input Parameters: + * cpu - The index of the CPU being re-started. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int up_cpurestart(int cpu); +#endif + /**************************************************************************** * Name: up_romgetc * diff --git a/sched/sched/sched_addprioritized.c b/sched/sched/sched_addprioritized.c index 3eff24b82c..199ea5bc66 100644 --- a/sched/sched/sched_addprioritized.c +++ b/sched/sched/sched_addprioritized.c @@ -46,26 +46,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index ffe18acaf0..9e851757c4 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -170,49 +170,61 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) FAR struct tcb_s *rtcb; FAR struct tcb_s *next; FAR dq_queue_t *tasklist; - uint8_t minprio; int task_state; int cpu; bool switched; bool doswitch; - int i; - /* Find the CPU that is executing the lowest priority task (possibly its - * IDLE task). - */ + /* Check if the blocked TCB is already assigned to a CPU */ - rtcb = NULL; - minprio = SCHED_PRIORITY_MAX; - cpu = 0; + if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + { + /* Yes.. that that is the CPU we must use */ - for (i = 0; i < CONFIG_SMP_NCPUS; i++) + cpu = btcb->cpu; + rtcb = (FAR struct tcb_s *)g_assignedtasks[cpu].head; + } + else { - FAR struct tcb_s *candidate = - (FAR struct tcb_s *)g_assignedtasks[i].head; + uint8_t minprio; + int i; - /* If this thread is executing its IDLE task, the use it. The IDLE - * task is always the last task in the assigned task list. + /* Otherwise, find the CPU that is executing the lowest priority task + * (possibly its IDLE task). */ - if (candidate->flink == NULL) + rtcb = NULL; + minprio = SCHED_PRIORITY_MAX; + cpu = 0; + + for (i = 0; i < CONFIG_SMP_NCPUS; i++) { - /* The IDLE task should always be assigned to this CPU and have a - * priority zero. + FAR struct tcb_s *candidate = + (FAR struct tcb_s *)g_assignedtasks[i].head; + + /* If this thread is executing its IDLE task, the use it. The + * IDLE task is always the last task in the assigned task list. */ - DEBUGASSERT((candidate->flags & TCB_FLAG_CPU_ASSIGNED) != 0 && - candidate->sched_priority == 0); + if (candidate->flink == NULL) + { + /* The IDLE task should always be assigned to this CPU and + * have a priority of zero. + */ + + DEBUGASSERT(candidate->sched_priority == 0); - rtcb = candidate; - cpu = i; - break; - } - else if (candidate->sched_priority < minprio) - { - DEBUGASSERT(candidate->sched_priority > 0); + rtcb = candidate; + cpu = i; + break; + } + else if (candidate->sched_priority < minprio) + { + DEBUGASSERT(candidate->sched_priority > 0); - rtcb = candidate; - cpu = i; + rtcb = candidate; + cpu = i; + } } } @@ -258,20 +270,46 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) btcb->task_state = TSTATE_TASK_PENDING; doswitch = false; } - else + else if (task_state == TSTATE_TASK_READYTORUN) + { + /* The new btcb was added either (1) in the middle of the assigned + * task list (the btcb->cpu field is already valid) or (2) was + * added to the ready-to-run list (the btcb->cpu field does not + * matter). Either way, it won't be running. + * + * Add the task to the ready-to-run (but not running) task list + */ + + (void)sched_addprioritized(btcb, (FAR dq_queue_t *)&g_readytorun); + + btcb->task_state = TSTATE_TASK_READYTORUN; + doswitch = false; + } + else /* (task_state == TSTATE_TASK_ASSIGNED || task_state == TSTATE_TASK_RUNNING) */ { + int me = this_cpu(); + + /* If we are modifying some assigned task list other than our own, we will + * need to stop that CPU. + */ + + if (cpu != me) + { + DEBUGVERIFY(up_cpustop(cpu)); + } + /* Add the task to the list corresponding to the selected state * and check if a context switch will occur */ - tasklist = TLIST_HEAD(task_state, cpu); + tasklist = (FAR dq_queue_t *)g_assignedtasks[cpu].head; switched = sched_addprioritized(btcb, tasklist); /* If the selected task was the g_assignedtasks[] list, then a context * swith will occur. */ - if (switched && task_state != TSTATE_TASK_READYTORUN) + if (switched) { /* The new btcb was added at the head of the ready-to-run list. It * is now the new active task! @@ -310,7 +348,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * lifting machinery. */ - next = (FAR dq_queue_t *)btcb->flink; + next = (FAR struct tcb_s *)btcb->flink; ASSERT(!rtcb->lockcount && next != NULL); if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) @@ -328,23 +366,28 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) */ next->task_state = TSTATE_TASK_READYTORUN; - (void)sched_addprioritized(btcb, &g_readytorun); + (void)sched_addprioritized(btcb, + (FAR dq_queue_t *)&g_readytorun); } doswitch = true; } else { - /* The new btcb was added either (1) in the middle of the assigned - * task list (the btcb->cpu field is already valid) or (2) was - * added to the ready-to-run list (the btcb->cpu field does not - * matter). Either way, it won't be running. - */ + /* No context switch. Assign the CPU and set the assigned state */ + + DEBUGASSERT(task_state == TSTATE_TASK_ASSIGNED); - DEBUGASSERT(task_state != TSTATE_TASK_RUNNING); + btcb->cpu = cpu; + btcb->task_state = TSTATE_TASK_ASSIGNED; + } - btcb->task_state = TSTATE_TASK_READYTORUN; - doswitch = false; + /* All done, restart the other that CPU. */ + + if (cpu != me) + { + DEBUGVERIFY(up_cpurestart(cpu)); + doswitch = false; } } diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index c62bb70b55..81c2c934e0 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_mergepending.c * - * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -55,13 +55,14 @@ * * Description: * This function merges the prioritized g_pendingtasks list into the - * prioritized g_readytorun task list. + * prioritized ready-to-run task list. * * Inputs: * None * * Return Value: - * true if the head of the g_readytorun task list has changed. + * true if the head of the ready-to-run task list has changed indicating + * a context switch is needed. * * Assumptions: * - The caller has established a critical section before @@ -72,75 +73,82 @@ * ****************************************************************************/ +#ifndef CONFIG_SMP bool sched_mergepending(void) { - FAR struct tcb_s *pndtcb; - FAR struct tcb_s *pndnext; - FAR struct tcb_s *rtrtcb; - FAR struct tcb_s *rtrprev; + FAR struct tcb_s *ptcb; + FAR struct tcb_s *pnext; + FAR struct tcb_s *rtcb; + FAR struct tcb_s *rprev; bool ret = false; /* Initialize the inner search loop */ - rtrtcb = this_task(); + rtcb = this_task(); /* Process every TCB in the g_pendingtasks list */ - for (pndtcb = (FAR struct tcb_s *)g_pendingtasks.head; pndtcb; pndtcb = pndnext) + for (ptcb = (FAR struct tcb_s *)g_pendingtasks.head; + ptcb; + ptcb = pnext) { - pndnext = pndtcb->flink; + pnext = ptcb->flink; - /* Search the g_readytorun list to find the location to insert the - * new pndtcb. Each is list is maintained in ascending sched_priority + /* REVISIT: Why don't we just remove the ptcb from pending task list + * and call sched_addreadytorun? + */ + + /* Search the ready-to-run list to find the location to insert the + * new ptcb. Each is list is maintained in ascending sched_priority * order. */ for (; - (rtrtcb && pndtcb->sched_priority <= rtrtcb->sched_priority); - rtrtcb = rtrtcb->flink); + (rtcb && ptcb->sched_priority <= rtcb->sched_priority); + rtcb = rtcb->flink); - /* Add the pndtcb to the spot found in the list. Check if the - * pndtcb goes at the ends of the g_readytorun list. This would be + /* Add the ptcb to the spot found in the list. Check if the + * ptcb goes at the ends of the ready-to-run list. This would be * error condition since the idle test must always be at the end of - * the g_readytorun list! + * the ready-to-run list! */ - ASSERT(rtrtcb); + ASSERT(rtcb); - /* The pndtcb goes just before rtrtcb */ + /* The ptcb goes just before rtcb */ - rtrprev = rtrtcb->blink; - if (!rtrprev) + rprev = rtcb->blink; + if (!rprev) { - /* Special case: Inserting pndtcb at the head of the list */ + /* Special case: Inserting ptcb at the head of the list */ /* Inform the instrumentation layer that we are switching tasks */ - sched_note_switch(rtrtcb, pndtcb); + sched_note_switch(rtcb, ptcb); /* Then insert at the head of the list */ - pndtcb->flink = rtrtcb; - pndtcb->blink = NULL; - rtrtcb->blink = pndtcb; - g_readytorun.head = (FAR dq_entry_t *)pndtcb; - rtrtcb->task_state = TSTATE_TASK_READYTORUN; - pndtcb->task_state = TSTATE_TASK_RUNNING; - ret = true; + ptcb->flink = rtcb; + ptcb->blink = NULL; + rtcb->blink = ptcb; + g_readytorun.head = (FAR dq_entry_t *)ptcb; + rtcb->task_state = TSTATE_TASK_READYTORUN; + ptcb->task_state = TSTATE_TASK_RUNNING; + ret = true; } else { /* Insert in the middle of the list */ - pndtcb->flink = rtrtcb; - pndtcb->blink = rtrprev; - rtrprev->flink = pndtcb; - rtrtcb->blink = pndtcb; - pndtcb->task_state = TSTATE_TASK_READYTORUN; + ptcb->flink = rtcb; + ptcb->blink = rprev; + rprev->flink = ptcb; + rtcb->blink = ptcb; + ptcb->task_state = TSTATE_TASK_READYTORUN; } /* Set up for the next time through */ - rtrtcb = pndtcb; + rtcb = ptcb; } /* Mark the input list empty */ @@ -150,3 +158,48 @@ bool sched_mergepending(void) return ret; } +#endif /* !CONFIG_SMP */ + +/**************************************************************************** + * Name: sched_mergepending + * + * Description: + * This function merges the prioritized g_pendingtasks list into the + * prioritized ready-to-run task list. + * + * Inputs: + * None + * + * Return Value: + * true if the head of the ready-to-run task list has changed indicating + * a context switch is needed. + * + * Assumptions: + * - The caller has established a critical section before + * calling this function (calling sched_lock() first is NOT + * a good idea -- use irqsave()). + * - The caller handles the condition that occurs if the + * the head of the sched_mergTSTATE_TASK_PENDINGs is changed. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +bool sched_mergepending(void) +{ + FAR struct tcb_s *ptcb; + bool ret = false; + + /* Remove and process every TCB in the g_pendingtasks list */ + + for (ptcb = (FAR struct tcb_s *)dq_remfirst((FAR dq_queue_t *)&g_pendingtasks); + ptcb != NULL; + ptcb = (FAR struct tcb_s *)dq_remfirst((FAR dq_queue_t *)&g_pendingtasks)) + { + /* Add the pending task to the correct ready-to-run list */ + + ret |= sched_addreadytorun(ptcb); + } + + return ret; +} +#endif /* CONFIG_SMP */ -- GitLab From 3f7f58de9dc8912f382c063d0e67841ebb624838 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 12 Feb 2016 17:13:38 -0600 Subject: [PATCH 718/858] SMP: Fix some debug assertion problems when DEBUG is enabled; Partial fix for one bring-up issue --- arch | 2 +- sched/init/os_smpstart.c | 22 +++++++++++++--------- sched/semaphore/spinlock.c | 6 +++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arch b/arch index a6ad88a85c..4abb852339 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a6ad88a85c9e4c6ab633fb53f53603539206a57c +Subproject commit 4abb8523390cecded97fe325448213983e47aedf diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 63164845a3..53a451f1cc 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -94,9 +94,21 @@ static const char g_idlename[] = "CPUn Idle" int os_idletask(int argc, FAR char *argv[]) { +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Finish TCB initialization */ + + FAR struct task_tcb_s *rtcb = (FAR struct task_tcb_s *)this_task(); + + /* Create stdout, stderr, stdin on the IDLE task. These will be + * inherited by all of the threads created by the IDLE task. + */ + + DEBUGVERIFY(group_setupidlefiles(rtcb)); +#endif + /* Enter the IDLE loop */ - sdbg("CPU%d: Beginning Idle Loop\n"); + sdbg("CPU%d: Beginning Idle Loop\n", this_cpu()); for (; ; ) { /* Perform garbage collection (if it is not being done by the worker @@ -210,14 +222,6 @@ static FAR void *os_idletcb_setup(int cpu, main_t idletask, pid_t pid) DEBUGVERIFY(group_allocate(itcb, itcb->cmn.flags)); #endif -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - /* Create stdout, stderr, stdin on the IDLE task. These will be - * inherited by all of the threads created by the IDLE task. - */ - - DEBUGVERIFY(group_setupidlefiles(itcb)); -#endif - #ifdef HAVE_TASK_GROUP /* Complete initialization of the IDLE group. Suppress retention * of child status in the IDLE group. diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index a31df567d8..b5396273a8 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -251,7 +251,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) * CPU and avoids such complexities. */ - DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED && + DEBUGASSERT(lock != NULL && lock->sp_lock == SP_LOCKED && lock->sp_cpu == this_cpu() && lock->sp_count > 0); /* Do we already hold the lock? */ @@ -260,7 +260,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) #else /* The alternative is to allow the lock to be released from any CPU */ - DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED && + DEBUGASSERT(lock != NULL && lock->sp_lock == SP_LOCKED && lock->sp_count > 0); #endif @@ -286,7 +286,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) #else /* CONFIG_SMP */ /* Just mark the spinlock unlocked */ - DEBUGASSERT(lock != NULL && lock->sp-lock = SP_LOCKED); + DEBUGASSERT(lock != NULL && lock->sp_lock == SP_LOCKED); lock->sp_lock = SP_UNLOCKED; #endif /* CONFIG_SMP */ -- GitLab From f45166af32a9c554f83327c6bc5868022ac721c9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 12 Feb 2016 18:03:08 -0600 Subject: [PATCH 719/858] SMP: Fix a IDLE task semaphore operation --- mm/mm_heap/mm_sem.c | 2 +- sched/init/os_smpstart.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index 4be65b623c..6a38f9b5a7 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -86,7 +86,7 @@ void mm_seminitialize(FAR struct mm_heap_s *heap) { /* Initialize the MM semaphore to one (to support one-at-a-time access to - * private data sets. + * private data sets). */ (void)sem_init(&heap->mm_semaphore, 0, 1); diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 53a451f1cc..4dce113d1d 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -98,12 +98,34 @@ int os_idletask(int argc, FAR char *argv[]) /* Finish TCB initialization */ FAR struct task_tcb_s *rtcb = (FAR struct task_tcb_s *)this_task(); + int ret; /* Create stdout, stderr, stdin on the IDLE task. These will be * inherited by all of the threads created by the IDLE task. + * + * We must have exclusive access to the memory manager to do this BUT the + * idle task cannot wait on a semaphore (at least not later in the + * initialzation sequency when this thread is started). So loop until + * we do finally get access + * */ - DEBUGVERIFY(group_setupidlefiles(rtcb)); + do + { + ret = kmm_trysemaphore(); + if (ret >= 0) + { + DEBUGVERIFY(group_setupidlefiles(rtcb)); + kmm_givesemaphore(); + } + else + { + /* Perform any processor-specific idle state operations */ + + up_idle(); + } + } + while (ret < 0); #endif /* Enter the IDLE loop */ -- GitLab From 8ac699b63d54fc4e3ba6a9767b9f06682452529a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Feb 2016 09:04:54 -0600 Subject: [PATCH 720/858] SMP: Need to perform all IDLE task memory allocations on initializatin thread prior to starting the other CPUs --- include/nuttx/arch.h | 4 +- sched/init/init.h | 19 ++++ sched/init/os_smpstart.c | 176 +----------------------------------- sched/init/os_start.c | 188 ++++++++++++++++++++++++++------------- 4 files changed, 150 insertions(+), 237 deletions(-) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index de85b99d13..a6a30e69f0 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -101,7 +101,6 @@ #include -#include #include #include #include @@ -1700,7 +1699,6 @@ int up_cpundx(void); * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU * 0 is already active) * idletask - The entry point to the IDLE task. - * pid - Task ID of the IDLE task * * Returned Value: * Zero on success; a negated errno value on failure. @@ -1708,7 +1706,7 @@ int up_cpundx(void); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpustart(int cpu, main_t idletask, pid_t pid); +int up_cpustart(int cpu, main_t idletask); #endif /**************************************************************************** diff --git a/sched/init/init.h b/sched/init/init.h index d87b0341f3..1d95df1f6c 100644 --- a/sched/init/init.h +++ b/sched/init/init.h @@ -85,6 +85,25 @@ void os_start(void); int os_smpstart(void); #endif +/**************************************************************************** + * Name: os_idletask + * + * Description: + * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). + * It is equivalent to the CPU 0 IDLE logic in os_start.c + * + * Input Parameters: + * Standard task arguments. + * + * Returned Value: + * This function does not return. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int os_idletask(int argc, FAR char *argv[]); +#endif + /**************************************************************************** * Name: os_bringup * diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 4dce113d1d..03f3b0992d 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -94,40 +94,6 @@ static const char g_idlename[] = "CPUn Idle" int os_idletask(int argc, FAR char *argv[]) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - /* Finish TCB initialization */ - - FAR struct task_tcb_s *rtcb = (FAR struct task_tcb_s *)this_task(); - int ret; - - /* Create stdout, stderr, stdin on the IDLE task. These will be - * inherited by all of the threads created by the IDLE task. - * - * We must have exclusive access to the memory manager to do this BUT the - * idle task cannot wait on a semaphore (at least not later in the - * initialzation sequency when this thread is started). So loop until - * we do finally get access - * - */ - - do - { - ret = kmm_trysemaphore(); - if (ret >= 0) - { - DEBUGVERIFY(group_setupidlefiles(rtcb)); - kmm_givesemaphore(); - } - else - { - /* Perform any processor-specific idle state operations */ - - up_idle(); - } - } - while (ret < 0); -#endif - /* Enter the IDLE loop */ sdbg("CPU%d: Beginning Idle Loop\n", this_cpu()); @@ -165,122 +131,6 @@ int os_idletask(int argc, FAR char *argv[]) } } -/**************************************************************************** - * Name: os_idletcb_setup - * - * Description: - * Initialize the IDLE task TCB for this CPU and add it to the correct OS - * task list. The calling sequence here is: - * - * 1. os_start() - Initializes the system and calls os_smpstart() - * 2. os_smpstart() - Calls up_cpustart() for each CPU 1..(CONFIG_SMP_NCPUS-1) - * 3. up_cpustart() - Calls os_idletcb_setup() when appropriate to configure - * the OS data structures. - * 4. up_cpustart() - may also call os_idletcb_teardown() to recover from - * from any errors. - * - * Input Parameters: - * cpu - The CPU to undel - * idle - Memory allocated by os_idletcb_setup - * pid - Task ID of the IDLE task - * - * Returned Value: - * Memory allocated by os_idletcb_setup (for error recovery). NULL is - * returned only a a failure to allocate memory. - * - ****************************************************************************/ - -static FAR void *os_idletcb_setup(int cpu, main_t idletask, pid_t pid) -{ - FAR struct os_tcballoc_s *alloc; - FAR struct task_tcb_s *itcb; - dq_queue_t *tasklist; - - /* IDLE TCB Initialization ************************************************/ - /* Allocate and clear the IDLE TCB */ - - alloc = (FAR struct os_tcballoc_s *)kmm_zalloc(sizeof(struct os_tcballoc_s)); - if (alloc == NULL) - { - return NULL; - } - - /* Initialize the TCB for the IDLE task on the stack. - * REVISIT: We should be able to use task_schedsetup() to do most of this - */ - - itcb = &alloc->tcb; - itcb->cmn.task_state = TSTATE_TASK_RUNNING; - itcb->cmn.entry.main = idletask; - itcb->cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); - itcb->cmn.cpu = cpu; - -#if CONFIG_TASK_NAME_SIZE > 0 - snprintf(itcb->cmn.name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", cpu); - alloc->idleargv[0] = itcb->cmn.name; -#else - alloc->idleargv[0] = (FAR char *)g_idlename; -#endif - alloc->idleargv[1] = NULL; - itcb->argv = alloc->idleargv; - - /* Add the IDLE task TCB to the end of the assigned task list */ - - tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, cpu); - dq_addfirst((FAR dq_entry_t *)itcb, tasklist); - - /* Initialize the processor-specific portion of the TCB */ - - up_initial_state(&itcb->cmn); - - /* PID assignment *********************************************************/ - - g_pidhash[PIDHASH(pid)].tcb = &itcb->cmn; - - /* IDLE Group Initialization **********************************************/ -#ifdef HAVE_TASK_GROUP - /* Allocate the IDLE group */ - - DEBUGVERIFY(group_allocate(itcb, itcb->cmn.flags)); -#endif - -#ifdef HAVE_TASK_GROUP - /* Complete initialization of the IDLE group. Suppress retention - * of child status in the IDLE group. - */ - - DEBUGVERIFY(group_initialize(itcb)); - itcb->cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT; -#endif - - return alloc; -} - -/**************************************************************************** - * Name: os_idletcb_teardown - * - * Description: - * Undo what os_idletcb_setup() did. Necessary only for error recovery. - * - * Input Parameters: - * cpu - The CPU to undel - * alloc - Memory allocated by os_idletcb_setup - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void os_idletcb_teardown(int cpu, FAR void *alloc) -{ - /* Undo what os_idletcb_setup() did */ - - FAR dq_queue_t *tasklist= TLIST_HEAD(TSTATE_TASK_RUNNING, 0); - dq_init(tasklist); - - kmm_free(alloc); -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -308,41 +158,19 @@ static void os_idletcb_teardown(int cpu, FAR void *alloc) int os_smpstart(void) { - FAR void *alloc; - pid_t pid; int ret; int cpu; - /* Reserve PIDs for IDLE tasks 1..(CONFIG_SMP_NCPUS-1). We do not have to - * be careful here because so far because there is only one CPU running and - * we have not yet started multi-tasking. - */ - - pid = g_lastpid + 1; /* Should be 1 */ - g_lastpid += CONFIG_SMP_NCPUS; /* Should be CONFIG_SMP_NCPUS */ - /* CPU0 is already running. Start the remaining CPUs */ - for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++, pid++) + for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++) { - /* Assign a PID to the IDLE task and set up the IDLE thread TCB */ - - alloc = os_idletcb_setup(cpu, os_idletask, pid); - if (alloc == NULL) - { - return -ENOMEM; - } - /* And start the CPU. */ - ret = up_cpustart(cpu, os_idletask, pid); + ret = up_cpustart(cpu, os_idletask); if (ret < 0) { sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret); - - /* Undo what os_idletcb_setup() did and return the failure*/ - - os_idletcb_teardown(cpu, alloc); return ret; } } diff --git a/sched/init/os_start.c b/sched/init/os_start.c index d201553387..efac6fcc78 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -39,13 +39,14 @@ #include #include +#include #include #include #include #include #include -#include +#include #include #include #include @@ -296,27 +297,40 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] = uint8_t g_os_initstate; /* See enum os_initstate_e */ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ -/* This is the task control block for this thread of execution. This thread - * of execution is the IDLE task. NOTE: the system boots into the IDLE - * task. The IDLE task spawns the user initialization task and that user - * initialization task is responsible for bringing up the rest of the system. +/* This is an arry of task control block (TCB) for the IDLE thread of each + * CPU. For the non-SMP case, this is a a single TCB; For the SMP case, + * there is one TCB per CPU. NOTE: The system boots on CPU0 into the IDLE + * task. The IDLE task later starts the other CPUs and spawns the user + * initialization task. That user initialization task is responsible for + * bringing up the rest of the system. */ -static struct task_tcb_s g_idletcb; +#ifdef CONFIG_SMP +static struct task_tcb_s g_idletcb[CONFIG_SMP_NCPUS]; +#else +static struct task_tcb_s g_idletcb[1]; +#endif /* This is the name of the idle task */ #ifdef CONFIG_SMP -static const char g_idlename[] = "CPU0 Idle"; +static const char g_idlename[] = "CPU Idle"; #else static const char g_idlename[] = "Idle Task"; #endif -/* This the IDLE idle threads argument list. */ +/* This the IDLE idle threads argument list. NOTE: Normally the argument + * list is created on the stack prior to starting the task. We have to + * do things s little differently here for the IDLE tasks. + */ +#ifdef CONFIG_SMP +static FAR char *g_idleargv[CONFIG_SMP_NCPUS][2]; +#else static FAR char *g_idleargv[2]; +#endif /**************************************************************************** * Public Functions @@ -340,7 +354,11 @@ static FAR char *g_idleargv[2]; void os_start(void) { - FAR dq_queue_t *tasklist; +#ifdef CONFIG_SMP + int cpu; +#else +# define cpu 0 +#endif int i; slldbg("Entry\n"); @@ -390,68 +408,100 @@ void os_start(void) g_pidhash[i].pid = INVALID_PROCESS_ID; } - /* Assign the process ID of ZERO to the idle task */ + /* Initialize the IDLE task TCB *******************************************/ - g_pidhash[PIDHASH(0)].tcb = &g_idletcb.cmn; - g_pidhash[PIDHASH(0)].pid = 0; +#ifdef CONFIG_SMP + for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++, g_lastpid++) +#endif + { + FAR dq_queue_t *tasklist; - /* Initialize the IDLE task TCB *******************************************/ - /* Initialize a TCB for this thread of execution. NOTE: The default - * value for most components of the g_idletcb are zero. The entire - * structure is set to zero. Then only the (potentially) non-zero - * elements are initialized. NOTE: The idle task is the only task in - * that has pid == 0 and sched_priority == 0. - */ + /* Assign the process ID(s) of ZERO to the idle task(s) */ - bzero((void *)&g_idletcb, sizeof(struct task_tcb_s)); - g_idletcb.cmn.task_state = TSTATE_TASK_RUNNING; - g_idletcb.cmn.entry.main = (main_t)os_start; + g_pidhash[PIDHASH(0)].tcb = &g_idletcb[cpu].cmn; + g_pidhash[PIDHASH(0)].pid = g_lastpid; - /* Set the task flags to indicate that this is a kernel thread and, if - * configured for SMP, that this task is assigned to CPU0. - */ + /* Initialize a TCB for this thread of execution. NOTE: The default + * value for most components of the g_idletcb are zero. The entire + * structure is set to zero. Then only the (potentially) non-zero + * elements are initialized. NOTE: The idle task is the only task in + * that has pid == 0 and sched_priority == 0. + */ + + bzero((void *)&g_idletcb[cpu], sizeof(struct task_tcb_s)); + g_idletcb[cpu].cmn.task_state = TSTATE_TASK_RUNNING; + + /* Set the entry point. This is only for debug purposes. NOTE: that + * the start_t entry point is not saved. That is acceptable, however, + * becaue it can be used only for restarting a task: The IDLE task + * cannot be restarted. + */ #ifdef CONFIG_SMP - g_idletcb.cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); + if (cpu > 0) + { + g_idletcb[cpu].cmn.entry.main = os_idletask; + } + else #else - g_idletcb.cmn.flags = TCB_FLAG_TTYPE_KERNEL; + { + g_idletcb[cpu].cmn.entry.main = (main_t)os_start; + } #endif - /* Set the IDLE task name */ + /* Set the task flags to indicate that this is a kernel thread and, if + * configured for SMP, that this task is assigned to the correct CPU. + */ + +#ifdef CONFIG_SMP + g_idletcb[cpu].cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); + g_idletcb[cpu].cmn.cpu = cpu; +#else + g_idletcb[cpu].cmn.flags = TCB_FLAG_TTYPE_KERNEL; +#endif + + /* Set the IDLE task name */ #if CONFIG_TASK_NAME_SIZE > 0 - strncpy(g_idletcb.cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE); - g_idletcb.cmn.name[CONFIG_TASK_NAME_SIZE] = '\0'; -#endif /* CONFIG_TASK_NAME_SIZE */ +# ifdef CONFIG_SMP + snprintf(g_idletcb[cpu].cmn.name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", cpu); +# else + strncpy(g_idletcb[cpu].cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE); + g_idletcb[cpu].cmn.name[CONFIG_TASK_NAME_SIZE] = '\0'; +# endif +#endif - /* Configure the task name in the argument list. The IDLE task does - * not really have an argument list, but this name is still useful - * for things like the NSH PS command. - * - * In the kernel mode build, the arguments are saved on the task's stack - * and there is no support that yet. - */ + /* Configure the task name in the argument list. The IDLE task does + * not really have an argument list, but this name is still useful + * for things like the NSH PS command. + * + * In the kernel mode build, the arguments are saved on the task's + * stack and there is no support that yet. + */ #if CONFIG_TASK_NAME_SIZE > 0 - g_idleargv[0] = g_idletcb.cmn.name; + g_idleargv[cpu][0] = g_idletcb[cpu].cmn.name; #else - g_idleargv[0] = (FAR char *)g_idlename; + g_idleargv[cpu][0] = (FAR char *)g_idlename; #endif /* CONFIG_TASK_NAME_SIZE */ - g_idleargv[1] = NULL; - g_idletcb.argv = g_idleargv; + g_idleargv[cpu][1] = NULL; + g_idletcb[cpu].argv = &g_idleargv[cpu][0]; - /* Then add the idle task's TCB to the head of the ready to run list */ + /* Then add the idle task's TCB to the head of the corrent ready to + * run list. + */ #ifdef CONFIG_SMP - tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, 0); + tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, cpu); #else - tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING); + tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING); #endif - dq_addfirst((FAR dq_entry_t *)&g_idletcb, tasklist); + dq_addfirst((FAR dq_entry_t *)&g_idletcb[cpu], tasklist); - /* Initialize the processor-specific portion of the TCB */ + /* Initialize the processor-specific portion of the TCB */ - up_initial_state(&g_idletcb.cmn); + up_initial_state(&g_idletcb[cpu].cmn); + } /* Initialize RTOS facilities *********************************************/ /* Initialize the semaphore facility. This has to be done very early @@ -632,28 +682,46 @@ void os_start(void) lib_initialize(); /* IDLE Group Initialization **********************************************/ + +#ifdef CONFIG_SMP + for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++) +#endif + { #ifdef HAVE_TASK_GROUP - /* Allocate the IDLE group */ + /* Allocate the IDLE group */ - DEBUGVERIFY(group_allocate(&g_idletcb, g_idletcb.cmn.flags)); + DEBUGVERIFY(group_allocate(&g_idletcb[cpu], g_idletcb[cpu].cmn.flags)); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - /* Create stdout, stderr, stdin on the IDLE task. These will be - * inherited by all of the threads created by the IDLE task. - */ +#ifdef CONFIG_SMP + if (cpu > 0) + { + /* Clone stdout, stderr, stdin from the CPU0 IDLE task. */ - DEBUGVERIFY(group_setupidlefiles(&g_idletcb)); + DEBUGVERIFY(group_setuptaskfiles(&g_idletcb[cpu])); + } + else +#endif + { + /* Create stdout, stderr, stdin on the CPU0 IDLE task. These + * will be inherited by all of the threads created by the CPU0 + * IDLE task. + */ + + DEBUGVERIFY(group_setupidlefiles(&g_idletcb[cpu])); + } #endif #ifdef HAVE_TASK_GROUP - /* Complete initialization of the IDLE group. Suppress retention - * of child status in the IDLE group. - */ + /* Complete initialization of the IDLE group. Suppress retention + * of child status in the IDLE group. + */ - DEBUGVERIFY(group_initialize(&g_idletcb)); - g_idletcb.cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT; + DEBUGVERIFY(group_initialize(&g_idletcb[cpu])); + g_idletcb[cpu].cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT; #endif +} #ifdef CONFIG_SMP /* Start all CPUs *********************************************************/ -- GitLab From 97cbd7112f480e6e1cdac6bfa93a7d89d7002d02 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Feb 2016 10:23:16 -0600 Subject: [PATCH 721/858] SMP: Implement enter/leave_critical_section --- include/nuttx/irq.h | 40 ++++++++++++++++++++++++++++++++++++++ include/nuttx/sched.h | 3 +++ include/nuttx/spinlock.h | 21 ++++++++++++++++++-- sched/irq/Make.defs | 6 +++++- sched/irq/irq.h | 22 +++++++++++++-------- sched/irq/irq_initialize.c | 17 ---------------- sched/semaphore/spinlock.c | 6 +++--- 7 files changed, 84 insertions(+), 31 deletions(-) diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index 43b9992cfd..519059c7f6 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -40,8 +40,11 @@ * Included Files ****************************************************************************/ +#include + #ifndef __ASSEMBLY__ # include +# include #endif /**************************************************************************** @@ -97,6 +100,43 @@ extern "C" int irq_attach(int irq, xcpt_t isr); +/**************************************************************************** + * Name: enter_critical_section + * + * Description: + * If SMP is enabled: + * Take the CPU IRQ lock and disable interrupts on all CPUs. A thread- + * specific counter is increment to indicate that the thread has IRQs + * disabled and to support nested calls to enter_critical_section(). + * If SMP is not enabled: + * This function is equivalent to irqsave(). + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +irqstate_t enter_critical_section(void); +#else +# define enter_critical_section(f) irqsave(f) +#endif + +/**************************************************************************** + * Name: leave_critical_section + * + * Description: + * If SMP is enabled: + * Decrement the IRQ lock count and if it decrements to zero then release + * the spinlock. + * If SMP is not enabled: + * This function is equivalent to irqrestore(). + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +void leave_critical_section(irqstate_t flags); +#else +# define leave_critical_section(f) irqrestore(f) +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index a0f3d13792..cade6cde3e 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -560,6 +560,9 @@ struct tcb_s #endif uint16_t flags; /* Misc. general status flags */ int16_t lockcount; /* 0=preemptable (not-locked) */ +#ifdef CONFIG_SMP + int16_t irqcount; /* 0=interrupts enabled */ +#endif #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) int32_t timeslice; /* RR timeslice OR Sporadic budget */ diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 9305c40d50..ad034fa650 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -103,7 +103,7 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock); * Name: spin_initialize * * Description: - * Initialize a spinlock object to its initial, unlocked state. + * Initialize a non-reentrant spinlock object to its initial, unlocked state. * * Input Parameters: * lock - A reference to the spinlock object to be initialized. @@ -113,7 +113,24 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock); * ****************************************************************************/ -void spin_initialize(FAR struct spinlock_s *lock); +/* void spin_initialize(FAR spinlock_t *lock); */ +#define spin_initialize(i) do { (l) = SPI_UNLOCKED; } while (0) + +/**************************************************************************** + * Name: spin_initializer + * + * Description: + * Initialize a re-entrant spinlock object to its initial, unlocked state. + * + * Input Parameters: + * lock - A reference to the spinlock object to be initialized. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void spin_initializer(FAR struct spinlock_s *lock); /**************************************************************************** * Name: spin_lock diff --git a/sched/irq/Make.defs b/sched/irq/Make.defs index 706569f66b..905720750e 100644 --- a/sched/irq/Make.defs +++ b/sched/irq/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # sched/irq/Make.defs # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,10 @@ CSRCS += irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c +ifeq ($(CONFIG_SMP),y) +CSRCS += irq_csection.c +endif + # Include irq build support DEPPATH += --dep-path irq diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 2e0269243b..d2c6321968 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -41,24 +41,30 @@ ****************************************************************************/ #include +#include #include #include -#include +#include /**************************************************************************** - * Pre-processor Definitions + * Public Data ****************************************************************************/ -/**************************************************************************** - * Public Type Declarations - ****************************************************************************/ +/* This is the list of interrupt handlers, one for each IRQ. This is used + * by irq_dispatch to transfer control to interrupt handlers after the + * occurrence of an interrupt. + */ extern FAR xcpt_t g_irqvector[NR_IRQS+1]; -/**************************************************************************** - * Public Data - ****************************************************************************/ +#ifdef CONFIG_SMP +/* This is the spinlock that enforces critical sections when interrupts are + * disabled. + */ + +extern spinlock_t g_cpu_irqlock; +#endif /**************************************************************************** * Public Function Prototypes diff --git a/sched/irq/irq_initialize.c b/sched/irq/irq_initialize.c index 9043260914..d558ff97e1 100644 --- a/sched/irq/irq_initialize.c +++ b/sched/irq/irq_initialize.c @@ -43,28 +43,12 @@ #include "irq/irq.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ FAR xcpt_t g_irqvector[NR_IRQS+1]; -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -88,4 +72,3 @@ void irq_initialize(void) g_irqvector[i] = irq_unexpected_isr; } } - diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index b5396273a8..7b12ffaf18 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -68,10 +68,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: spin_initialize + * Name: spin_initializer * * Description: - * Initialize a spinlock object to its initial, unlocked state. + * Initialize a re-entrant spinlock object to its initial, unlocked state. * * Input Parameters: * lock - A reference to the spinlock object to be initialized. @@ -81,7 +81,7 @@ * ****************************************************************************/ -void spin_initialize(FAR struct spinlock_s *lock) +void spin_initializer(FAR struct spinlock_s *lock) { DEBUGASSERT(lock != NULL); -- GitLab From d017e3eb2eb95d5122d1596084883b2a82b76d89 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Feb 2016 10:25:36 -0600 Subject: [PATCH 722/858] SMP: Forgot to add a file before the last commit --- sched/irq/irq_csection.c | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 sched/irq/irq_csection.c diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c new file mode 100644 index 0000000000..536117151d --- /dev/null +++ b/sched/irq/irq_csection.c @@ -0,0 +1,142 @@ +/**************************************************************************** + * sched/irq/irq_csection.c + * + * Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "sched/sched.h" +#include "irq/irq.h" + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Public Data + ****************************************************************************/ +/* This is the spinlock that enforces critical sections when interrupts are + * disabled. + */ + +spinlock_t g_cpu_irqlock = SP_UNLOCKED; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: enter_critical_section + * + * Description: + * Take the CPU IRQ lock and disable interrupts on all CPUs. A thread- + * specific counter is increment to indicate that the thread has IRQs + * disabled and to support nested calls to enter_critical_section(). + * + ****************************************************************************/ + +irqstate_t enter_critical_section(void) +{ + FAR struct tcb_s *rtcb = this_task(); + + /* Do we already have interrupts disabled? */ + + if (rtcb->irqcount > 0) + { + /* Yes... make sure that the spinlock is set and increment the IRQ + * lock count. + */ + + DEBUGASSERT(g_cpu_irqlock == SP_LOCKED && rtcb->irqcount < INT16_MAX); + rtcb->irqcount++; + } + else + { + /* NO.. Take the spinlock to get exclusive access and set the lock + * count to 1. + */ + + spin_lock(&g_cpu_irqlock); + rtcb->irqcount = 1; + } + + /* Then disable interrupts (if they have not already been disabeld) */ + + return irqsave(); +} + +/**************************************************************************** + * Name: leave_critical_section + * + * Description: + * Decrement the IRQ lock count and if it decrements to zero then release + * the spinlock. + * + ****************************************************************************/ + +void leave_critical_section(irqstate_t flags) +{ + FAR struct tcb_s *rtcb = this_task(); + + DEBUGASSERT(rtcb->irqcount > 0); + + /* Will we still have interrupts disabled after decrementing the count? */ + + if (rtcb->irqcount > 1) + { + /* Yes... make sure that the spinlock is set */ + + DEBUGASSERT(g_cpu_irqlock == SP_LOCKED); + rtcb->irqcount--; + } + else + { + /* NO.. Take the spinlock to get exclusive access. */ + + rtcb->irqcount = 0; + spin_unlock(g_cpu_irqlock); + } + + /* Restore the previous interrupt state which may still be interrupts + * disabled (but we don't have a mechanism to verify that now) + */ + + irqrestore(flags); +} + +#endif /* CONFIG_SMP */ -- GitLab From a604a8698045aac8d1b2225e21fb1f032e0cb038 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Feb 2016 10:48:30 -0600 Subject: [PATCH 723/858] Fix an error introduced in a previous commit --- sched/init/os_start.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sched/init/os_start.c b/sched/init/os_start.c index efac6fcc78..fc2066e620 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -329,7 +329,7 @@ static const char g_idlename[] = "Idle Task"; #ifdef CONFIG_SMP static FAR char *g_idleargv[CONFIG_SMP_NCPUS][2]; #else -static FAR char *g_idleargv[2]; +static FAR char *g_idleargv[1][2]; #endif /**************************************************************************** -- GitLab From d09db96a7c2b905c11f8640d0c76ba080838d45c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Feb 2016 19:28:57 -0600 Subject: [PATCH 724/858] Update ChangeLog --- ChangeLog | 3 +++ arch | 2 +- configs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a994b05c15..78892f8035 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11483,4 +11483,7 @@ * sched/sched.h and other files: Replace the bool 'prioritized' in the task list table with a uint8_t bit set so that additional attributes of a task list can be provided without adding more booleans (2016-10-11). + * Everywhere: Replace irqsave() with enter_critical_section(); replace + irqrestore() with leave_critical_section(). This is part of the onging + development of SMP support (2016-02-13). diff --git a/arch b/arch index 4abb852339..354df5c0f3 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4abb8523390cecded97fe325448213983e47aedf +Subproject commit 354df5c0f3f7e0f4df605a85edef7d8e170843c1 diff --git a/configs b/configs index f9d09bf8c0..cfbc3f7c3e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit f9d09bf8c091cc2d8578ae572ad8f48bb93d062a +Subproject commit cfbc3f7c3e07bf07b012e42933f3fea7c2397d52 -- GitLab From 2244ed46bcbd88f24ed508a3d464712480bb89ec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 07:32:58 -0600 Subject: [PATCH 725/858] nuttx/drivers: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- drivers/analog/adc.c | 14 +++---- drivers/analog/dac.c | 14 +++---- drivers/audio/wm8904.c | 27 +++++--------- drivers/can.c | 26 ++++++------- drivers/input/ads7843e.c | 13 ++++--- drivers/input/ajoystick.c | 14 +++---- drivers/input/button_lower.c | 10 ++--- drivers/input/button_upper.c | 14 +++---- drivers/input/djoystick.c | 14 +++---- drivers/input/max11802.c | 15 ++++---- drivers/input/mxt.c | 7 ++-- drivers/input/tsc2007.c | 15 ++++---- drivers/leds/userled_upper.c | 7 ++-- drivers/net/cs89x0.c | 8 ++-- drivers/net/dm90x0.c | 8 ++-- drivers/net/e1000.c | 8 ++-- drivers/net/enc28j60.c | 10 ++--- drivers/net/encx24j600.c | 8 ++-- drivers/net/ftmac100.c | 20 +++++----- drivers/net/skeleton.c | 8 ++-- drivers/net/vnet.c | 8 ++-- drivers/power/pm_activity.c | 6 +-- drivers/power/pm_changestate.c | 6 +-- drivers/power/pm_checkstate.c | 6 +-- drivers/pwm.c | 6 +-- drivers/sensors/zerocross.c | 14 +++---- drivers/serial/serial.c | 44 +++++++++++----------- drivers/serial/uart_16550.c | 12 +++--- drivers/syslog/ramlog.c | 16 ++++---- drivers/usbdev/cdcacm.c | 49 ++++++++++++------------- drivers/usbdev/composite.c | 23 +++++------- drivers/usbdev/pl2303.c | 37 ++++++++++--------- drivers/usbdev/usbdev_trace.c | 10 ++--- drivers/usbdev/usbmsc.c | 31 ++++++++-------- drivers/usbdev/usbmsc_scsi.c | 39 ++++++++++---------- drivers/usbhost/usbhost_cdcacm.c | 33 +++++++++-------- drivers/usbhost/usbhost_findclass.c | 26 +++---------- drivers/usbhost/usbhost_hidkbd.c | 27 +++++++------- drivers/usbhost/usbhost_hidmouse.c | 35 +++++++++--------- drivers/usbhost/usbhost_hub.c | 15 ++++---- drivers/usbhost/usbhost_registerclass.c | 6 +-- drivers/usbhost/usbhost_skeleton.c | 17 +++++---- drivers/usbhost/usbhost_storage.c | 33 +++++++++-------- drivers/usbhost/usbhost_trace.c | 6 +-- drivers/wireless/cc3000/cc3000.c | 21 ++++++----- 45 files changed, 386 insertions(+), 400 deletions(-) diff --git a/drivers/analog/adc.c b/drivers/analog/adc.c index b856d39589..ff6031ee68 100644 --- a/drivers/analog/adc.c +++ b/drivers/analog/adc.c @@ -59,7 +59,7 @@ #include #include -#include +#include /**************************************************************************** * Private Function Prototypes @@ -134,7 +134,7 @@ static int adc_open(FAR struct file *filep) { /* Yes.. perform one time hardware initialization. */ - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); ret = dev->ad_ops->ao_setup(dev); if (ret == OK) { @@ -152,7 +152,7 @@ static int adc_open(FAR struct file *filep) dev->ad_ocount = tmp; } - irqrestore(flags); + leave_critical_section(flags); } } @@ -201,9 +201,9 @@ static int adc_close(FAR struct file *filep) /* Free the IRQ and disable the ADC device */ - flags = irqsave(); /* Disable interrupts */ + flags = enter_critical_section(); /* Disable interrupts */ dev->ad_ops->ao_shutdown(dev); /* Disable the ADC */ - irqrestore(flags); + leave_critical_section(flags); sem_post(&dev->ad_closesem); } @@ -244,7 +244,7 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { /* Interrupts must be disabled while accessing the ad_recv FIFO */ - flags = irqsave(); + flags = enter_critical_section(); while (dev->ad_recv.af_head == dev->ad_recv.af_tail) { /* The receive FIFO is empty -- was non-blocking mode selected? */ @@ -340,7 +340,7 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer, size_t buflen) ret = nread; return_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); } avdbg("Returning: %d\n", ret); diff --git a/drivers/analog/dac.c b/drivers/analog/dac.c index 12be8837b5..daf8b5f34a 100644 --- a/drivers/analog/dac.c +++ b/drivers/analog/dac.c @@ -59,7 +59,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions @@ -143,7 +143,7 @@ static int dac_open(FAR struct file *filep) { /* Yes.. perform one time hardware initialization. */ - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); ret = dev->ad_ops->ao_setup(dev); if (ret == OK) { @@ -157,7 +157,7 @@ static int dac_open(FAR struct file *filep) dev->ad_ocount = tmp; } - irqrestore(flags); + leave_critical_section(flags); } } @@ -217,9 +217,9 @@ static int dac_close(FAR struct file *filep) /* Free the IRQ and disable the DAC device */ - flags = irqsave(); /* Disable interrupts */ + flags = enter_critical_section(); /* Disable interrupts */ dev->ad_ops->ao_shutdown(dev); /* Disable the DAC */ - irqrestore(flags); + leave_critical_section(flags); sem_post(&dev->ad_closesem); } @@ -289,7 +289,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t /* Interrupts must disabled throughout the following */ - flags = irqsave(); + flags = enter_critical_section(); /* Check if the TX FIFO was empty when we started. That is a clue that we have * to kick off a new TX sequence. @@ -442,7 +442,7 @@ static ssize_t dac_write(FAR struct file *filep, FAR const char *buffer, size_t ret = nsent; return_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c index 8d441e00ce..a437c137e8 100644 --- a/drivers/audio/wm8904.c +++ b/drivers/audio/wm8904.c @@ -3,7 +3,7 @@ * * Audio device driver for Wolfson Microelectronics WM8904 Audio codec. * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -59,6 +59,7 @@ #include #include +#include #include #include #include @@ -72,14 +73,6 @@ #include "wm8904.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -1324,7 +1317,7 @@ static void wm8904_senddone(FAR struct i2s_dev_s *i2s, * against that possibility. */ - flags = irqsave(); + flags = enter_critical_section(); /* Add the completed buffer to the end of our doneq. We do not yet * decrement the reference count. @@ -1341,7 +1334,7 @@ static void wm8904_senddone(FAR struct i2s_dev_s *i2s, /* REVISIT: This can be overwritten */ priv->result = result; - irqrestore(flags); + leave_critical_section(flags); /* Now send a message to the worker thread, informing it that there are * buffers in the done queue that need to be cleaned up. @@ -1376,13 +1369,13 @@ static void wm8904_returnbuffers(FAR struct wm8904_dev_s *priv) * use interrupt controls to protect against that possibility. */ - flags = irqsave(); + flags = enter_critical_section(); while (dq_peek(&priv->doneq) != NULL) { /* Take the next buffer from the queue of completed transfers */ apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->doneq); - irqrestore(flags); + leave_critical_section(flags); audvdbg("Returning: apb=%p curbyte=%d nbytes=%d flags=%04x\n", apb, apb->curbyte, apb->nbytes, apb->flags); @@ -1417,10 +1410,10 @@ static void wm8904_returnbuffers(FAR struct wm8904_dev_s *priv) #else priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK); #endif - flags = irqsave(); + flags = enter_critical_section(); } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -1468,9 +1461,9 @@ static int wm8904_sendbuffer(FAR struct wm8904_dev_s *priv) * to avoid a possible race condition. */ - flags = irqsave(); + flags = enter_critical_section(); priv->inflight++; - irqrestore(flags); + leave_critical_section(flags); /* Send the entire audio buffer via I2S. What is a reasonable timeout * to use? This would depend on the bit rate and size of the buffer. diff --git a/drivers/can.c b/drivers/can.c index e00d7ca337..a98e1145bc 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -58,7 +58,7 @@ # include #endif -#include +#include #ifdef CONFIG_CAN @@ -308,7 +308,7 @@ static void can_txready_work(FAR void *arg) * be performed with interrupt disabled. */ - flags = irqsave(); + flags = enter_critical_section(); if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail) { /* Send the next message in the FIFO. */ @@ -333,7 +333,7 @@ static void can_txready_work(FAR void *arg) } } - irqrestore(flags); + leave_critical_section(flags); } #endif @@ -382,7 +382,7 @@ static int can_open(FAR struct file *filep) { /* Yes.. perform one time hardware initialization. */ - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); ret = dev_setup(dev); if (ret == OK) { @@ -403,7 +403,7 @@ static int can_open(FAR struct file *filep) dev->cd_ocount = 1; } - irqrestore(flags); + leave_critical_section(flags); } else { @@ -486,9 +486,9 @@ static int can_close(FAR struct file *filep) /* Free the IRQ and disable the CAN device */ - flags = irqsave(); /* Disable interrupts */ + flags = enter_critical_section(); /* Disable interrupts */ dev_shutdown(dev); /* Disable the CAN */ - irqrestore(flags); + leave_critical_section(flags); sem_post(&dev->cd_closesem); } @@ -525,7 +525,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, { /* Interrupts must be disabled while accessing the cd_recv FIFO */ - flags = irqsave(); + flags = enter_critical_section(); while (dev->cd_recv.rx_head == dev->cd_recv.rx_tail) { /* The receive FIFO is empty -- was non-blocking mode selected? */ @@ -592,7 +592,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, ret = nread; return_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); } return ret; @@ -701,7 +701,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, /* Interrupts must disabled throughout the following */ - flags = irqsave(); + flags = enter_critical_section(); /* Check if the TX is inactive when we started. In certain race conditions, * there may be a pending interrupt to kick things back off, but we will @@ -811,7 +811,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, ret = nsent; return_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -836,7 +836,7 @@ static inline ssize_t can_rtrread(FAR struct can_dev_s *dev, /* Disable interrupts through this operation */ - flags = irqsave(); + flags = enter_critical_section(); /* Find an available slot in the pending RTR list */ @@ -866,7 +866,7 @@ static inline ssize_t can_rtrread(FAR struct can_dev_s *dev, } } - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/drivers/input/ads7843e.c b/drivers/input/ads7843e.c index 1648b7fddf..22b7606e63 100644 --- a/drivers/input/ads7843e.c +++ b/drivers/input/ads7843e.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/input/ads7843e.c * - * Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Diego Sanchez * @@ -63,6 +63,7 @@ #include #include +#include #include #include #include @@ -340,7 +341,7 @@ static int ads7843e_sample(FAR struct ads7843e_dev_s *priv, * from changing until it has been reported. */ - flags = irqsave(); + flags = enter_critical_section(); /* Is there new ADS7843E sample data available? */ @@ -375,7 +376,7 @@ static int ads7843e_sample(FAR struct ads7843e_dev_s *priv, ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -398,7 +399,7 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv, */ sched_lock(); - flags = irqsave(); + flags = enter_critical_section(); /* Now release the semaphore that manages mutually exclusive access to * the device structure. This may cause other tasks to become ready to @@ -448,7 +449,7 @@ errout: * have pre-emption disabled. */ - irqrestore(flags); + leave_critical_section(flags); /* Restore pre-emption. We might get suspended here but that is okay * because we already have our sample. Note: this means that if there @@ -1235,7 +1236,7 @@ int ads7843e_register(FAR struct spi_dev_s *spi, #ifdef CONFIG_ADS7843E_MULTIPLE priv->flink = g_ads7843elist; g_ads7843elist = priv; - irqrestore(flags); + leave_critical_section(flags); #endif /* Schedule work to perform the initial sampling and to set the data diff --git a/drivers/input/ajoystick.c b/drivers/input/ajoystick.c index ea1fc7848c..6c916d9f39 100644 --- a/drivers/input/ajoystick.c +++ b/drivers/input/ajoystick.c @@ -61,7 +61,7 @@ #include #include -#include +#include /**************************************************************************** * Private Types @@ -216,7 +216,7 @@ static void ajoy_enable(FAR struct ajoy_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Visit each opened reference to the device */ @@ -266,7 +266,7 @@ static void ajoy_enable(FAR struct ajoy_upperhalf_s *priv) lower->al_enable(lower, 0, 0, NULL, NULL); } - irqrestore(flags); + leave_critical_section(flags); } #endif @@ -314,7 +314,7 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Sample the new button state */ @@ -386,7 +386,7 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv) #endif priv->au_sample = sample; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -485,10 +485,10 @@ static int ajoy_close(FAR struct file *filep) * detection anyway. */ - flags = irqsave(); + flags = enter_critical_section(); closing = opriv->ao_closing; opriv->ao_closing = true; - irqrestore(flags); + leave_critical_section(flags); if (closing) { diff --git a/drivers/input/button_lower.c b/drivers/input/button_lower.c index fefab10b8c..868e1681a6 100644 --- a/drivers/input/button_lower.c +++ b/drivers/input/button_lower.c @@ -46,7 +46,7 @@ #include #include -#include +#include #undef __KERNEL__ #include @@ -135,7 +135,7 @@ static void btn_enable(FAR const struct btn_lowerhalf_s *lower, /* Start with all interrupts disabled */ - flags = irqsave(); + flags = enter_critical_section(); btn_disable(); illvdbg("press: %02x release: %02x handler: %p arg: %p\n", @@ -164,7 +164,7 @@ static void btn_enable(FAR const struct btn_lowerhalf_s *lower, } } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -182,7 +182,7 @@ static void btn_disable(void) /* Disable each button interrupt */ - flags = irqsave(); + flags = enter_critical_section(); for (id = 0; id < NUM_BUTTONS; id++) { (void)board_button_irq(id, NULL); @@ -192,7 +192,7 @@ static void btn_disable(void) g_btnhandler = NULL; g_btnarg = NULL; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/input/button_upper.c b/drivers/input/button_upper.c index 81e2157039..5eadfd87e3 100644 --- a/drivers/input/button_upper.c +++ b/drivers/input/button_upper.c @@ -57,7 +57,7 @@ #include #include -#include +#include /**************************************************************************** * Private Types @@ -212,7 +212,7 @@ static void btn_enable(FAR struct btn_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Visit each opened reference to the device */ @@ -262,7 +262,7 @@ static void btn_enable(FAR struct btn_upperhalf_s *priv) lower->bl_enable(lower, 0, 0, NULL, NULL); } - irqrestore(flags); + leave_critical_section(flags); } #endif @@ -310,7 +310,7 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Sample the new button state */ @@ -382,7 +382,7 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv) #endif priv->bu_sample = sample; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -481,10 +481,10 @@ static int btn_close(FAR struct file *filep) * detection anyway. */ - flags = irqsave(); + flags = enter_critical_section(); closing = opriv->bo_closing; opriv->bo_closing = true; - irqrestore(flags); + leave_critical_section(flags); if (closing) { diff --git a/drivers/input/djoystick.c b/drivers/input/djoystick.c index 93a448d2ae..5ea4cd7d28 100644 --- a/drivers/input/djoystick.c +++ b/drivers/input/djoystick.c @@ -61,7 +61,7 @@ #include #include -#include +#include /**************************************************************************** * Private Types @@ -216,7 +216,7 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Visit each opened reference to the device */ @@ -266,7 +266,7 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv) lower->dl_enable(lower, 0, 0, NULL, NULL); } - irqrestore(flags); + leave_critical_section(flags); } #endif @@ -314,7 +314,7 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Sample the new button state */ @@ -386,7 +386,7 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv) #endif priv->du_sample = sample; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -485,10 +485,10 @@ static int djoy_close(FAR struct file *filep) * detection anyway. */ - flags = irqsave(); + flags = enter_critical_section(); closing = opriv->do_closing; opriv->do_closing = true; - irqrestore(flags); + leave_critical_section(flags); if (closing) { diff --git a/drivers/input/max11802.c b/drivers/input/max11802.c index 25698427b9..2c3c1f7813 100644 --- a/drivers/input/max11802.c +++ b/drivers/input/max11802.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/input/max11802.c * - * Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014-2016 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Petteri Aimonen * @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -305,7 +306,7 @@ static int max11802_sample(FAR struct max11802_dev_s *priv, * from changing until it has been reported. */ - flags = irqsave(); + flags = enter_critical_section(); /* Is there new MAX11802 sample data available? */ @@ -340,7 +341,7 @@ static int max11802_sample(FAR struct max11802_dev_s *priv, ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -363,7 +364,7 @@ static int max11802_waitsample(FAR struct max11802_dev_s *priv, */ sched_lock(); - flags = irqsave(); + flags = enter_critical_section(); /* Now release the semaphore that manages mutually exclusive access to * the device structure. This may cause other tasks to become ready to @@ -413,7 +414,7 @@ errout: * have pre-emption disabled. */ - irqrestore(flags); + leave_critical_section(flags); /* Restore pre-emption. We might get suspended here but that is okay * because we already have our sample. Note: this means that if there @@ -1267,10 +1268,10 @@ int max11802_register(FAR struct spi_dev_s *spi, */ #ifdef CONFIG_MAX11802_MULTIPLE - flags = irqsave(); + flags = enter_critical_section(); priv->flink = g_max11802list; g_max11802list = priv; - irqrestore(flags); + leave_critical_section(flags); #endif /* Schedule work to perform the initial sampling and to set the data diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c index b37c49a622..1b370e9579 100644 --- a/drivers/input/mxt.c +++ b/drivers/input/mxt.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/input/mxt.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -673,7 +674,7 @@ static inline int mxt_waitsample(FAR struct mxt_dev_s *priv) * from changing until it has been reported. */ - flags = irqsave(); + flags = enter_critical_section(); /* Now release the semaphore that manages mutually exclusive access to * the device structure. This may cause other tasks to become ready to @@ -719,7 +720,7 @@ errout: * have pre-emption disabled. */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c index 0c1991b351..a27042400f 100644 --- a/drivers/input/tsc2007.c +++ b/drivers/input/tsc2007.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/input/tsc2007.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -62,6 +62,7 @@ #include #include +#include #include #include #include @@ -299,7 +300,7 @@ static int tsc2007_sample(FAR struct tsc2007_dev_s *priv, * from changing until it has been reported. */ - flags = irqsave(); + flags = enter_critical_section(); /* Is there new TSC2007 sample data available? */ @@ -334,7 +335,7 @@ static int tsc2007_sample(FAR struct tsc2007_dev_s *priv, ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -357,7 +358,7 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv, */ sched_lock(); - flags = irqsave(); + flags = enter_critical_section(); /* Now release the semaphore that manages mutually exclusive access to * the device structure. This may cause other tasks to become ready to @@ -403,7 +404,7 @@ errout: * have pre-emption disabled. */ - irqrestore(flags); + leave_critical_section(flags); /* Restore pre-emption. We might get suspended here but that is okay * because we already have our sample. Note: this means that if there @@ -1297,10 +1298,10 @@ int tsc2007_register(FAR struct i2c_master_s *dev, */ #ifdef CONFIG_TSC2007_MULTIPLE - flags = irqsave(); + flags = enter_critical_section(); priv->flink = g_tsc2007list; g_tsc2007list = priv; - irqrestore(flags); + leave_critical_section(flags); #endif /* Schedule work to perform the initial sampling and to set the data diff --git a/drivers/leds/userled_upper.c b/drivers/leds/userled_upper.c index 64dfab48c7..0d2377b624 100644 --- a/drivers/leds/userled_upper.c +++ b/drivers/leds/userled_upper.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/leds/userled_upper.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,7 @@ #include #include +#include #include #include #include @@ -253,10 +254,10 @@ static int userled_close(FAR struct file *filep) * detection anyway. */ - flags = irqsave(); + flags = enter_critical_section(); closing = opriv->bo_closing; opriv->bo_closing = true; - irqrestore(flags); + leave_critical_section(flags); if (closing) { diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c index 4ccc95ee73..dfaf2d6384 100644 --- a/drivers/net/cs89x0.c +++ b/drivers/net/cs89x0.c @@ -861,7 +861,7 @@ static int cs89x0_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); up_disable_irq(CONFIG_CS89x0_IRQ); /* Cancel the TX poll timer and TX timeout timers */ @@ -872,7 +872,7 @@ static int cs89x0_ifdown(struct net_driver_s *dev) /* Reset the device */ cs89x0->cs_bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -900,7 +900,7 @@ static int cs89x0_txavail(struct net_driver_s *dev) struct cs89x0_driver_s *cs89x0 = (struct cs89x0_driver_s *)dev->d_private; irqstate_t flags; - flags = irqsave(); + flags = enter_critical_section(); /* Ignore the notification if the interface is not yet up */ @@ -914,7 +914,7 @@ static int cs89x0_txavail(struct net_driver_s *dev) (void)devif_poll(&cs89x0->cs_dev, cs89x0_txpoll); } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/net/dm90x0.c b/drivers/net/dm90x0.c index aa3efbaf18..caaf0c1872 100644 --- a/drivers/net/dm90x0.c +++ b/drivers/net/dm90x0.c @@ -1411,7 +1411,7 @@ static int dm9x_ifdown(struct net_driver_s *dev) /* Disable the DM9X interrupt */ - flags = irqsave(); + flags = enter_critical_section(); up_disable_irq(CONFIG_DM9X_IRQ); /* Cancel the TX poll timer and TX timeout timers */ @@ -1428,7 +1428,7 @@ static int dm9x_ifdown(struct net_driver_s *dev) putreg(DM9X_ISR, DM9X_INT_ALL); /* Clear interrupt status */ dm9x->dm_bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -1457,7 +1457,7 @@ static int dm9x_txavail(struct net_driver_s *dev) irqstate_t flags; ndbg("Polling\n"); - flags = irqsave(); + flags = enter_critical_section(); /* Ignore the notification if the interface is not yet up */ @@ -1475,7 +1475,7 @@ static int dm9x_txavail(struct net_driver_s *dev) (void)devif_poll(&dm9x->dm_dev, dm9x_txpoll); } } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index cf3b860aca..11a4452989 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -847,7 +847,7 @@ static int e1000_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); e1000_turn_off(e1000); @@ -866,7 +866,7 @@ static int e1000_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ e1000->bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -900,7 +900,7 @@ static int e1000_txavail(struct net_driver_s *dev) * level processing. */ - flags = irqsave(); + flags = enter_critical_section(); /* Ignore the notification if the interface is not yet up */ @@ -914,7 +914,7 @@ static int e1000_txavail(struct net_driver_s *dev) } } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 37f94b867f..2ae3a01ebd 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -55,8 +55,8 @@ #include -#include #include +#include #include #include #include @@ -2149,7 +2149,7 @@ static int enc_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); priv->lower->disable(priv->lower); /* Cancel the TX poll timer and TX timeout timers */ @@ -2163,7 +2163,7 @@ static int enc_ifdown(struct net_driver_s *dev) enc_pwrsave(priv); priv->ifstate = ENCSTATE_DOWN; - irqrestore(flags); + leave_critical_section(flags); /* Un-lock the SPI bus */ @@ -2201,7 +2201,7 @@ static int enc_txavail(struct net_driver_s *dev) /* Ignore the notification if the interface is not yet up */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->ifstate == ENCSTATE_UP) { /* Check if the hardware is ready to send another packet. The driver @@ -2220,7 +2220,7 @@ static int enc_txavail(struct net_driver_s *dev) /* Un-lock the SPI bus */ - irqrestore(flags); + leave_critical_section(flags); enc_unlock(priv); return OK; } diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 360684fbac..aae63dcebb 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -2317,7 +2317,7 @@ static int enc_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); priv->lower->disable(priv->lower); /* Cancel the TX poll timer and TX timeout timers */ @@ -2331,7 +2331,7 @@ static int enc_ifdown(struct net_driver_s *dev) enc_pwrsave(priv); priv->ifstate = ENCSTATE_DOWN; - irqrestore(flags); + leave_critical_section(flags); /* Un-lock the SPI bus */ @@ -2370,7 +2370,7 @@ static int enc_txavail(struct net_driver_s *dev) /* Ignore the notification if the interface is not yet up */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->ifstate == ENCSTATE_RUNNING) { /* Check if the hardware is ready to send another packet. The driver @@ -2389,7 +2389,7 @@ static int enc_txavail(struct net_driver_s *dev) /* Un-lock the SPI bus */ - irqrestore(flags); + leave_critical_section(flags); enc_unlock(priv); return OK; diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 6f40eee1e0..fdf23a87e1 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -284,7 +284,7 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) FAR struct ftmac100_txdes_s *txdes; int len = priv->ft_dev.d_len; //irqstate_t flags; -//flags = irqsave(); +//flags = enter_critical_section(); //nvdbg("flags=%08x\n", flags); txdes = ftmac100_current_txdes(priv); @@ -323,7 +323,7 @@ static int ftmac100_transmit(FAR struct ftmac100_driver_s *priv) (void)wd_start(priv->ft_txtimeout, FTMAC100_TXTIMEOUT, ftmac100_txtimeout_expiry, 1, (wdparm_t)priv); -//irqrestore(flags); +//leave_critical_section(flags); return OK; } @@ -981,11 +981,11 @@ static void ftmac100_interrupt_work(FAR void *arg) /* Process pending Ethernet interrupts */ state = net_lock(); -//flags = irqsave(); +//flags = enter_critical_section(); ftmac100_interrupt_process(priv); -//irqrestore(flags); +//leave_critical_section(flags); net_unlock(state); /* Re-enable Ethernet interrupts */ @@ -1024,7 +1024,7 @@ static int ftmac100_interrupt(int irq, FAR void *context) * condition here. */ - flags = irqsave(); + flags = enter_critical_section(); priv->status = getreg32 (&iobase->isr); @@ -1055,7 +1055,7 @@ static int ftmac100_interrupt(int irq, FAR void *context) work_queue(HPWORK, &priv->ft_work, ftmac100_interrupt_work, priv, 0); - irqrestore(flags); + leave_critical_section(flags); #else /* Process the interrupt now */ putreg32 (INT_MASK_ALL_DISABLED, &iobase->imr); @@ -1374,7 +1374,7 @@ static int ftmac100_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); up_disable_irq(CONFIG_FTMAC100_IRQ); /* Cancel the TX poll timer and TX timeout timers */ @@ -1392,7 +1392,7 @@ static int ftmac100_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ft_bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -1501,12 +1501,12 @@ static int ftmac100_txavail(struct net_driver_s *dev) * level processing. */ - flags = irqsave(); + flags = enter_critical_section(); /* Perform the out-of-cycle poll now */ ftmac100_txavail_process(priv); - irqrestore(flags); + leave_critical_section(flags); #endif return OK; diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index ef6f2bf595..6194fbce34 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -911,7 +911,7 @@ static int skel_ifdown(FAR struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); up_disable_irq(CONFIG_skeleton_IRQ); /* Cancel the TX poll timer and TX timeout timers */ @@ -927,7 +927,7 @@ static int skel_ifdown(FAR struct net_driver_s *dev) /* Mark the device "down" */ priv->sk_bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -1036,12 +1036,12 @@ static int skel_txavail(FAR struct net_driver_s *dev) * level processing. */ - flags = irqsave(); + flags = enter_critical_section(); /* Perform the out-of-cycle poll now */ skel_txavail_process(priv); - irqrestore(flags); + leave_critical_section(flags); #endif return OK; diff --git a/drivers/net/vnet.c b/drivers/net/vnet.c index 06df87098b..eec509ec87 100644 --- a/drivers/net/vnet.c +++ b/drivers/net/vnet.c @@ -584,7 +584,7 @@ static int vnet_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = enter_critical_section(); /* Cancel the TX poll timer and TX timeout timers */ @@ -598,7 +598,7 @@ static int vnet_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ vnet->sk_bifup = false; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -630,7 +630,7 @@ static int vnet_txavail(struct net_driver_s *dev) * level processing. */ - flags = irqsave(); + flags = enter_critical_section(); /* Ignore the notification if the interface is not yet up */ @@ -652,7 +652,7 @@ static int vnet_txavail(struct net_driver_s *dev) } out: - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c index 2bf96b08c2..8394418000 100644 --- a/drivers/power/pm_activity.c +++ b/drivers/power/pm_activity.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include "pm.h" @@ -115,7 +115,7 @@ void pm_activity(int priority) { /* Add the priority to the accumulated counts in a critical section. */ - flags = irqsave(); + flags = enter_critical_section(); accum = (uint32_t)g_pmglobals.accum + priority; /* Make sure that we do not overflow the underlying uint16_t representation */ @@ -159,7 +159,7 @@ void pm_activity(int priority) (void)pm_update(tmp); } - irqrestore(flags); + leave_critical_section(flags); } } diff --git a/drivers/power/pm_changestate.c b/drivers/power/pm_changestate.c index 50aa8a07d5..271858710d 100644 --- a/drivers/power/pm_changestate.c +++ b/drivers/power/pm_changestate.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include "pm.h" @@ -194,7 +194,7 @@ int pm_changestate(enum pm_state_e newstate) * re-enabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* First, prepare the drivers for the state change. In this phase, * drivers may refuse the state state change. @@ -220,7 +220,7 @@ int pm_changestate(enum pm_state_e newstate) /* Restore the interrupt state */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index b085cbe0be..7ec0f83b63 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include "pm.h" @@ -116,7 +116,7 @@ enum pm_state_e pm_checkstate(void) * logic in pm_activity(). */ - flags = irqsave(); + flags = enter_critical_section(); /* Check the elapsed time. In periods of low activity, time slicing is * controlled by IDLE loop polling; in periods of higher activity, time @@ -148,7 +148,7 @@ enum pm_state_e pm_checkstate(void) (void)pm_update(accum); } - irqrestore(flags); + leave_critical_section(flags); /* Return the recommended state. Assuming that we are called from the * IDLE thread at the lowest priority level, any updates scheduled on the diff --git a/drivers/pwm.c b/drivers/pwm.c index 3903bdf4fa..b07e44ae2c 100644 --- a/drivers/pwm.c +++ b/drivers/pwm.c @@ -60,7 +60,7 @@ #include #include -#include +#include #ifdef CONFIG_PWM @@ -351,7 +351,7 @@ static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags) { /* Disable interrupts to avoid race conditions */ - flags = irqsave(); + flags = enter_critical_section(); /* Indicate that if will be waiting for the pulse count to complete. * Note that we will only wait if a non-zero pulse count is specified @@ -398,7 +398,7 @@ static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags) upper->waiting = false; } - irqrestore(flags); + leave_critical_section(flags); } return ret; diff --git a/drivers/sensors/zerocross.c b/drivers/sensors/zerocross.c index 22f2f499a9..980ffdd86c 100644 --- a/drivers/sensors/zerocross.c +++ b/drivers/sensors/zerocross.c @@ -60,7 +60,7 @@ #include #include -#include +#include #ifdef CONFIG_ZEROCROSS @@ -165,7 +165,7 @@ static void zerocross_enable(FAR struct zc_upperhalf_s *priv) * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Enable interrupts */ @@ -175,7 +175,7 @@ static void zerocross_enable(FAR struct zc_upperhalf_s *priv) lower->zc_enable(lower, (zc_interrupt_t)zerocross_interrupt, priv); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -193,7 +193,7 @@ static void zerocross_interrupt(FAR const struct zc_lowerhalf_s *lower, * interrupts must be disabled. */ - flags = irqsave(); + flags = enter_critical_section(); /* Update sample value */ @@ -215,7 +215,7 @@ static void zerocross_interrupt(FAR const struct zc_lowerhalf_s *lower, #endif } - irqrestore(flags); + leave_critical_section(flags); } /************************************************************************************ @@ -308,10 +308,10 @@ static int zc_close(FAR struct file *filep) * detection anyway. */ - flags = irqsave(); + flags = enter_critical_section(); closing = opriv->do_closing; opriv->do_closing = true; - irqrestore(flags); + leave_critical_section(flags); if (closing) { diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 32d2a073ad..5f84e23213 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -1,7 +1,7 @@ /************************************************************************************ * drivers/serial/serial.c * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -227,7 +227,7 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) * the following steps must be atomic. */ - flags = irqsave(); + flags = enter_critical_section(); #ifdef CONFIG_SERIAL_REMOVABLE /* Check if the removable device is no longer connected while we @@ -257,7 +257,7 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) uart_disabletxint(dev); } - irqrestore(flags); + leave_critical_section(flags); #ifdef CONFIG_SERIAL_REMOVABLE /* Check if the removable device was disconnected while we were @@ -366,9 +366,9 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, if (dev->isconsole) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); ret = uart_irqwrite(dev, buffer, buflen); - irqrestore(flags); + leave_critical_section(flags); return ret; } else @@ -712,7 +712,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen * that the following operations are atomic. */ - flags = irqsave(); + flags = enter_critical_section(); #ifdef CONFIG_SERIAL_DMA /* If RX buffer is empty move tail and head to zero position */ @@ -751,7 +751,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen ret = uart_takesem(&dev->recvsem, true); } - irqrestore(flags); + leave_critical_section(flags); /* Was a signal received while waiting for data to be * received? Was a removable device disconnected while @@ -799,7 +799,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen } #ifdef CONFIG_SERIAL_DMA - flags = irqsave(); + flags = enter_critical_section(); /* If RX buffer is empty move tail and head to zero position */ @@ -808,7 +808,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen rxbuf->head = rxbuf->tail = 0; } - irqrestore(flags); + leave_critical_section(flags); /* Notify DMA that there is free space in the RX buffer */ @@ -885,7 +885,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case FIONREAD: { int count; - irqstate_t state = irqsave(); + irqstate_t flags = enter_critical_section(); /* Determine the number of bytes available in the buffer */ @@ -898,7 +898,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) count = dev->recv.size - (dev->recv.tail - dev->recv.head); } - irqrestore(state); + leave_critical_section(flags); *(FAR int *)((uintptr_t)arg) = count; ret = 0; @@ -908,7 +908,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case FIONWRITE: { int count; - irqstate_t state = irqsave(); + irqstate_t flags = enter_critical_section(); /* Determine the number of bytes free in the buffer */ @@ -921,7 +921,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) count = dev->xmit.size - (dev->xmit.head - dev->xmit.tail) - 1; } - irqrestore(state); + leave_critical_section(flags); *(FAR int *)((uintptr_t)arg) = count; ret = 0; @@ -1182,14 +1182,14 @@ static int uart_close(FAR struct file *filep) /* Free the IRQ and disable the UART */ - flags = irqsave(); /* Disable interrupts */ + flags = enter_critical_section(); /* Disable interrupts */ uart_detach(dev); /* Detach interrupts */ if (!dev->isconsole) /* Check for the serial console UART */ { uart_shutdown(dev); /* Disable the UART */ } - irqrestore(flags); + leave_critical_section(flags); /* We need to re-initialize the semaphores if this is the last close * of the device, as the close might be caused by pthread_cancel() of @@ -1269,7 +1269,7 @@ static int uart_open(FAR struct file *filep) if (tmp == 1) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); /* If this is the console, then the UART has already been initialized. */ @@ -1280,7 +1280,7 @@ static int uart_open(FAR struct file *filep) ret = uart_setup(dev); if (ret < 0) { - irqrestore(flags); + leave_critical_section(flags); goto errout_with_sem; } } @@ -1295,7 +1295,7 @@ static int uart_open(FAR struct file *filep) if (ret < 0) { uart_shutdown(dev); - irqrestore(flags); + leave_critical_section(flags); goto errout_with_sem; } @@ -1306,7 +1306,7 @@ static int uart_open(FAR struct file *filep) dev->recv.head = 0; dev->recv.tail = 0; - /* Initialise termios state */ + /* Initialize termios state */ #ifdef CONFIG_SERIAL_TERMIOS dev->tc_iflag = 0; @@ -1331,7 +1331,7 @@ static int uart_open(FAR struct file *filep) /* Enable the RX interrupt */ uart_enablerxint(dev); - irqrestore(flags); + leave_critical_section(flags); } /* Save the new open count on success */ @@ -1454,7 +1454,7 @@ void uart_connected(FAR uart_dev_t *dev, bool connected) * function may be called from interrupt handling logic. */ - flags = irqsave(); + flags = enter_critical_section(); dev->disconnected = !connected; if (!connected) { @@ -1487,6 +1487,6 @@ void uart_connected(FAR uart_dev_t *dev, bool connected) uart_pollnotify(dev, (POLLERR | POLLHUP)); } - irqrestore(flags); + leave_critical_section(flags); } #endif diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index 7db5291701..6551a137e7 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -900,18 +900,18 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg) case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); u16550_enablebreaks(priv, true); - irqrestore(flags); + leave_critical_section(flags); } break; case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */ { irqstate_t flags; - flags = irqsave(); + flags = enter_critical_section(); u16550_enablebreaks(priv, false); - irqrestore(flags); + leave_critical_section(flags); } break; @@ -1010,7 +1010,7 @@ static void u16550_txint(struct uart_dev_s *dev, bool enable) FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; irqstate_t flags; - flags = irqsave(); + flags = enter_critical_section(); if (enable) { priv->ier |= UART_IER_ETBEI; @@ -1028,7 +1028,7 @@ static void u16550_txint(struct uart_dev_s *dev, bool enable) u16550_serialout(priv, UART_IER_OFFSET, priv->ier); } - irqrestore(flags); + leave_critical_section(flags); #endif } diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index b74c95f51c..ea8e035ce7 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -59,7 +59,7 @@ #include #include -#include +#include #ifdef CONFIG_RAMLOG @@ -182,7 +182,7 @@ static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, for (i = 0; i < CONFIG_RAMLOG_NPOLLWAITERS; i++) { - flags = irqsave(); + flags = enter_critical_section(); fds = priv->rl_fds[i]; if (fds) { @@ -192,7 +192,7 @@ static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, sem_post(fds->sem); } } - irqrestore(flags); + leave_critical_section(flags); } } #else @@ -210,7 +210,7 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch) /* Disable interrupts (in case we are NOT called from interrupt handler) */ - flags = irqsave(); + flags = enter_critical_section(); /* Calculate the write index AFTER the next byte is written */ @@ -226,7 +226,7 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch) { /* Yes... Return an indication that nothing was saved in the buffer. */ - irqrestore(flags); + leave_critical_section(flags); return -EBUSY; } @@ -234,7 +234,7 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch) priv->rl_buffer[priv->rl_head] = ch; priv->rl_head = nexthead; - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -494,7 +494,7 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size /* Are there threads waiting for read data? */ - flags = irqsave(); + flags = enter_critical_section(); #ifndef CONFIG_RAMLOG_NONBLOCKING for (i = 0; i < priv->rl_nwaiters; i++) { @@ -507,7 +507,7 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size /* Notify all poll/select waiters that they can write to the FIFO */ ramlog_pollnotify(priv, POLLIN); - irqrestore(flags); + leave_critical_section(flags); } #endif diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index c5f874ed7d..90eedc5f98 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/cdcacm.c * - * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -68,10 +69,6 @@ # include "composite.h" #endif -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -282,7 +279,7 @@ static uint16_t cdcacm_fillrequest(FAR struct cdcacm_dev_s *priv, uint8_t *reqbu /* Disable interrupts */ - flags = irqsave(); + flags = enter_critical_section(); /* Transfer bytes while we have bytes available and there is room in the request */ @@ -317,7 +314,7 @@ static uint16_t cdcacm_fillrequest(FAR struct cdcacm_dev_s *priv, uint8_t *reqbu uart_datasent(serdev); } - irqrestore(flags); + leave_critical_section(flags); return nbytes; } @@ -350,7 +347,7 @@ static int cdcacm_sndpacket(FAR struct cdcacm_dev_s *priv) } #endif - flags = irqsave(); + flags = enter_critical_section(); /* Use our IN endpoint for the transfer */ @@ -404,7 +401,7 @@ static int cdcacm_sndpacket(FAR struct cdcacm_dev_s *priv) } } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -834,7 +831,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep, /* Process the received data unless this is some unusual condition */ - flags = irqsave(); + flags = enter_critical_section(); switch (req->result) { case 0: /* Normal completion */ @@ -845,7 +842,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep, case -ESHUTDOWN: /* Disconnection */ usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSHUTDOWN), 0); priv->nrdq--; - irqrestore(flags); + leave_critical_section(flags); return; default: /* Some other error occurred */ @@ -862,7 +859,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep, usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-req->result); } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -898,10 +895,10 @@ static void cdcacm_wrcomplete(FAR struct usbdev_ep_s *ep, /* Return the write request to the free list */ - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; - irqrestore(flags); + leave_critical_section(flags); /* Send the next packet unless this was some unusual termination * condition @@ -1079,10 +1076,10 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->priv = reqcontainer; reqcontainer->req->callback = cdcacm_wrcomplete; - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; /* Count of write requests available */ - irqrestore(flags); + leave_critical_section(flags); } /* Report if we are selfpowered (unless we are part of a composite device) */ @@ -1208,7 +1205,7 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver, * of them) */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGASSERT(priv->nwrq == CONFIG_CDCACM_NWRREQS); while (!sq_empty(&priv->reqlist)) { @@ -1221,7 +1218,7 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver, } DEBUGASSERT(priv->nwrq == 0); - irqrestore(flags); + leave_critical_section(flags); /* Clear out all data in the circular buffer */ @@ -1648,7 +1645,7 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, * connection. */ - flags = irqsave(); + flags = enter_critical_section(); #ifdef CONFIG_SERIAL_REMOVABLE uart_connected(&priv->serdev, false); #endif @@ -1662,7 +1659,7 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, priv->serdev.xmit.head = 0; priv->serdev.xmit.tail = 0; priv->rxhead = 0; - irqrestore(flags); + leave_critical_section(flags); /* Perform the soft connect function so that we will we can be * re-enumerated (unless we are part of a composite device) @@ -1988,7 +1985,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case FIONREAD: { int count; - irqstate_t state = irqsave(); + irqstate_t flags = enter_critical_section(); /* Determine the number of bytes available in the buffer. */ @@ -2001,7 +1998,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) count = serdev->recv.size - (serdev->recv.tail - serdev->recv.head); } - irqrestore(state); + leave_critical_section(flags); *(int *)arg = count; ret = 0; @@ -2011,7 +2008,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case FIONWRITE: { int count; - irqstate_t state = irqsave(); + irqstate_t flags = enter_critical_section(); /* Determine the number of bytes free in the buffer. */ @@ -2024,7 +2021,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) count = serdev->xmit.size - (serdev->xmit.head - serdev->xmit.tail) - 1; } - irqrestore(state); + leave_critical_section(flags); *(int *)arg = count; ret = 0; @@ -2083,7 +2080,7 @@ static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable) * in the following. */ - flags = irqsave(); + flags = enter_critical_section(); if (enable) { /* RX "interrupts" are enabled. Is this a transition from disabled @@ -2132,7 +2129,7 @@ static void cdcuart_rxint(FAR struct uart_dev_s *dev, bool enable) priv->rxhead = serdev->recv.head; priv->rxenabled = false; } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index 1cc35aab89..b0f0c95c9c 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/composite.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -55,10 +56,6 @@ #ifdef CONFIG_USBDEV_COMPOSITE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -368,7 +365,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver, { /* Unbind the constituent class drivers */ - flags = irqsave(); + flags = enter_critical_section(); CLASS_UNBIND(priv->dev1, dev); CLASS_UNBIND(priv->dev2, dev); @@ -380,7 +377,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver, composite_freereq(dev->ep0, priv->ctrlreq); priv->ctrlreq = NULL; } - irqrestore(flags); + leave_critical_section(flags); } } @@ -665,11 +662,11 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver, * the disconnection. */ - flags = irqsave(); + flags = enter_critical_section(); priv->config = COMPOSITE_CONFIGIDNONE; CLASS_DISCONNECT(priv->dev1, dev); CLASS_DISCONNECT(priv->dev2, dev); - irqrestore(flags); + leave_critical_section(flags); /* Perform the soft connect function so that we will we can be * re-enumerated. @@ -716,10 +713,10 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver, /* Forward the suspend event to the constituent devices */ - flags = irqsave(); + flags = enter_critical_section(); CLASS_SUSPEND(priv->dev1, priv->usbdev); CLASS_SUSPEND(priv->dev2, priv->usbdev); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -758,10 +755,10 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver, /* Forward the resume event to the constituent devices */ - flags = irqsave(); + flags = enter_critical_section(); CLASS_RESUME(priv->dev1, priv->usbdev); CLASS_RESUME(priv->dev2, priv->usbdev); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index 8848905487..aa568d1385 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/pl2303.c * - * Copyright (C) 2008-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * This logic emulates the Prolific PL2303 serial/USB converter @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -537,7 +538,7 @@ static uint16_t usbclass_fillrequest(FAR struct pl2303_dev_s *priv, uint8_t *req /* Disable interrupts */ - flags = irqsave(); + flags = enter_critical_section(); /* Transfer bytes while we have bytes available and there is room in the request */ @@ -572,7 +573,7 @@ static uint16_t usbclass_fillrequest(FAR struct pl2303_dev_s *priv, uint8_t *req uart_datasent(serdev); } - irqrestore(flags); + leave_critical_section(flags); return nbytes; } @@ -605,7 +606,7 @@ static int usbclass_sndpacket(FAR struct pl2303_dev_s *priv) } #endif - flags = irqsave(); + flags = enter_critical_section(); /* Use our IN endpoint for the transfer */ @@ -659,7 +660,7 @@ static int usbclass_sndpacket(FAR struct pl2303_dev_s *priv) } } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -1216,7 +1217,7 @@ static void usbclass_rdcomplete(FAR struct usbdev_ep_s *ep, /* Process the received data unless this is some unusual condition */ - flags = irqsave(); + flags = enter_critical_section(); switch (req->result) { case 0: /* Normal completion */ @@ -1227,7 +1228,7 @@ static void usbclass_rdcomplete(FAR struct usbdev_ep_s *ep, case -ESHUTDOWN: /* Disconnection */ usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSHUTDOWN), 0); priv->nrdq--; - irqrestore(flags); + leave_critical_section(flags); return; default: /* Some other error occurred */ @@ -1243,7 +1244,7 @@ static void usbclass_rdcomplete(FAR struct usbdev_ep_s *ep, { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-req->result); } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -1279,10 +1280,10 @@ static void usbclass_wrcomplete(FAR struct usbdev_ep_s *ep, /* Return the write request to the free list */ - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; - irqrestore(flags); + leave_critical_section(flags); /* Send the next packet unless this was some unusual termination * condition @@ -1448,10 +1449,10 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->priv = reqcontainer; reqcontainer->req->callback = usbclass_wrcomplete; - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist); priv->nwrq++; /* Count of write requests available */ - irqrestore(flags); + leave_critical_section(flags); } /* Report if we are selfpowered */ @@ -1573,7 +1574,7 @@ static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver, * of them */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGASSERT(priv->nwrq == CONFIG_PL2303_NWRREQS); while (!sq_empty(&priv->reqlist)) { @@ -1585,7 +1586,7 @@ static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver, } } DEBUGASSERT(priv->nwrq == 0); - irqrestore(flags); + leave_critical_section(flags); } /* Clear out all data in the circular buffer */ @@ -1900,7 +1901,7 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, * connection. */ - flags = irqsave(); + flags = enter_critical_section(); #ifdef CONFIG_SERIAL_REMOVABLE uart_connected(&priv->serdev, false); #endif @@ -1914,7 +1915,7 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, priv->serdev.xmit.head = 0; priv->serdev.xmit.tail = 0; priv->rxhead = 0; - irqrestore(flags); + leave_critical_section(flags); /* Perform the soft connect function so that we will we can be * re-enumerated. @@ -2136,7 +2137,7 @@ static void usbser_rxint(FAR struct uart_dev_s *dev, bool enable) * in the following. */ - flags = irqsave(); + flags = enter_critical_section(); if (enable) { /* RX "interrupts" are enabled. Is this a transition from disabled @@ -2185,7 +2186,7 @@ static void usbser_rxint(FAR struct uart_dev_s *dev, bool enable) priv->rxhead = serdev->recv.head; priv->rxenabled = false; } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/usbdev/usbdev_trace.c b/drivers/usbdev/usbdev_trace.c index b7f00e93fb..be19863b1b 100644 --- a/drivers/usbdev/usbdev_trace.c +++ b/drivers/usbdev/usbdev_trace.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #undef usbtrace @@ -140,10 +140,10 @@ usbtrace_idset_t usbtrace_enable(usbtrace_idset_t idset) /* The following read and write must be atomic */ - flags = irqsave(); + flags = enter_critical_section(); ret = g_maskedidset; g_maskedidset = idset; - irqrestore(flags); + leave_critical_section(flags); return ret; } #endif /* CONFIG_USBDEV_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */ @@ -166,7 +166,7 @@ void usbtrace(uint16_t event, uint16_t value) /* Check if tracing is enabled for this ID */ - flags = irqsave(); + flags = enter_critical_section(); if ((g_maskedidset & TRACE_ID2BIT(event)) != 0) { #ifdef CONFIG_USBDEV_TRACE @@ -196,7 +196,7 @@ void usbtrace(uint16_t event, uint16_t value) #endif } - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_USBDEV_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */ diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 9e502e4e10..9e646c9509 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/usbmsc.c * - * Copyright (C) 2008-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Mass storage class device. Bulk-only with SCSI subclass. @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -360,9 +361,9 @@ static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->priv = reqcontainer; reqcontainer->req->callback = usbmsc_wrcomplete; - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); } /* Report if we are selfpowered (unless we are part of a composite device) */ @@ -477,7 +478,7 @@ static void usbmsc_unbind(FAR struct usbdevclass_driver_s *driver, * of them */ - flags = irqsave(); + flags = enter_critical_section(); while (!sq_empty(&priv->wrreqlist)) { reqcontainer = (struct usbmsc_req_s *)sq_remfirst(&priv->wrreqlist); @@ -495,7 +496,7 @@ static void usbmsc_unbind(FAR struct usbdevclass_driver_s *driver, priv->epbulkin = NULL; } - irqrestore(flags); + leave_critical_section(flags); } } @@ -868,14 +869,14 @@ static void usbmsc_disconnect(FAR struct usbdevclass_driver_s *driver, /* Reset the configuration */ - flags = irqsave(); + flags = enter_critical_section(); usbmsc_resetconfig(priv); /* Signal the worker thread */ priv->theventset |= USBMSC_EVENT_DISCONNECT; usbmsc_scsi_signal(priv); - irqrestore(flags); + leave_critical_section(flags); /* Perform the soft connect function so that we will we can be * re-enumerated (unless we are part of a composite device) @@ -1088,9 +1089,9 @@ void usbmsc_wrcomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) /* Return the write request to the free list */ - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)privreq, &priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); /* Process the received data unless this is some unusual condition */ @@ -1157,9 +1158,9 @@ void usbmsc_rdcomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) /* Add the filled read request from the rdreqlist */ - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)privreq, &priv->rdreqlist); - irqrestore(flags); + leave_critical_section(flags); /* Signal the worker thread that there is received data to be processed */ @@ -1681,10 +1682,10 @@ int usbmsc_exportluns(FAR void *handle) /* Signal to start the thread */ uvdbg("Signalling for the SCSI worker thread\n"); - flags = irqsave(); + flags = enter_critical_section(); priv->theventset |= USBMSC_EVENT_READY; usbmsc_scsi_signal(priv); - irqrestore(flags); + leave_critical_section(flags); errout_with_lock: usbmsc_scsi_unlock(priv); @@ -1792,10 +1793,10 @@ void usbmsc_uninitialize(FAR void *handle) { /* Yes.. Ask the thread to stop */ - flags = irqsave(); + flags = enter_critical_section(); priv->theventset |= USBMSC_EVENT_TERMINATEREQUEST; usbmsc_scsi_signal(priv); - irqrestore(flags); + leave_critical_section(flags); } usbmsc_scsi_unlock(priv); diff --git a/drivers/usbdev/usbmsc_scsi.c b/drivers/usbdev/usbmsc_scsi.c index 75e958cebe..a8b0f4004f 100644 --- a/drivers/usbdev/usbmsc_scsi.c +++ b/drivers/usbdev/usbmsc_scsi.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/usbmsc_scsi.c * - * Copyright (C) 2008-2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2010, 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Mass storage class device. Bulk-only with SCSI subclass. @@ -67,6 +67,7 @@ #include #include +#include #include #include #include @@ -379,7 +380,7 @@ static void usbmsc_scsi_wait(FAR struct usbmsc_dev_s *priv) * enabled while we wait for the event. */ - flags = irqsave(); + flags = enter_critical_section(); priv->thwaiting = true; /* Relinquish our lock on the SCSI state data */ @@ -399,7 +400,7 @@ static void usbmsc_scsi_wait(FAR struct usbmsc_dev_s *priv) /* Re-acquire our lock on the SCSI state data */ usbmsc_scsi_lock(priv); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -1631,9 +1632,9 @@ static int usbmsc_idlestate(FAR struct usbmsc_dev_s *priv) /* Take a request from the rdreqlist */ - flags = irqsave(); + flags = enter_critical_section(); privreq = (FAR struct usbmsc_req_s *)sq_remfirst(&priv->rdreqlist); - irqrestore(flags); + leave_critical_section(flags); /* Has anything been received? If not, just return an error. * This will cause us to remain in the IDLE state. When a USB request is @@ -2178,9 +2179,9 @@ static int usbmsc_cmdreadstate(FAR struct usbmsc_dev_s *priv) * that is it not NULL */ - flags = irqsave(); + flags = enter_critical_section(); privreq = (FAR struct usbmsc_req_s *)sq_remfirst(&priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); /* And submit the request to the bulk IN endpoint */ @@ -2413,9 +2414,9 @@ static int usbmsc_cmdfinishstate(FAR struct usbmsc_dev_s *priv) * that is it not NULL) */ - flags = irqsave(); + flags = enter_critical_section(); privreq = (FAR struct usbmsc_req_s *)sq_remfirst(&priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); /* Send the write request */ @@ -2463,7 +2464,7 @@ static int usbmsc_cmdfinishstate(FAR struct usbmsc_dev_s *priv) { /* Did the host stop sending unexpectedly early? */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->shortpacket) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHSHORTPKT), (uint16_t)priv->residue); @@ -2478,7 +2479,7 @@ static int usbmsc_cmdfinishstate(FAR struct usbmsc_dev_s *priv) } priv->theventset |= USBMSC_EVENT_ABORTBULKOUT; - irqrestore(flags); + leave_critical_section(flags); } break; @@ -2524,9 +2525,9 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv) /* Take a request from the wrreqlist */ - flags = irqsave(); + flags = enter_critical_section(); privreq = (FAR struct usbmsc_req_s *)sq_remfirst(&priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); /* If there no request structures available, then just return an error. * This will cause us to remain in the CMDSTATUS status. When a request is @@ -2589,9 +2590,9 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv) if (ret < 0) { usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_SNDSTATUSSUBMIT), (uint16_t)-ret); - flags = irqsave(); + flags = enter_critical_section(); (void)sq_addlast((FAR sq_entry_t *)privreq, &priv->wrreqlist); - irqrestore(flags); + leave_critical_section(flags); } /* Return to the IDLE state */ @@ -2663,7 +2664,7 @@ int usbmsc_scsi_main(int argc, char *argv[]) */ usbmsc_scsi_lock(priv); - flags = irqsave(); + flags = enter_critical_section(); if (priv->theventset == USBMSC_EVENT_NOEVENTS) { usbmsc_scsi_wait(priv); @@ -2730,7 +2731,7 @@ int usbmsc_scsi_main(int argc, char *argv[]) priv->thstate = USBMSC_STATE_IDLE; } - irqrestore(flags); + leave_critical_section(flags); /* Loop processing each SCSI command state. Each state handling * function will do the following: @@ -2810,14 +2811,14 @@ void usbmsc_scsi_signal(FAR struct usbmsc_dev_s *priv) * of the semaphore count are atomic. */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->thwaiting) { priv->thwaiting = false; sem_post(&priv->thwaitsem); } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/usbhost/usbhost_cdcacm.c b/drivers/usbhost/usbhost_cdcacm.c index 54b1c58042..ef00675627 100644 --- a/drivers/usbhost/usbhost_cdcacm.c +++ b/drivers/usbhost/usbhost_cdcacm.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_cdcacm.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -503,14 +504,14 @@ static FAR struct usbhost_cdcacm_s *usbhost_allocclass(void) * our pre-allocated class instances from the free list. */ - flags = irqsave(); + flags = enter_critical_section(); entry = g_freelist; if (entry) { g_freelist = entry->flink; } - irqrestore(flags); + leave_critical_section(flags); uvdbg("Allocated: %p\n", entry); return (FAR struct usbhost_cdcacm_s *)entry; } @@ -555,10 +556,10 @@ static void usbhost_freeclass(FAR struct usbhost_cdcacm_s *usbclass) /* Just put the pre-allocated class structure back on the freelist */ - flags = irqsave(); + flags = enter_critical_section(); entry->flink = g_freelist; g_freelist = entry; - irqrestore(flags); + leave_critical_section(flags); } #else static void usbhost_freeclass(FAR struct usbhost_cdcacm_s *usbclass) @@ -587,7 +588,7 @@ static int usbhost_devno_alloc(FAR struct usbhost_cdcacm_s *priv) irqstate_t flags; int devno; - flags = irqsave(); + flags = enter_critical_section(); for (devno = 0; devno < 32; devno++) { uint32_t bitno = 1 << devno; @@ -595,12 +596,12 @@ static int usbhost_devno_alloc(FAR struct usbhost_cdcacm_s *priv) { g_devinuse |= bitno; priv->minor = devno; - irqrestore(flags); + leave_critical_section(flags); return OK; } } - irqrestore(flags); + leave_critical_section(flags); return -EMFILE; } @@ -618,9 +619,9 @@ static void usbhost_devno_free(FAR struct usbhost_cdcacm_s *priv) if (devno >= 0 && devno < 32) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); g_devinuse &= ~(1 << devno); - irqrestore(flags); + leave_critical_section(flags); } } @@ -2113,7 +2114,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * is no longer available. */ - flags = irqsave(); + flags = enter_critical_section(); priv->disconnected = true; /* Let the upper half driver know that serial device is no longer @@ -2181,7 +2182,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) } } - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -2217,7 +2218,7 @@ static int usbhost_setup(FAR struct uart_dev_s *uartdev) * isconnect events. */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->disconnected) { /* No... the block driver is no longer bound to the class. That means that @@ -2235,7 +2236,7 @@ static int usbhost_setup(FAR struct uart_dev_s *uartdev) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); usbhost_givesem(&priv->exclsem); return ret; } @@ -2275,7 +2276,7 @@ static void usbhost_shutdown(FAR struct uart_dev_s *uartdev) * no asynchronous disconnect events. */ - flags = irqsave(); + flags = enter_critical_section(); /* Check if the USB CDC/ACM device is still connected. If the * CDC/ACM device is not connected and the reference count just @@ -2291,7 +2292,7 @@ static void usbhost_shutdown(FAR struct uart_dev_s *uartdev) usbhost_destroy(priv); } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** diff --git a/drivers/usbhost/usbhost_findclass.c b/drivers/usbhost/usbhost_findclass.c index d65b49c502..b544b60f48 100644 --- a/drivers/usbhost/usbhost_findclass.c +++ b/drivers/usbhost/usbhost_findclass.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_findclass.c * - * Copyright (C) 2010, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,28 +44,12 @@ #include #include +#include #include #include -#include #include "usbhost_registry.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -167,7 +151,7 @@ const struct usbhost_registry_s *usbhost_findclass(const struct usbhost_id_s *id * protected by disabling interrupts. */ - flags = irqsave(); + flags = enter_critical_section(); /* Examine each register class in the linked list */ @@ -186,7 +170,7 @@ const struct usbhost_registry_s *usbhost_findclass(const struct usbhost_id_s *id { /* Yes.. restore interrupts and return the class info */ - irqrestore(flags); + leave_critical_section(flags); return usbclass; } } @@ -194,7 +178,7 @@ const struct usbhost_registry_s *usbhost_findclass(const struct usbhost_id_s *id /* Not found... restore interrupts and return NULL */ - irqrestore(flags); + leave_critical_section(flags); return NULL; } diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index 5e820acb66..b36434dd31 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_hidkbd.c * - * Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,7 @@ #include #include +#include #include #include #include @@ -704,7 +705,7 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) irqstate_t flags; int devno; - flags = irqsave(); + flags = enter_critical_section(); for (devno = 0; devno < 26; devno++) { uint32_t bitno = 1 << devno; @@ -712,12 +713,12 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) { g_devinuse |= bitno; priv->devchar = 'a' + devno; - irqrestore(flags); + leave_critical_section(flags); return OK; } } - irqrestore(flags); + leave_critical_section(flags); return -EMFILE; } @@ -727,9 +728,9 @@ static void usbhost_freedevno(FAR struct usbhost_state_s *priv) if (devno >= 0 && devno < 26) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); g_devinuse &= ~(1 << devno); - irqrestore(flags); + leave_critical_section(flags); } } @@ -1268,7 +1269,7 @@ static int usbhost_kbdpoll(int argc, char *argv[]) udbg("Keyboard removed, polling halted\n"); - flags = irqsave(); + flags = enter_critical_section(); priv->polling = false; /* Decrement the reference count held by this thread. */ @@ -1303,7 +1304,7 @@ static int usbhost_kbdpoll(int argc, char *argv[]) usbhost_givesem(&priv->exclsem); } - irqrestore(flags); + leave_critical_section(flags); return 0; } @@ -2068,7 +2069,7 @@ static int usbhost_open(FAR struct file *filep) * events. */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->disconnected) { /* No... the driver is no longer bound to the class. That means that @@ -2086,7 +2087,7 @@ static int usbhost_open(FAR struct file *filep) priv->open = true; ret = OK; } - irqrestore(flags); + leave_critical_section(flags); usbhost_givesem(&priv->exclsem); return ret; @@ -2120,7 +2121,7 @@ static int usbhost_close(FAR struct file *filep) * asynchronous poll or disconnect events. */ - flags = irqsave(); + flags = enter_critical_section(); priv->crefs--; /* Check if the USB mouse device is still connected. If the device is @@ -2164,7 +2165,7 @@ static int usbhost_close(FAR struct file *filep) /* Skip giving the semaphore... it is no longer valid */ - irqrestore(flags); + leave_critical_section(flags); return OK; } else /* if (priv->crefs == 1) */ @@ -2180,7 +2181,7 @@ static int usbhost_close(FAR struct file *filep) } usbhost_givesem(&priv->exclsem); - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index 86a7bda2de..c61541d9c2 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_hidmouse.c * - * Copyright (C) 2014, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,7 @@ #include #include +#include #include #include #include @@ -564,7 +565,7 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) irqstate_t flags; int devno; - flags = irqsave(); + flags = enter_critical_section(); for (devno = 0; devno < 26; devno++) { uint32_t bitno = 1 << devno; @@ -572,12 +573,12 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) { g_devinuse |= bitno; priv->devno = devno; - irqrestore(flags); + leave_critical_section(flags); return OK; } } - irqrestore(flags); + leave_critical_section(flags); return -EMFILE; } @@ -587,9 +588,9 @@ static void usbhost_freedevno(FAR struct usbhost_state_s *priv) if (devno >= 0 && devno < 26) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); g_devinuse &= ~(1 << devno); - irqrestore(flags); + leave_critical_section(flags); } } @@ -1234,7 +1235,7 @@ static int usbhost_mouse_poll(int argc, char *argv[]) udbg("Mouse removed, polling halted\n"); - flags = irqsave(); + flags = enter_critical_section(); priv->polling = false; /* Decrement the reference count held by this thread. */ @@ -1269,7 +1270,7 @@ static int usbhost_mouse_poll(int argc, char *argv[]) usbhost_givesem(&priv->exclsem); } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -1292,7 +1293,7 @@ static int usbhost_sample(FAR struct usbhost_state_s *priv, * from changing until it has been reported. */ - flags = irqsave(); + flags = enter_critical_section(); /* Is there new mouse data available? */ @@ -1329,7 +1330,7 @@ static int usbhost_sample(FAR struct usbhost_state_s *priv, ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } @@ -1360,7 +1361,7 @@ static int usbhost_waitsample(FAR struct usbhost_state_s *priv, */ sched_lock(); - flags = irqsave(); + flags = enter_critical_section(); /* Now release the semaphore that manages mutually exclusive access to * the device structure. This may cause other tasks to become ready to @@ -1418,7 +1419,7 @@ errout: * have pre-emption disabled. */ - irqrestore(flags); + leave_critical_section(flags); /* Restore pre-emption. We might get suspended here but that is okay * because we already have our sample. Note: this means that if there @@ -2138,7 +2139,7 @@ static int usbhost_open(FAR struct file *filep) * events. */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->disconnected) { /* No... the driver is no longer bound to the class. That means that @@ -2178,7 +2179,7 @@ static int usbhost_open(FAR struct file *filep) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); usbhost_givesem(&priv->exclsem); return ret; @@ -2212,7 +2213,7 @@ static int usbhost_close(FAR struct file *filep) * asynchronous poll or disconnect events. */ - flags = irqsave(); + flags = enter_critical_section(); priv->crefs--; /* Check if the USB mouse device is still connected. If the device is @@ -2254,7 +2255,7 @@ static int usbhost_close(FAR struct file *filep) /* Skip giving the semaphore... it is no longer valid */ - irqrestore(flags); + leave_critical_section(flags); return OK; } else /* if (priv->crefs == 1) */ @@ -2270,7 +2271,7 @@ static int usbhost_close(FAR struct file *filep) } usbhost_givesem(&priv->exclsem); - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/usbhost/usbhost_hub.c b/drivers/usbhost/usbhost_hub.c index 170629987b..34b37f9b29 100644 --- a/drivers/usbhost/usbhost_hub.c +++ b/drivers/usbhost/usbhost_hub.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_hub.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Kaushal Parikh * Gregory Nutt * @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -980,7 +981,7 @@ static void usbhost_hub_event(FAR void *arg) * removed. */ - flags = irqsave(); + flags = enter_critical_section(); if (!priv->disconnected) { /* Wait for the next hub event */ @@ -993,7 +994,7 @@ static void usbhost_hub_event(FAR void *arg) } } - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -1038,7 +1039,7 @@ static void usbhost_disconnect_event(FAR void *arg) * longer available. */ - flags = irqsave(); + flags = enter_critical_section(); /* Cancel any pending transfers on the interrupt IN pipe */ @@ -1098,7 +1099,7 @@ static void usbhost_disconnect_event(FAR void *arg) kmm_free(hubclass); hport->devclass = NULL; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -1463,7 +1464,7 @@ static int usbhost_disconnected(struct usbhost_class_s *hubclass) * any subsequent completions of asynchronous transfers. */ - flags = irqsave(); + flags = enter_critical_section(); priv->disconnected = true; /* Cancel any pending work. There may be pending HUB work associated with @@ -1476,7 +1477,7 @@ static int usbhost_disconnected(struct usbhost_class_s *hubclass) ret = work_queue(LPWORK, &priv->work, (worker_t)usbhost_disconnect_event, hubclass, 0); - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/drivers/usbhost/usbhost_registerclass.c b/drivers/usbhost/usbhost_registerclass.c index 09d7c7c10d..aaf61d0428 100644 --- a/drivers/usbhost/usbhost_registerclass.c +++ b/drivers/usbhost/usbhost_registerclass.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include "usbhost_registry.h" @@ -104,14 +104,14 @@ int usbhost_registerclass(struct usbhost_registry_s *usbclass) * protected by disabling interrupts. */ - flags = irqsave(); + flags = enter_critical_section(); /* Add the new class ID info to the head of the list */ usbclass->flink = g_classregistry; g_classregistry = usbclass; - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/usbhost/usbhost_skeleton.c b/drivers/usbhost/usbhost_skeleton.c index 7b39360458..9a7ed87de3 100644 --- a/drivers/usbhost/usbhost_skeleton.c +++ b/drivers/usbhost/usbhost_skeleton.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_skeleton.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -293,7 +294,7 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) irqstate_t flags; int devno; - flags = irqsave(); + flags = enter_critical_section(); for (devno = 0; devno < 26; devno++) { uint32_t bitno = 1 << devno; @@ -301,12 +302,12 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) { g_devinuse |= bitno; priv->devchar = 'a' + devno; - irqrestore(flags); + leave_critical_section(flags); return OK; } } - irqrestore(flags); + leave_critical_section(flags); return -EMFILE; } @@ -316,9 +317,9 @@ static void usbhost_freedevno(FAR struct usbhost_state_s *priv) if (devno >= 0 && devno < 26) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); g_devinuse &= ~(1 << devno); - irqrestore(flags); + leave_critical_section(flags); } } @@ -1003,7 +1004,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * longer available. */ - flags = irqsave(); + flags = enter_critical_section(); priv->disconnected = true; /* Now check the number of references on the class instance. If it is one, @@ -1036,7 +1037,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) } } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/usbhost/usbhost_storage.c b/drivers/usbhost/usbhost_storage.c index b314bd7294..5d01a22b06 100644 --- a/drivers/usbhost/usbhost_storage.c +++ b/drivers/usbhost/usbhost_storage.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbhost/usbhost_storage.c * - * Copyright (C) 2010-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -368,14 +369,14 @@ static inline FAR struct usbhost_state_s *usbhost_allocclass(void) * our pre-allocated class instances from the free list. */ - flags = irqsave(); + flags = enter_critical_section(); entry = g_freelist; if (entry) { g_freelist = entry->flink; } - irqrestore(flags); + leave_critical_section(flags); ullvdbg("Allocated: %p\n", entry); return (FAR struct usbhost_state_s *)entry; } @@ -420,10 +421,10 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) /* Just put the pre-allocated class structure back on the freelist */ - flags = irqsave(); + flags = enter_critical_section(); entry->flink = g_freelist; g_freelist = entry; - irqrestore(flags); + leave_critical_section(flags); } #else static inline void usbhost_freeclass(FAR struct usbhost_state_s *usbclass) @@ -452,7 +453,7 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) irqstate_t flags; int devno; - flags = irqsave(); + flags = enter_critical_section(); for (devno = 0; devno < 26; devno++) { uint32_t bitno = 1 << devno; @@ -460,12 +461,12 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) { g_devinuse |= bitno; priv->sdchar = 'a' + devno; - irqrestore(flags); + leave_critical_section(flags); return OK; } } - irqrestore(flags); + leave_critical_section(flags); return -EMFILE; } @@ -475,9 +476,9 @@ static void usbhost_freedevno(FAR struct usbhost_state_s *priv) if (devno >= 0 && devno < 26) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); g_devinuse &= ~(1 << devno); - irqrestore(flags); + leave_critical_section(flags); } } @@ -1820,7 +1821,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * is no longer available. */ - flags = irqsave(); + flags = enter_critical_section(); priv->disconnected = true; /* Now check the number of references on the class instance. If it is one, @@ -1853,7 +1854,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) } } - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -1887,7 +1888,7 @@ static int usbhost_open(FAR struct inode *inode) * events. */ - flags = irqsave(); + flags = enter_critical_section(); if (priv->disconnected) { /* No... the block driver is no longer bound to the class. That means that @@ -1904,7 +1905,7 @@ static int usbhost_open(FAR struct inode *inode) priv->crefs++; ret = OK; } - irqrestore(flags); + leave_critical_section(flags); usbhost_givesem(&priv->exclsem); return ret; @@ -1943,7 +1944,7 @@ static int usbhost_close(FAR struct inode *inode) * no asynchronous disconnect events. */ - flags = irqsave(); + flags = enter_critical_section(); /* Check if the USB mass storage device is still connected. If the * storage device is not connected and the reference count just @@ -1959,7 +1960,7 @@ static int usbhost_close(FAR struct inode *inode) usbhost_destroy(priv); } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/drivers/usbhost/usbhost_trace.c b/drivers/usbhost/usbhost_trace.c index 20a30a0c34..cd1ef92c4f 100644 --- a/drivers/usbhost/usbhost_trace.c +++ b/drivers/usbhost/usbhost_trace.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #undef usbtrace @@ -148,7 +148,7 @@ void usbhost_trace_common(uint32_t event) /* Check if tracing is enabled for this ID */ - flags = irqsave(); + flags = enter_critical_section(); if (!g_disabled) { /* Yes... save the new trace data at the head */ @@ -170,7 +170,7 @@ void usbhost_trace_common(uint32_t event) } } } - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_USBHOST_TRACE */ diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index 68924193f2..f309e968fb 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/wireless/cc3000.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David_s5 * @@ -63,6 +63,7 @@ #include #include +#include #include #include #include @@ -1377,10 +1378,10 @@ static int cc3000_ioctl(FAR struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(psize != NULL); rv = priv->rx_buffer_max_len; - flags = irqsave(); + flags = enter_critical_section(); priv->rx_buffer_max_len = *psize; priv->rx_buffer.pbuffer = kmm_realloc(priv->rx_buffer.pbuffer, *psize); - irqrestore(flags); + leave_critical_section(flags); DEBUGASSERT(priv->rx_buffer.pbuffer); *psize = rv; break; @@ -1588,7 +1589,7 @@ int cc3000_register(FAR struct spi_dev_s *spi, #ifdef CONFIG_CC3000_MULTIPLE priv->flink = g_cc3000list; g_cc3000list = priv; - irqrestore(flags); + leave_critical_section(flags); #endif /* And return success (?) */ @@ -1726,7 +1727,7 @@ static int cc3000_add_socket(FAR struct cc3000_dev_s *priv, int sd) return sd; } - flags = irqsave(); + flags = enter_critical_section(); for (s = 0; s < CONFIG_WL_MAX_SOCKETS; s++) { if (priv->sockets[s].sd == FREE_SLOT) @@ -1738,7 +1739,7 @@ static int cc3000_add_socket(FAR struct cc3000_dev_s *priv, int sd) } } - irqrestore(flags); + leave_critical_section(flags); return s >= CONFIG_WL_MAX_SOCKETS ? -1 : OK; } @@ -1769,7 +1770,7 @@ static int cc3000_remove_socket(FAR struct cc3000_dev_s *priv, int sd) return sd; } - flags = irqsave(); + flags = enter_critical_section(); if (priv->accepting_socket.acc.sd == sd) { priv->accepting_socket.acc.sd = CLOSE_SLOT; @@ -1788,7 +1789,7 @@ static int cc3000_remove_socket(FAR struct cc3000_dev_s *priv, int sd) } } - irqrestore(flags); + leave_critical_section(flags); if (ps) { sched_lock(); @@ -1828,7 +1829,7 @@ static int cc3000_remote_closed_socket(FAR struct cc3000_dev_s *priv, int sd) return sd; } - flags = irqsave(); + flags = enter_critical_section(); for (s = 0; s < CONFIG_WL_MAX_SOCKETS; s++) { if (priv->sockets[s].sd == sd) @@ -1837,7 +1838,7 @@ static int cc3000_remote_closed_socket(FAR struct cc3000_dev_s *priv, int sd) } } - irqrestore(flags); + leave_critical_section(flags); return s >= CONFIG_WL_MAX_SOCKETS ? -1 : OK; } -- GitLab From 6e3107650d131499c0b09ea23e267416f21437d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:17:46 -0600 Subject: [PATCH 726/858] nuttx/sched: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- sched/clock/clock_initialize.c | 6 +-- sched/clock/clock_settime.c | 6 +-- sched/clock/clock_systimer.c | 9 ++-- sched/group/group_addrenv.c | 11 ++--- sched/group/group_create.c | 17 +++---- sched/group/group_find.c | 35 +++---------- sched/group/group_join.c | 15 ++---- sched/group/group_leave.c | 11 +++-- sched/irq/irq_attach.c | 6 +-- sched/mqueue/mq_msgfree.c | 33 +++---------- sched/mqueue/mq_rcvinternal.c | 29 ++--------- sched/mqueue/mq_receive.c | 30 +++-------- sched/mqueue/mq_send.c | 31 +++--------- sched/mqueue/mq_sndinternal.c | 39 ++++----------- sched/mqueue/mq_timedreceive.c | 33 ++++--------- sched/mqueue/mq_timedsend.c | 39 +++++---------- sched/mqueue/mq_waitirq.c | 29 ++--------- sched/pthread/pthread_condtimedwait.c | 31 +++--------- sched/sched/sched_addprioritized.c | 2 +- sched/sched/sched_addreadytorun.c | 4 +- sched/sched/sched_cpuload.c | 6 +-- sched/sched/sched_foreach.c | 9 ++-- sched/sched/sched_free.c | 39 +++------------ sched/sched/sched_garbage.c | 27 +++------- sched/sched/sched_mergepending.c | 4 +- sched/sched/sched_removereadytorun.c | 3 +- sched/sched/sched_setparam.c | 7 +-- sched/sched/sched_setpriority.c | 8 +-- sched/sched/sched_setscheduler.c | 11 +++-- sched/sched/sched_unlock.c | 5 +- sched/semaphore/sem_post.c | 30 +++-------- sched/semaphore/sem_recover.c | 31 ++---------- sched/semaphore/sem_tickwait.c | 5 +- sched/semaphore/sem_timedwait.c | 9 ++-- sched/semaphore/sem_timeout.c | 6 +-- sched/semaphore/sem_trywait.c | 10 ++-- sched/semaphore/sem_wait.c | 10 ++-- sched/semaphore/sem_waitirq.c | 10 ++-- sched/semaphore/spinlock.c | 1 + sched/signal/sig_action.c | 8 +-- sched/signal/sig_allocatependingsigaction.c | 30 +++-------- sched/signal/sig_deliver.c | 34 +++---------- sched/signal/sig_dispatch.c | 55 ++++++++------------- sched/signal/sig_nanosleep.c | 8 +-- sched/signal/sig_pending.c | 10 ++-- sched/signal/sig_procmask.c | 9 ++-- sched/signal/sig_releasependingsigaction.c | 34 +++---------- sched/signal/sig_releasependingsignal.c | 33 +++---------- sched/signal/sig_removependingsignal.c | 29 ++--------- sched/signal/sig_suspend.c | 11 +++-- sched/signal/sig_timedwait.c | 11 +++-- sched/task/task_activate.c | 31 ++---------- sched/task/task_reparent.c | 16 +++--- sched/task/task_restart.c | 7 +-- sched/task/task_terminate.c | 8 +-- sched/timer/timer_create.c | 9 ++-- sched/timer/timer_initialize.c | 6 +-- sched/timer/timer_release.c | 9 ++-- sched/timer/timer_settime.c | 21 ++------ sched/wdog/wd_cancel.c | 9 ++-- sched/wdog/wd_create.c | 13 ++--- sched/wdog/wd_delete.c | 31 +++--------- sched/wdog/wd_gettime.c | 30 ++--------- sched/wdog/wd_recover.c | 31 ++---------- sched/wdog/wd_start.c | 9 ++-- sched/wqueue/kwork_cancel.c | 7 +-- sched/wqueue/kwork_inherit.c | 15 +++--- sched/wqueue/kwork_process.c | 11 ++--- sched/wqueue/kwork_queue.c | 5 +- 69 files changed, 368 insertions(+), 819 deletions(-) diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index e9923db1f1..cccd175932 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -46,7 +46,7 @@ #include #ifdef CONFIG_RTC -# include +# include #endif #include @@ -256,9 +256,9 @@ void clock_synchronize(void) /* Re-initialize the time value to match the RTC */ - flags = irqsave(); + flags = enter_critical_section(); clock_inittime(); - irqrestore(flags); + leave_critical_section(flags); } #endif diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index 3749fa43df..e1516082a8 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include "clock/clock.h" @@ -109,7 +109,7 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp) * possible. */ - flags = irqsave(); + flags = enter_critical_section(); /* Get the elapsed time since power up (in milliseconds). This is a * bias value that we need to use to correct the base time. @@ -146,7 +146,7 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp) up_rtc_settime(tp); } #endif - irqrestore(flags); + leave_critical_section(flags); sdbg("basetime=(%ld,%lu) bias=(%ld,%lu)\n", (long)g_basetime.tv_sec, (unsigned long)g_basetime.tv_nsec, diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index 2710385a54..3e8e978ce9 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -41,6 +41,7 @@ #include +#include #include #include @@ -53,10 +54,6 @@ #undef clock_systimer -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -115,9 +112,9 @@ systime_t clock_systimer(void) /* 64-bit accesses are not atomic on most architectures. */ - flags = irqsave(); + flags = enter_critical_section(); sample = g_system_timer; - irqrestore(flags); + leave_critical_section(flags); return sample; # else /* CONFIG_SYSTEM_TIME64 */ diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index fcdd1a3e0c..b4525af8d2 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_addrenv.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include +#include #include #include "sched/sched.h" @@ -48,10 +49,6 @@ #ifdef CONFIG_ARCH_ADDRENV -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -138,7 +135,7 @@ int group_addrenv(FAR struct tcb_s *tcb) /* Are we going to change address environments? */ - flags = irqsave(); + flags = enter_critical_section(); if (gid != g_gid_current) { /* Yes.. Is there a current address environment in place? */ @@ -178,7 +175,7 @@ int group_addrenv(FAR struct tcb_s *tcb) g_gid_current = gid; } - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 683b234400..3b3cb6be08 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_create.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "environ/environ.h" @@ -58,10 +59,6 @@ #define GROUP_INITIAL_MEMBERS 4 -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -119,7 +116,7 @@ static void group_assigngid(FAR struct task_group_s *group) { /* Increment the ID counter. This is global data so be extra paranoid. */ - flags = irqsave(); + flags = enter_critical_section(); gid = ++g_gidcounter; /* Check for overflow */ @@ -127,13 +124,13 @@ static void group_assigngid(FAR struct task_group_s *group) if (gid <= 0) { g_gidcounter = 1; - irqrestore(flags); + leave_critical_section(flags); } else { /* Does a task group with this ID already exist? */ - irqrestore(flags); + leave_critical_section(flags); if (group_findbygid(gid) == NULL) { /* Now assign this ID to the group and return */ @@ -309,10 +306,10 @@ int group_initialize(FAR struct task_tcb_s *tcb) #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) /* Add the initialized entry to the list of groups */ - flags = irqsave(); + flags = enter_critical_section(); group->flink = g_grouphead; g_grouphead = group; - irqrestore(flags); + leave_critical_section(flags); #endif diff --git a/sched/group/group_find.c b/sched/group/group_find.c index ab88163cac..3db582fa25 100644 --- a/sched/group/group_find.c +++ b/sched/group/group_find.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_find.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "group/group.h" @@ -51,26 +52,6 @@ #ifdef HAVE_TASK_GROUP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -107,17 +88,17 @@ FAR struct task_group_s *group_findbygid(gid_t gid) /* Find the status structure with the matching GID */ - flags = irqsave(); + flags = enter_critical_section(); for (group = g_grouphead; group; group = group->flink) { if (group->tg_gid == gid) { - irqrestore(flags); + leave_critical_section(flags); return group; } } - irqrestore(flags); + leave_critical_section(flags); return NULL; } #endif @@ -153,17 +134,17 @@ FAR struct task_group_s *group_findbypid(pid_t pid) /* Find the status structure with the matching PID */ - flags = irqsave(); + flags = enter_critical_section(); for (group = g_grouphead; group; group = group->flink) { if (group->tg_task == pid) { - irqrestore(flags); + leave_critical_section(flags); return group; } } - irqrestore(flags); + leave_critical_section(flags); return NULL; } #endif diff --git a/sched/group/group_join.c b/sched/group/group_join.c index eab5bdbcc7..bdf2fc546d 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_join.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -59,14 +60,6 @@ #define GROUP_REALLOC_MEMBERS 4 -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -126,10 +119,10 @@ static inline int group_addmember(FAR struct task_group_s *group, pid_t pid) * may be traversed from an interrupt handler (read-only). */ - flags = irqsave(); + flags = enter_critical_section(); group->tg_members = newmembers; group->tg_mxmembers = newmax; - irqrestore(flags); + leave_critical_section(flags); } /* Assign this new pid to the group; group->tg_nmembers will be incremented diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index c22c0aee48..9c5cf0f50b 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_leave.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -89,7 +90,7 @@ static void group_remove(FAR struct task_group_s *group) * This is probably un-necessary. */ - flags = irqsave(); + flags = enter_critical_section(); /* Find the task group structure */ @@ -115,7 +116,7 @@ static void group_remove(FAR struct task_group_s *group) curr->flink = NULL; } - irqrestore(flags); + leave_critical_section(flags); } #endif @@ -320,10 +321,10 @@ static inline void group_removemember(FAR struct task_group_s *group, pid_t pid) * interrupt handlers (read-only). */ - flags = irqsave(); + flags = enter_critical_section(); group->tg_members[i] = group->tg_members[group->tg_nmembers - 1]; group->tg_nmembers--; - irqrestore(flags); + leave_critical_section(flags); } } } diff --git a/sched/irq/irq_attach.c b/sched/irq/irq_attach.c index e218a7015c..6402ca3157 100644 --- a/sched/irq/irq_attach.c +++ b/sched/irq/irq_attach.c @@ -83,14 +83,14 @@ int irq_attach(int irq, xcpt_t isr) if ((unsigned)irq < NR_IRQS) { - irqstate_t state; + irqstate_t flags; /* If the new ISR is NULL, then the ISR is being detached. * In this case, disable the ISR and direct any interrupts * to the unexpected interrupt handler. */ - state = irqsave(); + flags = enter_critical_section(); if (isr == NULL) { /* Disable the interrupt if we can before detaching it. We might @@ -116,7 +116,7 @@ int irq_attach(int irq, xcpt_t isr) /* Save the new ISR in the table. */ g_irqvector[irq] = isr; - irqrestore(state); + leave_critical_section(flags); ret = OK; } diff --git a/sched/mqueue/mq_msgfree.c b/sched/mqueue/mq_msgfree.c index 9d83f7be28..3aefca36d4 100644 --- a/sched/mqueue/mq_msgfree.c +++ b/sched/mqueue/mq_msgfree.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_msgfree.c * - * Copyright (C) 2007, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,31 +41,12 @@ #include +#include #include #include #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -88,7 +69,7 @@ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) { - irqstate_t saved_state; + irqstate_t flags; /* If this is a generally available pre-allocated message, * then just put it back in the free list. @@ -100,9 +81,9 @@ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)mqmsg, &g_msgfree); - irqrestore(saved_state); + leave_critical_section(flags); } /* If this is a message pre-allocated for interrupts, @@ -115,9 +96,9 @@ void mq_msgfree(FAR struct mqueue_msg_s *mqmsg) * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)mqmsg, &g_msgfreeirq); - irqrestore(saved_state); + leave_critical_section(flags); } /* Otherwise, deallocate it. Note: interrupt handlers diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index 7c019e7d38..c260c1183d 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_rcvinternal.c * - * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2012-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,31 +48,12 @@ #include #include +#include #include #include "sched/sched.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -249,7 +230,7 @@ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR char *ubuffer, int *prio) { FAR struct tcb_s *btcb; - irqstate_t saved_state; + irqstate_t flags; FAR struct mqueue_inode_s *msgq; ssize_t rcvmsglen; @@ -283,7 +264,7 @@ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, * messages can be sent from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head; btcb && btcb->msgwaitq != msgq; btcb = btcb->flink); @@ -299,7 +280,7 @@ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, msgq->nwaitnotfull--; up_unblock_task(btcb); - irqrestore(saved_state); + leave_critical_section(flags); } /* Return the length of the message transferred to the user buffer */ diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c index 173c147a5a..4fed3b5afd 100644 --- a/sched/mqueue/mq_receive.c +++ b/sched/mqueue/mq_receive.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_receive.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,30 +44,12 @@ #include #include #include + +#include #include #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -116,7 +98,7 @@ ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio) { FAR struct mqueue_msg_s *mqmsg; - irqstate_t saved_state; + irqstate_t flags; ssize_t ret = ERROR; DEBUGASSERT(up_interrupt_context() == false); @@ -143,12 +125,12 @@ ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen, * because messages can be sent from interrupt level. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Get the message from the message queue */ mqmsg = mq_waitreceive(mqdes); - irqrestore(saved_state); + leave_critical_section(flags); /* Check if we got a message from the message queue. We might * not have a message if: diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index 7ba1d1ca9c..84c22b5d76 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_send.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,30 +44,11 @@ #include #include +#include #include #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -119,7 +100,7 @@ int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) { FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *mqmsg = NULL; - irqstate_t saved_state; + irqstate_t flags; int ret = ERROR; /* Verify the input parameters -- setting errno appropriately @@ -143,14 +124,14 @@ int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) * non-FULL. This would fail with EAGAIN, EINTR, or ETIMEOUT. */ - saved_state = irqsave(); + flags = enter_critical_section(); if (up_interrupt_context() || /* In an interrupt handler */ msgq->nmsgs < msgq->maxmsgs || /* OR Message queue not full */ mq_waitsend(mqdes) == OK) /* OR Successfully waited for mq not full */ { /* Allocate the message */ - irqrestore(saved_state); + leave_critical_section(flags); mqmsg = mq_msgalloc(); } else @@ -162,7 +143,7 @@ int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) * - When we tried waiting, the wait was unsuccessful. */ - irqrestore(saved_state); + leave_critical_section(flags); } /* Check if we were able to get a message structure -- this can fail diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index 0aaa61dad5..782eb84e33 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_send.c * - * Copyright (C) 2007, 2009, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -59,26 +60,6 @@ #endif #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -165,7 +146,7 @@ int mq_verifysend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) FAR struct mqueue_msg_s *mq_msgalloc(void) { FAR struct mqueue_msg_s *mqmsg; - irqstate_t saved_state; + irqstate_t flags; /* If we were called from an interrupt handler, then try to get the message * from generally available list of messages. If this fails, then try the @@ -193,9 +174,9 @@ FAR struct mqueue_msg_s *mq_msgalloc(void) * Disable interrupts -- we might be called from an interrupt handler. */ - saved_state = irqsave(); + flags = enter_critical_section(); mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); - irqrestore(saved_state); + leave_critical_section(flags); /* If we cannot a message from the free list, then we will have to allocate one. */ @@ -334,7 +315,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *next; FAR struct mqueue_msg_s *prev; - irqstate_t saved_state; + irqstate_t flags; /* Get a pointer to the message queue */ @@ -352,7 +333,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, /* Insert the new message in the message queue */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Search the message list to find the location to insert the new * message. Each is list is maintained in ascending priority order. @@ -377,7 +358,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, /* Increment the count of messages in the queue */ msgq->nmsgs++; - irqrestore(saved_state); + leave_critical_section(flags); /* Check if we need to notify any tasks that are attached to the * message queue @@ -429,7 +410,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, /* Check if any tasks are waiting for the MQ not empty event. */ - saved_state = irqsave(); + flags = enter_critical_section(); if (msgq->nwaitnotempty > 0) { /* Find the highest priority task that is waiting for @@ -451,7 +432,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, up_unblock_task(btcb); } - irqrestore(saved_state); + leave_critical_section(flags); sched_unlock(); return OK; } diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index 1e3d50d163..b5bb100b89 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_timedreceive.c * - * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -54,22 +55,6 @@ #include "clock/clock.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -95,13 +80,13 @@ static void mq_rcvtimeout(int argc, wdparm_t pid) { FAR struct tcb_s *wtcb; - irqstate_t saved_state; + irqstate_t flags; /* Disable interrupts. This is necessary because an interrupt handler may * attempt to send a message while we are doing this. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Get the TCB associated with this pid. It is possible that task may no * longer be active when this watchdog goes off. @@ -122,7 +107,7 @@ static void mq_rcvtimeout(int argc, wdparm_t pid) /* Interrupts may now be re-enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } /**************************************************************************** @@ -184,7 +169,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, { FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_msg_s *mqmsg; - irqstate_t saved_state; + irqstate_t flags; int ret = ERROR; DEBUGASSERT(up_interrupt_context() == false && rtcb->waitdog == NULL); @@ -229,7 +214,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, * because messages can be sent from interrupt level. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Check if the message queue is empty. If it is NOT empty, then we * will not need to start timer. @@ -258,7 +243,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, if (result != OK) { - irqrestore(saved_state); + leave_critical_section(flags); sched_unlock(); wd_delete(rtcb->waitdog); @@ -285,7 +270,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, /* We can now restore interrupts */ - irqrestore(saved_state); + leave_critical_section(flags); /* Check if we got a message from the message queue. We might * not have a message if: diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 90045436eb..860e6223db 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_timedsend.c * - * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -54,22 +55,6 @@ #include "sched/sched.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -95,13 +80,13 @@ static void mq_sndtimeout(int argc, wdparm_t pid) { FAR struct tcb_s *wtcb; - irqstate_t saved_state; + irqstate_t flags; /* Disable interrupts. This is necessary because an interrupt handler may * attempt to send a message while we are doing this. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Get the TCB associated with this pid. It is possible that task may no * longer be active when this watchdog goes off. @@ -122,7 +107,7 @@ static void mq_sndtimeout(int argc, wdparm_t pid) /* Interrupts may now be re-enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } /**************************************************************************** @@ -186,7 +171,7 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, FAR struct tcb_s *rtcb = this_task(); FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *mqmsg = NULL; - irqstate_t saved_state; + irqstate_t flags; int ticks; int result; int ret = ERROR; @@ -274,7 +259,7 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, * disabled here so that this time stays valid until the wait begins. */ - saved_state = irqsave(); + flags = enter_critical_section(); result = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); /* If the time has already expired and the message queue is empty, @@ -290,7 +275,7 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, if (result != OK) { - goto errout_with_irqsave; + goto errout_in_critical_section; } /* Start the watchdog and begin the wait for MQ not full */ @@ -314,12 +299,12 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, /* mq_waitsend() will set the errno, but the error exit will reset it */ result = get_errno(); - goto errout_with_irqsave; + goto errout_in_critical_section; } /* That is the end of the atomic operations */ - irqrestore(saved_state); + leave_critical_section(flags); /* If any of the above failed, set the errno. Otherwise, there should * be space for another message in the message queue. NOW we can allocate @@ -340,8 +325,8 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, * 'result' */ -errout_with_irqsave: - irqrestore(saved_state); +errout_in_critical_section: + leave_critical_section(flags); wd_delete(rtcb->waitdog); rtcb->waitdog = NULL; diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c index 092319f8e4..10dada1af4 100644 --- a/sched/mqueue/mq_waitirq.c +++ b/sched/mqueue/mq_waitirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_waitirq.c * - * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,31 +42,12 @@ #include #include +#include #include #include #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,13 +74,13 @@ void mq_waitirq(FAR struct tcb_s *wtcb, int errcode) { FAR struct mqueue_inode_s *msgq; - irqstate_t saved_state; + irqstate_t flags; /* Disable interrupts. This is necessary because an interrupt handler may * attempt to send a message while we are doing this. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* It is possible that an interrupt/context switch beat us to the punch and * already changed the task's state. NOTE: The operations within the if @@ -141,5 +122,5 @@ void mq_waitirq(FAR struct tcb_s *wtcb, int errcode) /* Interrupts may now be enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 9fb2673a5b..0e8443b2fb 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_condtimedwait.c * - * Copyright (C) 2007-2009, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -56,22 +57,6 @@ #include "clock/clock.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -185,7 +170,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, FAR struct tcb_s *rtcb = this_task(); int ticks; int mypid = (int)getpid(); - irqstate_t int_state; + irqstate_t flags; int ret = OK; int status; @@ -236,7 +221,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, */ sched_lock(); - int_state = irqsave(); + flags = enter_critical_section(); /* Convert the timespec to clock ticks. We must disable pre-emption * here so that this time stays valid until the wait begins. @@ -249,7 +234,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * we fall through the if/then/else */ - irqrestore(int_state); + leave_critical_section(flags); } else { @@ -264,7 +249,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * if/then/else */ - irqrestore(int_state); + leave_critical_section(flags); ret = ETIMEDOUT; } else @@ -279,7 +264,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * we fall through the if/then/else) */ - irqrestore(int_state); + leave_critical_section(flags); } else { @@ -322,7 +307,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * handling! (bad) */ - irqrestore(int_state); + leave_critical_section(flags); } /* Reacquire the mutex (retaining the ret). */ diff --git a/sched/sched/sched_addprioritized.c b/sched/sched/sched_addprioritized.c index 199ea5bc66..22907574ea 100644 --- a/sched/sched/sched_addprioritized.c +++ b/sched/sched/sched_addprioritized.c @@ -66,7 +66,7 @@ * Assumptions: * - The caller has established a critical section before * calling this function (calling sched_lock() first is NOT - * a good idea -- use irqsave()). + * a good idea -- use enter_critical_section()). * - The caller has already removed the input tcb from * whatever list it was in. * - The caller handles the condition that occurs if the diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 9e851757c4..08eb3a018c 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -69,7 +69,7 @@ * Assumptions: * - The caller has established a critical section before calling this * function (calling sched_lock() first is NOT a good idea -- use - * irqsave()). + * enter_critical_section()). * - The caller has already removed the input rtcb from whatever list it * was in. * - The caller handles the condition that occurs if the head of the @@ -156,7 +156,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * Assumptions: * - The caller has established a critical section before calling this * function (calling sched_lock() first is NOT a good idea -- use - * irqsave()). + * enter_critical_section()). * - The caller has already removed the input rtcb from whatever list it * was in. * - The caller handles the condition that occurs if the head of the diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index 2c3d629c19..f7158b74c2 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include "sched/sched.h" @@ -183,7 +183,7 @@ int clock_cpuload(int pid, FAR struct cpuload_s *cpuload) * synchronized when read. */ - flags = irqsave(); + flags = enter_critical_section(); /* Make sure that the entry is valid (TCB field is not NULL) and matches * the requested PID. The first check is needed if the thread has exited. @@ -205,7 +205,7 @@ int clock_cpuload(int pid, FAR struct cpuload_s *cpuload) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/sched/sched/sched_foreach.c b/sched/sched/sched_foreach.c index ecd7437d13..1ee962d772 100644 --- a/sched/sched/sched_foreach.c +++ b/sched/sched/sched_foreach.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_foreach.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,9 @@ ****************************************************************************/ #include + +#include + #include "sched/sched.h" /**************************************************************************** @@ -65,7 +68,7 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); int ndx; /* Vist each active task */ @@ -78,7 +81,7 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) } } - irqrestore(flags); + leave_critical_section(flags); } diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index e642a57921..cd1c5f3743 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_free.c * - * Copyright (C) 2007, 2009, 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -33,53 +33,26 @@ * ****************************************************************************/ - /**************************************************************************** * Included Files ****************************************************************************/ - #include #include #include +#include #include #include #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - - -/**************************************************************************** - * Public Data - ****************************************************************************/ - - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - - /**************************************************************************** * Public Functions ****************************************************************************/ - /**************************************************************************** * Name: sched_ufree and sched_kfree * @@ -119,7 +92,7 @@ void sched_ufree(FAR void *address) * using the user deallocator. */ - flags = irqsave(); + flags = enter_critical_section(); #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) DEBUGASSERT(!kmm_heapmember(address)); @@ -135,7 +108,7 @@ void sched_ufree(FAR void *address) #ifdef CONFIG_SCHED_WORKQUEUE work_signal(LPWORK); #endif - irqrestore(flags); + leave_critical_section(flags); } else { @@ -163,7 +136,7 @@ void sched_kfree(FAR void *address) * using the kernel deallocator. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGASSERT(kmm_heapmember(address)); /* Delay the deallocation until a more appropriate time. */ @@ -176,7 +149,7 @@ void sched_kfree(FAR void *address) #ifdef CONFIG_SCHED_WORKQUEUE work_signal(LPWORK); #endif - irqrestore(flags); + leave_critical_section(flags); } else { diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index f51a442caf..878522f80b 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_garbage.c * - * Copyright (C) 2009, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -38,26 +38,11 @@ ****************************************************************************/ #include +#include #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -101,9 +86,9 @@ static inline void sched_kucleanup(void) * we must disable interrupts around the queue operation. */ - flags = irqsave(); + flags = enter_critical_section(); address = (FAR void *)sq_remfirst((FAR sq_queue_t *)&g_delayed_kufree); - irqrestore(flags); + leave_critical_section(flags); /* The address should always be non-NULL since that was checked in the * 'while' condition above. @@ -150,9 +135,9 @@ static inline void sched_kcleanup(void) * we must disable interrupts around the queue operation. */ - flags = irqsave(); + flags = enter_critical_section(); address = (FAR void *)sq_remfirst((FAR sq_queue_t *)&g_delayed_kfree); - irqrestore(flags); + leave_critical_section(flags); /* The address should always be non-NULL since that was checked in the * 'while' condition above. diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 81c2c934e0..48f6d58310 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -67,7 +67,7 @@ * Assumptions: * - The caller has established a critical section before * calling this function (calling sched_lock() first is NOT - * a good idea -- use irqsave()). + * a good idea -- use enter_critical_section()). * - The caller handles the condition that occurs if the * the head of the sched_mergTSTATE_TASK_PENDINGs is changed. * @@ -177,7 +177,7 @@ bool sched_mergepending(void) * Assumptions: * - The caller has established a critical section before * calling this function (calling sched_lock() first is NOT - * a good idea -- use irqsave()). + * a good idea -- use enter_critical_section()). * - The caller handles the condition that occurs if the * the head of the sched_mergTSTATE_TASK_PENDINGs is changed. * diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 1a175c7a0a..62a709ce0d 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -64,7 +64,8 @@ * * Assumptions: * - The caller has established a critical section before calling this - * function (calling sched_lock() first is NOT a good idea -- use irqsave()). + * function (calling sched_lock() first is NOT a good idea -- use + * enter_critical_section()). * - The caller handles the condition that occurs if the head of the * ready-to-run list is changed. * diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index 2af8d82405..824d51b53b 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_setparam.c * - * Copyright (C) 2007, 2009, 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "clock/clock.h" @@ -179,7 +180,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param) /* Stop/reset current sporadic scheduling */ - flags = irqsave(); + flags = enter_critical_section(); ret = sched_sporadic_reset(tcb); if (ret >= 0) { @@ -205,7 +206,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param) /* Restore interrupts and handler errors */ - irqrestore(flags); + leave_critical_section(flags); if (ret < 0) { errcode = -ret; diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 5af005e2b7..275de2426e 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -42,6 +42,8 @@ #include #include #include + +#include #include #include "sched/sched.h" @@ -82,7 +84,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) FAR struct tcb_s *rtcb = this_task(); FAR dq_queue_t *tasklist; tstate_t task_state; - irqstate_t saved_state; + irqstate_t flags; /* Verify that the requested priority is in the valid range */ @@ -97,7 +99,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) * performing the following. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* There are four cases that must be considered: */ @@ -209,6 +211,6 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) break; } - irqrestore(saved_state); + leave_critical_section(flags); return OK; } diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index 89fa9095aa..20026e7ec9 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_setscheduler.c * - * Copyright (C) 2007, 2009, 2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -86,7 +87,7 @@ int sched_setscheduler(pid_t pid, int policy, FAR const struct sched_param *param) { FAR struct tcb_s *tcb; - irqstate_t saved_state; + irqstate_t flags; #ifdef CONFIG_SCHED_SPORADIC int errcode; #endif @@ -131,7 +132,7 @@ int sched_setscheduler(pid_t pid, int policy, /* Further, disable timer interrupts while we set up scheduling policy. */ - saved_state = irqsave(); + flags = enter_critical_section(); tcb->flags &= ~TCB_FLAG_POLICY_MASK; switch (policy) { @@ -273,7 +274,7 @@ int sched_setscheduler(pid_t pid, int policy, #endif } - irqrestore(saved_state); + leave_critical_section(flags); /* Set the new priority */ @@ -284,7 +285,7 @@ int sched_setscheduler(pid_t pid, int policy, #ifdef CONFIG_SCHED_SPORADIC errout_with_irq: set_errno(errcode); - irqrestore(saved_state); + leave_critical_section(flags); sched_unlock(); return ERROR; #endif diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 4d206c4f48..81179ff6da 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -74,7 +75,7 @@ int sched_unlock(void) { /* Prevent context switches throughout the following */ - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); /* Decrement the preemption lock counter */ @@ -183,7 +184,7 @@ int sched_unlock(void) #endif } - irqrestore(flags); + leave_critical_section(flags); } return OK; diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 43e78bf154..97235de428 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_post.c * - * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,31 +42,13 @@ #include #include #include + +#include #include #include "sched/sched.h" #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -101,7 +83,7 @@ int sem_post(FAR sem_t *sem) { FAR struct tcb_s *stcb = NULL; - irqstate_t saved_state; + irqstate_t flags; int ret = ERROR; /* Make sure we were supplied with a valid semaphore. */ @@ -113,7 +95,7 @@ int sem_post(FAR sem_t *sem) * handler. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Perform the semaphore unlock operation. */ @@ -173,7 +155,7 @@ int sem_post(FAR sem_t *sem) /* Interrupts may now be enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } return ret; diff --git a/sched/semaphore/sem_recover.c b/sched/semaphore/sem_recover.c index f34662b81d..8b2d105b39 100644 --- a/sched/semaphore/sem_recover.c +++ b/sched/semaphore/sem_recover.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_recover.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,35 +39,12 @@ #include +#include #include #include #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -115,7 +92,7 @@ void sem_recover(FAR struct tcb_s *tcb) * enforce that here). */ - flags = irqsave(); + flags = enter_critical_section(); if (tcb->task_state == TSTATE_WAIT_SEM) { sem_t *sem = tcb->waitsem; @@ -144,5 +121,5 @@ void sem_recover(FAR struct tcb_s *tcb) tcb->waitsem = NULL; } - irqrestore(flags); + leave_critical_section(flags); } diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 66d4f446d7..a76308154a 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -109,7 +110,7 @@ int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay) * enabled while we are blocked waiting for the semaphore. */ - flags = irqsave(); + flags = enter_critical_section(); /* Try to take the semaphore without waiting. */ @@ -172,7 +173,7 @@ success_with_irqdisabled: /* Error exits */ errout_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); wd_delete(rtcb->waitdog); rtcb->waitdog = NULL; return ret; diff --git a/sched/semaphore/sem_timedwait.c b/sched/semaphore/sem_timedwait.c index e5722d401b..f006268c5c 100644 --- a/sched/semaphore/sem_timedwait.c +++ b/sched/semaphore/sem_timedwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_timedwait.c * - * Copyright (C) 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -134,7 +135,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) * enabled while we are blocked waiting for the semaphore. */ - flags = irqsave(); + flags = enter_critical_section(); /* Try to take the semaphore without waiting. */ @@ -205,7 +206,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime) /* Success exits */ success_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); wd_delete(rtcb->waitdog); rtcb->waitdog = NULL; return OK; @@ -213,7 +214,7 @@ success_with_irqdisabled: /* Error exits */ errout_with_irqdisabled: - irqrestore(flags); + leave_critical_section(flags); wd_delete(rtcb->waitdog); rtcb->waitdog = NULL; diff --git a/sched/semaphore/sem_timeout.c b/sched/semaphore/sem_timeout.c index 0bacd41237..542724a94c 100644 --- a/sched/semaphore/sem_timeout.c +++ b/sched/semaphore/sem_timeout.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include "semaphore/semaphore.h" @@ -78,7 +78,7 @@ void sem_timeout(int argc, wdparm_t pid) /* Disable interrupts to avoid race conditions */ - flags = irqsave(); + flags = enter_critical_section(); /* Get the TCB associated with this PID. It is possible that * task may no longer be active when this watchdog goes off. @@ -99,5 +99,5 @@ void sem_timeout(int argc, wdparm_t pid) /* Interrupts may now be enabled. */ - irqrestore(flags); + leave_critical_section(flags); } diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index e6d8830519..37ba0d66e2 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_trywait.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ #include #include #include + +#include #include #include "sched/sched.h" @@ -77,7 +79,7 @@ int sem_trywait(FAR sem_t *sem) { FAR struct tcb_s *rtcb = this_task(); - irqstate_t saved_state; + irqstate_t flags; int ret = ERROR; /* This API should not be called from interrupt handlers */ @@ -94,7 +96,7 @@ int sem_trywait(FAR sem_t *sem) * because sem_post() may be called from an interrupt handler. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Any further errors could only occurr because the semaphore is not * available. @@ -115,7 +117,7 @@ int sem_trywait(FAR sem_t *sem) /* Interrupts may now be enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } return ret; diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index 7e88140b72..86fb013696 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_wait.c * - * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ #include #include #include + +#include #include #include "sched/sched.h" @@ -77,7 +79,7 @@ int sem_wait(FAR sem_t *sem) { FAR struct tcb_s *rtcb = this_task(); - irqstate_t saved_state; + irqstate_t flags; int ret = ERROR; /* This API should not be called from interrupt handlers */ @@ -95,7 +97,7 @@ int sem_wait(FAR sem_t *sem) * handler. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Check if the lock is available */ @@ -186,7 +188,7 @@ int sem_wait(FAR sem_t *sem) /* Interrupts may now be enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } return ret; diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c index e80ef66cd7..5ddafa62e0 100644 --- a/sched/semaphore/sem_waitirq.c +++ b/sched/semaphore/sem_waitirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_waitirq.c * - * Copyright (C) 2007-2010, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ #include #include + +#include #include #include "semaphore/semaphore.h" @@ -77,14 +79,14 @@ void sem_waitirq(FAR struct tcb_s *wtcb, int errcode) { - irqstate_t saved_state; + irqstate_t flags; /* Disable interrupts. This is necessary (unfortunately) because an * interrupt handler may attempt to post the semaphore while we are * doing this. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* It is possible that an interrupt/context switch beat us to the punch * and already changed the task's state. @@ -124,5 +126,5 @@ void sem_waitirq(FAR struct tcb_s *wtcb, int errcode) /* Interrupts may now be enabled. */ - irqrestore(saved_state); + leave_critical_section(flags); } diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index 7b12ffaf18..a5919305f4 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -43,6 +43,7 @@ #include #include +#include #include "sched/sched.h" diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 8c88f55e12..c0f7dcc743 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_action.c * - * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,8 @@ #include #include +#include + #include "sched/sched.h" #include "group/group.h" #include "signal/signal.h" @@ -219,7 +221,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * * can be modified by the child thread. */ - flags = irqsave(); + flags = enter_critical_section(); /* Mark that status should be not be retained */ @@ -228,7 +230,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * /* Free all pending exit status */ group_removechildren(rtcb->group); - irqrestore(flags); + leave_critical_section(flags); } #endif diff --git a/sched/signal/sig_allocatependingsigaction.c b/sched/signal/sig_allocatependingsigaction.c index 7b40802130..361b9460a3 100644 --- a/sched/signal/sig_allocatependingsigaction.c +++ b/sched/signal/sig_allocatependingsigaction.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_allocatependingsigaction.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,30 +41,12 @@ #include #include + +#include #include #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,7 +62,7 @@ FAR sigq_t *sig_allocatependingsigaction(void) { FAR sigq_t *sigq; - irqstate_t saved_state; + irqstate_t flags; /* Check if we were called from an interrupt handler. */ @@ -107,9 +89,9 @@ FAR sigq_t *sig_allocatependingsigaction(void) { /* Try to get the pending signal action structure from the free list */ - saved_state = irqsave(); + flags = enter_critical_section(); sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingaction); - irqrestore(saved_state); + leave_critical_section(flags); /* Check if we got one. */ diff --git a/sched/signal/sig_deliver.c b/sched/signal/sig_deliver.c index 212b49151b..1f9c378b8a 100644 --- a/sched/signal/sig_deliver.c +++ b/sched/signal/sig_deliver.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_deliver.c * - * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2012-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,31 +45,13 @@ #include #include #include + +#include #include #include "semaphore/semaphore.h" #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -88,7 +70,7 @@ void sig_deliver(FAR struct tcb_s *stcb) FAR sigq_t *sigq; FAR sigq_t *next; sigset_t savesigprocmask; - irqstate_t saved_state; + irqstate_t flags; int saved_errno; sched_lock(); @@ -111,10 +93,10 @@ void sig_deliver(FAR struct tcb_s *stcb) * time, there should never be more than one signal in the sigpostedq */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_rem((FAR sq_entry_t *)sigq, &(stcb->sigpendactionq)); sq_addlast((FAR sq_entry_t *)sigq, &(stcb->sigpostedq)); - irqrestore(saved_state); + leave_critical_section(flags); /* Call the signal handler (unless the signal was cancelled) * @@ -172,9 +154,9 @@ void sig_deliver(FAR struct tcb_s *stcb) /* Remove the signal from the sigpostedq */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_rem((FAR sq_entry_t *)sigq, &(stcb->sigpostedq)); - irqrestore(saved_state); + leave_critical_section(flags); /* Then deallocate it */ diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index b6027c9b7e..b52b89290f 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_dispatch.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -54,22 +55,6 @@ #include "signal/signal.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -89,7 +74,7 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) { FAR sigactq_t *sigact; FAR sigq_t *sigq; - irqstate_t saved_state; + irqstate_t flags; int ret = OK; sched_lock(); @@ -123,9 +108,9 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) /* Put it at the end of the pending signals list */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigq, &(stcb->sigpendactionq)); - irqrestore(saved_state); + leave_critical_section(flags); } } @@ -144,7 +129,7 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) static FAR sigpendq_t *sig_allocatependingsignal(void) { FAR sigpendq_t *sigpend; - irqstate_t saved_state; + irqstate_t flags; /* Check if we were called from an interrupt handler. */ @@ -172,9 +157,9 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) { /* Try to get the pending signal structure from the free list */ - saved_state = irqsave(); + flags = enter_critical_section(); sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal); - irqrestore(saved_state); + leave_critical_section(flags); /* Check if we got one. */ @@ -211,13 +196,13 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, int signo) { FAR sigpendq_t *sigpend = NULL; - irqstate_t saved_state; + irqstate_t flags; DEBUGASSERT(group); /* Pending sigals can be added from interrupt level. */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Seach the list for a sigpendion on this signal */ @@ -225,7 +210,7 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, (sigpend && sigpend->info.si_signo != signo); sigpend = sigpend->flink); - irqrestore(saved_state); + leave_critical_section(flags); return sigpend; } @@ -245,7 +230,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, { FAR struct task_group_s *group = stcb->group; FAR sigpendq_t *sigpend; - irqstate_t saved_state; + irqstate_t flags; DEBUGASSERT(group); @@ -274,9 +259,9 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, /* Add the structure to the pending signal list */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigpend, &group->sigpendingq); - irqrestore(saved_state); + leave_critical_section(flags); } } @@ -311,7 +296,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) { - irqstate_t saved_state; + irqstate_t flags; int ret = OK; sdbg("TCB=0x%08x signo=%d code=%d value=%d mask=%08x\n", @@ -333,14 +318,14 @@ int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) * from the interrupt level. */ - saved_state = irqsave(); + flags = enter_critical_section(); if (stcb->task_state == TSTATE_WAIT_SIG && sigismember(&stcb->sigwaitmask, info->si_signo)) { memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t)); stcb->sigwaitmask = NULL_SIGNAL_SET; up_unblock_task(stcb); - irqrestore(saved_state); + leave_critical_section(flags); } /* Its not one we are waiting for... Add it to the list of pending @@ -349,7 +334,7 @@ int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) else { - irqrestore(saved_state); + leave_critical_section(flags); ASSERT(sig_addpendingsignal(stcb, info)); } } @@ -373,7 +358,7 @@ int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) * signals can be queued from the interrupt level. */ - saved_state = irqsave(); + flags = enter_critical_section(); if (stcb->task_state == TSTATE_WAIT_SIG) { memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t)); @@ -381,7 +366,7 @@ int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) up_unblock_task(stcb); } - irqrestore(saved_state); + leave_critical_section(flags); /* If the task neither was waiting for the signal nor had a signal * handler attached to the signal, then the default action is diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index da87609ea3..ccd8e30769 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include "clock/clock.h" @@ -143,7 +143,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) * after the wait. */ - flags = irqsave(); + flags = enter_critical_section(); starttick = clock_systimer(); /* Set up for the sleep. Using the empty set means that we are not @@ -173,7 +173,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) { /* The timeout "error" is the normal, successful result */ - irqrestore(flags); + leave_critical_section(flags); return OK; } @@ -214,7 +214,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) (void)clock_ticks2time((int)remaining, rmtp); } - irqrestore(flags); + leave_critical_section(flags); errout: set_errno(errval); diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index fe0e537d1e..91a272c547 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_pending.c * - * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,8 @@ #include #include +#include + #include "sched/sched.h" #include "signal/signal.h" @@ -94,20 +96,20 @@ sigset_t sig_pendingset(FAR struct tcb_s *stcb) FAR struct task_group_s *group = stcb->group; sigset_t sigpendset; FAR sigpendq_t *sigpend; - irqstate_t saved_state; + irqstate_t flags; DEBUGASSERT(group); sigpendset = NULL_SIGNAL_SET; - saved_state = irqsave(); + flags = enter_critical_section(); for (sigpend = (FAR sigpendq_t *)group->sigpendingq.head; (sigpend); sigpend = sigpend->flink) { sigaddset(&sigpendset, sigpend->info.si_signo); } - irqrestore(saved_state); + leave_critical_section(flags); return sigpendset; } diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index 5f0c68e389..e7a7ad9d8a 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_procmask.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -95,7 +96,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { FAR struct tcb_s *rtcb = this_task(); sigset_t oldsigprocmask; - irqstate_t saved_state; + irqstate_t flags; int ret = OK; sched_lock(); @@ -116,7 +117,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) * ourselves from attempts to process signals from interrupts */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Okay, determine what we are supposed to do */ @@ -149,7 +150,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) break; } - irqrestore(saved_state); + leave_critical_section(flags); /* Now, process any pending signals that were just unmasked */ diff --git a/sched/signal/sig_releasependingsigaction.c b/sched/signal/sig_releasependingsigaction.c index 3d47b7f2d0..11e8d72f98 100644 --- a/sched/signal/sig_releasependingsigaction.c +++ b/sched/signal/sig_releasependingsigaction.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_releasependingsigaction.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,27 +41,9 @@ #include -#include "signal/signal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ +#include -/**************************************************************************** - * Private Functions - ****************************************************************************/ +#include "signal/signal.h" /**************************************************************************** * Public Functions @@ -77,7 +59,7 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) { - irqstate_t saved_state; + irqstate_t flags; /* If this is a generally available pre-allocated structyre, * then just put it back in the free list. @@ -88,9 +70,9 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) /* Make sure we avoid concurrent access to the free * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingaction); - irqrestore(saved_state); + leave_critical_section(flags); } /* If this is a message pre-allocated for interrupts, @@ -102,9 +84,9 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) /* Make sure we avoid concurrent access to the free * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction); - irqrestore(saved_state); + leave_critical_section(flags); } /* Otherwise, deallocate it. Note: interrupt handlers diff --git a/sched/signal/sig_releasependingsignal.c b/sched/signal/sig_releasependingsignal.c index 97ed25c02a..3f671a8678 100644 --- a/sched/signal/sig_releasependingsignal.c +++ b/sched/signal/sig_releasependingsignal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_releasependingsignal.c * - * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,32 +46,13 @@ #include #include +#include #include #include #include #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -86,7 +67,7 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) { - irqstate_t saved_state; + irqstate_t flags; /* If this is a generally available pre-allocated structyre, * then just put it back in the free list. @@ -98,9 +79,9 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigpend, &g_sigpendingsignal); - irqrestore(saved_state); + leave_critical_section(flags); } /* If this is a message pre-allocated for interrupts, @@ -113,9 +94,9 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) * list from interrupt handlers. */ - saved_state = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigpend, &g_sigpendingirqsignal); - irqrestore(saved_state); + leave_critical_section(flags); } /* Otherwise, deallocate it. Note: interrupt handlers diff --git a/sched/signal/sig_removependingsignal.c b/sched/signal/sig_removependingsignal.c index 7f2a53ee9c..3de79184f7 100644 --- a/sched/signal/sig_removependingsignal.c +++ b/sched/signal/sig_removependingsignal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_removependingsignal.c * - * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,32 +46,13 @@ #include #include +#include #include #include #include #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -89,11 +70,11 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) FAR struct task_group_s *group = stcb->group; FAR sigpendq_t *currsig; FAR sigpendq_t *prevsig; - irqstate_t saved_state; + irqstate_t flags; DEBUGASSERT(group); - saved_state = irqsave(); + flags = enter_critical_section(); for (prevsig = NULL, currsig = (FAR sigpendq_t *)group->sigpendingq.head; (currsig && currsig->info.si_signo != signo); @@ -111,7 +92,7 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) } } - irqrestore(saved_state); + leave_critical_section(flags); return currsig; } diff --git a/sched/signal/sig_suspend.c b/sched/signal/sig_suspend.c index 56dc982991..d3a4a9ba71 100644 --- a/sched/signal/sig_suspend.c +++ b/sched/signal/sig_suspend.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_suspend.c * - * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -94,7 +95,7 @@ int sigsuspend(FAR const sigset_t *set) sigset_t intersection; sigset_t saved_sigprocmask; FAR sigpendq_t *sigpend; - irqstate_t saved_state; + irqstate_t flags; int unblocksigno; /* Several operations must be performed below: We must determine if any @@ -104,7 +105,7 @@ int sigsuspend(FAR const sigset_t *set) */ sched_lock(); /* Not necessary */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Check if there is a pending signal corresponding to one of the * signals that will be unblocked by the new sigprocmask. @@ -123,7 +124,7 @@ int sigsuspend(FAR const sigset_t *set) ASSERT(sigpend); sig_releasependingsignal(sigpend); - irqrestore(saved_state); + leave_critical_section(flags); } else { @@ -142,7 +143,7 @@ int sigsuspend(FAR const sigset_t *set) /* We are running again, restore the original sigprocmask */ rtcb->sigprocmask = saved_sigprocmask; - irqrestore(saved_state); + leave_critical_section(flags); /* Now, handle the (rare?) case where (a) a blocked signal was received * while the task was suspended but (b) restoring the original diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index ecf0798f87..687884dcf9 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_timedwait.c * - * Copyright (C) 2007-2009, 2012-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -166,7 +167,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, FAR struct tcb_s *rtcb = this_task(); sigset_t intersection; FAR sigpendq_t *sigpend; - irqstate_t saved_state; + irqstate_t flags; int32_t waitticks; int ret = ERROR; @@ -180,7 +181,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, * can only be eliminated by disabling interrupts! */ - saved_state = irqsave(); + flags = enter_critical_section(); /* Check if there is a pending signal corresponding to one of the * signals in the pending signal set argument. @@ -207,7 +208,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, /* Then dispose of the pending signal structure properly */ sig_releasependingsignal(sigpend); - irqrestore(saved_state); + leave_critical_section(flags); /* The return value is the number of the signal that awakened us */ @@ -338,7 +339,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, memcpy(info, &rtcb->sigunbinfo, sizeof(struct siginfo)); } - irqrestore(saved_state); + leave_critical_section(flags); } sched_unlock(); diff --git a/sched/task/task_activate.c b/sched/task/task_activate.c index 1c97f60dd1..dfe7f5192a 100644 --- a/sched/task/task_activate.c +++ b/sched/task/task_activate.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_activate.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,32 +42,9 @@ #include #include +#include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -89,7 +66,7 @@ int task_activate(FAR struct tcb_s *tcb) { - irqstate_t flags = irqsave(); + irqstate_t flags = enter_critical_section(); #ifdef CONFIG_SCHED_INSTRUMENTATION @@ -112,6 +89,6 @@ int task_activate(FAR struct tcb_s *tcb) #endif up_unblock_task(tcb); - irqrestore(flags); + leave_critical_section(flags); return OK; } diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index 7ce7feed9c..690294ec02 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_reparent.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,16 +41,14 @@ #include +#include + #include "sched/sched.h" #include "group/group.h" #include "task/task.h" #ifdef CONFIG_SCHED_HAVE_PARENT -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -90,7 +88,7 @@ int task_reparent(pid_t ppid, pid_t chpid) * the three task: Child, current parent, and new parent. */ - flags = irqsave(); + flags = enter_critical_section(); /* Get the child tasks task group */ @@ -202,7 +200,7 @@ int task_reparent(pid_t ppid, pid_t chpid) #endif /* CONFIG_SCHED_CHILD_STATUS */ errout_with_ints: - irqrestore(flags); + leave_critical_section(flags); return ret; } #else @@ -222,7 +220,7 @@ int task_reparent(pid_t ppid, pid_t chpid) * the three task: Child, current parent, and new parent. */ - flags = irqsave(); + flags = enter_critical_section(); /* Get the child tasks TCB (chtcb) */ @@ -314,7 +312,7 @@ int task_reparent(pid_t ppid, pid_t chpid) #endif /* CONFIG_SCHED_CHILD_STATUS */ errout_with_ints: - irqrestore(flags); + leave_critical_section(flags); return ret; } #endif diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index f72507756c..0656494696 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -43,6 +43,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -81,7 +82,7 @@ int task_restart(pid_t pid) FAR struct tcb_s *rtcb; FAR struct task_tcb_s *tcb; FAR dq_queue_t *tasklist; - irqstate_t state; + irqstate_t flags; int status; /* Make sure this task does not become ready-to-run while @@ -156,10 +157,10 @@ int task_restart(pid_t pid) tasklist = TLIST_HEAD(tcb->cmn.task_state); #endif - state = irqsave(); + flags = enter_critical_section(); dq_rem((FAR dq_entry_t *)tcb, tasklist); tcb->cmn.task_state = TSTATE_TASK_INVALID; - irqrestore(state); + leave_critical_section(flags); /* Deallocate anything left in the TCB's queues */ diff --git a/sched/task/task_terminate.c b/sched/task/task_terminate.c index f3abb7d825..52e4e4c8c0 100644 --- a/sched/task/task_terminate.c +++ b/sched/task/task_terminate.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include "sched/sched.h" #ifndef CONFIG_DISABLE_SIGNALS @@ -101,7 +101,7 @@ int task_terminate(pid_t pid, bool nonblocking) { FAR struct tcb_s *dtcb; FAR dq_queue_t *tasklist; - irqstate_t saved_state; + irqstate_t flags; /* Make sure the task does not become ready-to-run while we are futzing with * its TCB by locking ourselves as the executing task. @@ -158,10 +158,10 @@ int task_terminate(pid_t pid, bool nonblocking) tasklist = TLIST_HEAD(dtcb->task_state); #endif - saved_state = irqsave(); + flags = enter_critical_section(); dq_rem((FAR dq_entry_t *)dtcb, tasklist); dtcb->task_state = TSTATE_TASK_INVALID; - irqrestore(saved_state); + leave_critical_section(flags); /* At this point, the TCB should no longer be accessible to the system */ diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 9f73875a17..a573ff38ba 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -73,9 +74,9 @@ static FAR struct posix_timer_s *timer_allocate(void) /* Try to get a preallocated timer from the free list */ #if CONFIG_PREALLOC_TIMERS > 0 - flags = irqsave(); + flags = enter_critical_section(); ret = (FAR struct posix_timer_s *)sq_remfirst((FAR sq_queue_t *)&g_freetimers); - irqrestore(flags); + leave_critical_section(flags); /* Did we get one? */ @@ -103,9 +104,9 @@ static FAR struct posix_timer_s *timer_allocate(void) /* And add it to the end of the list of allocated timers */ - flags = irqsave(); + flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)ret, (FAR sq_queue_t *)&g_alloctimers); - irqrestore(flags); + leave_critical_section(flags); } return ret; diff --git a/sched/timer/timer_initialize.c b/sched/timer/timer_initialize.c index ab0c16d70c..634397fb6d 100644 --- a/sched/timer/timer_initialize.c +++ b/sched/timer/timer_initialize.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include "timer/timer.h" @@ -155,7 +155,7 @@ void weak_function timer_deleteall(pid_t pid) FAR struct posix_timer_s *next; irqstate_t flags; - flags = irqsave(); + flags = enter_critical_section(); for (timer = (FAR struct posix_timer_s *)g_alloctimers.head; timer; timer = next) { next = timer->flink; @@ -165,7 +165,7 @@ void weak_function timer_deleteall(pid_t pid) } } - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_DISABLE_POSIX_TIMERS */ diff --git a/sched/timer/timer_release.c b/sched/timer/timer_release.c index 05de32cd9e..3ad62febbc 100644 --- a/sched/timer/timer_release.c +++ b/sched/timer/timer_release.c @@ -10,7 +10,7 @@ * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions i, 2016n binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. @@ -42,6 +42,7 @@ #include #include +#include #include #include "timer/timer.h" @@ -68,7 +69,7 @@ static inline void timer_free(struct posix_timer_s *timer) /* Remove the timer from the allocated list */ - flags = irqsave(); + flags = enter_critical_section(); sq_rem((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_alloctimers); /* Return it to the free list if it is one of the preallocated timers */ @@ -77,14 +78,14 @@ static inline void timer_free(struct posix_timer_s *timer) if ((timer->pt_flags & PT_FLAGS_PREALLOCATED) != 0) { sq_addlast((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_freetimers); - irqrestore(flags); + leave_critical_section(flags); } else #endif { /* Otherwise, return it to the heap */ - irqrestore(flags); + leave_critical_section(flags); sched_kfree(timer); } } diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index de8eda47e8..dbba72a414 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -1,7 +1,7 @@ /******************************************************************************** * sched/timer/timer_settime.c * - * Copyright (C) 2007-2010, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "clock/clock.h" @@ -52,18 +53,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - /******************************************************************************** * Private Function Prototypes ********************************************************************************/ @@ -310,7 +299,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value FAR struct itimerspec *ovalue) { FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid; - irqstate_t state; + irqstate_t flags; int delay; int ret = OK; @@ -350,7 +339,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value * that the system timer is stable. */ - state = irqsave(); + flags = enter_critical_section(); /* Check if abstime is selected */ @@ -392,7 +381,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value 1, (uint32_t)((wdparm_t)timer)); } - irqrestore(state); + leave_critical_section(flags); return ret; } diff --git a/sched/wdog/wd_cancel.c b/sched/wdog/wd_cancel.c index 225e62a223..498e814427 100644 --- a/sched/wdog/wd_cancel.c +++ b/sched/wdog/wd_cancel.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wdog/wd_cancel.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -93,14 +94,14 @@ int wd_cancel(WDOG_ID wdog) { FAR struct wdog_s *curr; FAR struct wdog_s *prev; - irqstate_t state; + irqstate_t flags; int ret = ERROR; /* Prohibit timer interactions with the timer queue until the * cancellation is complete */ - state = irqsave(); + flags = enter_critical_section(); /* Make sure that the watchdog is initialized (non-NULL) and is still * active. @@ -168,6 +169,6 @@ int wd_cancel(WDOG_ID wdog) ret = OK; } - irqrestore(state); + leave_critical_section(flags); return ret; } diff --git a/sched/wdog/wd_create.c b/sched/wdog/wd_create.c index 82078cde58..2beb4ea98b 100644 --- a/sched/wdog/wd_create.c +++ b/sched/wdog/wd_create.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wdog/wd_create.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,8 @@ #include #include -#include +#include +#include #include #include @@ -93,14 +94,14 @@ WDOG_ID wd_create (void) { FAR struct wdog_s *wdog; - irqstate_t state; + irqstate_t flags; /* These actions must be atomic with respect to other tasks and also with * respect to interrupt handlers that may be allocating or freeing watchdog * timers. */ - state = irqsave(); + flags = enter_critical_section(); /* If we are in an interrupt handler -OR- if the number of pre-allocated * timer structures exceeds the reserve, then take the the next timer from @@ -136,7 +137,7 @@ WDOG_ID wd_create (void) DEBUGASSERT(g_wdnfree == 0); } - irqrestore(state); + leave_critical_section(flags); } /* We are in a normal tasking context AND there are not enough unreserved, @@ -148,7 +149,7 @@ WDOG_ID wd_create (void) { /* We do not require that interrupts be disabled to do this. */ - irqrestore(state); + leave_critical_section(flags); wdog = (FAR struct wdog_s *)kmm_malloc(sizeof(struct wdog_s)); /* Did we get one? */ diff --git a/sched/wdog/wd_delete.c b/sched/wdog/wd_delete.c index 14156418ad..d28252fce4 100644 --- a/sched/wdog/wd_delete.c +++ b/sched/wdog/wd_delete.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wdog/wd_delete.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,32 +43,13 @@ #include #include +#include #include #include #include #include "wdog/wdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -95,7 +76,7 @@ int wd_delete(WDOG_ID wdog) { - irqstate_t state; + irqstate_t flags; DEBUGASSERT(wdog); @@ -103,7 +84,7 @@ int wd_delete(WDOG_ID wdog) * it is being deallocated. */ - state = irqsave(); + flags = enter_critical_section(); /* Check if the watchdog has been started. */ @@ -128,7 +109,7 @@ int wd_delete(WDOG_ID wdog) * We don't need interrupts disabled to do this. */ - irqrestore(state); + leave_critical_section(flags); sched_kfree(wdog); } @@ -145,7 +126,7 @@ int wd_delete(WDOG_ID wdog) sq_addlast((FAR sq_entry_t *)wdog, &g_wdfreelist); g_wdnfree++; DEBUGASSERT(g_wdnfree <= CONFIG_PREALLOC_WDOGS); - irqrestore(state); + leave_critical_section(flags); } /* Return success */ diff --git a/sched/wdog/wd_gettime.c b/sched/wdog/wd_gettime.c index 03b815f815..f533f42f1e 100644 --- a/sched/wdog/wd_gettime.c +++ b/sched/wdog/wd_gettime.c @@ -1,7 +1,7 @@ /******************************************************************************** * sched/wdog/wd_gettime.c * - * Copyright (C) 2007, 2009, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,30 +40,10 @@ #include #include -#include +#include #include "wdog/wdog.h" -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Types - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ @@ -92,7 +72,7 @@ int wd_gettime(WDOG_ID wdog) /* Verify the wdog */ - flags = irqsave(); + flags = enter_critical_section(); if (wdog && WDOG_ISACTIVE(wdog)) { /* Traverse the watchdog list accumulating lag times until we find the wdog @@ -107,12 +87,12 @@ int wd_gettime(WDOG_ID wdog) delay += curr->lag; if (curr == wdog) { - irqrestore(flags); + leave_critical_section(flags); return delay; } } } - irqrestore(flags); + leave_critical_section(flags); return 0; } diff --git a/sched/wdog/wd_recover.c b/sched/wdog/wd_recover.c index f9471a64b3..2a4847471b 100644 --- a/sched/wdog/wd_recover.c +++ b/sched/wdog/wd_recover.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wdog/wdog_recover.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,36 +39,13 @@ #include +#include #include #include #include #include "wdog/wdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -103,7 +80,7 @@ void wd_recover(FAR struct tcb_s *tcb) * the future. */ - flags = irqsave(); + flags = enter_critical_section(); if (tcb->waitdog) { (void)wd_cancel(tcb->waitdog); @@ -111,5 +88,5 @@ void wd_recover(FAR struct tcb_s *tcb) tcb->waitdog = NULL; } - irqrestore(flags); + leave_critical_section(flags); } diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index f69a4d649c..0932bb6d55 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wdog/wd_start.c * - * Copyright (C) 2007-2009, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -232,7 +233,7 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...) FAR struct wdog_s *prev; FAR struct wdog_s *next; int32_t now; - irqstate_t state; + irqstate_t flags; int i; /* Verify the wdog */ @@ -249,7 +250,7 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...) * the critical section is established. */ - state = irqsave(); + flags = enter_critical_section(); if (WDOG_ISACTIVE(wdog)) { wd_cancel(wdog); @@ -394,7 +395,7 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...) sched_timer_resume(); #endif - irqrestore(state); + leave_critical_section(flags); return OK; } diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index c4175f7f03..22a6071944 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wqueue/kwork_cancel.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -104,7 +105,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, * new work is typically added to the work queue from interrupt handlers. */ - flags = irqsave(); + flags = enter_critical_section(); if (work->worker != NULL) { /* A little test of the integrity of the work queue */ @@ -123,7 +124,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, ret = OK; } - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/sched/wqueue/kwork_inherit.c b/sched/wqueue/kwork_inherit.c index c169d877ca..b6d98c7b40 100644 --- a/sched/wqueue/kwork_inherit.c +++ b/sched/wqueue/kwork_inherit.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/work/work_inherit.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include +#include #include #include "sched/sched.h" @@ -49,10 +50,6 @@ #if defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_SCHED_LPWORK) && \ defined(CONFIG_PRIORITY_INHERITANCE) -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -333,7 +330,7 @@ void lpwork_boostpriority(uint8_t reqprio) /* Prevent context switches until we get the priorities right */ - flags = irqsave(); + flags = enter_critical_section(); sched_lock(); /* Adjust the priority of every worker thread */ @@ -344,7 +341,7 @@ void lpwork_boostpriority(uint8_t reqprio) } sched_unlock(); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -379,7 +376,7 @@ void lpwork_restorepriority(uint8_t reqprio) /* Prevent context switches until we get the priorities right */ - flags = irqsave(); + flags = enter_critical_section(); sched_lock(); /* Adjust the priority of every worker thread */ @@ -390,7 +387,7 @@ void lpwork_restorepriority(uint8_t reqprio) } sched_unlock(); - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_SCHED_WORKQUEUE && CONFIG_SCHED_LPWORK && CONFIG_PRIORITY_INHERITANCE */ diff --git a/sched/wqueue/kwork_process.c b/sched/wqueue/kwork_process.c index b5c44be5ae..f09735fd66 100644 --- a/sched/wqueue/kwork_process.c +++ b/sched/wqueue/kwork_process.c @@ -45,11 +45,10 @@ #include #include +#include #include #include -#include - #include "wqueue/wqueue.h" #ifdef CONFIG_SCHED_WORKQUEUE @@ -110,7 +109,7 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) */ next = period; - flags = irqsave(); + flags = enter_critical_section(); /* Get the time that we started this polling cycle in clock ticks. */ @@ -162,7 +161,7 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) * performed... we don't have any idea how long this will take! */ - irqrestore(flags); + leave_critical_section(flags); worker(arg); /* Now, unfortunately, since we re-enabled interrupts we don't @@ -170,7 +169,7 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) * back at the head of the list. */ - flags = irqsave(); + flags = enter_critical_section(); work = (FAR struct work_s *)wqueue->q.head; } else @@ -264,7 +263,7 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) } } - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index e2f7d88003..3c4acb2d00 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -98,7 +99,7 @@ static void work_qqueue(FAR struct kwork_wqueue_s *wqueue, * or interrupt handlers. */ - flags = irqsave(); + flags = enter_critical_section(); work->worker = worker; /* Work callback. non-NULL means queued */ work->arg = arg; /* Callback argument */ work->delay = delay; /* Delay until work performed */ @@ -109,7 +110,7 @@ static void work_qqueue(FAR struct kwork_wqueue_s *wqueue, dq_addlast((FAR dq_entry_t *)work, &wqueue->q); - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** -- GitLab From e6bd3544f6575c2e91c827dd9afedef9de557911 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:20:35 -0600 Subject: [PATCH 727/858] Fix a name collision introduced in last commit --- sched/timer/timer_settime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index dbba72a414..d134441e3e 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -299,7 +299,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value FAR struct itimerspec *ovalue) { FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid; - irqstate_t flags; + irqstate_t intflags; int delay; int ret = OK; @@ -339,7 +339,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value * that the system timer is stable. */ - flags = enter_critical_section(); + intflags = enter_critical_section(); /* Check if abstime is selected */ @@ -381,7 +381,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value 1, (uint32_t)((wdparm_t)timer)); } - leave_critical_section(flags); + leave_critical_section(intflags); return ret; } -- GitLab From aa3e778dc6374b6dc3005eec5f207c4b4eafa6e3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:38:44 -0600 Subject: [PATCH 728/858] nuttx/net: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- net/arp/arp_notify.c | 14 +++++++------- net/icmpv6/icmpv6_notify.c | 14 +++++++------- net/icmpv6/icmpv6_rnotify.c | 14 +++++++------- net/iob/iob_alloc.c | 11 ++++++----- net/iob/iob_alloc_qentry.c | 9 +++++---- net/iob/iob_free.c | 23 ++++------------------- net/iob/iob_free_qentry.c | 7 ++++--- net/utils/net_lock.c | 7 ++++--- 8 files changed, 44 insertions(+), 55 deletions(-) diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c index e5a1559502..0966c92292 100644 --- a/net/arp/arp_notify.c +++ b/net/arp/arp_notify.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include "arp/arp.h" @@ -104,10 +104,10 @@ void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify) /* Add the wait structure to the list with interrupts disabled */ - flags = irqsave(); + flags = enter_critical_section(); notify->nt_flink = g_arp_waiters; g_arp_waiters = notify; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -134,7 +134,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify) * head of the list). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_arp_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink); @@ -154,7 +154,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->nt_sem); return ret; } @@ -184,7 +184,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout) * enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); abstime.tv_sec += timeout->tv_sec; @@ -220,7 +220,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout) /* Re-enable interrupts and return the result of the wait */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/icmpv6/icmpv6_notify.c b/net/icmpv6/icmpv6_notify.c index 07191a5342..4185b5a352 100644 --- a/net/icmpv6/icmpv6_notify.c +++ b/net/icmpv6/icmpv6_notify.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include "icmpv6/icmpv6.h" @@ -105,10 +105,10 @@ void icmpv6_wait_setup(const net_ipv6addr_t ipaddr, /* Add the wait structure to the list with interrupts disabled */ - flags = irqsave(); + flags = enter_critical_section(); notify->nt_flink = g_icmpv6_waiters; g_icmpv6_waiters = notify; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -136,7 +136,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify) * head of the list). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_icmpv6_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink); @@ -156,7 +156,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->nt_sem); return ret; } @@ -186,7 +186,7 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify, * be re-enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); abstime.tv_sec += timeout->tv_sec; @@ -212,7 +212,7 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify, /* Re-enable interrupts and return the result of the wait */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/icmpv6/icmpv6_rnotify.c b/net/icmpv6/icmpv6_rnotify.c index d7c04976eb..c8e38e3d63 100644 --- a/net/icmpv6/icmpv6_rnotify.c +++ b/net/icmpv6/icmpv6_rnotify.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include "netdev/netdev.h" #include "utils/utils.h" @@ -170,10 +170,10 @@ void icmpv6_rwait_setup(FAR struct net_driver_s *dev, /* Add the wait structure to the list with interrupts disabled */ - flags = irqsave(); + flags = enter_critical_section(); notify->rn_flink = g_icmpv6_rwaiters; g_icmpv6_rwaiters = notify; - irqrestore(flags); + leave_critical_section(flags); #else /* If there is only a single network device, then there can be only a @@ -218,7 +218,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) * head of the list). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_icmpv6_rwaiters; curr && curr != notify; prev = curr, curr = curr->rn_flink); @@ -238,7 +238,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->rn_sem); return ret; @@ -282,7 +282,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, * be re-enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); abstime.tv_sec += timeout->tv_sec; @@ -308,7 +308,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, /* Re-enable interrupts and return the result of the wait */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index 2583fc4136..e5483a2c3e 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -89,7 +90,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled) * we are waiting for I/O buffers to become free. */ - flags = irqsave(); + flags = enter_critical_section(); do { /* Try to get an I/O buffer. If successful, the semaphore count @@ -158,7 +159,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled) } while (ret == OK && iob == NULL); - irqrestore(flags); + leave_critical_section(flags); return iob; } @@ -219,7 +220,7 @@ FAR struct iob_s *iob_tryalloc(bool throttled) * to protect the free list: We disable interrupts very briefly. */ - flags = irqsave(); + flags = enter_critical_section(); #if CONFIG_IOB_THROTTLE > 0 /* If there are free I/O buffers for this allocation */ @@ -257,7 +258,7 @@ FAR struct iob_s *iob_tryalloc(bool throttled) g_throttle_sem.semcount--; DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE); #endif - irqrestore(flags); + leave_critical_section(flags); /* Put the I/O buffer in a known state */ @@ -269,6 +270,6 @@ FAR struct iob_s *iob_tryalloc(bool throttled) } } - irqrestore(flags); + leave_critical_section(flags); return NULL; } diff --git a/net/iob/iob_alloc_qentry.c b/net/iob/iob_alloc_qentry.c index 2aab1e6353..c1a9f54a97 100644 --- a/net/iob/iob_alloc_qentry.c +++ b/net/iob/iob_alloc_qentry.c @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -83,7 +84,7 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void) * re-enabled while we are waiting for I/O buffers to become free. */ - flags = irqsave(); + flags = enter_critical_section(); do { /* Try to get an I/O buffer chain container. If successful, the @@ -152,7 +153,7 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void) } while (ret == OK && !qentry); - irqrestore(flags); + leave_critical_section(flags); return qentry; } @@ -207,7 +208,7 @@ FAR struct iob_qentry_s *iob_tryalloc_qentry(void) * to protect the free list: We disable interrupts very briefly. */ - flags = irqsave(); + flags = enter_critical_section(); iobq = g_iob_freeqlist; if (iobq) { @@ -233,7 +234,7 @@ FAR struct iob_qentry_s *iob_tryalloc_qentry(void) iobq->qe_head = NULL; /* Nothing is contained */ } - irqrestore(flags); + leave_critical_section(flags); return iobq; } diff --git a/net/iob/iob_free.c b/net/iob/iob_free.c index 984287600d..53d8f6fb1d 100644 --- a/net/iob/iob_free.c +++ b/net/iob/iob_free.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/iob/iob_free.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,27 +50,12 @@ #include #include +#include #include #include #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -128,7 +113,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) * protect the free list: We disable interrupts very briefly. */ - flags = irqsave(); + flags = enter_critical_section(); iob->io_flink = g_iob_freelist; g_iob_freelist = iob; @@ -138,7 +123,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) #if CONFIG_IOB_THROTTLE > 0 sem_post(&g_throttle_sem); #endif - irqrestore(flags); + leave_critical_section(flags); /* And return the I/O buffer after the one that was freed */ diff --git a/net/iob/iob_free_qentry.c b/net/iob/iob_free_qentry.c index f93f16f8f6..2c5e6fc6e9 100644 --- a/net/iob/iob_free_qentry.c +++ b/net/iob/iob_free_qentry.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/iob/iob_free_qentry.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -95,14 +96,14 @@ FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq) * measures to protect the free list: We disable interrupts very briefly. */ - flags = irqsave(); + flags = enter_critical_section(); iobq->qe_flink = g_iob_freeqlist; g_iob_freeqlist = iobq; /* Signal that an I/O buffer chain container is available */ sem_post(&g_qentry_sem); - irqrestore(flags); + leave_critical_section(flags); /* And return the I/O buffer chain container after the one that was freed */ diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c index da359840ce..49ce834070 100644 --- a/net/utils/net_lock.c +++ b/net/utils/net_lock.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/utils/net_lock.c * - * Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -197,7 +198,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime) irqstate_t flags; int ret; - flags = irqsave(); /* No interrupts */ + flags = enter_critical_section(); /* No interrupts */ sched_lock(); /* No context switches */ if (g_holder == me) { @@ -235,7 +236,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime) } sched_unlock(); - irqrestore(flags); + leave_critical_section(flags); return ret; } -- GitLab From 884d9355c6aa06b15c019db7dc05fe92c65748fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:43:47 -0600 Subject: [PATCH 729/858] nuttx/fs: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- fs/procfs/fs_procfs.c | 11 +++++------ fs/procfs/fs_procfsproc.c | 27 +++++++++++++-------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 7f86a17a8d..3db09f68be 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -61,8 +62,6 @@ #include #include -#include - #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) /**************************************************************************** @@ -509,9 +508,9 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, */ #ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS - flags = irqsave(); + flags = enter_critical_section(); sched_foreach(procfs_enum, level0); - irqrestore(flags); + leave_critical_section(flags); #else level0->base.index = 0; level0->base.nentries = 0; @@ -752,9 +751,9 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) pid = level0->pid[index]; - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(pid); - irqrestore(flags); + leave_critical_section(flags); if (!tcb) { diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index b01b2cbb8e..e90d46ef08 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/procfs/fs_procfsproc.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -64,8 +65,6 @@ # include #endif -#include - #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) #ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS @@ -1032,9 +1031,9 @@ static int proc_open(FAR struct file *filep, FAR const char *relpath, pid = (pid_t)tmp; - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(pid); - irqrestore(flags); + leave_critical_section(flags); if (!tcb) { @@ -1122,13 +1121,13 @@ static ssize_t proc_read(FAR struct file *filep, FAR char *buffer, /* Verify that the thread is still valid */ - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(procfile->pid); if (!tcb) { fdbg("ERROR: PID %d is not valid\n", (int)procfile->pid); - irqrestore(flags); + leave_critical_section(flags); return -ENODEV; } @@ -1166,7 +1165,7 @@ static ssize_t proc_read(FAR struct file *filep, FAR char *buffer, break; } - irqrestore(flags); + leave_critical_section(flags); /* Update the file offset */ @@ -1271,9 +1270,9 @@ static int proc_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir) pid = (pid_t)tmp; - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(pid); - irqrestore(flags); + leave_critical_section(flags); if (!tcb) { @@ -1403,9 +1402,9 @@ static int proc_readdir(struct fs_dirent_s *dir) pid = procdir->pid; - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(pid); - irqrestore(flags); + leave_critical_section(flags); if (!tcb) { @@ -1513,9 +1512,9 @@ static int proc_stat(const char *relpath, struct stat *buf) pid = (pid_t)tmp; - flags = irqsave(); + flags = enter_critical_section(); tcb = sched_gettcb(pid); - irqrestore(flags); + leave_critical_section(flags); if (!tcb) { -- GitLab From f45db0313d22bff88a1c5e82b7c5906358f46682 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:46:08 -0600 Subject: [PATCH 730/858] nuttx/binfmt: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- binfmt/binfmt_execsymtab.c | 11 ++++++----- binfmt/binfmt_schedunload.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/binfmt/binfmt_execsymtab.c b/binfmt/binfmt_execsymtab.c index ceb532d94c..09a36bfce7 100644 --- a/binfmt/binfmt_execsymtab.c +++ b/binfmt/binfmt_execsymtab.c @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/binfmt_execsymtab.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include +#include #include #include @@ -116,10 +117,10 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols) * size are returned as a single atomic operation. */ - flags = irqsave(); + flags = enter_critical_section(); *symtab = g_exec_symtab; *nsymbols = g_exec_nsymbols; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -147,10 +148,10 @@ void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols) * size are set as a single atomic operation. */ - flags = irqsave(); + flags = enter_critical_section(); g_exec_symtab = symtab; g_exec_nsymbols = nsymbols; - irqrestore(flags); + leave_critical_section(flags); } #endif /* CONFIG_LIBC_EXECFUNCS */ \ No newline at end of file diff --git a/binfmt/binfmt_schedunload.c b/binfmt/binfmt_schedunload.c index b9c6a9d6d1..f9da1349f6 100644 --- a/binfmt/binfmt_schedunload.c +++ b/binfmt/binfmt_schedunload.c @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/binfmt_schedunload.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -105,10 +106,10 @@ static void unload_list_add(pid_t pid, FAR struct binary_s *bin) * interrupts. */ - flags = irqsave(); + flags = enter_critical_section(); bin->flink = g_unloadhead; g_unloadhead = bin; - irqrestore(flags); + leave_critical_section(flags); } /**************************************************************************** @@ -313,13 +314,13 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin) /* Emergency removal from the list */ - flags = irqsave(); + flags = enter_critical_section(); if (unload_list_remove(pid) != bin) { blldbg("ERROR: Failed to remove structure\n"); } - irqrestore(flags); + leave_critical_section(flags); goto errout; } -- GitLab From 046e39e2c60bb1bd77c2aff10ba0f9641300de54 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:57:01 -0600 Subject: [PATCH 731/858] nuttx/mm and libc: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- libc/syslog/lib_setlogmask.c | 8 ++++---- libc/unistd/lib_gethostname.c | 8 ++++---- libc/unistd/lib_sethostname.c | 8 +++++--- mm/mm_gran/mm_grancritical.c | 8 ++++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libc/syslog/lib_setlogmask.c b/libc/syslog/lib_setlogmask.c index f51572e408..2179b7b6a9 100644 --- a/libc/syslog/lib_setlogmask.c +++ b/libc/syslog/lib_setlogmask.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/syslog/lib_setlogmask.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ #include #include -#include +#include #include "syslog/syslog.h" @@ -97,11 +97,11 @@ int setlogmask(int mask) * as interrupts. */ - flags = irqsave(); + flags = enter_critical_section(); oldmask = g_syslog_mask; g_syslog_mask = (uint8_t)mask; - irqrestore(flags); + leave_critical_section(flags); return oldmask; } diff --git a/libc/unistd/lib_gethostname.c b/libc/unistd/lib_gethostname.c index ec12b5afe5..c21b9157b3 100644 --- a/libc/unistd/lib_gethostname.c +++ b/libc/unistd/lib_gethostname.c @@ -2,7 +2,7 @@ * libc/unistd/lib_gethostname.c * * Copyright (C) 2015 Stavros Polymenis. All rights reserved. - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2016 Gregory Nutt. All rights reserved. * Author: Stavros Polymenis * Gregory Nutt * @@ -45,7 +45,7 @@ #include #include -#include +#include /* This file is only compiled if network support is enabled */ @@ -119,9 +119,9 @@ int gethostname(FAR char *name, size_t namelen) * that it could change while we are copying it. */ - flags = irqsave(); + flags = enter_critical_section(); strncpy(name, g_hostname, namelen); - irqrestore(flags); + leave_critical_section(flags); return 0; diff --git a/libc/unistd/lib_sethostname.c b/libc/unistd/lib_sethostname.c index 2546e0fce9..8d51c74971 100644 --- a/libc/unistd/lib_sethostname.c +++ b/libc/unistd/lib_sethostname.c @@ -2,7 +2,9 @@ * libc/unistd/lib_gethostname.c * * Copyright (C) 2015 Stavros Polymenis. All rights reserved. + * Copyright (C) 2015, 2016 Gregory Nutt. All rights reserved. * Author: Stavros Polymenis + * Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +44,7 @@ #include #include -#include +#include /* This file is only compiled if network support is enabled */ @@ -118,10 +120,10 @@ int sethostname(FAR const char *name, size_t size) * are setting it. */ - flags = irqsave(); + flags = enter_critical_section(); strncpy(g_hostname, name, MIN(HOST_NAME_MAX, size)); g_hostname[HOST_NAME_MAX] = '\0'; - irqrestore(flags); + leave_critical_section(flags); return 0; } diff --git a/mm/mm_gran/mm_grancritical.c b/mm/mm_gran/mm_grancritical.c index ae16a39844..a105f03a07 100644 --- a/mm/mm_gran/mm_grancritical.c +++ b/mm/mm_gran/mm_grancritical.c @@ -1,7 +1,7 @@ /**************************************************************************** * mm/mm_gran/mm_grancritical.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include "mm_gran/mm_gran.h" @@ -83,7 +83,7 @@ void gran_enter_critical(FAR struct gran_s *priv) { #ifdef CONFIG_GRAN_INTR - priv->irqstate = irqsave(); + priv->irqstate = enter_critical_section(); #else int ret; @@ -104,7 +104,7 @@ void gran_enter_critical(FAR struct gran_s *priv) void gran_leave_critical(FAR struct gran_s *priv) { #ifdef CONFIG_GRAN_INTR - irqrestore(priv->irqstate); + leave_critical_section(priv->irqstate); #else sem_post(&priv->exclsem); #endif -- GitLab From 88c17bb4f22aefec89d36b793f92b9a633925837 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 15:09:28 -0600 Subject: [PATCH 732/858] nuttx/graphics and include: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- Documentation | 2 +- graphics/nxterm/nxterm_kbdin.c | 21 ++++++--------------- include/nuttx/net/net.h | 8 ++++---- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Documentation b/Documentation index 0d2a964b20..7711e6eb46 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 0d2a964b20c73ca7c67f6602345f903055c02623 +Subproject commit 7711e6eb4606b41a45858ac240e619167c5488d5 diff --git a/graphics/nxterm/nxterm_kbdin.c b/graphics/nxterm/nxterm_kbdin.c index 3b53514ec1..395f6f759f 100644 --- a/graphics/nxterm/nxterm_kbdin.c +++ b/graphics/nxterm/nxterm_kbdin.c @@ -1,7 +1,7 @@ /**************************************************************************** * nuttx/graphics/nxterm/nxterm_kbdin.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,22 +46,12 @@ #include #include +#include + #include "nxterm.h" #ifdef CONFIG_NXTERM_NXKBDIN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -81,7 +71,7 @@ static void nxterm_pollnotify(FAR struct nxterm_state_s *priv, pollevent_t event for (i = 0; i < CONFIG_NXTERM_NPOLLWAITERS; i++) { - flags = irqsave(); + flags = enter_critical_section(); fds = priv->fds[i]; if (fds) { @@ -91,7 +81,8 @@ static void nxterm_pollnotify(FAR struct nxterm_state_s *priv, pollevent_t event sem_post(fds->sem); } } - irqrestore(flags); + + leave_critical_section(flags); } } #else diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index a5b2afc440..07f6cead77 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/net.h * - * Copyright (C) 2007, 2009-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,7 +50,7 @@ #include #ifndef CONFIG_NET_NOINTS -# include +# include #endif /**************************************************************************** @@ -253,7 +253,7 @@ void net_initialize(void); #ifdef CONFIG_NET_NOINTS net_lock_t net_lock(void); #else -# define net_lock() irqsave() +# define net_lock() enter_critical_section() #endif /**************************************************************************** @@ -267,7 +267,7 @@ net_lock_t net_lock(void); #ifdef CONFIG_NET_NOINTS void net_unlock(net_lock_t flags); #else -# define net_unlock(f) irqrestore(f) +# define net_unlock(f) leave_critical_section(f) #endif /**************************************************************************** -- GitLab From 9cb2a6b1f96b8373dc8995fe2f1b5759a4ce60d2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 16:19:15 -0600 Subject: [PATCH 733/858] Rename irqsave() and irqrestore() to up_irq_save() and up_irq_restore() --- ChangeLog | 4 ++++ TODO | 4 ++-- arch | 2 +- configs | 2 +- include/nuttx/arch.h | 4 ++-- include/nuttx/irq.h | 8 ++++---- sched/irq/irq_csection.c | 4 ++-- sched/irq/irq_unexpectedisr.c | 2 +- sched/paging/pg_worker.c | 2 +- sched/semaphore/spinlock.c | 12 ++++++------ 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78892f8035..bdcaee4d7f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11486,4 +11486,8 @@ * Everywhere: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section(). This is part of the onging development of SMP support (2016-02-13). + * Conform to naming convention: Rename irqsave() to up_irq_save(); rename + irqrestore() to up_irq_restore(). These should no longer be used. If + your code still uses them, please switch to enter_critical_section() + and leave_critical_section() (2016-02-14). diff --git a/TODO b/TODO index e8bf3a1a8b..0c17856b6e 100644 --- a/TODO +++ b/TODO @@ -1604,8 +1604,8 @@ o Linux/Cywgin simulation (arch/sim) "faked" during IDLE loop processing and, as a result, there is no task pre-emption because there are no asynchronous events. This could probably be fixed if the "timer interrupt" were driver by Linux - signals. NOTE: You would also have to implement irqsave() and - irqrestore() to block and (conditionally) unblock the signal. + signals. NOTE: You would also have to implement up_irq_save() and + up_irq_restore() to block and (conditionally) unblock the signal. Status: Open Priority: Low diff --git a/arch b/arch index 354df5c0f3..4a9148e44a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 354df5c0f3f7e0f4df605a85edef7d8e170843c1 +Subproject commit 4a9148e44aa3a1540ce26fc15599732c281cbbfd diff --git a/configs b/configs index cfbc3f7c3e..904067c60c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit cfbc3f7c3e07bf07b012e42933f3fea7c2397d52 +Subproject commit 904067c60cb19341e9f806710f7f8c20301a33e8 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index a6a30e69f0..bec1aab8e1 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1350,7 +1350,7 @@ bool up_interrupt_context(void); * * This function implements enabling of the device specified by 'irq' * at the interrupt controller level if supported by the architecture - * (irqrestore() supports the global level, the device level is hardware + * (up_irq_restore() supports the global level, the device level is hardware * specific). * * Since this API is not supported on all architectures, it should be @@ -1368,7 +1368,7 @@ void up_enable_irq(int irq); * Description: * This function implements disabling of the device specified by 'irq' * at the interrupt controller level if supported by the architecture - * (irqsave() supports the global level, the device level is hardware + * (up_irq_save() supports the global level, the device level is hardware * specific). * * Since this API is not supported on all architectures, it should be diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index 519059c7f6..2f7dba3764 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -109,14 +109,14 @@ int irq_attach(int irq, xcpt_t isr); * specific counter is increment to indicate that the thread has IRQs * disabled and to support nested calls to enter_critical_section(). * If SMP is not enabled: - * This function is equivalent to irqsave(). + * This function is equivalent to up_irq_save(). * ****************************************************************************/ #ifdef CONFIG_SMP irqstate_t enter_critical_section(void); #else -# define enter_critical_section(f) irqsave(f) +# define enter_critical_section(f) up_irq_save(f) #endif /**************************************************************************** @@ -127,14 +127,14 @@ irqstate_t enter_critical_section(void); * Decrement the IRQ lock count and if it decrements to zero then release * the spinlock. * If SMP is not enabled: - * This function is equivalent to irqrestore(). + * This function is equivalent to up_irq_restore(). * ****************************************************************************/ #ifdef CONFIG_SMP void leave_critical_section(irqstate_t flags); #else -# define leave_critical_section(f) irqrestore(f) +# define leave_critical_section(f) up_irq_restore(f) #endif #undef EXTERN diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index 536117151d..38eebdf3d0 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -97,7 +97,7 @@ irqstate_t enter_critical_section(void) /* Then disable interrupts (if they have not already been disabeld) */ - return irqsave(); + return up_irq_save(); } /**************************************************************************** @@ -136,7 +136,7 @@ void leave_critical_section(irqstate_t flags) * disabled (but we don't have a mechanism to verify that now) */ - irqrestore(flags); + up_irq_restore(flags); } #endif /* CONFIG_SMP */ diff --git a/sched/irq/irq_unexpectedisr.c b/sched/irq/irq_unexpectedisr.c index 9f207ae860..490a6251e1 100644 --- a/sched/irq/irq_unexpectedisr.c +++ b/sched/irq/irq_unexpectedisr.c @@ -80,7 +80,7 @@ int irq_unexpected_isr(int irq, FAR void *context) { - (void)irqsave(); + (void)up_irq_save(); lldbg("irq: %d\n", irq); PANIC(); return OK; /* Won't get here */ diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 701076901a..668d768d44 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -537,7 +537,7 @@ int pg_worker(int argc, char *argv[]) */ pglldbg("Started\n"); - (void)irqsave(); + (void)up_irq_save(); for (; ; ) { /* Wait awhile. We will wait here until either the configurable timeout diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index a5919305f4..2b6c56f052 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -157,7 +157,7 @@ void spin_lockr(FAR struct spinlock_s *lock) /* Disable interrupts (all CPUs) */ - flags = irqsave(); + flags = up_irq_save(); /* Do we already hold the lock on this CPU? */ @@ -187,9 +187,9 @@ void spin_lockr(FAR struct spinlock_s *lock) while (up_testset(&lock->sp_lock) == SP_LOCKED) { - irqrestore(flags); + up_irq_restore(flags); sched_yield(); - flags = irqsave(); + flags = up_irq_save(); } /* Take one count on the lock */ @@ -198,7 +198,7 @@ void spin_lockr(FAR struct spinlock_s *lock) lock->sp_count = 1; } - irqrestore(flags); + up_irq_restore(flags); #else /* CONFIG_SMP */ @@ -242,7 +242,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) /* Disable interrupts (all CPUs) */ - flags = irqsave(); + flags = up_irq_save(); #ifdef CONFIG_SPINLOCK_LOCKDOWN /* REVISIT: What happens if this thread took the lock on a different CPU, @@ -282,7 +282,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) } } - irqrestore(flags); + up_irq_restore(flags); #else /* CONFIG_SMP */ /* Just mark the spinlock unlocked */ -- GitLab From 1e9fb78d1c11d0a727b991e6ae4150c4e011441f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 16:20:54 -0600 Subject: [PATCH 734/858] Update submodule --- Documentation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation b/Documentation index 7711e6eb46..d03dc1e3e3 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 7711e6eb4606b41a45858ac240e619167c5488d5 +Subproject commit d03dc1e3e320d6822211bc99101f1828fee49df8 -- GitLab From 4d0103f210893af708f16c38856ceffb2e80e1ea Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 16:55:06 -0600 Subject: [PATCH 735/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bdcaee4d7f..7ce513e2f0 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11490,4 +11490,6 @@ irqrestore() to up_irq_restore(). These should no longer be used. If your code still uses them, please switch to enter_critical_section() and leave_critical_section() (2016-02-14). + * Also rename irqdisable() and irqenable() to up_irq_disable() and + up_irq_enable (2016-02-14). diff --git a/arch b/arch index 4a9148e44a..70afd900cc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 4a9148e44aa3a1540ce26fc15599732c281cbbfd +Subproject commit 70afd900cc88772c12618e1b099e47e20d947979 -- GitLab From c7df82147ffe84e9c100dabb4a4e6149cb623fe9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 08:06:17 -0600 Subject: [PATCH 736/858] SMP: First cut integration of enter/leave_critical_section and the scheduler. There are some issues. --- arch | 2 +- sched/irq/irq.h | 14 ++++ sched/irq/irq_csection.c | 105 +++++++++++++++++++++------ sched/sched/sched_addreadytorun.c | 26 ++++++- sched/sched/sched_lock.c | 2 +- sched/sched/sched_removereadytorun.c | 30 ++++++-- sched/sched/sched_unlock.c | 8 +- 7 files changed, 153 insertions(+), 34 deletions(-) diff --git a/arch b/arch index 70afd900cc..839a04f989 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 70afd900cc88772c12618e1b099e47e20d947979 +Subproject commit 839a04f989000895820af4691d9596fc4385f48b diff --git a/sched/irq/irq.h b/sched/irq/irq.h index d2c6321968..75d18755b9 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -64,6 +64,20 @@ extern FAR xcpt_t g_irqvector[NR_IRQS+1]; */ extern spinlock_t g_cpu_irqlock; + +/* Used to keep track of which CPU(s) hold the IRQ lock. There really should + * only be one. + */ + +#if (CONFIG_SMP_NCPUS <= 8) +volatile uint8_t g_cpu_irqset; +#elif (CONFIG_SMP_NCPUS <= 16) +volatile uint16_t g_cpu_irqset; +#elif (CONFIG_SMP_NCPUS <= 32) +volatile uint32_t g_cpu_irqset; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif #endif /**************************************************************************** diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index 38eebdf3d0..c3467abfbb 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -56,6 +57,20 @@ spinlock_t g_cpu_irqlock = SP_UNLOCKED; +/* Used to keep track of which CPU(s) hold the IRQ lock. There really should + * only be one. + */ + +#if (CONFIG_SMP_NCPUS <= 8) +volatile uint8_t g_cpu_irqset; +#elif (CONFIG_SMP_NCPUS <= 16) +volatile uint16_t g_cpu_irqset; +#elif (CONFIG_SMP_NCPUS <= 32) +volatile uint32_t g_cpu_irqset; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -72,10 +87,22 @@ spinlock_t g_cpu_irqlock = SP_UNLOCKED; irqstate_t enter_critical_section(void) { - FAR struct tcb_s *rtcb = this_task(); + FAR struct tcb_s *rtcb; + + /* Do nothing if called from an interrupt handler */ + + if (up_interrupt_context()) + { + /* The value returned does not matter. We assume only that it is a + * scalar here. + */ + + return (irqstate_t)0; + } /* Do we already have interrupts disabled? */ + rtcb = this_task(); if (rtcb->irqcount > 0) { /* Yes... make sure that the spinlock is set and increment the IRQ @@ -89,13 +116,28 @@ irqstate_t enter_critical_section(void) { /* NO.. Take the spinlock to get exclusive access and set the lock * count to 1. + * + * We must avoid that case where a context occurs between taking the + * g_cpu_irqlock and disabling interrupts. Also interrupts disables + * must follow a stacked order. We cannot other context switches to + * re-order the enabling/disabling of interrupts. We can both by + * locking the scheduler while interrupts are disabled. + * + * NOTE: that sched_lock() also uses a spinlock. We will avoid + * deadlocks by assuring that the scheduler spinlock is always + * taken before the IRQ spinlock. */ + sched_lock(); spin_lock(&g_cpu_irqlock); + rtcb->irqcount = 1; + g_cpu_irqset |= (1 << this_cpu()); } - /* Then disable interrupts (if they have not already been disabeld) */ + /* Then disable interrupts (they may already be disabled, be we need to + * return valid interrupt status in any event). + */ return up_irq_save(); } @@ -111,32 +153,51 @@ irqstate_t enter_critical_section(void) void leave_critical_section(irqstate_t flags) { - FAR struct tcb_s *rtcb = this_task(); + /* Do nothing if called from an interrupt handler */ - DEBUGASSERT(rtcb->irqcount > 0); - - /* Will we still have interrupts disabled after decrementing the count? */ - - if (rtcb->irqcount > 1) + if (!up_interrupt_context()) { - /* Yes... make sure that the spinlock is set */ + FAR struct tcb_s *rtcb = this_task(); - DEBUGASSERT(g_cpu_irqlock == SP_LOCKED); - rtcb->irqcount--; - } - else - { - /* NO.. Take the spinlock to get exclusive access. */ + DEBUGASSERT(rtcb->irqcount > 0); - rtcb->irqcount = 0; - spin_unlock(g_cpu_irqlock); - } + /* Will we still have interrupts disabled after decrementing the + * count? + */ - /* Restore the previous interrupt state which may still be interrupts - * disabled (but we don't have a mechanism to verify that now) - */ + if (rtcb->irqcount > 1) + { + /* Yes... make sure that the spinlock is set */ + + DEBUGASSERT(g_cpu_irqlock == SP_LOCKED); + rtcb->irqcount--; + } + else + { + /* NO.. Release the spinlock to allow other access. + * + * REVISIT: There is a cornercase where multiple CPUs may think + * they are the holder of the IRQ spinlock. We will need to disable + * the scheduler to assure that the following operation is atomic + * Hmmm... but that could cause a deadlock! What to do? Perhaps + * an array of booleans instead of a bitset? + */ + + g_cpu_irqset &= ~(1 << this_cpu()); + rtcb->irqcount = 0; + spin_unlock(g_cpu_irqlock); + + /* And re-enable pre-emption */ + + sched_unlock(); + } + + /* Restore the previous interrupt state which may still be interrupts + * disabled (but we don't have a mechanism to verify that now) + */ - up_irq_restore(flags); + up_irq_restore(flags); + } } #endif /* CONFIG_SMP */ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 08eb3a018c..5a0cac5c9d 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -43,6 +43,7 @@ #include #include +#include "irq/irq.h" #include "sched/sched.h" /**************************************************************************** @@ -326,7 +327,10 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) btcb->cpu = cpu; btcb->task_state = TSTATE_TASK_RUNNING; - /* Adjust global pre-emption controls. */ + /* Adjust global pre-emption controls. If the lockcount is + * greater than zero, then this task/this CPU holds the scheduler + * lock. + */ if (btcb->lockcount > 0) { @@ -335,13 +339,31 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) } else { - g_cpu_lockset &= ~(1 << cpu); + g_cpu_lockset &= ~(1 << cpu); if (g_cpu_lockset == 0) { g_cpu_schedlock = SP_UNLOCKED; } } + /* Adjust global IRQ controls. If irqcount is greater than zero, + * then this task/this CPU holds the IRQ lock + */ + + if (btcb->irqcount > 0) + { + g_cpu_irqset |= (1 << cpu); + g_cpu_irqlock = SP_LOCKED; + } + else + { + g_cpu_irqset &= ~(1 << cpu); + if (g_cpu_irqset == 0) + { + g_cpu_irqlock = SP_UNLOCKED; + } + } + /* If the following task is not assigned to this CPU, then it must * be moved to the g_readytorun list. Since it cannot be at the * head of the list, we can do this without invoking any heavy diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 9340d65ea5..c524cdd8cc 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -109,7 +109,7 @@ volatile spinlock_t g_cpu_schedlock; #if (CONFIG_SMP_NCPUS <= 8) -volatile uint8_t g_cpu_lockset; +volatile uint8_t g_cpu_lockset; #elif (CONFIG_SMP_NCPUS <= 16) volatile uint16_t g_cpu_lockset; #elif (CONFIG_SMP_NCPUS <= 32) diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 62a709ce0d..a844af73d7 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -43,6 +43,7 @@ #include #include +#include "irq/irq.h" #include "sched/sched.h" /**************************************************************************** @@ -109,7 +110,9 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) DEBUGASSERT(ntcb != NULL); #ifdef CONFIG_SMP - /* Will pre-emption be disabled after the switch? */ + /* Will pre-emption be disabled after the switch? If the lockcount is + * greater than zero, then this task/this CPU holds the scheduler lock. + */ if (ntcb->lockcount > 0) { @@ -120,15 +123,30 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) } else { - /* No.. we may need to perform release our hold on the lock. - * - * REVISIT: It might be possible for two CPUs to hold the logic in - * some strange cornercases like: - */ + /* No.. we may need to perform release our hold on the lock. */ g_cpu_lockset &= ~(1 << this_cpu()); g_cpu_schedlock = ((g_cpu_lockset == 0) ? SP_UNLOCKED : SP_LOCKED); } + + /* Interrupts be disabled after the switch. If irqcount is greater + * than zero, then this task/this CPU holds the IRQ lock + */ + + if (ntcb->irqcount > 0) + { + /* Yes... make sure that scheduling logic knows about this */ + + g_cpu_irqset |= (1 << this_cpu()); + g_cpu_irqlock = SP_LOCKED; + } + else + { + /* No.. we may need to perform release our hold on the lock. */ + + g_cpu_irqset &= ~(1 << this_cpu()); + g_cpu_irqlock = ((g_cpu_irqset == 0) ? SP_UNLOCKED : SP_LOCKED); + } #endif /* Inform the instrumentation layer that we are switching tasks */ diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 81179ff6da..602ed81761 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -73,13 +73,17 @@ int sched_unlock(void) if (rtcb && !up_interrupt_context()) { - /* Prevent context switches throughout the following */ + /* Prevent context switches throughout the following. + * + * REVISIT: This is awkward. In the SMP case, enter_critical_section + * increments the lockcount! + */ irqstate_t flags = enter_critical_section(); /* Decrement the preemption lock counter */ - if (rtcb->lockcount) + if (rtcb->lockcount > 0) { rtcb->lockcount--; } -- GitLab From 3c46fa3f9f37de63aa90b321d588c6f0699c3bb7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 08:50:20 -0600 Subject: [PATCH 737/858] Fix a contention problem in the previous critical section design --- sched/irq/irq.h | 18 ++++++++++++++++++ sched/irq/irq_csection.c | 31 ++++++++++++++----------------- sched/irq/irq_unexpectedisr.c | 20 -------------------- sched/sched/sched_addreadytorun.c | 8 +++++--- sched/sched/sched_unlock.c | 21 +++++++++++---------- sched/task/task_exit.c | 2 +- 6 files changed, 49 insertions(+), 51 deletions(-) diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 75d18755b9..586f86904f 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -92,7 +92,25 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Name: irq_initialize + * + * Description: + * Configure the IRQ subsystem + * + ****************************************************************************/ + void weak_function irq_initialize(void); + +/**************************************************************************** + * Name: irq_unexpected_isr + * + * Description: + * An interrupt has been received for an IRQ that was never registered + * with the system. + * + ****************************************************************************/ + int irq_unexpected_isr(int irq, FAR void *context); #undef EXTERN diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index c3467abfbb..efd0f2f7be 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -39,7 +39,6 @@ #include -#include #include #include @@ -120,15 +119,12 @@ irqstate_t enter_critical_section(void) * We must avoid that case where a context occurs between taking the * g_cpu_irqlock and disabling interrupts. Also interrupts disables * must follow a stacked order. We cannot other context switches to - * re-order the enabling/disabling of interrupts. We can both by - * locking the scheduler while interrupts are disabled. + * re-order the enabling/disabling of interrupts. * - * NOTE: that sched_lock() also uses a spinlock. We will avoid - * deadlocks by assuring that the scheduler spinlock is always - * taken before the IRQ spinlock. + * The scheduler accomplishes this by treating the irqcount like + * lockcount: Both will disable pre-emption. */ - sched_lock(); spin_lock(&g_cpu_irqlock); rtcb->irqcount = 1; @@ -174,22 +170,23 @@ void leave_critical_section(irqstate_t flags) } else { - /* NO.. Release the spinlock to allow other access. + /* Release any ready-to-run tasks that have collected in + * g_pendingtasks if the scheduler is not locked. * - * REVISIT: There is a cornercase where multiple CPUs may think - * they are the holder of the IRQ spinlock. We will need to disable - * the scheduler to assure that the following operation is atomic - * Hmmm... but that could cause a deadlock! What to do? Perhaps - * an array of booleans instead of a bitset? + * NOTE: This operation has a very high likelihood of causing + * this task to be switched out! */ + if (g_pendingtasks.head != NULL && rtcb->lockcount <= 0) + { + up_release_pending(); + } + + /* NO.. Release the spinlock to allow other access. */ + g_cpu_irqset &= ~(1 << this_cpu()); rtcb->irqcount = 0; spin_unlock(g_cpu_irqlock); - - /* And re-enable pre-emption */ - - sched_unlock(); } /* Restore the previous interrupt state which may still be interrupts diff --git a/sched/irq/irq_unexpectedisr.c b/sched/irq/irq_unexpectedisr.c index 490a6251e1..191d0a2194 100644 --- a/sched/irq/irq_unexpectedisr.c +++ b/sched/irq/irq_unexpectedisr.c @@ -45,26 +45,6 @@ #include "irq/irq.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 5a0cac5c9d..2ccc5d723b 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -86,10 +86,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) /* Check if pre-emption is disabled for the current running task and if * the new ready-to-run task would cause the current running task to be - * pre-empted. + * pre-empted. NOTE that IRQs disabled implies that pre-emption is + * also disabled. */ - if (rtcb->lockcount && rtcb->sched_priority < btcb->sched_priority) + if ((rtcb->lockcount > 0 || rtcb->irqcount > 0) && + rtcb->sched_priority < btcb->sched_priority) { /* Yes. Preemption would occur! Add the new ready-to-run task to the * g_pendingtasks task list for now. @@ -112,7 +114,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * is now the new active task! */ - ASSERT(!rtcb->lockcount && btcb->flink != NULL); + ASSERT(rtcb->lockcount == 0 && btcb->flink != NULL); btcb->task_state = TSTATE_TASK_RUNNING; btcb->flink->task_state = TSTATE_TASK_READYTORUN; diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 602ed81761..f8d7f79f71 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -73,11 +73,7 @@ int sched_unlock(void) if (rtcb && !up_interrupt_context()) { - /* Prevent context switches throughout the following. - * - * REVISIT: This is awkward. In the SMP case, enter_critical_section - * increments the lockcount! - */ + /* Prevent context switches throughout the following. */ irqstate_t flags = enter_critical_section(); @@ -99,9 +95,6 @@ int sched_unlock(void) #ifdef CONFIG_SMP /* The lockcount has decremented to zero and we need to perform * release our hold on the lock. - * - * REVISIT: It might be possible for two CPUs to hold the logic in - * some strange cornercases like: */ DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && @@ -115,10 +108,18 @@ int sched_unlock(void) #endif /* Release any ready-to-run tasks that have collected in - * g_pendingtasks. + * g_pendingtasks. In the SMP case, the scheduler remains + * locked if interrupts are disabled. + * + * NOTE: This operation has a very high likelihood of causing + * this task to be switched out! */ - if (g_pendingtasks.head) +#ifdef CONFIG_SMP + if (g_pendingtasks.head != NULL) +#else + if (g_pendingtasks.head != NULL && rtcb->irqcount <= 0) +#endif { up_release_pending(); } diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index a8de026ca8..ed67101bd6 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -131,7 +131,7 @@ int task_exit(void) * task list now */ - if (g_pendingtasks.head) + if (g_pendingtasks.head != NULL) { (void)sched_mergepending(); } -- GitLab From 83999381387a1f96afbfa8cd42d093169912b7a5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 10:15:07 -0600 Subject: [PATCH 738/858] SMP: I think we have to spinlock before we are possibly suspended --- sched/irq/irq_csection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index efd0f2f7be..a62b08f684 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -170,6 +170,12 @@ void leave_critical_section(irqstate_t flags) } else { + /* NO.. Release the spinlock to allow other access. */ + + g_cpu_irqset &= ~(1 << this_cpu()); + rtcb->irqcount = 0; + spin_unlock(g_cpu_irqlock); + /* Release any ready-to-run tasks that have collected in * g_pendingtasks if the scheduler is not locked. * @@ -181,12 +187,6 @@ void leave_critical_section(irqstate_t flags) { up_release_pending(); } - - /* NO.. Release the spinlock to allow other access. */ - - g_cpu_irqset &= ~(1 << this_cpu()); - rtcb->irqcount = 0; - spin_unlock(g_cpu_irqlock); } /* Restore the previous interrupt state which may still be interrupts -- GitLab From 8ea1bc318846b0ce9c969a767aa800080155d31c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 11:06:54 -0600 Subject: [PATCH 739/858] SMP: Fix backward spinlock test --- include/nuttx/spinlock.h | 6 +++--- sched/sched/sched_removereadytorun.c | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index ad034fa650..080f73d4c3 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -227,7 +227,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); * Name: spin_islocked * * Description: - * Release one count on a renonentrant spinlock. + * Release one count on a non-reentrant spinlock. * * Input Parameters: * lock - A reference to the spinlock object to test. @@ -238,7 +238,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); ****************************************************************************/ /* bool spin_islocked(FAR spinlock_t lock); */ -#define spin_islocked(l) ((l) == SP_UNLOCKED) +#define spin_islocked(l) ((l) == SP_LOCKED) /**************************************************************************** * Name: spin_islockedr @@ -255,7 +255,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); ****************************************************************************/ /* bool spin_islockedr(FAR struct spinlock_s *lock); */ -#define spin_islockedr(l) ((l)->sp_lock == SP_UNLOCKED) +#define spin_islockedr(l) ((l)->sp_lock == SP_LOCKED) #endif /* CONFIG_SPINLOCK */ #endif /* __INCLUDE_NUTTX_SPINLOCK_H */ diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index a844af73d7..847b40f73b 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -74,7 +74,6 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { - FAR struct tcb_s *ntcb = NULL; FAR dq_queue_t *tasklist; bool ret = false; @@ -94,19 +93,19 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) * occur. */ - if (!rtcb->blink || TLIST_ISRUNNABLE(rtcb->task_state)) + if (rtcb->blink == NULL && TLIST_ISRUNNABLE(rtcb->task_state)) #else /* There is only one list, g_readytorun, and it always contains the * currently running task. If we are removing the head of this list, * then we are removing the currently active task. */ - if (!rtcb->blink) + if (rtcb->blink == NULL) #endif { /* There must always be at least one task in the list (the idle task) */ - ntcb = (FAR struct tcb_s *)rtcb->flink; + FAR struct tcb_s *ntcb = (FAR struct tcb_s *)rtcb->flink; DEBUGASSERT(ntcb != NULL); #ifdef CONFIG_SMP -- GitLab From fc842d740addda36246e1d400785c11ee20ec15f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 11:07:42 -0600 Subject: [PATCH 740/858] SMP: os_start needs to hold the KMM semaphore to prevent threads from allocating memory until the bring-up is complete --- sched/init/os_start.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sched/init/os_start.c b/sched/init/os_start.c index fc2066e620..e99331b6e6 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -726,7 +726,18 @@ void os_start(void) #ifdef CONFIG_SMP /* Start all CPUs *********************************************************/ + /* A few basic sanity checks */ + DEBUGASSERT(this_cpu() == 0 && CONFIG_MAX_TASKS > CONFIG_SMP_NCPUS); + + /* Take the memory manager semaphore on this CPU so that it will not be + * available on the other CPUs until we have finished initialization. + */ + + DEBUGVERIFY(kmm_trysemaphore()); + + /* Then start the other CPUs */ + DEBUGVERIFY(os_smpstart()); #endif /* CONFIG_SMP */ @@ -740,6 +751,13 @@ void os_start(void) DEBUGVERIFY(os_bringup()); +#ifdef CONFIG_SMP + /* Let other threads have access to the memory manager */ + + kmm_givesemaphore(); + +#endif /* CONFIG_SMP */ + /* The IDLE Loop **********************************************************/ /* When control is return to this point, the system is idle. */ -- GitLab From cfcd98ca8978c84eabb219cebe3d8e752374da49 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 11:45:34 -0600 Subject: [PATCH 741/858] SMP: Used wrong point to wrong TCB --- arch | 2 +- sched/sched/sched_addreadytorun.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 839a04f989..414b1da6b1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 839a04f989000895820af4691d9596fc4385f48b +Subproject commit 414b1da6b18e57ec4119c0a70f84e7c635243717 diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2ccc5d723b..d80ab456cb 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -171,7 +171,6 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) bool sched_addreadytorun(FAR struct tcb_s *btcb) { FAR struct tcb_s *rtcb; - FAR struct tcb_s *next; FAR dq_queue_t *tasklist; int task_state; int cpu; @@ -305,7 +304,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * and check if a context switch will occur */ - tasklist = (FAR dq_queue_t *)g_assignedtasks[cpu].head; + tasklist = (FAR dq_queue_t *)&g_assignedtasks[cpu]; switched = sched_addprioritized(btcb, tasklist); /* If the selected task was the g_assignedtasks[] list, then a context @@ -314,6 +313,8 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (switched) { + FAR struct tcb_s *next; + /* The new btcb was added at the head of the ready-to-run list. It * is now the new active task! * @@ -375,7 +376,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) next = (FAR struct tcb_s *)btcb->flink; ASSERT(!rtcb->lockcount && next != NULL); - if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + if ((next->flags & TCB_FLAG_CPU_ASSIGNED) != 0) { next->task_state = TSTATE_TASK_ASSIGNED; } @@ -390,7 +391,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) */ next->task_state = TSTATE_TASK_READYTORUN; - (void)sched_addprioritized(btcb, + (void)sched_addprioritized(next, (FAR dq_queue_t *)&g_readytorun); } -- GitLab From fccef49305b38bbbfe0e8c221e4dc933daf2a021 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 13:48:08 -0600 Subject: [PATCH 742/858] Cosmetic changes to comments --- arch | 2 +- configs | 2 +- mm/mm_heap/mm_sem.c | 5 ----- sched/irq/irq_csection.c | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch b/arch index 414b1da6b1..88ef94c7b3 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 414b1da6b18e57ec4119c0a70f84e7c635243717 +Subproject commit 88ef94c7b32a793e11a7d0eb75b0f6c839a59a91 diff --git a/configs b/configs index 904067c60c..ebc3a71916 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 904067c60cb19341e9f806710f7f8c20301a33e8 +Subproject commit ebc3a719168c1e7524a64498cd6d9312f26d36b0 diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index 6a38f9b5a7..ae00b0b80f 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -67,10 +67,6 @@ # endif #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -220,4 +216,3 @@ void mm_givesemaphore(FAR struct mm_heap_s *heap) ASSERT(sem_post(&heap->mm_semaphore) == 0); } } - diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index a62b08f684..265236b464 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/irq/irq_csection.c * - * Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without -- GitLab From 8774e7a4a055a12eea008e31d32bdf92dcfb6a95 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 15 Feb 2016 18:35:05 -0600 Subject: [PATCH 743/858] SMP: Fix missing initialization value --- sched/init/os_start.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sched/init/os_start.c b/sched/init/os_start.c index e99331b6e6..af5dc3f78e 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -429,6 +429,7 @@ void os_start(void) */ bzero((void *)&g_idletcb[cpu], sizeof(struct task_tcb_s)); + g_idletcb[cpu].cmn.pid = g_lastpid; g_idletcb[cpu].cmn.task_state = TSTATE_TASK_RUNNING; /* Set the entry point. This is only for debug purposes. NOTE: that -- GitLab From 55d33fd9128d4930390f6fbb96a6d21d25637b52 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 07:50:18 -0600 Subject: [PATCH 744/858] Update some comments --- arch | 2 +- include/nuttx/arch.h | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch b/arch index 88ef94c7b3..8012d549ae 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 88ef94c7b32a793e11a7d0eb75b0f6c839a59a91 +Subproject commit 8012d549ae583abf8e6d902a42fe6e1a534bb2a5 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index bec1aab8e1..c50c598fe6 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1690,9 +1690,13 @@ int up_cpundx(void); * initialization of the OS, just before beginning normal multitasking, * the additional CPUs would be started by calling this function. * - * Each CPU is provided the entry point to is IDLE task when started. The - * OS initialization logic calls this function repeatedly until each CPU - * has been started. + * Each CPU is provided the entry point to is IDLE task when started. A + * TCB for each CPU's IDLE task has been initialized and placed in the + * CPU's g_assignedtasks[cpu] list. Not stack has been alloced or + * initialized. + * + * The OS initialization logic calls this function repeatedly until each + * CPU has been started, 1 through (CONFIG_SMP_NCPUS-1). * * Input Parameters: * cpu - The index of the CPU being started. This will be a numeric -- GitLab From a442245479d2d387ecdc7ac7608c03bf7efff39a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 10:14:33 -0600 Subject: [PATCH 745/858] SMP: Fix some non-SMP errors that crept in; fix a recursion problem; re-partition some functionality to improve design and readability --- arch | 2 +- sched/sched/Make.defs | 4 + sched/sched/sched.h | 3 + sched/sched/sched_addreadytorun.c | 43 +---- sched/sched/sched_cpuselect.c | 110 ++++++++++++ sched/sched/sched_reprioritize.c | 24 --- sched/sched/sched_setpriority.c | 289 +++++++++++++++++++++--------- sched/sched/sched_unlock.c | 4 +- sched/semaphore/spinlock.c | 2 + 9 files changed, 327 insertions(+), 154 deletions(-) create mode 100644 sched/sched/sched_cpuselect.c diff --git a/arch b/arch index 8012d549ae..790c6be472 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 8012d549ae583abf8e6d902a42fe6e1a534bb2a5 +Subproject commit 790c6be472dd5c386723e5b54bef495300ad6d7d diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index 65710efdd2..3c521a25d7 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -47,6 +47,10 @@ ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) CSRCS += sched_reprioritize.c endif +ifeq ($(CONFIG_SMP),y) +CSRCS += sched_cpuselect.c +endif + ifeq ($(CONFIG_SCHED_WAITPID),y) CSRCS += sched_waitpid.c ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) diff --git a/sched/sched/sched.h b/sched/sched/sched.h index ecdc74a4ec..61ff5fd64b 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -422,9 +422,12 @@ void sched_sporadic_lowpriority(FAR struct tcb_s *tcb); #endif #ifdef CONFIG_SMP +int sched_cpu_select(void); # define sched_islocked(tcb) spin_islocked(g_cpu_schedlock) #else # define sched_islocked(tcb) ((tcb)->lockcount > 0) +# define sched_cpu_select (0) + #endif /* CPU load measurement support */ diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index d80ab456cb..2157e01ea0 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -90,8 +90,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * also disabled. */ - if ((rtcb->lockcount > 0 || rtcb->irqcount > 0) && - rtcb->sched_priority < btcb->sched_priority) + if (rtcb->lockcount > 0 && rtcb->sched_priority < btcb->sched_priority) { /* Yes. Preemption would occur! Add the new ready-to-run task to the * g_pendingtasks task list for now. @@ -184,51 +183,19 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) /* Yes.. that that is the CPU we must use */ cpu = btcb->cpu; - rtcb = (FAR struct tcb_s *)g_assignedtasks[cpu].head; } else { - uint8_t minprio; - int i; - /* Otherwise, find the CPU that is executing the lowest priority task * (possibly its IDLE task). */ - rtcb = NULL; - minprio = SCHED_PRIORITY_MAX; - cpu = 0; - - for (i = 0; i < CONFIG_SMP_NCPUS; i++) - { - FAR struct tcb_s *candidate = - (FAR struct tcb_s *)g_assignedtasks[i].head; - - /* If this thread is executing its IDLE task, the use it. The - * IDLE task is always the last task in the assigned task list. - */ - - if (candidate->flink == NULL) - { - /* The IDLE task should always be assigned to this CPU and - * have a priority of zero. - */ - - DEBUGASSERT(candidate->sched_priority == 0); + cpu = sched_cpu_select(); + } - rtcb = candidate; - cpu = i; - break; - } - else if (candidate->sched_priority < minprio) - { - DEBUGASSERT(candidate->sched_priority > 0); + /* Get the task currently running on the CPU (maybe the IDLE task) */ - rtcb = candidate; - cpu = i; - } - } - } + rtcb = (FAR struct tcb_s *)g_assignedtasks[cpu].head; /* Determine the desired new task state. First, if the new task priority * is higher then the priority of the lowest priority, running task, then diff --git a/sched/sched/sched_cpuselect.c b/sched/sched/sched_cpuselect.c new file mode 100644 index 0000000000..2ca906ff38 --- /dev/null +++ b/sched/sched/sched_cpuselect.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * sched/sched/sched_cpuselect.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "sched/sched.h" + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_cpu_select + * + * Description: + * Return the index to the CPU with the lowest priority running task, + * possbily its IDLE task. + * + * Inputs: + * None + * + * Return Value: + * Index of the CPU with the lowest priority running task + * + ****************************************************************************/ + +static int sched_cpu_select(void) +{ + uint8_t minprio; + int cpu; + int i; + + /* Otherwise, find the CPU that is executing the lowest priority task + * (possibly its IDLE task). + */ + + minprio = SCHED_PRIORITY_MAX; + cpu = 0; + + for (i = 0; i < CONFIG_SMP_NCPUS; i++) + { + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_assignedtasks[i].head; + + /* If this thread is executing its IDLE task, the use it. The IDLE + * task is always the last task in the assigned task list. + */ + + if (rtcb->flink == NULL) + { + /* The IDLE task should always be assigned to this CPU and have + * a priority of zero. + */ + + DEBUGASSERT(rtcb->sched_priority == 0); + return i; + } + else if (rtcb->sched_priority < minprio) + { + DEBUGASSERT(rtcb->sched_priority > 0); + cpu = i; + } + } + + return cpu; +} + +#endif /* CONFIG_SMP */ diff --git a/sched/sched/sched_reprioritize.c b/sched/sched/sched_reprioritize.c index b9bff17f36..d9431cf165 100644 --- a/sched/sched/sched_reprioritize.c +++ b/sched/sched/sched_reprioritize.c @@ -47,30 +47,6 @@ #ifdef CONFIG_PRIORITY_INHERITANCE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 275de2426e..2661edcf71 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -48,6 +48,197 @@ #include "sched/sched.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_running_setpriority + * + * Description: + * This function sets the priority of a running task. This does nothing + * if we are increasing the priority of a running task. If we are dropping + * the priority of a running task, then this could cause then next lower + * priority task to run, + * + * NOTE: Setting a task's priority to the same value has a similar effect + * to sched_yield() -- The task will be moved to after all other tasks + * with the same priority. + * + * Inputs: + * tcb - the TCB of task to reprioritize. + * sched_priority - The new task priority + * + * Return Value: + * None + * + ****************************************************************************/ + +static inline void sched_running_setpriority(FAR struct tcb_s *tcb, + int sched_priority) +{ + /* A context switch will occur if the new priority of the running + * task becomes less than OR EQUAL TO the next highest priority + * ready to run task. + */ + + if (sched_priority <= tcb->flink->sched_priority) + { + /* A context switch will occur. */ + + up_reprioritize_rtr(tcb, (uint8_t)sched_priority); + } + + /* Otherwise, we can just change priority since it has no effect */ + + else + { + /* Change the task priority */ + + tcb->sched_priority = (uint8_t)sched_priority; + } +} + +/**************************************************************************** + * Name: sched_readytorun_setpriority + * + * Description: + * This function sets the priority of a ready-to-run task. This may alter + * the position of the task in the ready-to-run list and if the priority + * is increased, may cause the task to become running. + * + * Inputs: + * tcb - the TCB of task to reprioritize. + * sched_priority - The new task priority + * + * Return Value: + * None + * + ****************************************************************************/ + +static void sched_readytorun_setpriority(FAR struct tcb_s *tcb, + int sched_priority) +{ + FAR struct tcb_s *rtcb; + +#ifdef CONFIG_SMP + int cpu; + + /* CASE 2a. The task is ready-to-run (but not running) but not assigned to + * a CPU. An increase in priority could cause a context switch may be caused + * by the re-prioritization. The task is not assigned and may run on any CPU. + */ + + if (tcb->task_state == TSTATE_TASK_READYTORUN) + { + cpu = sched_cpu_select(); + } + + /* CASE 2b. The task is ready to run, and assigned to a CPU. An increase + * in priority could cause this task to become running but the task can + * only run on its assigned CPU. + */ + + else + { + cpu = tcb->cpu; + } + + /* The running task is the the task at the head of the g_assignedtasks[] + * associated with the selected CPU. + */ + + rtcb = current_task(cpu); + +#else + /* CASE 2. The task is ready-to-run (but not running) and a context switch + * may be caused by the re-prioritization. + */ + + rtcb = this_task(); +#endif + + /* A context switch will occur if the new priority of the ready-to-run + * task is (strictly) greater than the current running task + */ + + if (sched_priority > rtcb->sched_priority) + { + /* A context switch will occur. */ + + up_reprioritize_rtr(tcb, (uint8_t)sched_priority); + } + + /* Otherwise, we can just change priority and re-schedule (since it have + * no other effect). + */ + + else + { + /* Remove the TCB from the ready-to-run task list that it resides in */ + + ASSERT(!sched_removereadytorun(tcb)); + + /* Change the task priority */ + + tcb->sched_priority = (uint8_t)sched_priority; + + /* Put it back into the correct ready-to-run task list */ + + DEBUGASSERT(!sched_addreadytorun(tcb)); + } +} + +/**************************************************************************** + * Name: sched_blocked_setpriority + * + * Description: + * Change the priority of a blocked tasks. The only issue here is that + * the task may like in a prioritized or an non-prioritized queue. + * + * Inputs: + * tcb - the TCB of task to reprioritize. + * sched_priority - The new task priority + * + * Return Value: + * None + * + ****************************************************************************/ + +static inline void sched_blocked_setpriority(FAR struct tcb_s *tcb, + int sched_priority) +{ + FAR dq_queue_t *tasklist; + tstate_t task_state = tcb->task_state; + + /* CASE 3a. The task resides in a prioritized list. */ + + tasklist = TLIST_BLOCKED(task_state); + if (TLIST_ISPRIORITIZED(task_state)) + { + /* Remove the TCB from the prioritized task list */ + + dq_rem((FAR dq_entry_t *)tcb, tasklist); + + /* Change the task priority */ + + tcb->sched_priority = (uint8_t)sched_priority; + + /* Put it back into the prioritized list at the correct position. */ + + sched_addprioritized(tcb, tasklist); + } + + /* CASE 3b. The task resides in a non-prioritized list. */ + + else + { + /* Just change the task's priority */ + + tcb->sched_priority = (uint8_t)sched_priority; + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -59,7 +250,7 @@ * This function sets the priority of a specified task. * * NOTE: Setting a task's priority to the same value has a similar effect - * to sched_yield() -- The task will be moved to after all other tasks + * to sched_yield() -- The task will be moved to after all other tasks * with the same priority. * * Inputs: @@ -81,9 +272,6 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) { - FAR struct tcb_s *rtcb = this_task(); - FAR dq_queue_t *tasklist; - tstate_t task_state; irqstate_t flags; /* Verify that the requested priority is in the valid range */ @@ -101,37 +289,16 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) flags = enter_critical_section(); - /* There are four cases that must be considered: */ + /* There are three major cases (and two sub-cases) that must be considered: */ - task_state = tcb->task_state; - switch (task_state) + switch (tcb->task_state) { - /* CASE 1. The task is and a context switch may be caused by the - * re-prioritization + /* CASE 1. The task is running and a context switch may be caused by + * the re-prioritization */ case TSTATE_TASK_RUNNING: - - /* A context switch will occur if the new priority of the running - * task becomes less than OR EQUAL TO the next highest priority - * ready to run task. - */ - - if (sched_priority <= tcb->flink->sched_priority) - { - /* A context switch will occur. */ - - up_reprioritize_rtr(tcb, (uint8_t)sched_priority); - } - - /* Otherwise, we can just change priority since it has no effect */ - - else - { - /* Change the task priority */ - - tcb->sched_priority = (uint8_t)sched_priority; - } + sched_running_setpriority(tcb, sched_priority); break; /* CASE 2. The task is ready-to-run (but not running) and a context @@ -142,72 +309,16 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) #ifdef CONFIG_SMP case TSTATE_TASK_ASSIGNED: #endif - - /* A context switch will occur if the new priority of the ready-to - * run task is (strictly) greater than the current running task - */ - - if (sched_priority > rtcb->sched_priority) - { - /* A context switch will occur. */ - - up_reprioritize_rtr(tcb, (uint8_t)sched_priority); - } - - /* Otherwise, we can just change priority and re-schedule (since it - * have no other effect). - */ - - else - { - /* Remove the TCB from the ready-to-run task list */ - - ASSERT(!sched_removereadytorun(tcb)); - - /* Change the task priority */ - - tcb->sched_priority = (uint8_t)sched_priority; - - /* Put it back into the ready-to-run task list */ - - DEBUGASSERT(!sched_addreadytorun(tcb)); - } + sched_readytorun_setpriority(tcb, sched_priority); break; + /* CASE 3. The task is not in the ready to run list. Changing its * Priority cannot effect the currently executing task. */ default: - - /* CASE 3a. The task resides in a prioritized list. */ - - tasklist = TLIST_BLOCKED(task_state); - if (TLIST_ISPRIORITIZED(task_state)) - { - /* Remove the TCB from the prioritized task list */ - - dq_rem((FAR dq_entry_t *)tcb, tasklist); - - /* Change the task priority */ - - tcb->sched_priority = (uint8_t)sched_priority; - - /* Put it back into the prioritized list at the correct - * position - */ - - sched_addprioritized(tcb, tasklist); - } - - /* CASE 3b. The task resides in a non-prioritized list. */ - - else - { - /* Just change the task's priority */ - - tcb->sched_priority = (uint8_t)sched_priority; - } + sched_blocked_setpriority(tcb, sched_priority); break; } diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index f8d7f79f71..2c12f98f4d 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -116,9 +116,9 @@ int sched_unlock(void) */ #ifdef CONFIG_SMP - if (g_pendingtasks.head != NULL) -#else if (g_pendingtasks.head != NULL && rtcb->irqcount <= 0) +#else + if (g_pendingtasks.head != NULL) #endif { up_release_pending(); diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index 2b6c56f052..e97f4a012f 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -120,7 +120,9 @@ void spin_lock(FAR volatile spinlock_t *lock) { while (up_testset(lock) == SP_LOCKED) { +#if 0 /* Would recurse */ sched_yield(); +#endif } } -- GitLab From 7f18b515f453382ed79c005a0178c43c010e857d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 10:40:25 -0600 Subject: [PATCH 746/858] SMP: Fix a typo in last commit --- sched/sched/sched_cpuselect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sched/sched/sched_cpuselect.c b/sched/sched/sched_cpuselect.c index 2ca906ff38..7bebc89424 100644 --- a/sched/sched/sched_cpuselect.c +++ b/sched/sched/sched_cpuselect.c @@ -65,9 +65,12 @@ * Return Value: * Index of the CPU with the lowest priority running task * + * Assumptions: + * Called from within a critical section. + * ****************************************************************************/ -static int sched_cpu_select(void) +int sched_cpu_select(void) { uint8_t minprio; int cpu; -- GitLab From 384e51cb05621a66780059e5ada36f5789b7a01f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 15:21:45 -0600 Subject: [PATCH 747/858] Add some additional schedule instrumentation --- arch | 2 +- include/sched.h | 24 +++++++++++++++++++----- libc/stdio/lib_printf.c | 37 ------------------------------------- sched/Kconfig | 28 +++++++++++++++++++++++++--- sched/irq/irq_csection.c | 13 ++++++++++++- sched/sched/sched_lock.c | 11 +++++++++++ sched/sched/sched_unlock.c | 7 +++++++ 7 files changed, 75 insertions(+), 47 deletions(-) diff --git a/arch b/arch index 790c6be472..bceb7b7852 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 790c6be472dd5c386723e5b54bef495300ad6d7d +Subproject commit bceb7b7852a855d0de9afc4caeee801b4349db8e diff --git a/include/sched.h b/include/sched.h index 4fe16542d6..f3b675da72 100644 --- a/include/sched.h +++ b/include/sched.h @@ -145,13 +145,27 @@ int sched_lockcount(void); void sched_note_start(FAR struct tcb_s *tcb); void sched_note_stop(FAR struct tcb_s *tcb); -void sched_note_switch(FAR struct tcb_s *pFromTcb, - FAR struct tcb_s *pToTcb); +void sched_note_switch(FAR struct tcb_s *fromtcb, + FAR struct tcb_s *totcb); +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +void sched_note_premption(FAR struct tcb_s *tcb, bool locked); #else -# define sched_note_start(t) -# define sched_note_stop(t) -# define sched_note_switch(t1, t2) +# define sched_note_premption(t,l) +#endif + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +void sched_note_csection(FAR struct tcb_s *tcb, bool enter); +#else +# define sched_note_csection(t,e) +#endif + +#else +# define sched_note_start(t) +# define sched_note_stop(t) +# define sched_note_switch(t1, t2) +# define sched_note_premption(t,l) +# define sched_note_csection(t,e) #endif /* CONFIG_SCHED_INSTRUMENTATION */ #undef EXTERN diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index 7088452393..5f1096a3a2 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -33,10 +33,6 @@ * ****************************************************************************/ -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - /**************************************************************************** * Included Files ****************************************************************************/ @@ -46,38 +42,6 @@ #include "libc.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -108,4 +72,3 @@ int printf(FAR const IPTR char *fmt, ...) return ret; } - diff --git a/sched/Kconfig b/sched/Kconfig index c30b672b1d..574223fd67 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -601,10 +601,32 @@ config SCHED_INSTRUMENTATION If enabled, then the board-specific logic must provide the following functions (see include/sched.h): - void sched_note_start(FAR struct tcb_s *tcb); - void sched_note_stop(FAR struct tcb_s *tcb); - void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb); + void sched_note_start(FAR struct tcb_s *tcb); + void sched_note_stop(FAR struct tcb_s *tcb); + void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb); +if SCHED_INSTRUMENTATION +config SCHED_INSTRUMENTATION_PREEMPTION + bool "Preemption monitor hooks + default n + ---help--- + Enables additional hooks for changes to pre-emption state. Board- + specific logic must provide this additional logic. + + void sched_note_premption(FAR struct tcb_s *tcb, bool state); + +config SCHED_INSTRUMENTATION_CSECTION + bool "Critical section monitor hooks + default n + depends on SMP + ---help--- + Enables additional hooks for entry and exit from critical sections. + Interrupts are disabled while within a critical section. Board- + specific logic must provide this additional logic. + + void sched_note_csection(FAR struct tcb_s *tcb, bool state); + +endif # SCHED_INSTRUMENTATION endmenu # Performance Monitoring menu "Files and I/O" diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index 265236b464..34e77f3b1c 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -129,6 +129,12 @@ irqstate_t enter_critical_section(void) rtcb->irqcount = 1; g_cpu_irqset |= (1 << this_cpu()); + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + /* Note that we have entered the critical section */ + + sched_note_csection(rtcb, true); +#endif } /* Then disable interrupts (they may already be disabled, be we need to @@ -170,7 +176,12 @@ void leave_critical_section(irqstate_t flags) } else { - /* NO.. Release the spinlock to allow other access. */ +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + /* No.. Note that we have entered the critical section */ + + sched_note_csection(rtcb, false); +#endif + /* Release the spinlock to allow other access. */ g_cpu_irqset &= ~(1 << this_cpu()); rtcb->irqcount = 0; diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index c524cdd8cc..025b0bf035 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -201,6 +201,17 @@ int sched_lock(void) */ rtcb->lockcount++; + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + /* Check if we just acquired the lock */ + + if (rtcb->lockcount == 1) + { + /* Note that we have pre-emption locked */ + + sched_note_premption(rtcb, true); + } +#endif } return OK; diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 2c12f98f4d..35d9afd5fb 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -90,6 +90,13 @@ int sched_unlock(void) if (rtcb->lockcount <= 0) { +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + /* Note that we no longer have pre-emption */ + + sched_note_premption(rtcb, false); +#endif + /* Set the lock count to zero */ + rtcb->lockcount = 0; #ifdef CONFIG_SMP -- GitLab From 6dfa72d038302d6edc9afed13f833d4cd9337519 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 16:43:19 -0600 Subject: [PATCH 748/858] SMP: Fix some dumb but difficult to debug errors --- arch | 2 +- sched/init/os_start.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch b/arch index bceb7b7852..17b239501e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bceb7b7852a855d0de9afc4caeee801b4349db8e +Subproject commit 17b239501e1b11ae065586efe31f2c4e8ffd4122 diff --git a/sched/init/os_start.c b/sched/init/os_start.c index af5dc3f78e..93379dde4d 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -418,8 +418,8 @@ void os_start(void) /* Assign the process ID(s) of ZERO to the idle task(s) */ - g_pidhash[PIDHASH(0)].tcb = &g_idletcb[cpu].cmn; - g_pidhash[PIDHASH(0)].pid = g_lastpid; + g_pidhash[PIDHASH(g_lastpid)].tcb = &g_idletcb[cpu].cmn; + g_pidhash[PIDHASH(g_lastpid)].pid = g_lastpid; /* Initialize a TCB for this thread of execution. NOTE: The default * value for most components of the g_idletcb are zero. The entire @@ -444,11 +444,10 @@ void os_start(void) g_idletcb[cpu].cmn.entry.main = os_idletask; } else -#else +#endif { g_idletcb[cpu].cmn.entry.main = (main_t)os_start; } -#endif /* Set the task flags to indicate that this is a kernel thread and, if * configured for SMP, that this task is assigned to the correct CPU. -- GitLab From 6aeb4a52e827121faddc01470ff4293c40746a04 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 19:33:22 -0600 Subject: [PATCH 749/858] Performance improvement: Idle loop should not take MM semaphore if there is not garbage to be collected. This can cause loss of performance and thrashing in tasking --- include/nuttx/kmalloc.h | 18 ++++++-- sched/init/os_smpstart.c | 5 ++- sched/init/os_start.c | 10 +++-- sched/sched/sched_garbage.c | 79 ++++++++++++++++++++++++++++++++++- sched/wqueue/kwork_hpthread.c | 2 +- sched/wqueue/kwork_lpthread.c | 2 +- 6 files changed, 103 insertions(+), 13 deletions(-) diff --git a/include/nuttx/kmalloc.h b/include/nuttx/kmalloc.h index 162b9356db..4734a264f6 100644 --- a/include/nuttx/kmalloc.h +++ b/include/nuttx/kmalloc.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/kmalloc.h * - * Copyright (C) 2007-2008, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2011, 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -177,7 +177,7 @@ void group_free(FAR struct task_group_s *group, FAR void *mem); /* Handles memory freed from an interrupt handler. In that context, kmm_free() * (or kumm_free()) cannot be called. Instead, the allocations are saved in a * list of delayed allocations that will be periodically cleaned up by - * sched_garbagecollection(). + * sched_garbage_collection(). */ void sched_ufree(FAR void *address); @@ -196,7 +196,19 @@ void sched_kfree(FAR void *address); * the system for memory in some context. */ -void sched_garbagecollection(void); +void sched_garbage_collection(void); + +/* Is is not a good idea for the IDLE threads to take the KMM semaphore. + * That can cause the IDLE thread to take processing time from higher + * priority tasks. The IDLE threads will only take the KMM semaphore if + * there is garbage to be collected. + * + * Certainly there is a race condition involved in sampling the garbage + * state. The looping nature of the IDLE loops should catch any missed + * garbage from the test on the next time arround. + */ + +bool sched_have_garbage(void); #undef KMALLOC_EXTERN #if defined(__cplusplus) diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 03f3b0992d..29a3ae7c77 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -97,6 +97,7 @@ int os_idletask(int argc, FAR char *argv[]) /* Enter the IDLE loop */ sdbg("CPU%d: Beginning Idle Loop\n", this_cpu()); + for (; ; ) { /* Perform garbage collection (if it is not being done by the worker @@ -118,9 +119,9 @@ int os_idletask(int argc, FAR char *argv[]) * queue so that is done in a safer context. */ - if (kmm_trysemaphore() == 0) + if (sched_have_garbage() && kmm_trysemaphore() == 0) { - sched_garbagecollection(); + sched_garbage_collection(); kmm_givesemaphore(); } #endif diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 93379dde4d..b968bc8451 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -415,11 +415,13 @@ void os_start(void) #endif { FAR dq_queue_t *tasklist; + int hashndx; /* Assign the process ID(s) of ZERO to the idle task(s) */ - g_pidhash[PIDHASH(g_lastpid)].tcb = &g_idletcb[cpu].cmn; - g_pidhash[PIDHASH(g_lastpid)].pid = g_lastpid; + hashndx = PIDHASH(g_lastpid); + g_pidhash[hashndx].tcb = &g_idletcb[cpu].cmn; + g_pidhash[hashndx].pid = g_lastpid; /* Initialize a TCB for this thread of execution. NOTE: The default * value for most components of the g_idletcb are zero. The entire @@ -783,9 +785,9 @@ void os_start(void) * queue so that is done in a safer context. */ - if (kmm_trysemaphore() == 0) + if (sched_have_garbage() && kmm_trysemaphore() == 0) { - sched_garbagecollection(); + sched_garbage_collection(); kmm_givesemaphore(); } #endif diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index 878522f80b..ac6ef387da 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -104,6 +104,29 @@ static inline void sched_kucleanup(void) #endif } +/**************************************************************************** + * Name: sched_have_kugarbage + * + * Description: + * Return TRUE if there is user heap garbage to be collected. + * + * Input parameters: + * None + * + * Returned Value: + * TRUE if there is kernel heap garbage to be collected. + * + ****************************************************************************/ + +#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ + defined(CONFIG_MM_KERNEL_HEAP) +static inline bool sched_have_kugarbage(void) +{ + return (g_delayed_kufree.head != NULL); +#else +# define sched_have_kugarbage() false +#endif + /**************************************************************************** * Name: sched_kcleanup * @@ -155,11 +178,35 @@ static inline void sched_kcleanup(void) # define sched_kcleanup() #endif +/**************************************************************************** + * Name: sched_have_kgarbage + * + * Description: + * Return TRUE if there is kernal heap garbage to be collected. + * + * Input parameters: + * None + * + * Returned Value: + * TRUE if there is kernel heap garbage to be collected. + * + ****************************************************************************/ + +#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ + defined(CONFIG_MM_KERNEL_HEAP) +static inline bool sched_have_kgarbage(void) +{ + return (g_delayed_kfree.head != NULL); +#else +# define sched_have_kgarbage() false +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** - * Name: sched_garbagecollection + * Name: sched_garbage_collection * * Description: * Clean-up memory de-allocations that we queued because they could not @@ -180,7 +227,7 @@ static inline void sched_kcleanup(void) * ****************************************************************************/ -void sched_garbagecollection(void) +void sched_garbage_collection(void) { /* Handle deferred deallocations for the kernel heap */ @@ -190,3 +237,31 @@ void sched_garbagecollection(void) sched_kucleanup(); } + +/**************************************************************************** + * Name: sched_have_garbage + * + * Description: + * Return TRUE if there is garbage to be collected. + * + * Is is not a good idea for the IDLE threads to take the KMM semaphore. + * That can cause the IDLE thread to take processing time from higher + * priority tasks. The IDLE threads will only take the KMM semaphore if + * there is garbage to be collected. + * + * Certainly there is a race condition involved in sampling the garbage + * state. The looping nature of the IDLE loops should catch any missed + * garbage from the test on the next time arround. + * + * Input parameters: + * None + * + * Returned Value: + * TRUE if there is garbage to be collected. + * + ****************************************************************************/ + +bool sched_have_garbage(void) +{ + return (sched_have_kgarbage() || sched_have_kugarbage()); +} diff --git a/sched/wqueue/kwork_hpthread.c b/sched/wqueue/kwork_hpthread.c index 5a6b387999..fea380243c 100644 --- a/sched/wqueue/kwork_hpthread.c +++ b/sched/wqueue/kwork_hpthread.c @@ -120,7 +120,7 @@ static int work_hpthread(int argc, char *argv[]) * thread instead. */ - sched_garbagecollection(); + sched_garbage_collection(); #endif /* Then process queued work. work_process will not return until: (1) diff --git a/sched/wqueue/kwork_lpthread.c b/sched/wqueue/kwork_lpthread.c index eacbb6a265..fe4b5e847e 100644 --- a/sched/wqueue/kwork_lpthread.c +++ b/sched/wqueue/kwork_lpthread.c @@ -156,7 +156,7 @@ static int work_lpthread(int argc, char *argv[]) * the garbage collection. */ - sched_garbagecollection(); + sched_garbage_collection(); /* Then process queued work. work_process will not return until: * (1) there is no further work in the work queue, and (2) the polling -- GitLab From d6912d0b00d91e4c29765a643ae970971f843567 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Feb 2016 20:11:25 -0600 Subject: [PATCH 750/858] Fix some bad conditional compilation and other typos in last commit --- sched/sched/sched_garbage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index ac6ef387da..1fd3fbf050 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -118,11 +118,11 @@ static inline void sched_kucleanup(void) * ****************************************************************************/ -#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ - defined(CONFIG_MM_KERNEL_HEAP) +#ifndef CONFIG_BUILD_KERNEL static inline bool sched_have_kugarbage(void) { return (g_delayed_kufree.head != NULL); +} #else # define sched_have_kugarbage() false #endif @@ -197,6 +197,7 @@ static inline void sched_kcleanup(void) static inline bool sched_have_kgarbage(void) { return (g_delayed_kfree.head != NULL); +} #else # define sched_have_kgarbage() false #endif -- GitLab From 8ac12839c3c0c7b1f35562c8af8b8be391d9a99d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 10:55:18 -0600 Subject: [PATCH 751/858] leave_critical_section: Fix text of whether spinlock should be released or not --- configs | 2 +- sched/irq/irq_csection.c | 36 +++++++++++++++++++++---------- sched/sched/sched_addreadytorun.c | 4 ++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/configs b/configs index ebc3a71916..ff5400544e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ebc3a719168c1e7524a64498cd6d9312f26d36b0 +Subproject commit ff5400544e8ab499fcf20a1a88ebec05c9cbd2e9 diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index 34e77f3b1c..d8e671d977 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -181,22 +181,36 @@ void leave_critical_section(irqstate_t flags) sched_note_csection(rtcb, false); #endif - /* Release the spinlock to allow other access. */ + /* Decrement our count on the lock. If all CPUs have released, + * then unlock the spinlock. + */ - g_cpu_irqset &= ~(1 << this_cpu()); rtcb->irqcount = 0; - spin_unlock(g_cpu_irqlock); + g_cpu_irqset &= ~(1 << this_cpu()); - /* Release any ready-to-run tasks that have collected in - * g_pendingtasks if the scheduler is not locked. - * - * NOTE: This operation has a very high likelihood of causing - * this task to be switched out! - */ + /* Have all CPUs release the lock? */ - if (g_pendingtasks.head != NULL && rtcb->lockcount <= 0) + if (g_cpu_irqset == 0) { - up_release_pending(); + /* Unlock the IRQ spinlock */ + + spin_unlock(g_cpu_irqlock); + + /* Check if there are pending tasks and that pre-emption is + * also enabled. + */ + + if (g_pendingtasks.head != NULL && !spin_islocked(&g_cpu_schedlock)) + { + /* Release any ready-to-run tasks that have collected in + * g_pendingtasks if the scheduler is not locked. + * + * NOTE: This operation has a very high likelihood of causing + * this task to be switched out! + */ + + up_release_pending(); + } } } diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2157e01ea0..a0d1dc822c 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -113,7 +113,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * is now the new active task! */ - ASSERT(rtcb->lockcount == 0 && btcb->flink != NULL); + ASSERT(!spin_islocked(&g_cpu_schedlock) && btcb->flink != NULL); btcb->task_state = TSTATE_TASK_RUNNING; btcb->flink->task_state = TSTATE_TASK_READYTORUN; @@ -341,7 +341,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) */ next = (FAR struct tcb_s *)btcb->flink; - ASSERT(!rtcb->lockcount && next != NULL); + ASSERT(!spin_islocked(&g_cpu_schedlock) && next != NULL); if ((next->flags & TCB_FLAG_CPU_ASSIGNED) != 0) { -- GitLab From b50325bb381569dacf251b7f0edd97b206237ba4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 13:20:01 -0600 Subject: [PATCH 752/858] SMP: Add funtions to perform atomic bit set/clear operations; fix two errors in SMP macros --- configs | 2 +- include/nuttx/spinlock.h | 58 +++++++++++++++++++++- sched/irq/irq.h | 17 ++----- sched/irq/irq_csection.c | 31 ++++-------- sched/sched/sched.h | 15 ++---- sched/sched/sched_addreadytorun.c | 24 ++++------ sched/sched/sched_lock.c | 27 ++++------- sched/sched/sched_removereadytorun.c | 16 +++---- sched/sched/sched_unlock.c | 7 +-- sched/semaphore/spinlock.c | 72 ++++++++++++++++++++++++++++ sched/task/task_exit.c | 11 ++--- 11 files changed, 178 insertions(+), 102 deletions(-) diff --git a/configs b/configs index ff5400544e..af52276c2a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit ff5400544e8ab499fcf20a1a88ebec05c9cbd2e9 +Subproject commit af52276c2aa09944c1c2f158cdb05e7eb53c1659 diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 080f73d4c3..9fadbb3784 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -73,6 +73,18 @@ struct spinlock_s #endif }; +/* This is the smallest integer type that will not a bitset of all CPUs */ + +#if (CONFIG_SMP_NCPUS <= 8) +typedef volatile uint8_t cpuset_t; +#elif (CONFIG_SMP_NCPUS <= 16) +typedef volatile uint16_t cpuset_t; +#elif (CONFIG_SMP_NCPUS <= 32) +typedef volatile uint32_t cpuset_t; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -202,7 +214,7 @@ void spin_lockr(FAR struct spinlock_s *lock); ****************************************************************************/ /* void spin_unlock(FAR spinlock_t *lock); */ -#define spin_unlock(l) do { (l) = SP_UNLOCKED; } while (0) +#define spin_unlock(l) do { *(l) = SP_UNLOCKED; } while (0) /**************************************************************************** * Name: spin_unlockr @@ -238,7 +250,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); ****************************************************************************/ /* bool spin_islocked(FAR spinlock_t lock); */ -#define spin_islocked(l) ((l) == SP_LOCKED) +#define spin_islocked(l) (*(l) == SP_LOCKED) /**************************************************************************** * Name: spin_islockedr @@ -257,5 +269,47 @@ void spin_unlockr(FAR struct spinlock_s *lock); /* bool spin_islockedr(FAR struct spinlock_s *lock); */ #define spin_islockedr(l) ((l)->sp_lock == SP_LOCKED) +/**************************************************************************** + * Name: spin_setbit + * + * Description: + * Makes setting a CPU bit in a bitset an atomic action + * + * Input Parameters: + * set - A reference to the bitset to set the CPU bit in + * cpu - The bit number to be set + * setlock - A reference to the lock lock protecting the set + * orlock - Will be set to SP_LOCKED while holding setlock + * + * Returned Value: + * None + * + ****************************************************************************/ + +void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, + FAR volatile spinlock_t *setlock, + FAR volatile spinlock_t *orlock); + +/**************************************************************************** + * Name: spin_clrbit + * + * Description: + * Makes clearing a CPU bit in a bitset an atomic action + * + * Input Parameters: + * set - A reference to the bitset to set the CPU bit in + * cpu - The bit number to be set + * setlock - A reference to the lock lock protecting the set + * orlock - Will be set to SP_UNLOCKED if all bits become cleared in set + * + * Returned Value: + * None + * + ****************************************************************************/ + +void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, + FAR volatile spinlock_t *setlock, + FAR volatile spinlock_t *orlock); + #endif /* CONFIG_SPINLOCK */ #endif /* __INCLUDE_NUTTX_SPINLOCK_H */ diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 586f86904f..0e9357834c 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -63,21 +63,12 @@ extern FAR xcpt_t g_irqvector[NR_IRQS+1]; * disabled. */ -extern spinlock_t g_cpu_irqlock; +extern volatile spinlock_t g_cpu_irqlock; -/* Used to keep track of which CPU(s) hold the IRQ lock. There really should - * only be one. - */ +/* Used to keep track of which CPU(s) hold the IRQ lock. */ -#if (CONFIG_SMP_NCPUS <= 8) -volatile uint8_t g_cpu_irqset; -#elif (CONFIG_SMP_NCPUS <= 16) -volatile uint16_t g_cpu_irqset; -#elif (CONFIG_SMP_NCPUS <= 32) -volatile uint32_t g_cpu_irqset; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif +extern volatile spinlock_t g_cpu_irqsetlock; +extern volatile cpuset_t g_cpu_irqset; #endif /**************************************************************************** diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index d8e671d977..fedf44b906 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -54,21 +54,12 @@ * disabled. */ -spinlock_t g_cpu_irqlock = SP_UNLOCKED; +volatile spinlock_t g_cpu_irqlock = SP_UNLOCKED; -/* Used to keep track of which CPU(s) hold the IRQ lock. There really should - * only be one. - */ +/* Used to keep track of which CPU(s) hold the IRQ lock. */ -#if (CONFIG_SMP_NCPUS <= 8) -volatile uint8_t g_cpu_irqset; -#elif (CONFIG_SMP_NCPUS <= 16) -volatile uint16_t g_cpu_irqset; -#elif (CONFIG_SMP_NCPUS <= 32) -volatile uint32_t g_cpu_irqset; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif +volatile spinlock_t g_cpu_irqsetlock; +volatile cpuset_t g_cpu_irqset; /**************************************************************************** * Public Functions @@ -125,10 +116,9 @@ irqstate_t enter_critical_section(void) * lockcount: Both will disable pre-emption. */ - spin_lock(&g_cpu_irqlock); - + spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); rtcb->irqcount = 1; - g_cpu_irqset |= (1 << this_cpu()); #ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION /* Note that we have entered the critical section */ @@ -186,16 +176,13 @@ void leave_critical_section(irqstate_t flags) */ rtcb->irqcount = 0; - g_cpu_irqset &= ~(1 << this_cpu()); + spin_clrbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); /* Have all CPUs release the lock? */ - if (g_cpu_irqset == 0) + if (!spin_islocked(&g_cpu_irqlock)) { - /* Unlock the IRQ spinlock */ - - spin_unlock(g_cpu_irqlock); - /* Check if there are pending tasks and that pre-emption is * also enabled. */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 61ff5fd64b..dfb222514a 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -355,15 +355,10 @@ extern volatile uint32_t g_cpuload_total; extern volatile spinlock_t g_cpu_schedlock; -#if (CONFIG_SMP_NCPUS <= 8) -extern volatile uint8_t g_cpu_lockset; -#elif (CONFIG_SMP_NCPUS <= 16) -extern volatile uint16_t g_cpu_lockset; -#elif (CONFIG_SMP_NCPUS <= 32) -extern volatile uint32_t g_cpu_lockset; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif +/* Used to keep track of which CPU(s) hold the IRQ lock. */ + +extern volatile spinlock_t g_cpu_locksetlock; +extern volatile cpuset_t g_cpu_lockset; #endif /* CONFIG_SMP */ @@ -423,7 +418,7 @@ void sched_sporadic_lowpriority(FAR struct tcb_s *tcb); #ifdef CONFIG_SMP int sched_cpu_select(void); -# define sched_islocked(tcb) spin_islocked(g_cpu_schedlock) +# define sched_islocked(tcb) spin_islocked(&g_cpu_schedlock) #else # define sched_islocked(tcb) ((tcb)->lockcount > 0) # define sched_cpu_select (0) diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index a0d1dc822c..fc8fc9ca19 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -229,7 +229,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * start running the task. Be we cannot do that if pre-emption is disable. */ - if (spin_islocked(g_cpu_schedlock) && task_state == TSTATE_TASK_RUNNING) + if (spin_islocked(&g_cpu_schedlock) && task_state == TSTATE_TASK_RUNNING) { /* Preemption would occur! Add the new ready-to-run task to the * g_pendingtasks task list for now. @@ -304,16 +304,13 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->lockcount > 0) { - g_cpu_lockset |= (1 << cpu); - g_cpu_schedlock = SP_LOCKED; + spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } else { - g_cpu_lockset &= ~(1 << cpu); - if (g_cpu_lockset == 0) - { - g_cpu_schedlock = SP_UNLOCKED; - } + spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } /* Adjust global IRQ controls. If irqcount is greater than zero, @@ -322,16 +319,13 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->irqcount > 0) { - g_cpu_irqset |= (1 << cpu); - g_cpu_irqlock = SP_LOCKED; + spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); } else { - g_cpu_irqset &= ~(1 << cpu); - if (g_cpu_irqset == 0) - { - g_cpu_irqlock = SP_UNLOCKED; - } + spin_clrbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); } /* If the following task is not assigned to this CPU, then it must diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 025b0bf035..bf4bf86322 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -106,17 +106,12 @@ * least one CPU has pre-emption disabled. */ -volatile spinlock_t g_cpu_schedlock; - -#if (CONFIG_SMP_NCPUS <= 8) -volatile uint8_t g_cpu_lockset; -#elif (CONFIG_SMP_NCPUS <= 16) -volatile uint16_t g_cpu_lockset; -#elif (CONFIG_SMP_NCPUS <= 32) -volatile uint32_t g_cpu_lockset; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif +volatile spinlock_t g_cpu_schedlock = SP_UNLOCKED; + +/* Used to keep track of which CPU(s) hold the IRQ lock. */ + +volatile spinlock_t g_cpu_locksetlock; +volatile cpuset_t g_cpu_lockset; #endif /* CONFIG_SMP */ @@ -175,14 +170,8 @@ int sched_lock(void) * If the scheduler is locked on another CPU, then we for the lock. */ - spin_lock(&g_cpu_schedlock); - - /* Set a bit in g_cpu_lockset to indicate that this CPU holds the - * scheduler lock. This is mostly for debug purposes but should - * also handle few cornercases during context switching. - */ - - g_cpu_lockset |= (1 << this_cpu()); + spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } else { diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 847b40f73b..ab16d4e199 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -117,15 +117,15 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { /* Yes... make sure that scheduling logic knows about this */ - g_cpu_lockset |= (1 << this_cpu()); - g_cpu_schedlock = SP_LOCKED; + spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } else { /* No.. we may need to perform release our hold on the lock. */ - g_cpu_lockset &= ~(1 << this_cpu()); - g_cpu_schedlock = ((g_cpu_lockset == 0) ? SP_UNLOCKED : SP_LOCKED); + spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } /* Interrupts be disabled after the switch. If irqcount is greater @@ -136,15 +136,15 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { /* Yes... make sure that scheduling logic knows about this */ - g_cpu_irqset |= (1 << this_cpu()); - g_cpu_irqlock = SP_LOCKED; + spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); } else { /* No.. we may need to perform release our hold on the lock. */ - g_cpu_irqset &= ~(1 << this_cpu()); - g_cpu_irqlock = ((g_cpu_irqset == 0) ? SP_UNLOCKED : SP_LOCKED); + spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + &g_cpu_irqlock); } #endif diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 35d9afd5fb..e08fb4482a 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -107,11 +107,8 @@ int sched_unlock(void) DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && (g_cpu_lockset & (1 << this_cpu())) != 0); - g_cpu_lockset &= ~(1 << this_cpu()); - if (g_cpu_lockset == 0) - { - spin_unlock(g_cpu_schedlock); - } + spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); #endif /* Release any ready-to-run tasks that have collected in diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index e97f4a012f..38e7c23b26 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -295,4 +295,76 @@ void spin_unlockr(FAR struct spinlock_s *lock) #endif /* CONFIG_SMP */ } +/**************************************************************************** + * Name: spin_setbit + * + * Description: + * Makes setting a CPU bit in a bitset an atomic action + * + * Input Parameters: + * set - A reference to the bitset to set the CPU bit in + * cpu - The bit number to be set + * setlock - A reference to the lock lock protecting the set + * orlock - Will be set to SP_LOCKED while holding setlock + * + * Returned Value: + * None + * + ****************************************************************************/ + +void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, + FAR volatile spinlock_t *setlock, + FAR volatile spinlock_t *orlock) +{ + /* First, get the 'setlock' spinlock */ + + spin_lock(setlock); + + /* Then set the bit and mark the 'orlock' as locked */ + + *set |= (1 << cpu); + *orlock = SP_LOCKED; + + /* Release the 'setlock' */ + + spin_unlock(setlock); +} + +/**************************************************************************** + * Name: spin_clrbit + * + * Description: + * Makes clearing a CPU bit in a bitset an atomic action + * + * Input Parameters: + * set - A reference to the bitset to set the CPU bit in + * cpu - The bit number to be set + * setlock - A reference to the lock lock protecting the set + * orlock - Will be set to SP_UNLOCKED if all bits become cleared in set + * + * Returned Value: + * None + * + ****************************************************************************/ + +void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, + FAR volatile spinlock_t *setlock, + FAR volatile spinlock_t *orlock) +{ + /* First, get the 'setlock' spinlock */ + + spin_lock(setlock); + + /* Then clear the bit in the CPU set. Set/clear the 'orlock' depending + * upon the resulting state of the CPU set. + */ + + *set &= ~(1 << cpu); + *orlock = (*set != 0) ? SP_LOCKED : SP_UNLOCKED; + + /* Release the 'setlock' */ + + spin_unlock(setlock); +} + #endif /* CONFIG_SPINLOCK */ diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index ed67101bd6..964b1be8d0 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -111,8 +111,8 @@ int task_exit(void) #ifdef CONFIG_SMP /* Make sure that the system knows about the locked state */ - g_cpu_schedlock = SP_LOCKED; - g_cpu_lockset |= (1 << this_cpu()); + spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); #endif rtcb->task_state = TSTATE_TASK_READYTORUN; @@ -151,11 +151,8 @@ int task_exit(void) { /* Make sure that the system knows about the unlocked state */ - g_cpu_lockset &= ~(1 << this_cpu()); - if (g_cpu_lockset == 0) - { - g_cpu_schedlock = SP_UNLOCKED; - } + spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + &g_cpu_schedlock); } #endif -- GitLab From 95735519dd504ffe088e04a0fa4f2dd6e8156f5c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 13:36:25 -0600 Subject: [PATCH 753/858] SMP: Cosmetic renaming to clarify functionality of SMP interfaces. Update comments. --- arch | 2 +- configs | 2 +- include/nuttx/arch.h | 28 +++++++++++++++------------- sched/init/os_smpstart.c | 2 +- sched/sched/sched.h | 2 +- sched/sched/sched_addreadytorun.c | 4 ++-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/arch b/arch index 17b239501e..bd833ac25f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 17b239501e1b11ae065586efe31f2c4e8ffd4122 +Subproject commit bd833ac25f0f982a372d8d9df5e1634a6eb21b32 diff --git a/configs b/configs index af52276c2a..0ace58ab54 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit af52276c2aa09944c1c2f158cdb05e7eb53c1659 +Subproject commit 0ace58ab548d5aeae58ebdda44e9ef08d6a79bef diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index c50c598fe6..179aa49473 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1660,7 +1660,7 @@ int up_timer_start(FAR const struct timespec *ts); /* See prototype in include/nuttx/spinlock.h */ /**************************************************************************** - * Name: up_cpundx + * Name: up_cpu_index * * Description: * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that @@ -1676,13 +1676,13 @@ int up_timer_start(FAR const struct timespec *ts); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpundx(void); +int up_cpu_index(void); #else -# define up_cpundx() (0) +# define up_cpu_index() (0) #endif /**************************************************************************** - * Name: up_cpustart + * Name: up_cpu_start * * Description: * In an SMP configution, only one CPU is initially active (CPU 0). System @@ -1710,15 +1710,16 @@ int up_cpundx(void); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpustart(int cpu, main_t idletask); +int up_cpu_start(int cpu, main_t idletask); #endif /**************************************************************************** - * Name: up_cpustop + * Name: up_cpu_pause * * Description: * Save the state of the current task at the head of the - * g_assignedtasks[cpu] task list and then stop the CPU. + * g_assignedtasks[cpu] task list and then pause task execution on the + * CPU. * * This function is called by the OS when the logic executing on one CPU * needs to modify the state of the g_assignedtasks[cpu] list for another @@ -1733,17 +1734,18 @@ int up_cpustart(int cpu, main_t idletask); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpustop(int cpu); +int up_cpu_pause(int cpu); #endif /**************************************************************************** - * Name: up_cpurestart + * Name: up_cpu_resume * * Description: - * Restart the cpu, restoring the state of the task at the head of the - * g_assignedtasks[cpu] list. + * Restart the cpu after it was paused via up_cpu_pause(), restoring the + * state of the task at the head of the g_assignedtasks[cpu] list, and + * resume normal tasking. * - * This function is called after up_cpustop in order resume operation of + * This function is called after up_cpu_pause in order resume operation of * the CPU after modifying its g_assignedtasks[cpu] list. * * Input Parameters: @@ -1755,7 +1757,7 @@ int up_cpustop(int cpu); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpurestart(int cpu); +int up_cpu_resume(int cpu); #endif /**************************************************************************** diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 29a3ae7c77..215cdd45fc 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -168,7 +168,7 @@ int os_smpstart(void) { /* And start the CPU. */ - ret = up_cpustart(cpu, os_idletask); + ret = up_cpu_start(cpu, os_idletask); if (ret < 0) { sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret); diff --git a/sched/sched/sched.h b/sched/sched/sched.h index dfb222514a..ca701a8a83 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -72,7 +72,7 @@ #ifdef CONFIG_SMP # define current_task(cpu) ((FAR struct tcb_s *)g_assignedtasks[cpu].head) -# define this_cpu() up_cpundx() +# define this_cpu() up_cpu_index() #else # define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head) # define this_cpu() (0) diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index fc8fc9ca19..6beb3267ff 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -264,7 +264,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (cpu != me) { - DEBUGVERIFY(up_cpustop(cpu)); + DEBUGVERIFY(up_cpu_pause(cpu)); } /* Add the task to the list corresponding to the selected state @@ -372,7 +372,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (cpu != me) { - DEBUGVERIFY(up_cpurestart(cpu)); + DEBUGVERIFY(up_cpu_resume(cpu)); doswitch = false; } } -- GitLab From 269c242f7b6ec2c13da4dc44d0b6edbee6dd47ee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 16:51:58 -0600 Subject: [PATCH 754/858] Update TODO list --- TODO | 13 ++++++++++++- sched/signal/sig_cleanup.c | 20 -------------------- sched/signal/sig_findaction.c | 20 -------------------- sched/signal/sig_initialize.c | 8 -------- sched/signal/sig_lowest.c | 20 -------------------- sched/signal/sig_nanosleep.c | 20 -------------------- sched/signal/sig_pause.c | 20 -------------------- sched/signal/sig_waitinfo.c | 20 -------------------- 8 files changed, 12 insertions(+), 129 deletions(-) diff --git a/TODO b/TODO index 0c17856b6e..5d484fd1da 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,7 @@ nuttx/ (13) Task/Scheduler (sched/) (1) Memory Management (mm/) - (3) Signals (sched/signal, arch/) + (4) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) (6) Kernel/Protected Build @@ -360,6 +360,17 @@ o Signals (sched/signal, arch/) Status: Open Priority: Low. Even if there are only 31 usable signals, that is still a lot. + Title: THREAD COMMON SIGNAL HANDLING + Description: Signal handlers are assigned on a per thread basis. Signal lists + and data structures are a part of the TCB. This is incorrect. + Signal handlers are a global property of the task group: The + main thread and all of its child threads. Signal handlers for + all threads should be attach-able from the main thread, for + example. + Status: Open + Priority: Medium. This is a pretty big violation of the signal handling + principles. + o pthreads (sched/pthreads) ^^^^^^^^^^^^^^^^^ diff --git a/sched/signal/sig_cleanup.c b/sched/signal/sig_cleanup.c index 0d623e504c..5847a3f83c 100644 --- a/sched/signal/sig_cleanup.c +++ b/sched/signal/sig_cleanup.c @@ -42,26 +42,6 @@ #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index 659e832002..0980e0658d 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -40,26 +40,6 @@ #include #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index 5056325ec9..02c0685efd 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -45,14 +45,6 @@ #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/sched/signal/sig_lowest.c b/sched/signal/sig_lowest.c index 9f8b6d5179..5474e25e7d 100644 --- a/sched/signal/sig_lowest.c +++ b/sched/signal/sig_lowest.c @@ -43,26 +43,6 @@ #include "signal/signal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index ccd8e30769..9ffbcb52c7 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -49,26 +49,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/signal/sig_pause.c b/sched/signal/sig_pause.c index 9c390308f4..80fc712cb7 100644 --- a/sched/signal/sig_pause.c +++ b/sched/signal/sig_pause.c @@ -42,26 +42,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/signal/sig_waitinfo.c b/sched/signal/sig_waitinfo.c index 2107071160..d271dc9884 100644 --- a/sched/signal/sig_waitinfo.c +++ b/sched/signal/sig_waitinfo.c @@ -40,26 +40,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From b71907888ed220321c6142bb047c3f5277ff925d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 17:04:51 -0600 Subject: [PATCH 755/858] Remove some empty file section section header comments --- sched/mqueue/mq_desclose.c | 16 ---------------- sched/mqueue/mq_descreate.c | 16 ---------------- sched/mqueue/mq_initialize.c | 4 ---- sched/mqueue/mq_msgqalloc.c | 20 -------------------- sched/mqueue/mq_msgqfree.c | 20 -------------------- sched/mqueue/mq_notify.c | 20 -------------------- sched/mqueue/mq_recover.c | 20 -------------------- sched/mqueue/mq_release.c | 20 -------------------- 8 files changed, 136 deletions(-) diff --git a/sched/mqueue/mq_desclose.c b/sched/mqueue/mq_desclose.c index 812059e0ff..1de8ae073e 100644 --- a/sched/mqueue/mq_desclose.c +++ b/sched/mqueue/mq_desclose.c @@ -49,22 +49,6 @@ #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_descreate.c b/sched/mqueue/mq_descreate.c index 957b52815c..211e0846fe 100644 --- a/sched/mqueue/mq_descreate.c +++ b/sched/mqueue/mq_descreate.c @@ -56,22 +56,6 @@ #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index c60fd9038a..14eda7b852 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -45,10 +45,6 @@ #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Type Declarations ****************************************************************************/ diff --git a/sched/mqueue/mq_msgqalloc.c b/sched/mqueue/mq_msgqalloc.c index 6d9ccb0501..5bdfee47a3 100644 --- a/sched/mqueue/mq_msgqalloc.c +++ b/sched/mqueue/mq_msgqalloc.c @@ -49,26 +49,6 @@ #include "sched/sched.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_msgqfree.c b/sched/mqueue/mq_msgqfree.c index ac3627898b..53e73aef1a 100644 --- a/sched/mqueue/mq_msgqfree.c +++ b/sched/mqueue/mq_msgqfree.c @@ -43,26 +43,6 @@ #include #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index eff00d1083..cc5ac36b52 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -50,26 +50,6 @@ #include "sched/sched.h" #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_recover.c b/sched/mqueue/mq_recover.c index d4514549fe..b9a09881eb 100644 --- a/sched/mqueue/mq_recover.c +++ b/sched/mqueue/mq_recover.c @@ -46,26 +46,6 @@ #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/mqueue/mq_release.c b/sched/mqueue/mq_release.c index cf9db170af..9f2fbfbbeb 100644 --- a/sched/mqueue/mq_release.c +++ b/sched/mqueue/mq_release.c @@ -43,26 +43,6 @@ #include "mqueue/mqueue.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From a20863f6c042b76f24287eda46e77de3dbe156ba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 17:15:08 -0600 Subject: [PATCH 756/858] Remove some empty file section section header comments --- sched/wqueue/kwork_cancel.c | 16 ---------------- sched/wqueue/kwork_hpthread.c | 12 ------------ sched/wqueue/kwork_lpthread.c | 12 ------------ sched/wqueue/kwork_signal.c | 21 +-------------------- 4 files changed, 1 insertion(+), 60 deletions(-) diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 22a6071944..659d9688b7 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -51,22 +51,6 @@ #ifdef CONFIG_SCHED_WORKQUEUE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/wqueue/kwork_hpthread.c b/sched/wqueue/kwork_hpthread.c index fea380243c..ae3f518be5 100644 --- a/sched/wqueue/kwork_hpthread.c +++ b/sched/wqueue/kwork_hpthread.c @@ -52,14 +52,6 @@ #ifdef CONFIG_SCHED_HPWORK -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -68,10 +60,6 @@ struct hp_wqueue_s g_hpwork; -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/wqueue/kwork_lpthread.c b/sched/wqueue/kwork_lpthread.c index fe4b5e847e..2a47fbca48 100644 --- a/sched/wqueue/kwork_lpthread.c +++ b/sched/wqueue/kwork_lpthread.c @@ -55,14 +55,6 @@ #ifdef CONFIG_SCHED_LPWORK -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -71,10 +63,6 @@ struct lp_wqueue_s g_lpwork; -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/wqueue/kwork_signal.c b/sched/wqueue/kwork_signal.c index 885652f27e..a4d94dbef9 100644 --- a/sched/wqueue/kwork_signal.c +++ b/sched/wqueue/kwork_signal.c @@ -48,29 +48,10 @@ #ifdef CONFIG_SCHED_WORKQUEUE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Name: work_signal * -- GitLab From 970b34ae8f7338071e592c1c4ac03424679e90e4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 17:17:44 -0600 Subject: [PATCH 757/858] Remove some empty file section section header comments --- sched/wdog/wd_cancel.c | 20 -------------------- sched/wdog/wd_create.c | 20 -------------------- sched/wdog/wd_initialize.c | 12 ------------ sched/wdog/wd_start.c | 9 +-------- sched/wdog/wdog.h | 8 -------- 5 files changed, 1 insertion(+), 68 deletions(-) diff --git a/sched/wdog/wd_cancel.c b/sched/wdog/wd_cancel.c index 498e814427..ac8db7ed33 100644 --- a/sched/wdog/wd_cancel.c +++ b/sched/wdog/wd_cancel.c @@ -49,26 +49,6 @@ #include "sched/sched.h" #include "wdog/wdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/wdog/wd_create.c b/sched/wdog/wd_create.c index 2beb4ea98b..416da9c351 100644 --- a/sched/wdog/wd_create.c +++ b/sched/wdog/wd_create.c @@ -49,26 +49,6 @@ #include "wdog/wdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/wdog/wd_initialize.c b/sched/wdog/wd_initialize.c index 84894903cb..54b98e4838 100644 --- a/sched/wdog/wd_initialize.c +++ b/sched/wdog/wd_initialize.c @@ -43,14 +43,6 @@ #include "wdog/wdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -85,10 +77,6 @@ uint16_t g_wdnfree; static struct wdog_s g_wdpool[CONFIG_PREALLOC_WDOGS]; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index 0932bb6d55..9e99d01277 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -86,17 +86,10 @@ typedef void (*wdentry4_t)(int argc, wdparm_t arg1, wdparm_t arg2, wdparm_t arg3, wdparm_t arg4); #endif -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ + /**************************************************************************** * Name: wd_expiration * diff --git a/sched/wdog/wdog.h b/sched/wdog/wdog.h index e1cacf1fa5..73e4d4b969 100644 --- a/sched/wdog/wdog.h +++ b/sched/wdog/wdog.h @@ -48,14 +48,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ -- GitLab From 6543c570d48d207aeea74bd2188a9149af5c3b53 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 17:38:39 -0600 Subject: [PATCH 758/858] Remove some empty file section section header comments --- sched/environ/env_clearenv.c | 4 ---- sched/environ/env_dup.c | 4 ---- sched/environ/env_findvar.c | 4 ---- sched/environ/env_getenv.c | 4 ---- sched/environ/env_getenvironptr.c | 4 ---- sched/environ/env_putenv.c | 4 ---- sched/environ/env_release.c | 4 ---- sched/environ/env_removevar.c | 4 ---- sched/environ/env_setenv.c | 4 ---- sched/environ/env_unsetenv.c | 4 ---- sched/environ/environ.h | 4 ---- sched/paging/paging.h | 4 ---- sched/paging/pg_worker.c | 4 ---- sched/semaphore/sem_destroy.c | 20 -------------------- sched/semaphore/semaphore.h | 12 ------------ sched/timer/timer_delete.c | 16 ---------------- sched/timer/timer_getoverrun.c | 16 ---------------- sched/timer/timer_gettime.c | 16 ---------------- sched/timer/timer_initialize.c | 8 -------- 19 files changed, 140 deletions(-) diff --git a/sched/environ/env_clearenv.c b/sched/environ/env_clearenv.c index 4085fd20da..ededbadbed 100644 --- a/sched/environ/env_clearenv.c +++ b/sched/environ/env_clearenv.c @@ -46,10 +46,6 @@ #include "sched/sched.h" #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index ffb68e2eaa..1745385daf 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -51,10 +51,6 @@ #include "sched/sched.h" #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_findvar.c b/sched/environ/env_findvar.c index 2a5b959da7..f6b44da5c4 100644 --- a/sched/environ/env_findvar.c +++ b/sched/environ/env_findvar.c @@ -47,10 +47,6 @@ #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c index 0c28e6d970..e5309be325 100644 --- a/sched/environ/env_getenv.c +++ b/sched/environ/env_getenv.c @@ -49,10 +49,6 @@ #include "sched/sched.h" #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_getenvironptr.c b/sched/environ/env_getenvironptr.c index b54c41a0e5..d392777392 100644 --- a/sched/environ/env_getenvironptr.c +++ b/sched/environ/env_getenvironptr.c @@ -47,10 +47,6 @@ #undef get_environ_ptr -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_putenv.c b/sched/environ/env_putenv.c index 1d10d798a1..484fd3ad59 100644 --- a/sched/environ/env_putenv.c +++ b/sched/environ/env_putenv.c @@ -48,10 +48,6 @@ #include -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_release.c b/sched/environ/env_release.c index 67db8eda9f..d1ace0505b 100644 --- a/sched/environ/env_release.c +++ b/sched/environ/env_release.c @@ -48,10 +48,6 @@ #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_removevar.c b/sched/environ/env_removevar.c index 4132eb2604..b18ebbf899 100644 --- a/sched/environ/env_removevar.c +++ b/sched/environ/env_removevar.c @@ -46,10 +46,6 @@ #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index 8f5b38b1ac..38faae839a 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -52,10 +52,6 @@ #include "sched/sched.h" #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index ac96e49c1b..2956cfe783 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -50,10 +50,6 @@ #include "sched/sched.h" #include "environ/environ.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/environ/environ.h b/sched/environ/environ.h index c570835c87..7ad59626e5 100644 --- a/sched/environ/environ.h +++ b/sched/environ/environ.h @@ -52,10 +52,6 @@ # define env_release(group) (0) #else -/**************************************************************************** - * Public Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/sched/paging/paging.h b/sched/paging/paging.h index e25bd782b8..cccda6e4ed 100644 --- a/sched/paging/paging.h +++ b/sched/paging/paging.h @@ -71,10 +71,6 @@ # warning "Page fill support requires signals" #endif -/**************************************************************************** - * Public Types - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 668d768d44..29344fb842 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -67,10 +67,6 @@ # warning "Signals needed by this function (CONFIG_DISABLE_SIGNALS=n)" #endif -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c index adaef3e552..7518382bb9 100644 --- a/sched/semaphore/sem_destroy.c +++ b/sched/semaphore/sem_destroy.c @@ -44,26 +44,6 @@ #include "semaphore/semaphore.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index c0d77f07c3..85f4e6c876 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -49,18 +49,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/timer/timer_delete.c b/sched/timer/timer_delete.c index 45933db210..495db81dc1 100644 --- a/sched/timer/timer_delete.c +++ b/sched/timer/timer_delete.c @@ -46,22 +46,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/timer/timer_getoverrun.c b/sched/timer/timer_getoverrun.c index ce2d44ba17..e92a81bef9 100644 --- a/sched/timer/timer_getoverrun.c +++ b/sched/timer/timer_getoverrun.c @@ -46,22 +46,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/timer/timer_gettime.c b/sched/timer/timer_gettime.c index 0653432302..44bf877c9f 100644 --- a/sched/timer/timer_gettime.c +++ b/sched/timer/timer_gettime.c @@ -47,22 +47,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Data - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/timer/timer_initialize.c b/sched/timer/timer_initialize.c index 634397fb6d..2a215c605c 100644 --- a/sched/timer/timer_initialize.c +++ b/sched/timer/timer_initialize.c @@ -51,10 +51,6 @@ #ifndef CONFIG_DISABLE_POSIX_TIMERS -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - /******************************************************************************** * Private Data ********************************************************************************/ @@ -82,10 +78,6 @@ volatile sq_queue_t g_freetimers; volatile sq_queue_t g_alloctimers; -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ -- GitLab From 720343612b4974c6d212d56ef33efe772c8b6671 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 18:05:03 -0600 Subject: [PATCH 759/858] Remove some empty file section section header comments --- sched/clock/clock_dow.c | 4 ---- sched/clock/clock_getres.c | 28 ---------------------------- sched/clock/clock_initialize.c | 16 ---------------- sched/clock/clock_settime.c | 28 ---------------------------- sched/clock/clock_ticks2time.c | 20 -------------------- sched/clock/clock_time2ticks.c | 20 -------------------- sched/errno/errno_get.c | 4 ---- sched/errno/errno_set.c | 4 ---- sched/group/group_addrenv.c | 4 ---- sched/group/group_foreachchild.c | 4 ---- sched/group/group_malloc.c | 20 -------------------- sched/group/group_setupidlefiles.c | 4 ---- sched/group/group_setupstreams.c | 4 ---- sched/group/group_signal.c | 8 -------- sched/group/group_zalloc.c | 20 -------------------- 15 files changed, 188 deletions(-) diff --git a/sched/clock/clock_dow.c b/sched/clock/clock_dow.c index 00e9703bc5..c105d1edaa 100644 --- a/sched/clock/clock_dow.c +++ b/sched/clock/clock_dow.c @@ -45,10 +45,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/sched/clock/clock_getres.c b/sched/clock/clock_getres.c index 4c154ea6f8..aad5dec9c3 100644 --- a/sched/clock/clock_getres.c +++ b/sched/clock/clock_getres.c @@ -46,34 +46,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index cccd175932..6e653e78e7 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -64,18 +64,6 @@ #define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) #define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -90,10 +78,6 @@ volatile uint32_t g_system_timer; struct timespec g_basetime; -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index e1516082a8..640e375a63 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -49,34 +49,6 @@ #include "clock/clock.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/clock/clock_ticks2time.c b/sched/clock/clock_ticks2time.c index 07b7c915bc..b69379d827 100644 --- a/sched/clock/clock_ticks2time.c +++ b/sched/clock/clock_ticks2time.c @@ -42,26 +42,6 @@ #include #include "clock/clock.h" -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/clock/clock_time2ticks.c b/sched/clock/clock_time2ticks.c index f01d91b402..8667e6bcd9 100644 --- a/sched/clock/clock_time2ticks.c +++ b/sched/clock/clock_time2ticks.c @@ -44,26 +44,6 @@ #include "clock/clock.h" -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/errno/errno_get.c b/sched/errno/errno_get.c index 100facc335..8982ac61e7 100644 --- a/sched/errno/errno_get.c +++ b/sched/errno/errno_get.c @@ -49,10 +49,6 @@ #undef get_errno #undef errno -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/errno/errno_set.c b/sched/errno/errno_set.c index 73f8198977..540bc8b782 100644 --- a/sched/errno/errno_set.c +++ b/sched/errno/errno_set.c @@ -49,10 +49,6 @@ #undef set_errno #undef errno -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index b4525af8d2..ddc27a4153 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -61,10 +61,6 @@ gid_t g_gid_current; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_foreachchild.c b/sched/group/group_foreachchild.c index 72c1c3b93e..10fed5f90a 100644 --- a/sched/group/group_foreachchild.c +++ b/sched/group/group_foreachchild.c @@ -45,10 +45,6 @@ #ifdef HAVE_GROUP_MEMBERS -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_malloc.c b/sched/group/group_malloc.c index b8ed5c487e..c8fe8104c4 100644 --- a/sched/group/group_malloc.c +++ b/sched/group/group_malloc.c @@ -50,26 +50,6 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_setupidlefiles.c b/sched/group/group_setupidlefiles.c index a18af782ab..c5ed320f5e 100644 --- a/sched/group/group_setupidlefiles.c +++ b/sched/group/group_setupidlefiles.c @@ -53,10 +53,6 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_setupstreams.c b/sched/group/group_setupstreams.c index ea57f32fc7..02df7b7b53 100644 --- a/sched/group/group_setupstreams.c +++ b/sched/group/group_setupstreams.c @@ -55,10 +55,6 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NFILE_STREAMS > 0 -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/group/group_signal.c b/sched/group/group_signal.c index 565c8ffda8..f3ed143bbd 100644 --- a/sched/group/group_signal.c +++ b/sched/group/group_signal.c @@ -51,10 +51,6 @@ #if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_SIGNALS) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -70,10 +66,6 @@ struct group_signal_s }; #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/group/group_zalloc.c b/sched/group/group_zalloc.c index 23ddea6f8b..eb7794eace 100644 --- a/sched/group/group_zalloc.c +++ b/sched/group/group_zalloc.c @@ -46,26 +46,6 @@ #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ defined(CONFIG_MM_KERNEL_HEAP) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From 241ab98c5b39f7a65435088a33b84a6a764439f7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 18:31:56 -0600 Subject: [PATCH 760/858] Remove some empty file section section header comments --- mm/kmm_heap/kmm_addregion.c | 16 ---------------- mm/kmm_heap/kmm_brkaddr.c | 4 ---- mm/kmm_heap/kmm_calloc.c | 4 ---- mm/kmm_heap/kmm_extend.c | 4 ---- mm/kmm_heap/kmm_free.c | 8 -------- mm/kmm_heap/kmm_heapmember.c | 16 ---------------- mm/kmm_heap/kmm_initialize.c | 12 ------------ mm/kmm_heap/kmm_kernel.c | 16 ---------------- mm/kmm_heap/kmm_mallinfo.c | 12 ------------ mm/kmm_heap/kmm_malloc.c | 20 -------------------- mm/kmm_heap/kmm_memalign.c | 8 -------- mm/kmm_heap/kmm_realloc.c | 8 -------- mm/kmm_heap/kmm_sbrk.c | 4 ---- mm/kmm_heap/kmm_sem.c | 16 ---------------- mm/kmm_heap/kmm_zalloc.c | 4 ---- mm/mm_gran/mm_granalloc.c | 4 ---- mm/mm_gran/mm_grancritical.c | 12 ------------ mm/mm_gran/mm_graninit.c | 4 ---- mm/mm_gran/mm_granmark.c | 8 -------- mm/mm_gran/mm_granrelease.c | 4 ---- mm/mm_gran/mm_granreserve.c | 4 ---- 21 files changed, 188 deletions(-) diff --git a/mm/kmm_heap/kmm_addregion.c b/mm/kmm_heap/kmm_addregion.c index 47dcbd54fb..41884fa7c3 100644 --- a/mm/kmm_heap/kmm_addregion.c +++ b/mm/kmm_heap/kmm_addregion.c @@ -43,22 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_brkaddr.c b/mm/kmm_heap/kmm_brkaddr.c index a04032e832..4329a0cf87 100644 --- a/mm/kmm_heap/kmm_brkaddr.c +++ b/mm/kmm_heap/kmm_brkaddr.c @@ -45,10 +45,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_calloc.c b/mm/kmm_heap/kmm_calloc.c index 2da8e815c8..4c3f1bc8e2 100644 --- a/mm/kmm_heap/kmm_calloc.c +++ b/mm/kmm_heap/kmm_calloc.c @@ -43,10 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_extend.c b/mm/kmm_heap/kmm_extend.c index 0a05ccd8d6..256c84d24d 100644 --- a/mm/kmm_heap/kmm_extend.c +++ b/mm/kmm_heap/kmm_extend.c @@ -43,10 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_free.c b/mm/kmm_heap/kmm_free.c index 7b47fae7b1..c901678818 100644 --- a/mm/kmm_heap/kmm_free.c +++ b/mm/kmm_heap/kmm_free.c @@ -46,14 +46,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_heapmember.c b/mm/kmm_heap/kmm_heapmember.c index 3fbe96adcb..b96a6f7ada 100644 --- a/mm/kmm_heap/kmm_heapmember.c +++ b/mm/kmm_heap/kmm_heapmember.c @@ -45,22 +45,6 @@ #if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG) -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_initialize.c b/mm/kmm_heap/kmm_initialize.c index 07c679e28b..03baba8120 100644 --- a/mm/kmm_heap/kmm_initialize.c +++ b/mm/kmm_heap/kmm_initialize.c @@ -43,14 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -59,10 +51,6 @@ struct mm_heap_s g_kmmheap; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_kernel.c b/mm/kmm_heap/kmm_kernel.c index f2477e228a..4a2231dd01 100644 --- a/mm/kmm_heap/kmm_kernel.c +++ b/mm/kmm_heap/kmm_kernel.c @@ -46,22 +46,6 @@ #if ((defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ defined(CONFIG_BUILD_KERNEL)) && defined(CONFIG_MM_KERNEL_HEAP) -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_mallinfo.c b/mm/kmm_heap/kmm_mallinfo.c index 2ad3d26df6..9f812bad2b 100644 --- a/mm/kmm_heap/kmm_mallinfo.c +++ b/mm/kmm_heap/kmm_mallinfo.c @@ -45,18 +45,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_malloc.c b/mm/kmm_heap/kmm_malloc.c index a360c50f8f..06bed81c50 100644 --- a/mm/kmm_heap/kmm_malloc.c +++ b/mm/kmm_heap/kmm_malloc.c @@ -43,26 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_memalign.c b/mm/kmm_heap/kmm_memalign.c index 1fde19f7e4..2ca1465bf0 100644 --- a/mm/kmm_heap/kmm_memalign.c +++ b/mm/kmm_heap/kmm_memalign.c @@ -45,14 +45,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_realloc.c b/mm/kmm_heap/kmm_realloc.c index 3f553c0716..477e2b70b1 100644 --- a/mm/kmm_heap/kmm_realloc.c +++ b/mm/kmm_heap/kmm_realloc.c @@ -43,14 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_sbrk.c b/mm/kmm_heap/kmm_sbrk.c index 3cee21b426..4d4b95746f 100644 --- a/mm/kmm_heap/kmm_sbrk.c +++ b/mm/kmm_heap/kmm_sbrk.c @@ -43,10 +43,6 @@ #if defined(CONFIG_BUILD_KERNEL) && defined(__KERNEL__) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_sem.c b/mm/kmm_heap/kmm_sem.c index ffff92920f..2ba019f673 100644 --- a/mm/kmm_heap/kmm_sem.c +++ b/mm/kmm_heap/kmm_sem.c @@ -43,22 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/kmm_heap/kmm_zalloc.c b/mm/kmm_heap/kmm_zalloc.c index 303d1f0040..19bea29f15 100644 --- a/mm/kmm_heap/kmm_zalloc.c +++ b/mm/kmm_heap/kmm_zalloc.c @@ -43,10 +43,6 @@ #ifdef CONFIG_MM_KERNEL_HEAP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_gran/mm_granalloc.c b/mm/mm_gran/mm_granalloc.c index f3537c7d6a..79044ca3a1 100644 --- a/mm/mm_gran/mm_granalloc.c +++ b/mm/mm_gran/mm_granalloc.c @@ -47,10 +47,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/mm/mm_gran/mm_grancritical.c b/mm/mm_gran/mm_grancritical.c index a105f03a07..fd8485c411 100644 --- a/mm/mm_gran/mm_grancritical.c +++ b/mm/mm_gran/mm_grancritical.c @@ -50,18 +50,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_gran/mm_graninit.c b/mm/mm_gran/mm_graninit.c index 9da0de1fc8..03cde59b11 100644 --- a/mm/mm_gran/mm_graninit.c +++ b/mm/mm_gran/mm_graninit.c @@ -49,10 +49,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/mm/mm_gran/mm_granmark.c b/mm/mm_gran/mm_granmark.c index d9dfcb9ec6..7466d91c73 100644 --- a/mm/mm_gran/mm_granmark.c +++ b/mm/mm_gran/mm_granmark.c @@ -47,14 +47,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_gran/mm_granrelease.c b/mm/mm_gran/mm_granrelease.c index bb5084da40..38fc354ced 100644 --- a/mm/mm_gran/mm_granrelease.c +++ b/mm/mm_gran/mm_granrelease.c @@ -49,10 +49,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/mm/mm_gran/mm_granreserve.c b/mm/mm_gran/mm_granreserve.c index 6becbd0f00..9958127969 100644 --- a/mm/mm_gran/mm_granreserve.c +++ b/mm/mm_gran/mm_granreserve.c @@ -47,10 +47,6 @@ #ifdef CONFIG_GRAN -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ -- GitLab From c4493528a1e0374e6ce0367047a2dfedf2b9ef9b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 17 Feb 2016 18:57:35 -0600 Subject: [PATCH 761/858] Remove some empty file section section header comments --- mm/mm_heap/mm_addfreechunk.c | 8 -------- mm/mm_heap/mm_brkaddr.c | 4 ---- mm/mm_heap/mm_calloc.c | 4 ---- mm/mm_heap/mm_initialize.c | 12 ------------ mm/mm_heap/mm_mallinfo.c | 12 ------------ mm/mm_heap/mm_malloc.c | 16 ---------------- mm/mm_heap/mm_memalign.c | 8 -------- mm/mm_heap/mm_realloc.c | 8 -------- mm/mm_heap/mm_sbrk.c | 4 ---- mm/mm_heap/mm_shrinkchunk.c | 4 ---- mm/mm_heap/mm_size2ndx.c | 4 ---- mm/shm/shm_initialize.c | 12 ------------ mm/shm/shmat.c | 16 ---------------- mm/shm/shmctl.c | 16 ---------------- mm/shm/shmdt.c | 16 ---------------- mm/shm/shmget.c | 12 ------------ 16 files changed, 156 deletions(-) diff --git a/mm/mm_heap/mm_addfreechunk.c b/mm/mm_heap/mm_addfreechunk.c index 7119eebe78..e2defc0908 100644 --- a/mm/mm_heap/mm_addfreechunk.c +++ b/mm/mm_heap/mm_addfreechunk.c @@ -41,14 +41,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_brkaddr.c b/mm/mm_heap/mm_brkaddr.c index 1d7b22680c..38aa113efa 100644 --- a/mm/mm_heap/mm_brkaddr.c +++ b/mm/mm_heap/mm_brkaddr.c @@ -43,10 +43,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_calloc.c b/mm/mm_heap/mm_calloc.c index fe94ff0338..43d06e2e31 100644 --- a/mm/mm_heap/mm_calloc.c +++ b/mm/mm_heap/mm_calloc.c @@ -41,10 +41,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index 188b55dd83..bd9d4f524a 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -45,18 +45,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c index 5aa720e7a9..f3c8775ba6 100644 --- a/mm/mm_heap/mm_mallinfo.c +++ b/mm/mm_heap/mm_mallinfo.c @@ -45,18 +45,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index e1ed4b8c15..3f9db86a33 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -52,22 +52,6 @@ # define NULL ((void *)0) #endif -/**************************************************************************** - * Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index 0609885653..bd8abb8c05 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -43,14 +43,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index 7b6e75f298..bf28ff62df 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -46,14 +46,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_sbrk.c b/mm/mm_heap/mm_sbrk.c index 19a91cc3dd..774d5d3f11 100644 --- a/mm/mm_heap/mm_sbrk.c +++ b/mm/mm_heap/mm_sbrk.c @@ -49,10 +49,6 @@ #ifdef CONFIG_BUILD_KERNEL -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index c829876079..8ce1c7c333 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -43,10 +43,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/mm_heap/mm_size2ndx.c b/mm/mm_heap/mm_size2ndx.c index e3273767e9..841dea3687 100644 --- a/mm/mm_heap/mm_size2ndx.c +++ b/mm/mm_heap/mm_size2ndx.c @@ -41,10 +41,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/shm/shm_initialize.c b/mm/shm/shm_initialize.c index b57d3e8f9a..a25bc8fd19 100644 --- a/mm/shm/shm_initialize.c +++ b/mm/shm/shm_initialize.c @@ -52,14 +52,6 @@ #ifdef CONFIG_MM_SHM -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -68,10 +60,6 @@ struct shm_info_s g_shminfo; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/shm/shmat.c b/mm/shm/shmat.c index 3a9bc4c089..b3658a38fa 100644 --- a/mm/shm/shmat.c +++ b/mm/shm/shmat.c @@ -50,22 +50,6 @@ #ifdef CONFIG_MM_SHM -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/shm/shmctl.c b/mm/shm/shmctl.c index 0c2dc6cb86..6ba3a33f1a 100644 --- a/mm/shm/shmctl.c +++ b/mm/shm/shmctl.c @@ -55,22 +55,6 @@ #ifdef CONFIG_MM_SHM -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/shm/shmdt.c b/mm/shm/shmdt.c index 2215b03785..201e944b65 100644 --- a/mm/shm/shmdt.c +++ b/mm/shm/shmdt.c @@ -50,22 +50,6 @@ #ifdef CONFIG_MM_SHM -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/mm/shm/shmget.c b/mm/shm/shmget.c index 35bb7c26ac..e3f0208460 100644 --- a/mm/shm/shmget.c +++ b/mm/shm/shmget.c @@ -53,18 +53,6 @@ #ifdef CONFIG_MM_SHM -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ -- GitLab From 52fbbaf778c9f48d1ad9e8237b7f5b69e2f1c40b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 08:34:11 -0600 Subject: [PATCH 762/858] 1. SMP: Fix an assertion. SMP-specific change accidentally made in non-SMP code 2. Move list of signal actions from the task TCB to the task group. Signal handlers are a property of the entire task group and not of individual threads in the group. I know, I preferred it the other way too but this is more compliant with POSIX. --- ChangeLog | 7 +- TODO | 106 ++++++++++++++++++++++++- include/nuttx/sched.h | 4 +- sched/group/group_signal.c | 12 ++- sched/sched/sched_addreadytorun.c | 2 +- sched/signal/sig_action.c | 16 ++-- sched/signal/sig_cleanup.c | 20 ++--- sched/signal/sig_dispatch.c | 12 ++- sched/signal/sig_findaction.c | 8 +- sched/signal/sig_pending.c | 2 +- sched/signal/sig_removependingsignal.c | 6 +- sched/signal/signal.h | 2 +- 12 files changed, 157 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ce513e2f0..47354c5a4a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11491,5 +11491,8 @@ your code still uses them, please switch to enter_critical_section() and leave_critical_section() (2016-02-14). * Also rename irqdisable() and irqenable() to up_irq_disable() and - up_irq_enable (2016-02-14). - + up_irq_enable() (2016-02-14). + * sched/signal and include/nuttx/sched.h: Move the list of signal + actions from the TCB to the group structure. Signal handlers are not + per thread but, rather, per task group. I know, I preferred it the + other way too, but this is more compliant with POSIX (2016-02-18). diff --git a/TODO b/TODO index 5d484fd1da..5351334ad5 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated February 8, 2016) +NuttX TODO List (Last updated February 18, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -25,7 +25,7 @@ nuttx/ (8) Graphics subsystem (graphics/) (1) Pascal add-on (pcode/) (1) Build system / Toolchains - (3) Linux/Cywgin simulation (arch/sim) + (4) Linux/Cywgin simulation (arch/sim) (4) ARM (arch/arm/) apps/ @@ -1620,6 +1620,108 @@ o Linux/Cywgin simulation (arch/sim) Status: Open Priority: Low + Title: SMP SIMULATION INCOMPLETE + Description: The configuration has basic support SMP testing. The simulation + supports the emulation of multiple CPUs by creating multiple + pthreads, each run a copy of the simulation in the same process + address space. + + The simulation SMP implemention is incomplete, however. Two + critical SMP functions are not implemented: + + - int up_cpu_pause(void) + - int up_cpu_resume(void) + + These are used to start a new task on a different CPU: (1) + the other CPU is stopped or paused, (2) the OS datastructures + for that CPU are modified, then (2) the other CPU is resumed. + Unfortunately, I have not yet thought of a way to implement + them in the simulation. + + Currently, for example, you can enable SMP for ostest + configuration by enabling: + + -# CONFIG_EXPERIMENTAL is not set + +CONFIG_EXPERIMENTAL=y + + +CONFIG_SPINLOCK=y + +CONFIG_SMP=y + +CONFIG_SMP_NCPUS=2 + +CONFIG_SMP_IDLETHREAD_STACKSIZE=2048 + + And you can enable some additional debug output with: + + -# CONFIG_DEBUG_SCHED is not set + +CONFIG_DEBUG_SCHED=y + + -# CONFIG_SCHED_INSTRUMENTATION is not set + +CONFIG_SCHED_INSTRUMENTATION=y + + The result should be as follows: + + - CPU0 initializes and starts CPU1. CPU1 is running an + executing the IDLE task. + + os_start: Entry + os_idletask: CPU1: Beginning Idle Loop + + - CPU0 brings up the the OS test application on CPU0 + + os_do_appstart: Starting init thread + CPU0: Start init, TCB@42f490, state=5 + up_unblock_task: Unblocking TCB=42f490 + CPU0: Suspend CPU0 IDLE, TCB@42c180, state=4 + CPU0: Resume init, TCB@42f490, state=0 + up_unblock_task: New Active Task TCB=42f490 + + - OS test runs and performs some basic checks. + + stdio_test: write fd=1 + stdio_test: Standard I/O Check: printf + stdio_test: write fd=2 + stdio_test: Standard I/O Check: fprintf to stderr + ostest_main: putenv(Variable1=BadValue3) + + up_block_task: Blocking TCB=42f490 + CPU0: Suspend init, TCB@42f490, state=4 + CPU0: Resume CPU0 IDLE, TCB@42c180, state=3 + up_block_task: New Active Task TCB=42c180 + up_unblock_task: Unblocking TCB=42f490 + CPU0: Suspend CPU0 IDLE, TCB@42c180, state=4 + CPU0: Resume init, TCB@42f490, state=0 + up_unblock_task: New Active Task TCB=42f490 + + ostest_main: setenv(Variable1, GoodValue1, TRUE) + ostest_main: setenv(Variable2, BadValue1, FALSE) + ostest_main: setenv(Variable2, GoodValue2, TRUE) + ostest_main: setenv(Variable3, Variable3, FALSE) + ostest_main: setenv(Variable3, Variable3, FALSE) + show_variable: Variable=Variable1 has value=GoodValue1 + show_variable: Variable=Variable2 has value=GoodValue2 + show_variable: Variable=Variable3 has value=GoodValue3 + + - Then OS test tries to start the task ostest on CPU1 + + CPU0: Start ostest, TCB@430e90, state=5 + up_unblock_task: Unblocking TCB=430e90 + CPU1: Suspend CPU1 IDLE, TCB@42c2c0, state=4 + CPU0: Resume ostest, TCB@430e90, state=0 + ostest_main: Started user_main at PID=4 + + There is no failure but, of course, the task on CPU1 does not + run, i.e., it does not replace the IDLE task running on CPU1. + + 2016-02-16: The NSH configuration can be forced to run, but + only if (1) You don't try to execute built-in commands or to + execute commands in the background. Those thoses cases, it + will try to start the command on CPU1 and the same problem + as for the ostest case occurs. + + Also, for NSH you have to modify arch/sim/src/up_idle.c so + that the IDLE loop only runfs for CPU0. Otherwise, often + simuart_post() will be called from CPU1 and it will try to + restart NSH on CPU0 and, again, the same problem occurs. + o ARM (arch/arm/) ^^^^^^^^^^^^^^^ diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index cade6cde3e..586c1a81e9 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -445,7 +445,8 @@ struct task_group_s #ifndef CONFIG_DISABLE_SIGNALS /* POSIX Signal Control Fields ************************************************/ - sq_queue_t sigpendingq; /* List of pending signals */ + sq_queue_t tg_sigactionq; /* List of actions for signals */ + sq_queue_t tg_sigpendingq; /* List of pending signals */ #endif #ifndef CONFIG_DISABLE_ENVIRON @@ -599,7 +600,6 @@ struct tcb_s #ifndef CONFIG_DISABLE_SIGNALS sigset_t sigprocmask; /* Signals that are blocked */ sigset_t sigwaitmask; /* Waiting for pending signals */ - sq_queue_t sigactionq; /* List of actions for signals */ sq_queue_t sigpendactionq; /* List of pending signal actions */ sq_queue_t sigpostedq; /* List of posted signals */ siginfo_t sigunbinfo; /* Signal info when task unblocked */ diff --git a/sched/group/group_signal.c b/sched/group/group_signal.c index f3ed143bbd..7b29e3d5d6 100644 --- a/sched/group/group_signal.c +++ b/sched/group/group_signal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_signal.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,6 +89,7 @@ struct group_signal_s static int group_signal_handler(pid_t pid, FAR void *arg) { FAR struct group_signal_s *info = (FAR struct group_signal_s *)arg; + FAR struct task_group_s *group; FAR struct tcb_s *tcb; FAR sigactq_t *sigact; int ret; @@ -98,7 +99,7 @@ static int group_signal_handler(pid_t pid, FAR void *arg) /* Get the TCB associated with the group member */ tcb = sched_gettcb(pid); - DEBUGASSERT(tcb); + DEBUGASSERT(tcb ! = NULL); if (tcb) { /* Set this one as the default if we have not already set the default. */ @@ -151,9 +152,12 @@ static int group_signal_handler(pid_t pid, FAR void *arg) info->utcb = tcb; } - /* Is there also an action associated with the task? */ + /* Is there also a action associated with the task group? */ - sigact = sig_findaction(tcb, info->siginfo->si_signo); + group = tcb->group; + DEBUGASSERT(group != NULL); + + sigact = sig_findaction(group, info->siginfo->si_signo); if (sigact) { /* Yes.. then use this thread. The requirement is this: diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 6beb3267ff..2bcc3f9087 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -113,7 +113,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * is now the new active task! */ - ASSERT(!spin_islocked(&g_cpu_schedlock) && btcb->flink != NULL); + DEBUGASSERT(rtcb->lockcount == 0 && btcb->flink != NULL); btcb->task_state = TSTATE_TASK_RUNNING; btcb->flink->task_state = TSTATE_TASK_READYTORUN; diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index c0f7dcc743..4b61dc1d49 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -156,12 +156,16 @@ static FAR sigactq_t *sig_allocateaction(void) int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction *oact) { FAR struct tcb_s *rtcb = this_task(); + FAR struct task_group_s *group; FAR sigactq_t *sigact; /* Since sigactions can only be installed from the running thread of * execution, no special precautions should be necessary. */ + DEBUGASSERT(rtcb != NULL && rtcb->group != NULL); + group = rtcb->group; + /* Verify the signal number */ if (!GOOD_SIGNO(signo)) @@ -170,9 +174,9 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * return ERROR; } - /* Find the signal in the sigactionq */ + /* Find the signal in the signal action queue */ - sigact = sig_findaction(rtcb, signo); + sigact = sig_findaction(group, signo); /* Return the old sigaction value if so requested */ @@ -242,9 +246,9 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * if (sigact) { - /* Yes.. Remove it from sigactionq */ + /* Yes.. Remove it from signal action queue */ - sq_rem((FAR sq_entry_t *)sigact, &rtcb->sigactionq); + sq_rem((FAR sq_entry_t *)sigact, &group->tg_sigactionq); /* And deallocate it */ @@ -278,9 +282,9 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * sigact->signo = (uint8_t)signo; - /* Add the new sigaction to sigactionq */ + /* Add the new sigaction to signal action queue */ - sq_addlast((FAR sq_entry_t *)sigact, &rtcb->sigactionq); + sq_addlast((FAR sq_entry_t *)sigact, &group->tg_sigactionq); } /* Set the new sigaction */ diff --git a/sched/signal/sig_cleanup.c b/sched/signal/sig_cleanup.c index 5847a3f83c..4a37e67b5f 100644 --- a/sched/signal/sig_cleanup.c +++ b/sched/signal/sig_cleanup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_cleanup.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -58,16 +58,8 @@ void sig_cleanup(FAR struct tcb_s *stcb) { - FAR sigactq_t *sigact; FAR sigq_t *sigq; - /* Deallocate all entries in the list of signal actions */ - - while ((sigact = (FAR sigactq_t *)sq_remfirst(&stcb->sigactionq)) != NULL) - { - sig_releaseaction(sigact); - } - /* Deallocate all entries in the list of pending signal actions */ while ((sigq = (FAR sigq_t *)sq_remfirst(&stcb->sigpendactionq)) != NULL) @@ -101,11 +93,19 @@ void sig_cleanup(FAR struct tcb_s *stcb) void sig_release(FAR struct task_group_s *group) { + FAR sigactq_t *sigact; FAR sigpendq_t *sigpend; + /* Deallocate all entries in the list of signal actions */ + + while ((sigact = (FAR sigactq_t *)sq_remfirst(&group->tg_sigactionq)) != NULL) + { + sig_releaseaction(sigact); + } + /* Deallocate all entries in the list of pending signals */ - while ((sigpend = (FAR sigpendq_t *)sq_remfirst(&group->sigpendingq)) != NULL) + while ((sigpend = (FAR sigpendq_t *)sq_remfirst(&group->tg_sigpendingq)) != NULL) { sig_releasependingsignal(sigpend); } diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index b52b89290f..2fedb96088 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -72,6 +72,7 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) { + FAR struct task_group_s *group; FAR sigactq_t *sigact; FAR sigq_t *sigq; irqstate_t flags; @@ -79,9 +80,12 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) sched_lock(); - /* Find the sigaction associated with this signal */ + /* Find the group sigaction associated with this signal */ + + DEBUGASSERT(stcb != NULL && stcb->group != NULL); - sigact = sig_findaction(stcb, info->si_signo); + group = stcb->group; + sigact = sig_findaction(group, info->si_signo); /* Check if a valid signal handler is available and if the signal is * unblocked. NOTE: There is no default action. @@ -206,7 +210,7 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, /* Seach the list for a sigpendion on this signal */ - for (sigpend = (FAR sigpendq_t *)group->sigpendingq.head; + for (sigpend = (FAR sigpendq_t *)group->tg_sigpendingq.head; (sigpend && sigpend->info.si_signo != signo); sigpend = sigpend->flink); @@ -260,7 +264,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, /* Add the structure to the pending signal list */ flags = enter_critical_section(); - sq_addlast((FAR sq_entry_t *)sigpend, &group->sigpendingq); + sq_addlast((FAR sq_entry_t *)sigpend, &group->tg_sigpendingq); leave_critical_section(flags); } } diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index 0980e0658d..769a678d3c 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig_findaction.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,13 +52,13 @@ * ****************************************************************************/ -FAR sigactq_t *sig_findaction(FAR struct tcb_s *stcb, int signo) +FAR sigactq_t *sig_findaction(FAR struct task_group_s *group, int signo) { FAR sigactq_t *sigact = NULL; /* Verify the caller's sanity */ - if (stcb) + if (group) { /* Sigactions can only be assigned to the currently executing * thread. So, a simple lock ought to give us sufficient @@ -69,7 +69,7 @@ FAR sigactq_t *sig_findaction(FAR struct tcb_s *stcb, int signo) /* Seach the list for a sigaction on this signal */ - for (sigact = (FAR sigactq_t *)stcb->sigactionq.head; + for (sigact = (FAR sigactq_t *)group->tg_sigactionq.head; ((sigact) && (sigact->signo != signo)); sigact = sigact->flink); diff --git a/sched/signal/sig_pending.c b/sched/signal/sig_pending.c index 91a272c547..aadef0b86b 100644 --- a/sched/signal/sig_pending.c +++ b/sched/signal/sig_pending.c @@ -103,7 +103,7 @@ sigset_t sig_pendingset(FAR struct tcb_s *stcb) sigpendset = NULL_SIGNAL_SET; flags = enter_critical_section(); - for (sigpend = (FAR sigpendq_t *)group->sigpendingq.head; + for (sigpend = (FAR sigpendq_t *)group->tg_sigpendingq.head; (sigpend); sigpend = sigpend->flink) { sigaddset(&sigpendset, sigpend->info.si_signo); diff --git a/sched/signal/sig_removependingsignal.c b/sched/signal/sig_removependingsignal.c index 3de79184f7..90485c2dc5 100644 --- a/sched/signal/sig_removependingsignal.c +++ b/sched/signal/sig_removependingsignal.c @@ -76,7 +76,7 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) flags = enter_critical_section(); - for (prevsig = NULL, currsig = (FAR sigpendq_t *)group->sigpendingq.head; + for (prevsig = NULL, currsig = (FAR sigpendq_t *)group->tg_sigpendingq.head; (currsig && currsig->info.si_signo != signo); prevsig = currsig, currsig = currsig->flink); @@ -84,11 +84,11 @@ FAR sigpendq_t *sig_removependingsignal(FAR struct tcb_s *stcb, int signo) { if (prevsig) { - sq_remafter((FAR sq_entry_t *)prevsig, &group->sigpendingq); + sq_remafter((FAR sq_entry_t *)prevsig, &group->tg_sigpendingq); } else { - sq_remfirst(&group->sigpendingq); + sq_remfirst(&group->tg_sigpendingq); } } diff --git a/sched/signal/signal.h b/sched/signal/signal.h index bce55af8bd..e8cfda81b6 100644 --- a/sched/signal/signal.h +++ b/sched/signal/signal.h @@ -186,7 +186,7 @@ void sig_release(FAR struct task_group_s *group); FAR sigq_t *sig_allocatependingsigaction(void); void sig_deliver(FAR struct tcb_s *stcb); -FAR sigactq_t *sig_findaction(FAR struct tcb_s *stcb, int signo); +FAR sigactq_t *sig_findaction(FAR struct task_group_s *group, int signo); int sig_lowest(FAR sigset_t *set); #ifdef CONFIG_CAN_PASS_STRUCTS int sig_mqnotempty(int tid, int signo, union sigval value); -- GitLab From 7d9287958fa136828b1611e65065a82649760305 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 09:21:43 -0600 Subject: [PATCH 763/858] Minor simplication to last commit; Update TODO list --- TODO | 13 +------------ sched/group/group_signal.c | 8 ++------ sched/signal/sig_dispatch.c | 20 +++++++++----------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 5351334ad5..724519cd31 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,7 @@ nuttx/ (13) Task/Scheduler (sched/) (1) Memory Management (mm/) - (4) Signals (sched/signal, arch/) + (3) Signals (sched/signal, arch/) (2) pthreads (sched/pthread) (0) Message Queues (sched/mqueue) (6) Kernel/Protected Build @@ -360,17 +360,6 @@ o Signals (sched/signal, arch/) Status: Open Priority: Low. Even if there are only 31 usable signals, that is still a lot. - Title: THREAD COMMON SIGNAL HANDLING - Description: Signal handlers are assigned on a per thread basis. Signal lists - and data structures are a part of the TCB. This is incorrect. - Signal handlers are a global property of the task group: The - main thread and all of its child threads. Signal handlers for - all threads should be attach-able from the main thread, for - example. - Status: Open - Priority: Medium. This is a pretty big violation of the signal handling - principles. - o pthreads (sched/pthreads) ^^^^^^^^^^^^^^^^^ diff --git a/sched/group/group_signal.c b/sched/group/group_signal.c index 7b29e3d5d6..1f681928d9 100644 --- a/sched/group/group_signal.c +++ b/sched/group/group_signal.c @@ -89,12 +89,11 @@ struct group_signal_s static int group_signal_handler(pid_t pid, FAR void *arg) { FAR struct group_signal_s *info = (FAR struct group_signal_s *)arg; - FAR struct task_group_s *group; FAR struct tcb_s *tcb; FAR sigactq_t *sigact; int ret; - DEBUGASSERT(info); + DEBUGASSERT(tcb != NULL && tcb->group != NULL && info != NULL); /* Get the TCB associated with the group member */ @@ -154,10 +153,7 @@ static int group_signal_handler(pid_t pid, FAR void *arg) /* Is there also a action associated with the task group? */ - group = tcb->group; - DEBUGASSERT(group != NULL); - - sigact = sig_findaction(group, info->siginfo->si_signo); + sigact = sig_findaction(tcb->group, info->siginfo->si_signo); if (sigact) { /* Yes.. then use this thread. The requirement is this: diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 2fedb96088..1d3526d5a1 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -72,20 +72,17 @@ static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info) { - FAR struct task_group_s *group; FAR sigactq_t *sigact; FAR sigq_t *sigq; irqstate_t flags; int ret = OK; sched_lock(); + DEBUGASSERT(stcb != NULL && stcb->group != NULL); /* Find the group sigaction associated with this signal */ - DEBUGASSERT(stcb != NULL && stcb->group != NULL); - - group = stcb->group; - sigact = sig_findaction(group, info->si_signo); + sigact = sig_findaction(stcb->group, info->si_signo); /* Check if a valid signal handler is available and if the signal is * unblocked. NOTE: There is no default action. @@ -202,7 +199,7 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, FAR sigpendq_t *sigpend = NULL; irqstate_t flags; - DEBUGASSERT(group); + DEBUGASSERT(group != NULL); /* Pending sigals can be added from interrupt level. */ @@ -232,13 +229,14 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group, static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, FAR siginfo_t *info) { - FAR struct task_group_s *group = stcb->group; + FAR struct task_group_s *group; FAR sigpendq_t *sigpend; irqstate_t flags; - DEBUGASSERT(group); + DEBUGASSERT(stcb != NULL && stcb->group != NULL); + group = stcb->group; - /* Check if the signal is already pending */ + /* Check if the signal is already pending for the group */ sigpend = sig_findpendingsignal(group, info->si_signo); if (sigpend) @@ -248,7 +246,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, memcpy(&sigpend->info, info, sizeof(siginfo_t)); } - /* No... There is nothing pending for this signo */ + /* No... There is nothing pending in the group for this signo */ else { @@ -261,7 +259,7 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb, memcpy(&sigpend->info, info, sizeof(siginfo_t)); - /* Add the structure to the pending signal list */ + /* Add the structure to the group pending signal list */ flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigpend, &group->tg_sigpendingq); -- GitLab From 17800007776ba2b20626e1a925c2916815635e4d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 12:31:21 -0600 Subject: [PATCH 764/858] SMP: Setting bit for wrong CPU. Assertion has cause false alarm crashes.. --- arch | 2 +- include/nuttx/sched.h | 4 +++- sched/sched/sched_addreadytorun.c | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/arch b/arch index bd833ac25f..5a6306b76a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bd833ac25f0f982a372d8d9df5e1634a6eb21b32 +Subproject commit 5a6306b76aa6656c56f5c19cbf18757a295ee1bc diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 586c1a81e9..e7a8d5c26f 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -216,7 +216,9 @@ enum tstate_e }; typedef enum tstate_e tstate_t; -/* The following definitions are determined by tstate_t */ +/* The following definitions are determined by tstate_t. Ordering of values + * in the enumeration is important! + */ #define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN #define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2bcc3f9087..82b567856d 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -275,7 +275,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) switched = sched_addprioritized(btcb, tasklist); /* If the selected task was the g_assignedtasks[] list, then a context - * swith will occur. + * switch will occur. */ if (switched) @@ -304,12 +304,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->lockcount > 0) { - spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_setbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } else { - spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_clrbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } @@ -319,12 +319,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->irqcount > 0) { - spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } else { - spin_clrbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_clrbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } @@ -334,11 +334,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * lifting machinery. */ + DEBUGASSERT(btcb->flink != NULL); next = (FAR struct tcb_s *)btcb->flink; - ASSERT(!spin_islocked(&g_cpu_schedlock) && next != NULL); if ((next->flags & TCB_FLAG_CPU_ASSIGNED) != 0) { + DEBUGASSERT(next->cpu == cpu); next->task_state = TSTATE_TASK_ASSIGNED; } else -- GitLab From 41d7c35e739b6734c694c618ce82dcd7ccd9ec98 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 13:38:24 -0600 Subject: [PATCH 765/858] Trivial update to TODO --- TODO | 3 +++ configs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 724519cd31..5d24888828 100644 --- a/TODO +++ b/TODO @@ -1711,6 +1711,9 @@ o Linux/Cywgin simulation (arch/sim) simuart_post() will be called from CPU1 and it will try to restart NSH on CPU0 and, again, the same problem occurs. + 2016-02-18: There is an initial implementation based on + signals and signal handling, but this is not yet functional. + o ARM (arch/arm/) ^^^^^^^^^^^^^^^ diff --git a/configs b/configs index 0ace58ab54..c44086d92f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0ace58ab548d5aeae58ebdda44e9ef08d6a79bef +Subproject commit c44086d92ff6f6cdf181be34d7f24c08438ea91b -- GitLab From 6d9724934841b18b7c20630ca1d7bc65b24e8e27 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 14:56:48 -0600 Subject: [PATCH 766/858] Trivial, cosmetic changes --- arch | 2 +- sched/signal/sig_dispatch.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 5a6306b76a..689e18739d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5a6306b76aa6656c56f5c19cbf18757a295ee1bc +Subproject commit 689e18739d4dc9d5238dd4b74e88792cfc1ec2e1 diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 1d3526d5a1..107982c59b 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -305,7 +305,7 @@ int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) stcb, info->si_signo, info->si_code, info->si_value.sival_int, stcb->sigprocmask); - DEBUGASSERT(stcb && info); + DEBUGASSERT(stcb != NULL && info != NULL); /************************* MASKED SIGNAL HANDLING ************************/ @@ -439,7 +439,7 @@ int sig_dispatch(pid_t pid, FAR siginfo_t *info) /* Get the TCB associated with the pid */ stcb = sched_gettcb(pid); - if (stcb) + if (stcb != NULL) { /* The task/thread associated with this PID is still active. Get its * task group. @@ -459,7 +459,7 @@ int sig_dispatch(pid_t pid, FAR siginfo_t *info) /* Did we locate the group? */ - if (group) + if (group != NULL) { /* Yes.. call group_signal() to send the signal to the correct group * member. @@ -478,7 +478,7 @@ int sig_dispatch(pid_t pid, FAR siginfo_t *info) /* Get the TCB associated with the pid */ stcb = sched_gettcb(pid); - if (!stcb) + if (stcb == NULL) { return -ESRCH; } -- GitLab From 94bea6547bb0609002f484dee86340c4aee7782c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 17:13:03 -0600 Subject: [PATCH 767/858] Fix two unterminated strings in Kconfig files --- configs | 2 +- sched/Kconfig | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configs b/configs index c44086d92f..7b89b3ddfa 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit c44086d92ff6f6cdf181be34d7f24c08438ea91b +Subproject commit 7b89b3ddfab4fc733a81bca8db5f0277e72535de diff --git a/sched/Kconfig b/sched/Kconfig index 574223fd67..a8a439d270 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -607,7 +607,7 @@ config SCHED_INSTRUMENTATION if SCHED_INSTRUMENTATION config SCHED_INSTRUMENTATION_PREEMPTION - bool "Preemption monitor hooks + bool "Preemption monitor hooks" default n ---help--- Enables additional hooks for changes to pre-emption state. Board- @@ -616,7 +616,7 @@ config SCHED_INSTRUMENTATION_PREEMPTION void sched_note_premption(FAR struct tcb_s *tcb, bool state); config SCHED_INSTRUMENTATION_CSECTION - bool "Critical section monitor hooks + bool "Critical section monitor hooks" default n depends on SMP ---help--- -- GitLab From fd94d7a6752bc497d9f72b772cae228a52692cda Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 06:52:41 -0600 Subject: [PATCH 768/858] Update TODO --- TODO | 113 ++++++++++++++++---------------------------------------- arch | 2 +- configs | 2 +- 3 files changed, 34 insertions(+), 83 deletions(-) diff --git a/TODO b/TODO index 5d24888828..54fb00ef5b 100644 --- a/TODO +++ b/TODO @@ -1609,26 +1609,19 @@ o Linux/Cywgin simulation (arch/sim) Status: Open Priority: Low - Title: SMP SIMULATION INCOMPLETE + Title: SMP SIMULATION ISSUES Description: The configuration has basic support SMP testing. The simulation supports the emulation of multiple CPUs by creating multiple pthreads, each run a copy of the simulation in the same process address space. - The simulation SMP implemention is incomplete, however. Two - critical SMP functions are not implemented: + At present, the SMP simulation is not fully functional: It does + operate on the simulated CPU threads for a few context switches + then fails during a setjmp() operation. I suspect that this is + not an issue with the NuttX SMP logic but more likely some chaos + in the pthread controls. - - int up_cpu_pause(void) - - int up_cpu_resume(void) - - These are used to start a new task on a different CPU: (1) - the other CPU is stopped or paused, (2) the OS datastructures - for that CPU are modified, then (2) the other CPU is resumed. - Unfortunately, I have not yet thought of a way to implement - them in the simulation. - - Currently, for example, you can enable SMP for ostest - configuration by enabling: + You can enable SMP for ostest configuration by enabling: -# CONFIG_EXPERIMENTAL is not set +CONFIG_EXPERIMENTAL=y @@ -1638,6 +1631,13 @@ o Linux/Cywgin simulation (arch/sim) +CONFIG_SMP_NCPUS=2 +CONFIG_SMP_IDLETHREAD_STACKSIZE=2048 + You also must enable near-realtime-performance otherwise even long + timeouts will expire before a CPU thread even has a chance to + execute. + + -# CONFIG_SIM_WALLTIME is not set + +CONFIG_SIM_WALLTIME=y + And you can enable some additional debug output with: -# CONFIG_DEBUG_SCHED is not set @@ -1646,73 +1646,24 @@ o Linux/Cywgin simulation (arch/sim) -# CONFIG_SCHED_INSTRUMENTATION is not set +CONFIG_SCHED_INSTRUMENTATION=y - The result should be as follows: - - - CPU0 initializes and starts CPU1. CPU1 is running an - executing the IDLE task. - - os_start: Entry - os_idletask: CPU1: Beginning Idle Loop - - - CPU0 brings up the the OS test application on CPU0 - - os_do_appstart: Starting init thread - CPU0: Start init, TCB@42f490, state=5 - up_unblock_task: Unblocking TCB=42f490 - CPU0: Suspend CPU0 IDLE, TCB@42c180, state=4 - CPU0: Resume init, TCB@42f490, state=0 - up_unblock_task: New Active Task TCB=42f490 - - - OS test runs and performs some basic checks. - - stdio_test: write fd=1 - stdio_test: Standard I/O Check: printf - stdio_test: write fd=2 - stdio_test: Standard I/O Check: fprintf to stderr - ostest_main: putenv(Variable1=BadValue3) - - up_block_task: Blocking TCB=42f490 - CPU0: Suspend init, TCB@42f490, state=4 - CPU0: Resume CPU0 IDLE, TCB@42c180, state=3 - up_block_task: New Active Task TCB=42c180 - up_unblock_task: Unblocking TCB=42f490 - CPU0: Suspend CPU0 IDLE, TCB@42c180, state=4 - CPU0: Resume init, TCB@42f490, state=0 - up_unblock_task: New Active Task TCB=42f490 - - ostest_main: setenv(Variable1, GoodValue1, TRUE) - ostest_main: setenv(Variable2, BadValue1, FALSE) - ostest_main: setenv(Variable2, GoodValue2, TRUE) - ostest_main: setenv(Variable3, Variable3, FALSE) - ostest_main: setenv(Variable3, Variable3, FALSE) - show_variable: Variable=Variable1 has value=GoodValue1 - show_variable: Variable=Variable2 has value=GoodValue2 - show_variable: Variable=Variable3 has value=GoodValue3 - - - Then OS test tries to start the task ostest on CPU1 - - CPU0: Start ostest, TCB@430e90, state=5 - up_unblock_task: Unblocking TCB=430e90 - CPU1: Suspend CPU1 IDLE, TCB@42c2c0, state=4 - CPU0: Resume ostest, TCB@430e90, state=0 - ostest_main: Started user_main at PID=4 - - There is no failure but, of course, the task on CPU1 does not - run, i.e., it does not replace the IDLE task running on CPU1. - - 2016-02-16: The NSH configuration can be forced to run, but - only if (1) You don't try to execute built-in commands or to - execute commands in the background. Those thoses cases, it - will try to start the command on CPU1 and the same problem - as for the ostest case occurs. - - Also, for NSH you have to modify arch/sim/src/up_idle.c so - that the IDLE loop only runfs for CPU0. Otherwise, often - simuart_post() will be called from CPU1 and it will try to - restart NSH on CPU0 and, again, the same problem occurs. - - 2016-02-18: There is an initial implementation based on - signals and signal handling, but this is not yet functional. + The NSH configuration can also be forced to run SMP, but + suffers from the same quirky behavior. I can be made + reliable if you modify arch/sim/src/up_idle.c so that + the IDLE loop only runs for CPU0. Otherwise, often + simuart_post() will be called from CPU1 and it will try + to restart NSH on CPU0 and, again, the same quirkiness + occurs. + + But for example, this command: + + nsh> sleep 1 & + + will execute the sleep command on CPU1 which has worked + every time that I have tried it (which is not too many + times). + + Status: Open + Priority: Low, SMP is important, but SMP on the simulator is not o ARM (arch/arm/) ^^^^^^^^^^^^^^^ diff --git a/arch b/arch index 689e18739d..6586d3eb74 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 689e18739d4dc9d5238dd4b74e88792cfc1ec2e1 +Subproject commit 6586d3eb74044666941bb29d1fd3eceee8d57483 diff --git a/configs b/configs index 7b89b3ddfa..4127469e4f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 7b89b3ddfab4fc733a81bca8db5f0277e72535de +Subproject commit 4127469e4f06fcfc21610df669337a9552165ca7 -- GitLab From 9b214957a6b97294bcafa46cde127d8cc763db69 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 08:19:14 -0600 Subject: [PATCH 769/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 6586d3eb74..0dd769aeea 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6586d3eb74044666941bb29d1fd3eceee8d57483 +Subproject commit 0dd769aeeaa882e4d8934414471f163c985823e6 diff --git a/configs b/configs index 4127469e4f..d5a1be277d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4127469e4f06fcfc21610df669337a9552165ca7 +Subproject commit d5a1be277d62a97c5115175b55771841495dcde7 -- GitLab From 3994b094c51f760dea896abf3287eecb9ab04aee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 10:01:15 -0600 Subject: [PATCH 770/858] Remove some empty C file section comments; Update some text in TODO file --- TODO | 4 +++- sched/pthread/pthread.h | 4 ---- sched/pthread/pthread_barrierdestroy.c | 20 -------------------- sched/pthread/pthread_barrierinit.c | 20 -------------------- sched/pthread/pthread_barrierwait.c | 20 -------------------- sched/pthread/pthread_completejoin.c | 16 ---------------- sched/pthread/pthread_condbroadcast.c | 20 -------------------- sched/pthread/pthread_condsignal.c | 20 -------------------- sched/pthread/pthread_condwait.c | 20 -------------------- sched/pthread/pthread_detach.c | 20 -------------------- sched/pthread/pthread_exit.c | 20 -------------------- sched/pthread/pthread_findjoininfo.c | 20 -------------------- sched/pthread/pthread_getschedparam.c | 20 -------------------- sched/pthread/pthread_getspecific.c | 20 -------------------- sched/pthread/pthread_initialize.c | 20 -------------------- sched/pthread/pthread_join.c | 20 -------------------- sched/pthread/pthread_keycreate.c | 20 -------------------- sched/pthread/pthread_keydelete.c | 20 -------------------- sched/pthread/pthread_mutexdestroy.c | 20 -------------------- sched/pthread/pthread_mutexinit.c | 20 -------------------- sched/pthread/pthread_mutexlock.c | 20 -------------------- sched/pthread/pthread_mutextrylock.c | 20 -------------------- sched/pthread/pthread_mutexunlock.c | 20 -------------------- sched/pthread/pthread_once.c | 20 -------------------- sched/pthread/pthread_release.c | 20 -------------------- sched/pthread/pthread_setcancelstate.c | 24 ------------------------ sched/pthread/pthread_setschedparam.c | 20 -------------------- sched/pthread/pthread_setschedprio.c | 24 ------------------------ sched/pthread/pthread_setspecific.c | 20 -------------------- sched/pthread/pthread_sigmask.c | 20 -------------------- sched/pthread/pthread_yield.c | 20 -------------------- 31 files changed, 3 insertions(+), 589 deletions(-) diff --git a/TODO b/TODO index 54fb00ef5b..31e12cfeeb 100644 --- a/TODO +++ b/TODO @@ -1619,7 +1619,9 @@ o Linux/Cywgin simulation (arch/sim) operate on the simulated CPU threads for a few context switches then fails during a setjmp() operation. I suspect that this is not an issue with the NuttX SMP logic but more likely some chaos - in the pthread controls. + in the pthread controls. I have seen similar such strange behavior + other times that I have tried to use setjmp/longmp from a signal + handler! You can enable SMP for ostest configuration by enabling: diff --git a/sched/pthread/pthread.h b/sched/pthread/pthread.h index 1c4faa3441..6371e9df33 100644 --- a/sched/pthread/pthread.h +++ b/sched/pthread/pthread.h @@ -50,10 +50,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Type Declarations ****************************************************************************/ diff --git a/sched/pthread/pthread_barrierdestroy.c b/sched/pthread/pthread_barrierdestroy.c index edf88a28f9..dbad57947a 100644 --- a/sched/pthread/pthread_barrierdestroy.c +++ b/sched/pthread/pthread_barrierdestroy.c @@ -44,26 +44,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/pthread/pthread_barrierinit.c b/sched/pthread/pthread_barrierinit.c index 4686985144..adaca2876c 100644 --- a/sched/pthread/pthread_barrierinit.c +++ b/sched/pthread/pthread_barrierinit.c @@ -44,26 +44,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/pthread/pthread_barrierwait.c b/sched/pthread/pthread_barrierwait.c index 74a459137f..2d5a306df0 100644 --- a/sched/pthread/pthread_barrierwait.c +++ b/sched/pthread/pthread_barrierwait.c @@ -45,26 +45,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/pthread/pthread_completejoin.c b/sched/pthread/pthread_completejoin.c index ec7bb96af6..2d9f3530e5 100644 --- a/sched/pthread/pthread_completejoin.c +++ b/sched/pthread/pthread_completejoin.c @@ -49,22 +49,6 @@ #include "group/group.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_condbroadcast.c b/sched/pthread/pthread_condbroadcast.c index 812b701ea9..a86c3a8a14 100644 --- a/sched/pthread/pthread_condbroadcast.c +++ b/sched/pthread/pthread_condbroadcast.c @@ -46,26 +46,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_condsignal.c b/sched/pthread/pthread_condsignal.c index e6b30adac5..b84ef5d55c 100644 --- a/sched/pthread/pthread_condsignal.c +++ b/sched/pthread/pthread_condsignal.c @@ -45,26 +45,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index ab85895807..d60aece8ef 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -47,26 +47,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 7d8c829221..6bc3585b48 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -50,26 +50,6 @@ #include "group/group.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index a384fbedf3..d742ef8fdd 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -53,26 +53,6 @@ #include "task/task.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_findjoininfo.c b/sched/pthread/pthread_findjoininfo.c index 28174becd8..60769bc16d 100644 --- a/sched/pthread/pthread_findjoininfo.c +++ b/sched/pthread/pthread_findjoininfo.c @@ -44,26 +44,6 @@ #include "group/group.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index 24b18c1535..fbb1be26b0 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -44,26 +44,6 @@ #include #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_getspecific.c b/sched/pthread/pthread_getspecific.c index e535600e0e..7ba16a9541 100644 --- a/sched/pthread/pthread_getspecific.c +++ b/sched/pthread/pthread_getspecific.c @@ -47,26 +47,6 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_initialize.c b/sched/pthread/pthread_initialize.c index 05dd8d8fad..0ced8d6181 100644 --- a/sched/pthread/pthread_initialize.c +++ b/sched/pthread/pthread_initialize.c @@ -45,26 +45,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index 7dbffe68ac..9bb9fa3fa0 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -47,26 +47,6 @@ #include "group/group.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_keycreate.c b/sched/pthread/pthread_keycreate.c index 3589dd61c8..60be2fb5e3 100644 --- a/sched/pthread/pthread_keycreate.c +++ b/sched/pthread/pthread_keycreate.c @@ -47,26 +47,6 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_keydelete.c b/sched/pthread/pthread_keydelete.c index 7915ed6e3e..57cd46309a 100644 --- a/sched/pthread/pthread_keydelete.c +++ b/sched/pthread/pthread_keydelete.c @@ -45,26 +45,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index 95fc8abef1..d7d5e7c898 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -47,26 +47,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_mutexinit.c b/sched/pthread/pthread_mutexinit.c index 9ed0b6ecb8..c4355d41bd 100644 --- a/sched/pthread/pthread_mutexinit.c +++ b/sched/pthread/pthread_mutexinit.c @@ -46,26 +46,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index 0ff12ab512..85e16adc47 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -47,26 +47,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index d7b182c875..249dd28d8c 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -48,26 +48,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 5ec784b8cc..3b50894050 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -47,26 +47,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_once.c b/sched/pthread/pthread_once.c index 7254fdbc88..b8afe81112 100644 --- a/sched/pthread/pthread_once.c +++ b/sched/pthread/pthread_once.c @@ -45,26 +45,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/sched/pthread/pthread_release.c b/sched/pthread/pthread_release.c index b06f8d3c9a..7620afbcd9 100644 --- a/sched/pthread/pthread_release.c +++ b/sched/pthread/pthread_release.c @@ -46,26 +46,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_setcancelstate.c b/sched/pthread/pthread_setcancelstate.c index d05e9c6acd..a17560224e 100644 --- a/sched/pthread/pthread_setcancelstate.c +++ b/sched/pthread/pthread_setcancelstate.c @@ -41,30 +41,6 @@ #include #include "sched/sched.h" -/****************************************************************************************** - * Pre-processor Definitions - ******************************************************************************************/ - -/****************************************************************************************** - * Private Types - ******************************************************************************************/ - -/****************************************************************************************** - * Private Function Prototypes - ******************************************************************************************/ - -/****************************************************************************************** - * Public Data - ******************************************************************************************/ - -/****************************************************************************************** - * Private Variables - ******************************************************************************************/ - -/****************************************************************************************** - * Private Functions - ******************************************************************************************/ - /****************************************************************************************** * Public Functions ******************************************************************************************/ diff --git a/sched/pthread/pthread_setschedparam.c b/sched/pthread/pthread_setschedparam.c index 972593c67c..fe7ee0cdb1 100644 --- a/sched/pthread/pthread_setschedparam.c +++ b/sched/pthread/pthread_setschedparam.c @@ -45,26 +45,6 @@ #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_setschedprio.c b/sched/pthread/pthread_setschedprio.c index 823386859b..cf31d9f013 100644 --- a/sched/pthread/pthread_setschedprio.c +++ b/sched/pthread/pthread_setschedprio.c @@ -44,30 +44,6 @@ #include #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_setspecific.c b/sched/pthread/pthread_setspecific.c index f78141c539..977f16ec2b 100644 --- a/sched/pthread/pthread_setspecific.c +++ b/sched/pthread/pthread_setspecific.c @@ -47,26 +47,6 @@ #include "sched/sched.h" #include "pthread/pthread.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_sigmask.c b/sched/pthread/pthread_sigmask.c index ac541d8f8e..012024b71d 100644 --- a/sched/pthread/pthread_sigmask.c +++ b/sched/pthread/pthread_sigmask.c @@ -44,26 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/pthread/pthread_yield.c b/sched/pthread/pthread_yield.c index c5bf47bb53..0577e21f83 100644 --- a/sched/pthread/pthread_yield.c +++ b/sched/pthread/pthread_yield.c @@ -40,26 +40,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From 050b3ee06a5bdfeb5bcecf61605d9890d0d9837a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 15:34:36 -0600 Subject: [PATCH 771/858] profcs task status will now show CPU is SMP is enabled --- ChangeLog | 3 +++ TODO | 8 +++++++- fs/procfs/fs_procfsproc.c | 25 +++++++++++++++++++++++++ include/nuttx/sched.h | 2 ++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 47354c5a4a..4506db9338 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11496,3 +11496,6 @@ actions from the TCB to the group structure. Signal handlers are not per thread but, rather, per task group. I know, I preferred it the other way too, but this is more compliant with POSIX (2016-02-18). + * fs/ procfs/fs_procfsproc.c: Add support for showing CPU if SMP is + is enabled (2016-02-19). + diff --git a/TODO b/TODO index 31e12cfeeb..9bf3e7ede3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ NuttX TODO List (Last updated February 18, 2016) +NuttX TODO List (Last updated February 18, 2016) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -1621,7 +1622,12 @@ o Linux/Cywgin simulation (arch/sim) not an issue with the NuttX SMP logic but more likely some chaos in the pthread controls. I have seen similar such strange behavior other times that I have tried to use setjmp/longmp from a signal - handler! + handler! Like when I tried to implement simulated interrupts + using signals. + + Apparently, if longjmp is invoked from the context of a signal + handler, the result is undefined: + http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1318.htm You can enable SMP for ostest configuration by enabling: diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index e90d46ef08..d47da8b67b 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -375,6 +375,7 @@ static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath) * Type: xxxxxxx {Task, pthread, Kthread, Invalid} * PPID: xxxxx Parent thread ID * Group: xxxxx Group ID + * CPU: xxx CPU (CONFIG_SMP only) * State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running, Inactive}, * {Unlock, Semaphore, Signal, MQ empty, MQ full} * Flags: xxx N,P,X @@ -461,6 +462,30 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, } #endif +#ifdef CONFIG_SMP + if (tcb->task_state >= FIRST_ASSIGNED_STATE && + tcb->task_state <= LAST_ASSIGNED_STATE) + { + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "CPU:", + tcb->cpu); + } + else + { + linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s---\n", "CPU:"); + } + + copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); + + totalsize += copysize; + buffer += copysize; + remaining -= copysize; + + if (totalsize >= buflen) + { + return totalsize; + } +#endif + /* Show the thread state */ linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%s\n", "State:", diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index e7a8d5c26f..65722e23b0 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -222,6 +222,8 @@ typedef enum tstate_e tstate_t; #define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN #define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING +#define FIRST_ASSIGNED_STATE TSTATE_TASK_ASSIGNED +#define LAST_ASSIGNED_STATE TSTATE_TASK_RUNNING #define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE #define LAST_BLOCKED_STATE (NUM_TASK_STATES-1) -- GitLab From 72d39202952bb0fae1af703e4d488695e733be44 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 15:57:07 -0600 Subject: [PATCH 772/858] Rename cpuset_t to cpu_set_t which is the type used in some non-standard Linux/GNU interfaces. Move definitions of cpu_set_t to include/sys/types.h. Add prototypes for sched_setaffinity(), sched_getaffinity(), pthread_attr_setaffinity_np(), pthread_attr_getaffinity_np(), pthread_setaffinity_np(), and pthread_getaffinity_np(). No implementation is yet in place. --- ChangeLog | 8 +++++++- configs | 2 +- include/nuttx/spinlock.h | 18 ++++-------------- include/pthread.h | 19 +++++++++++++++++++ include/sched.h | 8 ++++++++ sched/irq/irq.h | 4 +++- sched/irq/irq_csection.c | 4 +++- sched/sched/sched.h | 2 +- sched/sched/sched_lock.c | 3 ++- sched/semaphore/spinlock.c | 5 +++-- 10 files changed, 51 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4506db9338..b0bb7c11e1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11498,4 +11498,10 @@ other way too, but this is more compliant with POSIX (2016-02-18). * fs/ procfs/fs_procfsproc.c: Add support for showing CPU if SMP is is enabled (2016-02-19). - + * include/pthread.h, sched.h, sys/types.h and other files: Rename + cpuset_t to cpu_set_t which is the type used in some non-standard + Linux/GNU interfaces. Move definitions of cpu_set_t to include/sys/types.h. + Add prototypes for sched_setaffinity(), sched_getaffinity(), + pthread_attr_setaffinity_np(), pthread_attr_getaffinity_np(), + pthread_setaffinity_np(), and pthread_getaffinity_np(). No implementation + is yet in place (2016-02-19). diff --git a/configs b/configs index d5a1be277d..82e43f4b00 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d5a1be277d62a97c5115175b55771841495dcde7 +Subproject commit 82e43f4b0032f3dff1de6c91863424caf6c770fd diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 9fadbb3784..3ce3391b01 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -41,6 +41,8 @@ ****************************************************************************/ #include + +#include #include #ifdef CONFIG_SPINLOCK @@ -73,18 +75,6 @@ struct spinlock_s #endif }; -/* This is the smallest integer type that will not a bitset of all CPUs */ - -#if (CONFIG_SMP_NCPUS <= 8) -typedef volatile uint8_t cpuset_t; -#elif (CONFIG_SMP_NCPUS <= 16) -typedef volatile uint16_t cpuset_t; -#elif (CONFIG_SMP_NCPUS <= 32) -typedef volatile uint32_t cpuset_t; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -286,7 +276,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); * ****************************************************************************/ -void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock); @@ -307,7 +297,7 @@ void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, * ****************************************************************************/ -void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock); diff --git a/include/pthread.h b/include/pthread.h index 00cd95772d..a949cf41f4 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -290,6 +290,16 @@ int pthread_attr_setinheritsched(FAR pthread_attr_t *attr, int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr, FAR int *inheritsched); +#ifdef CONFIG_SMP +/* Set or obtain thread affinity attributes */ + +int pthread_attr_setaffinity_np(FAR pthread_attr_t *attr, + size_t cpusetsize, + FAR const cpu_set_t *cpuset); +int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr, + size_t cpusetsize, cpu_set_t *cpuset); +#endif + /* Set or obtain the default stack size */ int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize); @@ -346,6 +356,15 @@ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_param *param); int pthread_setschedprio(pthread_t thread, int prio); +/* Thread affinity */ + +#ifdef CONFIG_SMP +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, + FAR const cpu_set_t *cpuset); +int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, + FAR cpu_set_t *cpuset); +#endif + /* Thread-specific Data Interfaces */ int pthread_key_create(FAR pthread_key_t *key, diff --git a/include/sched.h b/include/sched.h index f3b675da72..6f3a8115c4 100644 --- a/include/sched.h +++ b/include/sched.h @@ -131,6 +131,14 @@ int sched_get_priority_max(int policy); int sched_get_priority_min(int policy); int sched_rr_get_interval(pid_t pid, FAR struct timespec *interval); +#ifdef CONFIG_SMP +/* Task affinity */ + +int sched_setaffinity(pid_t pid, size_t cpusetsize, + FAR const cpu_set_t *mask); +int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask); +#endif + /* Task Switching Interfaces (non-standard) */ int sched_lock(void); diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 0e9357834c..36742f062b 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -68,7 +70,7 @@ extern volatile spinlock_t g_cpu_irqlock; /* Used to keep track of which CPU(s) hold the IRQ lock. */ extern volatile spinlock_t g_cpu_irqsetlock; -extern volatile cpuset_t g_cpu_irqset; +extern volatile cpu_set_t g_cpu_irqset; #endif /**************************************************************************** diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index fedf44b906..e2bb1d995f 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -39,6 +39,8 @@ #include +#include + #include #include @@ -59,7 +61,7 @@ volatile spinlock_t g_cpu_irqlock = SP_UNLOCKED; /* Used to keep track of which CPU(s) hold the IRQ lock. */ volatile spinlock_t g_cpu_irqsetlock; -volatile cpuset_t g_cpu_irqset; +volatile cpu_set_t g_cpu_irqset; /**************************************************************************** * Public Functions diff --git a/sched/sched/sched.h b/sched/sched/sched.h index ca701a8a83..32fe377532 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -358,7 +358,7 @@ extern volatile spinlock_t g_cpu_schedlock; /* Used to keep track of which CPU(s) hold the IRQ lock. */ extern volatile spinlock_t g_cpu_locksetlock; -extern volatile cpuset_t g_cpu_lockset; +extern volatile cpu_set_t g_cpu_lockset; #endif /* CONFIG_SMP */ diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index bf4bf86322..83ba4b8635 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -111,7 +112,7 @@ volatile spinlock_t g_cpu_schedlock = SP_UNLOCKED; /* Used to keep track of which CPU(s) hold the IRQ lock. */ volatile spinlock_t g_cpu_locksetlock; -volatile cpuset_t g_cpu_lockset; +volatile cpu_set_t g_cpu_lockset; #endif /* CONFIG_SMP */ diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index 38e7c23b26..79d904e7ef 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -312,7 +313,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) * ****************************************************************************/ -void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock) { @@ -347,7 +348,7 @@ void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, * ****************************************************************************/ -void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock) { -- GitLab From 2075eb7932ed33db3f34e42bdcd62c0c94d24de2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 16:03:01 -0600 Subject: [PATCH 773/858] Fix a typo introduced in the last commit and a file that was missed in the last commit --- include/nuttx/spinlock.h | 2 +- include/sys/types.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 3ce3391b01..544facfef9 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -42,7 +42,7 @@ #include -#include +#include #include #ifdef CONFIG_SPINLOCK diff --git a/include/sys/types.h b/include/sys/types.h index cc6672d2c0..a818cc2a80 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -244,6 +244,20 @@ typedef uint32_t clock_t; typedef uint32_t useconds_t; typedef int32_t suseconds_t; +#ifdef CONFIG_SMP +/* This is the smallest integer type that will hold a bitset of all CPUs */ + +#if (CONFIG_SMP_NCPUS <= 8) +typedef volatile uint8_t cpu_set_t; +#elif (CONFIG_SMP_NCPUS <= 16) +typedef volatile uint16_t cpu_set_t; +#elif (CONFIG_SMP_NCPUS <= 32) +typedef volatile uint32_t cpu_set_t; +#else +# error SMP: Extensions needed to support this number of CPUs +#endif +#endif /* CONFIG_SMP */ + /* BSD types provided only to support porting to NuttX. */ typedef unsigned char u_char; -- GitLab From a633353ec31c4e53bc45e87d90091c0a6bce4fac Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 17:33:35 -0600 Subject: [PATCH 774/858] Add a CPU affinity set to the TCB if SMP is enable and use this CPU set as a mask for determining which CPUs the thread may run on. Add an affinity field to the attrributes to permit controlling which CPUs a pthread may run on. Implements pthread_att_setaffinity_np() and pthread_attr_getaffinity_np(). --- ChangeLog | 8 +++ include/nuttx/pthread.h | 28 ++++++++++- include/nuttx/sched.h | 3 +- include/pthread.h | 4 ++ libc/pthread/Make.defs | 5 ++ libc/pthread/pthread_attrdestroy.c | 20 -------- libc/pthread/pthread_attrgetinheritsched.c | 20 -------- libc/pthread/pthread_attrgetschedpolicy.c | 20 -------- libc/pthread/pthread_attrgetstacksize.c | 20 -------- libc/pthread/pthread_attrinit.c | 16 ------ libc/pthread/pthread_attrsetinheritsched.c | 20 -------- libc/pthread/pthread_attrsetstacksize.c | 20 -------- libc/pthread/pthread_barrierattrdestroy.c | 20 -------- libc/pthread/pthread_barrierattrgetpshared.c | 20 -------- libc/pthread/pthread_barrierattrinit.c | 20 -------- libc/pthread/pthread_mutexattrdestroy.c | 20 -------- libc/pthread/pthread_mutexattrgetpshared.c | 20 -------- libc/pthread/pthread_mutexattrgettype.c | 20 -------- libc/pthread/pthread_mutexattrinit.c | 20 -------- libc/pthread/pthread_mutexattrsetpshared.c | 20 -------- libc/pthread/pthread_mutexattrsettype.c | 20 -------- sched/init/os_start.c | 28 +++++++++-- sched/pthread/pthread_create.c | 16 +++++- sched/sched/sched.h | 4 +- sched/sched/sched_addreadytorun.c | 16 +++--- sched/sched/sched_cpuselect.c | 48 +++++++++++------- sched/sched/sched_setpriority.c | 2 +- sched/task/task_setup.c | 51 ++++++++++++++++++-- 28 files changed, 174 insertions(+), 355 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0bb7c11e1..b882a7c254 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11505,3 +11505,11 @@ pthread_attr_setaffinity_np(), pthread_attr_getaffinity_np(), pthread_setaffinity_np(), and pthread_getaffinity_np(). No implementation is yet in place (2016-02-19). + * sched/sched_cpuselect.c, include/nuttx/sched.h, and other files. Add + a CPU affinity set to the TCB if SMP is enabled and use this CPU set as + a mask for determining which CPUs the thread may run on (2016-02-19). + * libc/pthread, sched/pthread/pthread_start.c, and include/pthread.h: + Add an affinity field to the attrributes to permit controlling + which CPUs a pthread may run on. Implements pthread_att_setaffinity_np() + and pthread_attr_getaffinity_np() (2016-02-19). + diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index eff079be74..54d5dc659b 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -57,7 +57,24 @@ # define PTHREAD_DEFAULT_POLICY SCHED_RR #endif -#ifdef CONFIG_SCHED_SPORADIC +/* A lot of hassle to use the old-fashioned struct initializers. But this + * gives us backward compatibility with some very old compilers. + */ + +#if defined(CONFIG_SCHED_SPORADIC) && defined(CONFIG_SMP) +# define PTHREAD_ATTR_INITIALIZER \ + { \ + PTHREAD_DEFAULT_PRIORITY, /* priority */ \ + PTHREAD_DEFAULT_POLICY, /* policy */ \ + PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \ + 0, /* low_priority */ \ + 0, /* max_repl */ \ + 0, /* affinity */ \ + PTHREAD_STACK_DEFAULT, /* stacksize */ \ + {0, 0}, /* repl_period */ \ + {0, 0} /* budget */ \ + } +#elif defined(CONFIG_SCHED_SPORADIC) # define PTHREAD_ATTR_INITIALIZER \ { \ PTHREAD_DEFAULT_PRIORITY, /* priority */ \ @@ -69,6 +86,15 @@ {0, 0}, /* repl_period */ \ {0, 0}, /* budget */ \ } +#elif defined(CONFIG_SMP) +# define PTHREAD_ATTR_INITIALIZER \ + { \ + PTHREAD_DEFAULT_PRIORITY, /* priority */ \ + PTHREAD_DEFAULT_POLICY, /* policy */ \ + PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \ + 0, /* affinity */ \ + PTHREAD_STACK_DEFAULT, /* stacksize */ \ + } #else # define PTHREAD_ATTR_INITIALIZER \ { \ diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 65722e23b0..b4f3d055fa 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -148,7 +148,7 @@ # define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */ # define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */ # define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */ -#define TCB_FLAG_CPU_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */ +#define TCB_FLAG_CPU_LOCKED (1 << 6) /* Bit 6: Locked to this CPU */ #define TCB_FLAG_EXIT_PROCESSING (1 << 7) /* Bit 7: Exitting */ /* Bits 8-15: Available */ @@ -562,6 +562,7 @@ struct tcb_s uint8_t task_state; /* Current state of the thread */ #ifdef CONFIG_SMP uint8_t cpu; /* CPU index if running or assigned */ + cpu_set_t affinity; /* Bit set of permitted CPUs */ #endif uint16_t flags; /* Misc. general status flags */ int16_t lockcount; /* 0=preemptable (not-locked) */ diff --git a/include/pthread.h b/include/pthread.h index a949cf41f4..438ec2805f 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -178,6 +178,10 @@ struct pthread_attr_s uint8_t max_repl; /* Maximum pending replenishments */ #endif +#ifdef CONFIG_SMP + cpu_set_t affinity; /* Set of permitted CPUs for the thread */ +#endif + size_t stacksize; /* Size of the stack allocated for the pthread */ #ifdef CONFIG_SCHED_SPORADIC diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs index a443a69969..8070197dd0 100644 --- a/libc/pthread/Make.defs +++ b/libc/pthread/Make.defs @@ -46,6 +46,11 @@ CSRCS += pthread_attrinit.c pthread_attrdestroy.c \ pthread_mutexattrinit.c pthread_mutexattrdestroy.c \ pthread_mutexattrgetpshared.c pthread_mutexattrsetpshared.c +ifeq ($(CONFIG_SMP),y) +CSRCS += pthread_attrgetaffinity.c pthread_attrsetaffinity.c +# CSRCS += pthread_getaffinity.c pthread_setaffinity.c +endif + ifeq ($(CONFIG_MUTEX_TYPES),y) CSRCS += pthread_mutexattrsettype.c pthread_mutexattrgettype.c endif diff --git a/libc/pthread/pthread_attrdestroy.c b/libc/pthread/pthread_attrdestroy.c index 22a7d8e894..04223f0e04 100644 --- a/libc/pthread/pthread_attrdestroy.c +++ b/libc/pthread/pthread_attrdestroy.c @@ -44,26 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrgetinheritsched.c b/libc/pthread/pthread_attrgetinheritsched.c index 5fad0456c2..c4c2838dae 100644 --- a/libc/pthread/pthread_attrgetinheritsched.c +++ b/libc/pthread/pthread_attrgetinheritsched.c @@ -44,26 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrgetschedpolicy.c b/libc/pthread/pthread_attrgetschedpolicy.c index ff67f5ad96..52a48a9504 100644 --- a/libc/pthread/pthread_attrgetschedpolicy.c +++ b/libc/pthread/pthread_attrgetschedpolicy.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrgetstacksize.c b/libc/pthread/pthread_attrgetstacksize.c index fc65f3d65f..ea95ec7328 100644 --- a/libc/pthread/pthread_attrgetstacksize.c +++ b/libc/pthread/pthread_attrgetstacksize.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrinit.c b/libc/pthread/pthread_attrinit.c index e40dfa81f4..e073fcd89f 100644 --- a/libc/pthread/pthread_attrinit.c +++ b/libc/pthread/pthread_attrinit.c @@ -46,14 +46,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -69,14 +61,6 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; #endif -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrsetinheritsched.c b/libc/pthread/pthread_attrsetinheritsched.c index 34d8ce277d..07506773ad 100644 --- a/libc/pthread/pthread_attrsetinheritsched.c +++ b/libc/pthread/pthread_attrsetinheritsched.c @@ -45,26 +45,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_attrsetstacksize.c b/libc/pthread/pthread_attrsetstacksize.c index 96379dd0e6..97769acd25 100644 --- a/libc/pthread/pthread_attrsetstacksize.c +++ b/libc/pthread/pthread_attrsetstacksize.c @@ -44,26 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_barrierattrdestroy.c b/libc/pthread/pthread_barrierattrdestroy.c index 55f735a1c2..98342e28c1 100644 --- a/libc/pthread/pthread_barrierattrdestroy.c +++ b/libc/pthread/pthread_barrierattrdestroy.c @@ -43,26 +43,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/libc/pthread/pthread_barrierattrgetpshared.c b/libc/pthread/pthread_barrierattrgetpshared.c index d64423499e..ce186f230a 100644 --- a/libc/pthread/pthread_barrierattrgetpshared.c +++ b/libc/pthread/pthread_barrierattrgetpshared.c @@ -43,26 +43,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/libc/pthread/pthread_barrierattrinit.c b/libc/pthread/pthread_barrierattrinit.c index 2deb60ba56..16c31922d7 100644 --- a/libc/pthread/pthread_barrierattrinit.c +++ b/libc/pthread/pthread_barrierattrinit.c @@ -43,26 +43,6 @@ #include #include -/******************************************************************************** - * Pre-processor Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Public Data - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - /******************************************************************************** * Public Functions ********************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrdestroy.c b/libc/pthread/pthread_mutexattrdestroy.c index c59478d880..60b50718c1 100644 --- a/libc/pthread/pthread_mutexattrdestroy.c +++ b/libc/pthread/pthread_mutexattrdestroy.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrgetpshared.c b/libc/pthread/pthread_mutexattrgetpshared.c index 97f69b0d77..586a1b203e 100644 --- a/libc/pthread/pthread_mutexattrgetpshared.c +++ b/libc/pthread/pthread_mutexattrgetpshared.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrgettype.c b/libc/pthread/pthread_mutexattrgettype.c index 240a157055..cc553c8350 100644 --- a/libc/pthread/pthread_mutexattrgettype.c +++ b/libc/pthread/pthread_mutexattrgettype.c @@ -43,26 +43,6 @@ #ifdef CONFIG_MUTEX_TYPES -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrinit.c b/libc/pthread/pthread_mutexattrinit.c index 17dbd9e849..b12b8a2994 100644 --- a/libc/pthread/pthread_mutexattrinit.c +++ b/libc/pthread/pthread_mutexattrinit.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrsetpshared.c b/libc/pthread/pthread_mutexattrsetpshared.c index 075820df52..82f20092bd 100644 --- a/libc/pthread/pthread_mutexattrsetpshared.c +++ b/libc/pthread/pthread_mutexattrsetpshared.c @@ -43,26 +43,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/pthread/pthread_mutexattrsettype.c b/libc/pthread/pthread_mutexattrsettype.c index b3f23f4da0..ef8b263686 100644 --- a/libc/pthread/pthread_mutexattrsettype.c +++ b/libc/pthread/pthread_mutexattrsettype.c @@ -43,26 +43,6 @@ #ifdef CONFIG_MUTEX_TYPES -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/init/os_start.c b/sched/init/os_start.c index b968bc8451..8858a58341 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -73,6 +73,16 @@ #endif #include "init/init.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SMP +/* This set of all CPUs */ + +# define SCHED_ALL_CPUS ((1 << CONFIG_SMP_NCPUS) - 1) +#endif /* CONFIG_SMP */ + /**************************************************************************** * Public Data ****************************************************************************/ @@ -452,19 +462,31 @@ void os_start(void) } /* Set the task flags to indicate that this is a kernel thread and, if - * configured for SMP, that this task is assigned to the correct CPU. + * configured for SMP, that this task is locked to this CPU. */ #ifdef CONFIG_SMP - g_idletcb[cpu].cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_ASSIGNED); + g_idletcb[cpu].cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_LOCKED); g_idletcb[cpu].cmn.cpu = cpu; #else g_idletcb[cpu].cmn.flags = TCB_FLAG_TTYPE_KERNEL; #endif - /* Set the IDLE task name */ +#ifdef CONFIG_SMP + /* Set the affinity mask to allow the thread to run on all CPUs. No, + * this IDLE thread can only run on its assigned CPU. That is + * enforced by the TCB_FLAG_CPU_LOCKED which overrides the affinity + * mask. This is essential because all tasks inherit the affinity + * mask from their parent and, ultimately, the parent of all tasks is + * the IDLE task. + */ + + g_idletcb[cpu].cmn.affinity = SCHED_ALL_CPUS; +#endif #if CONFIG_TASK_NAME_SIZE > 0 + /* Set the IDLE task name */ + # ifdef CONFIG_SMP snprintf(g_idletcb[cpu].cmn.name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", cpu); # else diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 3354067c31..52275b8e8d 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_create.c * - * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -404,6 +404,20 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, goto errout_with_join; } +#ifdef CONFIG_SMP + /* pthread_schedsetup() will set the affinity mask by inheriting the + * setting from the parent task. We need to override this setting + * with the value from the pthread attributes unless that value is + * zero: Zero is the default value and simply means to inherit the + * parent thread's affinity mask. + */ + + if ( attr->affinity != 0) + { + ptcb->cmn.affinity = attr->affinity; + } +#endif + /* Configure the TCB for a pthread receiving on parameter * passed by value */ diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 32fe377532..504c949e8c 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -417,11 +417,11 @@ void sched_sporadic_lowpriority(FAR struct tcb_s *tcb); #endif #ifdef CONFIG_SMP -int sched_cpu_select(void); +int sched_cpu_select(cpu_set_t affinity); # define sched_islocked(tcb) spin_islocked(&g_cpu_schedlock) #else # define sched_islocked(tcb) ((tcb)->lockcount > 0) -# define sched_cpu_select (0) +# define sched_cpu_select(a) (0) #endif diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 82b567856d..40017bb47b 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -176,9 +176,9 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) bool switched; bool doswitch; - /* Check if the blocked TCB is already assigned to a CPU */ + /* Check if the blocked TCB is locked to this CPU */ - if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + if ((btcb->flags & TCB_FLAG_CPU_LOCKED) != 0) { /* Yes.. that that is the CPU we must use */ @@ -190,7 +190,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * (possibly its IDLE task). */ - cpu = sched_cpu_select(); + cpu = sched_cpu_select(btcb->affinity); } /* Get the task currently running on the CPU (maybe the IDLE task) */ @@ -207,11 +207,11 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) task_state = TSTATE_TASK_RUNNING; } - /* If it will not be running, but is assigned to a CPU, then it will be in - * the asssigned state. + /* If it will not be running, but is locked to a CPU, then it will be in + * the assigned state. */ - else if ((btcb->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + else if ((btcb->flags & TCB_FLAG_CPU_LOCKED) != 0) { task_state = TSTATE_TASK_ASSIGNED; cpu = btcb->cpu; @@ -328,7 +328,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) &g_cpu_irqlock); } - /* If the following task is not assigned to this CPU, then it must + /* If the following task is not locked to this CPU, then it must * be moved to the g_readytorun list. Since it cannot be at the * head of the list, we can do this without invoking any heavy * lifting machinery. @@ -337,7 +337,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) DEBUGASSERT(btcb->flink != NULL); next = (FAR struct tcb_s *)btcb->flink; - if ((next->flags & TCB_FLAG_CPU_ASSIGNED) != 0) + if ((next->flags & TCB_FLAG_CPU_LOCKED) != 0) { DEBUGASSERT(next->cpu == cpu); next->task_state = TSTATE_TASK_ASSIGNED; diff --git a/sched/sched/sched_cpuselect.c b/sched/sched/sched_cpuselect.c index 7bebc89424..efd5c8417b 100644 --- a/sched/sched/sched_cpuselect.c +++ b/sched/sched/sched_cpuselect.c @@ -48,6 +48,12 @@ #ifdef CONFIG_SMP +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define IMPOSSIBLE_CPU 0xff + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -60,7 +66,7 @@ * possbily its IDLE task. * * Inputs: - * None + * affinity - The set of CPUs on which the thread is permitted to run. * * Return Value: * Index of the CPU with the lowest priority running task @@ -70,7 +76,7 @@ * ****************************************************************************/ -int sched_cpu_select(void) +int sched_cpu_select(cpu_set_t affinity) { uint8_t minprio; int cpu; @@ -81,32 +87,38 @@ int sched_cpu_select(void) */ minprio = SCHED_PRIORITY_MAX; - cpu = 0; + cpu = IMPOSSIBLE_CPU; for (i = 0; i < CONFIG_SMP_NCPUS; i++) { - FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_assignedtasks[i].head; + /* If the thread permitted to run on this CPU? */ - /* If this thread is executing its IDLE task, the use it. The IDLE - * task is always the last task in the assigned task list. - */ - - if (rtcb->flink == NULL) + if ((affinity & (1 << i)) != 0) { - /* The IDLE task should always be assigned to this CPU and have - * a priority of zero. + FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_assignedtasks[i].head; + + /* If this thread is executing its IDLE task, the use it. The + * IDLE task is always the last task in the assigned task list. */ - DEBUGASSERT(rtcb->sched_priority == 0); - return i; - } - else if (rtcb->sched_priority < minprio) - { - DEBUGASSERT(rtcb->sched_priority > 0); - cpu = i; + if (rtcb->flink == NULL) + { + /* The IDLE task should always be assigned to this CPU and have + * a priority of zero. + */ + + DEBUGASSERT(rtcb->sched_priority == 0); + return i; + } + else if (rtcb->sched_priority < minprio) + { + DEBUGASSERT(rtcb->sched_priority > 0); + cpu = i; + } } } + DEBUGASSERT(cpu != IMPOSSIBLE_CPU); return cpu; } diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 2661edcf71..ba969eb13f 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -131,7 +131,7 @@ static void sched_readytorun_setpriority(FAR struct tcb_s *tcb, if (tcb->task_state == TSTATE_TASK_READYTORUN) { - cpu = sched_cpu_select(); + cpu = sched_cpu_select(tcb->affinity); } /* CASE 2b. The task is ready to run, and assigned to a CPU. An increase diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index ee87fd93a9..619a81819d 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_setup.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,6 +146,38 @@ static int task_assignpid(FAR struct tcb_s *tcb) return ERROR; } +/**************************************************************************** + * Name: task_inherit_affinity + * + * Description: + * exec(), task_create(), and vfork() all inherit the affinity mask from + * the parent thread. This is the default for pthread_create() as well + * but the affinity mask can be specified in the pthread attributes as + * well. pthread_setup() will have to fix up the affinity mask in this + * case. + * + * Parameters: + * tcb - The TCB of the new task. + * + * Returned Value: + * None + * + * Assumptions: + * The parent of the new task is the task at the head of the ready-to-run + * list. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +static inline void task_inherit_affinity(FAR struct tcb_s *tcb) +{ + FAR struct tcb_s *rtcb = this_task(); + tcb->affinity = rtcb->affinity; +} +#else +# define task_inherit_affinity(tcb) +#endif + /**************************************************************************** * Name: task_saveparent * @@ -348,11 +380,22 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority, task_saveparent(tcb, ttype); +#ifdef CONFIG_SMP + /* exec(), task_create(), and vfork() all inherit the affinity mask + * from the parent thread. This is the default for pthread_create() + * as well but the affinity mask can be specified in the pthread + * attributes as well. pthread_create() will have to fix up the + * affinity mask in this case. + */ + + task_inherit_affinity(tcb); +#endif + +#ifndef CONFIG_DISABLE_SIGNALS /* exec(), pthread_create(), task_create(), and vfork() all * inherit the signal mask of the parent thread. */ -#ifndef CONFIG_DISABLE_SIGNALS (void)sigprocmask(SIG_SETMASK, NULL, &tcb->sigprocmask); #endif @@ -628,8 +671,8 @@ int task_schedsetup(FAR struct task_tcb_s *tcb, int priority, start_t start, ****************************************************************************/ #ifndef CONFIG_DISABLE_PTHREAD -int pthread_schedsetup(FAR struct pthread_tcb_s *tcb, int priority, start_t start, - pthread_startroutine_t entry) +int pthread_schedsetup(FAR struct pthread_tcb_s *tcb, int priority, + start_t start, pthread_startroutine_t entry) { /* Perform common thread setup */ -- GitLab From 28d138c5841dfcf71f115c2dd3317b6b36c8c8cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 17:58:47 -0600 Subject: [PATCH 775/858] Add files that I forgot to add in the last commit --- libc/pthread/pthread_attrgetaffinity.c | 74 +++++++++++++++++++++++++ libc/pthread/pthread_attrsetaffinity.c | 77 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 libc/pthread/pthread_attrgetaffinity.c create mode 100644 libc/pthread/pthread_attrsetaffinity.c diff --git a/libc/pthread/pthread_attrgetaffinity.c b/libc/pthread/pthread_attrgetaffinity.c new file mode 100644 index 0000000000..f77d267cac --- /dev/null +++ b/libc/pthread/pthread_attrgetaffinity.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * libc/pthread/pthread_attrgetaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_getaffinity + * + * Description: + * + * Parameters: + * attr + * cpuset + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr, + size_t cpusetsize, cpu_set_t *cpuset) +{ + sdbg("attr=0x%p cpusetsize=%d cpuset=0x%p\n", attr, (int)cpusetsize, cpuset); + + DEBUGASSERT(attr != NULL && cpusetsize == sizeof(cpu_set_t) && cpuset != NULL); + + *cpuset = attr->affinity; + return OK; +} diff --git a/libc/pthread/pthread_attrsetaffinity.c b/libc/pthread/pthread_attrsetaffinity.c new file mode 100644 index 0000000000..200711dea1 --- /dev/null +++ b/libc/pthread/pthread_attrsetaffinity.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * libc/pthread/pthread_attrsetaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_setaffinity + * + * Description: + * + * Parameters: + * attr + * stacksize + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setaffinity_np(FAR pthread_attr_t *attr, + size_t cpusetsize, + FAR const cpu_set_t *cpuset) +{ + sdbg("attr=0x%p cpusetsize=%d cpuset=0x%p\n", attr, (int)cpusetsize, cpuset); + + DEBUGASSERT(attr != NULL && cpusetsize == sizeof(cpu_set_t) && + cpuset != NULL && *cpuset != 0); + + attr->affinity = *cpuset; + return OK; +} -- GitLab From 1b5e296cf23ade33376175d88ca6d9f4fea7895e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 17:59:19 -0600 Subject: [PATCH 776/858] Add pthread_setaffinity() and pthread_getaffinity() --- ChangeLog | 2 + sched/pthread/Make.defs | 4 ++ sched/pthread/pthread_getaffinity.c | 103 +++++++++++++++++++++++++++ sched/pthread/pthread_setaffinity.c | 105 ++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 sched/pthread/pthread_getaffinity.c create mode 100644 sched/pthread/pthread_setaffinity.c diff --git a/ChangeLog b/ChangeLog index b882a7c254..b2241a7590 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11512,4 +11512,6 @@ Add an affinity field to the attrributes to permit controlling which CPUs a pthread may run on. Implements pthread_att_setaffinity_np() and pthread_attr_getaffinity_np() (2016-02-19). + * sched/pthread: Add pthread_setaffinity() and pthread_getaffinity() + (2016-02-19). diff --git a/sched/pthread/Make.defs b/sched/pthread/Make.defs index 89272b14b2..be0c9c1ae2 100644 --- a/sched/pthread/Make.defs +++ b/sched/pthread/Make.defs @@ -51,6 +51,10 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y) CSRCS += pthread_condtimedwait.c pthread_kill.c pthread_sigmask.c endif +ifeq ($(CONFIG_SMP),y) +CSRCS += pthread_setaffinity.c pthread_getaffinity.c +endif + # Include pthread build support DEPPATH += --dep-path pthread diff --git a/sched/pthread/pthread_getaffinity.c b/sched/pthread/pthread_getaffinity.c new file mode 100644 index 0000000000..04d1921910 --- /dev/null +++ b/sched/pthread/pthread_getaffinity.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * pthread_getaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "pthread/pthread.h" + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_getschedparam + * + * Description: + * The pthread_getaffinity_np() function returns the CPU affinity mask + * of the thread thread in the buffer pointed to by cpuset. + * + * The argument cpusetsize is the length (in bytes) of the buffer + * pointed to by cpuset. Typically, this argument would be specified as + * sizeof(cpu_set_t). + * + * Parameters: + * thread - The ID of thread whose affinity set will be retrieved. + * cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t(). + * cpuset - The location to return the thread's new affinity set. + * + * Return Value: + * 0 if successful. Otherwise, an errno value is returned indicating the + * nature of the failure. + * + ****************************************************************************/ + +int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, + FAR cpu_set_t *cpuset) +{ + int ret; + + sdbg("thread ID=%d cpusetsize=%d cpuset=%p\n", + (int)thread, (int)cpusetsize, cpusetsize); + + DEBUGASSERT(thread > 0 && cpusetsize == sizeof(cpu_set_t) && + cpuset != NULL); + + /* Let sched_getaffinity do all of the work */ + + ret = sched_getaffinity((pid_t)thread, cpusetsize, cpuset); + if (ret < 0) + { + /* If sched_getaffinity() fails, return the errno */ + + ret = get_errno(); + DEBUGASSERT(ret > 0); + } + + return ret; +} + +#endif /* CONFIG_SMP */ diff --git a/sched/pthread/pthread_setaffinity.c b/sched/pthread/pthread_setaffinity.c new file mode 100644 index 0000000000..3948bf9025 --- /dev/null +++ b/sched/pthread/pthread_setaffinity.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * sched/pthread/pthread_setaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "pthread/pthread.h" + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_setaffinity + * + * Description: + * The pthread_setaffinity_np() function sets the CPU affinity mask of + * the thread thread to the CPU set pointed to by cpuset. If the call + * is successful, and the thread is not currently running on one of the + * CPUs in cpuset, then it is migrated to one of those CPUs. + + * The argument cpusetsize is the length (in bytes) of the buffer + * pointed to by cpuset. Typically, this argument would be specified as + * sizeof(cpu_set_t). + * + * Parameters: + * thread - The ID of thread whose affinity set will be modified. + * cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t(). + * cpuset - Provides the new affinity set for the thread. + * + * Return Value: + * 0 if successful. Otherwise, an errno value is returned indicating the + * nature of the failure. + * + ****************************************************************************/ + +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, + FAR const cpu_set_t *cpuset) +{ + int ret; + + sdbg("thread ID=%d cpusetsize=%d cpuset=%p\n", + (int)thread, (int)cpusetsize, cpusetsize); + + DEBUGASSERT(thread > 0 && cpusetsize == sizeof(cpu_set_t) && + cpuset != NULL); + + /* Let sched_setaffinity do all of the work */ + + ret = sched_setaffinity((pid_t)thread, cpusetsize, cpuset); + if (ret < 0) + { + /* If sched_setaffinity() fails, return the errno */ + + ret = get_errno(); + DEBUGASSERT(ret > 0); + } + + return ret; +} + +#endif /* CONFIG_SMP */ -- GitLab From 5a590e99b90bd2a8a933a003f725bc51fb2080e1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 18:13:06 -0600 Subject: [PATCH 777/858] Add SYSCALLS for pthread_setaffinity() and pthread_getaffinity() --- include/pthread.h | 8 ++------ include/sys/syscall.h | 20 ++++++++++++++------ sched/pthread/Make.defs | 2 +- syscall/syscall.csv | 2 ++ syscall/syscall_lookup.h | 6 +++++- syscall/syscall_stublookup.c | 7 ++++++- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index 438ec2805f..67851fd013 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -1,7 +1,7 @@ /******************************************************************************** * include/pthread.h * - * Copyright (C) 2007-2009, 2011-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -259,14 +259,10 @@ typedef struct pthread_barrier_s pthread_barrier_t; typedef bool pthread_once_t; #define __PTHREAD_ONCE_T_DEFINED 1 -/* Forware references */ +/* Forward references */ struct sched_param; /* Defined in sched.h */ -/******************************************************************************** - * Public Data - ********************************************************************************/ - /******************************************************************************** * Public Function Prototypes ********************************************************************************/ diff --git a/include/sys/syscall.h b/include/sys/syscall.h index c7d9b086c4..198b27c953 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -2,7 +2,7 @@ * include/sys/syscall.h * This file contains the system call numbers. * - * Copyright (C) 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -377,13 +377,21 @@ # define SYS_pthread_setspecific (__SYS_pthread+26) # define SYS_pthread_yield (__SYS_pthread+27) +# ifndef CONFIG_SMP +# define SYS_pthread_setaffinity_np (__SYS_pthread+28) +# define SYS_pthread_getaffinity_np (__SYS_pthread+29) +# define __SYS_pthread_signals (__SYS_pthread+30) +# else +# define __SYS_pthread_signals (__SYS_pthread+28) +# endif + # ifndef CONFIG_DISABLE_SIGNALS -# define SYS_pthread_cond_timedwait (__SYS_pthread+28) -# define SYS_pthread_kill (__SYS_pthread+29) -# define SYS_pthread_sigmask (__SYS_pthread+30) -# define __SYS_mqueue (__SYS_pthread+31) +# define SYS_pthread_cond_timedwait (__SYS_pthread_signals+0) +# define SYS_pthread_kill (__SYS_pthread_signals+1) +# define SYS_pthread_sigmask (__SYS_pthread_signals+2) +# define __SYS_mqueue (__SYS_pthread_signals+3) # else -# define __SYS_mqueue (__SYS_pthread+28) +# define __SYS_mqueue __SYS_pthread_signals # endif #else diff --git a/sched/pthread/Make.defs b/sched/pthread/Make.defs index be0c9c1ae2..d27938aa37 100644 --- a/sched/pthread/Make.defs +++ b/sched/pthread/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # sched/pthread/Make.defs # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/syscall/syscall.csv b/syscall/syscall.csv index b20a2aca97..a7d8121535 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -72,6 +72,7 @@ "pthread_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_t*","FAR const pthread_attr_t*","pthread_startroutine_t","pthread_addr_t" "pthread_detach","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t" "pthread_exit","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void","pthread_addr_t" +"pthread_getaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR cpu_set_t*" "pthread_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR int*","FAR struct sched_param*" "pthread_getspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","FAR void*","pthread_key_t" "pthread_join","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR pthread_addr_t*" @@ -84,6 +85,7 @@ "pthread_mutex_trylock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*" "pthread_mutex_unlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*" "pthread_once","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_once_t*","CODE void (*)(void)" +"pthread_setaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR const cpu_set_t*" "pthread_setcancelstate","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","int","FAR int*" "pthread_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int","FAR const struct sched_param*" "pthread_setschedprio","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 6ad246ba5b..8fb2f507b0 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -1,7 +1,7 @@ /**************************************************************************** * syscall/syscall_lookup.h * - * Copyright (C) 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -278,6 +278,10 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) SYSCALL_LOOKUP(pthread_setschedprio, 2, STUB_pthread_setschedprio) SYSCALL_LOOKUP(pthread_setspecific, 2, STUB_pthread_setspecific) SYSCALL_LOOKUP(pthread_yield, 0, STUB_pthread_yield) +# ifdef CONFIG_SMP + SYSCALL_LOOKUP(pthread_setaffinity, 3, STUB_pthread_setaffinity) + SYSCALL_LOOKUP(pthread_getaffinity, 3, STUB_pthread_getaffinity) +# endif # ifndef CONFIG_DISABLE_SIGNALS SYSCALL_LOOKUP(pthread_cond_timedwait, 3, STUB_pthread_cond_timedwait) SYSCALL_LOOKUP(pthread_kill, 2, STUB_pthread_kill) diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index ed151d246b..63af75eb40 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -1,7 +1,7 @@ /**************************************************************************** * syscall/syscall_stublookup.c * - * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -290,6 +290,11 @@ uintptr_t STUB_pthread_setspecific(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_pthread_yield(int nbr); +uintptr_t STUB_pthread_setaffinity(int nbr, uintptr_t parm1, + uintptr_t parm2, uintptr_t parm3); +uintptr_t STUB_pthread_getaffinity(int nbr, uintptr_t parm1, + uintptr_t parm2, uintptr_t parm3); + uintptr_t STUB_pthread_cond_timedwait(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); uintptr_t STUB_pthread_kill(int nbr, uintptr_t parm1, uintptr_t parm2); -- GitLab From 883a1adfe2d59a7a7ffa8d6e503ea933f84bce06 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 19:18:54 -0600 Subject: [PATCH 778/858] Implement sched_setaffinity() and sched_getaffinity() --- ChangeLog | 1 + libc/pthread/Make.defs | 1 - sched/sched/Make.defs | 2 +- sched/sched/sched_getaffinity.c | 104 ++++++++++++++++++++ sched/sched/sched_getparam.c | 24 ----- sched/sched/sched_getscheduler.c | 24 ----- sched/sched/sched_gettcb.c | 20 ---- sched/sched/sched_setaffinity.c | 163 +++++++++++++++++++++++++++++++ sched/sched/sched_verifytcb.c | 20 ---- sched/sched/sched_wait.c | 4 - 10 files changed, 269 insertions(+), 94 deletions(-) create mode 100644 sched/sched/sched_getaffinity.c create mode 100644 sched/sched/sched_setaffinity.c diff --git a/ChangeLog b/ChangeLog index b2241a7590..ff70a64918 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11514,4 +11514,5 @@ and pthread_attr_getaffinity_np() (2016-02-19). * sched/pthread: Add pthread_setaffinity() and pthread_getaffinity() (2016-02-19). + * sched/sched: Add sched_setaffinity() and sched_getaffinity() (2016-02-19). diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs index 8070197dd0..44a2d8b2d6 100644 --- a/libc/pthread/Make.defs +++ b/libc/pthread/Make.defs @@ -48,7 +48,6 @@ CSRCS += pthread_attrinit.c pthread_attrdestroy.c \ ifeq ($(CONFIG_SMP),y) CSRCS += pthread_attrgetaffinity.c pthread_attrsetaffinity.c -# CSRCS += pthread_getaffinity.c pthread_setaffinity.c endif ifeq ($(CONFIG_MUTEX_TYPES),y) diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index 3c521a25d7..aa806b95aa 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -48,7 +48,7 @@ CSRCS += sched_reprioritize.c endif ifeq ($(CONFIG_SMP),y) -CSRCS += sched_cpuselect.c +CSRCS += sched_getaffinity.c sched_setaffinity.c sched_cpuselect.c endif ifeq ($(CONFIG_SCHED_WAITPID),y) diff --git a/sched/sched/sched_getaffinity.c b/sched/sched/sched_getaffinity.c new file mode 100644 index 0000000000..e7d355b50f --- /dev/null +++ b/sched/sched/sched_getaffinity.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * sched/sched/sched_getaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "sched/sched.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_getscheduler + * + * Description: + * sched_getaffinity() writes the affinity mask of the thread whose ID + * is pid into the cpu_set_t pointed to by mask. The cpusetsize + * argument specifies the size (in bytes) of mask. If pid is zero, then + * the mask of the calling thread is returned. + * + * Inputs: + * pid - The ID of thread whose affinity set will be retrieved. + * cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t(). + * cpuset - The location to return the thread's new affinity set. + * + * Return Value: + * 0 if successful. Otherwise, ERROR (-1) is returned, and errno is + * set appropriately: + * + * ESRCH The task whose ID is pid could not be found. + * + ****************************************************************************/ + +int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask) +{ + FAR struct tcb_s *tcb; + + DEBUGASSERT(cpusetsize == sizeof(cpu_set_t) && mask != NULL); + + /* Verify that the PID corresponds to a real task */ + + sched_lock(); + if (!pid) + { + tcb = this_task(); + } + else + { + tcb = sched_gettcb(pid); + } + + if (tcb == NULL) + { + set_errno(ESRCH); + return ERROR; + } + + /* Return the affinity mask from the TCB. */ + + *mask = tcb->affinity; + sched_unlock(); + return OK; +} diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 0ab047f984..155049ff1f 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -45,30 +45,6 @@ #include "clock/clock.h" #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index a1afddf28e..47ba73fa9c 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -47,30 +47,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_gettcb.c b/sched/sched/sched_gettcb.c index 83de9358c7..a5fc20c278 100644 --- a/sched/sched/sched_gettcb.c +++ b/sched/sched/sched_gettcb.c @@ -43,26 +43,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_setaffinity.c b/sched/sched/sched_setaffinity.c new file mode 100644 index 0000000000..c2d50af146 --- /dev/null +++ b/sched/sched/sched_setaffinity.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * sched/sched/sched_setaffinity.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "sched/sched.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_getscheduler + * + * Description: + * sched_setaffinity() sets the CPU affinity mask of the thread whose ID + * is pid to the value specified by mask. If pid is zero, then the + * calling thread is used. The argument cpusetsize is the length (i + * bytes) of the data pointed to by mask. Normally this argument would + * be specified as sizeof(cpu_set_t). + * + * If the thread specified by pid is not currently running on one of the + * CPUs specified in mask, then that thread is migrated to one of the + * CPUs specified in mask. + * + * Inputs: + * pid - The ID of thread whose affinity set will be modified. + * cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t(). + * cpuset - The location to return the thread's new affinity set. + * + * Return Value: + * 0 if successful. Otherwise, ERROR (-1) is returned, and errno is + * set appropriately: + * + * ESRCH The task whose ID is pid could not be found. + * + ****************************************************************************/ + +int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask) +{ + FAR struct tcb_s *tcb; + irqstate_t flags; + int errcode = 0; + int ret; + + DEBUGASSERT(cpusetsize == sizeof(cpu_set_t) && mask != NULL); + + /* Verify that the PID corresponds to a real task */ + + sched_lock(); + if (!pid) + { + tcb = this_task(); + } + else + { + tcb = sched_gettcb(pid); + } + + if (tcb == NULL) + { + errcode = ESRCH; + goto errout_with_lock; + } + + /* Don't permit changing the affinity mask of any task locked to a CPU + * (i.e., an IDLE task) + */ + + flags = enter_critical_section(); + if ((tcb->flags & TCB_FLAG_CPU_LOCKED) != 0) + { + errcode = EINVAL; + goto errout_with_csection; + } + + /* Set the new affinity mask. */ + + tcb->affinity = *mask; + + /* Is the task still executing a a CPU in its affinity mask? Will this + * change cause the task to be removed from its current assigned task + * list? + * + * First... is the task in an assigned task list? + */ + + if (tcb->task_state >= FIRST_ASSIGNED_STATE && + tcb->task_state <= LAST_ASSIGNED_STATE) + { + /* Yes... is the CPU associated with the assigned task in the new + * affinity mask? + */ + + if ((tcb->affinity & (1 << tcb->cpu)) == 0) + { + /* No.. then we will need to move the task from the the assigned + * task list to some other ready to run list. + * + * sched_setpriority() will do just what we want... it will remove + * the task from its current position in the some assigned task list + * and then simply put it back in the right place. This works even + * if the task is this task. + */ + + ret = sched_setpriority(tcb, tcb->sched_priority); + if (ret < 0) + { + errcode = get_errno(); + } + } + } + +errout_with_csection: + leave_critical_section(flags); +errout_with_lock: + sched_unlock(); + set_errno(errcode); + return ERROR; +} diff --git a/sched/sched/sched_verifytcb.c b/sched/sched/sched_verifytcb.c index 31ff091884..5958b28e0c 100644 --- a/sched/sched/sched_verifytcb.c +++ b/sched/sched/sched_verifytcb.c @@ -44,26 +44,6 @@ #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/sched/sched/sched_wait.c b/sched/sched/sched_wait.c index 553ec529dd..d1547e07cf 100644 --- a/sched/sched/sched_wait.c +++ b/sched/sched/sched_wait.c @@ -49,10 +49,6 @@ #if defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT) -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From c929db42f9a171f752b6e9f9c6cc2f6b9545d4c4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 20 Feb 2016 08:07:54 -0600 Subject: [PATCH 779/858] Fix some bad SMP logic in sched_removereadytorun.c --- sched/sched/sched_addreadytorun.c | 2 +- sched/sched/sched_removereadytorun.c | 161 +++++++++++++++++++++------ 2 files changed, 127 insertions(+), 36 deletions(-) diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 40017bb47b..a105e4f545 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -369,7 +369,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) btcb->task_state = TSTATE_TASK_ASSIGNED; } - /* All done, restart the other that CPU. */ + /* All done, restart the other CPU (if it was paused). */ if (cpu != me) { diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index ab16d4e199..19e6cbed1f 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -72,15 +72,84 @@ * ****************************************************************************/ +#ifndef CONFIG_SMP bool sched_removereadytorun(FAR struct tcb_s *rtcb) { - FAR dq_queue_t *tasklist; - bool ret = false; + bool doswitch = false; + + /* Check if the TCB to be removed is at the head of the ready to run list. + * There is only one list, g_readytorun, and it always contains the + * currently running task. If we are removing the head of this list, + * then we are removing the currently active task. + */ + + if (rtcb->blink == NULL) + { + /* There must always be at least one task in the list (the IDLE task) + * after the TCB being removed. + */ + + FAR struct tcb_s *ntcb = (FAR struct tcb_s *)rtcb->flink; + DEBUGASSERT(ntcb != NULL); + + /* Inform the instrumentation layer that we are switching tasks */ + + sched_note_switch(rtcb, ntcb); + ntcb->task_state = TSTATE_TASK_RUNNING; + doswitch = true; + } + + /* Remove the TCB from the ready-to-run list. In the non-SMP case, this + * is always the g_readytorun list. + */ - /* Check if the TCB to be removed is at the head of a ready to run list. */ + dq_rem((FAR dq_entry_t *)rtcb, (FAR dq_queue_t *)&g_readytorun); + + /* Since the TCB is not in any list, it is now invalid */ + + rtcb->task_state = TSTATE_TASK_INVALID; + return doswitch; +} +#endif /* !CONFIG_SMP */ + +/**************************************************************************** + * Name: sched_removereadytorun + * + * Description: + * This function removes a TCB from the ready to run list. + * + * Inputs: + * rtcb - Points to the TCB that is ready-to-run + * + * Return Value: + * true if the currently active task (the head of the ready-to-run list) + * has changed. + * + * Assumptions: + * - The caller has established a critical section before calling this + * function (calling sched_lock() first is NOT a good idea -- use + * enter_critical_section()). + * - The caller handles the condition that occurs if the head of the + * ready-to-run list is changed. + * + ****************************************************************************/ #ifdef CONFIG_SMP - /* For the case of SMP, there are two lists involved: (1) the +bool sched_removereadytorun(FAR struct tcb_s *rtcb) +{ + FAR dq_queue_t *tasklist; + bool doswitch = false; + int cpu; + + /* Which CPU (if any) is the task running on? Which task list holds the + * TCB? + */ + + cpu = rtcb->cpu; + tasklist = TLIST_HEAD(rtcb->task_state, cpu); + + /* Check if the TCB to be removed is at the head of a ready to run list. + * For the case of SMP, there are two lists involved: (1) the * g_readytorun list that holds non-running tasks that have not been * assigned to a CPU, and (2) and the g_assignedtasks[] lists which hold * tasks assigned a CPU, including the task that is currently running on @@ -94,21 +163,27 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) */ if (rtcb->blink == NULL && TLIST_ISRUNNABLE(rtcb->task_state)) -#else - /* There is only one list, g_readytorun, and it always contains the - * currently running task. If we are removing the head of this list, - * then we are removing the currently active task. - */ - - if (rtcb->blink == NULL) -#endif { - /* There must always be at least one task in the list (the idle task) */ + FAR struct tcb_s *ntcb; + int me; - FAR struct tcb_s *ntcb = (FAR struct tcb_s *)rtcb->flink; + /* There must always be at least one task in the list (the IDLE task) + * after the TCB being removed. + */ + + ntcb = (FAR struct tcb_s *)rtcb->flink; DEBUGASSERT(ntcb != NULL); -#ifdef CONFIG_SMP + /* If we are modifying the head of some assigned task list other than + * our own, we will need to stop that CPU. + */ + + me = this_cpu(); + if (cpu != me) + { + DEBUGVERIFY(up_cpu_pause(cpu)); + } + /* Will pre-emption be disabled after the switch? If the lockcount is * greater than zero, then this task/this CPU holds the scheduler lock. */ @@ -117,18 +192,18 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { /* Yes... make sure that scheduling logic knows about this */ - spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_setbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } else { /* No.. we may need to perform release our hold on the lock. */ - spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_clrbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } - /* Interrupts be disabled after the switch. If irqcount is greater + /* Interrupts may be disabled after the switch. If irqcount is greater * than zero, then this task/this CPU holds the IRQ lock */ @@ -136,40 +211,56 @@ bool sched_removereadytorun(FAR struct tcb_s *rtcb) { /* Yes... make sure that scheduling logic knows about this */ - spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } else { /* No.. we may need to perform release our hold on the lock. */ - spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } -#endif /* Inform the instrumentation layer that we are switching tasks */ sched_note_switch(rtcb, ntcb); ntcb->task_state = TSTATE_TASK_RUNNING; - ret = true; - } - /* Remove the TCB from the ready-to-run list. In the non-SMP case, this - * is always the g_readytorun list; In the SMP case, however, this may be - * either the g_readytorun() or the g_assignedtasks[cpu] list. - */ + /* The task is running but the CPU that it was running on has been + * paused. We can now safely remove its TCB from the ready-to-run + * task list. In the SMP case this may be either the g_readytorun() + * or the g_assignedtasks[cpu] list. + */ -#ifdef CONFIG_SMP - tasklist = TLIST_HEAD(rtcb->task_state, rtcb->cpu); -#else - tasklist = (FAR dq_queue_t *)&g_readytorun; -#endif + dq_rem((FAR dq_entry_t *)rtcb, tasklist); - dq_rem((FAR dq_entry_t *)rtcb, tasklist); + /* All done, restart the other CPU (if it was paused). */ - /* Since the TCB is not in any list, it is now invalid */ + doswitch = true; + if (cpu != me) + { + /* In this we will not want to report a context switch to this + * CPU. Only the other CPU is affected. + */ + + DEBUGVERIFY(up_cpu_resume(cpu)); + doswitch = false; + } + } + else + { + /* The task is not running. Just remove its TCB from the ready-to-run + * list. In the SMP case this may be either the g_readytorun() or the + * g_assignedtasks[cpu] list. + */ + + dq_rem((FAR dq_entry_t *)rtcb, tasklist); + } + + /* Since the TCB is no longer in any list, it is now invalid */ rtcb->task_state = TSTATE_TASK_INVALID; - return ret; + return doswitch; } +#endif /* CONFIG_SMP */ -- GitLab From df3111f1091e7eab07c6400ed37c2a4fc01e187e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 20 Feb 2016 10:21:08 -0600 Subject: [PATCH 780/858] Update README --- Documentation | 2 +- README.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation b/Documentation index d03dc1e3e3..ae853e5f4f 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit d03dc1e3e320d6822211bc99101f1828fee49df8 +Subproject commit ae853e5f4f26a3e91f715c9a4d35fe223b2e49a1 diff --git a/README.txt b/README.txt index 0f3949ac6d..aa93873503 100644 --- a/README.txt +++ b/README.txt @@ -1548,6 +1548,8 @@ apps/ | |- json/README.txt | |- pashello/README.txt | `- README.txt + |- gpsutils/ + | `- minmea/README.txt |- graphics/ | `- tiff/README.txt |- interpreters/ -- GitLab From 0eadf1dcad1cc83180771b69a742e73542f56c22 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 20 Feb 2016 14:57:05 -0600 Subject: [PATCH 781/858] Costmetic change + update submodules --- arch | 2 +- configs | 2 +- include/pthread.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 0dd769aeea..15236a5b07 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0dd769aeeaa882e4d8934414471f163c985823e6 +Subproject commit 15236a5b07c6f5d254ccdc8478c613a5c21e4296 diff --git a/configs b/configs index 82e43f4b00..24d0c13b63 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 82e43f4b0032f3dff1de6c91863424caf6c770fd +Subproject commit 24d0c13b63d15b148c2be12b9e6dd685ed34c4c0 diff --git a/include/pthread.h b/include/pthread.h index 67851fd013..b2ebffda45 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -356,9 +356,9 @@ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_param *param); int pthread_setschedprio(pthread_t thread, int prio); +#ifdef CONFIG_SMP /* Thread affinity */ -#ifdef CONFIG_SMP int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, FAR const cpu_set_t *cpuset); int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, -- GitLab From f3356fee5b321ca5ef525512acb575cffc11bf70 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 20 Feb 2016 18:45:07 -0600 Subject: [PATCH 782/858] SMP: Add macros to CPU set manipulation to sched.h --- include/sched.h | 110 +++++++++++++++++++++++++++++++++++- libc/sched/Make.defs | 4 ++ libc/sched/sched_cpucount.c | 81 ++++++++++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 libc/sched/sched_cpucount.c diff --git a/include/sched.h b/include/sched.h index 6f3a8115c4..8733b8f46c 100644 --- a/include/sched.h +++ b/include/sched.h @@ -66,6 +66,113 @@ #define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS +/* CPU affinity mask helpers ***************************************************/ + +#ifdef CONFIG_SMP + +/* void CPU_ZERO(FAR cpu_set_t *set); */ + +# define CPU_ZERO(s) do { *(s) = 0; } while (0) + +/* void CPU_SET(int cpu, FAR cpu_set_t *set); */ + +# define CPU_SET(c,s) do { *(s) |= (1 << (c)); } while (0) + +/* void CPU_CLR(int cpu, FAR cpu_set_t *set); */ + +# define CPU_CLR(c,s) do { *(s) &= ~(1 << (c)); } while (0) + +/* int CPU_ISSET(int cpu, FAR const cpu_set_t *set); */ + +# define CPU_ISSET(c,s) ((*(s) & (1 << (c))) != 0) + +/* int CPU_COUNT(FAR const cpu_set_t *set); */ + +#define CPU_COUNT(s) sched_cpu_count(s) + +/* void CPU_AND(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_AND(d,s1,s2) do { *(d) = *(s1) & *(s2); } while (0) + +/* void CPU_OR(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_OR(d,s1,s2) do { *(d) = *(s1) | *(s2); } while (0) + +/* void CPU_XOR(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_XOR(d,s1,s2) do { *(d) = *(s1) ^ *(s2); } while (0) + +/* int CPU_EQUAL(FAR const cpu_set_t *set1, FAR const cpu_set_t *set2); */ + +# define CPU_EQUAL(s1,s2) (*(s2) == *(s2)) + +/* FAR cpu_set_t *CPU_ALLOC(int num_cpus); */ + +# define CPU_ALLOC(n) (FAR cpu_set_t *)malloc(sizeof(cpu_set_t)); + +/* void CPU_FREE(cpu_set_t *set); */ + +# define CPU_ALLOC(s) free(s) + +/* size_t CPU_ALLOC_SIZE(int num_cpus); */ + +# define CPU_ALLOC_SIZE(n) sizeof(cpu_set_t) + +/* void CPU_ZERO_S(size_t setsize, FAR cpu_set_t *set); */ + +# define CPU_ZERO_S(n,s) CPU_ZERO_S(s) + +/* void CPU_SET_S(int cpu, size_t setsize, FAR cpu_set_t *set); */ + +# define CPU_SET_S(c,n,s) CPU_SET(c,s) + +/* void CPU_CLR_S(int cpu, size_t setsize, FAR cpu_set_t *set); */ + +# define CPU_CLR_S(c,n,s) CPU_CLR(c,s) + +/* int CPU_ISSET_S(int cpu, size_t setsize, FAR const cpu_set_t *set); */ + +# define CPU_ISSET_S(c,n,s) CPU_ISSET(c,s) + +/* int CPU_COUNT_S(size_t setsize, FAR const cpu_set_t *set); */ + +# define CPU_COUNT_S(n,s) CPU_COUNT(s) + +/* void CPU_AND_S(size_t setsize, FAR cpu_set_t *destset, + * FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_AND_S(n,d,s1,s2) CPU_AND(d,s1,s2) + +/* void CPU_OR_S(size_t setsize, FAR cpu_set_t *destset, + * FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_OR_S(n,d,s1,s2) CPU_OR(d,s1,s2) + +/* void CPU_XOR_S(size_t setsize, FAR cpu_set_t *destset, + * FAR const cpu_set_t *srcset1, + * FAR const cpu_set_t *srcset2); + */ + +# define CPU_XOR_S(n,d,s1,s2) CPU_XOR(d,s1,s2) + +/* int CPU_EQUAL_S(size_t setsize, FAR const cpu_set_t *set1, + * FAR const cpu_set_t *set2); + */ + +# define CPU_EQUAL_S(n,s1,s2) CPU_EQUAL(s1,s2) + +#endif /* CONFIG_SMP */ + /******************************************************************************** * Public Type Definitions ********************************************************************************/ @@ -137,7 +244,8 @@ int sched_rr_get_interval(pid_t pid, FAR struct timespec *interval); int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask); int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask); -#endif +int sched_cpu_count(FAR const cpu_set_t *set); +#endif /* CONFIG_SMP */ /* Task Switching Interfaces (non-standard) */ diff --git a/libc/sched/Make.defs b/libc/sched/Make.defs index f1e69aff8b..eeb4be1c1b 100644 --- a/libc/sched/Make.defs +++ b/libc/sched/Make.defs @@ -37,6 +37,10 @@ CSRCS += sched_getprioritymax.c sched_getprioritymin.c +ifeq ($(CONFIG_SMP),y) +CSRCS += sched_cpucount.c +endif + ifeq ($(CONFIG_BUILD_PROTECTED),y) CSRCS += task_startup.c endif diff --git a/libc/sched/sched_cpucount.c b/libc/sched/sched_cpucount.c new file mode 100644 index 0000000000..3a2be5b3cb --- /dev/null +++ b/libc/sched/sched_cpucount.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * libc/sched/sched_cpucount.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_SMP + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_cpu_count + * + * Description: + * Return the number of bits set in the 'set'. This could be improved by + * using CPU-specific bit counting instructions. + * + * Inputs: + * set - The set of CPUs to be counted. + * + * Return Value: + * The number of CPUs in 'set' + * + ****************************************************************************/ + +int sched_cpu_count(FAR const cpu_set_t *set); +{ + int count; + int cpu; + + for (cpu = 0, count = 0; cpu < CONFIG_SMP_NCPUS; cpu++) + { + if ((*set & (1 << cpu)) != 0) + { + count++; + } + } + + return count; +} + +#endif /* CONFIG_SMP */ -- GitLab From 143d287f11b523b2518936f3e2415d117aeaacc0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 Feb 2016 11:27:55 -0600 Subject: [PATCH 783/858] Fix some missing header file inclusions and a misplaced semi-colon from recent commits --- arch | 2 +- include/sched.h | 4 +++- libc/pthread/pthread_attrgetaffinity.c | 1 + libc/pthread/pthread_attrsetaffinity.c | 1 + libc/sched/sched_cpucount.c | 2 +- sched/pthread/pthread_create.c | 2 +- sched/task/task_setup.c | 4 ++-- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch b/arch index 15236a5b07..a5acac8e6a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 15236a5b07c6f5d254ccdc8478c613a5c21e4296 +Subproject commit a5acac8e6adf2505c4e995797a203a0bc243f503 diff --git a/include/sched.h b/include/sched.h index 8733b8f46c..54501644bf 100644 --- a/include/sched.h +++ b/include/sched.h @@ -67,6 +67,7 @@ #define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS /* CPU affinity mask helpers ***************************************************/ +/* These are not standard but are defined for Linux compatibility */ #ifdef CONFIG_SMP @@ -88,7 +89,7 @@ /* int CPU_COUNT(FAR const cpu_set_t *set); */ -#define CPU_COUNT(s) sched_cpu_count(s) +# define CPU_COUNT(s) sched_cpu_count(s) /* void CPU_AND(FAR cpu_set_t *destset, FAR const cpu_set_t *srcset1, * FAR const cpu_set_t *srcset2); @@ -112,6 +113,7 @@ # define CPU_EQUAL(s1,s2) (*(s2) == *(s2)) +/* REVISIT: Variably sized CPU sets are not supported */ /* FAR cpu_set_t *CPU_ALLOC(int num_cpus); */ # define CPU_ALLOC(n) (FAR cpu_set_t *)malloc(sizeof(cpu_set_t)); diff --git a/libc/pthread/pthread_attrgetaffinity.c b/libc/pthread/pthread_attrgetaffinity.c index f77d267cac..c13ee71d0b 100644 --- a/libc/pthread/pthread_attrgetaffinity.c +++ b/libc/pthread/pthread_attrgetaffinity.c @@ -40,6 +40,7 @@ #include #include #include +#include #include /**************************************************************************** diff --git a/libc/pthread/pthread_attrsetaffinity.c b/libc/pthread/pthread_attrsetaffinity.c index 200711dea1..0222dfdd7d 100644 --- a/libc/pthread/pthread_attrsetaffinity.c +++ b/libc/pthread/pthread_attrsetaffinity.c @@ -41,6 +41,7 @@ #include #include +#include #include /**************************************************************************** diff --git a/libc/sched/sched_cpucount.c b/libc/sched/sched_cpucount.c index 3a2be5b3cb..6bdac11117 100644 --- a/libc/sched/sched_cpucount.c +++ b/libc/sched/sched_cpucount.c @@ -62,7 +62,7 @@ * ****************************************************************************/ -int sched_cpu_count(FAR const cpu_set_t *set); +int sched_cpu_count(FAR const cpu_set_t *set) { int count; int cpu; diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 52275b8e8d..0869c56ed8 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -412,7 +412,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, * parent thread's affinity mask. */ - if ( attr->affinity != 0) + if (attr->affinity != 0) { ptcb->cmn.affinity = attr->affinity; } diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 619a81819d..6d0ea9c2b2 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -163,8 +163,8 @@ static int task_assignpid(FAR struct tcb_s *tcb) * None * * Assumptions: - * The parent of the new task is the task at the head of the ready-to-run - * list. + * The parent of the new task is the task at the head of the assigned task + * list for the current CPU. * ****************************************************************************/ -- GitLab From 0fb035f76bc3338d4e6e3e9c00db2d80d3180995 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 Feb 2016 18:08:58 -0600 Subject: [PATCH 784/858] Standardize some naming in code section comments --- arch | 2 +- drivers/mtd/mtd_procfs.c | 2 +- drivers/rwbuffer.c | 2 +- drivers/serial/lowconsole.c | 2 +- drivers/serial/serial.c | 2 +- drivers/serial/uart_16550.c | 2 +- drivers/syslog/syslog_console.c | 2 +- drivers/usbdev/cdcacm.c | 2 +- drivers/usbdev/pl2303.c | 2 +- drivers/wireless/cc3000/wlan.c | 2 +- fs/binfs/fs_binfs.c | 2 +- fs/driver/fs_blockproxy.c | 2 +- fs/driver/fs_registerblockdriver.c | 2 +- fs/driver/fs_registerdriver.c | 2 +- fs/driver/fs_unregisterblockdriver.c | 2 +- fs/driver/fs_unregisterdriver.c | 2 +- fs/fat/fs_fat32.c | 2 +- fs/fat/fs_fat32dirent.c | 2 +- fs/fat/fs_fat32util.c | 2 +- fs/hostfs/hostfs.c | 2 +- fs/inode/fs_files.c | 4 ++-- fs/inode/fs_foreachinode.c | 9 +-------- fs/inode/fs_inode.c | 2 +- fs/inode/fs_inodeaddref.c | 2 +- fs/inode/fs_inodefind.c | 2 +- fs/inode/fs_inoderelease.c | 2 +- fs/inode/fs_inoderemove.c | 2 +- fs/inode/fs_inodereserve.c | 2 +- fs/mount/fs_foreachmountpoint.c | 8 -------- fs/mount/fs_mount.c | 2 +- fs/mount/fs_umount2.c | 2 +- fs/mqueue/mq_close.c | 2 +- fs/mqueue/mq_open.c | 2 +- fs/mqueue/mq_unlink.c | 2 +- fs/nfs/nfs_util.c | 2 +- fs/nxffs/nxffs_initialize.c | 2 +- fs/procfs/fs_procfs.c | 2 +- fs/procfs/fs_procfscpuload.c | 2 +- fs/procfs/fs_procfskmm.c | 2 +- fs/procfs/fs_procfsproc.c | 2 +- fs/procfs/fs_procfsuptime.c | 2 +- fs/romfs/fs_romfs.c | 2 +- fs/romfs/fs_romfsutil.c | 2 +- fs/semaphore/sem_close.c | 2 +- fs/semaphore/sem_open.c | 2 +- fs/semaphore/sem_unlink.c | 2 +- fs/smartfs/smartfs_procfs.c | 2 +- fs/smartfs/smartfs_smart.c | 2 +- fs/smartfs/smartfs_utils.c | 2 +- fs/vfs/fs_fsync.c | 2 +- fs/vfs/fs_mkdir.c | 2 +- fs/vfs/fs_rename.c | 2 +- fs/vfs/fs_rmdir.c | 2 +- fs/vfs/fs_sendfile.c | 2 +- fs/vfs/fs_unlink.c | 2 +- libc/aio/aio_error.c | 2 +- libc/aio/aio_return.c | 2 +- libc/aio/aio_suspend.c | 2 +- libc/audio/lib_buffer.c | 2 +- libc/math/lib_rint.c | 2 +- libc/math/lib_rintf.c | 2 +- libc/math/lib_rintl.c | 2 +- libc/misc/lib_sendfile.c | 2 +- libc/misc/lib_stream.c | 2 +- libc/misc/lib_streamsem.c | 2 +- libc/pthread/pthread_barrierattrsetpshared.c | 2 +- libc/pthread/pthread_startup.c | 2 +- libc/sched/task_startup.c | 2 +- libc/semaphore/sem_getvalue.c | 2 +- libc/semaphore/sem_init.c | 2 +- libc/signal/sig_fillset.c | 2 +- libc/signal/sig_ismember.c | 2 +- libc/stdio/lib_asprintf.c | 2 +- libc/stdio/lib_fflush.c | 2 +- libc/stdio/lib_fgetc.c | 2 +- libc/stdio/lib_fgetpos.c | 2 +- libc/stdio/lib_fprintf.c | 2 +- libc/stdio/lib_fputc.c | 2 +- libc/stdio/lib_fputs.c | 2 +- libc/stdio/lib_fread.c | 2 +- libc/stdio/lib_fseek.c | 2 +- libc/stdio/lib_fsetpos.c | 2 +- libc/stdio/lib_ftell.c | 2 +- libc/stdio/lib_fwrite.c | 2 +- libc/stdio/lib_libdtoa.c | 2 +- libc/stdio/lib_libfflush.c | 2 +- libc/stdio/lib_libflushall.c | 2 +- libc/stdio/lib_libfread.c | 2 +- libc/stdio/lib_libfwrite.c | 2 +- libc/stdio/lib_libnoflush.c | 2 +- libc/stdio/lib_libsnoflush.c | 2 +- libc/stdio/lib_libsprintf.c | 2 +- libc/stdio/lib_libvsprintf.c | 2 +- libc/stdio/lib_puts.c | 2 +- libc/stdio/lib_rdflush.c | 2 +- libc/stdio/lib_snprintf.c | 2 +- libc/stdio/lib_sprintf.c | 2 +- libc/stdio/lib_sscanf.c | 2 +- libc/stdio/lib_ungetc.c | 2 +- libc/stdio/lib_vasprintf.c | 2 +- libc/stdio/lib_vfprintf.c | 2 +- libc/stdio/lib_vprintf.c | 2 +- libc/stdio/lib_vsnprintf.c | 2 +- libc/stdio/lib_vsprintf.c | 2 +- libc/stdio/lib_wrflush.c | 2 +- libc/stdlib/lib_abort.c | 2 +- libc/termios/lib_cfgetspeed.c | 2 +- libc/termios/lib_cfsetspeed.c | 2 +- libc/termios/lib_tcflush.c | 2 +- libc/termios/lib_tcgetattr.c | 2 +- libc/termios/lib_tcsetattr.c | 2 +- libc/time/lib_calendar2utc.c | 2 +- libc/time/lib_dayofweek.c | 2 +- libc/time/lib_daysbeforemonth.c | 2 +- libc/time/lib_gmtime.c | 2 +- libc/time/lib_gmtimer.c | 2 +- libc/time/lib_isleapyear.c | 2 +- libc/time/lib_mktime.c | 2 +- libc/unistd/lib_access.c | 2 +- libc/unistd/lib_execl.c | 2 +- libc/unistd/lib_getopt.c | 2 +- libc/unistd/lib_getoptargp.c | 2 +- libc/unistd/lib_getoptindp.c | 2 +- libc/unistd/lib_getoptoptp.c | 2 +- libc/unistd/lib_sleep.c | 2 +- libc/unistd/lib_usleep.c | 2 +- libc/wqueue/work_cancel.c | 2 +- libc/wqueue/work_lock.c | 2 +- libc/wqueue/work_signal.c | 2 +- libxx/libxx.hxx | 2 +- libxx/libxx__gnu_unwind_find_exidx.hxx | 2 +- net/devif/devif_iobsend.c | 2 +- net/devif/devif_pktsend.c | 2 +- net/devif/devif_send.c | 2 +- net/icmp/icmp_ping.c | 2 +- net/icmp/icmp_poll.c | 2 +- net/icmpv6/icmpv6_ping.c | 2 +- net/icmpv6/icmpv6_poll.c | 2 +- net/igmp/igmp_send.c | 2 +- net/net_initialize.c | 4 ++-- net/pkt/pkt_input.c | 2 +- net/pkt/pkt_poll.c | 2 +- net/socket/net_sockets.c | 16 ---------------- net/tcp/tcp_appsend.c | 2 +- net/tcp/tcp_devpoll.c | 2 +- net/tcp/tcp_input.c | 2 +- net/tcp/tcp_send.c | 2 +- net/tcp/tcp_timer.c | 2 +- net/udp/udp_devpoll.c | 2 +- net/udp/udp_input.c | 2 +- net/udp/udp_send.c | 2 +- sched/irq/irq_attach.c | 2 +- sched/irq/irq_dispatch.c | 2 +- sched/mqueue/mq_initialize.c | 2 +- sched/paging/pg_worker.c | 2 +- sched/sched/sched_cpuload.c | 2 +- sched/sched/sched_timerexpiration.c | 2 +- sched/signal/sig_initialize.c | 2 +- sched/task/task_execv.c | 2 +- sched/task/task_exithook.c | 2 +- sched/task/task_init.c | 2 +- sched/task/task_start.c | 2 +- sched/task/task_starthook.c | 2 +- 163 files changed, 163 insertions(+), 194 deletions(-) diff --git a/arch b/arch index a5acac8e6a..5f1b167e40 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a5acac8e6adf2505c4e995797a203a0bc243f503 +Subproject commit 5f1b167e400e1dc23e5d6075db620d333a4414ff diff --git a/drivers/mtd/mtd_procfs.c b/drivers/mtd/mtd_procfs.c index b410df8756..bc3071c7e0 100644 --- a/drivers/mtd/mtd_procfs.c +++ b/drivers/mtd/mtd_procfs.c @@ -92,7 +92,7 @@ static int mtd_dup(FAR const struct file *oldp, static int mtd_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index 46d6fbefda..764a6ebbc1 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -75,7 +75,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/drivers/serial/lowconsole.c b/drivers/serial/lowconsole.c index 00cb7ebdf6..c6228d79a6 100644 --- a/drivers/serial/lowconsole.c +++ b/drivers/serial/lowconsole.c @@ -65,7 +65,7 @@ static ssize_t lowconsole_write(struct file *filep, const char *buffer, size_t b static int lowconsole_ioctl(struct file *filep, int cmd, unsigned long arg); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static const struct file_operations g_consoleops = diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 5f84e23213..2e13f3790a 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -89,7 +89,7 @@ static int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool se #endif /************************************************************************************ - * Private Variables + * Private Data ************************************************************************************/ static const struct file_operations g_serialops = diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index 6551a137e7..8b8eb82564 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -106,7 +106,7 @@ static bool u16550_txready(struct uart_dev_s *dev); static bool u16550_txempty(struct uart_dev_s *dev); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static const struct uart_ops_s g_uart_ops = diff --git a/drivers/syslog/syslog_console.c b/drivers/syslog/syslog_console.c index 6d3bb406cf..a3d3bb2bea 100644 --- a/drivers/syslog/syslog_console.c +++ b/drivers/syslog/syslog_console.c @@ -67,7 +67,7 @@ static int syslog_console_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static const struct file_operations g_consoleops = diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index 90eedc5f98..b4b5173678 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -209,7 +209,7 @@ static void cdcuart_txint(FAR struct uart_dev_s *dev, bool enable); static bool cdcuart_txempty(FAR struct uart_dev_s *dev); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* USB class device *********************************************************/ diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index aa568d1385..92285c01d1 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -371,7 +371,7 @@ static void usbser_txint(FAR struct uart_dev_s *dev, bool enable); static bool usbser_txempty(FAR struct uart_dev_s *dev); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* USB class device ********************************************************/ diff --git a/drivers/wireless/cc3000/wlan.c b/drivers/wireless/cc3000/wlan.c index 3b3eda23e8..175d6334b4 100644 --- a/drivers/wireless/cc3000/wlan.c +++ b/drivers/wireless/cc3000/wlan.c @@ -100,7 +100,7 @@ #define WLAN_SMART_CONFIG_START_PARAMS_LEN (4) /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 726a68cbef..9c03b9530e 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -93,7 +93,7 @@ static int binfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c index afabd1880f..b01ecc2a88 100644 --- a/fs/driver/fs_blockproxy.c +++ b/fs/driver/fs_blockproxy.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_registerblockdriver.c b/fs/driver/fs_registerblockdriver.c index ddcaef3671..65493c900c 100644 --- a/fs/driver/fs_registerblockdriver.c +++ b/fs/driver/fs_registerblockdriver.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_registerdriver.c b/fs/driver/fs_registerdriver.c index 6d60aeaf5c..42c7acf418 100644 --- a/fs/driver/fs_registerdriver.c +++ b/fs/driver/fs_registerdriver.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_unregisterblockdriver.c b/fs/driver/fs_unregisterblockdriver.c index f032d1b347..b4b775cdf0 100644 --- a/fs/driver/fs_unregisterblockdriver.c +++ b/fs/driver/fs_unregisterblockdriver.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/driver/fs_unregisterdriver.c b/fs/driver/fs_unregisterdriver.c index cd28debe50..b8dec302ed 100644 --- a/fs/driver/fs_unregisterdriver.c +++ b/fs/driver/fs_unregisterdriver.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index 95a6ce04d5..e344160ea5 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -118,7 +118,7 @@ static int fat_stat(struct inode *mountpt, const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c index 586c60d8ee..98a37e3198 100644 --- a/fs/fat/fs_fat32dirent.c +++ b/fs/fat/fs_fat32dirent.c @@ -156,7 +156,7 @@ static int fat_putsfdirentry(struct fat_mountpt_s *fs, uint8_t attributes, uint32_t fattime); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c index 380facb313..604b9ca07b 100644 --- a/fs/fat/fs_fat32util.c +++ b/fs/fat/fs_fat32util.c @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index 77aa771c92..f3701273e4 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -118,7 +118,7 @@ static int hostfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static uint8_t g_seminitialized = FALSE; diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index a35526232d..8366b55ce7 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -60,11 +60,11 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_foreachinode.c b/fs/inode/fs_foreachinode.c index 49f33ad30e..41ef0f0160 100644 --- a/fs/inode/fs_foreachinode.c +++ b/fs/inode/fs_foreachinode.c @@ -72,17 +72,10 @@ struct inode_path_s char path[CONFIG_PATH_MAX]; }; -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ + /**************************************************************************** * Name: foreach_inodelevel * diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c index 2e3edc4c1d..52985f8ad7 100644 --- a/fs/inode/fs_inode.c +++ b/fs/inode/fs_inode.c @@ -73,7 +73,7 @@ struct inode_sem_s }; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static struct inode_sem_s g_inode_sem; diff --git a/fs/inode/fs_inodeaddref.c b/fs/inode/fs_inodeaddref.c index 7378dc15be..b34a32c9f8 100644 --- a/fs/inode/fs_inodeaddref.c +++ b/fs/inode/fs_inodeaddref.c @@ -48,7 +48,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inodefind.c b/fs/inode/fs_inodefind.c index a2b761a233..533e2ef222 100644 --- a/fs/inode/fs_inodefind.c +++ b/fs/inode/fs_inodefind.c @@ -49,7 +49,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inoderelease.c b/fs/inode/fs_inoderelease.c index d4044e3b4d..97eadfaac0 100644 --- a/fs/inode/fs_inoderelease.c +++ b/fs/inode/fs_inoderelease.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c index 76fcd62c0f..e0b12299c0 100644 --- a/fs/inode/fs_inoderemove.c +++ b/fs/inode/fs_inoderemove.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index 5e674783df..9bf601e0c0 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mount/fs_foreachmountpoint.c b/fs/mount/fs_foreachmountpoint.c index fece2702e5..db6e386f7c 100644 --- a/fs/mount/fs_foreachmountpoint.c +++ b/fs/mount/fs_foreachmountpoint.c @@ -71,14 +71,6 @@ struct enum_mountpoint_s FAR void *arg; }; -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 533df4c6bc..abf7b9446e 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -93,7 +93,7 @@ struct fsmap_t }; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ #ifdef BDFS_SUPPORT diff --git a/fs/mount/fs_umount2.c b/fs/mount/fs_umount2.c index 8d56aa31bf..a60dfc2a09 100644 --- a/fs/mount/fs_umount2.c +++ b/fs/mount/fs_umount2.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c index d8527e7cf3..0d0a471461 100644 --- a/fs/mqueue/mq_close.c +++ b/fs/mqueue/mq_close.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index 3dbb2f9f8c..ca4ef46bdd 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index f71b12d45a..e9cce12c89 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nfs/nfs_util.c b/fs/nfs/nfs_util.c index dbe547bcd9..eb339cee69 100644 --- a/fs/nfs/nfs_util.c +++ b/fs/nfs/nfs_util.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/nxffs/nxffs_initialize.c b/fs/nxffs/nxffs_initialize.c index 745ca4560a..b453b38b9b 100644 --- a/fs/nxffs/nxffs_initialize.c +++ b/fs/nxffs/nxffs_initialize.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* See fs_mount.c -- this structure is explicitly externed there. diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 3db09f68be..506ab9fcb5 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -212,7 +212,7 @@ int procfs_initialize(void); #endif /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/procfs/fs_procfscpuload.c b/fs/procfs/fs_procfscpuload.c index fd94c91870..f33986d716 100644 --- a/fs/procfs/fs_procfscpuload.c +++ b/fs/procfs/fs_procfscpuload.c @@ -100,7 +100,7 @@ static int cpuload_dup(FAR const struct file *oldp, static int cpuload_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/procfs/fs_procfskmm.c b/fs/procfs/fs_procfskmm.c index edfe3933e8..3424338dc0 100644 --- a/fs/procfs/fs_procfskmm.c +++ b/fs/procfs/fs_procfskmm.c @@ -98,7 +98,7 @@ static int kmm_dup(FAR const struct file *oldp, static int kmm_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index d47da8b67b..720c517438 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -197,7 +197,7 @@ static int proc_rewinddir(FAR struct fs_dirent_s *dir); static int proc_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index dce272e69f..3e725c1473 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -102,7 +102,7 @@ static int uptime_dup(FAR const struct file *oldp, static int uptime_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 00f3f92886..84c786671c 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -101,7 +101,7 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 7269bf14bc..9e19b7a447 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_close.c b/fs/semaphore/sem_close.c index 97d2bf5886..3576cba215 100644 --- a/fs/semaphore/sem_close.c +++ b/fs/semaphore/sem_close.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 4bae07352c..6b3d6e0d3e 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/semaphore/sem_unlink.c b/fs/semaphore/sem_unlink.c index bdeb826b81..636c793085 100644 --- a/fs/semaphore/sem_unlink.c +++ b/fs/semaphore/sem_unlink.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/smartfs/smartfs_procfs.c b/fs/smartfs/smartfs_procfs.c index c0f60c13e6..474d85009f 100644 --- a/fs/smartfs/smartfs_procfs.c +++ b/fs/smartfs/smartfs_procfs.c @@ -153,7 +153,7 @@ static size_t smartfs_files_read(FAR struct file *filep, FAR char *buffer, #endif /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static const struct smartfs_procfs_entry_s g_direntry[] = diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index fffba254b7..122d6dca87 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -110,7 +110,7 @@ static off_t smartfs_seek_internal(struct smartfs_mountpt_s *fs, off_t offset, int whence); /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static uint8_t g_seminitialized = FALSE; diff --git a/fs/smartfs/smartfs_utils.c b/fs/smartfs/smartfs_utils.c index 58dcde8e6b..dba35882bc 100644 --- a/fs/smartfs/smartfs_utils.c +++ b/fs/smartfs/smartfs_utils.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ #if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || \ diff --git a/fs/vfs/fs_fsync.c b/fs/vfs/fs_fsync.c index 246dc51d89..167daafa21 100644 --- a/fs/vfs/fs_fsync.c +++ b/fs/vfs/fs_fsync.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_mkdir.c b/fs/vfs/fs_mkdir.c index 01ed5bb629..886b4114a1 100644 --- a/fs/vfs/fs_mkdir.c +++ b/fs/vfs/fs_mkdir.c @@ -68,7 +68,7 @@ #ifdef FS_HAVE_MKDIR /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c index e6ebfd3d63..785898f253 100644 --- a/fs/vfs/fs_rename.c +++ b/fs/vfs/fs_rename.c @@ -68,7 +68,7 @@ #ifdef FS_HAVE_RENAME /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_rmdir.c b/fs/vfs/fs_rmdir.c index 234b11399d..ba46b25ee9 100644 --- a/fs/vfs/fs_rmdir.c +++ b/fs/vfs/fs_rmdir.c @@ -68,7 +68,7 @@ #ifdef FS_HAVE_RMDIR /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_sendfile.c b/fs/vfs/fs_sendfile.c index 8e68c8514b..cf05b88868 100644 --- a/fs/vfs/fs_sendfile.c +++ b/fs/vfs/fs_sendfile.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c index 126caf2adc..4c884c421b 100644 --- a/fs/vfs/fs_unlink.c +++ b/fs/vfs/fs_unlink.c @@ -68,7 +68,7 @@ #ifdef FS_HAVE_UNLINK /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio_error.c b/libc/aio/aio_error.c index 8bfa1978fb..896ac97056 100644 --- a/libc/aio/aio_error.c +++ b/libc/aio/aio_error.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio_return.c b/libc/aio/aio_return.c index 4672de0855..cfc5874379 100644 --- a/libc/aio/aio_return.c +++ b/libc/aio/aio_return.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/aio/aio_suspend.c b/libc/aio/aio_suspend.c index 5e5fe33715..948462cd90 100644 --- a/libc/aio/aio_suspend.c +++ b/libc/aio/aio_suspend.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/audio/lib_buffer.c b/libc/audio/lib_buffer.c index f7e29dd033..af4e719879 100644 --- a/libc/audio/lib_buffer.c +++ b/libc/audio/lib_buffer.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index d180c2a251..2e6af43a87 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ double rint(double x) diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c index d72cbad7fd..ca733e3d79 100644 --- a/libc/math/lib_rintf.c +++ b/libc/math/lib_rintf.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ float rintf(float x) diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c index c6dc09a3b8..03d5de0442 100644 --- a/libc/math/lib_rintl.c +++ b/libc/math/lib_rintl.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ long double rintl(long double x) diff --git a/libc/misc/lib_sendfile.c b/libc/misc/lib_sendfile.c index 2313833dc7..c5c9b5536b 100644 --- a/libc/misc/lib_sendfile.c +++ b/libc/misc/lib_sendfile.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/misc/lib_stream.c b/libc/misc/lib_stream.c index f42b040cbb..bcf78389b0 100644 --- a/libc/misc/lib_stream.c +++ b/libc/misc/lib_stream.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/misc/lib_streamsem.c b/libc/misc/lib_streamsem.c index 9f26d96a72..ae6c2e0829 100644 --- a/libc/misc/lib_streamsem.c +++ b/libc/misc/lib_streamsem.c @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/pthread/pthread_barrierattrsetpshared.c b/libc/pthread/pthread_barrierattrsetpshared.c index 2fd224bad6..6839511df5 100644 --- a/libc/pthread/pthread_barrierattrsetpshared.c +++ b/libc/pthread/pthread_barrierattrsetpshared.c @@ -56,7 +56,7 @@ ********************************************************************************/ /******************************************************************************** - * Private Variables + * Private Data ********************************************************************************/ /******************************************************************************** diff --git a/libc/pthread/pthread_startup.c b/libc/pthread/pthread_startup.c index 7bbac36cd0..3d2b76ce8f 100644 --- a/libc/pthread/pthread_startup.c +++ b/libc/pthread/pthread_startup.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/sched/task_startup.c b/libc/sched/task_startup.c index 754e5aee3c..6012e62675 100644 --- a/libc/sched/task_startup.c +++ b/libc/sched/task_startup.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/semaphore/sem_getvalue.c b/libc/semaphore/sem_getvalue.c index 6233e60298..16fcc7be0a 100644 --- a/libc/semaphore/sem_getvalue.c +++ b/libc/semaphore/sem_getvalue.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/semaphore/sem_init.c b/libc/semaphore/sem_init.c index c7a4f70261..861acb6cde 100644 --- a/libc/semaphore/sem_init.c +++ b/libc/semaphore/sem_init.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/signal/sig_fillset.c b/libc/signal/sig_fillset.c index ecd5a82bc9..92f55edf40 100644 --- a/libc/signal/sig_fillset.c +++ b/libc/signal/sig_fillset.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/signal/sig_ismember.c b/libc/signal/sig_ismember.c index e03f5fbe97..c16ecd3d15 100644 --- a/libc/signal/sig_ismember.c +++ b/libc/signal/sig_ismember.c @@ -52,7 +52,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_asprintf.c b/libc/stdio/lib_asprintf.c index 4c3f85760a..b10a779dce 100644 --- a/libc/stdio/lib_asprintf.c +++ b/libc/stdio/lib_asprintf.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fflush.c b/libc/stdio/lib_fflush.c index d56f8fb75c..ae88e0ced2 100644 --- a/libc/stdio/lib_fflush.c +++ b/libc/stdio/lib_fflush.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fgetc.c b/libc/stdio/lib_fgetc.c index 15ccb893dd..c4b32d69b9 100644 --- a/libc/stdio/lib_fgetc.c +++ b/libc/stdio/lib_fgetc.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fgetpos.c b/libc/stdio/lib_fgetpos.c index ea49abb2ce..ba4fa478b2 100644 --- a/libc/stdio/lib_fgetpos.c +++ b/libc/stdio/lib_fgetpos.c @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fprintf.c b/libc/stdio/lib_fprintf.c index a0169972eb..191dc2e34a 100644 --- a/libc/stdio/lib_fprintf.c +++ b/libc/stdio/lib_fprintf.c @@ -68,7 +68,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fputc.c b/libc/stdio/lib_fputc.c index 9ba40a6e7d..57e784759a 100644 --- a/libc/stdio/lib_fputc.c +++ b/libc/stdio/lib_fputc.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fputs.c b/libc/stdio/lib_fputs.c index 033ff3b9b3..4b47a04628 100644 --- a/libc/stdio/lib_fputs.c +++ b/libc/stdio/lib_fputs.c @@ -80,7 +80,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fread.c b/libc/stdio/lib_fread.c index 6acb9d7e77..8132b3275a 100644 --- a/libc/stdio/lib_fread.c +++ b/libc/stdio/lib_fread.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fseek.c b/libc/stdio/lib_fseek.c index 1016d8b37f..bafe4488e4 100644 --- a/libc/stdio/lib_fseek.c +++ b/libc/stdio/lib_fseek.c @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fsetpos.c b/libc/stdio/lib_fsetpos.c index 681aa514f9..18843cb6f7 100644 --- a/libc/stdio/lib_fsetpos.c +++ b/libc/stdio/lib_fsetpos.c @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_ftell.c b/libc/stdio/lib_ftell.c index c13e64c9ae..8707c9b264 100644 --- a/libc/stdio/lib_ftell.c +++ b/libc/stdio/lib_ftell.c @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_fwrite.c b/libc/stdio/lib_fwrite.c index 941120ae6d..ffb76765ae 100644 --- a/libc/stdio/lib_fwrite.c +++ b/libc/stdio/lib_fwrite.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libdtoa.c b/libc/stdio/lib_libdtoa.c index 995b0d72c4..a3ef37d220 100644 --- a/libc/stdio/lib_libdtoa.c +++ b/libc/stdio/lib_libdtoa.c @@ -83,7 +83,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index 4eebac409d..ef20834b21 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libflushall.c b/libc/stdio/lib_libflushall.c index e040d2deb6..342c96a5bd 100644 --- a/libc/stdio/lib_libflushall.c +++ b/libc/stdio/lib_libflushall.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index e4ad730e26..8597209cd3 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index 12bfd033c8..12138e62ba 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libnoflush.c b/libc/stdio/lib_libnoflush.c index 6ad372a653..be4ea8ae54 100644 --- a/libc/stdio/lib_libnoflush.c +++ b/libc/stdio/lib_libnoflush.c @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libsnoflush.c b/libc/stdio/lib_libsnoflush.c index 809356f144..6deef38e03 100644 --- a/libc/stdio/lib_libsnoflush.c +++ b/libc/stdio/lib_libsnoflush.c @@ -75,7 +75,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libsprintf.c b/libc/stdio/lib_libsprintf.c index 8668a54674..edb49f8832 100644 --- a/libc/stdio/lib_libsprintf.c +++ b/libc/stdio/lib_libsprintf.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index c81e55617f..a103b0c4ee 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -222,7 +222,7 @@ static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, static const char g_nullstring[] = "(null)"; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_puts.c b/libc/stdio/lib_puts.c index c30c92aaf4..957e7426b9 100644 --- a/libc/stdio/lib_puts.c +++ b/libc/stdio/lib_puts.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_rdflush.c b/libc/stdio/lib_rdflush.c index 27bd25f6fd..cb928fb820 100644 --- a/libc/stdio/lib_rdflush.c +++ b/libc/stdio/lib_rdflush.c @@ -75,7 +75,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_snprintf.c b/libc/stdio/lib_snprintf.c index ca27bb0b46..a7bf89cebe 100644 --- a/libc/stdio/lib_snprintf.c +++ b/libc/stdio/lib_snprintf.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_sprintf.c b/libc/stdio/lib_sprintf.c index e857c79cab..8f75192896 100644 --- a/libc/stdio/lib_sprintf.c +++ b/libc/stdio/lib_sprintf.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c index d4996dceef..c54fb3f145 100644 --- a/libc/stdio/lib_sscanf.c +++ b/libc/stdio/lib_sscanf.c @@ -151,7 +151,7 @@ static int findwidth(FAR const char *buf, FAR const char *fmt) } /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_ungetc.c b/libc/stdio/lib_ungetc.c index 4ae4bc69b1..89220751b3 100644 --- a/libc/stdio/lib_ungetc.c +++ b/libc/stdio/lib_ungetc.c @@ -77,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vasprintf.c b/libc/stdio/lib_vasprintf.c index e74cce46cc..7338d03f59 100644 --- a/libc/stdio/lib_vasprintf.c +++ b/libc/stdio/lib_vasprintf.c @@ -87,7 +87,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vfprintf.c b/libc/stdio/lib_vfprintf.c index 783dc8b916..b77b1cb6af 100644 --- a/libc/stdio/lib_vfprintf.c +++ b/libc/stdio/lib_vfprintf.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vprintf.c b/libc/stdio/lib_vprintf.c index ee9a227c01..5f7a084453 100644 --- a/libc/stdio/lib_vprintf.c +++ b/libc/stdio/lib_vprintf.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vsnprintf.c b/libc/stdio/lib_vsnprintf.c index 6952ed5ad6..ddbb1ef9ef 100644 --- a/libc/stdio/lib_vsnprintf.c +++ b/libc/stdio/lib_vsnprintf.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_vsprintf.c b/libc/stdio/lib_vsprintf.c index f919de0887..a64fef6e73 100644 --- a/libc/stdio/lib_vsprintf.c +++ b/libc/stdio/lib_vsprintf.c @@ -68,7 +68,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdio/lib_wrflush.c b/libc/stdio/lib_wrflush.c index 0ccd007c6b..b07c48b290 100644 --- a/libc/stdio/lib_wrflush.c +++ b/libc/stdio/lib_wrflush.c @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/stdlib/lib_abort.c b/libc/stdlib/lib_abort.c index 86bad40726..f037e8d8cc 100644 --- a/libc/stdlib/lib_abort.c +++ b/libc/stdlib/lib_abort.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_cfgetspeed.c b/libc/termios/lib_cfgetspeed.c index b20e881604..507890a10d 100644 --- a/libc/termios/lib_cfgetspeed.c +++ b/libc/termios/lib_cfgetspeed.c @@ -45,7 +45,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_cfsetspeed.c b/libc/termios/lib_cfsetspeed.c index 8c76117536..7dce45d6a9 100644 --- a/libc/termios/lib_cfsetspeed.c +++ b/libc/termios/lib_cfsetspeed.c @@ -46,7 +46,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcflush.c b/libc/termios/lib_tcflush.c index 3203493432..013ebd4984 100644 --- a/libc/termios/lib_tcflush.c +++ b/libc/termios/lib_tcflush.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcgetattr.c b/libc/termios/lib_tcgetattr.c index 5c9c671d76..447e2ecf01 100644 --- a/libc/termios/lib_tcgetattr.c +++ b/libc/termios/lib_tcgetattr.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/termios/lib_tcsetattr.c b/libc/termios/lib_tcsetattr.c index 85e96111cf..ab93e2aafd 100644 --- a/libc/termios/lib_tcsetattr.c +++ b/libc/termios/lib_tcsetattr.c @@ -51,7 +51,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_calendar2utc.c b/libc/time/lib_calendar2utc.c index 95b33e2321..2c2d507d9d 100644 --- a/libc/time/lib_calendar2utc.c +++ b/libc/time/lib_calendar2utc.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_dayofweek.c b/libc/time/lib_dayofweek.c index 55fb3c4370..bf1ed7280f 100644 --- a/libc/time/lib_dayofweek.c +++ b/libc/time/lib_dayofweek.c @@ -68,7 +68,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_daysbeforemonth.c b/libc/time/lib_daysbeforemonth.c index e0cad2d206..8c09c2203e 100644 --- a/libc/time/lib_daysbeforemonth.c +++ b/libc/time/lib_daysbeforemonth.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static const uint16_t g_daysbeforemonth[13] = diff --git a/libc/time/lib_gmtime.c b/libc/time/lib_gmtime.c index bd0addf295..1eeade4675 100644 --- a/libc/time/lib_gmtime.c +++ b/libc/time/lib_gmtime.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_gmtimer.c b/libc/time/lib_gmtimer.c index d3f1740189..d6b224cfcc 100644 --- a/libc/time/lib_gmtimer.c +++ b/libc/time/lib_gmtimer.c @@ -82,7 +82,7 @@ static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_isleapyear.c b/libc/time/lib_isleapyear.c index faa1412189..3bad316477 100644 --- a/libc/time/lib_isleapyear.c +++ b/libc/time/lib_isleapyear.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/time/lib_mktime.c b/libc/time/lib_mktime.c index 84b00ae79a..5798ce5309 100644 --- a/libc/time/lib_mktime.c +++ b/libc/time/lib_mktime.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_access.c b/libc/unistd/lib_access.c index f700a2d6ae..b9d22f9e83 100644 --- a/libc/unistd/lib_access.c +++ b/libc/unistd/lib_access.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_execl.c b/libc/unistd/lib_execl.c index 86bb3aed69..08dbdc6112 100644 --- a/libc/unistd/lib_execl.c +++ b/libc/unistd/lib_execl.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getopt.c b/libc/unistd/lib_getopt.c index 1c0450100c..47ac085509 100644 --- a/libc/unistd/lib_getopt.c +++ b/libc/unistd/lib_getopt.c @@ -56,7 +56,7 @@ int optind = 1; /* Index into argv */ int optopt = '?'; /* unrecognized option character */ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ static FAR char *g_optptr = NULL; diff --git a/libc/unistd/lib_getoptargp.c b/libc/unistd/lib_getoptargp.c index 826132e07d..876b287929 100644 --- a/libc/unistd/lib_getoptargp.c +++ b/libc/unistd/lib_getoptargp.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getoptindp.c b/libc/unistd/lib_getoptindp.c index a487d9b126..d413642329 100644 --- a/libc/unistd/lib_getoptindp.c +++ b/libc/unistd/lib_getoptindp.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_getoptoptp.c b/libc/unistd/lib_getoptoptp.c index 238d68ac53..b1aa2fc218 100644 --- a/libc/unistd/lib_getoptoptp.c +++ b/libc/unistd/lib_getoptoptp.c @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_sleep.c b/libc/unistd/lib_sleep.c index 26f8d5b91e..785d76b63b 100644 --- a/libc/unistd/lib_sleep.c +++ b/libc/unistd/lib_sleep.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c index 7f554b3ebc..5b72bbdcdf 100644 --- a/libc/unistd/lib_usleep.c +++ b/libc/unistd/lib_usleep.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_cancel.c b/libc/wqueue/work_cancel.c index 50d5e5239d..8fe330ef0a 100644 --- a/libc/wqueue/work_cancel.c +++ b/libc/wqueue/work_cancel.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_lock.c b/libc/wqueue/work_lock.c index 7b6635991c..a8f1078707 100644 --- a/libc/wqueue/work_lock.c +++ b/libc/wqueue/work_lock.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libc/wqueue/work_signal.c b/libc/wqueue/work_signal.c index a474c2bc36..da8b174cd5 100644 --- a/libc/wqueue/work_signal.c +++ b/libc/wqueue/work_signal.c @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/libxx/libxx.hxx b/libxx/libxx.hxx index f8c1eada4a..be740aaf87 100644 --- a/libxx/libxx.hxx +++ b/libxx/libxx.hxx @@ -74,7 +74,7 @@ typedef CODE void (*__cxa_exitfunc_t)(void *arg); //*************************************************************************** -// Public Variables +// Public Data //*************************************************************************** extern "C" FAR void *__dso_handle; diff --git a/libxx/libxx__gnu_unwind_find_exidx.hxx b/libxx/libxx__gnu_unwind_find_exidx.hxx index 0925d76e90..9156874a6c 100644 --- a/libxx/libxx__gnu_unwind_find_exidx.hxx +++ b/libxx/libxx__gnu_unwind_find_exidx.hxx @@ -60,7 +60,7 @@ typedef struct __EIT_entry } __EIT_entry; //*************************************************************************** -// Public Variables +// Public Data //*************************************************************************** extern __EIT_entry __exidx_start; diff --git a/net/devif/devif_iobsend.c b/net/devif/devif_iobsend.c index 157064b0c0..66194aca91 100644 --- a/net/devif/devif_iobsend.c +++ b/net/devif/devif_iobsend.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/devif/devif_pktsend.c b/net/devif/devif_pktsend.c index 1f65182efd..7e6c83a209 100644 --- a/net/devif/devif_pktsend.c +++ b/net/devif/devif_pktsend.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/devif/devif_send.c b/net/devif/devif_send.c index 69781a87fb..8bcfedb0b0 100644 --- a/net/devif/devif_send.c +++ b/net/devif/devif_send.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 4b62bd1c82..954d22e4a9 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -98,7 +98,7 @@ struct icmp_ping_s ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmp/icmp_poll.c b/net/icmp/icmp_poll.c index a2da120887..ac21ead7fd 100644 --- a/net/icmp/icmp_poll.c +++ b/net/icmp/icmp_poll.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index b6f8edd299..0e9ac3b691 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -101,7 +101,7 @@ struct icmpv6_ping_s ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/icmpv6/icmpv6_poll.c b/net/icmpv6/icmpv6_poll.c index 7db797cb2c..6cf00532fb 100644 --- a/net/icmpv6/icmpv6_poll.c +++ b/net/icmpv6/icmpv6_poll.c @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index 5a2526395d..1482a63549 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -83,7 +83,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/net_initialize.c b/net/net_initialize.c index 6de3a97c10..df3a72226d 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -67,11 +67,11 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index f21c3716fc..60b2ca19aa 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index 561bb33fe5..afb65db24f 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index a327431b90..4d2ae7dd62 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -53,22 +53,6 @@ #if CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index 03ad447464..dbaeb5c2d3 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_devpoll.c b/net/tcp/tcp_devpoll.c index 92f7c57668..bf7a7ee681 100644 --- a/net/tcp/tcp_devpoll.c +++ b/net/tcp/tcp_devpoll.c @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 109e27b763..49c8aca1ae 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index dc1d3496f0..42fb9a62c8 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 16dd2e3226..48109d63be 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_devpoll.c b/net/udp/udp_devpoll.c index a142db1543..af6ae68918 100644 --- a/net/udp/udp_devpoll.c +++ b/net/udp/udp_devpoll.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_input.c b/net/udp/udp_input.c index a77371d0e8..601b0de2b7 100644 --- a/net/udp/udp_input.c +++ b/net/udp/udp_input.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index 021ea576e8..6bc010d997 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/irq/irq_attach.c b/sched/irq/irq_attach.c index 6402ca3157..d111eeb5c7 100644 --- a/sched/irq/irq_attach.c +++ b/sched/irq/irq_attach.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c index 6073c3edf7..4d18ac34fd 100644 --- a/sched/irq/irq_dispatch.c +++ b/sched/irq/irq_dispatch.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index 14eda7b852..b86c74c6d9 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -82,7 +82,7 @@ sq_queue_t g_msgfreeirq; sq_queue_t g_desfree; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* g_msgalloc is a pointer to the start of the allocated block of diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 29344fb842..08c94fd17c 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -90,7 +90,7 @@ pid_t g_pgworker; FAR struct tcb_s *g_pftcb; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ #ifndef CONFIG_PAGING_BLOCKINGFILL diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c index f7158b74c2..6cfe027bed 100644 --- a/sched/sched/sched_cpuload.c +++ b/sched/sched/sched_cpuload.c @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* This is the total number of clock tick counts. Essentially the diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 0c329e23cc..ee34099687 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -109,7 +109,7 @@ uint32_t g_oneshot_maxticks = UINT32_MAX; #endif /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* This is the duration of the currently active timer or, when * sched_timer_expiration() is called, the duration of interval timer diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index 02c0685efd..12dc4a18be 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -81,7 +81,7 @@ sq_queue_t g_sigpendingsignal; sq_queue_t g_sigpendingirqsignal; /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /* g_sigactionalloc is a pointer to the start of the allocated blocks of diff --git a/sched/task/task_execv.c b/sched/task/task_execv.c index 01d89f1393..c4457df537 100644 --- a/sched/task/task_execv.c +++ b/sched/task/task_execv.c @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index bc72151be1..b1210778d6 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -66,7 +66,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_init.c b/sched/task/task_init.c index 7f6fc14d8a..8583c1ecc3 100644 --- a/sched/task/task_init.c +++ b/sched/task/task_init.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_start.c b/sched/task/task_start.c index 9737d2ddf3..acff33e66c 100644 --- a/sched/task/task_start.c +++ b/sched/task/task_start.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** diff --git a/sched/task/task_starthook.c b/sched/task/task_starthook.c index c36517599e..f102afc0a7 100644 --- a/sched/task/task_starthook.c +++ b/sched/task/task_starthook.c @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ /**************************************************************************** -- GitLab From 7cb35587a31c10935da73435c93e9b22ef798e55 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Feb 2016 08:28:33 -0600 Subject: [PATCH 785/858] Correct minor typos in a Kconfig file --- configs | 2 +- sched/Kconfig | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs b/configs index 24d0c13b63..8fcf8b1b91 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 24d0c13b63d15b148c2be12b9e6dd685ed34c4c0 +Subproject commit 8fcf8b1b913dab18a3b1b4234258394b9d940561 diff --git a/sched/Kconfig b/sched/Kconfig index a8a439d270..66c9f02459 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -243,7 +243,7 @@ config SMP depends on ARCH_HAVE_MULTICPU && EXPERIMENTAL select SPINLOCK ---help--- - Enable support for Symmetric Multi-Processing (SMP) on a multi-CPU + Enables support for Symmetric Multi-Processing (SMP) on a multi-CPU platform. if SMP @@ -253,16 +253,16 @@ config SMP_NCPUS default 4 range 2 32 ---help--- - This value identifies the number of CPUs support by the processor + This value identifies the number of CPUs supported by the processor that will be used for SMP. config SMP_IDLETHREAD_STACKSIZE int "CPU IDLE stack size" default 2048 ---help--- - Each CPU will have its own IDLE stack. System initialization occurs + Each CPU will have its own IDLE task. System initialization occurs on CPU0 and uses CONFIG_IDLETHREAD_STACKSIZE which will probably be - larger than is generally needed. This setting provides the STACK + larger than is generally needed. This setting provides the stack size for the IDLE task on CPUS 1 through (CONFIG_SMP_NCPUS-1). endif # SMP -- GitLab From ea15ead6cc5c8b0aadfd01bfb27ff938f6c37bbf Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Mon, 22 Feb 2016 08:43:32 -0600 Subject: [PATCH 786/858] RGB LED driver --- drivers/leds/Kconfig | 7 + drivers/leds/Make.defs | 6 + drivers/leds/rgbled.c | 417 ++++++++++++++++++++++++++++++++++++ include/nuttx/leds/rgbled.h | 99 +++++++++ 4 files changed, 529 insertions(+) create mode 100644 drivers/leds/rgbled.c create mode 100644 include/nuttx/leds/rgbled.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 4a12d3eb12..5a673606fc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -41,6 +41,13 @@ config USERLED_LOWER endif # USERLED +config RGBLED + bool "RGB LED Driver Support" + default n + ---help--- + This selection enables building of the "upper-half" RGB LED driver. + See include/nuttx/rgbled.h for further PWM driver information. + config PCA9635PW bool "PCA9635PW I2C LED Driver" default n diff --git a/drivers/leds/Make.defs b/drivers/leds/Make.defs index a10f7b5ea0..794ba4202c 100644 --- a/drivers/leds/Make.defs +++ b/drivers/leds/Make.defs @@ -50,6 +50,12 @@ endif LEDVPATH = :leds endif +ifeq ($(CONFIG_RGBLED),y) + CSRCS += rgbled.c + LEDDEPATH = --dep-path leds + LEDVPATH = :leds +endif + ifeq ($(CONFIG_PCA9635PW),y) CSRCS += pca9635pw.c LEDDEPATH = --dep-path leds diff --git a/drivers/leds/rgbled.c b/drivers/leds/rgbled.c new file mode 100644 index 0000000000..27e7a1a9eb --- /dev/null +++ b/drivers/leds/rgbled.c @@ -0,0 +1,417 @@ +/**************************************************************************** + * drivers/rgbled.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#ifdef CONFIG_RGBLED + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Debug ********************************************************************/ +/* Non-standard debug that may be enabled just for testing PWM */ + +#ifdef CONFIG_DEBUG_RGBLED +# define pwmdbg dbg +# define pwmvdbg vdbg +# define pwmlldbg lldbg +# define pwmllvdbg llvdbg +#else +# define pwmdbg(x...) +# define pwmvdbg(x...) +# define pwmlldbg(x...) +# define pwmllvdbg(x...) +#endif + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/* This structure describes the state of the upper half driver */ + +struct rgbled_upperhalf_s +{ + uint8_t crefs; /* The number of times the device has been opened */ + volatile bool started; /* True: pulsed output is being generated */ + sem_t exclsem; /* Supports mutual exclusion */ + struct pwm_info_s ledr; /* Pulsed output for LED R*/ + struct pwm_info_s ledg; /* Pulsed output for LED G*/ + struct pwm_info_s ledb; /* Pulsed output for LED B*/ + struct pwm_lowerhalf_s *devledr; + struct pwm_lowerhalf_s *devledg; + struct pwm_lowerhalf_s *devledb; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int rgbled_open(FAR struct file *filep); +static int rgbled_close(FAR struct file *filep); +static ssize_t rgbled_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); +static ssize_t rgbled_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_rgbledops = +{ + rgbled_open, /* open */ + rgbled_close, /* close */ + rgbled_read, /* read */ + rgbled_write, /* write */ + 0, /* seek */ + 0 /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rgbled_open + * + * Description: + * This function is called whenever the PWM device is opened. + * + ****************************************************************************/ + +static int rgbled_open(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct rgbled_upperhalf_s *upper = inode->i_private; + uint8_t tmp; + int ret; + + pwmvdbg("crefs: %d\n", upper->crefs); + + /* Get exclusive access to the device structures */ + + ret = sem_wait(&upper->exclsem); + if (ret < 0) + { + ret = -get_errno(); + goto errout; + } + + /* Increment the count of references to the device. If this the first + * time that the driver has been opened for this device, then initialize + * the device. + */ + + tmp = upper->crefs + 1; + if (tmp == 0) + { + /* More than 255 opens; uint8_t overflows to zero */ + + ret = -EMFILE; + goto errout_with_sem; + } + + /* Save the new open count on success */ + + upper->crefs = tmp; + ret = OK; + +errout_with_sem: + sem_post(&upper->exclsem); + +errout: + return ret; +} + +/**************************************************************************** + * Name: rgbled_close + * + * Description: + * This function is called when the PWM device is closed. + * + ****************************************************************************/ + +static int rgbled_close(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct rgbled_upperhalf_s *upper = inode->i_private; + int ret; + + pwmvdbg("crefs: %d\n", upper->crefs); + + /* Get exclusive access to the device structures */ + + ret = sem_wait(&upper->exclsem); + if (ret < 0) + { + ret = -get_errno(); + goto errout; + } + + /* Decrement the references to the driver. If the reference count will + * decrement to 0, then uninitialize the driver. + */ + + if (upper->crefs > 1) + { + upper->crefs--; + } + + sem_post(&upper->exclsem); + ret = OK; + +errout: + return ret; +} + +/**************************************************************************** + * Name: rgbled_read + * + * Description: + * A dummy read method. This is provided only to satisfy the VFS layer. + * + ****************************************************************************/ + +static ssize_t rgbled_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + /* Return zero -- usually meaning end-of-file */ + + return 0; +} + +/**************************************************************************** + * Name: rgbled_write + * + * Description: + * A dummy write method. This is provided only to satisfy the VFS layer. + * + ****************************************************************************/ + +static ssize_t rgbled_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + + FAR struct inode *inode = filep->f_inode; + FAR struct rgbled_upperhalf_s *upper = inode->i_private; + FAR struct pwm_lowerhalf_s *ledr = upper->devledr; + FAR struct pwm_lowerhalf_s *ledg = upper->devledg; + FAR struct pwm_lowerhalf_s *ledb = upper->devledb; + + unsigned int red; + unsigned int green; + unsigned int blue; + char color[3]; + + /* We need to receive a string #RRGGBB = 7 bytes */ + + if (buffer == NULL || buflen < 7) + { + /* Well... nothing to do */ + + return -EINVAL; + } + + /* Check if it is a color format */ + + if (buffer[0] != '#') + { + /* The color code needs to start with # */ + + return -EINVAL; + } + + /* Move buffer to next character */ + + buffer++; + + color[0] = buffer[0]; + color[1] = buffer[1]; + color[2] = '\0'; + + red = strtol(color, NULL, 16); + + color[0] = buffer[2]; + color[1] = buffer[3]; + color[2] = '\0'; + + green = strtol(color, NULL, 16); + + color[0] = buffer[4]; + color[1] = buffer[5]; + color[2] = '\0'; + + blue = strtol(color, NULL, 16); + + /* Sane check */ + + if (red > 255) + { + red = 255; + } + + if (green > 255) + { + green = 255; + } + + if (blue > 255) + { + blue = 255; + } + + /* Convert 8bit to 16bits */ + + red <<= 8; + green <<= 8; + blue <<= 8; + + /* Setup LED R */ + + upper->ledr.frequency = 100; + upper->ledr.duty = red; + + ledr->ops->start(ledr, &upper->ledr); + + /* Setup LED G */ + + upper->ledg.frequency = 100; + upper->ledg.duty = green; + + ledg->ops->start(ledg, &upper->ledg); + + /* Setup LED B */ + + upper->ledb.frequency = 100; + upper->ledb.duty = blue; + + ledb->ops->start(ledb, &upper->ledb); + + return buflen; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rgbled_register + * + * Description: + * This function binds three instances of a "lower half" PWM driver with + * the "upper half" RGB LED device and registers that device so that can + * be used by application code. + * + * + * Input parameters: + * path - The full path to the driver to be registers in the NuttX pseudo- + * filesystem. The recommended convention is to name all PWM drivers + * as "/dev/rgdbled0", "/dev/rgbled1", etc. where the driver path + * differs only in the "minor" number at the end of the device name. + * ledr, ledg, and ledb - A pointer to an instance of lower half PWM + * drivers for the red, green, and blue LEDs, respectively. These + * instances will be bound to the RGB LED driver and must persists as + * long as that driver persists. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +int rgbled_register(FAR const char *path, FAR struct pwm_lowerhalf_s *ledr, + FAR struct pwm_lowerhalf_s *ledg, + FAR struct pwm_lowerhalf_s *ledb) +{ + FAR struct rgbled_upperhalf_s *upper; + + /* Allocate the upper-half data structure */ + + upper = (FAR struct rgbled_upperhalf_s *) + kmm_zalloc(sizeof(struct rgbled_upperhalf_s)); + + if (!upper) + { + pwmdbg("Allocation failed\n"); + return -ENOMEM; + } + + /* Initialize the PWM device structure (it was already zeroed by + * kmm_zalloc()) + */ + + sem_init(&upper->exclsem, 0, 1); + upper->devledr = ledr; + upper->devledg = ledg; + upper->devledb = ledb; + + /* Register the PWM device */ + + pwmvdbg("Registering %s\n", path); + return register_driver(path, &g_rgbledops, 0666, upper); +} + +#endif /* CONFIG_RGBLED */ diff --git a/include/nuttx/leds/rgbled.h b/include/nuttx/leds/rgbled.h new file mode 100644 index 0000000000..07560d6a6e --- /dev/null +++ b/include/nuttx/leds/rgbled.h @@ -0,0 +1,99 @@ +/**************************************************************************** + * include/nuttx/rgbled.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_LEDS_RGBLED_H +#define __INCLUDE_NUTTX_LEDS_RGBLED_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#include +#include + +#ifdef CONFIG_RGBLED + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: rgbled_register + * + * Description: + * This function binds three instances of a "lower half" PWM driver with + * the "upper half" RGB LED device and registers that device so that can + * be used by application code. + * + * + * Input parameters: + * path - The full path to the driver to be registers in the NuttX pseudo- + * filesystem. The recommended convention is to name all PWM drivers + * as "/dev/rgdbled0", "/dev/rgbled1", etc. where the driver path + * differs only in the "minor" number at the end of the device name. + * ledr, ledg, and ledb - A pointer to an instance of lower half PWM + * drivers for the red, green, and blue LEDs, respectively. These + * instances will be bound to the RGB LED driver and must persists as + * long as that driver persists. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +int rgbled_register(FAR const char *path, FAR struct pwm_lowerhalf_s *ledr, + FAR struct pwm_lowerhalf_s *ledg, + FAR struct pwm_lowerhalf_s *ledb); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_RGBLED */ +#endif /* __INCLUDE_NUTTX_LEDS_RGBLED_H */ -- GitLab From bc0648119e47507cee56a8d3366305285a6767f7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Feb 2016 09:09:24 -0600 Subject: [PATCH 787/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 5f1b167e40..1182e9ab34 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5f1b167e400e1dc23e5d6075db620d333a4414ff +Subproject commit 1182e9ab34aeefb94d9e502257effb94ea84091e diff --git a/configs b/configs index 8fcf8b1b91..0a0d6b3232 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 8fcf8b1b913dab18a3b1b4234258394b9d940561 +Subproject commit 0a0d6b3232f83e23f50a24698ffe6c22806df981 -- GitLab From 7c4444488361c9b0b28da37221e6b445b8cd8f38 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Feb 2016 16:26:04 -0600 Subject: [PATCH 788/858] FAT: Add an option to force all transfers to be performed indirectly through the FAT file system's internal sector buffers --- ChangeLog | 8 ++++++++ arch | 2 +- fs/fat/Kconfig | 26 +++++++++++++++++++++++++- fs/fat/fs_fat32.c | 18 ++++++++++++++---- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff70a64918..878c036e54 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11515,4 +11515,12 @@ * sched/pthread: Add pthread_setaffinity() and pthread_getaffinity() (2016-02-19). * sched/sched: Add sched_setaffinity() and sched_getaffinity() (2016-02-19). + * drivers/leds/rgbled.c: Add a driver to manage a RGB LED via PWM. From + Alan Carvalho de Assis (2016-02-22). + * arch/arm/src/stm32fcdiscovery: Add PWM support for the onboard RGB LED + From Alan Carvalho de Assis (2016-02-22). + * arch/arm/src/samv7: HSMCI driver can now be configured to handle unaligned + data buffers (2016-02-22). + * fs/fat: Add an option to force all transfers to be performed indirectly + using the FAT file system's internal sector buffers (2016-02-22). diff --git a/arch b/arch index 1182e9ab34..7ed1d2eb50 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1182e9ab34aeefb94d9e502257effb94ea84091e +Subproject commit 7ed1d2eb50bcfc637e21fcf41521e562d4a521a1 diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index d9bd865c3a..d0ec9a950a 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -13,6 +13,7 @@ config FS_FAT Enable FAT filesystem support if FS_FAT + config FAT_LCNAMES bool "FAT upper/lower names" default n @@ -49,6 +50,29 @@ config FS_FATTIME much sense in supporting FAT date and time unless you have a hardware RTC or other way to get the time and date. +config FAT_FORCE_INDIRECT +bool "Force all in-direct transfers" +default n +---help--- + Normally, the default behavior for the FAT file system is to perform + data transfers indirectly though specially allocated sector buffers + or, under certain circumstances, directly through user provided + buffers . These circumstances are: (1) The transfer is being + performed from the beginning of a sector (2) the user-provided + buffer will hold the full sector of data. + + Some hardware, however, may require special DMA-capable memory or + specially aligned memory in order to perform the transfers. In this + case, there may be no circumstance where the user buffer can be used. + Selecting this option will disable all attempts to use the user- + provided buffer: All transfers will be force to be performed + indirectly through the FAT file systems sector buffers. + + Note: This will have the negative impact of: (1) An extra data + copy to transfer the data between the user buffer and the FAT file + systems internal sector buffers, and (2) A loss of performance + because I/O will be limited to one sector at a time. + config FAT_DMAMEMORY bool "DMA memory allocator" default n @@ -66,4 +90,4 @@ config FAT_DMAMEMORY corresponding function that will be called to free the DMA-capable memory. -endif +endif # FAT diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index e344160ea5..ac492809f0 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -479,13 +479,16 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer, FAR struct fat_file_s *ff; unsigned int bytesread; unsigned int readsize; - unsigned int nsectors; size_t bytesleft; int32_t cluster; FAR uint8_t *userbuffer = (FAR uint8_t *)buffer; int sectorindex; int ret; + +#ifndef CONFIG_FAT_FORCE_INDIRECT + unsigned int nsectors; bool force_indirect = false; +#endif /* Sanity checks */ @@ -590,6 +593,7 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer, fat_read_restart: #endif +#ifndef CONFIG_FAT_FORCE_INDIRECT /* Check if the user has provided a buffer large enough to hold one * or more complete sectors -AND- the read is aligned to a sector * boundary. @@ -636,7 +640,7 @@ fat_read_restart: force_indirect = true; goto fat_read_restart; } -#endif +#endif /* CONFIG_FAT_DMAMEMORY */ goto errout_with_semaphore; } @@ -646,6 +650,7 @@ fat_read_restart: bytesread = nsectors * fs->fs_hwsectorsize; } else +#endif /* CONFIG_FAT_FORCE_INDIRECT */ { /* We are reading a partial sector, or handling a non-DMA-able * whole-sector transfer. First, read the whole sector @@ -709,11 +714,14 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer, int32_t cluster; unsigned int byteswritten; unsigned int writesize; - unsigned int nsectors; FAR uint8_t *userbuffer = (FAR uint8_t *)buffer; int sectorindex; int ret; + +#ifndef CONFIG_FAT_FORCE_INDIRECT + unsigned int nsectors; bool force_indirect = false; +#endif /* Sanity checks. I have seen the following assertion misfire if * CONFIG_DEBUG_MM is enabled while re-directing output to a @@ -844,6 +852,7 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer, fat_write_restart: #endif +#ifndef CONFIG_FAT_FORCE_INDIRECT /* Check if the user has provided a buffer large enough to * hold one or more complete sectors. */ @@ -890,7 +899,7 @@ fat_write_restart: force_indirect = true; goto fat_write_restart; } -#endif +#endif /* CONFIG_FAT_DMAMEMORY */ goto errout_with_semaphore; } @@ -901,6 +910,7 @@ fat_write_restart: ff->ff_bflags |= FFBUFF_MODIFIED; } else +#endif /* CONFIG_FAT_FORCE_INDIRECT */ { /* Decide whether we are performing a read-modify-write * operation, in which case we have to read the existing sector -- GitLab From c620b321b1d0270539dd751f5a3a53fe8d6c4c8e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Feb 2016 18:25:58 -0600 Subject: [PATCH 789/858] FAT: Add a new configuration option to decouple the logic that retries the direct transfer from the logic that enables DMA memory allocators. --- arch | 2 +- fs/fat/Kconfig | 45 ++++++++++++++++++++++++++++++++++++++++++--- fs/fat/fs_fat32.c | 45 +++++++++++++++++++++++---------------------- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/arch b/arch index 7ed1d2eb50..50415398b1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7ed1d2eb50bcfc637e21fcf41521e562d4a521a1 +Subproject commit 50415398b1ae76ffb66df9813f4647dcbfcee234 diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index d0ec9a950a..9176484f91 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -51,9 +51,9 @@ config FS_FATTIME hardware RTC or other way to get the time and date. config FAT_FORCE_INDIRECT -bool "Force all in-direct transfers" -default n ----help--- + bool "Force direct transfers" + default n + ---help--- Normally, the default behavior for the FAT file system is to perform data transfers indirectly though specially allocated sector buffers or, under certain circumstances, directly through user provided @@ -73,9 +73,20 @@ default n systems internal sector buffers, and (2) A loss of performance because I/O will be limited to one sector at a time. + This would typically be used with CONFIG_FAT_DMAMEMORY so that + special memory allocators are also used and transfers are also + performed using only that specially allocated memory. + CONFIG_FAT_DMAMEMORY, on the other hand, is often used without + CONFIG_FAT_FORCE_INDIRECT when the user memory buffers may come + from mixed locations, some of which are DMA-able and some of + which are not. But CONFIG_FAT_FORCE_INDIRECT could be used + without CONFIG_FAT_DMAMEMORY if there is, for example, only a + memory aligment constraints. + config FAT_DMAMEMORY bool "DMA memory allocator" default n + select FAT_DIRECT_RETRY if !FAT_FORCE_INDIRECT ---help--- The FAT file system allocates two I/O buffers for data transfer, each are the size of one device sector. One of the buffers is allocated @@ -90,4 +101,32 @@ config FAT_DMAMEMORY corresponding function that will be called to free the DMA-capable memory. +config FAT_DIRECT_RETRY + bool "Direct transfer retry" + default y if FAT_DMAMEMORY + default n if !FAT_DMAMEMORY + depends on !FAT_FORCE_INDIRECT + ---help--- + The FAT file system contains internal, well aligned sector buffers + for indirect data transfer. These transfers are indirect in the + sense that that the actual transfer occurs into/out of the sector + buffers and an additional copy is necessary to/from the user- + provided I/O buffers. But under certain conditions, the FAT file + system will use the caller-provided I/O buffers directly to improve + efficiency. Those conditions are (1) CONFIG_FAT_FORCE_INDIRECT is + not defined, (2) The access is to/from the beginning of a sector, + and (3) the user provided buffer is large enough to hold an entire + sector. + + The lower level SDIO driver may have, certain requirements on the + memory buffer in order to perform the transfer. Perhaps special + DMA memory should be used (with CONFIG_FAT_DMAMEMORY) or perhaps + some special memory alignment is required to interace with the + hardware. + + If this option is selected, then the FAT file system will first + try the user provided I/O buffer under above conditions. If the + transfer fails with -EFAULT. then the FAT file system will try one + more time using the internal sector buffers. + endif # FAT diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index ac492809f0..7fddec4d03 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -409,17 +409,16 @@ static int fat_close(FAR struct file *filep) /* Recover our private data from the struct file instance */ - ff = filep->f_priv; + ff = filep->f_priv; + inode = filep->f_inode; + fs = inode->i_private; + + DEBUGASSERT(fs != NULL); /* Check for the forced mount condition */ if ((ff->ff_bflags & UMOUNT_FORCED) == 0) { - inode = filep->f_inode; - fs = inode->i_private; - - DEBUGASSERT(fs != NULL); - /* Do not check if the mount is healthy. We must support closing of * the file even when there is healthy mount. */ @@ -589,7 +588,7 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer, ff->ff_sectorsincluster = fs->fs_fatsecperclus; } -#ifdef CONFIG_FAT_DMAMEMORY /* Warning avoidance */ +#ifdef CONFIG_FAT_DIRECT_RETRY /* Warning avoidance */ fat_read_restart: #endif @@ -626,21 +625,22 @@ fat_read_restart: ret = fat_hwread(fs, userbuffer, ff->ff_currentsector, nsectors); if (ret < 0) { -#ifdef CONFIG_FAT_DMAMEMORY +#ifdef CONFIG_FAT_DIRECT_RETRY /* The low-level driver may return -EFAULT in the case where - * the transfer cannot be performed due to DMA constraints. - * It is probable that the buffer is completely un-DMA-able, - * so force indirect transfers via the sector buffer and - * restart the operation. + * the transfer cannot be performed due to buffer memory + * constraints. It is probable that the buffer is completely + * un-DMA-able or improperly aligned. In this case, force + * indirect transfers via the sector buffer and restart the + * operation (unless we have already tried that). */ - if (ret == -EFAULT) + if (ret == -EFAULT && !force_indirect) { fdbg("DMA: read alignment error, restarting indirect\n"); force_indirect = true; goto fat_read_restart; } -#endif /* CONFIG_FAT_DMAMEMORY */ +#endif /* CONFIG_FAT_DIRECT_RETRY */ goto errout_with_semaphore; } @@ -848,7 +848,7 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer, ff->ff_currentsector = fat_cluster2sector(fs, cluster); } -#ifdef CONFIG_FAT_DMAMEMORY /* Warning avoidance */ +#ifdef CONFIG_FAT_DIRECT_RETRY /* Warning avoidance */ fat_write_restart: #endif @@ -885,21 +885,22 @@ fat_write_restart: ret = fat_hwwrite(fs, userbuffer, ff->ff_currentsector, nsectors); if (ret < 0) { -#ifdef CONFIG_FAT_DMAMEMORY +#ifdef CONFIG_FAT_DIRECT_RETRY /* The low-level driver may return -EFAULT in the case where - * the transfer cannot be performed due to DMA constraints. - * It is probable that the buffer is completely un-DMA-able, - * so force indirect transfers via the sector buffer and - * restart the operation. + * the transfer cannot be performed due to buffer memory + * constraints. It is probable that the buffer is completely + * un-DMA-able or improperly aligned. In this case, force + * indirect transfers via the sector buffer and restart the + * operation (unless we have already tried that). */ - if (ret == -EFAULT) + if (ret == -EFAULT && !force_indirect) { fdbg("DMA: write alignment error, restarting indirect\n"); force_indirect = true; goto fat_write_restart; } -#endif /* CONFIG_FAT_DMAMEMORY */ +#endif /* CONFIG_FAT_DIRECT_RETRY */ goto errout_with_semaphore; } -- GitLab From 0682671ffe4d64bb361e07f131f22161333279db Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 23 Feb 2016 06:38:51 -0600 Subject: [PATCH 790/858] Update Kconfig help comments --- arch | 2 +- fs/fat/Kconfig | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch b/arch index 50415398b1..6e6f7947bc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 50415398b1ae76ffb66df9813f4647dcbfcee234 +Subproject commit 6e6f7947bc11679ec220022b696b8d47badf45f7 diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index 9176484f91..d02b3d7304 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -83,6 +83,20 @@ config FAT_FORCE_INDIRECT without CONFIG_FAT_DMAMEMORY if there is, for example, only a memory aligment constraints. + FORCE_ DMA DIRECT EXAMPLE USAGE + INDIRECT MEMORY RETRY + Y Y * Use specially allocated memory; + Never use caller provided buffer + Y N * Not recommended + N Y ** Special memory required; user memory + has mixed capability; sometimes + caller memory is not usable + N N Y No special memory but there are + alignment requirements; return is + caller buffer is not properly aligned + N N N User memory can always be used for + transfer. + config FAT_DMAMEMORY bool "DMA memory allocator" default n @@ -101,6 +115,20 @@ config FAT_DMAMEMORY corresponding function that will be called to free the DMA-capable memory. + FORCE_ DMA DIRECT EXAMPLE USAGE + INDIRECT MEMORY RETRY + Y Y * Use specially allocated memory; + Never use caller provided buffer + Y N * Not recommended + N Y ** Special memory required; user memory + has mixed capability; sometimes + caller memory is not usable + N N Y No special memory but there are + alignment requirements; return is + caller buffer is not properly aligned + N N N User memory can always be used for + transfer. + config FAT_DIRECT_RETRY bool "Direct transfer retry" default y if FAT_DMAMEMORY @@ -129,4 +157,18 @@ config FAT_DIRECT_RETRY transfer fails with -EFAULT. then the FAT file system will try one more time using the internal sector buffers. + FORCE_ DMA DIRECT EXAMPLE USAGE + INDIRECT MEMORY RETRY + Y Y * Use specially allocated memory; + Never use caller provided buffer + Y N * Not recommended + N Y ** Special memory required; user memory + has mixed capability; sometimes + caller memory is not usable + N N Y No special memory but there are + alignment requirements; return is + caller buffer is not properly aligned + N N N User memory can always be used for + transfer. + endif # FAT -- GitLab From 35df528f69a98ce4310e1537356f324d756621b6 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Tue, 23 Feb 2016 07:33:52 -0600 Subject: [PATCH 791/858] PCA9555: Remove duplicate variable declaration --- configs | 2 +- drivers/ioexpander/pca9555.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/configs b/configs index 0a0d6b3232..3ffa424853 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0a0d6b3232f83e23f50a24698ffe6c22806df981 +Subproject commit 3ffa42485392801e69a4a17e1dab42b6174a9332 diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 422852cd26..e8273ae817 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -459,8 +459,6 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev, int index; int pin; - int ret; - /* Get exclusive access to the PCA555 */ pca9555_lock(pca); -- GitLab From d0c09771dbdac03d5bf28b62c06f21b9da88b963 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 23 Feb 2016 10:27:40 -0600 Subject: [PATCH 792/858] sched: Recent change of ASSERT to DEBUGASSERT causes a crash when debug is diabled because there is a critical function call within the assertion --- configs | 2 +- sched/sched/sched_setpriority.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs b/configs index 3ffa424853..521652bd7f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3ffa42485392801e69a4a17e1dab42b6174a9332 +Subproject commit 521652bd7fcedc8c92e928fccb8c493f30456b59 diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index ba969eb13f..9e2c9384aa 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -185,7 +185,7 @@ static void sched_readytorun_setpriority(FAR struct tcb_s *tcb, /* Put it back into the correct ready-to-run task list */ - DEBUGASSERT(!sched_addreadytorun(tcb)); + ASSERT(!sched_addreadytorun(tcb)); } } -- GitLab From b6f5ffa9a857fa6770e0abbbfad81429a990655d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 24 Feb 2016 11:54:02 -0600 Subject: [PATCH 793/858] CDC/AC: too man right parentheses if IFLOW_CONTROL enabled --- configs | 2 +- drivers/usbhost/usbhost_cdcacm.c | 8 ++++---- fs/fat/Kconfig | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/configs b/configs index 521652bd7f..b5ee355239 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 521652bd7fcedc8c92e928fccb8c493f30456b59 +Subproject commit b5ee35523986bd879009b829723b1c85e1b4662e diff --git a/drivers/usbhost/usbhost_cdcacm.c b/drivers/usbhost/usbhost_cdcacm.c index ef00675627..0c35d61bf4 100644 --- a/drivers/usbhost/usbhost_cdcacm.c +++ b/drivers/usbhost/usbhost_cdcacm.c @@ -249,7 +249,7 @@ struct usbhost_cdcacm_s bool rxena; /* True: RX "interrupts" enabled */ #ifdef CONFIG_SERIAL_IFLOWCONTROL bool iflow; /* True: Input flow control (RTS) enabled */ - bool rts; /* True: Input flow control is effect */ + bool rts; /* True: Input flow control is in effect */ #endif #ifdef CONFIG_SERIAL_OFLOWCONTROL bool oflow; /* True: Output flow control (CTS) enabled */ @@ -2562,7 +2562,7 @@ static void usbhost_rxint(FAR struct uart_dev_s *uartdev, bool enable) */ #ifdef CONFIG_SERIAL_IFLOWCONTROL - if (priv->rts)) + if (priv->rts) #endif { ret = work_queue(LPWORK, &priv->rxwork, @@ -2654,7 +2654,7 @@ static bool usbhost_rxflowcontrol(FAR struct uart_dev_s *uartdev, * RTS. */ - priv ->rts = false; + priv->rts = false; /* Cancel any pending RX data reception work */ @@ -2668,7 +2668,7 @@ static bool usbhost_rxflowcontrol(FAR struct uart_dev_s *uartdev, * RTS. */ - priv ->rts = true; + priv->rts = true; /* Restart RX data reception work flow unless RX reception is * disabled. diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index d02b3d7304..1c20a9ddd1 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -97,6 +97,9 @@ config FAT_FORCE_INDIRECT N N N User memory can always be used for transfer. + * CONFIG_DIRECT_RETRY cannot be selected with CONFIG_FORCE_INDIRECT + ** CONFIG_DIRECT_RETRY is automatically selected with CONFIG_DMA_MEMORY + config FAT_DMAMEMORY bool "DMA memory allocator" default n @@ -129,6 +132,9 @@ config FAT_DMAMEMORY N N N User memory can always be used for transfer. + * CONFIG_DIRECT_RETRY cannot be selected with CONFIG_FORCE_INDIRECT + ** CONFIG_DIRECT_RETRY is automatically selected with CONFIG_DMA_MEMORY + config FAT_DIRECT_RETRY bool "Direct transfer retry" default y if FAT_DMAMEMORY @@ -171,4 +177,7 @@ config FAT_DIRECT_RETRY N N N User memory can always be used for transfer. + * CONFIG_DIRECT_RETRY cannot be selected with CONFIG_FORCE_INDIRECT + ** CONFIG_DIRECT_RETRY is automatically selected with CONFIG_DMA_MEMORY + endif # FAT -- GitLab From d19e9cc448c4b96c528bd1d5d4af1855a5991972 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 24 Feb 2016 16:10:20 -0600 Subject: [PATCH 794/858] networking: cosmetic changes --- arch | 2 +- net/arp/Make.defs | 2 +- net/pkt/pkt.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 6e6f7947bc..733010246b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 6e6f7947bc11679ec220022b696b8d47badf45f7 +Subproject commit 733010246bc55e28b8c99bc13798955a207c9860 diff --git a/net/arp/Make.defs b/net/arp/Make.defs index acbe39d5ae..36001d9957 100644 --- a/net/arp/Make.defs +++ b/net/arp/Make.defs @@ -36,7 +36,7 @@ # ARP support is available for Ethernet only ifeq ($(CONFIG_NET_ARP),y) -NET_CSRCS +=arp_arpin.c arp_out.c arp_format.c arp_table.c arp_timer.c +NET_CSRCS += arp_arpin.c arp_out.c arp_format.c arp_table.c arp_timer.c ifeq ($(CONFIG_NET_ARP_IPIN),y) NET_CSRCS += arp_ipin.c diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h index 12138d4aa3..dc5c3812c4 100644 --- a/net/pkt/pkt.h +++ b/net/pkt/pkt.h @@ -94,7 +94,7 @@ extern "C" * Public Function Prototypes ****************************************************************************/ - struct eth_hdr_s; /* Forward reference */ +struct eth_hdr_s; /* Forward reference */ /* Defined in pkt_conn.c ****************************************************/ /**************************************************************************** -- GitLab From bcbd8ee964f97584ef51856509632320d6aee769 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 24 Feb 2016 19:02:51 -0600 Subject: [PATCH 795/858] Networking: Cosmetic change --- arch | 2 +- net/local/local_connect.c | 4 ++-- net/netdev/netdev_ioctl.c | 10 ++++++---- net/pkt/pkt_conn.c | 4 ++-- net/socket/bind.c | 4 ++-- net/socket/net_sockets.c | 4 ++-- net/udp/udp_conn.c | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch b/arch index 733010246b..e42c14f776 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 733010246bc55e28b8c99bc13798955a207c9860 +Subproject commit e42c14f77680579dbbfea48e257a8bda7079ddbf diff --git a/net/local/local_connect.c b/net/local/local_connect.c index f1176ad3c8..1eab722083 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/local/local_connnect.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -97,7 +97,7 @@ static inline void _local_semtake(sem_t *sem) * the wait was awakened by a signal. */ - ASSERT(*get_errno_ptr() == EINTR); + DEBUGASSERT(get_errno() == EINTR); } } diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index d54c3f6b05..c4a1a650d0 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/netdev/netdev_ioctl.c * - * Copyright (C) 2007-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2012, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1083,26 +1083,28 @@ int netdev_ioctl(int sockfd, int cmd, unsigned long arg) /* Execute the command */ ret = netdev_ifrioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg)); + #ifdef CONFIG_NET_IGMP + /* Check for address filtering commands */ + if (ret == -ENOTTY) { - ret = netdev_imsfioctl(psock, cmd, (FAR struct ip_msfilter *)((uintptr_t)arg)); } #endif +#ifdef CONFIG_NET_ARP /* Check for ARP table IOCTL commands */ -#ifdef CONFIG_NET_ARP if (ret == -ENOTTY) { ret = netdev_arpioctl(psock, cmd, (FAR struct arpreq *)((uintptr_t)arg)); } #endif +#ifdef CONFIG_NET_ROUTE /* Check for Routing table IOCTL commands */ -#ifdef CONFIG_NET_ROUTE if (ret == -ENOTTY) { ret = netdev_rtioctl(psock, cmd, (FAR struct rtentry *)((uintptr_t)arg)); diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c index c47eea2d11..52345043b4 100644 --- a/net/pkt/pkt_conn.c +++ b/net/pkt/pkt_conn.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/pkt/pkt_conn.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Large parts of this file were leveraged from uIP logic: @@ -97,7 +97,7 @@ static inline void _pkt_semtake(sem_t *sem) * the wait was awakened by a signal. */ - ASSERT(*get_errno_ptr() == EINTR); + DEBUGASSERT(get_errno() == EINTR); } } diff --git a/net/socket/bind.c b/net/socket/bind.c index fa39ed6f64..8095c71807 100644 --- a/net/socket/bind.c +++ b/net/socket/bind.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/bind.c * - * Copyright (C) 2007-2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -316,7 +316,7 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr, return OK; errout: - *get_errno_ptr() = err; + set_errno(err); return ERROR; } diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index 4d2ae7dd62..31274117c7 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/net_sockets.c * - * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,7 +67,7 @@ static void _net_semtake(FAR struct socketlist *list) * the wait was awakened by a signal. */ - ASSERT(*get_errno_ptr() == EINTR); + DEBUGASSERT(get_errno() == EINTR); } } diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index 7a0ce2e60c..ddd599382e 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/udp/udp_conn.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Large parts of this file were leveraged from uIP logic: @@ -115,7 +115,7 @@ static inline void _udp_semtake(FAR sem_t *sem) * the wait was awakened by a signal. */ - ASSERT(*get_errno_ptr() == EINTR); + ASSERT(get_errno() == EINTR); } } -- GitLab From 1ed1765e1a7552fc35e64a9097e898495ee01c9f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 08:19:10 -0600 Subject: [PATCH 796/858] sys/socket.h: Add IEEE802.15-4 protocol family --- arch | 2 +- include/sys/socket.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch b/arch index e42c14f776..1fb2ed39e0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e42c14f77680579dbbfea48e257a8bda7079ddbf +Subproject commit 1fb2ed39e08f3ec82e68a16a1bc63dc9e0e6e6d2 diff --git a/include/sys/socket.h b/include/sys/socket.h index 0f9f10f4d1..8f1df8818a 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/socket.h * - * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -64,6 +64,7 @@ #define PF_ATMPVC 8 /* Access to raw ATM PVCs */ #define PF_APPLETALK 9 /* Appletalk */ #define PF_PACKET 10 /* Low level packet interface */ +#define PF_IEEE802154 11 /* IEEE802154 sockets */ /* Address families */ -- GitLab From e4e61810985e5f04b9e8e2d34bdb8e61d220b55c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 10:43:51 -0600 Subject: [PATCH 797/858] net/: IEEE 802.15-4 basic build build structure. --- include/nuttx/net/arp.h | 3 ++- include/nuttx/net/net.h | 1 + include/sys/socket.h | 2 +- net/Kconfig | 1 + net/Makefile | 1 + net/devif/devif.h | 20 +++++++-------- net/ieee802154/Kconfig | 19 ++++++++++++++ net/ieee802154/Make.defs | 49 ++++++++++++++++++++++++++++++++++++ net/netdev/netdev_register.c | 14 ++++++++--- net/pkt/pkt.h | 2 +- 10 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 net/ieee802154/Kconfig create mode 100644 net/ieee802154/Make.defs diff --git a/include/nuttx/net/arp.h b/include/nuttx/net/arp.h index dab5e27876..4768c9fdff 100644 --- a/include/nuttx/net/arp.h +++ b/include/nuttx/net/arp.h @@ -68,7 +68,8 @@ * in the first 6-bytes of the sockaddr sa_data array. */ -#define ARPHRD_ETHER 1 /* Only Ethernet is supported */ +#define ARPHRD_ETHER 1 /* Ethernet */ +#define ARPHRD_IEEE802154 804 /* IEEE 802-15-4 */ /**************************************************************************** * Public Types diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 07f6cead77..86de2a18fa 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -79,6 +79,7 @@ enum net_lltype_e NET_LL_LOOPBACK, /* Local loopback */ NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ NET_LL_TUN, /* TUN Virtual Network Device */ + NET_LL_IEEE802154 /* IEEE 802.15-4 */ }; /* This defines a bitmap big enough for one bit for each socket option */ diff --git a/include/sys/socket.h b/include/sys/socket.h index 8f1df8818a..71710d308e 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -64,7 +64,7 @@ #define PF_ATMPVC 8 /* Access to raw ATM PVCs */ #define PF_APPLETALK 9 /* Appletalk */ #define PF_PACKET 10 /* Low level packet interface */ -#define PF_IEEE802154 11 /* IEEE802154 sockets */ +#define PF_IEEE802154 11 /* IEEE802.15-4 sockets */ /* Address families */ diff --git a/net/Kconfig b/net/Kconfig index 52a425900a..d2d7c1c0cd 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -269,6 +269,7 @@ source "net/pkt/Kconfig" source "net/local/Kconfig" source "net/tcp/Kconfig" source "net/udp/Kconfig" +source "net/ieee802154/Kconfig" source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" source "net/igmp/Kconfig" diff --git a/net/Makefile b/net/Makefile index 4d42b212b5..a8628c4a9a 100644 --- a/net/Makefile +++ b/net/Makefile @@ -67,6 +67,7 @@ include pkt/Make.defs include local/Make.defs include tcp/Make.defs include udp/Make.defs +include ieee802154/Make.defs include devif/Make.defs include loopback/Make.defs include route/Make.defs diff --git a/net/devif/devif.h b/net/devif/devif.h index 58f7fffa9d..2251ffcad0 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -1,7 +1,7 @@ /**************************************************************************** * net/devif/devif.h * - * Copyright (C) 2007-2009, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * This logic was leveraged from uIP which also has a BSD-style license: @@ -296,7 +296,7 @@ void devif_initialize(void); * Configure the pre-allocated callback structures into a free list. * * Assumptions: - * This function is called with interrupts disabled. + * This function must be called with the network locked. * ****************************************************************************/ @@ -314,7 +314,7 @@ void devif_callback_init(void); * callback. * * Assumptions: - * This function is called with the network locked. + * This function must be called with the network locked. * ****************************************************************************/ @@ -336,7 +336,7 @@ FAR struct devif_callback_s * * The callback structure will be freed in any event. * * Assumptions: - * This function is called with the network locked. + * This function must be called with the network locked. * ****************************************************************************/ @@ -360,7 +360,7 @@ void devif_conn_callback_free(FAR struct net_driver_s *dev, * The callback structure will be freed in any event. * * Assumptions: - * This function is called with the network locked. + * This function must be called with the network locked. * ****************************************************************************/ @@ -386,7 +386,7 @@ void devif_dev_callback_free(FAR struct net_driver_s *dev, * The updated flags as modified by the callback functions. * * Assumptions: - * This function is called with the network locked. + * This function must be called with the network locked. * ****************************************************************************/ @@ -411,7 +411,7 @@ uint16_t devif_conn_event(FAR struct net_driver_s *dev, FAR void *pvconn, * The updated flags as modified by the callback functions. * * Assumptions: - * This function is called with the network locked. + * This function must be called with the network locked. * ****************************************************************************/ @@ -455,8 +455,7 @@ void devif_send(FAR struct net_driver_s *dev, FAR const void *buf, int len); * in an I/O buffer chain, rather than a flat buffer. * * Assumptions: - * Called from the interrupt level or, at a minimum, with interrupts - * disabled. + * This function must be called with the network locked. * ****************************************************************************/ @@ -478,8 +477,7 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *buf, * no header on the data. * * Assumptions: - * Called from the interrupt level or, at a minimum, with interrupts - * disabled. + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig new file mode 100644 index 0000000000..3a31761693 --- /dev/null +++ b/net/ieee802154/Kconfig @@ -0,0 +1,19 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menu "IEEE802.15-4 Configuration" + +config NET_IEEE802154 + bool "IEEE802.15-4 support" + default n + depends on EXPERIMENTAL + ---help--- + Enable IEEE802.15-4 protocol socket support + +if NET_IEEE802154 + + +endif # NET_IEEE802154 +endmenu # IEEE802.15-4 Configuration diff --git a/net/ieee802154/Make.defs b/net/ieee802154/Make.defs new file mode 100644 index 0000000000..93d849eff7 --- /dev/null +++ b/net/ieee802154/Make.defs @@ -0,0 +1,49 @@ +############################################################################ +# net/ieee802154/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# IEEE802.15-4 support + +ifeq ($(CONFIG_NET_IEEE802154),y) + +# Include IEEE802.15-4 file in the build + +# NET_CSRCS += + +# Include the ieee802154 directory in the build + +DEPPATH += --dep-path ieee802154 +VPATH += :ieee802154 + +endif # CONFIG_NET_IEEE802154 diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index fd6ce96985..b850dc109f 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -194,7 +194,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) switch (lltype) { #ifdef CONFIG_NET_LOOPBACK - case NET_LL_LOOPBACK: /* Local loopback */ + case NET_LL_LOOPBACK: /* Local loopback */ dev->d_llhdrlen = 0; dev->d_mtu = NET_LO_MTU; #ifdef CONFIG_NET_TCP @@ -205,7 +205,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #endif #ifdef CONFIG_NET_ETHERNET - case NET_LL_ETHERNET: /* Ethernet */ + case NET_LL_ETHERNET: /* Ethernet */ dev->d_llhdrlen = ETH_HDRLEN; dev->d_mtu = CONFIG_NET_ETH_MTU; #ifdef CONFIG_NET_TCP @@ -215,8 +215,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) break; #endif +#ifdef CONFIG_NET_IEEE802154 + case NET_LL_IEEE802154: /* IEEE802.15-4 */ + nlldbg("ERROR: IEEE 802.15-4 not yet supported\n"); + return -ENOSYS; +#endif + #ifdef CONFIG_NET_SLIP - case NET_LL_SLIP: /* Serial Line Internet Protocol (SLIP) */ + case NET_LL_SLIP: /* Serial Line Internet Protocol (SLIP) */ dev->d_llhdrlen = 0; dev->d_mtu = CONFIG_NET_SLIP_MTU; #ifdef CONFIG_NET_TCP @@ -227,7 +233,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #endif #ifdef CONFIG_NET_TUN - case NET_LL_TUN: /* Virtual Network Device (TUN) */ + case NET_LL_TUN: /* Virtual Network Device (TUN) */ dev->d_llhdrlen = 0; dev->d_mtu = CONFIG_NET_TUN_MTU; #ifdef CONFIG_NET_TCP diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h index dc5c3812c4..295c40b07e 100644 --- a/net/pkt/pkt.h +++ b/net/pkt/pkt.h @@ -61,7 +61,7 @@ * Public Type Definitions ****************************************************************************/ -/* Representation of a uIP packet socket connection */ +/* Representation of a packet socket connection */ struct devif_callback_s; /* Forward reference */ -- GitLab From 6af9b23df5d6a7ea70db450cd15219ce53d7b907 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 13:59:42 -0600 Subject: [PATCH 798/858] libc/netdb: Fix some compile issues when IPv6 is enabled --- libc/netdb/lib_dnsquery.c | 4 ++-- libc/netdb/lib_gethostbynamer.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/netdb/lib_dnsquery.c b/libc/netdb/lib_dnsquery.c index 283b3ae8fe..54a5046fab 100644 --- a/libc/netdb/lib_dnsquery.c +++ b/libc/netdb/lib_dnsquery.c @@ -190,7 +190,7 @@ static int dns_send_query(int sd, FAR const char *name, #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (uaddr->addr.sa_family == AF_INET) + if (uaddr->ipv4.sin_family == AF_INET) #endif { addrlen = sizeof(struct sockaddr_in); @@ -521,7 +521,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, #ifdef CONFIG_NET_IPv6 /* Is this an IPv4 address? */ - if (query->addr.sa_family == AF_INET6) + if (query->addr->sa_family == AF_INET6) { /* Yes.. verify the address size */ diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 747cf6a0c5..80109dfe77 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -382,7 +382,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; - addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr; } #endif @@ -524,7 +524,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; - addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr; } #endif -- GitLab From 0b441ff1f493044f429ffee03e2636086c9cb5f0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 14:01:22 -0600 Subject: [PATCH 799/858] net/: Add basic IEEE 802.15-4 socket support --- ChangeLog | 2 ++ configs | 2 +- net/ieee802154/Kconfig | 31 ++++++++++++++++++++++++++++++- net/ieee802154/Make.defs | 2 +- net/netdev/netdev_register.c | 25 +++++++++++++++---------- net/socket/net_close.c | 4 ++-- net/socket/net_sendfile.c | 9 ++++++--- net/socket/recvfrom.c | 9 ++++++--- net/socket/socket.c | 7 +++++-- net/tcp/tcp.h | 2 +- net/tcp/tcp_accept.c | 4 +++- net/tcp/tcp_conn.c | 2 ++ net/tcp/tcp_send_buffered.c | 12 ++++++++---- net/tcp/tcp_send_unbuffered.c | 12 ++++++++---- net/udp/udp.h | 2 +- net/udp/udp_callback.c | 2 +- net/udp/udp_psock_sendto.c | 6 ++++-- net/udp/udp_send.c | 6 +++--- 18 files changed, 99 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 878c036e54..b0e42092ed 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11523,4 +11523,6 @@ data buffers (2016-02-22). * fs/fat: Add an option to force all transfers to be performed indirectly using the FAT file system's internal sector buffers (2016-02-22). + * net/: Add basic support for IEEE 802.15-4 sockets. Compiles but still + missing a few things (2016-02-25). diff --git a/configs b/configs index b5ee355239..3f48fbde14 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b5ee35523986bd879009b829723b1c85e1b4662e +Subproject commit 3f48fbde14b07c116c06411209767def1056a9bb diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig index 3a31761693..0062c29fcd 100644 --- a/net/ieee802154/Kconfig +++ b/net/ieee802154/Kconfig @@ -8,12 +8,41 @@ menu "IEEE802.15-4 Configuration" config NET_IEEE802154 bool "IEEE802.15-4 support" default n - depends on EXPERIMENTAL + depends on EXPERIMENTAL && NET_IPv6 ---help--- Enable IEEE802.15-4 protocol socket support if NET_IEEE802154 +config NET_IEEE802154_MTU + int "IEEE 802.15-4 packet buffer size (MTU)" + default 1294 if NET_IPv6 + default 590 if !NET_IPv6 + depends on NET_ETHERNET + range 590 1518 + ---help--- + Packet buffer size. This size includes the TCP/UDP payload plus the + size of TCP/UDP header, the IP header, and the IEEE 802.15-4 header. + This value is normally referred to as the MTU (Maximum Transmission + Unit); the payload is the MSS (Maximum Segment Size). + + IPv4 hosts are required to be able to handle an MSS of at least + 536 octets, resulting in a minimum buffer size of 536+20+20+xx = + xx. REVISIT! + + IPv6 hosts are required to be able to handle an MSS of 1220 octets, + resulting in a minimum buffer size of of 1220+20+40+xx = xx. REVISIT! + +config IEEE802154_TCP_RECVWNDO + int "EEE 802.15-4 TCP receive window size" + default 1220 if NET_IPv6 + default 536 if !NET_IPv6 + depends on NET_ETHERNET && NET_TCP + ---help--- + The size of the advertised receiver's window. Should be set low + (i.e., to the size of the MSS) if the application is slow to process + incoming data, or high (32768 bytes) if the application processes + data quickly. REVISIT! endif # NET_IEEE802154 endmenu # IEEE802.15-4 Configuration diff --git a/net/ieee802154/Make.defs b/net/ieee802154/Make.defs index 93d849eff7..de55524501 100644 --- a/net/ieee802154/Make.defs +++ b/net/ieee802154/Make.defs @@ -39,7 +39,7 @@ ifeq ($(CONFIG_NET_IEEE802154),y) # Include IEEE802.15-4 file in the build -# NET_CSRCS += +# NET_CSRCS += # Include the ieee802154 directory in the build diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index b850dc109f..29a20c747d 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -61,23 +61,22 @@ * Pre-processor Definitions ****************************************************************************/ -#define NETDEV_ETH_FORMAT "eth%d" -#define NETDEV_LO_FORMAT "lo" -#define NETDEV_SLIP_FORMAT "sl%d" -#define NETDEV_TUN_FORMAT "tun%d" +#define NETDEV_ETH_FORMAT "eth%d" +#define NETDEV_LO_FORMAT "lo" +#define NETDEV_IEEE802154_FORMAT "wpan%d" +#define NETDEV_SLIP_FORMAT "sl%d" +#define NETDEV_TUN_FORMAT "tun%d" #if defined(CONFIG_NET_SLIP) # define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT #elif defined(CONFIG_NET_ETHERNET) # define NETDEV_DEFAULT_FORMAT NETDEV_ETH_FORMAT +#elif defined(CONFIG_NET_IEEE802154) +# define NETDEV_DEFAULT_FORMAT NETDEV_IEEE802154_FORMAT #else /* if defined(CONFIG_NET_LOOPBACK) */ # define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -217,8 +216,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_IEEE802154 case NET_LL_IEEE802154: /* IEEE802.15-4 */ - nlldbg("ERROR: IEEE 802.15-4 not yet supported\n"); - return -ENOSYS; +# warning Missing IEEE 802.15-4 logic: Header length + //dev->d_llhdrlen = ???; + dev->d_mtu = CONFIG_NET_IEEE802154_MTU; +#ifdef CONFIG_NET_TCP + dev->d_recvwndo = CONFIG_NET_IEEE802154_TCP_RECVWNDO; +#endif + devfmt = NETDEV_IEEE802154_FORMAT; + break; #endif #ifdef CONFIG_NET_SLIP diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 8d657583bd..c4d8cfff85 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -301,12 +301,12 @@ static inline void netclose_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index a8b7b9f162..e286cb2af7 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -175,7 +175,8 @@ static uint16_t ack_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, if (IFF_IS_IPv6(dev->d_flags)) #endif { - DEBUGASSERT(pstate->snd_sock == PF_INET6); + DEBUGASSERT(pstate->snd_sock == PF_INET6 || + pstate->snd_sock == PF_IEEE802154); tcp = TCPIPv6BUF; } #endif /* CONFIG_NET_IPv6 */ @@ -514,12 +515,14 @@ static inline void sendfile_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a6921315fd..a02a1e3acc 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1024,7 +1024,7 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6) + if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) { FAR struct sockaddr_in6 *infrom6 = (FAR struct sockaddr_in6 *)infrom; FAR socklen_t *fromlen = pstate->rf_fromlen; @@ -1350,12 +1350,12 @@ static inline void recvfrom_udp_rxnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver of the receive ready */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_rxnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else @@ -1892,6 +1892,9 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, #ifdef CONFIG_NET_IPv6 case PF_INET6: +#ifdef CONFIG_NET_IEEE802145 + case PF_IEEE802154: +#endif { minlen = sizeof(struct sockaddr_in6); } diff --git a/net/socket/socket.c b/net/socket/socket.c index 93fd41a278..cfe84fdc7e 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/socket.c * - * Copyright (C) 2007-2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -250,7 +250,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) int ret; int err; - /* Only PF_INET, PF_INET6 or PF_PACKET domains supported */ + /* Only PF_INET, PF_INET6, PF_PACKET, PF_IEEE802154 domains supported */ switch (domain) { @@ -265,6 +265,9 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) #ifdef CONFIG_NET_IPv6 case PF_INET6: +#ifdef CONFIG_NET_IEEE802154 + case PF_IEEE802154: +#endif #ifdef CONFIG_NET_LOCAL ipdomain = true; #endif diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 2f3284d709..27692fcce4 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -149,7 +149,7 @@ struct tcp_conn_s uint8_t sndseq[4]; /* The sequence number that was last sent by us */ uint8_t crefs; /* Reference counts on this instance */ #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ + uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802154 */ #endif uint8_t sa; /* Retransmission time-out calculation state * variable */ diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 102f8c2213..6bb1bd3d8a 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -139,7 +139,9 @@ static inline void accept_tcpsender(FAR struct socket *psock, { FAR struct sockaddr_in6 *inaddr = (FAR struct sockaddr_in6 *)addr; - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + inaddr->sin6_family = AF_INET6; inaddr->sin6_port = conn->rport; net_ipv6addr_copy(inaddr->sin6_addr.s6_addr, conn->u.ipv6.raddr); diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 6cc9950fc0..ab579a042f 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -977,6 +977,8 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, domain = ipv6 ? PF_INET6 : PF_INET; #elif defined(CONFIG_NET_IPv4) domain = PF_INET; +#elif defined(CONFIG_NET_IEEE802154) + domain = PF_IEEE80254; #else /* defined(CONFIG_NET_IPv6) */ domain = PF_INET6; #endif diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 077a1dbe2e..bf14e81434 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -241,11 +241,13 @@ static inline void send_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + tcp_ipv4_select(dev); } } @@ -857,12 +859,14 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 7c0faac458..3d77aea3c6 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -190,11 +190,13 @@ static inline void tcpsend_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + tcp_ipv4_select(dev); } } @@ -637,12 +639,14 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/udp/udp.h b/net/udp/udp.h index 91447d2596..621cf927ac 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -85,7 +85,7 @@ struct udp_conn_s union ip_binding_u u; /* IP address binding */ uint16_t lport; /* Bound local port number (network byte order) */ uint16_t rport; /* Remote port number (network byte order) */ - uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ + uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802145 */ uint8_t ttl; /* Default time-to-live */ uint8_t crefs; /* Reference counts on this instance */ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 0492fb5bb8..2ae9923d31 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -134,7 +134,7 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6) + if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) { FAR struct udp_hdr_s *udp = UDPIPv6BUF; FAR struct ipv6_hdr_s *ipv6 = IPv6BUF; diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 71fbe55af1..60cc465496 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -188,11 +188,13 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev, udp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + udp_ipv4_select(dev); } } diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index 6bc010d997..f24abc284d 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -121,7 +121,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - (conn->domain == PF_INET6 && + ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { @@ -147,7 +147,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr); #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET6 && + if ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr)) { in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr); @@ -241,7 +241,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - (conn->domain == PF_INET6 && + ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { -- GitLab From 9ff645a2986213bf8cc281e14cbf64e190f4068b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 15:11:30 -0600 Subject: [PATCH 800/858] drivers/ieee802154: Add a skeleton IEEE802154 driver --- drivers/Kconfig | 11 + drivers/Makefile | 1 + drivers/ieee802154/Kconfig | 4 + drivers/ieee802154/Make.defs | 49 ++ drivers/ieee802154/skeleton.c | 1168 ++++++++++++++++++++++++++++++++ include/nuttx/net/ieee802154.h | 82 +++ net/ieee802154/ieee802154.h | 56 ++ net/udp/udp_input.c | 12 - 8 files changed, 1371 insertions(+), 12 deletions(-) create mode 100644 drivers/ieee802154/Kconfig create mode 100644 drivers/ieee802154/Make.defs create mode 100644 drivers/ieee802154/skeleton.c create mode 100644 include/nuttx/net/ieee802154.h create mode 100644 net/ieee802154/ieee802154.h diff --git a/drivers/Kconfig b/drivers/Kconfig index bef5458d4a..e2396dcc2e 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -373,6 +373,17 @@ if IOEXPANDER source drivers/ioexpander/Kconfig endif # IOEXPANDER +menuconfig IEEE802154 + bool "IEEE 802.15-4 Device Support" + default n + depends on EXPERIMENTAL + ---help--- + This directory holds implementations of IEEE802.15.4 device drivers. + +if IEEE802154 +source drivers/ieee802154/Kconfig +endif + menuconfig LCD bool "LCD Driver Support" default n diff --git a/drivers/Makefile b/drivers/Makefile index 025444990f..e741dd116e 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -54,6 +54,7 @@ include audio$(DELIM)Make.defs include bch$(DELIM)Make.defs include i2c$(DELIM)Make.defs include input$(DELIM)Make.defs +include ieee802154$(DELIM)Make.defs include ioexpander$(DELIM)Make.defs include lcd$(DELIM)Make.defs include leds$(DELIM)Make.defs diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig new file mode 100644 index 0000000000..f72f3c094c --- /dev/null +++ b/drivers/ieee802154/Kconfig @@ -0,0 +1,4 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# diff --git a/drivers/ieee802154/Make.defs b/drivers/ieee802154/Make.defs new file mode 100644 index 0000000000..f45e479281 --- /dev/null +++ b/drivers/ieee802154/Make.defs @@ -0,0 +1,49 @@ +############################################################################ +# drivers/ieee802154/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Include nothing if IEEE 802.15-4 is disabled + +ifeq ($(CONFIG_IEEE802154),y) + +# Include common IEEE 802.15-4 + +# Include IEEE 802.15.4 drivers + +# Include IEEE 802.15.4 build support + +DEPPATH += --dep-path ieee802154 +VPATH += :ieee802154 + +endif # CONFIG_IEEE802154 diff --git a/drivers/ieee802154/skeleton.c b/drivers/ieee802154/skeleton.c new file mode 100644 index 0000000000..15218169a7 --- /dev/null +++ b/drivers/ieee802154/skeleton.c @@ -0,0 +1,1168 @@ +/**************************************************************************** + * drivers/ieee802154/skeleton.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#if defined(CONFIG_NET) && defined(CONFIG_NET_skeleton) + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_NET_NOINTS +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* If processing is not done at the interrupt level, then high priority + * work queue support is required. + */ + +#if defined(CONFIG_NET_NOINTS) && !defined(CONFIG_SCHED_HPWORK) +# error High priority work queue support is required +#endif + +/* CONFIG_skeleton_NINTERFACES determines the number of physical interfaces + * that will be supported. + */ + +#ifndef CONFIG_skeleton_NINTERFACES +# define CONFIG_skeleton_NINTERFACES 1 +#endif + +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ + +#define skeleton_WDDELAY (1*CLK_TCK) + +/* TX timeout = 1 minute */ + +#define skeleton_TXTIMEOUT (60*CLK_TCK) + +/* This is a helper pointer for accessing the contents of the Ethernet header */ + +#define BUF ((struct eth_hdr_s *)priv->sk_dev.d_buf) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The skel_driver_s encapsulates all state information for a single hardware + * interface + */ + +struct skel_driver_s +{ + bool sk_bifup; /* true:ifup false:ifdown */ + WDOG_ID sk_txpoll; /* TX poll timer */ + WDOG_ID sk_txtimeout; /* TX timeout timer */ +#ifdef CONFIG_NET_NOINTS + struct work_s sk_work; /* For deferring work to the work queue */ +#endif + + /* This holds the information visible to the NuttX network */ + + struct net_driver_s sk_dev; /* Interface understood by the network */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct skel_driver_s g_skel[CONFIG_skeleton_NINTERFACES]; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Common TX logic */ + +static int skel_transmit(FAR struct skel_driver_s *priv); +static int skel_txpoll(FAR struct net_driver_s *dev); + +/* Interrupt handling */ + +static void skel_receive(FAR struct skel_driver_s *priv); +static void skel_txdone(FAR struct skel_driver_s *priv); +static inline void skel_interrupt_process(FAR struct skel_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void skel_interrupt_work(FAR void *arg); +#endif +static int skel_interrupt(int irq, FAR void *context); + +/* Watchdog timer expirations */ + +static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void skel_txtimeout_work(FAR void *arg); +#endif +static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...); + +static inline void skel_poll_process(FAR struct skel_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void skel_poll_work(FAR void *arg); +#endif +static void skel_poll_expiry(int argc, wdparm_t arg, ...); + +/* NuttX callback functions */ + +static int skel_ifup(FAR struct net_driver_s *dev); +static int skel_ifdown(FAR struct net_driver_s *dev); +static inline void skel_txavail_process(FAR struct skel_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void skel_txavail_work(FAR void *arg); +#endif +static int skel_txavail(FAR struct net_driver_s *dev); +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#ifdef CONFIG_NET_IGMP +static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#endif +#ifdef CONFIG_NET_ICMPv6 +static void skel_ipv6multicast(FAR struct skel_driver_s *priv); +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: skel_transmit + * + * Description: + * Start hardware transmission. Called either from the txdone interrupt + * handling or from watchdog based polling. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * the network is locked. + * + ****************************************************************************/ + +static int skel_transmit(FAR struct skel_driver_s *priv) +{ + /* Verify that the hardware is ready to send another packet. If we get + * here, then we are committed to sending a packet; Higher level logic + * must have assured that there is no transmission in progress. + */ + + /* Increment statistics */ + + NETDEV_TXPACKETS(priv->sk_dev); + + /* Send the packet: address=priv->sk_dev.d_buf, length=priv->sk_dev.d_len */ + + /* Enable Tx interrupts */ + + /* Setup the TX timeout watchdog (perhaps restarting the timer) */ + + (void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT, + skel_txtimeout_expiry, 1, (wdparm_t)priv); + return OK; +} + +/**************************************************************************** + * Function: skel_txpoll + * + * Description: + * The transmitter is available, check if the network has any outgoing + * packets ready to send. This is a callback from devif_poll(). + * devif_poll() may be called: + * + * 1. When the preceding TX packet send is complete, + * 2. When the preceding TX packet send timesout and the interface is reset + * 3. During normal TX polling + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * the network is locked. + * + ****************************************************************************/ + +static int skel_txpoll(FAR struct net_driver_s *dev) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + + /* If the polling resulted in data that should be sent out on the network, + * the field d_len is set to a value > 0. + */ + + if (priv->sk_dev.d_len > 0) + { + /* Look up the destination MAC address and add it to the Ethernet + * header. + */ + + neighbor_out(&priv->sk_dev); + + /* Send the packet */ + + skel_transmit(priv); + + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + } + + /* If zero is returned, the polling will continue until all connections have + * been examined. + */ + + return 0; +} + +/**************************************************************************** + * Function: skel_receive + * + * Description: + * An interrupt was received indicating the availability of a new RX packet + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void skel_receive(FAR struct skel_driver_s *priv) +{ + do + { + /* Check for errors and update statistics */ + + /* Check if the packet is a valid size for the network buffer + * configuration. + */ + + /* Copy the data data from the hardware to priv->sk_dev.d_buf. Set + * amount of data in priv->sk_dev.d_len + */ + + /* We only accept IPv6 packets of the configured type and ARP packets */ + + if (BUF->type == HTONS(ETHTYPE_IP6)) + { + nllvdbg("Iv6 frame\n"); + NETDEV_RXIPV6(&priv->sk_dev); + + /* Give the IPv6 packet to the network layer */ + + ieee802154_input(&priv->sk_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (priv->sk_dev.d_len > 0) + { + /* Update the Ethernet header with the correct MAC address */ + + neighbor_out(&priv->sk_dev); + + /* And send the packet */ + + skel_transmit(priv); + } + } + else + +#ifdef CONFIG_NET_ARP + if (BUF->type == htons(ETHTYPE_ARP)) + { + arp_arpin(&priv->sk_dev); + NETDEV_RXARP(&priv->sk_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (priv->sk_dev.d_len > 0) + { + skel_transmit(priv); + } + } +#endif + else + { + NETDEV_RXDROPPED(&priv->sk_dev); + } + } + while (); /* While there are more packets to be processed */ +} + +/**************************************************************************** + * Function: skel_txdone + * + * Description: + * An interrupt was received indicating that the last TX packet(s) is done + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void skel_txdone(FAR struct skel_driver_s *priv) +{ + /* Check for errors and update statistics */ + + NETDEV_TXDONE(priv->sk_dev); + + /* Check if there are pending transmissions */ + + /* If no further transmissions are pending, then cancel the TX timeout and + * disable further Tx interrupts. + */ + + wd_cancel(priv->sk_txtimeout); + + /* Then make sure that the TX poll timer is running (if it is already + * running, the following would restart it). This is necessary to + * avoid certain race conditions where the polling sequence can be + * interrupted. + */ + + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); + + /* And disable further TX interrupts. */ + + /* In any event, poll the network for new TX data */ + + (void)devif_poll(&priv->sk_dev, skel_txpoll); +} + +/**************************************************************************** + * Function: skel_interrupt_process + * + * Description: + * Interrupt processing. This may be performed either within the interrupt + * handler or on the worker thread, depending upon the configuration + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static inline void skel_interrupt_process(FAR struct skel_driver_s *priv) +{ + /* Get and clear interrupt status bits */ + + /* Handle interrupts according to status bit settings */ + + /* Check if we received an incoming packet, if so, call skel_receive() */ + + skel_receive(priv); + + /* Check if a packet transmission just completed. If so, call skel_txdone. + * This may disable further Tx interrupts if there are no pending + * transmissions. + */ + + skel_txdone(priv); +} + +/**************************************************************************** + * Function: skel_interrupt_work + * + * Description: + * Perform interrupt related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() was called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void skel_interrupt_work(FAR void *arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + net_lock_t state; + + /* Process pending Ethernet interrupts */ + + state = net_lock(); + skel_interrupt_process(priv); + net_unlock(state); + + /* Re-enable Ethernet interrupts */ + + up_enable_irq(CONFIG_skeleton_IRQ); +} +#endif + +/**************************************************************************** + * Function: skel_interrupt + * + * Description: + * Hardware interrupt handler + * + * Parameters: + * irq - Number of the IRQ that generated the interrupt + * context - Interrupt register state save info (architecture-specific) + * + * Returned Value: + * OK on success + * + * Assumptions: + * + ****************************************************************************/ + +static int skel_interrupt(int irq, FAR void *context) +{ + FAR struct skel_driver_s *priv = &g_skel[0]; + +#ifdef CONFIG_NET_NOINTS + /* Disable further Ethernet interrupts. Because Ethernet interrupts are + * also disabled if the TX timeout event occurs, there can be no race + * condition here. + */ + + up_disable_irq(CONFIG_skeleton_IRQ); + + /* TODO: Determine if a TX transfer just completed */ + + { + /* If a TX transfer just completed, then cancel the TX timeout so + * there will be do race condition between any subsequent timeout + * expiration and the deferred interrupt processing. + */ + + wd_cancel(priv->sk_txtimeout); + } + + /* Cancel any pending poll work */ + + work_cancel(HPWORK, &priv->sk_work); + + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(HPWORK, &priv->sk_work, skel_interrupt_work, priv, 0); + +#else + /* Process the interrupt now */ + + skel_interrupt_process(priv); +#endif + + return OK; +} + +/**************************************************************************** + * Function: skel_txtimeout_process + * + * Description: + * Process a TX timeout. Called from the either the watchdog timer + * expiration logic or from the worker thread, depending upon the + * configuration. The timeout means that the last TX never completed. + * Reset the hardware and start again. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv) +{ + /* Increment statistics and dump debug info */ + + NETDEV_TXTIMEOUTS(priv->sk_dev); + + /* Then reset the hardware */ + + /* Then poll the network for new XMIT data */ + + (void)devif_poll(&priv->sk_dev, skel_txpoll); +} + +/**************************************************************************** + * Function: skel_txtimeout_work + * + * Description: + * Perform TX timeout related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void skel_txtimeout_work(FAR void *arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + net_lock_t state; + + /* Process pending Ethernet interrupts */ + + state = net_lock(); + skel_txtimeout_process(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: skel_txtimeout_expiry + * + * Description: + * Our TX watchdog timed out. Called from the timer interrupt handler. + * The last TX never completed. Reset the hardware and start again. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + +#ifdef CONFIG_NET_NOINTS + /* Disable further Ethernet interrupts. This will prevent some race + * conditions with interrupt work. There is still a potential race + * condition with interrupt work that is already queued and in progress. + */ + + up_disable_irq(CONFIG_skeleton_IRQ); + + /* Cancel any pending poll or interrupt work. This will have no effect + * on work that has already been started. + */ + + work_cancel(HPWORK, &priv->sk_work); + + /* Schedule to perform the TX timeout processing on the worker thread. */ + + work_queue(HPWORK, &priv->sk_work, skel_txtimeout_work, priv, 0); +#else + /* Process the timeout now */ + + skel_txtimeout_process(priv); +#endif +} + +/**************************************************************************** + * Function: skel_poll_process + * + * Description: + * Perform the periodic poll. This may be called either from watchdog + * timer logic or from the worker thread, depending upon the configuration. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static inline void skel_poll_process(FAR struct skel_driver_s *priv) +{ + /* Check if there is room in the send another TX packet. We cannot perform + * the TX poll if he are unable to accept another packet for transmission. + */ + + /* If so, update TCP timing states and poll the network for new XMIT data. + * Hmmm.. might be bug here. Does this mean if there is a transmit in + * progress, we will missing TCP time state updates? + */ + + (void)devif_timer(&priv->sk_dev, skel_txpoll); + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); +} + +/**************************************************************************** + * Function: skel_poll_work + * + * Description: + * Perform periodic polling from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void skel_poll_work(FAR void *arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + net_lock_t state; + + /* Perform the poll */ + + state = net_lock(); + skel_poll_process(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: skel_poll_expiry + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void skel_poll_expiry(int argc, wdparm_t arg, ...) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + +#ifdef CONFIG_NET_NOINTS + /* Is our single work structure available? It may not be if there are + * pending interrupt actions. + */ + + if (work_available(&priv->sk_work)) + { + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(HPWORK, &priv->sk_work, skel_poll_work, priv, 0); + } + else + { + /* No.. Just re-start the watchdog poll timer, missing one polling + * cycle. + */ + + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, arg); + } + +#else + /* Process the interrupt now */ + + skel_poll_process(priv); +#endif +} + +/**************************************************************************** + * Function: skel_ifup + * + * Description: + * NuttX Callback: Bring up the Ethernet interface when an IP address is + * provided + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int skel_ifup(FAR struct net_driver_s *dev) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + +#ifdef CONFIG_NET_IPv6 + ndbg("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], + dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], + dev->d_ipv6addr[6], dev->d_ipv6addr[7]); +#endif + + /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ + + /* Instantiate the MAC address from priv->sk_dev.d_mac.ether_addr_octet */ + +#ifdef CONFIG_NET_ICMPv6 + /* Set up IPv6 multicast address filtering */ + + skel_ipv6multicast(priv); +#endif + + /* Set and activate a timer process */ + + (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, + (wdparm_t)priv); + + /* Enable the Ethernet interrupt */ + + priv->sk_bifup = true; + up_enable_irq(CONFIG_skeleton_IRQ); + return OK; +} + +/**************************************************************************** + * Function: skel_ifdown + * + * Description: + * NuttX Callback: Stop the interface. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int skel_ifdown(FAR struct net_driver_s *dev) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + irqstate_t flags; + + /* Disable the Ethernet interrupt */ + + flags = enter_critical_section(); + up_disable_irq(CONFIG_skeleton_IRQ); + + /* Cancel the TX poll timer and TX timeout timers */ + + wd_cancel(priv->sk_txpoll); + wd_cancel(priv->sk_txtimeout); + + /* Put the EMAC in its reset, non-operational state. This should be + * a known configuration that will guarantee the skel_ifup() always + * successfully brings the interface back up. + */ + + /* Mark the device "down" */ + + priv->sk_bifup = false; + leave_critical_section(flags); + return OK; +} + +/**************************************************************************** + * Function: skel_txavail_process + * + * Description: + * Perform an out-of-cycle poll. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static inline void skel_txavail_process(FAR struct skel_driver_s *priv) +{ + /* Ignore the notification if the interface is not yet up */ + + if (priv->sk_bifup) + { + /* Check if there is room in the hardware to hold another outgoing packet. */ + + /* If so, then poll the network for new XMIT data */ + + (void)devif_poll(&priv->sk_dev, skel_txpoll); + } +} + +/**************************************************************************** + * Function: skel_txavail_work + * + * Description: + * Perform an out-of-cycle poll on the worker thread. + * + * Parameters: + * arg - Reference to the NuttX driver state structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * Called on the higher priority worker thread. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void skel_txavail_work(FAR void *arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + net_lock_t state; + + /* Perform the poll */ + + state = net_lock(); + skel_txavail_process(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: skel_txavail + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static int skel_txavail(FAR struct net_driver_s *dev) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + +#ifdef CONFIG_NET_NOINTS + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&priv->sk_work)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(HPWORK, &priv->sk_work, skel_txavail_work, priv, 0); + } + +#else + irqstate_t flags; + + /* Disable interrupts because this function may be called from interrupt + * level processing. + */ + + flags = enter_critical_section(); + + /* Perform the out-of-cycle poll now */ + + skel_txavail_process(priv); + leave_critical_section(flags); +#endif + + return OK; +} + +/**************************************************************************** + * Function: skel_addmac + * + * Description: + * NuttX Callback: Add the specified MAC address to the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be added + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + + /* Add the MAC address to the hardware multicast routing table */ + + return OK; +} +#endif + +/**************************************************************************** + * Function: skel_rmmac + * + * Description: + * NuttX Callback: Remove the specified MAC address from the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be removed + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IGMP +static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + + /* Add the MAC address to the hardware multicast routing table */ + + return OK; +} +#endif + +/**************************************************************************** + * Function: skel_ipv6multicast + * + * Description: + * Configure the IPv6 multicast MAC address. + * + * Parameters: + * priv - A reference to the private driver state structure + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ICMPv6 +static void skel_ipv6multicast(FAR struct skel_driver_s *priv) +{ + FAR struct net_driver_s *dev; + uint16_t tmp16; + uint8_t mac[6]; + + /* For ICMPv6, we need to add the IPv6 multicast address + * + * For IPv6 multicast addresses, the Ethernet MAC is derived by + * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, + * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map + * to the Ethernet MAC address 33:33:00:01:00:03. + * + * NOTES: This appears correct for the ICMPv6 Router Solicitation + * Message, but the ICMPv6 Neighbor Solicitation message seems to + * use 33:33:ff:01:00:03. + */ + + mac[0] = 0x33; + mac[1] = 0x33; + + dev = &priv->dev; + tmp16 = dev->d_ipv6addr[6]; + mac[2] = 0xff; + mac[3] = tmp16 >> 8; + + tmp16 = dev->d_ipv6addr[7]; + mac[4] = tmp16 & 0xff; + mac[5] = tmp16 >> 8; + + nvdbg("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + (void)skel_addmac(dev, mac); + +#ifdef CONFIG_NET_ICMPv6_AUTOCONF + /* Add the IPv6 all link-local nodes Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Advertisement + * packets. + */ + + (void)skel_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_AUTOCONF */ +#ifdef CONFIG_NET_ICMPv6_ROUTER + /* Add the IPv6 all link-local routers Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Solicitation + * packets. + */ + + (void)skel_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_ROUTER */ +} +#endif /* CONFIG_NET_ICMPv6 */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: skel_initialize + * + * Description: + * Initialize the Ethernet controller and driver + * + * Parameters: + * intf - In the case where there are multiple EMACs, this value + * identifies which EMAC is to be initialized. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +int skel_initialize(int intf) +{ + FAR struct skel_driver_s *priv; + + /* Get the interface structure associated with this interface number. */ + + DEBUGASSERT(intf < CONFIG_skeleton_NINTERFACES); + priv = &g_skel[intf]; + + /* Check if a Ethernet chip is recognized at its I/O base */ + + /* Attach the IRQ to the driver */ + + if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt)) + { + /* We could not attach the ISR to the interrupt */ + + return -EAGAIN; + } + + /* Initialize the driver structure */ + + memset(priv, 0, sizeof(struct skel_driver_s)); + priv->sk_dev.d_ifup = skel_ifup; /* I/F up (new IP address) callback */ + priv->sk_dev.d_ifdown = skel_ifdown; /* I/F down callback */ + priv->sk_dev.d_txavail = skel_txavail; /* New TX data callback */ +#ifdef CONFIG_NET_IGMP + priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */ + priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */ +#endif + priv->sk_dev.d_private = (FAR void *)g_skel; /* Used to recover private state from dev */ + + /* Create a watchdog for timing polling for and timing of transmisstions */ + + priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ + priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ + + /* Put the interface in the down state. This usually amounts to resetting + * the device and/or calling skel_ifdown(). + */ + + /* Read the MAC address from the hardware into priv->sk_dev.d_mac.ether_addr_octet */ + + /* Register the device with the OS so that socket IOCTLs can be performed */ + + (void)netdev_register(&priv->sk_dev, NET_LL_IEEE802154); + return OK; +} + +#endif /* CONFIG_NET && CONFIG_NET_skeleton */ diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h new file mode 100644 index 0000000000..cb3a3ef046 --- /dev/null +++ b/include/nuttx/net/ieee802154.h @@ -0,0 +1,82 @@ +/**************************************************************************** + * include/nuttx/net/ieee802154.h + * Definitions for use with PF_IEEE802154 sockets + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Includes some definitions that a compatible with the LGPL GNU C Library + * header file of the same name. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_IEEE802154_H +#define __INCLUDE_NUTTX_NET_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_input + * + * Description: + * This function provides the interface between IEEE 802.15-4 device driver + * and IEEE 802.15-4 socket logic. All IPv6 frames that are received should + * be provided to ieee802154_input(). + * + * Input Parameters: + * dev - The device providing the IPv6 frame + * + * Returned Value: + * OK The packet has been processed and can be deleted. + * + ****************************************************************************/ + +struct net_driver_s; /* Forward reference */ +int ieee802154_input(FAR struct net_driver_s *dev); + +#endif /* __INCLUDE_NUTTX_NET_IEEE802154_H */ diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h new file mode 100644 index 0000000000..9d9e8191f4 --- /dev/null +++ b/net/ieee802154/ieee802154.h @@ -0,0 +1,56 @@ +/**************************************************************************** + * net/ieee802154/ieee802154.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NET_IEEE802_15_4_IEEE802154_H +#define __NET_IEEE802_15_4_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* CONFIG_NET_IEEE802154 */ +#endif /* __NET_IEEE802_15_4_IEEE802154_H */ diff --git a/net/udp/udp_input.c b/net/udp/udp_input.c index 601b0de2b7..640fd617ad 100644 --- a/net/udp/udp_input.c +++ b/net/udp/udp_input.c @@ -56,18 +56,6 @@ #include "utils/utils.h" #include "udp/udp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ -- GitLab From b0ea870bcc46a7e664204fb8e4d72e0b2969e0ba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 25 Feb 2016 18:34:36 -0600 Subject: [PATCH 801/858] Remove some empty code section comments --- net/arp/arp_arpin.c | 12 ------------ net/arp/arp_dump.c | 16 ---------------- net/arp/arp_format.c | 12 ------------ net/arp/arp_ipin.c | 12 ------------ net/arp/arp_notify.c | 12 ------------ net/arp/arp_out.c | 8 -------- net/arp/arp_send.c | 8 -------- net/arp/arp_table.c | 12 ------------ net/icmp/icmp.h | 8 -------- net/icmp/icmp_input.c | 12 ------------ net/icmp/icmp_ping.c | 8 -------- net/icmp/icmp_poll.c | 16 ---------------- net/igmp/igmp.h | 4 ---- net/igmp/igmp_group.c | 4 ---- net/igmp/igmp_input.c | 4 ---- net/igmp/igmp_join.c | 8 -------- net/igmp/igmp_leave.c | 8 -------- net/igmp/igmp_mcastmac.c | 4 ---- net/igmp/igmp_msg.c | 8 -------- net/igmp/igmp_poll.c | 4 ---- net/igmp/igmp_send.c | 8 -------- net/route/net_addroute.c | 8 -------- net/route/net_foreachroute.c | 4 ---- net/udp/udp_callback.c | 4 ---- net/udp/udp_devpoll.c | 16 ---------------- net/udp/udp_finddev.c | 8 -------- net/udp/udp_ipselect.c | 8 -------- net/udp/udp_psock_send.c | 8 -------- net/udp/udp_send.c | 12 ------------ net/utils/net_chksum.c | 4 ---- net/utils/net_dsec2tick.c | 8 -------- net/utils/net_ipv6_mask2pref.c | 4 ---- net/utils/utils.h | 4 ---- 33 files changed, 276 deletions(-) diff --git a/net/arp/arp_arpin.c b/net/arp/arp_arpin.c index 883d2f2a42..6945ff666a 100644 --- a/net/arp/arp_arpin.c +++ b/net/arp/arp_arpin.c @@ -62,18 +62,6 @@ #define ETHBUF ((struct eth_hdr_s *)&dev->d_buf[0]) #define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[ETH_HDRLEN]) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_dump.c b/net/arp/arp_dump.c index 739c280837..50ea5a27e5 100644 --- a/net/arp/arp_dump.c +++ b/net/arp/arp_dump.c @@ -49,22 +49,6 @@ #ifdef CONFIG_NET_ARP_DUMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_format.c b/net/arp/arp_format.c index 21cd99d20f..4b0af255d5 100644 --- a/net/arp/arp_format.c +++ b/net/arp/arp_format.c @@ -62,18 +62,6 @@ #define ETHBUF ((struct eth_hdr_s *)&dev->d_buf[0]) #define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[ETH_HDRLEN]) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_ipin.c b/net/arp/arp_ipin.c index febcaf82dc..870e9a0a08 100644 --- a/net/arp/arp_ipin.c +++ b/net/arp/arp_ipin.c @@ -59,18 +59,6 @@ #define ETHBUF ((struct eth_hdr_s *)&dev->d_buf[0]) #define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[ETH_HDRLEN]) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c index 0966c92292..727d765651 100644 --- a/net/arp/arp_notify.c +++ b/net/arp/arp_notify.c @@ -54,14 +54,6 @@ #ifdef CONFIG_NET_ARP_SEND -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -70,10 +62,6 @@ static FAR struct arp_notify_s *g_arp_waiters; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_out.c b/net/arp/arp_out.c index daa71b2ac4..563d601337 100644 --- a/net/arp/arp_out.c +++ b/net/arp/arp_out.c @@ -62,10 +62,6 @@ #define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[ETH_HDRLEN]) #define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[ETH_HDRLEN]) -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -107,10 +103,6 @@ static const uint8_t g_multicast_ethaddr[3] = }; #endif -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/arp/arp_send.c b/net/arp/arp_send.c index 1b19e91a43..b6431582b1 100644 --- a/net/arp/arp_send.c +++ b/net/arp/arp_send.c @@ -69,14 +69,6 @@ #define CONFIG_ARP_SEND_DELAYNSEC \ ((CONFIG_ARP_SEND_DELAYMSEC - 1000*CONFIG_ARP_SEND_DELAYSEC) * 1000000) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/arp/arp_table.c b/net/arp/arp_table.c index a89e445fa1..bdb27ad79d 100644 --- a/net/arp/arp_table.c +++ b/net/arp/arp_table.c @@ -62,14 +62,6 @@ #ifdef CONFIG_NET_ARP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -79,10 +71,6 @@ static struct arp_entry g_arptable[CONFIG_NET_ARPTAB_SIZE]; static uint8_t g_arptime; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/icmp/icmp.h b/net/icmp/icmp.h index 3e55d4c51a..9750d88539 100644 --- a/net/icmp/icmp.h +++ b/net/icmp/icmp.h @@ -48,14 +48,6 @@ #ifdef CONFIG_NET_ICMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/net/icmp/icmp_input.c b/net/icmp/icmp_input.c index 6cc688ab7c..2d919b8f76 100644 --- a/net/icmp/icmp_input.c +++ b/net/icmp/icmp_input.c @@ -68,18 +68,6 @@ #define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 954d22e4a9..337968bf84 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -93,14 +93,6 @@ struct icmp_ping_s bool png_sent; /* true... the PING request has been sent */ }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/icmp/icmp_poll.c b/net/icmp/icmp_poll.c index ac21ead7fd..9a5eed1d08 100644 --- a/net/icmp/icmp_poll.c +++ b/net/icmp/icmp_poll.c @@ -49,22 +49,6 @@ #include "devif/devif.h" #include "icmp/icmp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/igmp/igmp.h b/net/igmp/igmp.h index ae785e5af7..5af1594a2e 100644 --- a/net/igmp/igmp.h +++ b/net/igmp/igmp.h @@ -81,10 +81,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/net/igmp/igmp_group.c b/net/igmp/igmp_group.c index 03f2613026..92b34427b4 100644 --- a/net/igmp/igmp_group.c +++ b/net/igmp/igmp_group.c @@ -126,10 +126,6 @@ static struct igmp_group_s g_preallocgrps[CONFIG_PREALLOC_IGMPGROUPS]; static FAR sq_queue_t g_freelist; #endif -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/igmp/igmp_input.c b/net/igmp/igmp_input.c index 64a5aba912..c2b3c870a3 100644 --- a/net/igmp/igmp_input.c +++ b/net/igmp/igmp_input.c @@ -64,10 +64,6 @@ #define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/igmp/igmp_join.c b/net/igmp/igmp_join.c index 2eb454d1dc..83ef65a0f8 100644 --- a/net/igmp/igmp_join.c +++ b/net/igmp/igmp_join.c @@ -58,14 +58,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/igmp/igmp_leave.c b/net/igmp/igmp_leave.c index 20a36ef004..4035358e8f 100644 --- a/net/igmp/igmp_leave.c +++ b/net/igmp/igmp_leave.c @@ -60,14 +60,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/igmp/igmp_mcastmac.c b/net/igmp/igmp_mcastmac.c index ceee9101bf..2172a281ec 100644 --- a/net/igmp/igmp_mcastmac.c +++ b/net/igmp/igmp_mcastmac.c @@ -55,10 +55,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/igmp/igmp_msg.c b/net/igmp/igmp_msg.c index d680541d95..3fd56fc381 100644 --- a/net/igmp/igmp_msg.c +++ b/net/igmp/igmp_msg.c @@ -55,14 +55,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/igmp/igmp_poll.c b/net/igmp/igmp_poll.c index 6beb8a31e6..e7dfd10683 100644 --- a/net/igmp/igmp_poll.c +++ b/net/igmp/igmp_poll.c @@ -56,10 +56,6 @@ #ifdef CONFIG_NET_IGMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index 1482a63549..d40301495a 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -78,14 +78,6 @@ #define RASIZE (4) #define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/route/net_addroute.c b/net/route/net_addroute.c index 7ff316660d..bf9ea3f3df 100644 --- a/net/route/net_addroute.c +++ b/net/route/net_addroute.c @@ -53,14 +53,6 @@ #if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/route/net_foreachroute.c b/net/route/net_foreachroute.c index 41cd1245a3..13c154f539 100644 --- a/net/route/net_foreachroute.c +++ b/net/route/net_foreachroute.c @@ -50,10 +50,6 @@ #if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 2ae9923d31..778581298b 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -63,10 +63,6 @@ #define UDPIPv4BUF ((FAR struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN]) #define UDPIPv6BUF ((FAR struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/udp/udp_devpoll.c b/net/udp/udp_devpoll.c index af6ae68918..22962173db 100644 --- a/net/udp/udp_devpoll.c +++ b/net/udp/udp_devpoll.c @@ -54,22 +54,6 @@ #include "devif/devif.h" #include "udp/udp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index 38287d887d..c943ab3796 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -48,14 +48,6 @@ #include "netdev/netdev.h" #include "udp/udp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/udp/udp_ipselect.c b/net/udp/udp_ipselect.c index b11fb00ac6..286e796102 100644 --- a/net/udp/udp_ipselect.c +++ b/net/udp/udp_ipselect.c @@ -50,14 +50,6 @@ #include "udp/udp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/udp/udp_psock_send.c b/net/udp/udp_psock_send.c index b042d9c485..e3e2eb0c88 100644 --- a/net/udp/udp_psock_send.c +++ b/net/udp/udp_psock_send.c @@ -49,14 +49,6 @@ #include "socket/socket.h" #include "udp/udp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index f24abc284d..713e043738 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -74,18 +74,6 @@ #define UDPIPv6BUF \ ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/utils/net_chksum.c b/net/utils/net_chksum.c index 776438b607..9f4055c756 100644 --- a/net/utils/net_chksum.c +++ b/net/utils/net_chksum.c @@ -59,10 +59,6 @@ #define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define ICMPv6BUF ((struct icmp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/utils/net_dsec2tick.c b/net/utils/net_dsec2tick.c index 833ce48c0e..96a28db005 100644 --- a/net/utils/net_dsec2tick.c +++ b/net/utils/net_dsec2tick.c @@ -40,14 +40,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/utils/net_ipv6_mask2pref.c b/net/utils/net_ipv6_mask2pref.c index dd9e00b6d8..763fc0188a 100644 --- a/net/utils/net_ipv6_mask2pref.c +++ b/net/utils/net_ipv6_mask2pref.c @@ -46,10 +46,6 @@ #ifdef CONFIG_NET_IPv6 -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/net/utils/utils.h b/net/utils/utils.h index 90592b2f7a..355e75e51e 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -44,10 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Types ****************************************************************************/ -- GitLab From 8db55f6493ad9b5fa0f86b4380856c18d8d30bb8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 06:45:37 -0600 Subject: [PATCH 802/858] Back out most of previous commit --- ChangeLog | 2 -- net/netdev/netdev_register.c | 3 +-- net/socket/net_close.c | 4 ++-- net/socket/net_sendfile.c | 9 +++------ net/socket/recvfrom.c | 9 +++------ net/socket/socket.c | 7 ++----- net/tcp/tcp.h | 2 +- net/tcp/tcp_accept.c | 4 +--- net/tcp/tcp_conn.c | 2 -- net/tcp/tcp_send_buffered.c | 12 ++++-------- net/tcp/tcp_send_unbuffered.c | 12 ++++-------- net/udp/udp.h | 2 +- net/udp/udp_callback.c | 2 +- net/udp/udp_psock_sendto.c | 6 ++---- net/udp/udp_send.c | 6 +++--- 15 files changed, 28 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0e42092ed..878c036e54 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11523,6 +11523,4 @@ data buffers (2016-02-22). * fs/fat: Add an option to force all transfers to be performed indirectly using the FAT file system's internal sector buffers (2016-02-22). - * net/: Add basic support for IEEE 802.15-4 sockets. Compiles but still - missing a few things (2016-02-25). diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 29a20c747d..af523f5ad1 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -216,8 +216,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_IEEE802154 case NET_LL_IEEE802154: /* IEEE802.15-4 */ -# warning Missing IEEE 802.15-4 logic: Header length - //dev->d_llhdrlen = ???; + dev->d_llhdrlen = 0; /* REVISIT */ dev->d_mtu = CONFIG_NET_IEEE802154_MTU; #ifdef CONFIG_NET_TCP dev->d_recvwndo = CONFIG_NET_IEEE802154_TCP_RECVWNDO; diff --git a/net/socket/net_close.c b/net/socket/net_close.c index c4d8cfff85..8d657583bd 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -301,12 +301,12 @@ static inline void netclose_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154); + DEBUGASSERT(psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index e286cb2af7..a8b7b9f162 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -175,8 +175,7 @@ static uint16_t ack_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, if (IFF_IS_IPv6(dev->d_flags)) #endif { - DEBUGASSERT(pstate->snd_sock == PF_INET6 || - pstate->snd_sock == PF_IEEE802154); + DEBUGASSERT(pstate->snd_sock == PF_INET6); tcp = TCPIPv6BUF; } #endif /* CONFIG_NET_IPv6 */ @@ -515,14 +514,12 @@ static inline void sendfile_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a02a1e3acc..a6921315fd 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1024,7 +1024,7 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) + if (conn->domain == PF_INET6) { FAR struct sockaddr_in6 *infrom6 = (FAR struct sockaddr_in6 *)infrom; FAR socklen_t *fromlen = pstate->rf_fromlen; @@ -1350,12 +1350,12 @@ static inline void recvfrom_udp_rxnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver of the receive ready */ - DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_rxnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else @@ -1892,9 +1892,6 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, #ifdef CONFIG_NET_IPv6 case PF_INET6: -#ifdef CONFIG_NET_IEEE802145 - case PF_IEEE802154: -#endif { minlen = sizeof(struct sockaddr_in6); } diff --git a/net/socket/socket.c b/net/socket/socket.c index cfe84fdc7e..93fd41a278 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/socket.c * - * Copyright (C) 2007-2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -250,7 +250,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) int ret; int err; - /* Only PF_INET, PF_INET6, PF_PACKET, PF_IEEE802154 domains supported */ + /* Only PF_INET, PF_INET6 or PF_PACKET domains supported */ switch (domain) { @@ -265,9 +265,6 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) #ifdef CONFIG_NET_IPv6 case PF_INET6: -#ifdef CONFIG_NET_IEEE802154 - case PF_IEEE802154: -#endif #ifdef CONFIG_NET_LOCAL ipdomain = true; #endif diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 27692fcce4..2f3284d709 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -149,7 +149,7 @@ struct tcp_conn_s uint8_t sndseq[4]; /* The sequence number that was last sent by us */ uint8_t crefs; /* Reference counts on this instance */ #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802154 */ + uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ #endif uint8_t sa; /* Retransmission time-out calculation state * variable */ diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 6bb1bd3d8a..102f8c2213 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -139,9 +139,7 @@ static inline void accept_tcpsender(FAR struct socket *psock, { FAR struct sockaddr_in6 *inaddr = (FAR struct sockaddr_in6 *)addr; - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); inaddr->sin6_family = AF_INET6; inaddr->sin6_port = conn->rport; net_ipv6addr_copy(inaddr->sin6_addr.s6_addr, conn->u.ipv6.raddr); diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index ab579a042f..6cc9950fc0 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -977,8 +977,6 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, domain = ipv6 ? PF_INET6 : PF_INET; #elif defined(CONFIG_NET_IPv4) domain = PF_INET; -#elif defined(CONFIG_NET_IEEE802154) - domain = PF_IEEE80254; #else /* defined(CONFIG_NET_IPv6) */ domain = PF_INET6; #endif diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index bf14e81434..077a1dbe2e 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -241,13 +241,11 @@ static inline void send_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); tcp_ipv4_select(dev); } } @@ -859,14 +857,12 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 3d77aea3c6..7c0faac458 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -190,13 +190,11 @@ static inline void tcpsend_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); tcp_ipv4_select(dev); } } @@ -639,14 +637,12 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/udp/udp.h b/net/udp/udp.h index 621cf927ac..91447d2596 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -85,7 +85,7 @@ struct udp_conn_s union ip_binding_u u; /* IP address binding */ uint16_t lport; /* Bound local port number (network byte order) */ uint16_t rport; /* Remote port number (network byte order) */ - uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802145 */ + uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ uint8_t ttl; /* Default time-to-live */ uint8_t crefs; /* Reference counts on this instance */ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 778581298b..86b733f81a 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -130,7 +130,7 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) + if (conn->domain == PF_INET6) { FAR struct udp_hdr_s *udp = UDPIPv6BUF; FAR struct ipv6_hdr_s *ipv6 = IPv6BUF; diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 60cc465496..71fbe55af1 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -188,13 +188,11 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev, udp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ + else /* if (psock->s_domain == PF_INET6) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6 || - psock->s_domain == PF_IEEE802154); - + DEBUGASSERT(psock->s_domain == PF_INET6); udp_ipv4_select(dev); } } diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index 713e043738..b764fade42 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -109,7 +109,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && + (conn->domain == PF_INET6 && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { @@ -135,7 +135,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr); #ifdef CONFIG_NET_IPv6 - if ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && + if (conn->domain == PF_INET6 && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr)) { in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr); @@ -229,7 +229,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && + (conn->domain == PF_INET6 && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { -- GitLab From 2c95fef501b07d63f2bc3f5dee59d7a3fb87abd3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 07:35:55 -0600 Subject: [PATCH 803/858] Remove some empty code section comments --- net/iob/iob.h | 12 ------------ net/iob/iob_clone.c | 12 ------------ net/iob/iob_concat.c | 16 ---------------- net/iob/iob_contig.c | 12 ------------ net/iob/iob_copyin.c | 8 -------- net/iob/iob_copyout.c | 12 ------------ net/iob/iob_free_chain.c | 16 ---------------- net/iob/iob_free_qentry.c | 16 ---------------- net/iob/iob_free_queue.c | 12 ------------ net/iob/iob_initialize.c | 8 -------- net/iob/iob_pack.c | 12 ------------ net/iob/iob_test.c | 16 ++-------------- net/iob/iob_trimhead.c | 12 ------------ net/iob/iob_trimhead_queue.c | 12 ------------ net/iob/iob_trimtail.c | 16 ---------------- net/netdev/netdev.h | 8 -------- net/netdev/netdev_carrier.c | 20 -------------------- net/netdev/netdev_count.c | 20 -------------------- net/netdev/netdev_default.c | 24 ------------------------ net/netdev/netdev_foreach.c | 20 -------------------- net/netdev/netdev_rxnotify.c | 20 -------------------- net/netdev/netdev_txnotify.c | 20 -------------------- net/netdev/netdev_unregister.c | 16 ---------------- net/pkt/pkt_callback.c | 8 -------- net/pkt/pkt_finddev.c | 8 -------- net/pkt/pkt_input.c | 12 ------------ net/pkt/pkt_poll.c | 16 ---------------- net/pkt/pkt_send.c | 4 ---- net/socket/accept.c | 4 ---- net/socket/net_close.c | 4 ---- net/socket/net_dupsd.c | 4 ---- net/socket/net_monitor.c | 5 +---- net/socket/net_vfcntl.c | 4 ---- net/socket/send.c | 12 ------------ net/tcp/tcp.h | 1 + net/tcp/tcp_accept.c | 8 -------- net/tcp/tcp_appsend.c | 16 ---------------- net/tcp/tcp_backlog.c | 8 -------- net/tcp/tcp_callback.c | 4 ---- net/tcp/tcp_devpoll.c | 16 ---------------- net/tcp/tcp_finddev.c | 4 ---- net/tcp/tcp_input.c | 12 ------------ net/tcp/tcp_ipselect.c | 8 -------- net/tcp/tcp_send.c | 8 -------- net/tcp/tcp_send_buffered.c | 4 ---- net/tcp/tcp_seqno.c | 8 -------- net/tcp/tcp_timer.c | 16 ---------------- net/tcp/tcp_wrbuffer.c | 4 ---- net/tcp/tcp_wrbuffer_dump.c | 4 ---- 49 files changed, 4 insertions(+), 538 deletions(-) diff --git a/net/iob/iob.h b/net/iob/iob.h index 5b14e7e569..cbef08ddc0 100644 --- a/net/iob/iob.h +++ b/net/iob/iob.h @@ -48,14 +48,6 @@ #ifdef CONFIG_NET_IOB -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -80,10 +72,6 @@ extern sem_t g_throttle_sem; /* Counts available I/O buffers when throttled */ extern sem_t g_qentry_sem; /* Counts free I/O buffer queue containers */ #endif -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/net/iob/iob_clone.c b/net/iob/iob_clone.c index 1162b87dd8..db29abde24 100644 --- a/net/iob/iob_clone.c +++ b/net/iob/iob_clone.c @@ -63,18 +63,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_concat.c b/net/iob/iob_concat.c index 21ad4e1fc0..b543d63e6c 100644 --- a/net/iob/iob_concat.c +++ b/net/iob/iob_concat.c @@ -52,22 +52,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_contig.c b/net/iob/iob_contig.c index 9c3a6306ba..749e72a0c7 100644 --- a/net/iob/iob_contig.c +++ b/net/iob/iob_contig.c @@ -63,18 +63,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_copyin.c b/net/iob/iob_copyin.c index d4a18e7831..c5030c91c5 100644 --- a/net/iob/iob_copyin.c +++ b/net/iob/iob_copyin.c @@ -70,14 +70,6 @@ typedef CODE struct iob_s *(*iob_alloc_t)(bool throttled); -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_copyout.c b/net/iob/iob_copyout.c index e7b682651c..2cb0a10be6 100644 --- a/net/iob/iob_copyout.c +++ b/net/iob/iob_copyout.c @@ -62,18 +62,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_free_chain.c b/net/iob/iob_free_chain.c index 2534bde100..810622e828 100644 --- a/net/iob/iob_free_chain.c +++ b/net/iob/iob_free_chain.c @@ -51,22 +51,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_free_qentry.c b/net/iob/iob_free_qentry.c index 2c5e6fc6e9..e663d8a2ea 100644 --- a/net/iob/iob_free_qentry.c +++ b/net/iob/iob_free_qentry.c @@ -57,22 +57,6 @@ #if CONFIG_IOB_NCHAINS > 0 -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_free_queue.c b/net/iob/iob_free_queue.c index cf7ffff0c4..91ded4f42c 100644 --- a/net/iob/iob_free_queue.c +++ b/net/iob/iob_free_queue.c @@ -58,22 +58,10 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Private Types - ****************************************************************************/ - #ifndef NULL # define NULL ((FAR void *)0) #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_initialize.c b/net/iob/iob_initialize.c index 647eb0649c..d63d957219 100644 --- a/net/iob/iob_initialize.c +++ b/net/iob/iob_initialize.c @@ -53,14 +53,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/net/iob/iob_pack.c b/net/iob/iob_pack.c index 4765e8e594..660b31d4a8 100644 --- a/net/iob/iob_pack.c +++ b/net/iob/iob_pack.c @@ -60,18 +60,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_test.c b/net/iob/iob_test.c index fe683f9d2d..0e13fab793 100644 --- a/net/iob/iob_test.c +++ b/net/iob/iob_test.c @@ -49,24 +49,12 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -uint8_t buffer1[16384]; -uint8_t buffer2[16384]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ +static uint8_t buffer1[16384]; +static uint8_t buffer2[16384]; /**************************************************************************** * Private Functions diff --git a/net/iob/iob_trimhead.c b/net/iob/iob_trimhead.c index ffb1bc8b73..70a5359603 100644 --- a/net/iob/iob_trimhead.c +++ b/net/iob/iob_trimhead.c @@ -61,18 +61,6 @@ # define NULL ((FAR void *)0) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_trimhead_queue.c b/net/iob/iob_trimhead_queue.c index 9315b8d3fe..24b9878321 100644 --- a/net/iob/iob_trimhead_queue.c +++ b/net/iob/iob_trimhead_queue.c @@ -63,18 +63,6 @@ # define NULL ((FAR void *)0) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/iob/iob_trimtail.c b/net/iob/iob_trimtail.c index 6305069860..6965fe3da5 100644 --- a/net/iob/iob_trimtail.c +++ b/net/iob/iob_trimtail.c @@ -53,22 +53,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev.h b/net/netdev/netdev.h index 4289dc561a..19955d3951 100644 --- a/net/netdev/netdev.h +++ b/net/netdev/netdev.h @@ -47,14 +47,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/net/netdev/netdev_carrier.c b/net/netdev/netdev_carrier.c index 397ca4cb88..8c42203328 100644 --- a/net/netdev/netdev_carrier.c +++ b/net/netdev/netdev_carrier.c @@ -54,26 +54,6 @@ #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_count.c b/net/netdev/netdev_count.c index d036339c54..73ff960f3d 100644 --- a/net/netdev/netdev_count.c +++ b/net/netdev/netdev_count.c @@ -48,26 +48,6 @@ #include "utils/utils.h" #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_default.c b/net/netdev/netdev_default.c index addb67dcc7..24884259a7 100644 --- a/net/netdev/netdev_default.c +++ b/net/netdev/netdev_default.c @@ -45,30 +45,6 @@ #include "utils/utils.h" #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: netdev_maskcmp - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_foreach.c b/net/netdev/netdev_foreach.c index 8098dfd12e..99d6a8c061 100644 --- a/net/netdev/netdev_foreach.c +++ b/net/netdev/netdev_foreach.c @@ -46,26 +46,6 @@ #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_rxnotify.c b/net/netdev/netdev_rxnotify.c index afef07e545..187ca6c05e 100644 --- a/net/netdev/netdev_rxnotify.c +++ b/net/netdev/netdev_rxnotify.c @@ -50,26 +50,6 @@ #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_txnotify.c b/net/netdev/netdev_txnotify.c index bbf4e9dec3..3d0c85203c 100644 --- a/net/netdev/netdev_txnotify.c +++ b/net/netdev/netdev_txnotify.c @@ -50,26 +50,6 @@ #include "netdev/netdev.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/netdev/netdev_unregister.c b/net/netdev/netdev_unregister.c index 9dad59c222..fc326dcf31 100644 --- a/net/netdev/netdev_unregister.c +++ b/net/netdev/netdev_unregister.c @@ -65,22 +65,6 @@ # define NETDEV_FORMAT "eth%d" #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/pkt/pkt_callback.c b/net/pkt/pkt_callback.c index cc66f6d47a..5376b4ce22 100644 --- a/net/pkt/pkt_callback.c +++ b/net/pkt/pkt_callback.c @@ -49,14 +49,6 @@ #include "devif/devif.h" #include "pkt/pkt.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/pkt/pkt_finddev.c b/net/pkt/pkt_finddev.c index 885f6402b2..639c894b3b 100644 --- a/net/pkt/pkt_finddev.c +++ b/net/pkt/pkt_finddev.c @@ -45,14 +45,6 @@ #include "netdev/netdev.h" #include "pkt/pkt.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index 60b2ca19aa..27b3af4d25 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -60,18 +60,6 @@ #define PKTBUF ((struct eth_hdr_s *)&dev->d_buf) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index afb65db24f..dc4f5a92d0 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -54,22 +54,6 @@ #include "devif/devif.h" #include "pkt/pkt.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/pkt/pkt_send.c b/net/pkt/pkt_send.c index b36e3cb8bb..1310cb9208 100644 --- a/net/pkt/pkt_send.c +++ b/net/pkt/pkt_send.c @@ -61,10 +61,6 @@ #include "socket/socket.h" #include "pkt/pkt.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ diff --git a/net/socket/accept.c b/net/socket/accept.c index 83cd9602cc..ea1e887bf9 100644 --- a/net/socket/accept.c +++ b/net/socket/accept.c @@ -54,10 +54,6 @@ #include "local/local.h" #include "socket/socket.h" -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 8d657583bd..f439811b85 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -66,10 +66,6 @@ #include "local/local.h" #include "socket/socket.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ diff --git a/net/socket/net_dupsd.c b/net/socket/net_dupsd.c index 9ebe0b30b7..85d9b6f935 100644 --- a/net/socket/net_dupsd.c +++ b/net/socket/net_dupsd.c @@ -48,10 +48,6 @@ #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/socket/net_monitor.c b/net/socket/net_monitor.c index 8c3f24f4a9..3e6cf0c2ae 100644 --- a/net/socket/net_monitor.c +++ b/net/socket/net_monitor.c @@ -50,10 +50,6 @@ #include "tcp/tcp.h" #include "socket/socket.h" -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -66,6 +62,7 @@ static uint16_t connection_event(FAR struct net_driver_s *dev, /**************************************************************************** * Private Functions ****************************************************************************/ + /**************************************************************************** * Name: connection_closed * diff --git a/net/socket/net_vfcntl.c b/net/socket/net_vfcntl.c index 5341328a7b..d6fd76f20b 100644 --- a/net/socket/net_vfcntl.c +++ b/net/socket/net_vfcntl.c @@ -52,10 +52,6 @@ #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/socket/send.c b/net/socket/send.c index 562152031c..60b19ab296 100644 --- a/net/socket/send.c +++ b/net/socket/send.c @@ -49,18 +49,6 @@ #include "local/local.h" #include "socket/socket.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 2f3284d709..0b3bd37ce5 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -126,6 +126,7 @@ /**************************************************************************** * Public Type Definitions ****************************************************************************/ + /* Representation of a TCP connection. * * The tcp_conn_s structure is used for identifying a connection. All diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 102f8c2213..a37db211db 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -54,10 +54,6 @@ #include "socket/socket.h" #include "tcp/tcp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -72,10 +68,6 @@ struct accept_s int acpt_result; /* The result of the wait */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index dbaeb5c2d3..a56da75714 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -55,22 +55,6 @@ #include "devif/devif.h" #include "tcp/tcp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_backlog.c b/net/tcp/tcp_backlog.c index bbd5c26353..f4bba6cbeb 100644 --- a/net/tcp/tcp_backlog.c +++ b/net/tcp/tcp_backlog.c @@ -52,14 +52,6 @@ #include "devif/devif.h" #include "tcp/tcp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index d8bcd9dd22..73c6175fee 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -53,10 +53,6 @@ #include "iob/iob.h" #include "tcp/tcp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_devpoll.c b/net/tcp/tcp_devpoll.c index bf7a7ee681..e4fadc6be6 100644 --- a/net/tcp/tcp_devpoll.c +++ b/net/tcp/tcp_devpoll.c @@ -55,22 +55,6 @@ #include "devif/devif.h" #include "tcp/tcp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index 8d7d468292..ef6ae8f0d2 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -49,10 +49,6 @@ #include "netdev/netdev.h" #include "tcp/tcp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 49c8aca1ae..3db34ae384 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -60,18 +60,6 @@ #include "utils/utils.h" #include "tcp/tcp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_ipselect.c b/net/tcp/tcp_ipselect.c index 6669b3be0c..a2570c34b0 100644 --- a/net/tcp/tcp_ipselect.c +++ b/net/tcp/tcp_ipselect.c @@ -49,14 +49,6 @@ #include "tcp/tcp.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 42fb9a62c8..14affd53de 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -68,14 +68,6 @@ #define TCPIPv4BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN]) #define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 077a1dbe2e..3ab9f269d7 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -101,10 +101,6 @@ # define WRB_DUMP(msg,wrb,len,offset) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/net/tcp/tcp_seqno.c b/net/tcp/tcp_seqno.c index 6eb9141ce5..d2c5600107 100644 --- a/net/tcp/tcp_seqno.c +++ b/net/tcp/tcp_seqno.c @@ -55,10 +55,6 @@ #include "devif/devif.h" -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -67,10 +63,6 @@ static uint32_t g_tcpsequence; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 48109d63be..a9681a5c8a 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -56,22 +56,6 @@ #include "devif/devif.h" #include "tcp/tcp.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index d50878a455..cb6c10e9d8 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -88,10 +88,6 @@ struct wrbuffer_s static struct wrbuffer_s g_wrbuffer; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/tcp/tcp_wrbuffer_dump.c b/net/tcp/tcp_wrbuffer_dump.c index 741120f6fd..5458519195 100644 --- a/net/tcp/tcp_wrbuffer_dump.c +++ b/net/tcp/tcp_wrbuffer_dump.c @@ -48,10 +48,6 @@ #ifdef CONFIG_DEBUG -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ -- GitLab From 2f28ca86c294ea9941357f4b72d1eab3271830dd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 10:08:36 -0600 Subject: [PATCH 804/858] Clean up some naming; rename net/ieee802154 to net/6lowpan --- drivers/Kconfig | 2 +- drivers/ieee802154/Make.defs | 4 ++-- include/nuttx/net/arp.h | 2 +- include/nuttx/net/ieee802154.h | 4 ++-- include/nuttx/net/net.h | 2 +- include/sys/socket.h | 2 +- .../ieee802154.h => 6lowpan/6lowpan.h} | 2 +- net/{ieee802154 => 6lowpan}/Kconfig | 23 ++++++++----------- net/{ieee802154 => 6lowpan}/Make.defs | 12 +++++----- net/Kconfig | 2 +- net/Makefile | 2 +- net/netdev/netdev_register.c | 2 +- 12 files changed, 28 insertions(+), 31 deletions(-) rename net/{ieee802154/ieee802154.h => 6lowpan/6lowpan.h} (98%) rename net/{ieee802154 => 6lowpan}/Kconfig (70%) rename net/{ieee802154 => 6lowpan}/Make.defs (90%) diff --git a/drivers/Kconfig b/drivers/Kconfig index e2396dcc2e..3493d02c00 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -374,7 +374,7 @@ source drivers/ioexpander/Kconfig endif # IOEXPANDER menuconfig IEEE802154 - bool "IEEE 802.15-4 Device Support" + bool "IEEE 802.15.4 Device Support" default n depends on EXPERIMENTAL ---help--- diff --git a/drivers/ieee802154/Make.defs b/drivers/ieee802154/Make.defs index f45e479281..88c20db518 100644 --- a/drivers/ieee802154/Make.defs +++ b/drivers/ieee802154/Make.defs @@ -33,11 +33,11 @@ # ############################################################################ -# Include nothing if IEEE 802.15-4 is disabled +# Include nothing if IEEE 802.15.4 is disabled ifeq ($(CONFIG_IEEE802154),y) -# Include common IEEE 802.15-4 +# Include common IEEE 802.15.4 # Include IEEE 802.15.4 drivers diff --git a/include/nuttx/net/arp.h b/include/nuttx/net/arp.h index 4768c9fdff..236053ce70 100644 --- a/include/nuttx/net/arp.h +++ b/include/nuttx/net/arp.h @@ -69,7 +69,7 @@ */ #define ARPHRD_ETHER 1 /* Ethernet */ -#define ARPHRD_IEEE802154 804 /* IEEE 802-15-4 */ +#define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 */ /**************************************************************************** * Public Types diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h index cb3a3ef046..1ac577cea2 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/ieee802154.h @@ -64,8 +64,8 @@ * Name: ieee802154_input * * Description: - * This function provides the interface between IEEE 802.15-4 device driver - * and IEEE 802.15-4 socket logic. All IPv6 frames that are received should + * This function provides the interface between IEEE 802.15.4 device driver + * and IEEE 802.15.4 socket logic. All IPv6 frames that are received should * be provided to ieee802154_input(). * * Input Parameters: diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 86de2a18fa..45c84811ee 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -79,7 +79,7 @@ enum net_lltype_e NET_LL_LOOPBACK, /* Local loopback */ NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ NET_LL_TUN, /* TUN Virtual Network Device */ - NET_LL_IEEE802154 /* IEEE 802.15-4 */ + NET_LL_IEEE802154 /* IEEE 802.15.4 */ }; /* This defines a bitmap big enough for one bit for each socket option */ diff --git a/include/sys/socket.h b/include/sys/socket.h index 71710d308e..7276fe2700 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -64,7 +64,7 @@ #define PF_ATMPVC 8 /* Access to raw ATM PVCs */ #define PF_APPLETALK 9 /* Appletalk */ #define PF_PACKET 10 /* Low level packet interface */ -#define PF_IEEE802154 11 /* IEEE802.15-4 sockets */ +#define PF_IEEE802154 11 /* IEEE 802.15.4 sockets */ /* Address families */ diff --git a/net/ieee802154/ieee802154.h b/net/6lowpan/6lowpan.h similarity index 98% rename from net/ieee802154/ieee802154.h rename to net/6lowpan/6lowpan.h index 9d9e8191f4..cb5a54eb34 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/6lowpan/6lowpan.h @@ -1,5 +1,5 @@ /**************************************************************************** - * net/ieee802154/ieee802154.h + * net/6lowpan/6lowpan.h * * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/net/ieee802154/Kconfig b/net/6lowpan/Kconfig similarity index 70% rename from net/ieee802154/Kconfig rename to net/6lowpan/Kconfig index 0062c29fcd..a96521a49b 100644 --- a/net/ieee802154/Kconfig +++ b/net/6lowpan/Kconfig @@ -3,26 +3,24 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -menu "IEEE802.15-4 Configuration" +menu "IEEE 802.15.4 Configuration" config NET_IEEE802154 - bool "IEEE802.15-4 support" + bool "IEEE 802.15.4 support" default n depends on EXPERIMENTAL && NET_IPv6 ---help--- - Enable IEEE802.15-4 protocol socket support + Enable IEEE 802.15.4 protocol socket support if NET_IEEE802154 config NET_IEEE802154_MTU - int "IEEE 802.15-4 packet buffer size (MTU)" - default 1294 if NET_IPv6 - default 590 if !NET_IPv6 - depends on NET_ETHERNET + int "IEEE 802.15.4 packet buffer size (MTU)" + default 1294 range 590 1518 ---help--- Packet buffer size. This size includes the TCP/UDP payload plus the - size of TCP/UDP header, the IP header, and the IEEE 802.15-4 header. + size of TCP/UDP header, the IP header, and the IEEE 802.15.4 header. This value is normally referred to as the MTU (Maximum Transmission Unit); the payload is the MSS (Maximum Segment Size). @@ -34,10 +32,9 @@ config NET_IEEE802154_MTU resulting in a minimum buffer size of of 1220+20+40+xx = xx. REVISIT! config IEEE802154_TCP_RECVWNDO - int "EEE 802.15-4 TCP receive window size" - default 1220 if NET_IPv6 - default 536 if !NET_IPv6 - depends on NET_ETHERNET && NET_TCP + int "IEEE 802.15.4 TCP receive window size" + default 1220 + depends on NET_TCP ---help--- The size of the advertised receiver's window. Should be set low (i.e., to the size of the MSS) if the application is slow to process @@ -45,4 +42,4 @@ config IEEE802154_TCP_RECVWNDO data quickly. REVISIT! endif # NET_IEEE802154 -endmenu # IEEE802.15-4 Configuration +endmenu # IEEE 802.15.4 Configuration diff --git a/net/ieee802154/Make.defs b/net/6lowpan/Make.defs similarity index 90% rename from net/ieee802154/Make.defs rename to net/6lowpan/Make.defs index de55524501..e04fd7a17c 100644 --- a/net/ieee802154/Make.defs +++ b/net/6lowpan/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# net/ieee802154/Make.defs +# net/6lowpan/Make.defs # # Copyright (C) 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -33,17 +33,17 @@ # ############################################################################ -# IEEE802.15-4 support +# IEEE 802.15.4 support ifeq ($(CONFIG_NET_IEEE802154),y) -# Include IEEE802.15-4 file in the build +# Include IEEE 802.15.4 file in the build # NET_CSRCS += -# Include the ieee802154 directory in the build +# Include the 6lowpan directory in the build -DEPPATH += --dep-path ieee802154 -VPATH += :ieee802154 +DEPPATH += --dep-path 6lowpan +VPATH += :6lowpan endif # CONFIG_NET_IEEE802154 diff --git a/net/Kconfig b/net/Kconfig index d2d7c1c0cd..ca36d66e16 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -269,7 +269,7 @@ source "net/pkt/Kconfig" source "net/local/Kconfig" source "net/tcp/Kconfig" source "net/udp/Kconfig" -source "net/ieee802154/Kconfig" +source "net/6lowpan/Kconfig" source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" source "net/igmp/Kconfig" diff --git a/net/Makefile b/net/Makefile index a8628c4a9a..5cfc2349e2 100644 --- a/net/Makefile +++ b/net/Makefile @@ -67,7 +67,7 @@ include pkt/Make.defs include local/Make.defs include tcp/Make.defs include udp/Make.defs -include ieee802154/Make.defs +include 6lowpan/Make.defs include devif/Make.defs include loopback/Make.defs include route/Make.defs diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index af523f5ad1..e1228de7b1 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -215,7 +215,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #endif #ifdef CONFIG_NET_IEEE802154 - case NET_LL_IEEE802154: /* IEEE802.15-4 */ + case NET_LL_IEEE802154: /* IEEE 802.15.4 */ dev->d_llhdrlen = 0; /* REVISIT */ dev->d_mtu = CONFIG_NET_IEEE802154_MTU; #ifdef CONFIG_NET_TCP -- GitLab From 6481aa8a3da92a22409d11ee2de6cbe736c60f0f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 11:20:07 -0600 Subject: [PATCH 805/858] Remove drivers/ieee802154/skeleton.c --- drivers/ieee802154/skeleton.c | 1168 --------------------------------- 1 file changed, 1168 deletions(-) delete mode 100644 drivers/ieee802154/skeleton.c diff --git a/drivers/ieee802154/skeleton.c b/drivers/ieee802154/skeleton.c deleted file mode 100644 index 15218169a7..0000000000 --- a/drivers/ieee802154/skeleton.c +++ /dev/null @@ -1,1168 +0,0 @@ -/**************************************************************************** - * drivers/ieee802154/skeleton.c - * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#if defined(CONFIG_NET) && defined(CONFIG_NET_skeleton) - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_NET_NOINTS -# include -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* If processing is not done at the interrupt level, then high priority - * work queue support is required. - */ - -#if defined(CONFIG_NET_NOINTS) && !defined(CONFIG_SCHED_HPWORK) -# error High priority work queue support is required -#endif - -/* CONFIG_skeleton_NINTERFACES determines the number of physical interfaces - * that will be supported. - */ - -#ifndef CONFIG_skeleton_NINTERFACES -# define CONFIG_skeleton_NINTERFACES 1 -#endif - -/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ - -#define skeleton_WDDELAY (1*CLK_TCK) - -/* TX timeout = 1 minute */ - -#define skeleton_TXTIMEOUT (60*CLK_TCK) - -/* This is a helper pointer for accessing the contents of the Ethernet header */ - -#define BUF ((struct eth_hdr_s *)priv->sk_dev.d_buf) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* The skel_driver_s encapsulates all state information for a single hardware - * interface - */ - -struct skel_driver_s -{ - bool sk_bifup; /* true:ifup false:ifdown */ - WDOG_ID sk_txpoll; /* TX poll timer */ - WDOG_ID sk_txtimeout; /* TX timeout timer */ -#ifdef CONFIG_NET_NOINTS - struct work_s sk_work; /* For deferring work to the work queue */ -#endif - - /* This holds the information visible to the NuttX network */ - - struct net_driver_s sk_dev; /* Interface understood by the network */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct skel_driver_s g_skel[CONFIG_skeleton_NINTERFACES]; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* Common TX logic */ - -static int skel_transmit(FAR struct skel_driver_s *priv); -static int skel_txpoll(FAR struct net_driver_s *dev); - -/* Interrupt handling */ - -static void skel_receive(FAR struct skel_driver_s *priv); -static void skel_txdone(FAR struct skel_driver_s *priv); -static inline void skel_interrupt_process(FAR struct skel_driver_s *priv); -#ifdef CONFIG_NET_NOINTS -static void skel_interrupt_work(FAR void *arg); -#endif -static int skel_interrupt(int irq, FAR void *context); - -/* Watchdog timer expirations */ - -static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv); -#ifdef CONFIG_NET_NOINTS -static void skel_txtimeout_work(FAR void *arg); -#endif -static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...); - -static inline void skel_poll_process(FAR struct skel_driver_s *priv); -#ifdef CONFIG_NET_NOINTS -static void skel_poll_work(FAR void *arg); -#endif -static void skel_poll_expiry(int argc, wdparm_t arg, ...); - -/* NuttX callback functions */ - -static int skel_ifup(FAR struct net_driver_s *dev); -static int skel_ifdown(FAR struct net_driver_s *dev); -static inline void skel_txavail_process(FAR struct skel_driver_s *priv); -#ifdef CONFIG_NET_NOINTS -static void skel_txavail_work(FAR void *arg); -#endif -static int skel_txavail(FAR struct net_driver_s *dev); -#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) -static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); -#ifdef CONFIG_NET_IGMP -static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); -#endif -#ifdef CONFIG_NET_ICMPv6 -static void skel_ipv6multicast(FAR struct skel_driver_s *priv); -#endif -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: skel_transmit - * - * Description: - * Start hardware transmission. Called either from the txdone interrupt - * handling or from watchdog based polling. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * OK on success; a negated errno on failure - * - * Assumptions: - * May or may not be called from an interrupt handler. In either case, - * the network is locked. - * - ****************************************************************************/ - -static int skel_transmit(FAR struct skel_driver_s *priv) -{ - /* Verify that the hardware is ready to send another packet. If we get - * here, then we are committed to sending a packet; Higher level logic - * must have assured that there is no transmission in progress. - */ - - /* Increment statistics */ - - NETDEV_TXPACKETS(priv->sk_dev); - - /* Send the packet: address=priv->sk_dev.d_buf, length=priv->sk_dev.d_len */ - - /* Enable Tx interrupts */ - - /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - - (void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT, - skel_txtimeout_expiry, 1, (wdparm_t)priv); - return OK; -} - -/**************************************************************************** - * Function: skel_txpoll - * - * Description: - * The transmitter is available, check if the network has any outgoing - * packets ready to send. This is a callback from devif_poll(). - * devif_poll() may be called: - * - * 1. When the preceding TX packet send is complete, - * 2. When the preceding TX packet send timesout and the interface is reset - * 3. During normal TX polling - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * OK on success; a negated errno on failure - * - * Assumptions: - * May or may not be called from an interrupt handler. In either case, - * the network is locked. - * - ****************************************************************************/ - -static int skel_txpoll(FAR struct net_driver_s *dev) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ - - if (priv->sk_dev.d_len > 0) - { - /* Look up the destination MAC address and add it to the Ethernet - * header. - */ - - neighbor_out(&priv->sk_dev); - - /* Send the packet */ - - skel_transmit(priv); - - /* Check if there is room in the device to hold another packet. If not, - * return a non-zero value to terminate the poll. - */ - } - - /* If zero is returned, the polling will continue until all connections have - * been examined. - */ - - return 0; -} - -/**************************************************************************** - * Function: skel_receive - * - * Description: - * An interrupt was received indicating the availability of a new RX packet - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void skel_receive(FAR struct skel_driver_s *priv) -{ - do - { - /* Check for errors and update statistics */ - - /* Check if the packet is a valid size for the network buffer - * configuration. - */ - - /* Copy the data data from the hardware to priv->sk_dev.d_buf. Set - * amount of data in priv->sk_dev.d_len - */ - - /* We only accept IPv6 packets of the configured type and ARP packets */ - - if (BUF->type == HTONS(ETHTYPE_IP6)) - { - nllvdbg("Iv6 frame\n"); - NETDEV_RXIPV6(&priv->sk_dev); - - /* Give the IPv6 packet to the network layer */ - - ieee802154_input(&priv->sk_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (priv->sk_dev.d_len > 0) - { - /* Update the Ethernet header with the correct MAC address */ - - neighbor_out(&priv->sk_dev); - - /* And send the packet */ - - skel_transmit(priv); - } - } - else - -#ifdef CONFIG_NET_ARP - if (BUF->type == htons(ETHTYPE_ARP)) - { - arp_arpin(&priv->sk_dev); - NETDEV_RXARP(&priv->sk_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (priv->sk_dev.d_len > 0) - { - skel_transmit(priv); - } - } -#endif - else - { - NETDEV_RXDROPPED(&priv->sk_dev); - } - } - while (); /* While there are more packets to be processed */ -} - -/**************************************************************************** - * Function: skel_txdone - * - * Description: - * An interrupt was received indicating that the last TX packet(s) is done - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void skel_txdone(FAR struct skel_driver_s *priv) -{ - /* Check for errors and update statistics */ - - NETDEV_TXDONE(priv->sk_dev); - - /* Check if there are pending transmissions */ - - /* If no further transmissions are pending, then cancel the TX timeout and - * disable further Tx interrupts. - */ - - wd_cancel(priv->sk_txtimeout); - - /* Then make sure that the TX poll timer is running (if it is already - * running, the following would restart it). This is necessary to - * avoid certain race conditions where the polling sequence can be - * interrupted. - */ - - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, - (wdparm_t)priv); - - /* And disable further TX interrupts. */ - - /* In any event, poll the network for new TX data */ - - (void)devif_poll(&priv->sk_dev, skel_txpoll); -} - -/**************************************************************************** - * Function: skel_interrupt_process - * - * Description: - * Interrupt processing. This may be performed either within the interrupt - * handler or on the worker thread, depending upon the configuration - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static inline void skel_interrupt_process(FAR struct skel_driver_s *priv) -{ - /* Get and clear interrupt status bits */ - - /* Handle interrupts according to status bit settings */ - - /* Check if we received an incoming packet, if so, call skel_receive() */ - - skel_receive(priv); - - /* Check if a packet transmission just completed. If so, call skel_txdone. - * This may disable further Tx interrupts if there are no pending - * transmissions. - */ - - skel_txdone(priv); -} - -/**************************************************************************** - * Function: skel_interrupt_work - * - * Description: - * Perform interrupt related work from the worker thread - * - * Parameters: - * arg - The argument passed when work_queue() was called. - * - * Returned Value: - * OK on success - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_NOINTS -static void skel_interrupt_work(FAR void *arg) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - net_lock_t state; - - /* Process pending Ethernet interrupts */ - - state = net_lock(); - skel_interrupt_process(priv); - net_unlock(state); - - /* Re-enable Ethernet interrupts */ - - up_enable_irq(CONFIG_skeleton_IRQ); -} -#endif - -/**************************************************************************** - * Function: skel_interrupt - * - * Description: - * Hardware interrupt handler - * - * Parameters: - * irq - Number of the IRQ that generated the interrupt - * context - Interrupt register state save info (architecture-specific) - * - * Returned Value: - * OK on success - * - * Assumptions: - * - ****************************************************************************/ - -static int skel_interrupt(int irq, FAR void *context) -{ - FAR struct skel_driver_s *priv = &g_skel[0]; - -#ifdef CONFIG_NET_NOINTS - /* Disable further Ethernet interrupts. Because Ethernet interrupts are - * also disabled if the TX timeout event occurs, there can be no race - * condition here. - */ - - up_disable_irq(CONFIG_skeleton_IRQ); - - /* TODO: Determine if a TX transfer just completed */ - - { - /* If a TX transfer just completed, then cancel the TX timeout so - * there will be do race condition between any subsequent timeout - * expiration and the deferred interrupt processing. - */ - - wd_cancel(priv->sk_txtimeout); - } - - /* Cancel any pending poll work */ - - work_cancel(HPWORK, &priv->sk_work); - - /* Schedule to perform the interrupt processing on the worker thread. */ - - work_queue(HPWORK, &priv->sk_work, skel_interrupt_work, priv, 0); - -#else - /* Process the interrupt now */ - - skel_interrupt_process(priv); -#endif - - return OK; -} - -/**************************************************************************** - * Function: skel_txtimeout_process - * - * Description: - * Process a TX timeout. Called from the either the watchdog timer - * expiration logic or from the worker thread, depending upon the - * configuration. The timeout means that the last TX never completed. - * Reset the hardware and start again. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - ****************************************************************************/ - -static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv) -{ - /* Increment statistics and dump debug info */ - - NETDEV_TXTIMEOUTS(priv->sk_dev); - - /* Then reset the hardware */ - - /* Then poll the network for new XMIT data */ - - (void)devif_poll(&priv->sk_dev, skel_txpoll); -} - -/**************************************************************************** - * Function: skel_txtimeout_work - * - * Description: - * Perform TX timeout related work from the worker thread - * - * Parameters: - * arg - The argument passed when work_queue() as called. - * - * Returned Value: - * OK on success - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_NOINTS -static void skel_txtimeout_work(FAR void *arg) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - net_lock_t state; - - /* Process pending Ethernet interrupts */ - - state = net_lock(); - skel_txtimeout_process(priv); - net_unlock(state); -} -#endif - -/**************************************************************************** - * Function: skel_txtimeout_expiry - * - * Description: - * Our TX watchdog timed out. Called from the timer interrupt handler. - * The last TX never completed. Reset the hardware and start again. - * - * Parameters: - * argc - The number of available arguments - * arg - The first argument - * - * Returned Value: - * None - * - * Assumptions: - * Global interrupts are disabled by the watchdog logic. - * - ****************************************************************************/ - -static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - -#ifdef CONFIG_NET_NOINTS - /* Disable further Ethernet interrupts. This will prevent some race - * conditions with interrupt work. There is still a potential race - * condition with interrupt work that is already queued and in progress. - */ - - up_disable_irq(CONFIG_skeleton_IRQ); - - /* Cancel any pending poll or interrupt work. This will have no effect - * on work that has already been started. - */ - - work_cancel(HPWORK, &priv->sk_work); - - /* Schedule to perform the TX timeout processing on the worker thread. */ - - work_queue(HPWORK, &priv->sk_work, skel_txtimeout_work, priv, 0); -#else - /* Process the timeout now */ - - skel_txtimeout_process(priv); -#endif -} - -/**************************************************************************** - * Function: skel_poll_process - * - * Description: - * Perform the periodic poll. This may be called either from watchdog - * timer logic or from the worker thread, depending upon the configuration. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static inline void skel_poll_process(FAR struct skel_driver_s *priv) -{ - /* Check if there is room in the send another TX packet. We cannot perform - * the TX poll if he are unable to accept another packet for transmission. - */ - - /* If so, update TCP timing states and poll the network for new XMIT data. - * Hmmm.. might be bug here. Does this mean if there is a transmit in - * progress, we will missing TCP time state updates? - */ - - (void)devif_timer(&priv->sk_dev, skel_txpoll); - - /* Setup the watchdog poll timer again */ - - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, - (wdparm_t)priv); -} - -/**************************************************************************** - * Function: skel_poll_work - * - * Description: - * Perform periodic polling from the worker thread - * - * Parameters: - * arg - The argument passed when work_queue() as called. - * - * Returned Value: - * OK on success - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_NOINTS -static void skel_poll_work(FAR void *arg) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - net_lock_t state; - - /* Perform the poll */ - - state = net_lock(); - skel_poll_process(priv); - net_unlock(state); -} -#endif - -/**************************************************************************** - * Function: skel_poll_expiry - * - * Description: - * Periodic timer handler. Called from the timer interrupt handler. - * - * Parameters: - * argc - The number of available arguments - * arg - The first argument - * - * Returned Value: - * None - * - * Assumptions: - * Global interrupts are disabled by the watchdog logic. - * - ****************************************************************************/ - -static void skel_poll_expiry(int argc, wdparm_t arg, ...) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - -#ifdef CONFIG_NET_NOINTS - /* Is our single work structure available? It may not be if there are - * pending interrupt actions. - */ - - if (work_available(&priv->sk_work)) - { - /* Schedule to perform the interrupt processing on the worker thread. */ - - work_queue(HPWORK, &priv->sk_work, skel_poll_work, priv, 0); - } - else - { - /* No.. Just re-start the watchdog poll timer, missing one polling - * cycle. - */ - - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, arg); - } - -#else - /* Process the interrupt now */ - - skel_poll_process(priv); -#endif -} - -/**************************************************************************** - * Function: skel_ifup - * - * Description: - * NuttX Callback: Bring up the Ethernet interface when an IP address is - * provided - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static int skel_ifup(FAR struct net_driver_s *dev) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - -#ifdef CONFIG_NET_IPv6 - ndbg("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", - dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], - dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], - dev->d_ipv6addr[6], dev->d_ipv6addr[7]); -#endif - - /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ - - /* Instantiate the MAC address from priv->sk_dev.d_mac.ether_addr_octet */ - -#ifdef CONFIG_NET_ICMPv6 - /* Set up IPv6 multicast address filtering */ - - skel_ipv6multicast(priv); -#endif - - /* Set and activate a timer process */ - - (void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, - (wdparm_t)priv); - - /* Enable the Ethernet interrupt */ - - priv->sk_bifup = true; - up_enable_irq(CONFIG_skeleton_IRQ); - return OK; -} - -/**************************************************************************** - * Function: skel_ifdown - * - * Description: - * NuttX Callback: Stop the interface. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static int skel_ifdown(FAR struct net_driver_s *dev) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - irqstate_t flags; - - /* Disable the Ethernet interrupt */ - - flags = enter_critical_section(); - up_disable_irq(CONFIG_skeleton_IRQ); - - /* Cancel the TX poll timer and TX timeout timers */ - - wd_cancel(priv->sk_txpoll); - wd_cancel(priv->sk_txtimeout); - - /* Put the EMAC in its reset, non-operational state. This should be - * a known configuration that will guarantee the skel_ifup() always - * successfully brings the interface back up. - */ - - /* Mark the device "down" */ - - priv->sk_bifup = false; - leave_critical_section(flags); - return OK; -} - -/**************************************************************************** - * Function: skel_txavail_process - * - * Description: - * Perform an out-of-cycle poll. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * Called in normal user mode - * - ****************************************************************************/ - -static inline void skel_txavail_process(FAR struct skel_driver_s *priv) -{ - /* Ignore the notification if the interface is not yet up */ - - if (priv->sk_bifup) - { - /* Check if there is room in the hardware to hold another outgoing packet. */ - - /* If so, then poll the network for new XMIT data */ - - (void)devif_poll(&priv->sk_dev, skel_txpoll); - } -} - -/**************************************************************************** - * Function: skel_txavail_work - * - * Description: - * Perform an out-of-cycle poll on the worker thread. - * - * Parameters: - * arg - Reference to the NuttX driver state structure (cast to void*) - * - * Returned Value: - * None - * - * Assumptions: - * Called on the higher priority worker thread. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_NOINTS -static void skel_txavail_work(FAR void *arg) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; - net_lock_t state; - - /* Perform the poll */ - - state = net_lock(); - skel_txavail_process(priv); - net_unlock(state); -} -#endif - -/**************************************************************************** - * Function: skel_txavail - * - * Description: - * Driver callback invoked when new TX data is available. This is a - * stimulus perform an out-of-cycle poll and, thereby, reduce the TX - * latency. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * Called in normal user mode - * - ****************************************************************************/ - -static int skel_txavail(FAR struct net_driver_s *dev) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - -#ifdef CONFIG_NET_NOINTS - /* Is our single work structure available? It may not be if there are - * pending interrupt actions and we will have to ignore the Tx - * availability action. - */ - - if (work_available(&priv->sk_work)) - { - /* Schedule to serialize the poll on the worker thread. */ - - work_queue(HPWORK, &priv->sk_work, skel_txavail_work, priv, 0); - } - -#else - irqstate_t flags; - - /* Disable interrupts because this function may be called from interrupt - * level processing. - */ - - flags = enter_critical_section(); - - /* Perform the out-of-cycle poll now */ - - skel_txavail_process(priv); - leave_critical_section(flags); -#endif - - return OK; -} - -/**************************************************************************** - * Function: skel_addmac - * - * Description: - * NuttX Callback: Add the specified MAC address to the hardware multicast - * address filtering - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * mac - The MAC address to be added - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) -static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - - /* Add the MAC address to the hardware multicast routing table */ - - return OK; -} -#endif - -/**************************************************************************** - * Function: skel_rmmac - * - * Description: - * NuttX Callback: Remove the specified MAC address from the hardware multicast - * address filtering - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * mac - The MAC address to be removed - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_NET_IGMP -static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) -{ - FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; - - /* Add the MAC address to the hardware multicast routing table */ - - return OK; -} -#endif - -/**************************************************************************** - * Function: skel_ipv6multicast - * - * Description: - * Configure the IPv6 multicast MAC address. - * - * Parameters: - * priv - A reference to the private driver state structure - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_NET_ICMPv6 -static void skel_ipv6multicast(FAR struct skel_driver_s *priv) -{ - FAR struct net_driver_s *dev; - uint16_t tmp16; - uint8_t mac[6]; - - /* For ICMPv6, we need to add the IPv6 multicast address - * - * For IPv6 multicast addresses, the Ethernet MAC is derived by - * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, - * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map - * to the Ethernet MAC address 33:33:00:01:00:03. - * - * NOTES: This appears correct for the ICMPv6 Router Solicitation - * Message, but the ICMPv6 Neighbor Solicitation message seems to - * use 33:33:ff:01:00:03. - */ - - mac[0] = 0x33; - mac[1] = 0x33; - - dev = &priv->dev; - tmp16 = dev->d_ipv6addr[6]; - mac[2] = 0xff; - mac[3] = tmp16 >> 8; - - tmp16 = dev->d_ipv6addr[7]; - mac[4] = tmp16 & 0xff; - mac[5] = tmp16 >> 8; - - nvdbg("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - (void)skel_addmac(dev, mac); - -#ifdef CONFIG_NET_ICMPv6_AUTOCONF - /* Add the IPv6 all link-local nodes Ethernet address. This is the - * address that we expect to receive ICMPv6 Router Advertisement - * packets. - */ - - (void)skel_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); - -#endif /* CONFIG_NET_ICMPv6_AUTOCONF */ -#ifdef CONFIG_NET_ICMPv6_ROUTER - /* Add the IPv6 all link-local routers Ethernet address. This is the - * address that we expect to receive ICMPv6 Router Solicitation - * packets. - */ - - (void)skel_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); - -#endif /* CONFIG_NET_ICMPv6_ROUTER */ -} -#endif /* CONFIG_NET_ICMPv6 */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: skel_initialize - * - * Description: - * Initialize the Ethernet controller and driver - * - * Parameters: - * intf - In the case where there are multiple EMACs, this value - * identifies which EMAC is to be initialized. - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -int skel_initialize(int intf) -{ - FAR struct skel_driver_s *priv; - - /* Get the interface structure associated with this interface number. */ - - DEBUGASSERT(intf < CONFIG_skeleton_NINTERFACES); - priv = &g_skel[intf]; - - /* Check if a Ethernet chip is recognized at its I/O base */ - - /* Attach the IRQ to the driver */ - - if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt)) - { - /* We could not attach the ISR to the interrupt */ - - return -EAGAIN; - } - - /* Initialize the driver structure */ - - memset(priv, 0, sizeof(struct skel_driver_s)); - priv->sk_dev.d_ifup = skel_ifup; /* I/F up (new IP address) callback */ - priv->sk_dev.d_ifdown = skel_ifdown; /* I/F down callback */ - priv->sk_dev.d_txavail = skel_txavail; /* New TX data callback */ -#ifdef CONFIG_NET_IGMP - priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */ - priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */ -#endif - priv->sk_dev.d_private = (FAR void *)g_skel; /* Used to recover private state from dev */ - - /* Create a watchdog for timing polling for and timing of transmisstions */ - - priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ - priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ - - /* Put the interface in the down state. This usually amounts to resetting - * the device and/or calling skel_ifdown(). - */ - - /* Read the MAC address from the hardware into priv->sk_dev.d_mac.ether_addr_octet */ - - /* Register the device with the OS so that socket IOCTLs can be performed */ - - (void)netdev_register(&priv->sk_dev, NET_LL_IEEE802154); - return OK; -} - -#endif /* CONFIG_NET && CONFIG_NET_skeleton */ -- GitLab From 309beae2cdd2defa6bfeb29dd9106f6c55b7903e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 15:03:16 -0600 Subject: [PATCH 806/858] Move drivers/ieee802154 to drivers/wireless/ieee802154; rename include/nuttx/net ieee802154 to 6lowpan.h --- configs | 2 +- drivers/Kconfig | 11 -------- drivers/Makefile | 1 - drivers/wireless/Kconfig | 11 ++++++++ drivers/wireless/Make.defs | 6 +++++ drivers/{ => wireless}/ieee802154/Kconfig | 0 drivers/{ => wireless}/ieee802154/Make.defs | 5 ++-- include/nuttx/net/{ieee802154.h => 6lowpan.h} | 27 +++---------------- net/netdev/netdev_rxnotify.c | 2 +- 9 files changed, 26 insertions(+), 39 deletions(-) rename drivers/{ => wireless}/ieee802154/Kconfig (100%) rename drivers/{ => wireless}/ieee802154/Make.defs (91%) rename include/nuttx/net/{ieee802154.h => 6lowpan.h} (76%) diff --git a/configs b/configs index 3f48fbde14..45657b1172 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3f48fbde14b07c116c06411209767def1056a9bb +Subproject commit 45657b1172f9cfe6bf72e6313eb98e2cce78ee39 diff --git a/drivers/Kconfig b/drivers/Kconfig index 3493d02c00..bef5458d4a 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -373,17 +373,6 @@ if IOEXPANDER source drivers/ioexpander/Kconfig endif # IOEXPANDER -menuconfig IEEE802154 - bool "IEEE 802.15.4 Device Support" - default n - depends on EXPERIMENTAL - ---help--- - This directory holds implementations of IEEE802.15.4 device drivers. - -if IEEE802154 -source drivers/ieee802154/Kconfig -endif - menuconfig LCD bool "LCD Driver Support" default n diff --git a/drivers/Makefile b/drivers/Makefile index e741dd116e..025444990f 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -54,7 +54,6 @@ include audio$(DELIM)Make.defs include bch$(DELIM)Make.defs include i2c$(DELIM)Make.defs include input$(DELIM)Make.defs -include ieee802154$(DELIM)Make.defs include ioexpander$(DELIM)Make.defs include lcd$(DELIM)Make.defs include leds$(DELIM)Make.defs diff --git a/drivers/wireless/Kconfig b/drivers/wireless/Kconfig index b55b9d5756..45d0c2b54d 100644 --- a/drivers/wireless/Kconfig +++ b/drivers/wireless/Kconfig @@ -15,6 +15,17 @@ menuconfig WL_CC3000 source drivers/wireless/cc3000/Kconfig +menuconfig IEEE802154 + bool "IEEE 802.15.4 Device Support" + default n + depends on EXPERIMENTAL + ---help--- + This directory holds implementations of IEEE802.15.4 device drivers. + +if IEEE802154 +source drivers/wireless/ieee802154/Kconfig +endif + config WL_NRF24L01 bool "nRF24l01+ transceiver support" default n diff --git a/drivers/wireless/Make.defs b/drivers/wireless/Make.defs index 235e09a672..23dcbdb8c8 100644 --- a/drivers/wireless/Make.defs +++ b/drivers/wireless/Make.defs @@ -35,6 +35,12 @@ ifeq ($(CONFIG_WIRELESS),y) +# Include IEEE 802.15.4 support + +ifeq ($(CONFIG_IEEE802154),y) +include wireless$(DELIM)ieee802154$(DELIM)Make.defs +endif + # Include wireless drivers ifeq ($(CONFIG_WL_CC1101),y) diff --git a/drivers/ieee802154/Kconfig b/drivers/wireless/ieee802154/Kconfig similarity index 100% rename from drivers/ieee802154/Kconfig rename to drivers/wireless/ieee802154/Kconfig diff --git a/drivers/ieee802154/Make.defs b/drivers/wireless/ieee802154/Make.defs similarity index 91% rename from drivers/ieee802154/Make.defs rename to drivers/wireless/ieee802154/Make.defs index 88c20db518..b0eda57ca2 100644 --- a/drivers/ieee802154/Make.defs +++ b/drivers/wireless/ieee802154/Make.defs @@ -43,7 +43,8 @@ ifeq ($(CONFIG_IEEE802154),y) # Include IEEE 802.15.4 build support -DEPPATH += --dep-path ieee802154 -VPATH += :ieee802154 +DEPPATH += --dep-path wireless$(DELIM)ieee802154 +VPATH += :wireless$(DELIM)ieee802154 +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)ieee802154} endif # CONFIG_IEEE802154 diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/6lowpan.h similarity index 76% rename from include/nuttx/net/ieee802154.h rename to include/nuttx/net/6lowpan.h index 1ac577cea2..4c9d7a85e1 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/6lowpan.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/net/ieee802154.h + * include/nuttx/net/6lowpan.h * Definitions for use with PF_IEEE802154 sockets * * Copyright (C) 2016 Gregory Nutt. All rights reserved. @@ -37,8 +37,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_NET_IEEE802154_H -#define __INCLUDE_NUTTX_NET_IEEE802154_H +#ifndef __INCLUDE_NUTTX_NET_6LOWPAN_H +#define __INCLUDE_NUTTX_NET_6LOWPAN_H /**************************************************************************** * Included Files @@ -60,23 +60,4 @@ * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: ieee802154_input - * - * Description: - * This function provides the interface between IEEE 802.15.4 device driver - * and IEEE 802.15.4 socket logic. All IPv6 frames that are received should - * be provided to ieee802154_input(). - * - * Input Parameters: - * dev - The device providing the IPv6 frame - * - * Returned Value: - * OK The packet has been processed and can be deleted. - * - ****************************************************************************/ - -struct net_driver_s; /* Forward reference */ -int ieee802154_input(FAR struct net_driver_s *dev); - -#endif /* __INCLUDE_NUTTX_NET_IEEE802154_H */ +#endif /* __INCLUDE_NUTTX_NET_6LOWPAN_H */ diff --git a/net/netdev/netdev_rxnotify.c b/net/netdev/netdev_rxnotify.c index 187ca6c05e..be7aed64d0 100644 --- a/net/netdev/netdev_rxnotify.c +++ b/net/netdev/netdev_rxnotify.c @@ -104,7 +104,7 @@ void netdev_ipv4_rxnotify(in_addr_t ripaddr) * * Description: * Notify the device driver that forwards the IPv6 address that the - * application waits for RX data. + * application waits for RX data. * * Parameters: * lipaddr - The local board IPv6 address of the socket -- GitLab From cfe018e991095dcfd8c8223407d98f8346251add Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 16:50:26 -0600 Subject: [PATCH 807/858] Rename CONFIG_WIRELESS to CONFIG_DRIVERS_WIRELESS --- Directories.mk | 6 ++++++ configs | 2 +- drivers/Kconfig | 6 +++--- drivers/wireless/Make.defs | 2 +- include/nuttx/wireless/cc3000/include/cc3000_upif.h | 4 ++-- include/nuttx/wireless/wireless.h | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Directories.mk b/Directories.mk index 83cbb5f1ab..dcf9fd6510 100644 --- a/Directories.mk +++ b/Directories.mk @@ -124,6 +124,12 @@ else OTHERDIRS += audio endif +ifeq ($(CONFIG_DRIVERS_WIRELESS),y) +NONFSDIRS += wireless +else +OTHERDIRS += wireless +endif + # CLEANDIRS are the directories that will clean in. These are # all directories that we know about. # KERNDEPDIRS are the directories in which we will build target dependencies. diff --git a/configs b/configs index 45657b1172..bdb92a1d64 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 45657b1172f9cfe6bf72e6313eb98e2cce78ee39 +Subproject commit bdb92a1d64163ff9a7eb8fe842cf304a553c0f94 diff --git a/drivers/Kconfig b/drivers/Kconfig index bef5458d4a..172b3be85b 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -550,15 +550,15 @@ if USBHOST source drivers/usbhost/Kconfig endif # USBHOST -menuconfig WIRELESS +menuconfig DRIVERS_WIRELESS bool "Wireless Device Support" default n ---help--- Drivers for various wireless devices. -if WIRELESS +if DRIVERS_WIRELESS source drivers/wireless/Kconfig -endif # WIRELESS +endif # DRIVERS_WIRELESS comment "System Logging Device Options" diff --git a/drivers/wireless/Make.defs b/drivers/wireless/Make.defs index 23dcbdb8c8..be63caaa76 100644 --- a/drivers/wireless/Make.defs +++ b/drivers/wireless/Make.defs @@ -33,7 +33,7 @@ # ############################################################################ -ifeq ($(CONFIG_WIRELESS),y) +ifeq ($(CONFIG_DRIVERS_WIRELESS),y) # Include IEEE 802.15.4 support diff --git a/include/nuttx/wireless/cc3000/include/cc3000_upif.h b/include/nuttx/wireless/cc3000/include/cc3000_upif.h index 1240655ee1..26c2e10972 100644 --- a/include/nuttx/wireless/cc3000/include/cc3000_upif.h +++ b/include/nuttx/wireless/cc3000/include/cc3000_upif.h @@ -56,7 +56,7 @@ #include #include -#if defined(CONFIG_WIRELESS) && defined(CONFIG_WL_CC3000) +#if defined(CONFIG_DRIVERS_WIRELESS) && defined(CONFIG_WL_CC3000) /**************************************************************************** * Pre-processor Definitions @@ -188,5 +188,5 @@ int cc3000_register(FAR struct spi_dev_s *spi, } #endif -#endif /* CONFIG_WIRELESS && CONFIG_INPUT_CC3000 */ +#endif /* CONFIG_DRIVERS_WIRELESS && CONFIG_INPUT_CC3000 */ #endif /* __INCLUDE_NUTTX_WIRELESS_CC3000_INCLUDE_CC3000_UPIFL_H */ diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 67146c7416..fd87265228 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -47,7 +47,7 @@ #include #include -#ifdef CONFIG_WIRELESS +#ifdef CONFIG_DRIVERS_WIRELESS /************************************************************************************ * Pre-processor Definitions -- GitLab From 6d1b4c051ef0bbd7e358f7e0f807d465450b2114 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 17:07:04 -0600 Subject: [PATCH 808/858] Add new top-level wireless/ directory --- ChangeLog | 2 + Directories.mk | 2 +- FlatLibs.mk | 8 +++- Kconfig | 15 ++++++++ KernelLibs.mk | 8 +++- LibTargets.mk | 6 +++ ProtectedLibs.mk | 8 +++- audio/.gitignore | 10 +++++ wireless/.gitignore | 10 +++++ wireless/Kconfig | 15 ++++++++ wireless/Makefile | 89 +++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 audio/.gitignore create mode 100644 wireless/.gitignore create mode 100644 wireless/Kconfig create mode 100644 wireless/Makefile diff --git a/ChangeLog b/ChangeLog index 878c036e54..bf8516b95e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11523,4 +11523,6 @@ data buffers (2016-02-22). * fs/fat: Add an option to force all transfers to be performed indirectly using the FAT file system's internal sector buffers (2016-02-22). + * drivers/wireless/ieee802154: New directory. Nothing there yet (2016-02-25). + * wireless/: New top level directory. Nothing there yet (2015-02-26). diff --git a/Directories.mk b/Directories.mk index dcf9fd6510..6eeedc79e8 100644 --- a/Directories.mk +++ b/Directories.mk @@ -1,7 +1,7 @@ ############################################################################ # Directories.mk # -# Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/FlatLibs.mk b/FlatLibs.mk index ebe69cbb61..13dcc6c340 100644 --- a/FlatLibs.mk +++ b/FlatLibs.mk @@ -1,7 +1,7 @@ ############################################################################ # FlatLibs.mk # -# Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -109,6 +109,12 @@ ifeq ($(CONFIG_AUDIO),y) NUTTXLIBS += lib$(DELIM)libaudio$(LIBEXT) endif +# Add libraries for the Wireless sub-system + +ifeq ($(CONFIG_WIRELESS),y) +NUTTXLIBS += lib$(DELIM)libwireless$(LIBEXT) +endif + # Export all libraries EXPORTLIBS = $(NUTTXLIBS) diff --git a/Kconfig b/Kconfig index 09991c5e6d..4584b62546 100644 --- a/Kconfig +++ b/Kconfig @@ -418,6 +418,7 @@ comment "Subsystem Debug Options" config DEBUG_AUDIO bool "Audio Device Debug Output" default n + depends on AUDIO ---help--- Enable low level debug SYSLOG output from the audio subsystem and device drivers. (disabled by default). Support for this debug option @@ -426,6 +427,7 @@ config DEBUG_AUDIO config DEBUG_BINFMT bool "Binary Loader Debug Output" default n + depends on !BINFMT_DISABLE ---help--- Enable binary loader debug SYSLOG output (disabled by default) @@ -488,6 +490,15 @@ config DEBUG_SYSCALL Enable very low level output related to system calls. This gives you basically a poor man's version of strace. +config DEBUG_WIRELESS + bool "Wireless Device Debug Output" + default n + depends on WIRELESS + ---help--- + Enable low level debug SYSLOG output from the wireless subsystem and + device drivers. (disabled by default). Support for this debug option + is architecture-specific and may not be available for some MCUs. + comment "OS Function Debug Options" config DEBUG_DMA @@ -782,6 +793,10 @@ menu "Audio Support" source audio/Kconfig endmenu +menu "Wireless Support" +source wireless/Kconfig +endmenu + menu "Binary Loader" source binfmt/Kconfig endmenu diff --git a/KernelLibs.mk b/KernelLibs.mk index 02f9f8aa90..a7888d714d 100644 --- a/KernelLibs.mk +++ b/KernelLibs.mk @@ -1,7 +1,7 @@ ############################################################################ # KernalLibs.mk # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -104,6 +104,12 @@ ifeq ($(CONFIG_AUDIO),y) NUTTXLIBS += lib$(DELIM)libaudio$(LIBEXT) endif +# Add libraries for the Wireless sub-system + +ifeq ($(CONFIG_WIRELESS),y) +NUTTXLIBS += lib$(DELIM)libwireless$(LIBEXT) +endif + # Export only the user libraries EXPORTLIBS = $(USERLIBS) diff --git a/LibTargets.mk b/LibTargets.mk index 24a2627a9c..873958f00a 100755 --- a/LibTargets.mk +++ b/LibTargets.mk @@ -118,6 +118,12 @@ audio$(DELIM)libaudio$(LIBEXT): context lib$(DELIM)libaudio$(LIBEXT): audio$(DELIM)libaudio$(LIBEXT) $(Q) install audio$(DELIM)libaudio$(LIBEXT) lib$(DELIM)libaudio$(LIBEXT) +wireless$(DELIM)libwireless$(LIBEXT): context + $(Q) $(MAKE) -C wireless TOPDIR="$(TOPDIR)" libwireless$(LIBEXT) KERNEL=y EXTRADEFINES=$(KDEFINE) + +lib$(DELIM)libwireless$(LIBEXT): wireless$(DELIM)libwireless$(LIBEXT) + $(Q) install wireless$(DELIM)libwireless$(LIBEXT) lib$(DELIM)libwireless$(LIBEXT) + $(ARCH_SRC)$(DELIM)libarch$(LIBEXT): context $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) KERNEL=y EXTRADEFINES=$(KDEFINE) diff --git a/ProtectedLibs.mk b/ProtectedLibs.mk index 3abd390848..70185eacf4 100644 --- a/ProtectedLibs.mk +++ b/ProtectedLibs.mk @@ -1,7 +1,7 @@ ############################################################################ # ProtectedLibs.mk # -# Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -114,6 +114,12 @@ ifeq ($(CONFIG_AUDIO),y) NUTTXLIBS += lib$(DELIM)libaudio$(LIBEXT) endif +# Add libraries for the Wireless sub-system + +ifeq ($(CONFIG_WIRELESS),y) +NUTTXLIBS += lib$(DELIM)libwireless$(LIBEXT) +endif + # Export only the user libraries EXPORTLIBS = $(USERLIBS) diff --git a/audio/.gitignore b/audio/.gitignore new file mode 100644 index 0000000000..4b32ec6a3d --- /dev/null +++ b/audio/.gitignore @@ -0,0 +1,10 @@ +/Make.dep +/.depend +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/wireless/.gitignore b/wireless/.gitignore new file mode 100644 index 0000000000..4b32ec6a3d --- /dev/null +++ b/wireless/.gitignore @@ -0,0 +1,10 @@ +/Make.dep +/.depend +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/wireless/Kconfig b/wireless/Kconfig new file mode 100644 index 0000000000..ed6a31377b --- /dev/null +++ b/wireless/Kconfig @@ -0,0 +1,15 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config WIRELESS + bool "Wireless Support" + default n + depends on EXPERIMENTAL + ---help--- + Enables overall support for Wireless library. + +if WIRELESS + +endif # WIRELESS diff --git a/wireless/Makefile b/wireless/Makefile new file mode 100644 index 0000000000..dd8dde282a --- /dev/null +++ b/wireless/Makefile @@ -0,0 +1,89 @@ +############################################################################ +# wireless/Makefile +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs +DELIM ?= $(strip /) + +ifeq ($(WINTOOL),y) +INCDIROPT = -w +endif + +DEPPATH = --dep-path . +ASRCS = +CSRCS = +VPATH = . + +# Include support for various drivers. Each Make.defs file will add its +# files to the source file list, add its DEPPATH info, and will add +# the appropriate paths to the VPATH variable + +ifeq ($(CONFIG_WIRELESS_FORMAT_PCM),y) + CSRCS += pcm_decode.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +BIN = libwireless$(LIBEXT) + +all: $(BIN) + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(BIN): $(OBJS) + $(call ARCHIVE, $@, $(OBJS)) + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, $(BIN)) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep -- GitLab From 1ecb092e51306241091a09eb831077ab89655f8b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 17:27:58 -0600 Subject: [PATCH 809/858] Add wireless/ieee802154 to the build --- ChangeLog | 2 ++ drivers/wireless/Make.defs | 2 +- drivers/wireless/ieee802154/Make.defs | 4 +-- wireless/Kconfig | 2 ++ wireless/Makefile | 7 ++++ wireless/ieee802154/Kconfig | 15 +++++++++ wireless/ieee802154/Make.defs | 46 +++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 wireless/ieee802154/Kconfig create mode 100644 wireless/ieee802154/Make.defs diff --git a/ChangeLog b/ChangeLog index bf8516b95e..9b233e1988 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11525,4 +11525,6 @@ using the FAT file system's internal sector buffers (2016-02-22). * drivers/wireless/ieee802154: New directory. Nothing there yet (2016-02-25). * wireless/: New top level directory. Nothing there yet (2015-02-26). + * wireless/ieee802154: Add an new directory to the build. Nothing there + yet (2016-02-26). diff --git a/drivers/wireless/Make.defs b/drivers/wireless/Make.defs index be63caaa76..6322a5c0b0 100644 --- a/drivers/wireless/Make.defs +++ b/drivers/wireless/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_DRIVERS_WIRELESS),y) # Include IEEE 802.15.4 support -ifeq ($(CONFIG_IEEE802154),y) +ifeq ($(CONFIG_DRIVERS_IEEE802154),y) include wireless$(DELIM)ieee802154$(DELIM)Make.defs endif diff --git a/drivers/wireless/ieee802154/Make.defs b/drivers/wireless/ieee802154/Make.defs index b0eda57ca2..7c72f907db 100644 --- a/drivers/wireless/ieee802154/Make.defs +++ b/drivers/wireless/ieee802154/Make.defs @@ -35,7 +35,7 @@ # Include nothing if IEEE 802.15.4 is disabled -ifeq ($(CONFIG_IEEE802154),y) +ifeq ($(CONFIG_DRIVERS_IEEE802154),y) # Include common IEEE 802.15.4 @@ -47,4 +47,4 @@ DEPPATH += --dep-path wireless$(DELIM)ieee802154 VPATH += :wireless$(DELIM)ieee802154 CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)ieee802154} -endif # CONFIG_IEEE802154 +endif # CONFIG_DRIVERS_IEEE802154 diff --git a/wireless/Kconfig b/wireless/Kconfig index ed6a31377b..440e30a665 100644 --- a/wireless/Kconfig +++ b/wireless/Kconfig @@ -12,4 +12,6 @@ config WIRELESS if WIRELESS +source wireless/ieee802154/Kconfig + endif # WIRELESS diff --git a/wireless/Makefile b/wireless/Makefile index dd8dde282a..85f69bd118 100644 --- a/wireless/Makefile +++ b/wireless/Makefile @@ -40,11 +40,18 @@ ifeq ($(WINTOOL),y) INCDIROPT = -w endif +# Add files to the build + DEPPATH = --dep-path . + ASRCS = CSRCS = VPATH = . +# Add IEEE 802.15.4 files to the build + +include ieee802154$(DELIM)Make.defs + # Include support for various drivers. Each Make.defs file will add its # files to the source file list, add its DEPPATH info, and will add # the appropriate paths to the VPATH variable diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig new file mode 100644 index 0000000000..18d5a8753c --- /dev/null +++ b/wireless/ieee802154/Kconfig @@ -0,0 +1,15 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config IEEE802154 + bool "IEEE 802.15.4 Wireless Support" + default n + depends on EXPERIMENTAL + ---help--- + Enables support for the IEEE 802.14.5Wireless library. + +if IEEE802154 + +endif # IEEE802154 diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs new file mode 100644 index 0000000000..9e0c66391b --- /dev/null +++ b/wireless/ieee802154/Make.defs @@ -0,0 +1,46 @@ +############################################################################ +# wireless/ieee802145/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_IEEE802154),y) + +# Include IEEE 802.15.4 support + +# Include wireless devices build support + +DEPPATH += --dep-path wireless/ieee802154 +VPATH += :wireless/ieee802154 +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)wireless$(DELIM)ieee802154} + +endif # CONFIG_IEEE802154 -- GitLab From d84fa1689a713f5ac427b7d1843334870ea273de Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Feb 2016 17:32:37 -0600 Subject: [PATCH 810/858] Add include/nuttx/wireless/ieee802154 directory (with dummy header file) --- ChangeLog | 2 + include/nuttx/net/6lowpan.h | 1 - .../nuttx/wireless/ieee802154/ieee802154.h | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 include/nuttx/wireless/ieee802154/ieee802154.h diff --git a/ChangeLog b/ChangeLog index 9b233e1988..cf3391ce9e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11527,4 +11527,6 @@ * wireless/: New top level directory. Nothing there yet (2015-02-26). * wireless/ieee802154: Add an new directory to the build. Nothing there yet (2016-02-26). + * include/nuttx/wireless/ieee802154: Add directory (and dummy header file) + (2016-02-16). diff --git a/include/nuttx/net/6lowpan.h b/include/nuttx/net/6lowpan.h index 4c9d7a85e1..cbd7e071bf 100644 --- a/include/nuttx/net/6lowpan.h +++ b/include/nuttx/net/6lowpan.h @@ -1,6 +1,5 @@ /**************************************************************************** * include/nuttx/net/6lowpan.h - * Definitions for use with PF_IEEE802154 sockets * * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h new file mode 100644 index 0000000000..250a81bf00 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/ieee802154.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * include/nuttx/net/ieee802154.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Includes some definitions that a compatible with the LGPL GNU C Library + * header file of the same name. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_IEEE802154_H +#define __INCLUDE_NUTTX_NET_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __INCLUDE_NUTTX_NET_IEEE802154_H */ -- GitLab From dc7adfa817323617867b4692d0743ab5cf46d6ec Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Fri, 26 Feb 2016 18:39:27 -0600 Subject: [PATCH 811/858] drivers/wireless/ieee802154/Kconfig drivers/wireless/ieee802154/Make.defs Changes to the build infrastructure to include the mrf24j40 driver include/nuttx/spi/spi.h Define a IEEE SPI device include/nuttx/wireless/ieee802154/ieee802154_radio.h This file defines the API of a IEEE 802.15.4 radio device, to be used by the future common MAC 802.15.4 layer drivers/wireless/ieee802154/mrf24j40.c drivers/wireless/ieee802154/mrf24j40.h The main MRF24J40 IEEE 802.15.4 radio driver include/nuttx/wireless/ieee802154/mrf24j40.h This file allows instanciation of the MRF24j40 driver from board configurations --- drivers/Kconfig | 2 - drivers/wireless/Kconfig | 7 +- drivers/wireless/ieee802154/Kconfig | 10 + drivers/wireless/ieee802154/Make.defs | 8 +- drivers/wireless/ieee802154/mrf24j40.c | 1398 +++++++++++++++++ drivers/wireless/ieee802154/mrf24j40.h | 206 +++ include/nuttx/spi/spi.h | 1 + .../wireless/ieee802154/ieee802154_radio.h | 224 +++ include/nuttx/wireless/ieee802154/mrf24j40.h | 111 ++ 9 files changed, 1960 insertions(+), 7 deletions(-) create mode 100644 drivers/wireless/ieee802154/mrf24j40.c create mode 100644 drivers/wireless/ieee802154/mrf24j40.h create mode 100644 include/nuttx/wireless/ieee802154/ieee802154_radio.h create mode 100644 include/nuttx/wireless/ieee802154/mrf24j40.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 172b3be85b..d9105fcd94 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -556,9 +556,7 @@ menuconfig DRIVERS_WIRELESS ---help--- Drivers for various wireless devices. -if DRIVERS_WIRELESS source drivers/wireless/Kconfig -endif # DRIVERS_WIRELESS comment "System Logging Device Options" diff --git a/drivers/wireless/Kconfig b/drivers/wireless/Kconfig index 45d0c2b54d..e978ef6e82 100644 --- a/drivers/wireless/Kconfig +++ b/drivers/wireless/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +if DRIVERS_WIRELESS + config WL_CC1101 bool "CC1101 RF transceiver support" default n @@ -15,16 +17,14 @@ menuconfig WL_CC3000 source drivers/wireless/cc3000/Kconfig -menuconfig IEEE802154 +menuconfig DRIVERS_IEEE802154 bool "IEEE 802.15.4 Device Support" default n depends on EXPERIMENTAL ---help--- This directory holds implementations of IEEE802.15.4 device drivers. -if IEEE802154 source drivers/wireless/ieee802154/Kconfig -endif config WL_NRF24L01 bool "nRF24l01+ transceiver support" @@ -103,3 +103,4 @@ config WL_PN532_DEBUG_RX depends on WL_PN532_DEBUG endif # WL_PN532 +endif # DRIVERS_WIRELESS diff --git a/drivers/wireless/ieee802154/Kconfig b/drivers/wireless/ieee802154/Kconfig index f72f3c094c..93e802323d 100644 --- a/drivers/wireless/ieee802154/Kconfig +++ b/drivers/wireless/ieee802154/Kconfig @@ -2,3 +2,13 @@ # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # + +if DRIVERS_IEEE802154 + +config IEEE802154_MRF24J40 + bool "Microchip MRF24J40 IEEE 802.15.4 transceiver" + default n + ---help--- + This selection enables support for the Microchip MRF24J40 device. + +endif # DRIVERS_IEEE802154 diff --git a/drivers/wireless/ieee802154/Make.defs b/drivers/wireless/ieee802154/Make.defs index 7c72f907db..b0a1406baa 100644 --- a/drivers/wireless/ieee802154/Make.defs +++ b/drivers/wireless/ieee802154/Make.defs @@ -37,9 +37,13 @@ ifeq ($(CONFIG_DRIVERS_IEEE802154),y) -# Include common IEEE 802.15.4 +# Include common IEEE 802.15.4 files into the build -# Include IEEE 802.15.4 drivers +# Include IEEE 802.15.4 drivers into the build + +ifeq ($(CONFIG_IEEE802154_MRF24J40),y) + CSRCS += mrf24j40.c +endif # Include IEEE 802.15.4 build support diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c new file mode 100644 index 0000000000..3d18362c45 --- /dev/null +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -0,0 +1,1398 @@ +/**************************************************************************** + * drivers/wireless/ieee802154/mrf24j40.c + * + * Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "mrf24j40.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#ifndef CONFIG_SCHED_HPWORK +#error High priority work queue required in this driver +#endif + +#ifndef CONFIG_IEEE802154_MRF24J40_SPIMODE +# define CONFIG_IEEE802154_MRF24J40_SPIMODE SPIDEV_MODE0 +#endif + +#ifndef CONFIG_IEEE802154_MRF24J40_FREQUENCY +# define CONFIG_IEEE802154_MRF24J40_FREQUENCY 8000000 +#endif + +/* Definitions for the device structure */ + +#define MRF24J40_RXMODE_NORMAL 0 +#define MRF24J40_RXMODE_PROMISC 1 +#define MRF24J40_RXMODE_NOCRC 2 + +/* Definitions for PA control on high power modules */ + +#define MRF24J40_PA_AUTO 1 +#define MRF24J40_PA_ED 2 +#define MRF24J40_PA_SLEEP 3 + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/* A MRF24J40 device instance */ + +struct mrf24j40_dev_s +{ + struct ieee802154_dev_s ieee; /* The public device instance */ + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + struct work_s irqwork; /* Interrupt continuation work queue support */ + FAR const struct mrf24j40_lower_s *lower; /* Low-level MCU-specific support */ + + uint16_t panid; /* PAN identifier, FFFF = not set */ + uint16_t saddr; /* short address, FFFF = not set */ + uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ + uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ + uint8_t devmode; /* device mode: device, coord, pancoord */ + uint8_t paenabled; /* enable usage of PA */ + uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ + int32_t txpower; /* TX power in mBm = dBm/100 */ + struct ieee802154_cca_s cca; /* Clear channel assessement method */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Internal operations */ + +static void mrf24j40_lock (FAR struct spi_dev_s *spi); + +static void mrf24j40_setreg (FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); +static uint8_t mrf24j40_getreg (FAR struct spi_dev_s *spi, uint32_t addr); + +static int mrf24j40_resetrfsm (FAR struct mrf24j40_dev_s *dev); +static int mrf24j40_pacontrol (FAR struct mrf24j40_dev_s *dev, int mode); +static int mrf24j40_initialize(FAR struct mrf24j40_dev_s *dev); + +static int mrf24j40_setrxmode (FAR struct mrf24j40_dev_s *dev, int mode); +static int mrf24j40_regdump (FAR struct mrf24j40_dev_s *dev); +static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev); +static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev); +static void mrf24j40_irqworker (FAR void *arg); +static int mrf24j40_interrupt (int irq, FAR void *context); + +/* Driver operations */ + +static int mrf24j40_setchannel (FAR struct ieee802154_dev_s *ieee, uint8_t chan); +static int mrf24j40_getchannel (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan); +static int mrf24j40_setpanid (FAR struct ieee802154_dev_s *ieee, uint16_t panid); +static int mrf24j40_getpanid (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid); +static int mrf24j40_setsaddr (FAR struct ieee802154_dev_s *ieee, uint16_t saddr); +static int mrf24j40_getsaddr (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr); +static int mrf24j40_seteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); +static int mrf24j40_geteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); +static int mrf24j40_setpromisc (FAR struct ieee802154_dev_s *ieee, bool promisc); +static int mrf24j40_getpromisc (FAR struct ieee802154_dev_s *ieee, FAR bool *promisc); +static int mrf24j40_setdevmode (FAR struct ieee802154_dev_s *ieee, uint8_t mode); +static int mrf24j40_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode); +static int mrf24j40_settxpower (FAR struct ieee802154_dev_s *ieee, int32_t txpwr); +static int mrf24j40_gettxpower (FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr); +static int mrf24j40_setcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); +static int mrf24j40_getcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); +static int mrf24j40_ioctl (FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg); +static int mrf24j40_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy); +static int mrf24j40_rxenable (FAR struct ieee802154_dev_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_transmit (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet); + +/* These are pointers to ALL registered MRF24J40 devices. + * This table is used during irqs to find the context + * Only one device is supported for now. + * More devices can be supported in the future by lookup them up + * using the IRQ number. See the ENC28J60 or CC3000 drivers for reference. + */ + +static struct mrf24j40_dev_s g_mrf24j40_devices[1]; + +static const struct ieee802154_devops_s mrf24j40_devops = +{ + mrf24j40_setchannel, mrf24j40_getchannel, + mrf24j40_setpanid , mrf24j40_getpanid, + mrf24j40_setsaddr , mrf24j40_getsaddr, + mrf24j40_seteaddr , mrf24j40_geteaddr, + mrf24j40_setpromisc, mrf24j40_getpromisc, + mrf24j40_setdevmode, mrf24j40_getdevmode, + mrf24j40_settxpower, mrf24j40_gettxpower, + mrf24j40_setcca , mrf24j40_getcca, + mrf24j40_ioctl, + mrf24j40_energydetect, + mrf24j40_rxenable, + mrf24j40_transmit +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifndef CONFIG_SPI_EXCHANGE +#error CONFIG_SPI_EXCHANGE required for this driver +#endif + +/* Hardware access routines */ + +/**************************************************************************** + * Name: mrf24j40_lock + * + * Description: + * Acquire exclusive access to the shared SPI bus. + * + ****************************************************************************/ + +static void mrf24j40_lock(FAR struct spi_dev_s *spi) +{ + SPI_LOCK (spi, 1); + SPI_SETBITS (spi, 8); + SPI_SETMODE (spi, CONFIG_IEEE802154_MRF24J40_SPIMODE); + SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_MRF24J40_FREQUENCY); +} + +/**************************************************************************** + * Name: mrf24j40_unlock + * + * Description: + * Release exclusive access to the shared SPI bus. + * + ****************************************************************************/ + +static inline void mrf24j40_unlock(FAR struct spi_dev_s *spi) +{ + SPI_LOCK(spi,0); +} + +/**************************************************************************** + * Name: mrf24j40_setreg + * + * Description: + * Define the value of an MRF24J40 device register + * + ****************************************************************************/ + +static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val) +{ + uint8_t buf[3]; + int len; + if (!(addr&0x80000000)) + { + addr &= 0x3F; /* 6-bit address */ + addr <<= 1; + addr |= 0x01; /* writing */ + buf[0] = addr; + len = 1; + } + else + { + addr &= 0x3FF; /* 10-bit address */ + addr <<= 5; + addr |= 0x8010; /* writing long */ + buf[0] = (addr >> 8); + buf[1] = (addr & 0xFF); + len = 2; + } + buf[len++] = val; + + mrf24j40_lock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SNDBLOCK(spi, buf, len); + SPI_SELECT(spi, SPIDEV_IEEE802154, false); + mrf24j40_unlock(spi); +} + +/**************************************************************************** + * Name: mrf24j40_getreg + * + * Description: + * Return the value of an MRF24J40 device register + * + ****************************************************************************/ + +static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr) +{ + uint8_t buf[3]; + uint8_t rx[3]; + int len; + + if (!(addr&0x80000000)) + { + /* 6-bit address */ + + addr &= 0x3F; + addr <<= 1; + buf[0] = addr; + len = 1; + } + else + { + /* 10-bit address */ + + addr &= 0x3FF; + addr <<= 5; + addr |= 0x8000; + buf[0] = (addr >> 8); + buf[1] = (addr & 0xFF); + len = 2; + } + + buf[len++] = 0xFF; /* dummy */ + + mrf24j40_lock (spi); + SPI_SELECT (spi, SPIDEV_IEEE802154, true); + SPI_EXCHANGE (spi, buf, rx, len); + SPI_SELECT (spi, SPIDEV_IEEE802154, false); + mrf24j40_unlock(spi); + + /*dbg("r[%04X]=%02X\n",addr,rx[len-1]);*/ + return rx[len-1]; +} + +/**************************************************************************** + * Name: mrf24j40_resetrfsm + * + * Description: + * Reset the RF state machine. Required at boot, after channel change, + * and probably after PA settings. + * + ****************************************************************************/ + +static int mrf24j40_resetrfsm(FAR struct mrf24j40_dev_s *dev) +{ + uint8_t reg; + + reg = mrf24j40_getreg(dev->spi, MRF24J40_RFCTL); + reg |= 0x04; + mrf24j40_setreg(dev->spi, MRF24J40_RFCTL, reg); + + reg &= ~0x04; + mrf24j40_setreg(dev->spi, MRF24J40_RFCTL, reg); + up_udelay(200); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_pacontrol + * + * Description: + * Control the external LNA/PA on the MRF24J40MB/MC/MD/ME modules + * GPIO 1: PA enable + * GPIO 2: LNA enable + * GPIO 3: PA power enable (not required on MB) + ****************************************************************************/ + +static int mrf24j40_pacontrol(FAR struct mrf24j40_dev_s *dev, int mode) +{ + if (!dev->paenabled) + { + return OK; + } + + if (mode == MRF24J40_PA_AUTO) + { + mrf24j40_setreg(dev->spi, MRF24J40_TRISGPIO, 0x08); + mrf24j40_setreg(dev->spi, MRF24J40_GPIO , 0x08); + mrf24j40_setreg(dev->spi, MRF24J40_TESTMODE, 0x0F); + } + else if (mode == MRF24J40_PA_ED) + { + mrf24j40_setreg(dev->spi, MRF24J40_TESTMODE, 0x08); + mrf24j40_setreg(dev->spi, MRF24J40_TRISGPIO, 0x0F); + mrf24j40_setreg(dev->spi, MRF24J40_GPIO , 0x0C); + } + else if (mode == MRF24J40_PA_SLEEP) + { + mrf24j40_setreg(dev->spi, MRF24J40_TESTMODE, 0x08); + mrf24j40_setreg(dev->spi, MRF24J40_TRISGPIO, 0x0F); + mrf24j40_setreg(dev->spi, MRF24J40_GPIO , 0x00); + } + else + { + return -EINVAL; + } + + mrf24j40_resetrfsm(dev); + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_initialize + * + * Description: + * Reset the device and put in in order of operation + * + ****************************************************************************/ + +static int mrf24j40_initialize(FAR struct mrf24j40_dev_s *dev) +{ + /* Software reset */ + + mrf24j40_setreg(dev->spi, MRF24J40_SOFTRST , 0x07); /* 00000111 Reset */ + while(mrf24j40_getreg(dev->spi, MRF24J40_SOFTRST) & 0x07); + + /* Apply recommended settings */ + + mrf24j40_setreg(dev->spi, MRF24J40_PACON2 , 0x98); /* 10011000 Enable FIFO (default), TXONTS=6 (recommended), TXONT<8:7>=0 */ + mrf24j40_setreg(dev->spi, MRF24J40_TXSTBL , 0x95); /* 10010101 set the SIFS period. RFSTBL=9, MSIFS=5, aMinSIFSPeriod=14 (min 12) */ + mrf24j40_setreg(dev->spi, MRF24J40_TXPEND , 0x7C); /* 01111100 set the LIFS period, MLIFS=1Fh=31 aMinLIFSPeriod=40 (min 40) */ + mrf24j40_setreg(dev->spi, MRF24J40_TXTIME , 0x30); /* 00110000 set the turnaround time, TURNTIME=3 aTurnAroundTime=12 */ + mrf24j40_setreg(dev->spi, MRF24J40_RFCON1 , 0x02); /* 00000010 VCO optimization, recommended value */ + mrf24j40_setreg(dev->spi, MRF24J40_RFCON2 , 0x80); /* 10000000 Enable PLL */ + mrf24j40_setreg(dev->spi, MRF24J40_RFCON6 , 0x90); /* 10010000 TX filter enable, fast 20M recovery, No bat monitor*/ + mrf24j40_setreg(dev->spi, MRF24J40_RFCON7 , 0x80); /* 10000000 Sleep clock on internal 100 kHz */ + mrf24j40_setreg(dev->spi, MRF24J40_RFCON8 , 0x10); /* 00010000 VCO control bit, as recommended */ + mrf24j40_setreg(dev->spi, MRF24J40_SLPCON1, 0x01); /* 00000001 no CLKOUT, default divisor */ + mrf24j40_setreg(dev->spi, MRF24J40_BBREG6 , 0x40); /* 01000000 Append RSSI to rx packets */ + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setrxmode + * + * Description: + * Set the RX mode (normal, promiscuous, no CRC) + * + ****************************************************************************/ + +static int mrf24j40_setrxmode(FAR struct mrf24j40_dev_s *dev, int mode) +{ + uint8_t reg; + if (mode < MRF24J40_RXMODE_NORMAL || mode > MRF24J40_RXMODE_NOCRC) + { + return -EINVAL; + } + + reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR); + reg &= ~0x03; + reg |= mode; + + /* Set mode options */ + + if (mode != MRF24J40_RXMODE_NORMAL) + { + /* Promisc and error modes: Disable auto ACK */ + reg |= MRF24J40_RXMCR_NOACKRSP; + } + else + { + /* Normal mode : enable auto-ACK */ + reg &= ~MRF24J40_RXMCR_NOACKRSP; + } + + mrf24j40_setreg(dev->spi, MRF24J40_RXMCR, reg); + + dev->rxmode = mode; + dbg("%u\n",(unsigned)mode); + return OK; +} + +/* Publicized driver routines */ + +/**************************************************************************** + * Name: mrf24j40_setchannel + * + * Description: + * Define the current radio channel the device is operating on. + * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: + * Chan MHz Chan MHz Chan MHz Chan MHz + * 11 2405 15 2425 19 2445 23 2465 + * 12 2410 16 2430 20 2450 24 2470 + * 13 2415 17 2435 21 2455 25 2475 + * 14 2420 18 2440 22 2460 26 2480 + * + ****************************************************************************/ + +static int mrf24j40_setchannel(FAR struct ieee802154_dev_s *ieee, + uint8_t chan) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + if (chan<11 || chan>26) + { + dbg("Invalid chan: %d\n",chan); + return -EINVAL; + } + + /* 15. Set channel – See Section 3.4 “Channel Selectionâ€. */ + + mrf24j40_setreg(dev->spi, MRF24J40_RFCON0, (chan - 11) << 4 | 0x03); + + /* 17. RFCTL (0x36) = 0x04 – Reset RF state machine. + * 18. RFCTL (0x36) = 0x00. + */ + + mrf24j40_resetrfsm(dev); + + dev->channel = chan; + //dbg("%u\n",(unsigned)chan); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_getchannel + * + * Description: + * Define the current radio channel the device is operating on. + * + ****************************************************************************/ + +static int mrf24j40_getchannel(FAR struct ieee802154_dev_s *ieee, + FAR uint8_t *chan) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *chan = dev->channel; + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setpanid + * + * Description: + * Define the PAN ID the device is operating on. + * + ****************************************************************************/ + +static int mrf24j40_setpanid(FAR struct ieee802154_dev_s *ieee, + uint16_t panid) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8)); + mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF)); + + dev->panid = panid; + dbg("%04X\n",(unsigned)panid); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_getpanid + * + * Description: + * Define the current PAN ID the device is operating on. + * + ****************************************************************************/ + +static int mrf24j40_getpanid(FAR struct ieee802154_dev_s *ieee, + FAR uint16_t *panid) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *panid = dev->panid; + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setsaddr + * + * Description: + * Define the device short address. The following addresses are special: + * FFFEh : Broadcast + * FFFFh : Unspecified + * + ****************************************************************************/ + +static int mrf24j40_setsaddr(FAR struct ieee802154_dev_s *ieee, + uint16_t saddr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8)); + mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF)); + + dev->saddr = saddr; + dbg("%04X\n",(unsigned)saddr); + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_getsaddr + * + * Description: + * Define the current short address the device is using. + * + ****************************************************************************/ + +static int mrf24j40_getsaddr(FAR struct ieee802154_dev_s *ieee, + FAR uint16_t *saddr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *saddr = dev->saddr; + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_seteaddr + * + * Description: + * Define the device extended address. The following addresses are special: + * FFFFFFFFFFFFFFFFh : Unspecified + * + ****************************************************************************/ + +static int mrf24j40_seteaddr(FAR struct ieee802154_dev_s *ieee, + FAR uint8_t *eaddr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + int i; + + for (i=0; i<8; i++) + { + mrf24j40_setreg(dev->spi, MRF24J40_EADR0 + i, eaddr[i]); + dev->eaddr[i] = eaddr[i]; + } + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_geteaddr + * + * Description: + * Define the current extended address the device is using. + * + ****************************************************************************/ + +static int mrf24j40_geteaddr(FAR struct ieee802154_dev_s *ieee, + FAR uint8_t *eaddr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + memcpy(eaddr, dev->eaddr, 8); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setpromisc + * + * Description: + * Set the device into promiscuous mode, e.g do not filter any incoming + * frame. + * + ****************************************************************************/ + +static int mrf24j40_setpromisc(FAR struct ieee802154_dev_s *ieee, + bool promisc) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + return mrf24j40_setrxmode(dev, promisc ? MRF24J40_RXMODE_PROMISC : + MRF24J40_RXMODE_NORMAL); +} + +/**************************************************************************** + * Name: mrf24j40_getpromisc + * + * Description: + * Get the device receive mode. + * + ****************************************************************************/ + +static int mrf24j40_getpromisc(FAR struct ieee802154_dev_s *ieee, + FAR bool *promisc) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *promisc = (dev->rxmode == MRF24J40_RXMODE_PROMISC); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setdevmode + * + * Description: + * Define the device behaviour: normal end device or coordinator + * + ****************************************************************************/ + +static int mrf24j40_setdevmode(FAR struct ieee802154_dev_s *ieee, + uint8_t mode) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + int ret = OK; + uint8_t reg; + + /* Disable slotted mode until I decide to implement slotted mode */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_TXMCR); + reg &= ~MRF24J40_TXMCR_SLOTTED; + mrf24j40_setreg(dev->spi, MRF24J40_TXMCR, reg); + mrf24j40_setreg(dev->spi, MRF24J40_ORDER, 0xFF); + + /* Define dev mode */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR); + + if (mode == IEEE802154_MODE_PANCOORD) + { + reg |= MRF24J40_RXMCR_PANCOORD; + reg &= ~MRF24J40_RXMCR_COORD; + } + else if (mode == IEEE802154_MODE_COORD) + { + reg |= MRF24J40_RXMCR_COORD; + reg &= ~MRF24J40_RXMCR_PANCOORD; + } + else if (mode == IEEE802154_MODE_DEVICE) + { + reg &= ~MRF24J40_RXMCR_PANCOORD; + reg &= ~MRF24J40_RXMCR_COORD; + } + else + { + return -EINVAL; + } + + mrf24j40_setreg(dev->spi, MRF24J40_RXMCR, reg); + dev->devmode = mode; + + return ret; +} + +/**************************************************************************** + * Name: mrf24j40_setdevmode + * + * Description: + * Return the current device mode + * + ****************************************************************************/ + +static int mrf24j40_getdevmode(FAR struct ieee802154_dev_s *ieee, + FAR uint8_t *mode) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *mode = dev->devmode; + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_settxpower + * + * Description: + * Define the transmit power. Value is passed in mBm, it is rounded to + * the nearest value. Some MRF modules have a power amplifier, this routine + * does not care about this. We only change the CHIP output power. + * + ****************************************************************************/ + +static int mrf24j40_settxpower(FAR struct ieee802154_dev_s *ieee, + int32_t txpwr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + uint8_t reg; + int save_txpwr = txpwr; + + if (txpwr <= -3000 && txpwr > -3630) + { + reg = 0xC0; + txpwr += 3000; + } + else if (txpwr <= -2000) + { + reg = 0x80; + txpwr += 2000; + } + else if (txpwr <= -1000) + { + reg = 0x40; + txpwr += 1000; + } + else if (txpwr <= 0) + { + reg = 0x00; + } + else + { + return -EINVAL; + } + + lldbg("remaining attenuation: %d mBm\n",txpwr); + + switch(txpwr/100) + { + case -9: + case -8: + case -7: + case -6: reg |= 0x07; break; + case -5: reg |= 0x06; break; + case -4: reg |= 0x05; break; + case -3: reg |= 0x04; break; + case -2: reg |= 0x03; break; + case -1: reg |= 0x02; break; + case 0: reg |= 0x00; break; /* value 0x01 is 0.5 db, not used */ + default: return -EINVAL; + } + + mrf24j40_setreg(dev->spi, MRF24J40_RFCON3, reg); + dev->txpower = save_txpwr; + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_gettxpower + * + * Description: + * Return the actual transmit power, in mBm. + * + ****************************************************************************/ + +static int mrf24j40_gettxpower(FAR struct ieee802154_dev_s *ieee, + FAR int32_t *txpwr) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + *txpwr = dev->txpower; + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_setcca + * + * Description: + * Define the Clear Channel Assessement method. + * + ****************************************************************************/ + +static int mrf24j40_setcca(FAR struct ieee802154_dev_s *ieee, + FAR struct ieee802154_cca_s *cca) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + uint8_t mode; + + if (!cca->use_ed && !cca->use_cs) + { + return -EINVAL; + } + + if (cca->use_cs && cca->csth > 0x0f) + { + return -EINVAL; + } + + mode = mrf24j40_getreg(dev->spi, MRF24J40_BBREG2); + mode &= 0x03; + + if (cca->use_ed) + { + mode |= MRF24J40_BBREG2_CCAMODE_ED; + mrf24j40_setreg(dev->spi, MRF24J40_CCAEDTH, cca->edth); + } + + if (cca->use_cs) + { + mode |= MRF24J40_BBREG2_CCAMODE_CS; + mode |= cca->csth << 2; + } + + mrf24j40_setreg(dev->spi, MRF24J40_BBREG2, mode); + + memcpy(&dev->cca, cca, sizeof(struct ieee802154_cca_s)); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_getcca + * + * Description: + * Return the Clear Channel Assessement method. + * + ****************************************************************************/ + +static int mrf24j40_getcca(FAR struct ieee802154_dev_s *ieee, + FAR struct ieee802154_cca_s *cca) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + memcpy(cca, &dev->cca, sizeof(struct ieee802154_cca_s)); + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_regdump + * + * Description: + * Display the value of all registers. + * + ****************************************************************************/ + +static int mrf24j40_regdump(FAR struct mrf24j40_dev_s *dev) +{ + uint32_t i; + char buf[4+16*3+2+1]; + int len=0; + + dbg("Short regs:\n"); + + for (i = 0; i < 0x40; i++) + { + if ((i & 15) == 0) + { + len=sprintf(buf, "%02x: ",i&0xFF); + } + + len += sprintf(buf+len, "%02x ", mrf24j40_getreg(dev->spi, i)); + if ((i & 15) == 15) + { + sprintf(buf+len, "\n"); + dbg("%s",buf); + } + } + + dbg("Long regs:\n"); + for (i=0x80000200;i<0x80000250;i++) + { + if ((i&15)==0) + { + len=sprintf(buf, "%02x: ",i&0xFF); + } + + len += sprintf(buf+len, "%02x ", mrf24j40_getreg(dev->spi, i)); + if ((i & 15) == 15) + { + sprintf(buf+len, "\n"); + dbg("%s",buf); + } + } + + return 0; +} + +/**************************************************************************** + * Name: mrf24j40_ioctl + * + * Description: + * Misc/unofficial device controls. + * + ****************************************************************************/ + +static int mrf24j40_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, + unsigned long arg) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + + switch(cmd) + { + case 1000: + return mrf24j40_regdump(dev); + + case 1001: dev->paenabled = (uint8_t)arg; + dbg("PA %sabled\n",arg?"en":"dis"); + return OK; + + default: + return -ENOTTY; + } +} + +/**************************************************************************** + * Name: mrf24j40_energydetect + * + * Description: + * Measure the RSSI level for the current channel. + * + ****************************************************************************/ + +static int mrf24j40_energydetect(FAR struct ieee802154_dev_s *ieee, + FAR uint8_t *energy) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + uint8_t reg; + + /* Manually enable the LNA*/ + + mrf24j40_pacontrol(dev, MRF24J40_PA_ED); + + /* Set RSSI average duration to 8 symbols */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_TXBCON1); + reg |= 0x30; + mrf24j40_setreg(dev->spi, MRF24J40_TXBCON1, reg); + + /* 1. Set RSSIMODE1 0x3E<7> – Initiate RSSI calculation. */ + + mrf24j40_setreg(dev->spi, MRF24J40_BBREG6, 0x80); + + /* 2. Wait until RSSIRDY 0x3E<0> is set to ‘1’ – RSSI calculation is + * complete. + */ + + while(!(mrf24j40_getreg(dev->spi, MRF24J40_BBREG6) & 0x01)); + + /* 3. Read RSSI 0x210<7:0> – The RSSI register contains the averaged RSSI + * received power level for 8 symbol periods. + */ + + *energy = mrf24j40_getreg(dev->spi, MRF24J40_RSSI); + + mrf24j40_setreg(dev->spi, MRF24J40_BBREG6, 0x40); + + /* Back to automatic control */ + + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + + return OK; +} + +/* Packet exchange */ + +/**************************************************************************** + * Name: mrf24j40_transmit + * + * Description: + * Send a regular packet over the air. + * + ****************************************************************************/ + +static int mrf24j40_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + uint32_t addr; + uint8_t reg; + int ret; + int hlen = 3; /* include frame control and seq number */ + uint8_t fc1, fc2; + + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + + addr = 0x80000000; + + /* Enable tx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_TXNIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + + /* Analyze frame control to compute header length */ + + fc1 = packet->data[0]; + fc2 = packet->data[1]; + + // dbg("fc1 %02X fc2 %02X\n", fc1,fc2); + + if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_SHORT) + { + hlen += 2 + 2; /* Destination PAN + shortaddr */ + } + else if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_EXT) + { + hlen += 2 + 8; /* Destination PAN + extaddr */ + } + + if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_SHORT) + { + if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA) + { + hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ + } + + hlen += 2; /* Source saddr */ + } + else if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_EXT) + { + if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA) + { + hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ + } + + hlen += 8; /* Ext saddr */ + } + +// dbg("hlen %d\n",hlen); + + /* Header len, 0, TODO for security modes */ + + mrf24j40_setreg(dev->spi, addr++, hlen); + + /* Frame length */ + + mrf24j40_setreg(dev->spi, addr++, packet->len); + + /* Frame data */ + + for (ret = 0; ret < packet->len; ret++) /* this sets the correct val for ret */ + { + mrf24j40_setreg(dev->spi, addr++, packet->data[ret]); + } + + /* If the frame control field contains + * an acknowledgment request, set the TXNACKREQ bit. + * See IEEE 802.15.4/2003 7.2.1.1 page 112 for info. + */ + + reg = MRF24J40_TXNCON_TXNTRIG; + if (fc1 & IEEE802154_FC1_ACKREQ) + { + reg |= MRF24J40_TXNCON_TXNACKREQ; + } + + /* Trigger packet emission */ + + mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); + + /* Suspend calling thread until transmit is complete */ + + return sem_wait(&ieee->txsem); +} + +/**************************************************************************** + * Name: mrf24j40_irqwork_tx + * + * Description: + * Manage completion of packet transmission. + * + ****************************************************************************/ + +static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev) +{ + uint8_t reg,txstat; + + txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); + + /* 1 means it failed, we want 1 to mean it worked. + * tx_ok = !(tmp & ~(1 << TXNSTAT)); + * retries = tmp >> 6; + * channel_busy = (tmp & (1 << CCAFAIL)); + */ + + //dbg("TXSTAT%02X!\n", txstat); +#warning TODO report errors + + /* Disable tx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg |= MRF24J40_INTCON_TXNIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + + /* Wake up the thread that triggered the transmission */ + + sem_post(&dev->ieee.txsem); +} + +/**************************************************************************** + * Name: mrf24j40_enablerx + * + * Description: + * Enable reception of a packet. The interrupt will signal the rx semaphore. + * + ****************************************************************************/ + +static int mrf24j40_rxenable(FAR struct ieee802154_dev_s *ieee, bool state, + FAR struct ieee802154_packet_s *packet) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + uint8_t reg; + + if (state) + { + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + ieee->rxbuf = packet; + + /* Enable rx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + } + else + { + ieee->rxbuf = NULL; + } + + return OK; +} + +/**************************************************************************** + * Name: mrf24j40_irqwork_rx + * + * Description: + * Manage packet reception. + * + ****************************************************************************/ + +static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev) +{ + uint32_t addr; + uint32_t index; + uint8_t reg; + + /*dbg("!\n");*/ + + /* Disable rx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg |= MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + + /* Disable packet reception */ + + mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV); + + /* Read packet */ + + addr = 0x80000300; + dev->ieee.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); + /*dbg("len %3d\n", dev->ieee.rxbuf->len);*/ + + for (index = 0; index < dev->ieee.rxbuf->len; index++) + { + dev->ieee.rxbuf->data[index] = mrf24j40_getreg(dev->spi, addr++); + } + + dev->ieee.rxbuf->lqi = mrf24j40_getreg(dev->spi, addr++); + dev->ieee.rxbuf->rssi = mrf24j40_getreg(dev->spi, addr++); + + /* Reduce len by 2, we only receive frames with correct crc, no check required */ + + dev->ieee.rxbuf->len -= 2; + + /* Enable reception of next packet by flushing the fifo. + * This is an MRF24J40 errata (no. 1). + */ + + mrf24j40_setreg(dev->spi, MRF24J40_RXFLUSH, 1); + + /* Enable packet reception */ + + mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0); + + sem_post(&dev->ieee.rxsem); +} + +/**************************************************************************** + * Name: mrf24j40_irqworker + * + * Description: + * Perform interrupt handling logic outside of the interrupt handler (on + * the work queue thread). + * + * Parameters: + * arg - The reference to the driver structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void mrf24j40_irqworker(FAR void *arg) +{ + FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)arg; + uint8_t intstat; + + DEBUGASSERT(dev); + DEBUGASSERT(dev->spi); + + /* Read and store INTSTAT - this clears the register. */ + + intstat = mrf24j40_getreg(dev->spi, MRF24J40_INTSTAT); +// dbg("INT%02X\n", intstat); + + /* Do work according to the pending interrupts */ + + if ((intstat & MRF24J40_INTSTAT_RXIF)) + { + /* A packet was received, retrieve it */ + + mrf24j40_irqwork_rx(dev); + } + + if ((intstat & MRF24J40_INTSTAT_TXNIF)) + { + /* A packet was transmitted or failed*/ + + mrf24j40_irqwork_tx(dev); + } + + /* Re-Enable GPIO interrupts */ + + dev->lower->enable(dev->lower, TRUE); +} + +/**************************************************************************** + * Name: mrf24j40_interrupt + * + * Description: + * Hardware interrupt handler + * + * Parameters: + * irq - Number of the IRQ that generated the interrupt + * context - Interrupt register state save info (architecture-specific) + * + * Returned Value: + * OK on success + * + * Assumptions: + * + ****************************************************************************/ + +static int mrf24j40_interrupt(int irq, FAR void *context) +{ + /* To support multiple devices, + * retrieve the priv structure using the irq number + */ + + register FAR struct mrf24j40_dev_s *dev = &g_mrf24j40_devices[0]; + + /* In complex environments, we cannot do SPI transfers from the interrupt + * handler because semaphores are probably used to lock the SPI bus. In + * this case, we will defer processing to the worker thread. This is also + * much kinder in the use of system resources and is, therefore, probably + * a good thing to do in any event. + */ + + DEBUGASSERT(work_available(&dev->irqwork)); + + /* Notice that further GPIO interrupts are disabled until the work is + * actually performed. This is to prevent overrun of the worker thread. + * Interrupts are re-enabled in enc_irqworker() when the work is completed. + */ + + dev->lower->enable(dev->lower, FALSE); + return work_queue(HPWORK, &dev->irqwork, mrf24j40_irqworker, (FAR void *)dev, 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mrf24j40_init + * + * Description: + * Return an mrf24j40 device for use by other drivers. + * + ****************************************************************************/ + +FAR struct ieee802154_dev_s *mrf24j40_init(FAR struct spi_dev_s *spi, + FAR const struct mrf24j40_lower_s *lower) +{ + FAR struct mrf24j40_dev_s *dev; + struct ieee802154_cca_s cca; + +#if 0 + dev = kmm_zalloc(sizeof(struct mrf24j40_dev_s)); + + if (!dev) + { + return NULL; + } +#else + dev = &g_mrf24j40_devices[0]; +#endif + + /* Attach irq */ + + if (lower->attach(lower, mrf24j40_interrupt) != OK) + { +#if 0 + free(dev); +#endif + return NULL; + } + + dev->ieee.ops = &mrf24j40_devops; + sem_init(&dev->ieee.rxsem, 0, 0); + sem_init(&dev->ieee.txsem, 0, 0); + + dev->lower = lower; + dev->spi = spi; + + mrf24j40_initialize(dev); + + mrf24j40_setchannel(&dev->ieee, 11); + mrf24j40_setpanid (&dev->ieee, IEEE802154_PAN_DEFAULT); + mrf24j40_setsaddr (&dev->ieee, IEEE802154_SADDR_UNSPEC); + mrf24j40_seteaddr (&dev->ieee, IEEE802154_EADDR_UNSPEC); + + /* Default device params */ + + cca.use_ed = 1; + cca.use_cs = 0; + cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED threshold -69 dBm */ + mrf24j40_setcca(&dev->ieee, &cca); + + mrf24j40_setrxmode(dev, MRF24J40_RXMODE_NORMAL); + + mrf24j40_settxpower(&dev->ieee, 0); /*16. Set transmitter power .*/ + + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + + dev->lower->enable(dev->lower, TRUE); + + return &dev->ieee; +} diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h new file mode 100644 index 0000000000..de3131e4df --- /dev/null +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -0,0 +1,206 @@ +/**************************************************************************** + * drivers/wireless/ieee802154/mrf24j40.h + * + * Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __DRIVERS_IEEE802154_MRF24J40_H +#define __DRIVERS_IEEE802154_MRF24J40_H + +/* MRF24J40 Registers *******************************************************/ + +#define MRF24J40_RXMCR 0x00 +#define MRF24J40_PANIDL 0x01 +#define MRF24J40_PANIDH 0x02 +#define MRF24J40_SADRL 0x03 +#define MRF24J40_SADRH 0x04 +#define MRF24J40_EADR0 0x05 +#define MRF24J40_EADR1 0x06 +#define MRF24J40_EADR2 0x07 +#define MRF24J40_EADR3 0x08 +#define MRF24J40_EADR4 0x09 +#define MRF24J40_EADR5 0x0A +#define MRF24J40_EADR6 0x0B +#define MRF24J40_EADR7 0x0C +#define MRF24J40_RXFLUSH 0x0D +#define MRF24J40_ORDER 0x10 +#define MRF24J40_TXMCR 0x11 +#define MRF24J40_ACKTMOUT 0x12 +#define MRF24J40_ESLOTG1 0x13 +#define MRF24J40_SYMTICKL 0x14 +#define MRF24J40_SYMTICKH 0x15 +#define MRF24J40_PACON0 0x16 +#define MRF24J40_PACON1 0x17 +#define MRF24J40_PACON2 0x18 +#define MRF24J40_TXBCON0 0x1A +#define MRF24J40_TXNCON 0x1B +#define MRF24J40_TXG1CON 0x1C +#define MRF24J40_TXG2CON 0x1D +#define MRF24J40_ESLOTG23 0x1E +#define MRF24J40_ESLOTG45 0x1F +#define MRF24J40_ESLOTG67 0x20 +#define MRF24J40_TXPEND 0x21 +#define MRF24J40_WAKECON 0x22 +#define MRF24J40_FRMOFFSET 0x23 +#define MRF24J40_TXSTAT 0x24 +#define MRF24J40_TXBCON1 0x25 +#define MRF24J40_GATECLK 0x26 +#define MRF24J40_TXTIME 0x27 +#define MRF24J40_HSYMTMRL 0x28 +#define MRF24J40_HSYMTMRH 0x29 +#define MRF24J40_SOFTRST 0x2A +#define MRF24J40_SECCON0 0x2C +#define MRF24J40_SECCON1 0x2C +#define MRF24J40_TXSTBL 0x2E +#define MRF24J40_RXSR 0x30 +#define MRF24J40_INTSTAT 0x31 +#define MRF24J40_INTCON 0x32 +#define MRF24J40_GPIO 0x33 +#define MRF24J40_TRISGPIO 0x34 +#define MRF24J40_SLPACK 0x35 +#define MRF24J40_RFCTL 0x36 +#define MRF24J40_SECCR2 0x37 +#define MRF24J40_BBREG0 0x38 +#define MRF24J40_BBREG1 0x39 +#define MRF24J40_BBREG2 0x3A +#define MRF24J40_BBREG3 0x3B +#define MRF24J40_BBREG4 0x3C +#define MRF24J40_BBREG6 0x3E +#define MRF24J40_CCAEDTH 0x3F + +#define MRF24J40_RFCON0 0x80000200 +#define MRF24J40_RFCON1 0x80000201 +#define MRF24J40_RFCON2 0x80000202 +#define MRF24J40_RFCON3 0x80000203 +#define MRF24J40_RFCON5 0x80000205 +#define MRF24J40_RFCON6 0x80000206 +#define MRF24J40_RFCON7 0x80000207 +#define MRF24J40_RFCON8 0x80000208 +#define MRF24J40_SLPCAL0 0x80000209 +#define MRF24J40_SLPCAL1 0x8000020A +#define MRF24J40_SLPCAL2 0x8000020B +#define MRF24J40_RFSTATE 0x8000020F +#define MRF24J40_RSSI 0x80000210 +#define MRF24J40_SLPCON0 0x80000211 +#define MRF24J40_SLPCON1 0x80000220 +#define MRF24J40_WAKETIMEL 0x80000222 +#define MRF24J40_WAKETIMEH 0x80000223 +#define MRF24J40_REMCNTL 0x80000224 +#define MRF24J40_REMCNTH 0x80000225 +#define MRF24J40_MAINCNT0 0x80000226 +#define MRF24J40_MAINCNT1 0x80000227 +#define MRF24J40_MAINCNT2 0x80000228 +#define MRF24J40_MAINCNT3 0x80000229 +#define MRF24J40_TESTMODE 0x8000022F +#define MRF24J40_ASSOEADR0 0x80000230 +#define MRF24J40_ASSOEADR1 0x80000231 +#define MRF24J40_ASSOEADR2 0x80000232 +#define MRF24J40_ASSOEADR3 0x80000233 +#define MRF24J40_ASSOEADR4 0x80000234 +#define MRF24J40_ASSOEADR5 0x80000235 +#define MRF24J40_ASSOEADR6 0x80000236 +#define MRF24J40_ASSOEADR7 0x80000237 +#define MRF24J40_ASSOSADR0 0x80000238 +#define MRF24J40_ASSOSADR1 0x80000239 +#define MRF24J40_UPNONCE0 0x80000240 +#define MRF24J40_UPNONCE1 0x80000241 +#define MRF24J40_UPNONCE2 0x80000242 +#define MRF24J40_UPNONCE3 0x80000243 +#define MRF24J40_UPNONCE4 0x80000244 +#define MRF24J40_UPNONCE5 0x80000245 +#define MRF24J40_UPNONCE6 0x80000246 +#define MRF24J40_UPNONCE7 0x80000247 +#define MRF24J40_UPNONCE8 0x80000248 +#define MRF24J40_UPNONCE9 0x80000249 +#define MRF24J40_UPNONCE10 0x8000024A +#define MRF24J40_UPNONCE11 0x8000024B +#define MRF24J40_UPNONCE12 0x8000024C + +/* INTSTAT bits */ + +#define MRF24J40_INTSTAT_SLPIF 0x80 +#define MRF24J40_INTSTAT_WAKEIF 0x40 +#define MRF24J40_INTSTAT_HSYMTMRIF 0x20 +#define MRF24J40_INTSTAT_SECIF 0x10 +#define MRF24J40_INTSTAT_RXIF 0x08 +#define MRF24J40_INTSTAT_TXG2IF 0x04 +#define MRF24J40_INTSTAT_TXG1IF 0x02 +#define MRF24J40_INTSTAT_TXNIF 0x01 + +/* RXMCR bits */ + +#define MRF24J40_RXMCR_PROMI 0x01 /* Enable promisc mode (rx all valid packets) */ +#define MRF24J40_RXMCR_ERRPKT 0x02 /* Do not check CRC */ +#define MRF24J40_RXMCR_COORD 0x04 /* Enable coordinator mode ??? DIFFERENCE ??? - not used in datasheet! */ +#define MRF24J40_RXMCR_PANCOORD 0x08 /* Enable PAN coordinator mode ??? DIFFERENCE ??? */ +#define MRF24J40_RXMCR_NOACKRSP 0x20 /* Enable auto ACK when a packet is rxed */ + +/* TXMCR bits */ + +#define MRF24J40_TXMCR_CSMABF0 0x01 +#define MRF24J40_TXMCR_CSMABF1 0x02 +#define MRF24J40_TXMCR_CSMABF2 0x04 +#define MRF24J40_TXMCR_MACMINBE0 0x08 +#define MRF24J40_TXMCR_MACMINBE1 0x10 +#define MRF24J40_TXMCR_SLOTTED 0x20 +#define MRF24J40_TXMCR_BATLIFEXT 0x40 +#define MRF24J40_TXMCR_NOCSMA 0x80 + +/* INTCON bits */ + +#define MRF24J40_INTCON_SLPIE 0x80 +#define MRF24J40_INTCON_WAKEIE 0x40 +#define MRF24J40_INTCON_HSYMTMRIE 0x20 +#define MRF24J40_INTCON_SECIE 0x10 +#define MRF24J40_INTCON_RXIE 0x08 +#define MRF24J40_INTCON_TXG2IE 0x04 +#define MRF24J40_INTCON_TXG1IE 0x02 +#define MRF24J40_INTCON_TXNIE 0x01 + +/* BBREG1 bits */ + +#define MRF24J40_BBREG1_RXDECINV 0x04 /* Enable/Disable packet reception */ + +/* BBREG2 bits */ + +#define MRF24J40_BBREG2_CCAMODE_ED 0x80 +#define MRF24J40_BBREG2_CCAMODE_CS 0x40 + +/* TXNCON bits */ + +#define MRF24J40_TXNCON_TXNTRIG 0x01 /* Trigger packet tx, automatically cleared */ +#define MRF24J40_TXNCON_TXNSECEN 0x02 /* Enable security */ +#define MRF24J40_TXNCON_TXNACKREQ 0x04 /* An ACK is requested for this pkt */ +#define MRF24J40_TXNCON_INDIRECT 0x08 /* Activate indirect tx bit (for coordinators) */ +#define MRF24J40_TXNCON_FPSTAT 0x10 /* Status of the frame pending big in txed acks */ + +#endif /* __DRIVERS_IEEE802154_MRF24J40_H */ diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 498fb294e4..5daacd3005 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -402,6 +402,7 @@ enum spi_dev_e SPIDEV_ACCELEROMETER, /* Select SPI Accelerometer device */ SPIDEV_BAROMETER, /* Select SPI Pressure/Barometer device */ SPIDEV_TEMPERATURE, /* Select SPI Temperature sensor device */ + SPIDEV_IEEE802154, /* Select SPI IEEE 802.15.4 wireless device */ SPIDEV_USER /* Board-specific values start here */ }; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h new file mode 100644 index 0000000000..c3439feb89 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -0,0 +1,224 @@ +/**************************************************************************** + * include/nuttx/wireless/ieee802154/ieee802154_radio.h + * + * Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* None at the moment */ + +/* IEEE 802.15.4 MAC Interface **********************************************/ + +/* Frame control field masks, 2 bytes + * Seee IEEE 802.15.4/2003 7.2.1.1 page 112 + */ + +#define IEEE802154_FC1_FTYPE 0x03 /* Frame type, bits 0-2 */ +#define IEEE802154_FC1_SEC 0x08 /* Security Enabled, bit 3 */ +#define IEEE802154_FC1_PEND 0x10 /* Frame pending, bit 4 */ +#define IEEE802154_FC1_ACKREQ 0x20 /* Acknowledge request, bit 5 */ +#define IEEE802154_FC1_INTRA 0x40 /* Intra PAN, bit 6 */ +#define IEEE802154_FC2_DADDR 0x0C /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FC2_VERSION 0x30 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FC2_SADDR 0xC0 /* Source addressing mode, bits 14-15 */ + +/* Frame Type */ + +#define IEEE802154_FRAME_BEACON 0x00 +#define IEEE802154_FRAME_DATA 0x01 +#define IEEE802154_FRAME_ACK 0x02 +#define IEEE802154_FRAME_COMMAND 0x03 + +/* Security Enabled */ + +#define IEEE802154_SEC_OFF 0x00 +#define IEEE802154_SEC_ON 0x08 + +/* Flags */ + +#define IEEE802154_PEND 0x10 +#define IEEE802154_ACK_REQ 0x20 +#define IEEE802154_INTRA 0x40 + +/* Dest Addressing modes */ + +#define IEEE802154_DADDR_NONE 0x00 +#define IEEE802154_DADDR_SHORT 0x08 +#define IEEE802154_DADDR_EXT 0x0A + +/* Src Addressing modes */ + +#define IEEE802154_SADDR_NONE 0x00 +#define IEEE802154_SADDR_SHORT 0x80 +#define IEEE802154_SADDR_EXT 0xA0 + +/* Some addresses */ + +#define IEEE802154_PAN_DEFAULT (uint16_t)0xFFFF +#define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF +#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE +#define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" + +#define IEEE802154_CMD_ASSOC_REQ 0x01 +#define IEEE802154_CMD_ASSOC_RSP 0x02 +#define IEEE802154_CMD_DIS_NOT 0x03 +#define IEEE802154_CMD_DATA_REQ 0x04 +#define IEEE802154_CMD_PANID_CONF_NOT 0x05 +#define IEEE802154_CMD_ORPHAN_NOT 0x06 +#define IEEE802154_CMD_BEACON_REQ 0x07 +#define IEEE802154_CMD_COORD_REALIGN 0x08 +#define IEEE802154_CMD_GTS_REQ 0x09 + +/* Device modes */ + +#define IEEE802154_MODE_DEVICE 0x00 +#define IEEE802154_MODE_COORD 0x01 /* avail in mrf24j40, but why? */ +#define IEEE802154_MODE_PANCOORD 0x02 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ieee802154_packet_s +{ + uint8_t len; + uint8_t data[127]; + uint8_t lqi; + uint8_t rssi; +}; + +struct ieee802154_cca_s +{ + uint8_t use_ed : 1; /* CCA using ED */ + uint8_t use_cs : 1; /* CCA using carrier sense */ + uint8_t edth; /* Energy detection threshold for CCA */ + uint8_t csth; /* Carrier sense threshold for CCA */ +}; + +struct ieee802154_dev_s; + +struct ieee802154_devops_s +{ + CODE int (*setchannel)(FAR struct ieee802154_dev_s *dev, uint8_t channel); + CODE int (*getchannel)(FAR struct ieee802154_dev_s *dev, + FAR uint8_t *channel); + + CODE int (*setpanid)(FAR struct ieee802154_dev_s *dev, uint16_t panid); + CODE int (*getpanid)(FAR struct ieee802154_dev_s *dev, + FAR uint16_t *panid); + + CODE int (*setsaddr)(FAR struct ieee802154_dev_s *dev, uint16_t saddr); + CODE int (*getsaddr)(FAR struct ieee802154_dev_s *dev, + FAR uint16_t *saddr); + + CODE int (*seteaddr)(FAR struct ieee802154_dev_s *dev, + FAR uint8_t *laddr); + CODE int (*geteaddr)(FAR struct ieee802154_dev_s *dev, + FAR uint8_t *laddr); + + CODE int (*setpromisc)(FAR struct ieee802154_dev_s *dev, bool promisc); + CODE int (*getpromisc)(FAR struct ieee802154_dev_s *dev, + FAR bool *promisc); + + CODE int (*setdevmode)(FAR struct ieee802154_dev_s *dev, uint8_t devmode); + CODE int (*getdevmode)(FAR struct ieee802154_dev_s *dev, + FAR uint8_t *devmode); + + CODE int (*settxpower)(FAR struct ieee802154_dev_s *dev, + int32_t txpwr); /* unit = 1 mBm = 1/100 dBm */ + CODE int (*gettxpower)(FAR struct ieee802154_dev_s *dev, + FAR int32_t *txpwr); + + CODE int (*setcca)(FAR struct ieee802154_dev_s *dev, + FAR struct ieee802154_cca_s *cca); + CODE int (*getcca)(FAR struct ieee802154_dev_s *dev, + FAR struct ieee802154_cca_s *cca); + + CODE int (*ioctl)(FAR struct ieee802154_dev_s *ieee, int cmd, + unsigned long arg); + CODE int (*energydetect)(FAR struct ieee802154_dev_s *dev, + FAR uint8_t *energy); + CODE int (*rxenable)(FAR struct ieee802154_dev_s *dev, bool state, + FAR struct ieee802154_packet_s *packet); + CODE int (*transmit)(FAR struct ieee802154_dev_s *dev, + FAR struct ieee802154_packet_s *packet); + + /*TODO beacon/sf order*/ +}; + +struct ieee802154_dev_s +{ + FAR const struct ieee802154_devops_s *ops; + + /* Packet reception management */ + + struct ieee802154_packet_s *rxbuf; + sem_t rxsem; + + /* Packet transmission management */ + + sem_t txsem; +}; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H */ diff --git a/include/nuttx/wireless/ieee802154/mrf24j40.h b/include/nuttx/wireless/ieee802154/mrf24j40.h new file mode 100644 index 0000000000..2c78faee01 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/mrf24j40.h @@ -0,0 +1,111 @@ +/**************************************************************************** + * include/nuttx/wireless/ieee802154/mrf24j40.h + * + * Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H + +/**************************************************************************** + * Included files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* The MRF24J40 provides interrupts to the MCU via a GPIO pin. The + * following structure provides an MCU-independent mechanism for controlling + * the MRF24J40 GPIO interrupt. + * + * The MRF24J40 interrupt is an active low, *level* interrupt. From Datasheet: + * "Note 1: The INTEDGE polarity defaults to: + * 0 = Falling Edge. Ensure that the inter- + * rupt polarity matches the interrupt pin + * polarity of the host microcontroller. + * Note 2: The INT pin will remain high or low, + * depending on INTEDGE polarity setting, + * until INTSTAT register is read." + */ + +struct mrf24j40_lower_s +{ + int (*attach)(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler); + void (*enable)(FAR const struct mrf24j40_lower_s *lower, int state); +}; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Function: mrf24j40_init + * + * Description: + * Initialize the IEEE802.15.4 driver. The MRF24J40 device is assumed to be + * in the post-reset state upon entry to this function. + * + * Parameters: + * spi - A reference to the platform's SPI driver for the MRF24J40 + * lower - The MCU-specific interrupt used to control low-level MCU + * functions (i.e., MRF24J40 GPIO interrupts). + * devno - If more than one MRF24J40 is supported, then this is the + * zero based number that identifies the MRF24J40; + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +struct spi_dev_s; /* Forward reference */ +FAR struct ieee802154_dev_s *mrf24j40_init(FAR struct spi_dev_s *spi, + FAR const struct mrf24j40_lower_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H */ -- GitLab From fdddebbffdc2672a9faff94351af0f3ed253103d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 27 Feb 2016 07:26:20 -0600 Subject: [PATCH 812/858] net/: Finish IEEE802154->6LOWPAN renaming; remove PF_IEEE804154; Move 6LoWPAN menu to inside Internet Protocol Menu --- include/nuttx/net/net.h | 2 +- .../nuttx/wireless/ieee802154/ieee802154.h | 6 ++-- include/sys/socket.h | 3 +- net/6lowpan/6lowpan.h | 10 +++---- net/6lowpan/Kconfig | 28 ++++++++----------- net/6lowpan/Make.defs | 4 +-- net/Kconfig | 5 ++-- net/netdev/netdev_register.c | 24 ++++++++-------- 8 files changed, 38 insertions(+), 44 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 45c84811ee..a11c8bcd2e 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -79,7 +79,7 @@ enum net_lltype_e NET_LL_LOOPBACK, /* Local loopback */ NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ NET_LL_TUN, /* TUN Virtual Network Device */ - NET_LL_IEEE802154 /* IEEE 802.15.4 */ + NET_LL_6LOWPAN /* IEEE 802.15.4 6LoWPAN*/ }; /* This defines a bitmap big enough for one bit for each socket option */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h index 250a81bf00..0211940414 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154.h +++ b/include/nuttx/wireless/ieee802154/ieee802154.h @@ -36,8 +36,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_NET_IEEE802154_H -#define __INCLUDE_NUTTX_NET_IEEE802154_H +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H /**************************************************************************** * Included Files @@ -59,4 +59,4 @@ * Public Function Prototypes ****************************************************************************/ -#endif /* __INCLUDE_NUTTX_NET_IEEE802154_H */ +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H */ diff --git a/include/sys/socket.h b/include/sys/socket.h index 7276fe2700..0f9f10f4d1 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/socket.h * - * Copyright (C) 2007, 2009, 2011, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -64,7 +64,6 @@ #define PF_ATMPVC 8 /* Access to raw ATM PVCs */ #define PF_APPLETALK 9 /* Appletalk */ #define PF_PACKET 10 /* Low level packet interface */ -#define PF_IEEE802154 11 /* IEEE 802.15.4 sockets */ /* Address families */ diff --git a/net/6lowpan/6lowpan.h b/net/6lowpan/6lowpan.h index cb5a54eb34..657b04c75b 100644 --- a/net/6lowpan/6lowpan.h +++ b/net/6lowpan/6lowpan.h @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __NET_IEEE802_15_4_IEEE802154_H -#define __NET_IEEE802_15_4_IEEE802154_H +#ifndef __NET_6LOWPAN_6LOWPAN_H +#define __NET_6LOWPAN_6LOWPAN_H /**************************************************************************** * Included Files @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_NET_IEEE802154 +#ifdef CONFIG_NET_6LOWPAN /**************************************************************************** * Public Types @@ -52,5 +52,5 @@ * Public Function Prototypes ****************************************************************************/ -#endif /* CONFIG_NET_IEEE802154 */ -#endif /* __NET_IEEE802_15_4_IEEE802154_H */ +#endif /* CONFIG_NET_6LOWPAN */ +#endif /* __NET_6LOWPAN_6LOWPAN_H */ diff --git a/net/6lowpan/Kconfig b/net/6lowpan/Kconfig index a96521a49b..e72e42268b 100644 --- a/net/6lowpan/Kconfig +++ b/net/6lowpan/Kconfig @@ -3,36 +3,31 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -menu "IEEE 802.15.4 Configuration" - -config NET_IEEE802154 - bool "IEEE 802.15.4 support" +menuconfig NET_6LOWPAN + bool "IEEE 802.15.4 6LoWPAN support" default n depends on EXPERIMENTAL && NET_IPv6 ---help--- - Enable IEEE 802.15.4 protocol socket support + Enable support for IEEE 802.15.4 Low power Wireless Personal Area + Networking (6LoWPAN). -if NET_IEEE802154 +if NET_6LOWPAN -config NET_IEEE802154_MTU - int "IEEE 802.15.4 packet buffer size (MTU)" +config NET_6LOWPAN_MTU + int "6LoWPAN packet buffer size (MTU)" default 1294 range 590 1518 ---help--- Packet buffer size. This size includes the TCP/UDP payload plus the - size of TCP/UDP header, the IP header, and the IEEE 802.15.4 header. + size of TCP/UDP header, the IP header, and data link layer headers. This value is normally referred to as the MTU (Maximum Transmission Unit); the payload is the MSS (Maximum Segment Size). - IPv4 hosts are required to be able to handle an MSS of at least - 536 octets, resulting in a minimum buffer size of 536+20+20+xx = - xx. REVISIT! - IPv6 hosts are required to be able to handle an MSS of 1220 octets, resulting in a minimum buffer size of of 1220+20+40+xx = xx. REVISIT! -config IEEE802154_TCP_RECVWNDO - int "IEEE 802.15.4 TCP receive window size" +config NET_6LOWPAN_TCP_RECVWNDO + int "6LoWPAN TCP receive window size" default 1220 depends on NET_TCP ---help--- @@ -41,5 +36,4 @@ config IEEE802154_TCP_RECVWNDO incoming data, or high (32768 bytes) if the application processes data quickly. REVISIT! -endif # NET_IEEE802154 -endmenu # IEEE 802.15.4 Configuration +endif # NET_6LOWPAN diff --git a/net/6lowpan/Make.defs b/net/6lowpan/Make.defs index e04fd7a17c..e52060673a 100644 --- a/net/6lowpan/Make.defs +++ b/net/6lowpan/Make.defs @@ -35,7 +35,7 @@ # IEEE 802.15.4 support -ifeq ($(CONFIG_NET_IEEE802154),y) +ifeq ($(CONFIG_NET_6LOWPAN),y) # Include IEEE 802.15.4 file in the build @@ -46,4 +46,4 @@ ifeq ($(CONFIG_NET_IEEE802154),y) DEPPATH += --dep-path 6lowpan VPATH += :6lowpan -endif # CONFIG_NET_IEEE802154 +endif # CONFIG_NET_6LOWPAN diff --git a/net/Kconfig b/net/Kconfig index ca36d66e16..a69a42e3d1 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -255,13 +255,15 @@ config NET_IPv4 ---help--- Build in support for IPv4. -config NET_IPv6 +menuconfig NET_IPv6 bool "IPv6" default n ---help--- Build in support for IPv6. source "net/neighbor/Kconfig" +source "net/6lowpan/Kconfig" + endmenu # Internet Protocol Selection source "net/socket/Kconfig" @@ -269,7 +271,6 @@ source "net/pkt/Kconfig" source "net/local/Kconfig" source "net/tcp/Kconfig" source "net/udp/Kconfig" -source "net/6lowpan/Kconfig" source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" source "net/igmp/Kconfig" diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index e1228de7b1..11982d9eeb 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -61,18 +61,18 @@ * Pre-processor Definitions ****************************************************************************/ -#define NETDEV_ETH_FORMAT "eth%d" -#define NETDEV_LO_FORMAT "lo" -#define NETDEV_IEEE802154_FORMAT "wpan%d" -#define NETDEV_SLIP_FORMAT "sl%d" -#define NETDEV_TUN_FORMAT "tun%d" +#define NETDEV_ETH_FORMAT "eth%d" +#define NETDEV_LO_FORMAT "lo" +#define NETDEV_WPAN_FORMAT "wpan%d" +#define NETDEV_SLIP_FORMAT "sl%d" +#define NETDEV_TUN_FORMAT "tun%d" #if defined(CONFIG_NET_SLIP) # define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT #elif defined(CONFIG_NET_ETHERNET) # define NETDEV_DEFAULT_FORMAT NETDEV_ETH_FORMAT -#elif defined(CONFIG_NET_IEEE802154) -# define NETDEV_DEFAULT_FORMAT NETDEV_IEEE802154_FORMAT +#elif defined(CONFIG_NET_6LOWPAN) +# define NETDEV_DEFAULT_FORMAT NETDEV_WPAN_FORMAT #else /* if defined(CONFIG_NET_LOOPBACK) */ # define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT #endif @@ -214,14 +214,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) break; #endif -#ifdef CONFIG_NET_IEEE802154 - case NET_LL_IEEE802154: /* IEEE 802.15.4 */ +#ifdef CONFIG_NET_6LOWPAN + case NET_LL_6LOWPAN: /* IEEE 802.15.4 */ dev->d_llhdrlen = 0; /* REVISIT */ - dev->d_mtu = CONFIG_NET_IEEE802154_MTU; + dev->d_mtu = CONFIG_NET_6LOWPAN_MTU; #ifdef CONFIG_NET_TCP - dev->d_recvwndo = CONFIG_NET_IEEE802154_TCP_RECVWNDO; + dev->d_recvwndo = CONFIG_NET_6LOWPAN_TCP_RECVWNDO; #endif - devfmt = NETDEV_IEEE802154_FORMAT; + devfmt = NETDEV_WPAN_FORMAT; break; #endif -- GitLab From d777110cbe9ff8c36079c4b5b0e4a9bc8948d788 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 27 Feb 2016 07:27:45 -0600 Subject: [PATCH 813/858] Eliminate a warning --- drivers/wireless/ieee802154/mrf24j40.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 3d18362c45..8648325307 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1118,7 +1118,8 @@ static int mrf24j40_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee8 static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev) { - uint8_t reg,txstat; + uint8_t txstat; + uint8_t reg; txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); @@ -1130,6 +1131,7 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev) //dbg("TXSTAT%02X!\n", txstat); #warning TODO report errors + UNUSED(txstat); /* Disable tx int */ -- GitLab From 3c5cd966465258d56006a44ad634d66df986345f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 27 Feb 2016 07:59:26 -0600 Subject: [PATCH 814/858] Remove definitions for unsupported protocol families and address families --- include/sys/socket.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index 0f9f10f4d1..355d1c0d32 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -52,18 +52,12 @@ /* Protocol families */ -#define PF_UNSPEC 0 /* Protocol family unspecified */ -#define PF_UNIX 1 /* Local communication */ -#define PF_LOCAL 1 /* Local communication */ -#define PF_INET 2 /* IPv4 Internet protocols */ -#define PF_INET6 3 /* IPv6 Internet protocols */ -#define PF_IPX 4 /* IPX - Novell protocols */ -#define PF_NETLINK 5 /* Kernel user interface device */ -#define PF_X25 6 /* ITU-T X.25 / ISO-8208 protocol */ -#define PF_AX25 7 /* Amateur radio AX.25 protocol */ -#define PF_ATMPVC 8 /* Access to raw ATM PVCs */ -#define PF_APPLETALK 9 /* Appletalk */ -#define PF_PACKET 10 /* Low level packet interface */ +#define PF_UNSPEC 0 /* Protocol family unspecified */ +#define PF_UNIX 1 /* Local communication */ +#define PF_LOCAL 1 /* Local communication */ +#define PF_INET 2 /* IPv4 Internet protocols */ +#define PF_INET6 3 /* IPv6 Internet protocols */ +#define PF_PACKET 4 /* Low level packet interface */ /* Address families */ @@ -72,12 +66,6 @@ #define AF_LOCAL PF_LOCAL #define AF_INET PF_INET #define AF_INET6 PF_INET6 -#define AF_IPX PF_IPX -#define AF_NETLINK PF_NETLINK -#define AF_X25 PF_X25 -#define AF_AX25 PF_AX25 -#define AF_ATMPVC PF_ATMPVC -#define AF_APPLETALK PF_APPLETALK #define AF_PACKET PF_PACKET /* The socket created by socket() has the indicated type, which specifies -- GitLab From 300edb9b0f98fb3aedf6213448fdd7da5930c89a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 27 Feb 2016 10:37:42 -0600 Subject: [PATCH 815/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- configs | 2 +- include/sys/socket.h | 8 +++++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf3391ce9e..67caa82148 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11529,4 +11529,6 @@ yet (2016-02-26). * include/nuttx/wireless/ieee802154: Add directory (and dummy header file) (2016-02-16). + * arch/arm/include and src: Rename the imx directories to imx1 to make room + in the namespace for other members of the i.MX family (2016-02-27). diff --git a/arch b/arch index 1fb2ed39e0..5358eb144d 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 1fb2ed39e08f3ec82e68a16a1bc63dc9e0e6e6d2 +Subproject commit 5358eb144d554cbc1fb95bbdadc2a96acd34a8e3 diff --git a/configs b/configs index bdb92a1d64..dd60f41b7e 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bdb92a1d64163ff9a7eb8fe842cf304a553c0f94 +Subproject commit dd60f41b7e7539f4b0aa51a61f4a23713817c270 diff --git a/include/sys/socket.h b/include/sys/socket.h index 355d1c0d32..1d88cb73ab 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/socket.h * - * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,7 +50,7 @@ * the protocol family which will be used for communication. */ -/* Protocol families */ +/* Supported Protocol Families */ #define PF_UNSPEC 0 /* Protocol family unspecified */ #define PF_UNIX 1 /* Local communication */ @@ -59,7 +59,9 @@ #define PF_INET6 3 /* IPv6 Internet protocols */ #define PF_PACKET 4 /* Low level packet interface */ -/* Address families */ +/* Supported Address Families. Opengroup.org requires only AF_UNSPEC, + * AF_UNIX, AF_INET and AF_INET6. + */ #define AF_UNSPEC PF_UNSPEC #define AF_UNIX PF_UNIX -- GitLab From 0970d43ab847001ae27f7de0400a26a7e7d4517f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 28 Feb 2016 07:48:16 -0600 Subject: [PATCH 816/858] Cosmetic changes to comments --- drivers/wireless/ieee802154/mrf24j40.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 8648325307..fa7cfd815d 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -59,9 +59,9 @@ #include "mrf24j40.h" -/************************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************************/ + ****************************************************************************/ #ifndef CONFIG_SCHED_HPWORK #error High priority work queue required in this driver @@ -75,6 +75,10 @@ # define CONFIG_IEEE802154_MRF24J40_FREQUENCY 8000000 #endif +#ifndef CONFIG_SPI_EXCHANGE +# error CONFIG_SPI_EXCHANGE required for this driver +#endif + /* Definitions for the device structure */ #define MRF24J40_RXMODE_NORMAL 0 @@ -87,9 +91,9 @@ #define MRF24J40_PA_ED 2 #define MRF24J40_PA_SLEEP 3 -/************************************************************************************ +/**************************************************************************** * Private Types - ************************************************************************************/ + ****************************************************************************/ /* A MRF24J40 device instance */ @@ -185,10 +189,6 @@ static const struct ieee802154_devops_s mrf24j40_devops = * Private Functions ****************************************************************************/ -#ifndef CONFIG_SPI_EXCHANGE -#error CONFIG_SPI_EXCHANGE required for this driver -#endif - /* Hardware access routines */ /**************************************************************************** @@ -232,6 +232,7 @@ static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t va { uint8_t buf[3]; int len; + if (!(addr&0x80000000)) { addr &= 0x3F; /* 6-bit address */ @@ -249,6 +250,7 @@ static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t va buf[1] = (addr & 0xFF); len = 2; } + buf[len++] = val; mrf24j40_lock(spi); -- GitLab From 4ad08a2d856e8d0c367b3d37f792ffe5425fb330 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 28 Feb 2016 14:17:39 -0600 Subject: [PATCH 817/858] Update ChangeLog --- ChangeLog | 4 ++++ arch | 2 +- configs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67caa82148..614504ce94 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11531,4 +11531,8 @@ (2016-02-16). * arch/arm/include and src: Rename the imx directories to imx1 to make room in the namespace for other members of the i.MX family (2016-02-27). + * arch/arm/include/imx6 and src/imx6: Evolving support for the NXP/Freescale + i.MX6Q (2016-02-28). + * configs/sabre-6quad: Placeholder that will eventually become board support + for the NXP/Freescale Sabre 6Quad board (2016-02-28). diff --git a/arch b/arch index 5358eb144d..809f7556a1 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5358eb144d554cbc1fb95bbdadc2a96acd34a8e3 +Subproject commit 809f7556a1bb01d8a3a501556387e364060d1ccd diff --git a/configs b/configs index dd60f41b7e..1056c41b05 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dd60f41b7e7539f4b0aa51a61f4a23713817c270 +Subproject commit 1056c41b050013d40d04942206653c984131bee2 -- GitLab From 4e5b80f4a6e56e79bb3cf0c4179b98eef1f2b065 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 28 Feb 2016 15:32:58 -0600 Subject: [PATCH 818/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 809f7556a1..79348c426f 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 809f7556a1bb01d8a3a501556387e364060d1ccd +Subproject commit 79348c426f9fd0215581c2e09f3cd9e0139cd628 diff --git a/configs b/configs index 1056c41b05..4f08ee120a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 1056c41b050013d40d04942206653c984131bee2 +Subproject commit 4f08ee120a35a252eca99507adea072ee0d5a584 -- GitLab From c02ede8fa0f7f40817c0a2e4eb71dae16e23f94b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 29 Feb 2016 13:18:42 -0600 Subject: [PATCH 819/858] Update README --- Documentation | 2 +- README.txt | 2 ++ arch | 2 +- configs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index ae853e5f4f..a671bbd607 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit ae853e5f4f26a3e91f715c9a4d35fe223b2e49a1 +Subproject commit a671bbd607e6b2e57b017b440286da99f57121d1 diff --git a/README.txt b/README.txt index aa93873503..d7f07482f6 100644 --- a/README.txt +++ b/README.txt @@ -1388,6 +1388,8 @@ nuttx/ | | `- README.txt | |- rgmp/ | | `- README.txt + | |- sabre-6quad/ + | | `- README.txt | |- sama5d2-xult/ | | `- README.txt | |- sama5d3x-ek/ diff --git a/arch b/arch index 79348c426f..ffca215af3 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 79348c426f9fd0215581c2e09f3cd9e0139cd628 +Subproject commit ffca215af34599e5e8ec8a29842d319c156e9ad8 diff --git a/configs b/configs index 4f08ee120a..6a5befdf8b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 4f08ee120a35a252eca99507adea072ee0d5a584 +Subproject commit 6a5befdf8bf12061dfec74061139ba9946b562dd -- GitLab From 480eab8423111eecdd8ea6e0665ff36ceed8487b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Mar 2016 12:59:12 -0600 Subject: [PATCH 820/858] Update ChangeLog --- ChangeLog | 3 ++- arch | 2 +- configs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 614504ce94..13184a8589 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11535,4 +11535,5 @@ i.MX6Q (2016-02-28). * configs/sabre-6quad: Placeholder that will eventually become board support for the NXP/Freescale Sabre 6Quad board (2016-02-28). - + * arch/arm/src/stm32: Support for STM32F46xx from Paul Alexander Patience + (2016-03-01). diff --git a/arch b/arch index ffca215af3..98e7054a2a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ffca215af34599e5e8ec8a29842d319c156e9ad8 +Subproject commit 98e7054a2a6b18c3a528cfa68e00b5fbfb77cd32 diff --git a/configs b/configs index 6a5befdf8b..868bee3a20 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6a5befdf8bf12061dfec74061139ba9946b562dd +Subproject commit 868bee3a201ac789e7b615b8080aa5113da592fa -- GitLab From 8899cef78e1177ce22c99a193a3bf6b1b0fa06b6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 1 Mar 2016 14:19:06 -0600 Subject: [PATCH 821/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 98e7054a2a..7fe684d488 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 98e7054a2a6b18c3a528cfa68e00b5fbfb77cd32 +Subproject commit 7fe684d488ea88c31b2a155690de8beb7345f913 diff --git a/configs b/configs index 868bee3a20..bc95bb361c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 868bee3a201ac789e7b615b8080aa5113da592fa +Subproject commit bc95bb361c0963b69782cc77cec251d047eadb0d -- GitLab From 5d63cd85c73328e181106337c7a57bb17e95474b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Mar 2016 07:33:24 -0600 Subject: [PATCH 822/858] sched/semaphore: Add an internal interface to reset a semaphore count. --- ChangeLog | 5 +- arch | 2 +- configs | 2 +- include/nuttx/semaphore.h | 18 ++++++ sched/semaphore/Make.defs | 4 +- sched/semaphore/sem_reset.c | 121 ++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 sched/semaphore/sem_reset.c diff --git a/ChangeLog b/ChangeLog index 13184a8589..4db1c92df0 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11536,4 +11536,7 @@ * configs/sabre-6quad: Placeholder that will eventually become board support for the NXP/Freescale Sabre 6Quad board (2016-02-28). * arch/arm/src/stm32: Support for STM32F46xx from Paul Alexander Patience - (2016-03-01). + * sched/semaphore/sem_reset.c and include/nuttx/semaphore.h: Add an internal, + non-standard interface to reset a semaphore count. This is sometimes + needed by drivers in order to recover from error conditions (2016-03-05) + diff --git a/arch b/arch index 7fe684d488..0b8fe68bf5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7fe684d488ea88c31b2a155690de8beb7345f913 +Subproject commit 0b8fe68bf5c15b49d7877c97516fdda542b2149b diff --git a/configs b/configs index bc95bb361c..0c764446fe 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit bc95bb361c0963b69782cc77cec251d047eadb0d +Subproject commit 0c764446fee7b6b4c6bb9c188042fb98b4d1e8eb diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 691e2f9624..bdb5cfb27f 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -113,6 +113,24 @@ extern "C" int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay); +/**************************************************************************** + * Name: sem_reset + * + * Description: + * Reset a semaphore to a specific value. This kind of operation is + * sometimes required for certain error handling conditions. + * + * Parameters: + * sem - Semaphore descriptor to be reset + * count - The requested semaphore count + * + * Return Value: + * 0 (OK) or a negated errno value if unsuccessful + * + ****************************************************************************/ + +int sem_reset(FAR sem_t *sem, int16_t count); + #undef EXTERN #ifdef __cplusplus } diff --git a/sched/semaphore/Make.defs b/sched/semaphore/Make.defs index e9624282c9..39ba7cd2dc 100644 --- a/sched/semaphore/Make.defs +++ b/sched/semaphore/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # sched/semaphore/Make.defs # -# Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,7 +35,7 @@ CSRCS += sem_destroy.c sem_wait.c sem_trywait.c sem_tickwait.c CSRCS += sem_timedwait.c sem_timeout.c sem_post.c sem_recover.c -CSRCS += sem_waitirq.c +CSRCS += sem_reset.c sem_waitirq.c ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) CSRCS += sem_initialize.c sem_holder.c diff --git a/sched/semaphore/sem_reset.c b/sched/semaphore/sem_reset.c new file mode 100644 index 0000000000..6db75887ab --- /dev/null +++ b/sched/semaphore/sem_reset.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * sched/semaphore/sem_reset.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "semaphore/semaphore.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sem_reset + * + * Description: + * Reset a semaphore to a specific value. This kind of operation is + * sometimes required for certain error handling conditions. + * + * Parameters: + * sem - Semaphore descriptor to be reset + * count - The requested semaphore count + * + * Return Value: + * 0 (OK) or a negated errno value if unsuccessful + * + ****************************************************************************/ + +int sem_reset(FAR sem_t *sem, int16_t count) +{ + irqstate_t flags; + + DEBUGASSERT(sem != NULL && count >= 0); + + /* Don't allow any context switches that may result from the following + * sem_post operations. + */ + + sched_lock(); + + /* Prevent any access to the semaphore by interrupt handlers while we are + * performing this operation. + */ + + flags = enter_critical_section(); + + /* A negative count indicates the negated number of threads that are + * waiting to take a count from the semaphore. Loop here, handing + * out counts to any waiting threads. + */ + + while (sem->semcount < 0 && count > 0) + { + /* Give out one counting, waking up one of the waiting threads + * and, perhaps, kicking off a lot of priority inheritance + * logic (REVISIT). + */ + + DEBUGVERIFY(sem_post(sem)); + count--; + } + + /* We exit the above loop with either (1) no threads waiting for the + * (i.e., with sem->semcount >= 0). In this case, 'count' holds the + * the new value of the semaphore count. OR (2) with threads still + * waiting but all of the semaphore counts exhausted: The current + * value of sem->semcount is correct. + */ + + if (sem->semcount >= 0) + { + sem->semcount = count; + } + + /* Allow any pending context switches to occur now */ + + leave_critical_section(flags); + sched_unlock(); + return OK; +} -- GitLab From 9b5e88af71a8e92e21cc0609852aa2bb4c2fb755 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Mar 2016 13:50:26 -0600 Subject: [PATCH 823/858] Update some comments --- arch | 2 +- configs | 2 +- include/nuttx/semaphore.h | 6 ++++-- include/semaphore.h | 2 +- sched/semaphore/sem_reset.c | 12 +++++++----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/arch b/arch index 0b8fe68bf5..7ce734b33c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0b8fe68bf5c15b49d7877c97516fdda542b2149b +Subproject commit 7ce734b33cc3e0d85cf26e9d9bf409ed47004919 diff --git a/configs b/configs index 0c764446fe..3783532d6d 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0c764446fee7b6b4c6bb9c188042fb98b4d1e8eb +Subproject commit 3783532d6d7f3d809c523b63a55d544d7e6e5c6c diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index bdb5cfb27f..4a5bb32d32 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -117,8 +117,10 @@ int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay); * Name: sem_reset * * Description: - * Reset a semaphore to a specific value. This kind of operation is - * sometimes required for certain error handling conditions. + * Reset a semaphore count to a specific value. This is similar to part + * of the operation of sem_init(). But sem_reset() may need to wake up + * tasks waiting on a count. This kind of operation is sometimes required + * within the OS (only) for certain error handling conditions. * * Parameters: * sem - Semaphore descriptor to be reset diff --git a/include/semaphore.h b/include/semaphore.h index de4394c4e1..142ef51ada 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -85,7 +85,7 @@ struct semholder_s struct sem_s { - int16_t semcount; /* >0 -> Num counts available */ + volatile int16_t semcount; /* >0 -> Num counts available */ /* <0 -> Num tasks waiting for semaphore */ /* If priority inheritance is enabled, then we have to keep track of which * tasks hold references to the semaphore. diff --git a/sched/semaphore/sem_reset.c b/sched/semaphore/sem_reset.c index 6db75887ab..4f98d4e8e3 100644 --- a/sched/semaphore/sem_reset.c +++ b/sched/semaphore/sem_reset.c @@ -55,8 +55,10 @@ * Name: sem_reset * * Description: - * Reset a semaphore to a specific value. This kind of operation is - * sometimes required for certain error handling conditions. + * Reset a semaphore count to a specific value. This is similar to part + * of the operation of sem_init(). But sem_reset() may need to wake up + * tasks waiting on a count. This kind of operation is sometimes required + * within the OS (only) for certain error handling conditions. * * Parameters: * sem - Semaphore descriptor to be reset @@ -74,7 +76,7 @@ int sem_reset(FAR sem_t *sem, int16_t count) DEBUGASSERT(sem != NULL && count >= 0); /* Don't allow any context switches that may result from the following - * sem_post operations. + * sem_post() operations. */ sched_lock(); @@ -85,7 +87,7 @@ int sem_reset(FAR sem_t *sem, int16_t count) flags = enter_critical_section(); - /* A negative count indicates the negated number of threads that are + /* A negative count indicates that the negated number of threads are * waiting to take a count from the semaphore. Loop here, handing * out counts to any waiting threads. */ @@ -105,7 +107,7 @@ int sem_reset(FAR sem_t *sem, int16_t count) * (i.e., with sem->semcount >= 0). In this case, 'count' holds the * the new value of the semaphore count. OR (2) with threads still * waiting but all of the semaphore counts exhausted: The current - * value of sem->semcount is correct. + * value of sem->semcount is already correct in this case. */ if (sem->semcount >= 0) -- GitLab From 93b6543a1feffc28134bba3609b5210f8df73032 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 6 Mar 2016 16:20:04 -0600 Subject: [PATCH 824/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 7ce734b33c..fcb55807a6 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7ce734b33cc3e0d85cf26e9d9bf409ed47004919 +Subproject commit fcb55807a64c6374265c8d7756463cb311e7f911 -- GitLab From c13cb0f83997a1e8219537fa8534eb13e7b99afb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Mar 2016 16:14:52 -0600 Subject: [PATCH 825/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index fcb55807a6..184bd455ff 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit fcb55807a64c6374265c8d7756463cb311e7f911 +Subproject commit 184bd455fffac7989e63c5270154380ac91a37d0 diff --git a/configs b/configs index 3783532d6d..131b6f6c9f 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 3783532d6d7f3d809c523b63a55d544d7e6e5c6c +Subproject commit 131b6f6c9f5fc3c19b178fa21df9ad074884ed27 -- GitLab From 88d8a81b23389f6aefcfb0add45b2d91715cef73 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Mar 2016 14:12:44 -0600 Subject: [PATCH 826/858] tools/testbuild.sh: kconfig-conf was silently failing because (1) it needs to execute from the top-level NuttX directory and (2) apps/Kconfig does not yet exist --- arch | 2 +- configs | 2 +- tools/testbuild.sh | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch b/arch index 184bd455ff..92eab5a12b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 184bd455fffac7989e63c5270154380ac91a37d0 +Subproject commit 92eab5a12badf6230d18b56c6027da6de442dc9a diff --git a/configs b/configs index 131b6f6c9f..88faa8e05c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 131b6f6c9f5fc3c19b178fa21df9ad074884ed27 +Subproject commit 88faa8e05cc65a32d47e0b97c1954ef1e6e073df diff --git a/tools/testbuild.sh b/tools/testbuild.sh index 0490b5d781..da4bb5911e 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -192,6 +192,8 @@ function configure { fi echo " Refreshing..." + cd $nuttx || { echo "ERROR: failed to CD to $nuttx"; exit 1; } + make context 1>/dev/null 2>&1 kconfig-conf --olddefconfig Kconfig 1>/dev/null } -- GitLab From 624601dc2b268b18e0226bbdabee1742cdd4cfc5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Mar 2016 14:25:05 -0600 Subject: [PATCH 827/858] Update submodules --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index 92eab5a12b..c84c4f2edc 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 92eab5a12badf6230d18b56c6027da6de442dc9a +Subproject commit c84c4f2edc06fc9bc5e0b4325063feda89b3d2a5 -- GitLab From 4d9c41fd5725ec6d52b7e0fbee2bc73764824a56 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Tue, 8 Mar 2016 15:31:23 -0600 Subject: [PATCH 828/858] AT24XX: Correct address calculation in Multi-Block-Read --- drivers/mtd/at24xx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index fdecf95b80..77ee7e800d 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -387,7 +387,8 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock, } offset += priv->pagesize; - } + buffer += priv->pagesize; + } #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); -- GitLab From 7fa0adff831e854d4b816d45c1a1a73a80028853 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Mar 2016 15:33:33 -0600 Subject: [PATCH 829/858] Fix a misplaced right bracket --- drivers/mtd/at24xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 77ee7e800d..ee324be4df 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -388,7 +388,7 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock, offset += priv->pagesize; buffer += priv->pagesize; - } + } #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); -- GitLab From 1c31e10397e092b4c1434737618d1f03d4d29e1e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Mar 2016 16:10:41 -0600 Subject: [PATCH 830/858] NRF2410L: Add missing conditional logic in vtable initialization --- drivers/wireless/nrf24l01.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index d1f81ee930..ab7402d773 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -235,7 +235,9 @@ static const struct file_operations nrf24l01_fops = #ifndef CONFIG_DISABLE_POLL nrf24l01_poll, /* poll */ #endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS NULL /* unlink */ +#endif }; /**************************************************************************** -- GitLab From fea11c002a0a576fbcb9b5c367300bd483bd7149 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 8 Mar 2016 16:50:58 -0600 Subject: [PATCH 831/858] Build system: Add 'make oldconfig' target. Use this option in tools/testbuild.sh. Add --silent option to tools/refresh.sh so that it can be run in batch without human interaction --- Makefile.unix | 3 +++ Makefile.win | 3 +++ arch | 2 +- configs | 2 +- tools/refresh.sh | 29 +++++++++++++++++++++++------ tools/testbuild.sh | 3 +-- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Makefile.unix b/Makefile.unix index b1147390ae..96179c419b 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -486,6 +486,9 @@ config: apps_preconfig oldconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --oldconfig Kconfig +olddefconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-conf --olddefconfig Kconfig + menuconfig: apps_preconfig $(Q) APPSDIR=${CONFIG_APPS_DIR} kconfig-mconf Kconfig diff --git a/Makefile.win b/Makefile.win index 4988b43ab0..5a71a42122 100644 --- a/Makefile.win +++ b/Makefile.win @@ -486,6 +486,9 @@ config: apps_preconfig oldconfig: apps_preconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --oldconfig Kconfig +olddefconfig: apps_preconfig + $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-conf --olddefconfig Kconfig + menuconfig: configenv apps_preconfig $(Q) set APPSDIR=$(patsubst "%",%,${CONFIG_APPS_DIR})& kconfig-mconf Kconfig diff --git a/arch b/arch index c84c4f2edc..84aade6ed5 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit c84c4f2edc06fc9bc5e0b4325063feda89b3d2a5 +Subproject commit 84aade6ed5dcc6fe8df0afb7cb0fc157e128c6bc diff --git a/configs b/configs index 88faa8e05c..b2be018b28 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 88faa8e05cc65a32d47e0b97c1954ef1e6e073df +Subproject commit b2be018b284cdaaf192afd6b61dfcd4dce065b73 diff --git a/tools/refresh.sh b/tools/refresh.sh index a35b25b419..01df311b60 100755 --- a/tools/refresh.sh +++ b/tools/refresh.sh @@ -36,12 +36,16 @@ USAGE="USAGE: $0 [--debug|--help] /" ADVICE="Try '$0 --help' for more information" unset CONFIG +silent=n while [ ! -z "$1" ]; do case $1 in --debug ) set -x ;; + --silent ) + silent=y + ;; --help ) echo "$0 is a tool for refreshing board configurations" echo "" @@ -50,6 +54,8 @@ while [ ! -z "$1" ]; do echo "Where:" echo " --debug" echo " Enable script debug" + echo " --silent" + echo " Update board configuration without interaction" echo " --help" echo " Show this help message and exit" echo " " @@ -157,9 +163,13 @@ fi cp -a $DEFCONFIG .config || \ { echo "ERROR: Failed to copy $DEFCONFIG to .config"; exit 1; } -# Then run oldconfig +# Then run oldconfig or oldefconfig -make oldconfig +if [ "X${silent}" == "Xy" ]; then + make olddefconfig +else + make oldconfig +fi # Show differences @@ -168,14 +178,21 @@ $CMPCONFIG $DEFCONFIG .config # Save the refreshed configuration -read -p "Save the new configuration (y/n)?" -n 1 -r -echo -if [[ $REPLY =~ ^[Yy]$ ]] -then +if [ "X${silent}" == "Xy" ]; then echo "Saving the new configuration file" mv .config $DEFCONFIG || \ { echo "ERROR: Failed to move .config to $DEFCONFIG"; exit 1; } chmod 644 $DEFCONFIG +else + read -p "Save the new configuration (y/n)?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + echo "Saving the new configuration file" + mv .config $DEFCONFIG || \ + { echo "ERROR: Failed to move .config to $DEFCONFIG"; exit 1; } + chmod 644 $DEFCONFIG + fi fi # Restore any previous .config file diff --git a/tools/testbuild.sh b/tools/testbuild.sh index da4bb5911e..8f5bb56d4b 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -193,8 +193,7 @@ function configure { echo " Refreshing..." cd $nuttx || { echo "ERROR: failed to CD to $nuttx"; exit 1; } - make context 1>/dev/null 2>&1 - kconfig-conf --olddefconfig Kconfig 1>/dev/null + make olddefconfig 1>/dev/null 2>&1 } # Perform the next build -- GitLab From fde277a38834590ba5fc3078f9e382b89c7ce7b7 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Wed, 9 Mar 2016 07:24:16 -0600 Subject: [PATCH 832/858] Missing parentheses in MSEC2TICK macro can lead to incorrect conversions --- arch | 2 +- configs | 2 +- include/nuttx/clock.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 84aade6ed5..0147de5a24 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 84aade6ed5dcc6fe8df0afb7cb0fc157e128c6bc +Subproject commit 0147de5a248d7ba7be9d5dbd7addbe4aeae6088c diff --git a/configs b/configs index b2be018b28..82e6f02229 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b2be018b284cdaaf192afd6b61dfcd4dce065b73 +Subproject commit 82e6f022294752fcbdd71e282c493eba20751732 diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index c0fcc35b75..a844396b30 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -157,7 +157,7 @@ #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK # define MSEC2TICK(msec) (((msec)+(MSEC_PER_TICK/2))/MSEC_PER_TICK) /* Rounds */ #else -# define MSEC2TICK(msec) USEC2TICK(msec * 1000) /* Rounds */ +# define MSEC2TICK(msec) USEC2TICK((msec) * USEC_PER_MSEC) /* Rounds */ #endif #define DSEC2TICK(dsec) MSEC2TICK((dsec) * MSEC_PER_DSEC) /* Rounds */ -- GitLab From c7e7bda830f3b99137164f432526ff48334d5eb9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Mar 2016 07:42:34 -0600 Subject: [PATCH 833/858] MTD struct mtd_geometry_s: Increase the size of blocksize again. Yes, there are devices with block size greater than 64KB. --- include/nuttx/mtd/mtd.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index f17b7d3b70..c8a34052c8 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -114,8 +114,7 @@ struct mtd_geometry_s { - uint16_t blocksize; /* Size of one read/write block. */ - /* Probably 16-bits wasted here for alignment */ + uint32_t blocksize; /* Size of one read/write block. */ uint32_t erasesize; /* Size of one erase blocks -- must be a multiple * of blocksize.*/ uint32_t neraseblocks; /* Number of erase blocks */ -- GitLab From 611fb044490ab89c83c3af4a61fe865c79f16bbe Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Wed, 9 Mar 2016 12:44:56 -0600 Subject: [PATCH 834/858] BlockToCharDev: increase sectorsize to 32 bit --- arch | 2 +- drivers/bch/bch.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 0147de5a24..9a31f264ec 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0147de5a248d7ba7be9d5dbd7addbe4aeae6088c +Subproject commit 9a31f264ec72f07d40fb3b79f77ca72869ca8eee diff --git a/drivers/bch/bch.h b/drivers/bch/bch.h index 5463518349..157cf06133 100644 --- a/drivers/bch/bch.h +++ b/drivers/bch/bch.h @@ -62,10 +62,10 @@ struct bchlib_s { FAR struct inode *inode; /* I-node of the block driver */ - sem_t sem; /* For atomic accesses to this structure */ + uint32_t sectsize; /* The size of one sector on the device */ size_t nsectors; /* Number of sectors supported by the device */ size_t sector; /* The current sector in the buffer */ - uint16_t sectsize; /* The size of one sector on the device */ + sem_t sem; /* For atomic accesses to this structure */ uint8_t refs; /* Number of references */ bool dirty; /* true: Data has been written to the buffer */ bool readonly; /* true: Only read operations are supported */ -- GitLab From 760fb63f33d8b4e6cc00c5ba2d06dc8d1d6d83d1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Mar 2016 17:39:43 -0600 Subject: [PATCH 835/858] Update README/TODO with new naming --- ChangeLog | 2 +- TODO | 2 +- arch | 2 +- configs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4db1c92df0..e8792ba888 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1654,7 +1654,7 @@ * arch/*/include/*/type.h: On some compilers, char defaults as unsigned. Explicitly add signed to integer types if signed is what is required. * arch/*: For all architectures -- Global register state save structure - (usually called current_regs) should be marked volatile; Added general + (usually called g_current_regs) should be marked volatile; Added general capability to support nested interrupts (not fully realized for all architectures). * sched/task_create.c: Add support for starting kernel-mode thread. diff --git a/TODO b/TODO index 9bf3e7ede3..d9c66df017 100644 --- a/TODO +++ b/TODO @@ -1679,7 +1679,7 @@ o ARM (arch/arm/) Title: IMPROVED ARM INTERRUPT HANDLING Description: ARM interrupt handling performance could be improved in some ways. One easy way is to use a pointer to the context save - area in current_regs instead of using up_copystate so much. + area in g_current_regs instead of using up_copystate so much. This approach is already implemented for the ARM Cortex-M0, Cortex-M3, Cortex-M4, and Cortex-A5 families. But still needs diff --git a/arch b/arch index 9a31f264ec..0dfea1d68b 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9a31f264ec72f07d40fb3b79f77ca72869ca8eee +Subproject commit 0dfea1d68b55f7d8378d422eb4875acc59867077 diff --git a/configs b/configs index 82e6f02229..d43a9495be 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 82e6f022294752fcbdd71e282c493eba20751732 +Subproject commit d43a9495be59baeae4e8626c3138cc7e792e3af1 -- GitLab From 6a056479d2c93af5e391d66ab8b3586ee3f27a9b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Mar 2016 18:12:41 -0600 Subject: [PATCH 836/858] Add a some missing FAR in shared header files --- arch | 2 +- include/nuttx/i2c/i2c_master.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch b/arch index 0dfea1d68b..97d205c697 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0dfea1d68b55f7d8378d422eb4875acc59867077 +Subproject commit 97d205c697886d4e28fbc785d373bb17541f11dd diff --git a/include/nuttx/i2c/i2c_master.h b/include/nuttx/i2c/i2c_master.h index 868dad15b9..1938bcbfa1 100644 --- a/include/nuttx/i2c/i2c_master.h +++ b/include/nuttx/i2c/i2c_master.h @@ -171,7 +171,7 @@ struct i2c_config_s { uint32_t frequency; /* I2C frequency */ uint16_t address; /* I2C address (7- or 10-bit) */ - uint8_t addrlen; /* I2C address length (7 or 10 bits) */ + uint8_t addrlen; /* I2C address length (7 or 10 bits) */ }; /* I2C transaction segment beginning with a START. A number of these can @@ -181,11 +181,11 @@ struct i2c_config_s struct i2c_msg_s { - uint32_t frequency; /* I2C frequency */ - uint16_t addr; /* Slave address (7- or 10-bit) */ - uint16_t flags; /* See I2C_M_* definitions */ - uint8_t *buffer; /* Buffer to be transferred */ - ssize_t length; /* Length of the buffer in bytes */ + uint32_t frequency; /* I2C frequency */ + uint16_t addr; /* Slave address (7- or 10-bit) */ + uint16_t flags; /* See I2C_M_* definitions */ + FAR uint8_t *buffer; /* Buffer to be transferred */ + ssize_t length; /* Length of the buffer in bytes */ }; /* I2C private data. This structure only defines the initial fields of the @@ -195,7 +195,7 @@ struct i2c_msg_s struct i2c_master_s { - const struct i2c_ops_s *ops; /* I2C vtable */ + FAR const struct i2c_ops_s *ops; /* I2C vtable */ }; /* This structure is used to communicate with the I2C character driver in -- GitLab From ea48809fff93a356a8fb5a92127cca794e381268 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 07:14:10 -0600 Subject: [PATCH 837/858] Update ChangeLog --- ChangeLog | 17 ++++++++++++++++- arch | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8792ba888..2fb7ff55c1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11539,4 +11539,19 @@ * sched/semaphore/sem_reset.c and include/nuttx/semaphore.h: Add an internal, non-standard interface to reset a semaphore count. This is sometimes needed by drivers in order to recover from error conditions (2016-03-05) - + * AT24xx driver: Correct missing address calculation logic. From Frank + Benkert (2016-03-08). + * arch/ renaming: current_regs renamed to g_current_regs in all + architectures. For ARM which is slowly developing SMP capability, + g_current_regs is now an array of dimension 1 in most case but of higher + dimension of the architecuture supports multiple CPUs (2016-03-09). + * MTD: Increase block size in mtd_geometry_s to 32-bits (2016-03-09). + * include/nuttx/clock.h: Missing parenteses in MSEC2TICK macro can + cause wrong calculations. From Stefan Kolb (2016-03-09). + * Build system: Added a 'make olddefconfig' target that will refresh + a .config file without interaction. tools/refesh.sh no has a --silent + option so that it can be used in batch modes without human input + (2016-03-09). + * tools/testbuild.sh: .config files were not being updated because (a) + kconfig-conf was being called in the wrong directory and (b) apps/Kconfig + had not yet been created. Now uses 'make olddefconfig' (2016-03-09). diff --git a/arch b/arch index 97d205c697..a620f59955 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 97d205c697886d4e28fbc785d373bb17541f11dd +Subproject commit a620f5995523c742551e300b0fdfc85306b2f6bb -- GitLab From 4a22542091c828a56de59e7eea2c77dcc452f856 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 10:10:25 -0600 Subject: [PATCH 838/858] Update ChangeLog --- ChangeLog | 2 ++ arch | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2fb7ff55c1..3f35d1531c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11555,3 +11555,5 @@ * tools/testbuild.sh: .config files were not being updated because (a) kconfig-conf was being called in the wrong directory and (b) apps/Kconfig had not yet been created. Now uses 'make olddefconfig' (2016-03-09). + * arch/arm/src/stm32l4 and include/stm32l4: Add support for the STM32L4 + family. From Sebastien Lorquet (2016-03-10). diff --git a/arch b/arch index a620f59955..d0c87105be 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a620f5995523c742551e300b0fdfc85306b2f6bb +Subproject commit d0c87105be2b62175b0223c5a45dd63db786494a -- GitLab From 30b6ee96c9a7a7c3ff8c4b9e9035e8267e3b6510 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 11:56:33 -0600 Subject: [PATCH 839/858] Add basic definitions for TLS support --- ChangeLog | 5 ++ arch | 2 +- configs | 2 +- include/nuttx/arch.h | 48 ++++++++++++++++++ include/nuttx/tls.h | 115 +++++++++++++++++++++++++++++++++++++++++++ sched/Kconfig | 36 ++++++++++++++ sched/Makefile | 21 ++++---- 7 files changed, 217 insertions(+), 12 deletions(-) create mode 100644 include/nuttx/tls.h diff --git a/ChangeLog b/ChangeLog index 3f35d1531c..87f3793afa 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11557,3 +11557,8 @@ had not yet been created. Now uses 'make olddefconfig' (2016-03-09). * arch/arm/src/stm32l4 and include/stm32l4: Add support for the STM32L4 family. From Sebastien Lorquet (2016-03-10). + * configs/nucleo-l476: Add support for the Nucleo-L476 board. From + Sebastien Lorquet (2016-03-10). + * sched/tls and include/nuttx/tls.h: Basic definitions needed to support + thread local storage (TLS). Not used anywhere yet (2016-03-10). + diff --git a/arch b/arch index d0c87105be..ed37b1b8fa 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit d0c87105be2b62175b0223c5a45dd63db786494a +Subproject commit ed37b1b8fa3f364229e3b26fc9bb62f1a7dd2b4f diff --git a/configs b/configs index d43a9495be..dc86e1cc52 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d43a9495be59baeae4e8626c3138cc7e792e3af1 +Subproject commit dc86e1cc52689e67e33f6c47ca0b2a3d4aa783a4 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 179aa49473..28d219c368 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1635,6 +1635,45 @@ int up_timer_cancel(FAR struct timespec *ts); int up_timer_start(FAR const struct timespec *ts); #endif +/**************************************************************************** + * TLS support + ****************************************************************************/ + +/**************************************************************************** + * Name: up_tls_info + * + * Description: + * Return the TLS information structure for the currently executing thread. + * When TLS is enabled, up_createstack() will align allocated stacks to + * the TLS_STACK_ALIGN value. An instance of the following structure will + * be implicitly positioned at the "lower" end of the stack. Assuming a + * "push down" stack, this is at the "far" end of the stack (and can be + * clobbered if the stack overflows). + * + * If an MCU has a "push up" then that TLS structure will lie at the top + * of the stack and stack allocation and initialization logic must take + * care to preserve this structure content. + * + * The stack memory is fully accessible to user mode threads but will + * contain references to OS internal, private data structures (such as the + * TCB) + * + * Input Parameters: + * None + * + * Returned Value: + * A pointer to TLS info structure at the beginning of the STACK memory + * allocation. This is essentially an appliction of the TLS_INFO(sp) + * macro and has a platform dependency only in the manner in which the + * stack pointer (sp) is obtained and interpreted. + * + ****************************************************************************/ + +#ifdef CONFIG_TLS +struct tls_info_s; /* Forward reference */ +FAR struct tls_info_s *up_tls_info(void); +#endif + /**************************************************************************** * Multiple CPU support ****************************************************************************/ @@ -1666,6 +1705,10 @@ int up_timer_start(FAR const struct timespec *ts); * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that * corresponds to the currently executing CPU. * + * If TLS is enabled, then the RTOS can get this information from the TLS + * info structure. Otherwise, the MCU-specific logic must provide some + * mechanism to provide the CPU index. + * * Input Parameters: * None * @@ -1676,7 +1719,12 @@ int up_timer_start(FAR const struct timespec *ts); ****************************************************************************/ #ifdef CONFIG_SMP +# ifdef CONFIG_TLS +int tls_cpu_index(void); +# define up_cpu_index() tls_cpu_index() +# else int up_cpu_index(void); +# endif #else # define up_cpu_index() (0) #endif diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h new file mode 100644 index 0000000000..b667bde786 --- /dev/null +++ b/include/nuttx/tls.h @@ -0,0 +1,115 @@ +/**************************************************************************** + * include/nuttx/tls.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_TLS_H +#define __INCLUDE_NUTTX_TLS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_TLS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_TLS_LOG2_MAXSTACK +# error CONFIG_TLS_LOG2_MAXSTACK is not defined +#endif + +/* TLS Definitions **********************************************************/ + +#define TLS_STACK_ALIGN (1L << CONFIG_TLS_LOG2_MAXSTACK) +#define TLS_STACK_MASK (TLS_STACK_ALIGN - 1) +#define TLS_MAXSTACK (TLS_STACK_ALIGN) +#define TLS_INFO(sp) ((FAR struct tls_info_s *)((sp) & TLS_STACK_MASK)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* When TLS is enabled, up_createstack() will align allocated stacks to the + * TLS_STACK_ALIGN value. An instance of the following structure will be + * implicitly positioned at the "lower" end of the stack. Assuming a + * "push down" stack, this is at the "far" end of the stack (and can be + * clobbered if the stack overflows). + * + * If an MCU has a "push up" then that TLS structure will lie at the top + * of the stack and stack allocation and initialization logic must take + * care to preserve this structure content. + * + * The stack memory is fully accessible to user mode threads but will + * contain references to OS internal, private data structures (such as the + * TCB) + */ + +struct tcb_s; /* Forward reference */ +struct tls_info_s +{ + FAR struct tcb_s *tl_tcb; /* The TCB of the current task */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_cpu_index + * + * Description: + * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. This is index is retained + * in the task TCB which is accessible via the tls_info_s structure. + * + * Input Parameters: + * None + * + * Returned Value: + * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int tls_cpu_index(void); +#endif + +#endif /* CONFIG_TLS */ +#endif /* __INCLUDE_NUTTX_TLS_H */ diff --git a/sched/Kconfig b/sched/Kconfig index 66c9f02459..fa8d25252c 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -503,6 +503,42 @@ config SCHED_WAITPID endmenu # Tasks and Scheduling +config ARCH_HAVE_TLS + bool + default n + ---help--- + Selected by the configuration system if the current architecture + supports TLS. + +menuconfig TLS + bool "Thread Local Storage (TLS)" + default n + depends on ARCH_HAVE_TLS + ---help--- + Build in support for stack based thread local storage (TLS). + +if TLS + +config TLS_LOG2_MAXSTACK + int "Maximum stack size (log2)" + default 13 + range 11 24 + ---help--- + Stack based TLS works by fetch thread information from the beginning + of the stack memory allocation. In order to do this, the memory + must be aligned in such a way that the executing logic can simply + masking the current stack pointer to get the beginning of the stack + allocation. + + This setting specifies the alignment of the stack as a power of 2: + 11=2KB, 12=4KB, 13=8KB, etc. The exact alignment is not so critical + except that (1) a very large value can cause you to run out of + alignable memory (and fail memory allocations), and (2) smaller + values will limit the maximum size of the stack (hence the naming + of this configuration value). + +endif # TLS + menu "Pthread Options" depends on !DISABLE_PTHREAD diff --git a/sched/Makefile b/sched/Makefile index 066c84d904..6a07d4a194 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -1,7 +1,7 @@ ############################################################################ # sched/Makefile # -# Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,22 +41,23 @@ CSRCS = VPATH = DEPPATH = --dep-path . +include clock/Make.defs +include errno/Make.defs +include environ/Make.defs +include group/Make.defs include init/Make.defs include irq/Make.defs +include mqueue/Make.defs +include module/Make.defs include paging/Make.defs -include group/Make.defs +include pthread/Make.defs include sched/Make.defs -include task/Make.defs -include errno/Make.defs -include wdog/Make.defs include semaphore/Make.defs include signal/Make.defs -include pthread/Make.defs -include mqueue/Make.defs -include clock/Make.defs +include task/Make.defs include timer/Make.defs -include environ/Make.defs -include module/Make.defs +include tls/Make.defs +include wdog/Make.defs include wqueue/Make.defs AOBJS = $(ASRCS:.S=$(OBJEXT)) -- GitLab From 0929c8b1d71499d700dd7f710efcb03179ae7d1e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 15:58:39 -0600 Subject: [PATCH 840/858] Update submodules --- ChangeLog | 3 ++- arch | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87f3793afa..86444d10c2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11560,5 +11560,6 @@ * configs/nucleo-l476: Add support for the Nucleo-L476 board. From Sebastien Lorquet (2016-03-10). * sched/tls and include/nuttx/tls.h: Basic definitions needed to support - thread local storage (TLS). Not used anywhere yet (2016-03-10). + thread local storage (TLS). Not used anywhere yet (and may not be used + in the near future either) (2016-03-10). diff --git a/arch b/arch index ed37b1b8fa..0d8d0f4ead 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ed37b1b8fa3f364229e3b26fc9bb62f1a7dd2b4f +Subproject commit 0d8d0f4ead50917143cddbc140ca6658664d6737 -- GitLab From f16f470881612fad0823c8dd63f07b791bb5dc81 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 17:24:48 -0600 Subject: [PATCH 841/858] Update README.txt files --- README.txt | 10 ++++++++++ tools/README.txt | 32 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index d7f07482f6..90c264446e 100644 --- a/README.txt +++ b/README.txt @@ -476,6 +476,16 @@ Refreshing Configurations be? Enter ? in response to the 'make oldconfig' prompt and it will show you the help text that goes with the option. + If you don't want to make any decisions are are willing to just accep the + recommended default value for each new configuration item, an even easier + way is: + + make oldefconfig + + The olddefconfig target will simply bring you configuration up to date with + the current Kconfig files, setting any new options to the default value. + No questions asked. + NuttX Configuration Tool ------------------------ diff --git a/tools/README.txt b/tools/README.txt index d4acb034f5..4f57ca0b34 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -575,7 +575,26 @@ refresh.sh new dependencies are added. So an old configuration file may not be usable anymore until it is refreshed. - The steps to refresh the file are: + Help is also available: + + $ tools/refresh.sh --help + tools/refresh.sh is a tool for refreshing board configurations + + USAGE: tools/refresh.sh [--debug|--help] / + + Where: + --debug + Enable script debug + --silent + Update board configuration without interaction + --help + Show this help message and exit + + The board directory under nuttx/configs + + The board configuration directory under nuttx/configs/ + + The steps to refresh the file taken by refresh.sh are: 1. Make tools/cmpconfig if it is not already built. 2. Copy the the defconfig file to the top-level NuttX @@ -584,6 +603,10 @@ refresh.sh 3. Execute 'make oldconfig' to update the configuration. 'make oldconfig' will prompt you for each change in the configuration that requires that you make some decision. + With the --silent option, the script will use 'make + oldefconfig' instead and you won't have to answer any + questions; the refresh will simply accept the default + value for any new configuration settings. 4. Then it runs tools/cmpconfig to show the real differences between the configuration files. Configuration files are complex and things can move around so a simple 'diff' between @@ -597,9 +620,10 @@ refresh.sh installed. 5. Finally, the refreshed defconfig file is copied back in place where it can be committed with the next set of - difference to the command line. refresh.sh will prompt - you first to avoid overwriting the defconfig file with - changes that you do not want. + difference to the command line. If you select the --silent + option, this file copy will occur autiomatically. Otherwise, + refresh.sh will prompt you first to avoid overwriting the + defconfig file with changes that you may not want. testbuild.sh ------------ -- GitLab From d69dc04d9610f33ec2324d99a40a61daab293e3d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 18:10:44 -0600 Subject: [PATCH 842/858] TLS: Fix an error in a macro --- arch | 2 +- include/nuttx/arch.h | 2 +- include/nuttx/tls.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch b/arch index 0d8d0f4ead..7195b24346 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 0d8d0f4ead50917143cddbc140ca6658664d6737 +Subproject commit 7195b24346e9d4115feff64d09f406ef31966630 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 28d219c368..448029f47e 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1663,7 +1663,7 @@ int up_timer_start(FAR const struct timespec *ts); * * Returned Value: * A pointer to TLS info structure at the beginning of the STACK memory - * allocation. This is essentially an appliction of the TLS_INFO(sp) + * allocation. This is essentially an application of the TLS_INFO(sp) * macro and has a platform dependency only in the manner in which the * stack pointer (sp) is obtained and interpreted. * diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index b667bde786..e3477aada1 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -60,7 +60,7 @@ #define TLS_STACK_ALIGN (1L << CONFIG_TLS_LOG2_MAXSTACK) #define TLS_STACK_MASK (TLS_STACK_ALIGN - 1) #define TLS_MAXSTACK (TLS_STACK_ALIGN) -#define TLS_INFO(sp) ((FAR struct tls_info_s *)((sp) & TLS_STACK_MASK)) +#define TLS_INFO(sp) ((FAR struct tls_info_s *)((sp) & ~TLS_STACK_MASK)) /**************************************************************************** * Public Types -- GitLab From 934069e422069a7774c4db09ad14156e059729c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 10 Mar 2016 19:31:22 -0600 Subject: [PATCH 843/858] TLS: Add logic to get/set arbitrary TLS values --- arch | 2 +- include/nuttx/tls.h | 53 +++++++++++++++++++++- sched/Kconfig | 7 +++ sched/tls/Make.defs | 51 +++++++++++++++++++++ sched/tls/tls.h | 49 ++++++++++++++++++++ sched/tls/tls_cpuindex.c | 97 ++++++++++++++++++++++++++++++++++++++++ sched/tls/tls_getelem.c | 92 +++++++++++++++++++++++++++++++++++++ sched/tls/tls_setelem.c | 88 ++++++++++++++++++++++++++++++++++++ 8 files changed, 436 insertions(+), 3 deletions(-) create mode 100644 sched/tls/Make.defs create mode 100644 sched/tls/tls.h create mode 100644 sched/tls/tls_cpuindex.c create mode 100644 sched/tls/tls_getelem.c create mode 100644 sched/tls/tls_setelem.c diff --git a/arch b/arch index 7195b24346..42309e169e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7195b24346e9d4115feff64d09f406ef31966630 +Subproject commit 42309e169e94db92096afb8f4b6957e84c6b6fc8 diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index e3477aada1..e6feaaeb15 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -55,6 +55,11 @@ # error CONFIG_TLS_LOG2_MAXSTACK is not defined #endif +#ifndef CONFIG_TLS_NELEM +# warning CONFIG_TLS_NELEM is not defined +# define CONFIG_TLS_NELEM 0 +#endif + /* TLS Definitions **********************************************************/ #define TLS_STACK_ALIGN (1L << CONFIG_TLS_LOG2_MAXSTACK) @@ -83,7 +88,10 @@ struct tcb_s; /* Forward reference */ struct tls_info_s { - FAR struct tcb_s *tl_tcb; /* The TCB of the current task */ + FAR struct tcb_s *tl_tcb; /* The TCB of the current task */ +#if CONFIG_TLS_NELEM > 0 + uintptr_t tl_elem[CONFIG_TLS_NELEM]; /* TLS elements */ +#endif }; /**************************************************************************** @@ -103,7 +111,7 @@ struct tls_info_s * * Returned Value: * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that - * corresponds to the currently executing CPU. + * corresponds to the currently executing CPU * ****************************************************************************/ @@ -111,5 +119,46 @@ struct tls_info_s int tls_cpu_index(void); #endif +/**************************************************************************** + * Name: tls_get_element + * + * Description: + * Return an the TLS element associated with the 'elem' index + * + * Input Parameters: + * elem - Index of TLS element to return + * + * Returned Value: + * The value of TLS element associated with 'elem'. Errors are not reported. + * Aero is returned in the event of an error, but zero may also be valid + * value and returned when there is no error. The only possible error would + * be if elem >=CONFIG_TLS_NELEM. + * + ****************************************************************************/ + +#if CONFIG_TLS_NELEM > 0 +uintptr_t tls_get_element(int elem); +#endif + +/**************************************************************************** + * Name: tls_get_element + * + * Description: + * Set the TLS element associated with the 'elem' index to 'value' + * + * Input Parameters: + * elem - Index of TLS element to set + * value - The new value of the TLS element + * + * Returned Value: + * None. Errors are not reported. The only possible error would be if + * elem >=CONFIG_TLS_NELEM. + * + ****************************************************************************/ + +#if CONFIG_TLS_NELEM > 0 +void tls_set_element(int elem, uintptr_t value); +#endif + #endif /* CONFIG_TLS */ #endif /* __INCLUDE_NUTTX_TLS_H */ diff --git a/sched/Kconfig b/sched/Kconfig index fa8d25252c..d1f4471b1e 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -537,6 +537,13 @@ config TLS_LOG2_MAXSTACK values will limit the maximum size of the stack (hence the naming of this configuration value). +config TLS_NELEM + int "Number of TLS elements" + default 0 + ---help--- + The number of unique TLS elements. These can be accessed with + tls_get_element() and tls_set_element(). + endif # TLS menu "Pthread Options" diff --git a/sched/tls/Make.defs b/sched/tls/Make.defs new file mode 100644 index 0000000000..a200777001 --- /dev/null +++ b/sched/tls/Make.defs @@ -0,0 +1,51 @@ +############################################################################ +# sched/tls/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_TLS),y) + +ifeq ($(CONFIG_SMP),y) +CSRCS += tls_cpuindex.c +endif + +ifneq ($(CONFIG_TLS_NELEM),0) +CSRCS += tls_setelem.c tls_getelem.c +endif + +# Include tls build support + +DEPPATH += --dep-path tls +VPATH += :tls + +endif diff --git a/sched/tls/tls.h b/sched/tls/tls.h new file mode 100644 index 0000000000..c7d361a3f7 --- /dev/null +++ b/sched/tls/tls.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * sched/tls/tls.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __SCHED_TLS_TLS_H +#define __SCHED_TLS_TLS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __SCHED_TLS_TLS_H */ diff --git a/sched/tls/tls_cpuindex.c b/sched/tls/tls_cpuindex.c new file mode 100644 index 0000000000..b906d0ade9 --- /dev/null +++ b/sched/tls/tls_cpuindex.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * libc/fixedmath/tls_cpuindex.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#if defined(CONFIG_TLS) && defined(CONFIG_SMP) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_cpu_index + * + * Description: + * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that + * corresponds to the currently executing CPU. This is index is retained + * in the task TCB which is accessible via the tls_info_s structure. + * + * There is a race condition in that this thread could be swapped out and + * be running on a different CPU when the function returns. If that is a + * problem, then the calling function should disable pre-emption before + * calling this function. + * + * Input Parameters: + * None + * + * Returned Value: + * On success, an integer index is returned in the range of 0 through + * (CONFIG_SMP_NCPUS-1) that corresponds to the currently executing CPU. + * + ****************************************************************************/ + +int tls_cpu_index(void) +{ + FAR struct tls_info_s *info; + FAR struct tcb_s *tcb; + + /* Get the TLS info structure from the current threads stack */ + + info = up_tls_info(); + DEBUGASSERT(info != NULL && info->tl_tcb != NULL); + + /* Get the TCB from the TLS info. We expect the TCB state to indicate that + * the task is running (it must be because it is this thread). + */ + + tcb = info->tl_tcb; + DEBUGASSERT(tcb->task_state == TSTATE_TASK_RUNNING && + tcb->cpu <= (CONFIG_SMP_NCPUS-1)); + + return tcb->cpu; +} + +#endif /* CONFIG_TLS && CONFIG_SMP */ diff --git a/sched/tls/tls_getelem.c b/sched/tls/tls_getelem.c new file mode 100644 index 0000000000..9a11a5194b --- /dev/null +++ b/sched/tls/tls_getelem.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * libc/fixedmath/tls_getelem.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#if defined(CONFIG_TLS) && CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_get_element + * + * Description: + * Return an the TLS element associated with the 'elem' index + * + * Input Parameters: + * elem - Index of TLS element to return + * + * Returned Value: + * The value of TLS element associated with 'elem'. Errors are not reported. + * Aero is returned in the event of an error, but zero may also be valid + * value and returned when there is no error. The only possible error would + * be if elem >=CONFIG_TLS_NELEM. + * + ****************************************************************************/ + +uintptr_t tls_get_element(int elem) +{ + FAR struct tls_info_s *info; + uintptr_t ret = 0; + + DEBUGASSERT(elem >= 0 && elem < CONFIG_TLS_NELEM); + if (elem >= 0 && elem < CONFIG_TLS_NELEM) + { + /* Get the TLS info structure from the current threads stack */ + + info = up_tls_info(); + DEBUGASSERT(info != NULL); + + /* Get the element value from the TLS info. */ + + ret = info->tl_elem[elem]; + } + + return ret; +} + +#endif /* CONFIG_TLS && CONFIG_TLS_NELEM > 0 */ diff --git a/sched/tls/tls_setelem.c b/sched/tls/tls_setelem.c new file mode 100644 index 0000000000..cca74adee3 --- /dev/null +++ b/sched/tls/tls_setelem.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/fixedmath/tls_setelem.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#if defined(CONFIG_TLS) && CONFIG_TLS_NELEM > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tls_get_element + * + * Description: + * Set the TLS element associated with the 'elem' index to 'value' + * + * Input Parameters: + * elem - Index of TLS element to set + * value - The new value of the TLS element + * + * Returned Value: + * None. Errors are not reported. The only possible error would be if + * elem >=CONFIG_TLS_NELEM. + * + ****************************************************************************/ + +void tls_set_element(int elem, uintptr_t value) +{ + FAR struct tls_info_s *info; + + DEBUGASSERT(elem >= 0 && elem < CONFIG_TLS_NELEM); + if (elem >= 0 && elem < CONFIG_TLS_NELEM) + { + /* Get the TLS info structure from the current threads stack */ + + info = up_tls_info(); + DEBUGASSERT(info != NULL); + + /* Set the element value int the TLS info. */ + + info->tl_elem[elem] = value; + } +} + +#endif /* CONFIG_TLS && CONFIG_TLS_NELEM > 0 */ -- GitLab From 24468128dec42609a16a3804c7ca57a316327fc9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Mar 2016 07:17:32 -0600 Subject: [PATCH 844/858] TLS: Simplify --- TODO | 4 ++ arch | 2 +- include/nuttx/arch.h | 21 +++---- include/nuttx/tls.h | 46 ++++----------- libc/Kconfig | 43 ++++++++++++++ libc/Makefile | 35 +++++------ {sched => libc}/tls/Make.defs | 8 +-- {sched => libc}/tls/tls.h | 0 {sched => libc}/tls/tls_getelem.c | 5 +- {sched => libc}/tls/tls_setelem.c | 5 +- sched/Kconfig | 43 -------------- sched/Makefile | 1 - sched/tls/tls_cpuindex.c | 97 ------------------------------- 13 files changed, 91 insertions(+), 219 deletions(-) rename {sched => libc}/tls/Make.defs (94%) rename {sched => libc}/tls/tls.h (100%) rename {sched => libc}/tls/tls_getelem.c (97%) rename {sched => libc}/tls/tls_setelem.c (97%) delete mode 100644 sched/tls/tls_cpuindex.c diff --git a/TODO b/TODO index d9c66df017..74e94c7b5a 100644 --- a/TODO +++ b/TODO @@ -524,6 +524,10 @@ o Kernel/Protected Build console output. The requests for the pid() are part of the implementation of the I/O's re-entrant semaphore implementation and would not be an issue in the more general case. + + Update: + One solution might be to used CONFIG_TLS, add the PID to struct + tls_info_s. Then the PID could be obtained without a system call. Status: Open Priority: Low-Medium. Right now, I do not know if these syscalls are a real performance issue or not. The above statistics were collected diff --git a/arch b/arch index 42309e169e..bc619710ab 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 42309e169e94db92096afb8f4b6957e84c6b6fc8 +Subproject commit bc619710ab72168bc8ad658deb344e68caf7dcf4 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 448029f47e..0a176653fd 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1654,9 +1654,7 @@ int up_timer_start(FAR const struct timespec *ts); * of the stack and stack allocation and initialization logic must take * care to preserve this structure content. * - * The stack memory is fully accessible to user mode threads but will - * contain references to OS internal, private data structures (such as the - * TCB) + * The stack memory is fully accessible to user mode threads. * * Input Parameters: * None @@ -1670,8 +1668,12 @@ int up_timer_start(FAR const struct timespec *ts); ****************************************************************************/ #ifdef CONFIG_TLS -struct tls_info_s; /* Forward reference */ -FAR struct tls_info_s *up_tls_info(void); +/* struct tls_info_s; + * FAR struct tls_info_s *up_tls_info(void); + * + * The actual declaration or definition is provided in arch/tls.h. The + * actual implementation may be a MACRO or and inline function. + */ #endif /**************************************************************************** @@ -1705,10 +1707,6 @@ FAR struct tls_info_s *up_tls_info(void); * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that * corresponds to the currently executing CPU. * - * If TLS is enabled, then the RTOS can get this information from the TLS - * info structure. Otherwise, the MCU-specific logic must provide some - * mechanism to provide the CPU index. - * * Input Parameters: * None * @@ -1719,12 +1717,7 @@ FAR struct tls_info_s *up_tls_info(void); ****************************************************************************/ #ifdef CONFIG_SMP -# ifdef CONFIG_TLS -int tls_cpu_index(void); -# define up_cpu_index() tls_cpu_index() -# else int up_cpu_index(void); -# endif #else # define up_cpu_index() (0) #endif diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index e6feaaeb15..39c9529716 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -57,7 +57,13 @@ #ifndef CONFIG_TLS_NELEM # warning CONFIG_TLS_NELEM is not defined -# define CONFIG_TLS_NELEM 0 +# define CONFIG_TLS_NELEM 1 +#endif + +#if CONFIG_TLS_NELEM < 1 +# error CONFIG_TLS_NELEM must be at least one +# undef CONFIG_TLS_NELEM +# define CONFIG_TLS_NELEM 1 #endif /* TLS Definitions **********************************************************/ @@ -80,45 +86,19 @@ * of the stack and stack allocation and initialization logic must take * care to preserve this structure content. * - * The stack memory is fully accessible to user mode threads but will - * contain references to OS internal, private data structures (such as the - * TCB) + * The stack memory is fully accessible to user mode threads. TLS is not + * available from interrupt handlers (nor from the IDLE thread). */ -struct tcb_s; /* Forward reference */ struct tls_info_s { - FAR struct tcb_s *tl_tcb; /* The TCB of the current task */ -#if CONFIG_TLS_NELEM > 0 uintptr_t tl_elem[CONFIG_TLS_NELEM]; /* TLS elements */ -#endif }; /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: tls_cpu_index - * - * Description: - * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that - * corresponds to the currently executing CPU. This is index is retained - * in the task TCB which is accessible via the tls_info_s structure. - * - * Input Parameters: - * None - * - * Returned Value: - * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that - * corresponds to the currently executing CPU - * - ****************************************************************************/ - -#ifdef CONFIG_SMP -int tls_cpu_index(void); -#endif - /**************************************************************************** * Name: tls_get_element * @@ -132,13 +112,11 @@ int tls_cpu_index(void); * The value of TLS element associated with 'elem'. Errors are not reported. * Aero is returned in the event of an error, but zero may also be valid * value and returned when there is no error. The only possible error would - * be if elem >=CONFIG_TLS_NELEM. + * be if elemn < 0 or elem >=CONFIG_TLS_NELEM. * ****************************************************************************/ -#if CONFIG_TLS_NELEM > 0 uintptr_t tls_get_element(int elem); -#endif /**************************************************************************** * Name: tls_get_element @@ -152,13 +130,11 @@ uintptr_t tls_get_element(int elem); * * Returned Value: * None. Errors are not reported. The only possible error would be if - * elem >=CONFIG_TLS_NELEM. + * elem < 0 or elem >=CONFIG_TLS_NELEM. * ****************************************************************************/ -#if CONFIG_TLS_NELEM > 0 void tls_set_element(int elem, uintptr_t value); -#endif #endif /* CONFIG_TLS */ #endif /* __INCLUDE_NUTTX_TLS_H */ diff --git a/libc/Kconfig b/libc/Kconfig index 54df4e2ede..276cc502e5 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -504,6 +504,49 @@ config ARCH_BZERO endif # ARCH_OPTIMIZED_FUNCTIONS +config ARCH_HAVE_TLS + bool + default n + ---help--- + Selected by the configuration system if the current architecture + supports TLS. + +menuconfig TLS + bool "Thread Local Storage (TLS)" + default n + depends on ARCH_HAVE_TLS + ---help--- + Build in support for stack based thread local storage (TLS). + +if TLS + +config TLS_LOG2_MAXSTACK + int "Maximum stack size (log2)" + default 13 + range 11 24 + ---help--- + Stack based TLS works by fetch thread information from the beginning + of the stack memory allocation. In order to do this, the memory + must be aligned in such a way that the executing logic can simply + masking the current stack pointer to get the beginning of the stack + allocation. + + This setting specifies the alignment of the stack as a power of 2: + 11=2KB, 12=4KB, 13=8KB, etc. The exact alignment is not so critical + except that (1) a very large value can cause you to run out of + alignable memory (and fail memory allocations), and (2) smaller + values will limit the maximum size of the stack (hence the naming + of this configuration value). + +config TLS_NELEM + int "Number of TLS elements" + default 1 + ---help--- + The number of unique TLS elements. These can be accessed with + the user library functions tls_get_element() and tls_set_element(). + +endif # TLS + config LIBC_NETDB bool default n diff --git a/libc/Makefile b/libc/Makefile index d83957a95c..f07366f076 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -61,30 +61,31 @@ CSRCS = DEPPATH := --dep-path . VPATH := . -include stdio/Make.defs -include stdlib/Make.defs -include unistd/Make.defs -include sched/Make.defs -include syslog/Make.defs -include string/Make.defs include aio/Make.defs -include pthread/Make.defs -include semaphore/Make.defs -include signal/Make.defs -include math/Make.defs +include audio/Make.defs +include dirent/Make.defs include fixedmath/Make.defs +include libgen/Make.defs +include math/Make.defs +include misc/Make.defs include net/Make.defs include netdb/Make.defs -include time/Make.defs -include libgen/Make.defs -include dirent/Make.defs -include termios/Make.defs -include spawn/Make.defs +include pthread/Make.defs include queue/Make.defs +include sched/Make.defs +include semaphore/Make.defs +include signal/Make.defs +include spawn/Make.defs +include stdio/Make.defs +include stdlib/Make.defs +include string/Make.defs include symtab/Make.defs +include syslog/Make.defs +include termios/Make.defs +include time/Make.defs +include tls/Make.defs +include unistd/Make.defs include wqueue/Make.defs -include misc/Make.defs -include audio/Make.defs # REVISIT: Backslash causes problems in $(COBJS) target DELIM := $(strip /) diff --git a/sched/tls/Make.defs b/libc/tls/Make.defs similarity index 94% rename from sched/tls/Make.defs rename to libc/tls/Make.defs index a200777001..c948e07194 100644 --- a/sched/tls/Make.defs +++ b/libc/tls/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# sched/tls/Make.defs +# libc/tls/Make.defs # # Copyright (C) 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -35,13 +35,7 @@ ifeq ($(CONFIG_TLS),y) -ifeq ($(CONFIG_SMP),y) -CSRCS += tls_cpuindex.c -endif - -ifneq ($(CONFIG_TLS_NELEM),0) CSRCS += tls_setelem.c tls_getelem.c -endif # Include tls build support diff --git a/sched/tls/tls.h b/libc/tls/tls.h similarity index 100% rename from sched/tls/tls.h rename to libc/tls/tls.h diff --git a/sched/tls/tls_getelem.c b/libc/tls/tls_getelem.c similarity index 97% rename from sched/tls/tls_getelem.c rename to libc/tls/tls_getelem.c index 9a11a5194b..a7a10299fc 100644 --- a/sched/tls/tls_getelem.c +++ b/libc/tls/tls_getelem.c @@ -44,8 +44,9 @@ #include #include +#include -#if defined(CONFIG_TLS) && CONFIG_TLS_NELEM > 0 +#ifdef CONFIG_TLS /**************************************************************************** * Public Functions @@ -89,4 +90,4 @@ uintptr_t tls_get_element(int elem) return ret; } -#endif /* CONFIG_TLS && CONFIG_TLS_NELEM > 0 */ +#endif /* CONFIG_TLS */ diff --git a/sched/tls/tls_setelem.c b/libc/tls/tls_setelem.c similarity index 97% rename from sched/tls/tls_setelem.c rename to libc/tls/tls_setelem.c index cca74adee3..14152590da 100644 --- a/sched/tls/tls_setelem.c +++ b/libc/tls/tls_setelem.c @@ -44,8 +44,9 @@ #include #include +#include -#if defined(CONFIG_TLS) && CONFIG_TLS_NELEM > 0 +#ifdef CONFIG_TLS /**************************************************************************** * Public Functions @@ -85,4 +86,4 @@ void tls_set_element(int elem, uintptr_t value) } } -#endif /* CONFIG_TLS && CONFIG_TLS_NELEM > 0 */ +#endif /* CONFIG_TLS */ diff --git a/sched/Kconfig b/sched/Kconfig index d1f4471b1e..66c9f02459 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -503,49 +503,6 @@ config SCHED_WAITPID endmenu # Tasks and Scheduling -config ARCH_HAVE_TLS - bool - default n - ---help--- - Selected by the configuration system if the current architecture - supports TLS. - -menuconfig TLS - bool "Thread Local Storage (TLS)" - default n - depends on ARCH_HAVE_TLS - ---help--- - Build in support for stack based thread local storage (TLS). - -if TLS - -config TLS_LOG2_MAXSTACK - int "Maximum stack size (log2)" - default 13 - range 11 24 - ---help--- - Stack based TLS works by fetch thread information from the beginning - of the stack memory allocation. In order to do this, the memory - must be aligned in such a way that the executing logic can simply - masking the current stack pointer to get the beginning of the stack - allocation. - - This setting specifies the alignment of the stack as a power of 2: - 11=2KB, 12=4KB, 13=8KB, etc. The exact alignment is not so critical - except that (1) a very large value can cause you to run out of - alignable memory (and fail memory allocations), and (2) smaller - values will limit the maximum size of the stack (hence the naming - of this configuration value). - -config TLS_NELEM - int "Number of TLS elements" - default 0 - ---help--- - The number of unique TLS elements. These can be accessed with - tls_get_element() and tls_set_element(). - -endif # TLS - menu "Pthread Options" depends on !DISABLE_PTHREAD diff --git a/sched/Makefile b/sched/Makefile index 6a07d4a194..63d1c519ed 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -56,7 +56,6 @@ include semaphore/Make.defs include signal/Make.defs include task/Make.defs include timer/Make.defs -include tls/Make.defs include wdog/Make.defs include wqueue/Make.defs diff --git a/sched/tls/tls_cpuindex.c b/sched/tls/tls_cpuindex.c deleted file mode 100644 index b906d0ade9..0000000000 --- a/sched/tls/tls_cpuindex.c +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - * libc/fixedmath/tls_cpuindex.c - * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include - -#if defined(CONFIG_TLS) && defined(CONFIG_SMP) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: tls_cpu_index - * - * Description: - * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that - * corresponds to the currently executing CPU. This is index is retained - * in the task TCB which is accessible via the tls_info_s structure. - * - * There is a race condition in that this thread could be swapped out and - * be running on a different CPU when the function returns. If that is a - * problem, then the calling function should disable pre-emption before - * calling this function. - * - * Input Parameters: - * None - * - * Returned Value: - * On success, an integer index is returned in the range of 0 through - * (CONFIG_SMP_NCPUS-1) that corresponds to the currently executing CPU. - * - ****************************************************************************/ - -int tls_cpu_index(void) -{ - FAR struct tls_info_s *info; - FAR struct tcb_s *tcb; - - /* Get the TLS info structure from the current threads stack */ - - info = up_tls_info(); - DEBUGASSERT(info != NULL && info->tl_tcb != NULL); - - /* Get the TCB from the TLS info. We expect the TCB state to indicate that - * the task is running (it must be because it is this thread). - */ - - tcb = info->tl_tcb; - DEBUGASSERT(tcb->task_state == TSTATE_TASK_RUNNING && - tcb->cpu <= (CONFIG_SMP_NCPUS-1)); - - return tcb->cpu; -} - -#endif /* CONFIG_TLS && CONFIG_SMP */ -- GitLab From 8cff133a1ce32386ee54eaa91e34763839589de1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Mar 2016 12:31:44 -0600 Subject: [PATCH 845/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index bc619710ab..ec1d206017 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bc619710ab72168bc8ad658deb344e68caf7dcf4 +Subproject commit ec1d206017d1e24feb3b2a1746f3302894c6cfc0 diff --git a/configs b/configs index dc86e1cc52..6f89f1dfc4 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit dc86e1cc52689e67e33f6c47ca0b2a3d4aa783a4 +Subproject commit 6f89f1dfc41638ae56f4d64415a45c70c7c88981 -- GitLab From a193e669d1ffe3924453a01b317b2bf32d6d04d8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Mar 2016 11:47:23 -0600 Subject: [PATCH 846/858] Update submodules --- arch | 2 +- configs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch b/arch index ec1d206017..e88525e003 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ec1d206017d1e24feb3b2a1746f3302894c6cfc0 +Subproject commit e88525e003cb18f916094e77a93a0eaa3c3e5358 diff --git a/configs b/configs index 6f89f1dfc4..e3b7df36bd 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 6f89f1dfc41638ae56f4d64415a45c70c7c88981 +Subproject commit e3b7df36bd6d8603b99917a3450a133d4edb53dd -- GitLab From 320b70ebad4cf82c8f1d9c0ef031711490f8c340 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Mar 2016 13:24:38 -0600 Subject: [PATCH 847/858] Update submodules --- arch | 2 +- configs | 2 +- sched/irq/irq.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch b/arch index e88525e003..211160ebe8 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e88525e003cb18f916094e77a93a0eaa3c3e5358 +Subproject commit 211160ebe8733a5456a49b88ef4c27482690b5d6 diff --git a/configs b/configs index e3b7df36bd..0ef97e910a 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e3b7df36bd6d8603b99917a3450a133d4edb53dd +Subproject commit 0ef97e910a44060bd20b5e96517344a324e965c3 diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 36742f062b..544be675d2 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -112,4 +112,3 @@ int irq_unexpected_isr(int irq, FAR void *context); #endif #endif /* __SCHED_IRQ_IRQ_H */ - -- GitLab From 79c1fa5bd75f9b13efb02688505d8cf7a748b50c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 12 Mar 2016 15:29:33 -0600 Subject: [PATCH 848/858] SMP: Simplified SMP interfaces --- arch | 2 +- include/nuttx/arch.h | 3 +- sched/init/init.h | 27 +++++++++++++--- sched/init/os_smpstart.c | 67 ++++++++++++++++++++++++++++++++-------- sched/init/os_start.c | 6 ++-- 5 files changed, 83 insertions(+), 22 deletions(-) diff --git a/arch b/arch index 211160ebe8..9336bbac1c 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 211160ebe8733a5456a49b88ef4c27482690b5d6 +Subproject commit 9336bbac1c82d417d65d0a973359e4fad25e2dd1 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 0a176653fd..04caec1319 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1743,7 +1743,6 @@ int up_cpu_index(void); * cpu - The index of the CPU being started. This will be a numeric * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU * 0 is already active) - * idletask - The entry point to the IDLE task. * * Returned Value: * Zero on success; a negated errno value on failure. @@ -1751,7 +1750,7 @@ int up_cpu_index(void); ****************************************************************************/ #ifdef CONFIG_SMP -int up_cpu_start(int cpu, main_t idletask); +int up_cpu_start(int cpu); #endif /**************************************************************************** diff --git a/sched/init/init.h b/sched/init/init.h index 1d95df1f6c..4724c83392 100644 --- a/sched/init/init.h +++ b/sched/init/init.h @@ -65,7 +65,7 @@ void os_start(void); /**************************************************************************** - * Name: os_smpstart + * Name: os_smp_start * * Description: * In an SMP configution, only one CPU is initially active (CPU 0). System @@ -82,11 +82,11 @@ void os_start(void); ****************************************************************************/ #ifdef CONFIG_SMP -int os_smpstart(void); +int os_smp_start(void); #endif /**************************************************************************** - * Name: os_idletask + * Name: os_idle_trampoline * * Description: * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). @@ -101,7 +101,26 @@ int os_smpstart(void); ****************************************************************************/ #ifdef CONFIG_SMP -int os_idletask(int argc, FAR char *argv[]); +void os_idle_trampoline(void); +#endif + +/**************************************************************************** + * Name: os_idle_task + * + * Description: + * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). + * It is equivalent to the CPU 0 IDLE logic in os_start.c + * + * Input Parameters: + * Standard task arguments. + * + * Returned Value: + * This function does not return. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int os_idle_task(int argc, FAR char *argv[]); #endif /**************************************************************************** diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 215cdd45fc..3a0aa8d470 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include @@ -74,11 +73,11 @@ static const char g_idlename[] = "CPUn Idle" #endif /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: os_idletask + * Name: os_idle_trampoline * * Description: * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). @@ -92,7 +91,33 @@ static const char g_idlename[] = "CPUn Idle" * ****************************************************************************/ -int os_idletask(int argc, FAR char *argv[]) +void os_idle_trampoline(void) +{ + /* Transfer control to the IDLE task */ + + (void)os_idle_task(0, NULL); + + /* The IDLE task should never return */ + + PANIC(); +} + +/**************************************************************************** + * Name: os_idle_task + * + * Description: + * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). + * It is equivalent to the CPU 0 IDLE logic in os_start.c + * + * Input Parameters: + * Standard task arguments. + * + * Returned Value: + * This function does not return. + * + ****************************************************************************/ + +int os_idle_task(int argc, FAR char *argv[]) { /* Enter the IDLE loop */ @@ -133,11 +158,7 @@ int os_idletask(int argc, FAR char *argv[]) } /**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: os_smpstart + * Name: os_smp_start * * Description: * In an SMP configution, only one CPU is initially active (CPU 0). System @@ -157,18 +178,38 @@ int os_idletask(int argc, FAR char *argv[]) * ****************************************************************************/ -int os_smpstart(void) +int os_smp_start(void) { int ret; int cpu; - /* CPU0 is already running. Start the remaining CPUs */ + /* Create a stack for all CPU IDLE threads (except CPU0 which already has + * a stack). + */ + + for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++) + { + FAR struct tcb_s *tcb = current_task(cpu); + DEBUGASSERT(tcb != NULL); + + ret = up_create_stack(tcb, CONFIG_SMP_IDLETHREAD_STACKSIZE, + TCB_FLAG_TTYPE_KERNEL); + if (ret < 0) + { + sdbg("ERROR: Failed to allocate stack for CPU%d\n", cpu); + return ret; + } + } + + /* Then start all of the other CPUs after we have completed the memory + * allocations. CPU0 is already running. + */ for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++) { - /* And start the CPU. */ + /* Start the CPU */ - ret = up_cpu_start(cpu, os_idletask); + ret = up_cpu_start(cpu); if (ret < 0) { sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret); diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 8858a58341..1e0a90b916 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -453,11 +453,13 @@ void os_start(void) #ifdef CONFIG_SMP if (cpu > 0) { - g_idletcb[cpu].cmn.entry.main = os_idletask; + g_idletcb[cpu].cmn.start = os_idle_trampoline; + g_idletcb[cpu].cmn.entry.main = os_idle_task; } else #endif { + g_idletcb[cpu].cmn.start = (start_t)os_start; g_idletcb[cpu].cmn.entry.main = (main_t)os_start; } @@ -762,7 +764,7 @@ void os_start(void) /* Then start the other CPUs */ - DEBUGVERIFY(os_smpstart()); + DEBUGVERIFY(os_smp_start()); #endif /* CONFIG_SMP */ -- GitLab From 2225940155a9c06b72eef109ea95f689f88959f4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Mar 2016 07:16:56 -0600 Subject: [PATCH 849/858] SMP: Add per-CPU initialization logic --- arch | 2 +- include/nuttx/arch.h | 22 ++++++++++++++++++++++ sched/init/os_smpstart.c | 15 +++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/arch b/arch index 9336bbac1c..e1ae334ff0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 9336bbac1c82d417d65d0a973359e4fad25e2dd1 +Subproject commit e1ae334ff043872b3678fc7fd48bea6125e8ea44 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 04caec1319..0603d8f662 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1753,6 +1753,28 @@ int up_cpu_index(void); int up_cpu_start(int cpu); #endif +/**************************************************************************** + * Name: up_cpu_initialize + * + * Description: + * After the CPU has been started (via up_cpu_start()) the system will + * call back into the architecture-specific code with this function on the + * thread of execution of the newly started CPU. This gives the + * architecture-specific a chance to perform ny initial, CPU-specific + * initialize on that thread. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +int up_cpu_initialize(void); +#endif + /**************************************************************************** * Name: up_cpu_pause * diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 3a0aa8d470..5c43b9beff 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -80,11 +80,14 @@ static const char g_idlename[] = "CPUn Idle" * Name: os_idle_trampoline * * Description: - * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). - * It is equivalent to the CPU 0 IDLE logic in os_start.c + * This is the common start-up logic for the IDLE task for CPUs 1 through + * (CONFIG_SMP_NCPUS-1). Having a start-up function such as this for the + * IDLE is not really an architectural necessity. It is used only for + * symmetry with now other threads are started (see task_start() and + * pthread_start()). * * Input Parameters: - * Standard task arguments. + * None. * * Returned Value: * This function does not return. @@ -93,7 +96,11 @@ static const char g_idlename[] = "CPUn Idle" void os_idle_trampoline(void) { - /* Transfer control to the IDLE task */ + /* Perform architecture-specific initialization for this CPU */ + + up_cpu_initialize(); + + /* Then transfer control to the IDLE task */ (void)os_idle_task(0, NULL); -- GitLab From 266980b828492344233f0f8472eaf78fc250a9fc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Mar 2016 10:13:01 -0600 Subject: [PATCH 850/858] Upate submodules --- Documentation | 2 +- arch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation b/Documentation index a671bbd607..828f2ee5b4 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit a671bbd607e6b2e57b017b440286da99f57121d1 +Subproject commit 828f2ee5b4457168a75c4f3c403c17e7d7605209 diff --git a/arch b/arch index e1ae334ff0..5732800564 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit e1ae334ff043872b3678fc7fd48bea6125e8ea44 +Subproject commit 57328005643fab97828d3deb4a1cd3db70d89b02 -- GitLab From 5675600946a88f350738086cedd4d2c659dbf0a9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 13 Mar 2016 12:08:09 -0600 Subject: [PATCH 851/858] Correct some comments --- Documentation | 2 +- include/nuttx/arch.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation b/Documentation index 828f2ee5b4..d1d8974e7a 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 828f2ee5b4457168a75c4f3c403c17e7d7605209 +Subproject commit d1d8974e7a8c743ed2ee102a93ad73478755a080 diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 0603d8f662..da9296af2d 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1692,7 +1692,7 @@ int up_timer_start(FAR const struct timespec *ts); * Returned Value: * The spinlock is always locked upon return. The value of previous value * of the spinlock variable is returned, either SP_LOCKED if the spinlock - * as previously locked (meaning that the test-and-set operation failed to + * was previously locked (meaning that the test-and-set operation failed to * obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked * (meaning that we successfully obtained the lock) * @@ -1733,7 +1733,7 @@ int up_cpu_index(void); * * Each CPU is provided the entry point to is IDLE task when started. A * TCB for each CPU's IDLE task has been initialized and placed in the - * CPU's g_assignedtasks[cpu] list. Not stack has been alloced or + * CPU's g_assignedtasks[cpu] list. A stack has also been allocateded and * initialized. * * The OS initialization logic calls this function repeatedly until each @@ -1788,7 +1788,7 @@ int up_cpu_initialize(void); * CPU. * * Input Parameters: - * cpu - The index of the CPU to be stopped/ + * cpu - The index of the CPU to be paused. * * Returned Value: * Zero on success; a negated errno value on failure. @@ -1811,7 +1811,7 @@ int up_cpu_pause(int cpu); * the CPU after modifying its g_assignedtasks[cpu] list. * * Input Parameters: - * cpu - The index of the CPU being re-started. + * cpu - The index of the CPU being resumed. * * Returned Value: * Zero on success; a negated errno value on failure. -- GitLab From e879d0f423d8f98b6400578128af39b02ee4773b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 16 Mar 2016 11:00:31 -0600 Subject: [PATCH 852/858] Move scheduler instrumentation hooks out of sched.h (where they seem like application interfaces) and into nuttx/sched.h where it is clare that these are OS internal interfaces. --- arch | 2 +- configs | 2 +- drivers/syslog/Kconfig | 1 - include/cxx/csched | 5 ----- include/nuttx/sched.h | 43 ++++++++++++++++++++++++++++++++++++++++++ include/sched.h | 39 ++++---------------------------------- 6 files changed, 49 insertions(+), 43 deletions(-) diff --git a/arch b/arch index 5732800564..ff28c33a23 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 57328005643fab97828d3deb4a1cd3db70d89b02 +Subproject commit ff28c33a233e86ab8d96434dcd87ccd5402e505b diff --git a/configs b/configs index 0ef97e910a..e147b03efb 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 0ef97e910a44060bd20b5e96517344a324e965c3 +Subproject commit e147b03efbd424a972e1dd61707c6182b90174f7 diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index e450d52de1..bdbc4c34f8 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -82,4 +82,3 @@ config SYSLOG_CONSOLE output (syslog_putc). This is useful, for example, if the only console is a Telnet console. Then in that case, console output from non-Telnet threads will go to the syslog output. - diff --git a/include/cxx/csched b/include/cxx/csched index 262782888c..f320a82a11 100644 --- a/include/cxx/csched +++ b/include/cxx/csched @@ -64,11 +64,6 @@ namespace std using ::sched_lock; using ::sched_unlock; using ::sched_lockcount; -#ifdef CONFIG_SCHED_INSTRUMENTATION - using ::sched_note_start; - using ::sched_note_stop; - using ::sched_note_switch; -#endif } #endif // __INCLUDE_CXX_CSCHED diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index b4f3d055fa..5dd13b692a 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -843,6 +843,49 @@ void sched_suspend_scheduler(FAR struct tcb_s *tcb); # define sched_suspend_scheduler(tcb) #endif +/******************************************************************************** + * Name: sched_note_* + * + * Description: + * If instrumentation of the scheduler is enabled, then some outboard logic + * must provide the following interfaces. These interfaces are not availalble + * to application code. + * + * Input Parameters: + * tcb - The TCB of the thread to be restarted. + * + * Returned Value: + * None + * + ********************************************************************************/ + +#ifdef CONFIG_SCHED_INSTRUMENTATION + +void sched_note_start(FAR struct tcb_s *tcb); +void sched_note_stop(FAR struct tcb_s *tcb); +void sched_note_switch(FAR struct tcb_s *fromtcb, + FAR struct tcb_s *totcb); + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +void sched_note_premption(FAR struct tcb_s *tcb, bool locked); +#else +# define sched_note_premption(t,l) +#endif + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +void sched_note_csection(FAR struct tcb_s *tcb, bool enter); +#else +# define sched_note_csection(t,e) +#endif + +#else +# define sched_note_start(t) +# define sched_note_stop(t) +# define sched_note_switch(t1, t2) +# define sched_note_premption(t,l) +# define sched_note_csection(t,e) +#endif /* CONFIG_SCHED_INSTRUMENTATION */ + #undef EXTERN #if defined(__cplusplus) } diff --git a/include/sched.h b/include/sched.h index 54501644bf..b9a21f0f6f 100644 --- a/include/sched.h +++ b/include/sched.h @@ -243,10 +243,10 @@ int sched_rr_get_interval(pid_t pid, FAR struct timespec *interval); #ifdef CONFIG_SMP /* Task affinity */ -int sched_setaffinity(pid_t pid, size_t cpusetsize, - FAR const cpu_set_t *mask); -int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask); -int sched_cpu_count(FAR const cpu_set_t *set); +int sched_setaffinity(pid_t pid, size_t cpusetsize, + FAR const cpu_set_t *mask); +int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask); +int sched_cpu_count(FAR const cpu_set_t *set); #endif /* CONFIG_SMP */ /* Task Switching Interfaces (non-standard) */ @@ -255,37 +255,6 @@ int sched_lock(void); int sched_unlock(void); int sched_lockcount(void); -/* If instrumentation of the scheduler is enabled, then some outboard logic - * must provide the following interfaces. - */ - -#ifdef CONFIG_SCHED_INSTRUMENTATION - -void sched_note_start(FAR struct tcb_s *tcb); -void sched_note_stop(FAR struct tcb_s *tcb); -void sched_note_switch(FAR struct tcb_s *fromtcb, - FAR struct tcb_s *totcb); - -#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION -void sched_note_premption(FAR struct tcb_s *tcb, bool locked); -#else -# define sched_note_premption(t,l) -#endif - -#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION -void sched_note_csection(FAR struct tcb_s *tcb, bool enter); -#else -# define sched_note_csection(t,e) -#endif - -#else -# define sched_note_start(t) -# define sched_note_stop(t) -# define sched_note_switch(t1, t2) -# define sched_note_premption(t,l) -# define sched_note_csection(t,e) -#endif /* CONFIG_SCHED_INSTRUMENTATION */ - #undef EXTERN #if defined(__cplusplus) } -- GitLab From 0369facbd5b2c38af227190a2fc8a04d0af5fb83 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 16 Mar 2016 11:01:19 -0600 Subject: [PATCH 853/858] Fix some spacing --- include/nuttx/sched.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 5dd13b692a..b48966ed3a 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -861,10 +861,9 @@ void sched_suspend_scheduler(FAR struct tcb_s *tcb); #ifdef CONFIG_SCHED_INSTRUMENTATION -void sched_note_start(FAR struct tcb_s *tcb); -void sched_note_stop(FAR struct tcb_s *tcb); -void sched_note_switch(FAR struct tcb_s *fromtcb, - FAR struct tcb_s *totcb); +void sched_note_start(FAR struct tcb_s *tcb); +void sched_note_stop(FAR struct tcb_s *tcb); +void sched_note_switch(FAR struct tcb_s *fromtcb, FAR struct tcb_s *totcb); #ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION void sched_note_premption(FAR struct tcb_s *tcb, bool locked); -- GitLab From 1951b9df57740b1b2978ac85da87fec31a528f74 Mon Sep 17 00:00:00 2001 From: Max Neklyudov Date: Thu, 17 Mar 2016 07:37:45 -0600 Subject: [PATCH 854/858] Improve m25px driver --- Documentation | 2 +- drivers/mtd/Kconfig | 4 ++++ drivers/mtd/m25px.c | 10 +++++++++- include/nuttx/sched.h | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation b/Documentation index d1d8974e7a..35343cbe66 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit d1d8974e7a8c743ed2ee102a93ad73478755a080 +Subproject commit 35343cbe6660bb07d9fee4c2e5af0dd450313c14 diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index b3bd84d703..5f04bccd60 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -408,6 +408,10 @@ config M25P_SPIMODE int "M25P SPI mode" default 0 +config M25P_SPIFREQUENCY + int "M25P SPI Frequency" + default 20000000 + config M25P_MANUFACTURER hex "M25P manufacturers ID" default 0x20 diff --git a/drivers/mtd/m25px.c b/drivers/mtd/m25px.c index 3a9bda2c9d..f117c10d91 100644 --- a/drivers/mtd/m25px.c +++ b/drivers/mtd/m25px.c @@ -69,6 +69,10 @@ # define CONFIG_M25P_SPIMODE SPIDEV_MODE0 #endif +#ifndef CONFIG_M25P_SPIFREQUENCY +# define CONFIG_M25P_SPIFREQUENCY 20000000 +#endif + /* Various manufacturers may have produced the parts. 0x20 is the manufacturer ID * for the STMicro MP25x serial FLASH. If, for example, you are using the a Macronix * International MX25 serial FLASH, the correct manufacturer ID would be 0xc2. @@ -137,6 +141,7 @@ #define M25P_M25P32_NSECTORS 64 #define M25P_M25P32_PAGE_SHIFT 8 /* Page size 1 << 8 = 256 */ #define M25P_M25P32_NPAGES 16384 +#define M25P_M25PX32_SUBSECT_SHIFT 12 /* Sub-Sector size 1 << 12 = 4,096 */ /* M25P64 capacity is 8,338,608 bytes: * (128 sectors) * (65,536 bytes per sector) @@ -285,7 +290,7 @@ static void m25p_lock(FAR struct spi_dev_s *dev) SPI_SETMODE(dev, CONFIG_M25P_SPIMODE); SPI_SETBITS(dev, 8); (void)SPI_HWFEATURES(dev, 0); - (void)SPI_SETFREQUENCY(dev, 20000000); + (void)SPI_SETFREQUENCY(dev, CONFIG_M25P_SPIFREQUENCY); } /************************************************************************************ @@ -383,6 +388,9 @@ static inline int m25p_readid(struct m25p_dev_s *priv) priv->nsectors = M25P_M25P32_NSECTORS; priv->pageshift = M25P_M25P32_PAGE_SHIFT; priv->npages = M25P_M25P32_NPAGES; +#ifdef CONFIG_M25P_SUBSECTOR_ERASE + priv->subsectorshift = M25P_M25PX32_SUBSECT_SHIFT; +#endif return OK; } else if (capacity == M25P_M25P64_CAPACITY) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index b48966ed3a..ac5f9b799a 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -852,7 +852,7 @@ void sched_suspend_scheduler(FAR struct tcb_s *tcb); * to application code. * * Input Parameters: - * tcb - The TCB of the thread to be restarted. + * tcb - The TCB of the thread. * * Returned Value: * None -- GitLab From 7f19631338005d35d5d628ed34ee0f948282ac25 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Mar 2016 09:49:43 -0600 Subject: [PATCH 855/858] sched/: Add option to buffer scheduler instrumentation data in memory. --- ChangeLog | 3 + include/nuttx/sched.h | 42 --- include/nuttx/sched_note.h | 219 ++++++++++++ sched/Kconfig | 48 ++- sched/init/os_smpstart.c | 10 + sched/init/os_start.c | 6 + sched/irq/irq_csection.c | 1 + sched/sched/Make.defs | 4 + sched/sched/sched_addreadytorun.c | 2 + sched/sched/sched_lock.c | 2 + sched/sched/sched_mergepending.c | 2 + sched/sched/sched_note.c | 491 +++++++++++++++++++++++++++ sched/sched/sched_removereadytorun.c | 2 + sched/sched/sched_unlock.c | 1 + sched/task/task_activate.c | 1 + sched/task/task_terminate.c | 1 + 16 files changed, 789 insertions(+), 46 deletions(-) create mode 100644 include/nuttx/sched_note.h create mode 100644 sched/sched/sched_note.c diff --git a/ChangeLog b/ChangeLog index 86444d10c2..3f3c141f51 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11562,4 +11562,7 @@ * sched/tls and include/nuttx/tls.h: Basic definitions needed to support thread local storage (TLS). Not used anywhere yet (and may not be used in the near future either) (2016-03-10). + * sched/sched_note.c and include/nuttx/sched_note.c: Add a configuration + option to buffer RTOS instrumentation data in an in-memory buffer + (2016-03-17). diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index ac5f9b799a..b4f3d055fa 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -843,48 +843,6 @@ void sched_suspend_scheduler(FAR struct tcb_s *tcb); # define sched_suspend_scheduler(tcb) #endif -/******************************************************************************** - * Name: sched_note_* - * - * Description: - * If instrumentation of the scheduler is enabled, then some outboard logic - * must provide the following interfaces. These interfaces are not availalble - * to application code. - * - * Input Parameters: - * tcb - The TCB of the thread. - * - * Returned Value: - * None - * - ********************************************************************************/ - -#ifdef CONFIG_SCHED_INSTRUMENTATION - -void sched_note_start(FAR struct tcb_s *tcb); -void sched_note_stop(FAR struct tcb_s *tcb); -void sched_note_switch(FAR struct tcb_s *fromtcb, FAR struct tcb_s *totcb); - -#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION -void sched_note_premption(FAR struct tcb_s *tcb, bool locked); -#else -# define sched_note_premption(t,l) -#endif - -#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION -void sched_note_csection(FAR struct tcb_s *tcb, bool enter); -#else -# define sched_note_csection(t,e) -#endif - -#else -# define sched_note_start(t) -# define sched_note_stop(t) -# define sched_note_switch(t1, t2) -# define sched_note_premption(t,l) -# define sched_note_csection(t,e) -#endif /* CONFIG_SCHED_INSTRUMENTATION */ - #undef EXTERN #if defined(__cplusplus) } diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h new file mode 100644 index 0000000000..dd7ca875a0 --- /dev/null +++ b/include/nuttx/sched_note.h @@ -0,0 +1,219 @@ +/**************************************************************************** + * include/nuttx/sched_note.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SCHED_NOTE_H +#define __INCLUDE_NUTTX_SCHED_NOTE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#ifdef CONFIG_SCHED_INSTRUMENTATION + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifdef CONFIG_SCHED_INSTRUMENTATION_BUFFER + +/* This type identifies a note structure */ + +enum note_type_e +{ + NOTE_START = 0, + NOTE_STOP, + NOTE_SWITCH +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + , + NOTE_PREEMPT_LOCK, + NOTE_PREEMPT_UNLOCK +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + , + NOTE_CSECTION_ENTER, + NOTE_CSECTION_LEAVE +#endif +}; + +/* This structure provides the common header of each note */ + +struct note_common_s +{ + uint8_t nc_length; /* Length of the note */ + uint8_t nc_type; /* See enum note_type_e */ + uint8_t nc_systime[4]; /* Time when note buffered */ +}; + +/* This is the specific form of the NOTE_START note */ + +struct note_start_s +{ + uint8_t nst_length; /* Length of the note */ + uint8_t nst_type; /* Must be NOTE_START */ + uint8_t nst_systime[4]; /* Time when note buffered */ + uint8_t nst_pid[2]; /* ID of the new thread/task */ +#if CONFIG_TASK_NAME_SIZE > 0 + char nst_name[1]; /* Start of the name of the thread/task */ +#endif +}; + +/* This is the specific form of the NOTE_STOP note */ + +struct note_stop_s +{ + uint8_t nsp_length; /* Length of the note */ + uint8_t nsp_type; /* Must be NOTE_STOP */ + uint8_t nsp_systime[4]; /* Time when note buffered */ + uint8_t nsp_pid[2]; /* ID of the thread/task that stopped */ +}; + +/* This is the specific form of the NOTE_SWITCH note */ + +struct note_switch_s +{ + uint8_t nsw_length; /* Length of the note */ + uint8_t nsw_type; /* Must be NOTE_SWITCH */ + uint8_t nsw_systime[4]; /* Time when note buffered */ + uint8_t nsw_pidout[2]; /* ID of the thread/task that was blocked */ + uint8_t nsw_pidin[2]; /* ID of the thread/task that was started */ +}; + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +/* This is the specific form of the NOTE_PREEMPT_LOCK/UNLOCK note */ + +struct note_preempt_s +{ + uint8_t npr_length; /* Length of the note */ + uint8_t npr_type; /* Must be NOTE_PREEMPT_LOCK or _UNLOCK */ + uint8_t npr_systime[4]; /* Time when note buffered */ + uint8_t npr_pid[2]; /* ID of the thread/task that change pre-emption */ + uint8_t npr_count[2]; /* Count of nested locks */ +}; +#endif /* CONFIG_SCHED_INSTRUMENTATION_PREEMPTION */ + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +/* This is the specific form of the NOTE_CSECTION_ENTER/LEAVE note */ + +struct note_csection_s +{ + uint8_t ncs_length; /* Length of the note */ + uint8_t ncs_type; /* Must be NOTE_CSECTION_ENTER or _LEAVE */ + uint8_t ncs_systime[4]; /* Time when note buffered */ + uint8_t ncs_pid[2]; /* ID of the thread/task that changed critical section */ +#ifdef CONFIG_SMP + uint8_t ncs_count[2]; /* Count of nested csections */ +#endif +}; +#endif /* CONFIG_SCHED_INSTRUMENTATION_CSECTION */ +#endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER */ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/******************************************************************************** + * Name: sched_note_* + * + * Description: + * If instrumentation of the scheduler is enabled, then some outboard logic + * must provide the following interfaces. These interfaces are not availalble + * to application code. + * + * NOTE: if CONFIG_SCHED_INSTRUMENTATION_BUFFER, then these interfaces are + * *not* available to the platform-specific logic. Rather, they provided by + * the note buffering logic. See sched_note_get() below. + * + * Input Parameters: + * tcb - The TCB of the thread. + * + * Returned Value: + * None + * + ********************************************************************************/ + +void sched_note_start(FAR struct tcb_s *tcb); +void sched_note_stop(FAR struct tcb_s *tcb); +void sched_note_switch(FAR struct tcb_s *fromtcb, FAR struct tcb_s *totcb); + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +void sched_note_premption(FAR struct tcb_s *tcb, bool locked); +#endif + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +void sched_note_csection(FAR struct tcb_s *tcb, bool enter); +#endif + +/**************************************************************************** + * Name: sched_note_get + * + * Description: + * Remove the next note from the tail of the circular buffer. The note + * is also removed from the circular buffer to make room for futher notes. + * + * Input Parameters: + * buffer - Location to return the next note + * buflen - The length of the user provided buffer. + * + * Returned Value: + * None + * + * Assumptions: + * On success, the length of the return note is provided. A negated + * errno value is returned on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_INSTRUMENTATION_BUFFER +ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen); +#endif + +#else /* CONFIG_SCHED_INSTRUMENTATION */ + +# define sched_note_start(t) +# define sched_note_stop(t) +# define sched_note_switch(t1, t2) +# define sched_note_premption(t,l) +# define sched_note_csection(t,e) + +#endif /* CONFIG_SCHED_INSTRUMENTATION */ +#endif /* __INCLUDE_NUTTX_SCHED_NOTE_H */ diff --git a/sched/Kconfig b/sched/Kconfig index 66c9f02459..dc9d7d13d9 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -370,10 +370,10 @@ config SPORADIC_INSTRUMENTATION scheduler behavior. If enabled, then the board-specific logic must provide the following functions: - void arch_sporadic_start(FAR struct tcb_s *tcb); - void arch_sporadic_lowpriority(FAR struct tcb_s *tcb); - void arch_sporadic_suspend(FAR struct tcb_s *tcb); - void arch_sporadic_resume(FAR struct tcb_s *tcb); + void arch_sporadic_start(FAR struct tcb_s *tcb); + void arch_sporadic_lowpriority(FAR struct tcb_s *tcb); + void arch_sporadic_suspend(FAR struct tcb_s *tcb); + void arch_sporadic_resume(FAR struct tcb_s *tcb); endif # SCHED_SPORADIC @@ -605,7 +605,15 @@ config SCHED_INSTRUMENTATION void sched_note_stop(FAR struct tcb_s *tcb); void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb); + NOTE: These are internal OS interfaces and are called at at very + critical locations in the OS. There is very little that can be + done in these interfaces. For example, normal devices may not be + used; syslog output cannot be performed. + + An option is to use SCHED_INSTRUMENTATION_BUFFER below. + if SCHED_INSTRUMENTATION + config SCHED_INSTRUMENTATION_PREEMPTION bool "Preemption monitor hooks" default n @@ -626,6 +634,38 @@ config SCHED_INSTRUMENTATION_CSECTION void sched_note_csection(FAR struct tcb_s *tcb, bool state); +config SCHED_INSTRUMENTATION_BUFFER + bool "Buffer instrumentation data in memory" + default n + ---help--- + If this option is selected, then in-memory buffering logic is + enabled to capature scheduler instrumentation data. This has + the advantage that (1) the platform logic does not have to provide + the sched_note_* interaces described for the previous settings. + Instead, the buffering logic catches all of these. It encodes + timestamps the scheduler note and adds the note to an in-memory, + circular buffer. And (2) buffering the scheduler instrumentation + data (versus performing some output operation) minimizes the impact + of the instrumentation on the behavior of the system. + + If the in-memory buffer becomes full, then older notes are + overwritten by newer notes. The following interface is provided: + + ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen); + + Platform specific information must call this function and dispose + of it quickly so that overwriting of the tail of the circular buffer + does not occur. See include/nuttx/sched_note.h for additional + information. + +config SCHED_NOTE_BUFSIZE + int "Instrumentation buffer size" + default 2048 + depends on SCHED_INSTRUMENTATION_BUFFER + ---help--- + The size of the in-memory, circular instrumentation buffer (in + bytes). + endif # SCHED_INSTRUMENTATION endmenu # Performance Monitoring diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 5c43b9beff..f613344b5f 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -96,10 +96,20 @@ static const char g_idlename[] = "CPUn Idle" void os_idle_trampoline(void) { +#ifdef CONFIG_SCHED_INSTRUMENTATION + FAR struct tcb_s *tcb = this_task(); +#endif + /* Perform architecture-specific initialization for this CPU */ up_cpu_initialize(); +#ifdef CONFIG_SCHED_INSTRUMENTATION + /* Announce that the IDLE task has started */ + + sched_note_start(tcb); +#endif + /* Then transfer control to the IDLE task */ (void)os_idle_task(0, NULL); diff --git a/sched/init/os_start.c b/sched/init/os_start.c index 1e0a90b916..a8456c008a 100644 --- a/sched/init/os_start.c +++ b/sched/init/os_start.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include "sched/sched.h" @@ -708,8 +709,13 @@ void os_start(void) lib_initialize(); /* IDLE Group Initialization **********************************************/ + /* Announce that the CPU0 IDLE task has started */ + + sched_note_start(&g_idletcb[0].cmn); #ifdef CONFIG_SMP + /* Initialize the IDLE group for the IDLE task of each CPU */ + for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++) #endif { diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index e2bb1d995f..414238045e 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -42,6 +42,7 @@ #include #include +#include #include #include "sched/sched.h" diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index aa806b95aa..74ffabe1f3 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -82,6 +82,10 @@ else CSRCS += sched_processtimer.c endif +ifeq ($(CONFIG_SCHED_INSTRUMENTATION_BUFFER),y) +CSRCS += sched_note.c +endif + # Include sched build support DEPPATH += --dep-path sched diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index a105e4f545..987c91d486 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -43,6 +43,8 @@ #include #include +#include + #include "irq/irq.h" #include "sched/sched.h" diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 83ba4b8635..529ba4a07f 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -44,6 +44,8 @@ #include #include +#include + #include "sched/sched.h" /**************************************************************************** diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 48f6d58310..e314e31d69 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -44,6 +44,8 @@ #include #include +#include + #include "sched/sched.h" /**************************************************************************** diff --git a/sched/sched/sched_note.c b/sched/sched/sched_note.c new file mode 100644 index 0000000000..3838bef8cd --- /dev/null +++ b/sched/sched/sched_note.c @@ -0,0 +1,491 @@ +/**************************************************************************** + * sched/sched/sched_note.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#ifdef CONFIG_SCHED_INSTRUMENTATION_BUFFER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct note_info_s +{ + unsigned int ni_head; + unsigned int ni_tail; + uint8_t ni_buffer[CONFIG_SCHED_NOTE_BUFSIZE]; +}; + +struct note_startalloc_s +{ + uint8_t nsa_length; + uint8_t nsa_type; + uint8_t nsa_systime[4]; + uint8_t nsa_pid[2]; +#if CONFIG_TASK_NAME_SIZE > 0 + char nsa_name[CONFIG_TASK_NAME_SIZE + 1]; +#endif +}; + +#if CONFIG_TASK_NAME_SIZE > 0 +# define SIZEOF_NOTE_START(n) (sizeof(struct note_start_s) + (n) - 1) +#else +# define SIZEOF_NOTE_START(n) (sizeof(struct note_start_s)) +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct note_info_s g_note_info; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: note_next + * + * Description: + * Return the circular buffer index at offset from the specified index + * value, handling wraparound + * + * Input Parameters: + * ndx - Old circular buffer index + * + * Returned Value: + * New circular buffer index + * + ****************************************************************************/ + +static inline unsigned int note_next(unsigned int ndx, unsigned int offset) +{ + ndx += offset; + if (ndx >= CONFIG_SCHED_NOTE_BUFSIZE) + { + ndx -= CONFIG_SCHED_NOTE_BUFSIZE; + } + + return ndx; +} + +/**************************************************************************** + * Name: note_systime + * + * Description: + * Save the current system time in the note structure as a 32-bit value. + * + * Input Parameters: + * note - The note structure to use + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void note_systime(FAR struct note_common_s *note) +{ + uint32_t systime = (uint32_t)clock_systimer(); + + /* Save the LS 32-bits of the system timer in little endian order */ + + note->nc_systime[0] = (uint8_t)( systime & 0xff); + note->nc_systime[1] = (uint8_t)((systime >> 8) & 0xff); + note->nc_systime[2] = (uint8_t)((systime >> 16) & 0xff); + note->nc_systime[3] = (uint8_t)((systime >> 24) & 0xff); +} + +/**************************************************************************** + * Name: note_length + * + * Description: + * Length of data currently in circular buffer. + * + * Input Parameters: + * None + * + * Returned Value: + * Length of data currently in circular buffer. + * + ****************************************************************************/ + +#ifdef CONFIG_DEBUG +static unsigned int note_length(void) +{ + unsigned int head = g_note_info.ni_head; + unsigned int tail = g_note_info.ni_tail; + + if (tail > head) + { + head += CONFIG_SCHED_NOTE_BUFSIZE; + } + + return head - tail; +} +#endif + +/**************************************************************************** + * Name: note_remove + * + * Description: + * Remove the variable length note from the tail of the circular buffer + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * We are within a critical section. + * + ****************************************************************************/ + +static void note_remove(void) +{ + FAR struct note_common_s *note; + unsigned int tail; + unsigned int length; + + /* Get the tail index of the circular buffer */ + + tail = g_note_info.ni_tail; + DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE); + + /* Get the length of the note at the tail index */ + + note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail]; + length = note->nc_length; + DEBUGASSERT(length <= note_length()); + + /* Increment the tail index to remove the entire note from the circular + * buffer. + */ + + g_note_info.ni_tail = note_next(tail, length); +} + +/**************************************************************************** + * Name: note_add + * + * Description: + * Add the variable length note to the head of the circular buffer + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * We are within a critical section. + * + ****************************************************************************/ + +static void note_add(FAR const uint8_t *note, uint8_t notelen) +{ + unsigned int head; + unsigned int next; + + /* Get the index to the head of the circular buffer */ + + DEBUGASSERT(note != NULL && notelen < CONFIG_SCHED_NOTE_BUFSIZE); + head = g_note_info.ni_head; + + /* Loop until all bytes have been transferred to the circular buffer */ + + while (notelen > 0) + { + /* Get the next head index. Would it collide with the current tail + * index? + */ + + next = note_next(head, 1); + if (next == g_note_info.ni_tail) + { + /* Yes, then remove the note at the tail index */ + + note_remove(); + } + + /* Save the next byte at the head index */ + + g_note_info.ni_buffer[head] = *note++; + + head = next; + notelen--; + } + + g_note_info.ni_head = head; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_note_* + * + * Description: + * These are the hooks into the scheduling instrumentation logic. Each + * simply formats the note associated with the schedule event and adds + * that note to the circular buffer. + * + * Input Parameters: + * tcb - The TCB of the thread. + * + * Returned Value: + * None + * + * Assumptions: + * We are within a critical section. + * + ****************************************************************************/ + +void sched_note_start(FAR struct tcb_s *tcb) +{ + struct note_startalloc_s note; + unsigned int length; +#if CONFIG_TASK_NAME_SIZE > 0 + int namelen; +#endif + + /* Copy the task name (if possible) and get the length of the note */ + +#if CONFIG_TASK_NAME_SIZE > 0 + namelen = strlen(tcb->name); + + DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE); + strncpy(note.nsa_name, tcb->name, CONFIG_TASK_NAME_SIZE + 1); + + length = SIZEOF_NOTE_START(namelen + 1); +#else + length = SIZEOF_NOTE_START(0) +#endif + + /* Finish formatting the note */ + + note.nsa_length = length; + note.nsa_type = NOTE_START; + note.nsa_pid[0] = (uint8_t)(tcb->pid & 0xff); + note.nsa_pid[1] = (uint8_t)((tcb->pid >> 8) & 0xff); + + note_systime((FAR struct note_common_s *)¬e); + + /* Add the note to circular buffer */ + + note_add((FAR const uint8_t *)¬e, length); +} + +void sched_note_stop(FAR struct tcb_s *tcb) +{ + struct note_stop_s note; + + /* Format the note */ + + note.nsp_length = sizeof(struct note_stop_s); + note.nsp_type = NOTE_STOP; + note.nsp_pid[0] = (uint8_t)(tcb->pid & 0xff); + note.nsp_pid[1] = (uint8_t)((tcb->pid >> 8) & 0xff); + + note_systime((FAR struct note_common_s *)¬e); + + /* Add the note to circular buffer */ + + note_add((FAR const uint8_t *)¬e, sizeof(struct note_stop_s)); +} + +void sched_note_switch(FAR struct tcb_s *fromtcb, FAR struct tcb_s *totcb) +{ + struct note_switch_s note; + + /* Format the note */ + + note.nsw_length = sizeof(struct note_switch_s); + note.nsw_type = NOTE_SWITCH; + note.nsw_pidout[0] = (uint8_t)(fromtcb->pid & 0xff); + note.nsw_pidout[1] = (uint8_t)((fromtcb->pid >> 8) & 0xff); + note.nsw_pidin[0] = (uint8_t)(totcb->pid & 0xff); + note.nsw_pidin[1] = (uint8_t)((totcb->pid >> 8) & 0xff); + + note_systime((FAR struct note_common_s *)¬e); + + /* Add the note to circular buffer */ + + note_add((FAR const uint8_t *)¬e, sizeof(struct note_switch_s)); +} + +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +void sched_note_premption(FAR struct tcb_s *tcb, bool locked) +{ + struct note_preempt_s note; + + /* Format the note */ + + note.npr_length = sizeof(struct note_preempt_s); + note.npr_type = locked ? NOTE_PREEMPT_LOCK : NOTE_PREEMPT_UNLOCK; + note.npr_pid[0] = (uint8_t)(tcb->pid & 0xff); + note.npr_pid[1] = (uint8_t)((tcb->pid >> 8) & 0xff); + note.npr_count[0] = (uint8_t)(tcb->lockcount & 0xff); + note.npr_count[1] = (uint8_t)((tcb->lockcount >> 8) & 0xff); + + note_systime((FAR struct note_common_s *)¬e); + + /* Add the note to circular buffer */ + + note_add((FAR const uint8_t *)¬e, sizeof(struct note_preempt_s)); +} +#endif + +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +void sched_note_csection(FAR struct tcb_s *tcb, bool enter) +{ + struct note_preempt_s note; + + /* Format the note */ + + note.ncs_length = sizeof(struct note_preempt_s); + note.ncs_type = enter ? NOTE_CSECTION_ENTER : NOTE_CSECTION_LEAVE; + note.ncs_pid[0] = (uint8_t)(tcb->pid & 0xff); + note.ncs_pid[1] = (uint8_t)((tcb->pid >> 8) & 0xff); +#ifdef CONFIG_SMP + note.ncs_count[0] = (uint8_t)(tcb->irqcount & 0xff); + note.ncs_count[1] = (uint8_t)((tcb->irqcount >> 8) & 0xff); +#endif + + note_systime((FAR struct note_common_s *)¬e); + + /* Add the note to circular buffer */ + + note_add((FAR const uint8_t *)¬e, sizeof(struct note_preempt_s)); +} +#endif + +/**************************************************************************** + * Name: sched_note_get + * + * Description: + * Remove the next note from the tail of the circular buffer. The note + * is also removed from the circular buffer to make room for futher notes. + * + * Input Parameters: + * buffer - Location to return the next note + * buflen - The length of the user provided buffer. + * + * Returned Value: + * None + * + * Assumptions: + * On success, the length of the return note is provided. A negated + * errno value is returned on failure. + * + ****************************************************************************/ + +ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen) +{ + FAR struct note_common_s *note; + irqstate_t flags; + unsigned int remaining; + unsigned int tail; + ssize_t notelen; + + DEBUGASSERT(buffer != NULL); + flags = enter_critical_section(); + + /* Get the index to the tail of the circular buffer */ + + tail = g_note_info.ni_tail; + DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE); + + /* Get the length of the note at the tail index */ + + note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail]; + notelen = note->nc_length; + DEBUGASSERT(notelen <= note_length()); + + /* Is the user buffer large enough to hold the note? */ + + if (buflen < notelen) + { + /* Remove the large note so that we do not get constipated. */ + + note_remove(); + + /* and return and error */ + + notelen = -EFBIG; + goto errout_with_csection; + } + + /* Loop until the note has been transferred to the user buffer */ + + remaining = (unsigned int)notelen; + while (remaining > 0) + { + /* Copy the next byte at the tail index */ + + *buffer++ = g_note_info.ni_buffer[tail]; + + /* Adjust indices and counts */ + + tail = note_next(tail, 1); + remaining--; + } + + g_note_info.ni_tail = tail; + +errout_with_csection: + leave_critical_section(flags); + return notelen; +} + +#endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER */ diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index 19e6cbed1f..84d3b25c11 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -43,6 +43,8 @@ #include #include +#include + #include "irq/irq.h" #include "sched/sched.h" diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index e08fb4482a..9a6ff5a924 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "sched/sched.h" diff --git a/sched/task/task_activate.c b/sched/task/task_activate.c index dfe7f5192a..47791c7a25 100644 --- a/sched/task/task_activate.c +++ b/sched/task/task_activate.c @@ -44,6 +44,7 @@ #include #include +#include /**************************************************************************** * Public Functions diff --git a/sched/task/task_terminate.c b/sched/task/task_terminate.c index 52e4e4c8c0..f9b115f8e4 100644 --- a/sched/task/task_terminate.c +++ b/sched/task/task_terminate.c @@ -46,6 +46,7 @@ #include #include +#include #include "sched/sched.h" #ifndef CONFIG_DISABLE_SIGNALS -- GitLab From 78e053565bdf9beea8c44e18b3ef18ede8bc93e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Mar 2016 09:50:53 -0600 Subject: [PATCH 856/858] Update submodule --- arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch b/arch index ff28c33a23..7ba04f55c0 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit ff28c33a233e86ab8d96434dcd87ccd5402e505b +Subproject commit 7ba04f55c09c7db11b4744c01db8c68a1fffdba4 -- GitLab From 3ef25dc49d4bf64ca919a9ef7564c8e1f92647ed Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Mar 2016 09:55:10 -0600 Subject: [PATCH 857/858] AT24xx: Add logic to unregister from the procfs file system if the driver is uninitialized --- drivers/mtd/at24xx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index ee324be4df..76d2cf2659 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -687,6 +687,15 @@ void at24c_uninitialize(FAR struct mtd_dev_s *mtd) { FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)mtd; DEBUGASSERT(priv != NULL); + +#ifdef CONFIG_MTD_REGISTRATION + /* Unregister the MTD with the procfs system if enabled */ + + mtd_unregister(&priv->mtd); +#endif + + /* Free the MTD driver instance */ + kmm_free(priv); } #endif /* CONFIG_AT24XX_MULTI */ -- GitLab From 242f8ff25f581ff328bf733eec669ec200933f41 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 17 Mar 2016 14:45:35 -0600 Subject: [PATCH 858/858] drivers/syslog/note_driver.c: Add a driver that will allow an application to read buffered scheduler instrumentation data --- ChangeLog | 2 + arch | 2 +- configs | 2 +- drivers/syslog/Kconfig | 8 ++ drivers/syslog/Make.defs | 30 +++++-- drivers/syslog/note_driver.c | 169 +++++++++++++++++++++++++++++++++++ include/nuttx/sched_note.h | 48 ++++++++-- sched/sched/sched_note.c | 75 ++++++++++++++-- 8 files changed, 315 insertions(+), 21 deletions(-) create mode 100644 drivers/syslog/note_driver.c diff --git a/ChangeLog b/ChangeLog index 3f3c141f51..423290c841 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11565,4 +11565,6 @@ * sched/sched_note.c and include/nuttx/sched_note.c: Add a configuration option to buffer RTOS instrumentation data in an in-memory buffer (2016-03-17). + * drivers/syslog/note_driver.c: Add a character driver that will allow + an appliation to read buffered scheduler instrumentation data (2016-03-17). diff --git a/arch b/arch index 7ba04f55c0..feb41dfa8e 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 7ba04f55c09c7db11b4744c01db8c68a1fffdba4 +Subproject commit feb41dfa8e178a1194fd17afae154bc55912993d diff --git a/configs b/configs index e147b03efb..f7c42ff4a0 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit e147b03efbd424a972e1dd61707c6182b90174f7 +Subproject commit f7c42ff4a006f5d37fa6a818aafaf20886309fd1 diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index bdbc4c34f8..d273e3d1a3 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -82,3 +82,11 @@ config SYSLOG_CONSOLE output (syslog_putc). This is useful, for example, if the only console is a Telnet console. Then in that case, console output from non-Telnet threads will go to the syslog output. + +config DRIVER_NOTE + bool "Scheduler instrumentation driver" + default n + depends on SCHED_INSTRUMENTATION_BUFFER + ---help--- + Enable building a serial driver that can be used by an application to read data + from the in-memory, scheduler instrumentatin "note" buffer. diff --git a/drivers/syslog/Make.defs b/drivers/syslog/Make.defs index c9aa7a0240..f573217d6d 100644 --- a/drivers/syslog/Make.defs +++ b/drivers/syslog/Make.defs @@ -34,6 +34,7 @@ # ############################################################################ +############################################################################ # Include SYSLOG drivers (only one should be enabled) ifeq ($(CONFIG_SYSLOG),y) @@ -47,6 +48,10 @@ ifeq ($(CONFIG_RAMLOG),y) CSRCS += ramlog.c endif +ifeq ($(CONFIG_DRIVER_NOTE),y) + CSRCS += note_driver.c +endif + # (Add other SYSLOG_CONSOLE drivers here) ifeq ($(CONFIG_SYSLOG_CONSOLE),y) @@ -58,17 +63,32 @@ endif DEPPATH += --dep-path syslog VPATH += :syslog -else - +############################################################################ # The RAMLOG can be used even if system logging is not enabled. -ifeq ($(CONFIG_RAMLOG),y) +else ifeq ($(CONFIG_RAMLOG),y) + +CSRCS += ramlog.c + +ifeq ($(CONFIG_DRIVER_NOTE),y) + CSRCS += note_driver.c +endif # Include RAMLOG build support -CSRCS += ramlog.c DEPPATH += --dep-path syslog VPATH += :syslog -endif +############################################################################ +# The scheduler note driver can be used in any event. + +else ifeq ($(CONFIG_DRIVER_NOTE),y) + +CSRCS += note_driver.c + +# Include note driver build support + +DEPPATH += --dep-path syslog +VPATH += :syslog + endif diff --git a/drivers/syslog/note_driver.c b/drivers/syslog/note_driver.c new file mode 100644 index 0000000000..5b92307917 --- /dev/null +++ b/drivers/syslog/note_driver.c @@ -0,0 +1,169 @@ +/**************************************************************************** + * drivers/syslog/note_driver.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ + defined(CONFIG_DRIVER_NOTE) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static ssize_t note_read(FAR struct file *filep, FAR char *buffer, + size_t buflen); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations note_fops = +{ + 0, /* open */ + 0, /* close */ + note_read, /* read */ + 0, /* write */ + 0, /* seek */ + 0 /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , 0 /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: note_read + ****************************************************************************/ + +static ssize_t note_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + ssize_t notelen; + ssize_t retlen ; + + DEBUGASSERT(filep != 0 && buffer != NULL && buflen > 0); + + /* Then loop, adding as many notes as possible to the user buffer. */ + + retlen = 0; + sched_lock(); + do + { + /* Get the next note (removing it from the buffer) */ + + notelen = sched_note_get((FAR uint8_t *)buffer, buflen); + if (notelen < 0) + { + /* We were unable to read the next note, probably because it will + * not fit into the user buffer. + */ + + if (retlen == 0) + { + /* If nothing was read then report the error. Otherwise, + * just silently drop the note. + */ + + retlen = notelen; + } + + break; + } + + /* Update pointers from the note that was transferred */ + + retlen += notelen; + buffer += notelen; + buflen -= notelen; + + /* Will the next note fit? There is a race here and even if the next + * note will fit, it may fail still when sched_note_get() is called. + * + * It won't fit (or an error occurred). Return what we have without + * trying to get the next note (which would cause it to be deleted). + */ + + notelen = sched_note_size(); + } + while (notelen > 0 && notelen <= buflen); + + sched_unlock(); + return retlen; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: note_register + * + * Description: + * Register a serial driver at /dev/note that can be used by an + * application to read data from the circular not buffer. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero is returned if the circular buffer is empty. Otherwise, a negated + * errno value is returned. + * + ****************************************************************************/ + +int note_register(void) +{ + return register_driver("/dev/note", ¬e_fops, 0666, NULL); +} + +#endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER && CONFIG_DRIVER_NOTE */ \ No newline at end of file diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h index dd7ca875a0..39096228b5 100644 --- a/include/nuttx/sched_note.h +++ b/include/nuttx/sched_note.h @@ -195,11 +195,9 @@ void sched_note_csection(FAR struct tcb_s *tcb, bool enter); * buflen - The length of the user provided buffer. * * Returned Value: - * None - * - * Assumptions: - * On success, the length of the return note is provided. A negated - * errno value is returned on failure. + * On success, the positive, non-zero length of the return note is + * provided. Zero is returned only if ther circular buffer is empty. A + * negated errno value is returned in the event of any failure. * ****************************************************************************/ @@ -207,6 +205,46 @@ void sched_note_csection(FAR struct tcb_s *tcb, bool enter); ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen); #endif +/**************************************************************************** + * Name: sched_note_size + * + * Description: + * Return the size of the next note at the tail of the circular buffer. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero is returned if the circular buffer is empty. Otherwise, the size + * of the next note is returned. + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_INSTRUMENTATION_BUFFER +ssize_t sched_note_size(void); +#endif + +/**************************************************************************** + * Name: note_register + * + * Description: + * Register a serial driver at /dev/note that can be used by an + * application to read data from the circular not buffer. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero is returned if the circular buffer is empty. Otherwise, a negated + * errno value is returned. + * + ****************************************************************************/ + +#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ + defined(CONFIG_DRIVER_NOTE) +int note_register(void); +#endif + #else /* CONFIG_SCHED_INSTRUMENTATION */ # define sched_note_start(t) diff --git a/sched/sched/sched_note.c b/sched/sched/sched_note.c index 3838bef8cd..83f14a6376 100644 --- a/sched/sched/sched_note.c +++ b/sched/sched/sched_note.c @@ -158,7 +158,6 @@ static void note_systime(FAR struct note_common_s *note) * ****************************************************************************/ -#ifdef CONFIG_DEBUG static unsigned int note_length(void) { unsigned int head = g_note_info.ni_head; @@ -171,7 +170,6 @@ static unsigned int note_length(void) return head - tail; } -#endif /**************************************************************************** * Name: note_remove @@ -422,11 +420,9 @@ void sched_note_csection(FAR struct tcb_s *tcb, bool enter) * buflen - The length of the user provided buffer. * * Returned Value: - * None - * - * Assumptions: - * On success, the length of the return note is provided. A negated - * errno value is returned on failure. + * On success, the positive, non-zero length of the return note is + * provided. Zero is returned only if ther circular buffer is empty. A + * negated errno value is returned in the event of any failure. * ****************************************************************************/ @@ -437,10 +433,20 @@ ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen) unsigned int remaining; unsigned int tail; ssize_t notelen; + size_t circlen; DEBUGASSERT(buffer != NULL); flags = enter_critical_section(); + /* Verify that the circular buffer is not empty */ + + circlen = note_length(); + if (circlen <= 0) + { + notelen = 0; + goto errout_with_csection; + } + /* Get the index to the tail of the circular buffer */ tail = g_note_info.ni_tail; @@ -448,9 +454,9 @@ ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen) /* Get the length of the note at the tail index */ - note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail]; + note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail]; notelen = note->nc_length; - DEBUGASSERT(notelen <= note_length()); + DEBUGASSERT(notelen <= circlen); /* Is the user buffer large enough to hold the note? */ @@ -488,4 +494,55 @@ errout_with_csection: return notelen; } +/**************************************************************************** + * Name: sched_note_size + * + * Description: + * Return the size of the next note at the tail of the circular buffer. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero is returned if the circular buffer is empty. Otherwise, the size + * of the next note is returned. + * + ****************************************************************************/ + +ssize_t sched_note_size(void) +{ + FAR struct note_common_s *note; + irqstate_t flags; + unsigned int tail; + ssize_t notelen; + size_t circlen; + + DEBUGASSERT(buffer != NULL); + flags = enter_critical_section(); + + /* Verify that the circular buffer is not empty */ + + circlen = note_length(); + if (circlen <= 0) + { + notelen = 0; + goto errout_with_csection; + } + + /* Get the index to the tail of the circular buffer */ + + tail = g_note_info.ni_tail; + DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE); + + /* Get the length of the note at the tail index */ + + note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail]; + notelen = note->nc_length; + DEBUGASSERT(notelen <= circlen); + +errout_with_csection: + leave_critical_section(flags); + return notelen; +} + #endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER */ -- GitLab